Skip to content

Commit

Permalink
fix(qr): img QR component - should track logo change
Browse files Browse the repository at this point in the history
  • Loading branch information
vnphanquang committed Mar 19, 2024
1 parent b502372 commit 54d21ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-hats-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@svelte-put/qr": patch
---

QR img component - track logo change
23 changes: 17 additions & 6 deletions packages/qr/src/img/QR.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
$: ({ data, anchorInnerFill, anchorOuterFill, logo, logoRatio, margin, moduleFill, shape, ...rest } = /** @type {import('../qr/types.js').QRConfig} */($$props));
// FIXME: svelte v5 for better dependency tracking here
let logoData = logo;
$: fetchLogo(logo);
$: src = createBase64Image(
/** @type {import('./QR.svelte').QRProps} */ ({
...DEFAULT_FILLS,
data,
anchorInnerFill,
anchorOuterFill,
logo,
logo: logoData,
logoRatio,
margin,
moduleFill,
Expand All @@ -27,14 +31,21 @@
const dispatch = createEventDispatcher();
onMount(async () => {
if (element) dispatch('qr:init', element);
});
/**
* @param {string} logo
*/
async function fetchLogo(logo) {
if (logo?.startsWith('http')) {
logo = await toDataURL(logo);
logoData = await toDataURL(logo);
dispatch('qr:logofetch', logo);
}
});
}
</script>
<slot {src}>
<img {src} alt={$$props.data ?? $$restProps.alt} {...rest} bind:this={element} />
</slot>
{#key src}
<slot {src}>
<img {src} alt={$$props.data ?? $$restProps.alt} {...rest} bind:this={element} />
</slot>
{/key}

0 comments on commit 54d21ac

Please sign in to comment.