@embedpdf/plugin-render 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-render.ts","../../src/svelte/components/RenderLayer.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","<script lang=\"ts\">\n import type { HTMLImgAttributes } from 'svelte/elements';\n import { ignore, PdfErrorCode } from '@embedpdf/models';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRenderCapability } from '../hooks';\n\n interface RenderLayerProps extends Omit<HTMLImgAttributes, 'style'> {\n /**\n * The ID of the document to render from\n */\n documentId: string;\n /**\n * The page index to render (0-based)\n */\n pageIndex: number;\n /**\n * Optional scale override. If not provided, uses document's current scale.\n */\n scale?: number;\n /**\n * Optional device pixel ratio override. If not provided, uses window.devicePixelRatio.\n */\n dpr?: number;\n class?: string;\n style?: string;\n }\n\n // Single allowed $props() call\n const allProps: RenderLayerProps = $props();\n\n // Keep the rest reactive (Svelte will wire these to prop updates)\n let {\n documentId,\n scale: scaleOverride,\n dpr: dprOverride,\n class: propsClass,\n style: propsStyle,\n pageIndex,\n ...attrs\n } = allProps;\n\n // Local non-reactive page index that only updates on actual change\n let localPageIndex = $state(pageIndex);\n\n // Watcher effect: only update localPageIndex if prop actually changes\n $effect(() => {\n if (pageIndex !== localPageIndex) {\n localPageIndex = pageIndex;\n }\n });\n\n const renderCapability = useRenderCapability();\n\n // Make document state follow the (reactive) documentId\n const documentState = useDocumentState(() => documentId);\n\n let imageUrl = $state<string | null>(null);\n let urlRef: string | null = null;\n\n // Track page refreshes from core\n const refreshVersion = $derived(documentState.current?.pageRefreshVersions?.[pageIndex] ?? 0);\n\n // Resolve actual scale / dpr (overrides win, otherwise follow document state)\n const actualScale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const actualDpr = $derived(dprOverride !== undefined ? dprOverride : window.devicePixelRatio);\n\n // Effect: reruns when:\n // - documentId changes\n // - actualScale changes\n // - actualDpr changes\n // - refreshVersion changes\n // - renderCapability.provides changes\n // It does NOT track pageIndex reactively.\n $effect(() => {\n const capability = renderCapability.provides;\n const docId = documentId;\n const scale = actualScale;\n const dpr = actualDpr;\n const refresh = refreshVersion;\n const page = localPageIndex;\n\n if (!capability || !docId) {\n // Cleanup if no capability/doc\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n imageUrl = null;\n return;\n }\n\n const scoped = capability.forDocument(docId);\n\n const task = scoped.renderPage({\n pageIndex: page,\n options: {\n scaleFactor: scale,\n dpr,\n },\n });\n\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n\n // Revoke previous URL if it existed\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n }\n\n urlRef = url;\n imageUrl = url;\n }, ignore);\n\n return () => {\n // Cleanup for this render run\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n imageUrl = null;\n } else {\n // If render not finished, abort task\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n });\n\n function handleImageLoad() {\n // Once image is loaded, we can drop the objectURL reference\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n }\n</script>\n\n{#if imageUrl}\n <img\n src={imageUrl}\n onload={handleImageLoad}\n style={`width: 100%; height: 100%; ${propsStyle ?? ''}`}\n {...attrs}\n class={propsClass}\n alt=\"\"\n />\n{/if}\n"],"names":["useRenderCapability","useCapability","RenderPlugin","id","allProps","$","rest_props","$$props","documentId","scale","scaleOverride","dpr","dprOverride","class","propsClass","style","propsStyle","pageIndex","attrs","localPageIndex","user_effect","get","set","renderCapability","documentState","useDocumentState","imageUrl","urlRef","refreshVersion","derived","_b","_a","current","pageRefreshVersions","actualScale","actualDpr","window","devicePixelRatio","handleImageLoad","URL","revokeObjectURL","capability","provides","docId","page","task","forDocument","renderPage","options","scaleFactor","wait","blob","url","createObjectURL","ignore","abort","code","PdfErrorCode","Cancelled","message","consequent","usePlugin"],"mappings":"oiBAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,qFCwB1EC,EAA0BC,EAAAC,WAAAC,EAAA,CAAA,UAAA,WAAA,4BAI9BC,EACAC,MAAOC,EACPC,IAAKC,EACLC,MAAOC,EACPC,MAAOC,EAAAC,UACPA,KACGC,GACDd,EAGAe,kBAAwBF,IAG5BZ,EAAAe,YAAO,KACDH,IAASZ,EAAAgB,IAAKF,IAChBd,EAAAiB,IAAAH,EAAiBF,GAAS,KAIxB,MAAAM,EAAmBvB,IAGnBwB,EAAgBC,mBAAgB,IAAOjB,GAEzC,IAAAkB,UAAiC,MACjCC,EAAwB,WAGtBC,EAAcvB,EAAAwB,QAAA,aAAY,OAAA,OAAAC,EAAA,OAAAC,EAAAP,EAAcQ,cAAd,EAAAD,EAAuBE,0BAAvB,EAAAH,EAA6Cb,KAAc,IAGrFiB,EAAW7B,EAAAwB,QAAA,WACf,YAAkB,IAAlBnB,EAA8BA,GAAiB,OAAAqB,EAAAP,EAAcQ,kBAASvB,QAAS,IAG3E0B,EAAS9B,EAAAwB,QAAA,SAA4B,IAAhBjB,EAA4BA,EAAcwB,OAAOC,kBAiEnE,SAAAC,IAEHX,IACFY,IAAIC,gBAAgBb,GACpBA,EAAS,KAEb,CA9DAtB,EAAAe,YAAO,WACCqB,EAAalB,EAAiBmB,SAC9BC,EAAQnC,EACRC,QAAQyB,GACRvB,QAAMwB,SACIP,GACV,MAAAgB,QAAOzB,OAERsB,IAAeE,SAEdhB,IACFY,IAAIC,gBAAgBb,GACpBA,EAAS,WAEXtB,EAAAiB,IAAAI,EAAW,MAIP,MAEAmB,EAFSJ,EAAWK,YAAYH,GAElBI,YAClB9B,UAAW2B,EACXI,QAAO,CACLC,YAAaxC,EACbE,SAgBS,OAZbkC,EAAKK,KAAMC,IACH,MAAAC,EAAMb,IAAIc,gBAAgBF,GAG5BxB,GACFY,IAAIC,gBAAgBb,GAGtBA,EAASyB,EACT/C,EAAAiB,IAAAI,EAAW0B,GAAG,IACbE,EAAAA,QAEU,KAEP3B,GACFY,IAAIC,gBAAgBb,GACpBA,EAAS,KACTtB,EAAAiB,IAAAI,EAAW,OAGXmB,EAAKU,MAAK,CACRC,KAAMC,EAAAA,aAAaC,UACnBC,QAAS,sHAiBVjC,UACGY,EAC6BvB,MAAA,8BAAAC,GAAc,QAC/CE,QACGJ,+DANNY,MAAQkC,0BAFb,wDDxI+B,IAAMC,YAAwB3D,EAAAA,aAAaC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-render.ts","../../src/svelte/components/RenderLayer.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","<script lang=\"ts\">\n import type { HTMLImgAttributes } from 'svelte/elements';\n import { ignore, PdfErrorCode } from '@embedpdf/models';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRenderCapability } from '../hooks';\n\n interface RenderLayerProps extends Omit<HTMLImgAttributes, 'style'> {\n /**\n * The ID of the document to render from\n */\n documentId: string;\n /**\n * The page index to render (0-based)\n */\n pageIndex: number;\n /**\n * Optional scale override. If not provided, uses document's current scale.\n */\n scale?: number;\n /**\n * Optional device pixel ratio override. If not provided, uses window.devicePixelRatio.\n */\n dpr?: number;\n class?: string;\n style?: string;\n }\n\n // Single allowed $props() call\n const allProps: RenderLayerProps = $props();\n\n // Keep the rest reactive (Svelte will wire these to prop updates)\n let {\n documentId,\n scale: scaleOverride,\n dpr: dprOverride,\n class: propsClass,\n style: propsStyle,\n pageIndex,\n ...attrs\n } = allProps;\n\n // Local non-reactive page index that only updates on actual change\n let localPageIndex = $state(pageIndex);\n\n // Watcher effect: only update localPageIndex if prop actually changes\n $effect(() => {\n if (pageIndex !== localPageIndex) {\n localPageIndex = pageIndex;\n }\n });\n\n const renderCapability = useRenderCapability();\n\n // Make document state follow the (reactive) documentId\n const documentState = useDocumentState(() => documentId);\n\n let imageUrl = $state<string | null>(null);\n let urlRef: string | null = null;\n\n // Track page refreshes from core\n const refreshVersion = $derived(documentState.current?.pageRefreshVersions?.[pageIndex] ?? 0);\n\n // Resolve actual scale / dpr (overrides win, otherwise follow document state)\n const actualScale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const actualDpr = $derived(dprOverride !== undefined ? dprOverride : window.devicePixelRatio);\n\n // Effect: reruns when:\n // - documentId changes\n // - actualScale changes\n // - actualDpr changes\n // - refreshVersion changes\n // - renderCapability.provides changes\n // It does NOT track pageIndex reactively.\n $effect(() => {\n const capability = renderCapability.provides;\n const docId = documentId;\n const scale = actualScale;\n const dpr = actualDpr;\n const refresh = refreshVersion;\n const page = localPageIndex;\n\n if (!capability || !docId) {\n // Cleanup if no capability/doc\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n imageUrl = null;\n return;\n }\n\n const scoped = capability.forDocument(docId);\n\n const task = scoped.renderPage({\n pageIndex: page,\n options: {\n scaleFactor: scale,\n dpr,\n },\n });\n\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n\n // Revoke previous URL if it existed\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n }\n\n urlRef = url;\n imageUrl = url;\n }, ignore);\n\n return () => {\n // Cleanup for this render run\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n imageUrl = null;\n } else {\n // If render not finished, abort task\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n });\n\n function handleImageLoad() {\n // Once image is loaded, we can drop the objectURL reference\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n }\n</script>\n\n{#if imageUrl}\n <img\n src={imageUrl}\n onload={handleImageLoad}\n style={`width: 100%; height: 100%; ${propsStyle ?? ''}`}\n {...attrs}\n class={propsClass}\n alt=\"\"\n />\n{/if}\n"],"names":["useRenderCapability","useCapability","RenderPlugin","id","allProps","$","rest_props","$$props","documentId","scale","scaleOverride","dpr","dprOverride","class","propsClass","style","propsStyle","pageIndex","attrs","localPageIndex","state","proxy","user_effect","get","set","renderCapability","documentState","useDocumentState","imageUrl","urlRef","refreshVersion","derived","_b","_a","current","pageRefreshVersions","actualScale","actualDpr","window","devicePixelRatio","handleImageLoad","URL","revokeObjectURL","capability","provides","docId","page","task","forDocument","renderPage","options","scaleFactor","wait","blob","url","createObjectURL","ignore","abort","code","PdfErrorCode","Cancelled","message","img","root_1","consequent","usePlugin"],"mappings":"oiBAIaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,qFCwB1EC,EAA0BC,EAAAC,WAAAC,EAAA,CAAA,UAAA,WAAA,4BAI9BC,EACAC,MAAOC,EACPC,IAAKC,EACLC,MAAOC,EACPC,MAAOC,EAAAC,UACPA,KACGC,GACDd,EAGAe,EAAiBd,EAAAe,MAAMf,EAAAgB,MAACJ,IAG5BZ,EAAAiB,YAAO,KACDL,IAASZ,EAAAkB,IAAKJ,IAChBd,EAAAmB,IAAAL,EAAiBF,GAAS,KAIxB,MAAAQ,EAAmBzB,IAGnB0B,EAAgBC,mBAAgB,IAAOnB,OAEzCoB,EAAWvB,EAAAe,MAAsB,MACjCS,EAAwB,WAGtBC,EAAczB,EAAA0B,QAAA,aAAY,OAAA,OAAAC,EAAA,OAAAC,EAAAP,EAAcQ,cAAd,EAAAD,EAAuBE,0BAAvB,EAAAH,EAA6Cf,KAAc,IAGrFmB,EAAW/B,EAAA0B,QAAA,WACf,YAAkB,IAAlBrB,EAA8BA,GAAiB,OAAAuB,EAAAP,EAAcQ,kBAASzB,QAAS,IAG3E4B,EAAShC,EAAA0B,QAAA,SAA4B,IAAhBnB,EAA4BA,EAAc0B,OAAOC,kBAiEnE,SAAAC,IAEHX,IACFY,IAAIC,gBAAgBb,GACpBA,EAAS,KAEb,CA9DAxB,EAAAiB,YAAO,WACCqB,EAAalB,EAAiBmB,SAC9BC,EAAQrC,EACRC,QAAQ2B,GACRzB,QAAM0B,SACIP,GACV,MAAAgB,QAAO3B,OAERwB,IAAeE,SAEdhB,IACFY,IAAIC,gBAAgBb,GACpBA,EAAS,WAEXxB,EAAAmB,IAAAI,EAAW,MAIP,MAEAmB,EAFSJ,EAAWK,YAAYH,GAElBI,YAClBhC,UAAW6B,EACXI,QAAO,CACLC,YAAa1C,EACbE,SAgBS,OAZboC,EAAKK,KAAMC,IACH,MAAAC,EAAMb,IAAIc,gBAAgBF,GAG5BxB,GACFY,IAAIC,gBAAgBb,GAGtBA,EAASyB,EACTjD,EAAAmB,IAAAI,EAAW0B,GAAG,IACbE,EAAAA,QAEU,KAEP3B,GACFY,IAAIC,gBAAgBb,GACpBA,EAAS,KACTxB,EAAAmB,IAAAI,EAAW,OAGXmB,EAAKU,MAAK,CACRC,KAAMC,EAAAA,aAAaC,UACnBC,QAAS,2EAgBhBC,EAAEC,uBAAFD,EAAE,KAAA,WACIlC,UACGY,EAC6BzB,MAAA,8BAAAC,GAAc,QAC/CE,QACGJ,4BALRgD,cAAAA,qBADElC,MAAQoC,0BAFb,wDDxI+B,IAAMC,YAAwB/D,EAAAA,aAAaC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-render.ts","../../src/svelte/components/RenderLayer.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","<script lang=\"ts\">\n import type { HTMLImgAttributes } from 'svelte/elements';\n import { ignore, PdfErrorCode } from '@embedpdf/models';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRenderCapability } from '../hooks';\n\n interface RenderLayerProps extends Omit<HTMLImgAttributes, 'style'> {\n /**\n * The ID of the document to render from\n */\n documentId: string;\n /**\n * The page index to render (0-based)\n */\n pageIndex: number;\n /**\n * Optional scale override. If not provided, uses document's current scale.\n */\n scale?: number;\n /**\n * Optional device pixel ratio override. If not provided, uses window.devicePixelRatio.\n */\n dpr?: number;\n class?: string;\n style?: string;\n }\n\n // Single allowed $props() call\n const allProps: RenderLayerProps = $props();\n\n // Keep the rest reactive (Svelte will wire these to prop updates)\n let {\n documentId,\n scale: scaleOverride,\n dpr: dprOverride,\n class: propsClass,\n style: propsStyle,\n pageIndex,\n ...attrs\n } = allProps;\n\n // Local non-reactive page index that only updates on actual change\n let localPageIndex = $state(pageIndex);\n\n // Watcher effect: only update localPageIndex if prop actually changes\n $effect(() => {\n if (pageIndex !== localPageIndex) {\n localPageIndex = pageIndex;\n }\n });\n\n const renderCapability = useRenderCapability();\n\n // Make document state follow the (reactive) documentId\n const documentState = useDocumentState(() => documentId);\n\n let imageUrl = $state<string | null>(null);\n let urlRef: string | null = null;\n\n // Track page refreshes from core\n const refreshVersion = $derived(documentState.current?.pageRefreshVersions?.[pageIndex] ?? 0);\n\n // Resolve actual scale / dpr (overrides win, otherwise follow document state)\n const actualScale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const actualDpr = $derived(dprOverride !== undefined ? dprOverride : window.devicePixelRatio);\n\n // Effect: reruns when:\n // - documentId changes\n // - actualScale changes\n // - actualDpr changes\n // - refreshVersion changes\n // - renderCapability.provides changes\n // It does NOT track pageIndex reactively.\n $effect(() => {\n const capability = renderCapability.provides;\n const docId = documentId;\n const scale = actualScale;\n const dpr = actualDpr;\n const refresh = refreshVersion;\n const page = localPageIndex;\n\n if (!capability || !docId) {\n // Cleanup if no capability/doc\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n imageUrl = null;\n return;\n }\n\n const scoped = capability.forDocument(docId);\n\n const task = scoped.renderPage({\n pageIndex: page,\n options: {\n scaleFactor: scale,\n dpr,\n },\n });\n\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n\n // Revoke previous URL if it existed\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n }\n\n urlRef = url;\n imageUrl = url;\n }, ignore);\n\n return () => {\n // Cleanup for this render run\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n imageUrl = null;\n } else {\n // If render not finished, abort task\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n });\n\n function handleImageLoad() {\n // Once image is loaded, we can drop the objectURL reference\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n }\n</script>\n\n{#if imageUrl}\n <img\n src={imageUrl}\n onload={handleImageLoad}\n style={`width: 100%; height: 100%; ${propsStyle ?? ''}`}\n {...attrs}\n class={propsClass}\n alt=\"\"\n />\n{/if}\n"],"names":[],"mappings":";;;;;;AAGO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;;wCCJpF;;QA4BQ,WAA0B,EAAA,WAAA,SAAA,CAAA,WAAA,YAAA,UAAA,CAAA;;IAI9B;AAAA,IACA,OAAO;AAAA,IACP,KAAK;AAAA,IACL,OAAO;AAAA,IACP,OAAO;AAAA,IACP;AAAA,OACG;AAAA,MACD;AAGA,MAAA,iCAAwB,SAAS,CAAA;AAGrC,IAAA,YAAO,MAAO;QACR,cAAS,EAAA,IAAK,cAAc,GAAE;AAChC,QAAA,IAAA,gBAAiB,WAAS,IAAA;AAAA,IAC5B;AAAA,EACF,CAAC;AAEK,QAAA,mBAAmB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UAAI,gBAAgB,MAAM;AAC1B,eAAS;AAAA,IACX;AAAA,EACF;;;;;;;mBAKO,QAAQ;AAAA,gBACL;AAAA,QAC6B,OAAA,8BAAA,cAAc,EAAE;AAAA,WACjD;AAAA,eACG;AAAA;;;;;;gBANN,QAAQ,EAAA,UAAA,UAAA;AAAA;;;;AAFb;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-render.ts","../../src/svelte/components/RenderLayer.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { RenderPlugin } from '@embedpdf/plugin-render';\n\nexport const useRenderPlugin = () => usePlugin<RenderPlugin>(RenderPlugin.id);\nexport const useRenderCapability = () => useCapability<RenderPlugin>(RenderPlugin.id);\n","<script lang=\"ts\">\n import type { HTMLImgAttributes } from 'svelte/elements';\n import { ignore, PdfErrorCode } from '@embedpdf/models';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRenderCapability } from '../hooks';\n\n interface RenderLayerProps extends Omit<HTMLImgAttributes, 'style'> {\n /**\n * The ID of the document to render from\n */\n documentId: string;\n /**\n * The page index to render (0-based)\n */\n pageIndex: number;\n /**\n * Optional scale override. If not provided, uses document's current scale.\n */\n scale?: number;\n /**\n * Optional device pixel ratio override. If not provided, uses window.devicePixelRatio.\n */\n dpr?: number;\n class?: string;\n style?: string;\n }\n\n // Single allowed $props() call\n const allProps: RenderLayerProps = $props();\n\n // Keep the rest reactive (Svelte will wire these to prop updates)\n let {\n documentId,\n scale: scaleOverride,\n dpr: dprOverride,\n class: propsClass,\n style: propsStyle,\n pageIndex,\n ...attrs\n } = allProps;\n\n // Local non-reactive page index that only updates on actual change\n let localPageIndex = $state(pageIndex);\n\n // Watcher effect: only update localPageIndex if prop actually changes\n $effect(() => {\n if (pageIndex !== localPageIndex) {\n localPageIndex = pageIndex;\n }\n });\n\n const renderCapability = useRenderCapability();\n\n // Make document state follow the (reactive) documentId\n const documentState = useDocumentState(() => documentId);\n\n let imageUrl = $state<string | null>(null);\n let urlRef: string | null = null;\n\n // Track page refreshes from core\n const refreshVersion = $derived(documentState.current?.pageRefreshVersions?.[pageIndex] ?? 0);\n\n // Resolve actual scale / dpr (overrides win, otherwise follow document state)\n const actualScale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const actualDpr = $derived(dprOverride !== undefined ? dprOverride : window.devicePixelRatio);\n\n // Effect: reruns when:\n // - documentId changes\n // - actualScale changes\n // - actualDpr changes\n // - refreshVersion changes\n // - renderCapability.provides changes\n // It does NOT track pageIndex reactively.\n $effect(() => {\n const capability = renderCapability.provides;\n const docId = documentId;\n const scale = actualScale;\n const dpr = actualDpr;\n const refresh = refreshVersion;\n const page = localPageIndex;\n\n if (!capability || !docId) {\n // Cleanup if no capability/doc\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n imageUrl = null;\n return;\n }\n\n const scoped = capability.forDocument(docId);\n\n const task = scoped.renderPage({\n pageIndex: page,\n options: {\n scaleFactor: scale,\n dpr,\n },\n });\n\n task.wait((blob) => {\n const url = URL.createObjectURL(blob);\n\n // Revoke previous URL if it existed\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n }\n\n urlRef = url;\n imageUrl = url;\n }, ignore);\n\n return () => {\n // Cleanup for this render run\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n imageUrl = null;\n } else {\n // If render not finished, abort task\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled render task',\n });\n }\n };\n });\n\n function handleImageLoad() {\n // Once image is loaded, we can drop the objectURL reference\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n }\n</script>\n\n{#if imageUrl}\n <img\n src={imageUrl}\n onload={handleImageLoad}\n style={`width: 100%; height: 100%; ${propsStyle ?? ''}`}\n {...attrs}\n class={propsClass}\n alt=\"\"\n />\n{/if}\n"],"names":[],"mappings":";;;;;;AAGO,MAAM,kBAAkB,MAAM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A,SAAS;AACZ,cAAA,MAAM,IAAI,gBAAgB,IAAI;AAGhC,YAAA,QAAQ;AACV,cAAI,gBAAgB,MAAM;AAAA,QAC5B;AAEA,iBAAS;AACT,UAAA,IAAA,UAAW,KAAG,IAAA;AAAA,MAChB;AAAA,MAAG;AAAA;AAEU,WAAA,MAAA;AAEP,UAAA,QAAQ;AACV,YAAI,gBAAgB,MAAM;AAC1B,iBAAS;AACT,UAAA,IAAA,UAAW,IAAI;AAAA,MACjB,OAAO;AAEL,aAAK,MAAK;AAAA,UACR,MAAM,aAAa;AAAA,UACnB,SAAS;AAAA;MAEb;AAAA,IACF;AAAA,EACF,CAAC;AAEQ,WAAA,kBAAkB;AAErB,QAAA,QAAQ;AACV,UAAI,gBAAgB,MAAM;AAC1B,eAAS;AAAA,IACX;AAAA,EACF;;;;;UAIC,MAAE,OAAA;yBAAF,KAAE,OAAA;AAAA,mBACI,QAAQ;AAAA,gBACL;AAAA,QAC6B,OAAA,8BAAA,cAAc,EAAE;AAAA,WACjD;AAAA,eACG;AAAA;;sBALR,GAAE;0BAAF,GAAE;AAAA;;gBADA,QAAQ,EAAA,UAAA,UAAA;AAAA;;;;AAFb;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-render",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -35,13 +35,13 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@embedpdf/models": "2.0.0"
38
+ "@embedpdf/models": "2.0.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/react": "^18.2.0",
42
42
  "typescript": "^5.0.0",
43
- "@embedpdf/core": "2.0.0",
44
- "@embedpdf/build": "1.1.0"
43
+ "@embedpdf/build": "1.1.0",
44
+ "@embedpdf/core": "2.0.1"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "preact": "^10.26.4",
@@ -49,7 +49,7 @@
49
49
  "react-dom": ">=16.8.0",
50
50
  "vue": ">=3.2.0",
51
51
  "svelte": ">=5 <6",
52
- "@embedpdf/core": "2.0.0"
52
+ "@embedpdf/core": "2.0.1"
53
53
  },
54
54
  "files": [
55
55
  "dist",