@embedpdf/plugin-stamp 2.11.0
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.
- package/LICENSE +21 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +980 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/actions.d.ts +14 -0
- package/dist/lib/defaults/name-map.d.ts +2 -0
- package/dist/lib/handlers/rubber-stamp.handler.d.ts +4 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/stamp-plugin.d.ts +54 -0
- package/dist/lib/tools.d.ts +58 -0
- package/dist/lib/types.d.ts +135 -0
- package/dist/preact/adapter.d.ts +5 -0
- package/dist/preact/annotation.d.ts +1 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -0
- package/dist/preact/index.cjs.map +1 -0
- package/dist/preact/index.d.ts +1 -0
- package/dist/preact/index.js +147 -0
- package/dist/preact/index.js.map +1 -0
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/annotation.d.ts +1 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +146 -0
- package/dist/react/index.js.map +1 -0
- package/dist/shared/components/index.d.ts +3 -0
- package/dist/shared/components/stamp-img.d.ts +10 -0
- package/dist/shared/components/stamp-preview-renderers.d.ts +2 -0
- package/dist/shared/components/stamp-renderer-registration.d.ts +1 -0
- package/dist/shared/hooks/index.d.ts +1 -0
- package/dist/shared/hooks/use-stamp.d.ts +18 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared-preact/components/index.d.ts +3 -0
- package/dist/shared-preact/components/stamp-img.d.ts +10 -0
- package/dist/shared-preact/components/stamp-preview-renderers.d.ts +2 -0
- package/dist/shared-preact/components/stamp-renderer-registration.d.ts +1 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-stamp.d.ts +18 -0
- package/dist/shared-preact/index.d.ts +4 -0
- package/dist/shared-react/components/index.d.ts +3 -0
- package/dist/shared-react/components/stamp-img.d.ts +10 -0
- package/dist/shared-react/components/stamp-preview-renderers.d.ts +2 -0
- package/dist/shared-react/components/stamp-renderer-registration.d.ts +1 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-stamp.d.ts +18 -0
- package/dist/shared-react/index.d.ts +4 -0
- package/dist/svelte/components/StampImg.svelte.d.ts +10 -0
- package/dist/svelte/components/StampPreview.svelte.d.ts +10 -0
- package/dist/svelte/components/StampRendererRegistration.svelte.d.ts +18 -0
- package/dist/svelte/components/index.d.ts +2 -0
- package/dist/svelte/components/stamp-preview-renderers.d.ts +2 -0
- package/dist/svelte/hooks/index.d.ts +1 -0
- package/dist/svelte/hooks/use-stamp.svelte.d.ts +23 -0
- package/dist/svelte/index.cjs +2 -0
- package/dist/svelte/index.cjs.map +1 -0
- package/dist/svelte/index.d.ts +4 -0
- package/dist/svelte/index.js +223 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/vue/components/index.d.ts +2 -0
- package/dist/vue/components/stamp-img.vue.d.ts +9 -0
- package/dist/vue/components/stamp-preview-renderers.d.ts +2 -0
- package/dist/vue/components/stamp-preview.vue.d.ts +10 -0
- package/dist/vue/components/stamp-renderer-registration.vue.d.ts +13 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-stamp.d.ts +262 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +4 -0
- package/dist/vue/index.js +235 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/components/stamp-preview-renderers.tsx","../../src/shared/components/stamp-renderer-registration.tsx","../../src/shared/hooks/use-stamp.ts","../../src/shared/components/stamp-img.tsx","../../src/shared/index.ts"],"sourcesContent":["import { PdfAnnotationSubtype } from '@embedpdf/models';\nimport { createRenderer, BoxedAnnotationRenderer } from '@embedpdf/plugin-annotation/@framework';\nimport { StampPreviewData } from '@embedpdf/plugin-stamp';\n\nexport const stampPreviewRenderers: BoxedAnnotationRenderer[] = [\n createRenderer<never, StampPreviewData>({\n id: 'stampPreview',\n matchesPreview: (p) => p.type === PdfAnnotationSubtype.STAMP,\n renderPreview: ({ data }) => {\n const rotationDeg = ((4 - data.pageRotation) % 4) * 90;\n return (\n <img\n src={data.ghostUrl}\n style={{\n width: '100%',\n height: '100%',\n opacity: 0.6,\n objectFit: 'contain' as const,\n pointerEvents: 'none' as const,\n transform: rotationDeg ? `rotate(${rotationDeg}deg)` : undefined,\n }}\n alt=\"\"\n />\n );\n },\n }),\n];\n","import { useRegisterRenderers } from '@embedpdf/plugin-annotation/@framework';\nimport { stampPreviewRenderers } from './stamp-preview-renderers';\n\nexport function StampRendererRegistration() {\n useRegisterRenderers(stampPreviewRenderers);\n return null;\n}\n","import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { StampPlugin, StampLibrary, ResolvedStamp, ActiveStampInfo } from '@embedpdf/plugin-stamp';\nimport { useState, useEffect } from '@framework';\n\nexport const useStampPlugin = () => usePlugin<StampPlugin>(StampPlugin.id);\nexport const useStampCapability = () => useCapability<StampPlugin>(StampPlugin.id);\n\nexport const useStampLibraries = () => {\n const { provides } = useStampCapability();\n const [libraries, setLibraries] = useState<StampLibrary[]>(provides?.getLibraries() ?? []);\n\n useEffect(() => {\n if (!provides) return;\n setLibraries(provides.getLibraries());\n return provides.onLibraryChange((libs) => {\n setLibraries(libs);\n });\n }, [provides]);\n\n return { libraries, provides };\n};\n\nexport const useStampsByCategory = (category: string) => {\n const { provides } = useStampCapability();\n const [stamps, setStamps] = useState<ResolvedStamp[]>([]);\n\n useEffect(() => {\n if (!provides) return;\n setStamps(provides.getStampsByCategory(category));\n return provides.onLibraryChange(() => {\n setStamps(provides.getStampsByCategory(category));\n });\n }, [provides, category]);\n\n return stamps;\n};\n\nexport const useStampsByLibrary = (libraryId?: string, category?: string) => {\n const { provides } = useStampCapability();\n const [stamps, setStamps] = useState<ResolvedStamp[]>([]);\n\n useEffect(() => {\n if (!provides) return;\n\n const derive = () => {\n const libraries = provides.getLibraries();\n const results: ResolvedStamp[] = [];\n\n for (const library of libraries) {\n if (libraryId && libraryId !== 'all' && library.id !== libraryId) continue;\n\n for (const stamp of library.stamps) {\n if (category) {\n const libraryMatches = library.categories?.includes(category) ?? false;\n const stampMatches = stamp.categories?.includes(category) ?? false;\n if (!libraryMatches && !stampMatches) continue;\n }\n results.push({ library, stamp });\n }\n }\n\n setStamps(results);\n };\n\n derive();\n return provides.onLibraryChange(derive);\n }, [provides, libraryId, category]);\n\n return stamps;\n};\n\nexport const useActiveStamp = (documentId: string) => {\n const { provides: stamp } = useStampCapability();\n const [activeStamp, setActiveStamp] = useState<ActiveStampInfo | null>(null);\n\n useEffect(() => {\n if (!stamp) return;\n const scope = stamp.forDocument(documentId);\n setActiveStamp(scope.getActiveStamp());\n return scope.onActiveStampChange(setActiveStamp);\n }, [stamp, documentId]);\n\n return activeStamp;\n};\n","import { useEffect, useState, useRef, HTMLAttributes, CSSProperties } from '@framework';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { useStampCapability } from '../hooks';\n\ntype StampImgProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n libraryId: string;\n pageIndex: number;\n width: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function StampImg({ libraryId, pageIndex, width, dpr, style, ...props }: StampImgProps) {\n const { provides } = useStampCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (!provides) return;\n\n const task = provides.renderStamp(libraryId, pageIndex, width, dpr ?? window.devicePixelRatio);\n\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled stamp render task',\n });\n }\n };\n }, [provides, libraryId, pageIndex, width, dpr]);\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n return url ? <img src={url} onLoad={handleImageLoad} style={style} {...props} /> : null;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { StampPluginPackage as BaseStampPackage } from '@embedpdf/plugin-stamp';\nimport { StampRendererRegistration } from './components/stamp-renderer-registration';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-stamp';\n\nexport const StampPluginPackage = createPluginPackage(BaseStampPackage)\n .addUtility(StampRendererRegistration)\n .build();\n"],"names":["BaseStampPackage"],"mappings":";;;;;;;;;AAIO,MAAM,wBAAmD;AAAA,EAC9D,eAAwC;AAAA,IACtC,IAAI;AAAA,IACJ,gBAAgB,CAAC,MAAM,EAAE,SAAS,qBAAqB;AAAA,IACvD,eAAe,CAAC,EAAE,WAAW;AAC3B,YAAM,eAAgB,IAAI,KAAK,gBAAgB,IAAK;AACpD,aACE;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,KAAK,KAAK;AAAA,UACV,OAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,SAAS;AAAA,YACT,WAAW;AAAA,YACX,eAAe;AAAA,YACf,WAAW,cAAc,UAAU,WAAW,SAAS;AAAA,UAAA;AAAA,UAEzD,KAAI;AAAA,QAAA;AAAA,MAAA;AAAA,IAGV;AAAA,EAAA,CACD;AACH;ACvBO,SAAS,4BAA4B;AAC1C,uBAAqB,qBAAqB;AAC1C,SAAO;AACT;ACFO,MAAM,iBAAiB,MAAM,UAAuB,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A,IACF;AAAA,EACF,GAAG,CAAC,UAAU,WAAW,WAAW,OAAO,GAAG,CAAC;AAE/C,QAAM,kBAAkB,MAAM;AAC5B,QAAI,OAAO,SAAS;AAClB,UAAI,gBAAgB,OAAO,OAAO;AAClC,aAAO,UAAU;AAAA,IACnB;AAAA,EACF;AAEA,SAAO,MAAM,oBAAC,OAAA,EAAI,KAAK,KAAK,QAAQ,iBAAiB,OAAe,GAAG,MAAA,CAAO,IAAK;AACrF;ACzCO,MAAM,qBAAqB,oBAAoBA,oBAAgB,EACnE,WAAW,yBAAyB,EACpC,MAAA;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/plugin-annotation/react';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/react';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-stamp"),r=require("@embedpdf/plugin-annotation/react"),n=require("react/jsx-runtime"),i=require("@embedpdf/models"),s=require("@embedpdf/core/react"),a=require("react"),o=[r.createRenderer({id:"stampPreview",matchesPreview:e=>e.type===i.PdfAnnotationSubtype.STAMP,renderPreview:({data:e})=>{const t=(4-e.pageRotation)%4*90;return n.jsx("img",{src:e.ghostUrl,style:{width:"100%",height:"100%",opacity:.6,objectFit:"contain",pointerEvents:"none",transform:t?`rotate(${t}deg)`:void 0},alt:""})}})];function u(){return r.useRegisterRenderers(o),null}const c=()=>s.useCapability(t.StampPlugin.id);const p=e.createPluginPackage(t.StampPluginPackage).addUtility(u).build();exports.StampImg=function({libraryId:e,pageIndex:t,width:r,dpr:s,style:o,...u}){const{provides:p}=c(),[d,l]=a.useState(),g=a.useRef(null);return a.useEffect(()=>{if(!p)return;const n=p.renderStamp(e,t,r,s??window.devicePixelRatio);return n.wait(e=>{const t=URL.createObjectURL(e);g.current=t,l(t)},i.ignore),()=>{g.current?(URL.revokeObjectURL(g.current),g.current=null):n.abort({code:i.PdfErrorCode.Cancelled,message:"canceled stamp render task"})}},[p,e,t,r,s]),d?n.jsx("img",{src:d,onLoad:()=>{g.current&&(URL.revokeObjectURL(g.current),g.current=null)},style:o,...u}):null},exports.StampPluginPackage=p,exports.StampRendererRegistration=u,exports.stampPreviewRenderers=o,exports.useActiveStamp=e=>{const{provides:t}=c(),[r,n]=a.useState(null);return a.useEffect(()=>{if(!t)return;const r=t.forDocument(e);return n(r.getActiveStamp()),r.onActiveStampChange(n)},[t,e]),r},exports.useStampCapability=c,exports.useStampLibraries=()=>{const{provides:e}=c(),[t,r]=a.useState((null==e?void 0:e.getLibraries())??[]);return a.useEffect(()=>{if(e)return r(e.getLibraries()),e.onLibraryChange(e=>{r(e)})},[e]),{libraries:t,provides:e}},exports.useStampPlugin=()=>s.usePlugin(t.StampPlugin.id),exports.useStampsByCategory=e=>{const{provides:t}=c(),[r,n]=a.useState([]);return a.useEffect(()=>{if(t)return n(t.getStampsByCategory(e)),t.onLibraryChange(()=>{n(t.getStampsByCategory(e))})},[t,e]),r},exports.useStampsByLibrary=(e,t)=>{const{provides:r}=c(),[n,i]=a.useState([]);return a.useEffect(()=>{if(!r)return;const n=()=>{var n,s;const a=r.getLibraries(),o=[];for(const r of a)if(!e||"all"===e||r.id===e)for(const e of r.stamps){if(t){const i=(null==(n=r.categories)?void 0:n.includes(t))??!1,a=(null==(s=e.categories)?void 0:s.includes(t))??!1;if(!i&&!a)continue}o.push({library:r,stamp:e})}i(o)};return n(),r.onLibraryChange(n)},[r,e,t]),n},Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/components/stamp-preview-renderers.tsx","../../src/shared/components/stamp-renderer-registration.tsx","../../src/shared/hooks/use-stamp.ts","../../src/shared/index.ts","../../src/shared/components/stamp-img.tsx"],"sourcesContent":["import { PdfAnnotationSubtype } from '@embedpdf/models';\nimport { createRenderer, BoxedAnnotationRenderer } from '@embedpdf/plugin-annotation/@framework';\nimport { StampPreviewData } from '@embedpdf/plugin-stamp';\n\nexport const stampPreviewRenderers: BoxedAnnotationRenderer[] = [\n createRenderer<never, StampPreviewData>({\n id: 'stampPreview',\n matchesPreview: (p) => p.type === PdfAnnotationSubtype.STAMP,\n renderPreview: ({ data }) => {\n const rotationDeg = ((4 - data.pageRotation) % 4) * 90;\n return (\n <img\n src={data.ghostUrl}\n style={{\n width: '100%',\n height: '100%',\n opacity: 0.6,\n objectFit: 'contain' as const,\n pointerEvents: 'none' as const,\n transform: rotationDeg ? `rotate(${rotationDeg}deg)` : undefined,\n }}\n alt=\"\"\n />\n );\n },\n }),\n];\n","import { useRegisterRenderers } from '@embedpdf/plugin-annotation/@framework';\nimport { stampPreviewRenderers } from './stamp-preview-renderers';\n\nexport function StampRendererRegistration() {\n useRegisterRenderers(stampPreviewRenderers);\n return null;\n}\n","import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { StampPlugin, StampLibrary, ResolvedStamp, ActiveStampInfo } from '@embedpdf/plugin-stamp';\nimport { useState, useEffect } from '@framework';\n\nexport const useStampPlugin = () => usePlugin<StampPlugin>(StampPlugin.id);\nexport const useStampCapability = () => useCapability<StampPlugin>(StampPlugin.id);\n\nexport const useStampLibraries = () => {\n const { provides } = useStampCapability();\n const [libraries, setLibraries] = useState<StampLibrary[]>(provides?.getLibraries() ?? []);\n\n useEffect(() => {\n if (!provides) return;\n setLibraries(provides.getLibraries());\n return provides.onLibraryChange((libs) => {\n setLibraries(libs);\n });\n }, [provides]);\n\n return { libraries, provides };\n};\n\nexport const useStampsByCategory = (category: string) => {\n const { provides } = useStampCapability();\n const [stamps, setStamps] = useState<ResolvedStamp[]>([]);\n\n useEffect(() => {\n if (!provides) return;\n setStamps(provides.getStampsByCategory(category));\n return provides.onLibraryChange(() => {\n setStamps(provides.getStampsByCategory(category));\n });\n }, [provides, category]);\n\n return stamps;\n};\n\nexport const useStampsByLibrary = (libraryId?: string, category?: string) => {\n const { provides } = useStampCapability();\n const [stamps, setStamps] = useState<ResolvedStamp[]>([]);\n\n useEffect(() => {\n if (!provides) return;\n\n const derive = () => {\n const libraries = provides.getLibraries();\n const results: ResolvedStamp[] = [];\n\n for (const library of libraries) {\n if (libraryId && libraryId !== 'all' && library.id !== libraryId) continue;\n\n for (const stamp of library.stamps) {\n if (category) {\n const libraryMatches = library.categories?.includes(category) ?? false;\n const stampMatches = stamp.categories?.includes(category) ?? false;\n if (!libraryMatches && !stampMatches) continue;\n }\n results.push({ library, stamp });\n }\n }\n\n setStamps(results);\n };\n\n derive();\n return provides.onLibraryChange(derive);\n }, [provides, libraryId, category]);\n\n return stamps;\n};\n\nexport const useActiveStamp = (documentId: string) => {\n const { provides: stamp } = useStampCapability();\n const [activeStamp, setActiveStamp] = useState<ActiveStampInfo | null>(null);\n\n useEffect(() => {\n if (!stamp) return;\n const scope = stamp.forDocument(documentId);\n setActiveStamp(scope.getActiveStamp());\n return scope.onActiveStampChange(setActiveStamp);\n }, [stamp, documentId]);\n\n return activeStamp;\n};\n","import { createPluginPackage } from '@embedpdf/core';\nimport { StampPluginPackage as BaseStampPackage } from '@embedpdf/plugin-stamp';\nimport { StampRendererRegistration } from './components/stamp-renderer-registration';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-stamp';\n\nexport const StampPluginPackage = createPluginPackage(BaseStampPackage)\n .addUtility(StampRendererRegistration)\n .build();\n","import { useEffect, useState, useRef, HTMLAttributes, CSSProperties } from '@framework';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { useStampCapability } from '../hooks';\n\ntype StampImgProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n libraryId: string;\n pageIndex: number;\n width: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function StampImg({ libraryId, pageIndex, width, dpr, style, ...props }: StampImgProps) {\n const { provides } = useStampCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (!provides) return;\n\n const task = provides.renderStamp(libraryId, pageIndex, width, dpr ?? window.devicePixelRatio);\n\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled stamp render task',\n });\n }\n };\n }, [provides, libraryId, pageIndex, width, dpr]);\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n return url ? <img src={url} onLoad={handleImageLoad} style={style} {...props} /> : null;\n}\n"],"names":["stampPreviewRenderers","createRenderer","id","matchesPreview","p","type","PdfAnnotationSubtype","STAMP","renderPreview","data","rotationDeg","pageRotation","jsx","src","ghostUrl","style","width","height","opacity","objectFit","pointerEvents","transform","alt","StampRendererRegistration","useRegisterRenderers","useStampCapability","useCapability","StampPlugin","StampPluginPackage","createPluginPackage","BaseStampPackage","addUtility","build","libraryId","pageIndex","dpr","props","provides","url","setUrl","useState","urlRef","useRef","useEffect","task","renderStamp","window","devicePixelRatio","wait","blob","objectUrl","URL","createObjectURL","current","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","onLoad","documentId","stamp","activeStamp","setActiveStamp","scope","forDocument","getActiveStamp","onActiveStampChange","libraries","setLibraries","getLibraries","onLibraryChange","libs","usePlugin","category","stamps","setStamps","getStampsByCategory","derive","results","library","libraryMatches","_a","categories","includes","stampMatches","_b","push"],"mappings":"uTAIaA,EAAmD,CAC9DC,iBAAwC,CACtCC,GAAI,eACJC,eAAiBC,GAAMA,EAAEC,OAASC,EAAAA,qBAAqBC,MACvDC,cAAe,EA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xC,CACAN,EAAQQ,KAAK,CAAEP,UAASnB,SAC1B,CAGFe,EAAUG,IAIZ,OADAD,IACO3C,EAASoC,gBAAgBO,IAC/B,CAAC3C,EAAUJ,EAAW2C,IAElBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../shared-react';
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { createPluginPackage } from "@embedpdf/core";
|
|
2
|
+
import { StampPlugin, StampPluginPackage as StampPluginPackage$1 } from "@embedpdf/plugin-stamp";
|
|
3
|
+
export * from "@embedpdf/plugin-stamp";
|
|
4
|
+
import { createRenderer, useRegisterRenderers } from "@embedpdf/plugin-annotation/react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
import { PdfAnnotationSubtype, ignore, PdfErrorCode } from "@embedpdf/models";
|
|
7
|
+
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
8
|
+
import { useState, useEffect, useRef } from "react";
|
|
9
|
+
const stampPreviewRenderers = [
|
|
10
|
+
createRenderer({
|
|
11
|
+
id: "stampPreview",
|
|
12
|
+
matchesPreview: (p) => p.type === PdfAnnotationSubtype.STAMP,
|
|
13
|
+
renderPreview: ({ data }) => {
|
|
14
|
+
const rotationDeg = (4 - data.pageRotation) % 4 * 90;
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
"img",
|
|
17
|
+
{
|
|
18
|
+
src: data.ghostUrl,
|
|
19
|
+
style: {
|
|
20
|
+
width: "100%",
|
|
21
|
+
height: "100%",
|
|
22
|
+
opacity: 0.6,
|
|
23
|
+
objectFit: "contain",
|
|
24
|
+
pointerEvents: "none",
|
|
25
|
+
transform: rotationDeg ? `rotate(${rotationDeg}deg)` : void 0
|
|
26
|
+
},
|
|
27
|
+
alt: ""
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
];
|
|
33
|
+
function StampRendererRegistration() {
|
|
34
|
+
useRegisterRenderers(stampPreviewRenderers);
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const useStampPlugin = () => usePlugin(StampPlugin.id);
|
|
38
|
+
const useStampCapability = () => useCapability(StampPlugin.id);
|
|
39
|
+
const useStampLibraries = () => {
|
|
40
|
+
const { provides } = useStampCapability();
|
|
41
|
+
const [libraries, setLibraries] = useState((provides == null ? void 0 : provides.getLibraries()) ?? []);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!provides) return;
|
|
44
|
+
setLibraries(provides.getLibraries());
|
|
45
|
+
return provides.onLibraryChange((libs) => {
|
|
46
|
+
setLibraries(libs);
|
|
47
|
+
});
|
|
48
|
+
}, [provides]);
|
|
49
|
+
return { libraries, provides };
|
|
50
|
+
};
|
|
51
|
+
const useStampsByCategory = (category) => {
|
|
52
|
+
const { provides } = useStampCapability();
|
|
53
|
+
const [stamps, setStamps] = useState([]);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!provides) return;
|
|
56
|
+
setStamps(provides.getStampsByCategory(category));
|
|
57
|
+
return provides.onLibraryChange(() => {
|
|
58
|
+
setStamps(provides.getStampsByCategory(category));
|
|
59
|
+
});
|
|
60
|
+
}, [provides, category]);
|
|
61
|
+
return stamps;
|
|
62
|
+
};
|
|
63
|
+
const useStampsByLibrary = (libraryId, category) => {
|
|
64
|
+
const { provides } = useStampCapability();
|
|
65
|
+
const [stamps, setStamps] = useState([]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!provides) return;
|
|
68
|
+
const derive = () => {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const libraries = provides.getLibraries();
|
|
71
|
+
const results = [];
|
|
72
|
+
for (const library of libraries) {
|
|
73
|
+
if (libraryId && libraryId !== "all" && library.id !== libraryId) continue;
|
|
74
|
+
for (const stamp of library.stamps) {
|
|
75
|
+
if (category) {
|
|
76
|
+
const libraryMatches = ((_a = library.categories) == null ? void 0 : _a.includes(category)) ?? false;
|
|
77
|
+
const stampMatches = ((_b = stamp.categories) == null ? void 0 : _b.includes(category)) ?? false;
|
|
78
|
+
if (!libraryMatches && !stampMatches) continue;
|
|
79
|
+
}
|
|
80
|
+
results.push({ library, stamp });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
setStamps(results);
|
|
84
|
+
};
|
|
85
|
+
derive();
|
|
86
|
+
return provides.onLibraryChange(derive);
|
|
87
|
+
}, [provides, libraryId, category]);
|
|
88
|
+
return stamps;
|
|
89
|
+
};
|
|
90
|
+
const useActiveStamp = (documentId) => {
|
|
91
|
+
const { provides: stamp } = useStampCapability();
|
|
92
|
+
const [activeStamp, setActiveStamp] = useState(null);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!stamp) return;
|
|
95
|
+
const scope = stamp.forDocument(documentId);
|
|
96
|
+
setActiveStamp(scope.getActiveStamp());
|
|
97
|
+
return scope.onActiveStampChange(setActiveStamp);
|
|
98
|
+
}, [stamp, documentId]);
|
|
99
|
+
return activeStamp;
|
|
100
|
+
};
|
|
101
|
+
function StampImg({ libraryId, pageIndex, width, dpr, style, ...props }) {
|
|
102
|
+
const { provides } = useStampCapability();
|
|
103
|
+
const [url, setUrl] = useState();
|
|
104
|
+
const urlRef = useRef(null);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!provides) return;
|
|
107
|
+
const task = provides.renderStamp(libraryId, pageIndex, width, dpr ?? window.devicePixelRatio);
|
|
108
|
+
task.wait((blob) => {
|
|
109
|
+
const objectUrl = URL.createObjectURL(blob);
|
|
110
|
+
urlRef.current = objectUrl;
|
|
111
|
+
setUrl(objectUrl);
|
|
112
|
+
}, ignore);
|
|
113
|
+
return () => {
|
|
114
|
+
if (urlRef.current) {
|
|
115
|
+
URL.revokeObjectURL(urlRef.current);
|
|
116
|
+
urlRef.current = null;
|
|
117
|
+
} else {
|
|
118
|
+
task.abort({
|
|
119
|
+
code: PdfErrorCode.Cancelled,
|
|
120
|
+
message: "canceled stamp render task"
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}, [provides, libraryId, pageIndex, width, dpr]);
|
|
125
|
+
const handleImageLoad = () => {
|
|
126
|
+
if (urlRef.current) {
|
|
127
|
+
URL.revokeObjectURL(urlRef.current);
|
|
128
|
+
urlRef.current = null;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
return url ? /* @__PURE__ */ jsx("img", { src: url, onLoad: handleImageLoad, style, ...props }) : null;
|
|
132
|
+
}
|
|
133
|
+
const StampPluginPackage = createPluginPackage(StampPluginPackage$1).addUtility(StampRendererRegistration).build();
|
|
134
|
+
export {
|
|
135
|
+
StampImg,
|
|
136
|
+
StampPluginPackage,
|
|
137
|
+
StampRendererRegistration,
|
|
138
|
+
stampPreviewRenderers,
|
|
139
|
+
useActiveStamp,
|
|
140
|
+
useStampCapability,
|
|
141
|
+
useStampLibraries,
|
|
142
|
+
useStampPlugin,
|
|
143
|
+
useStampsByCategory,
|
|
144
|
+
useStampsByLibrary
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/shared/components/stamp-preview-renderers.tsx","../../src/shared/components/stamp-renderer-registration.tsx","../../src/shared/hooks/use-stamp.ts","../../src/shared/components/stamp-img.tsx","../../src/shared/index.ts"],"sourcesContent":["import { PdfAnnotationSubtype } from '@embedpdf/models';\nimport { createRenderer, BoxedAnnotationRenderer } from '@embedpdf/plugin-annotation/@framework';\nimport { StampPreviewData } from '@embedpdf/plugin-stamp';\n\nexport const stampPreviewRenderers: BoxedAnnotationRenderer[] = [\n createRenderer<never, StampPreviewData>({\n id: 'stampPreview',\n matchesPreview: (p) => p.type === PdfAnnotationSubtype.STAMP,\n renderPreview: ({ data }) => {\n const rotationDeg = ((4 - data.pageRotation) % 4) * 90;\n return (\n <img\n src={data.ghostUrl}\n style={{\n width: '100%',\n height: '100%',\n opacity: 0.6,\n objectFit: 'contain' as const,\n pointerEvents: 'none' as const,\n transform: rotationDeg ? `rotate(${rotationDeg}deg)` : undefined,\n }}\n alt=\"\"\n />\n );\n },\n }),\n];\n","import { useRegisterRenderers } from '@embedpdf/plugin-annotation/@framework';\nimport { stampPreviewRenderers } from './stamp-preview-renderers';\n\nexport function StampRendererRegistration() {\n useRegisterRenderers(stampPreviewRenderers);\n return null;\n}\n","import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { StampPlugin, StampLibrary, ResolvedStamp, ActiveStampInfo } from '@embedpdf/plugin-stamp';\nimport { useState, useEffect } from '@framework';\n\nexport const useStampPlugin = () => usePlugin<StampPlugin>(StampPlugin.id);\nexport const useStampCapability = () => useCapability<StampPlugin>(StampPlugin.id);\n\nexport const useStampLibraries = () => {\n const { provides } = useStampCapability();\n const [libraries, setLibraries] = useState<StampLibrary[]>(provides?.getLibraries() ?? []);\n\n useEffect(() => {\n if (!provides) return;\n setLibraries(provides.getLibraries());\n return provides.onLibraryChange((libs) => {\n setLibraries(libs);\n });\n }, [provides]);\n\n return { libraries, provides };\n};\n\nexport const useStampsByCategory = (category: string) => {\n const { provides } = useStampCapability();\n const [stamps, setStamps] = useState<ResolvedStamp[]>([]);\n\n useEffect(() => {\n if (!provides) return;\n setStamps(provides.getStampsByCategory(category));\n return provides.onLibraryChange(() => {\n setStamps(provides.getStampsByCategory(category));\n });\n }, [provides, category]);\n\n return stamps;\n};\n\nexport const useStampsByLibrary = (libraryId?: string, category?: string) => {\n const { provides } = useStampCapability();\n const [stamps, setStamps] = useState<ResolvedStamp[]>([]);\n\n useEffect(() => {\n if (!provides) return;\n\n const derive = () => {\n const libraries = provides.getLibraries();\n const results: ResolvedStamp[] = [];\n\n for (const library of libraries) {\n if (libraryId && libraryId !== 'all' && library.id !== libraryId) continue;\n\n for (const stamp of library.stamps) {\n if (category) {\n const libraryMatches = library.categories?.includes(category) ?? false;\n const stampMatches = stamp.categories?.includes(category) ?? false;\n if (!libraryMatches && !stampMatches) continue;\n }\n results.push({ library, stamp });\n }\n }\n\n setStamps(results);\n };\n\n derive();\n return provides.onLibraryChange(derive);\n }, [provides, libraryId, category]);\n\n return stamps;\n};\n\nexport const useActiveStamp = (documentId: string) => {\n const { provides: stamp } = useStampCapability();\n const [activeStamp, setActiveStamp] = useState<ActiveStampInfo | null>(null);\n\n useEffect(() => {\n if (!stamp) return;\n const scope = stamp.forDocument(documentId);\n setActiveStamp(scope.getActiveStamp());\n return scope.onActiveStampChange(setActiveStamp);\n }, [stamp, documentId]);\n\n return activeStamp;\n};\n","import { useEffect, useState, useRef, HTMLAttributes, CSSProperties } from '@framework';\nimport { ignore, PdfErrorCode } from '@embedpdf/models';\nimport { useStampCapability } from '../hooks';\n\ntype StampImgProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {\n libraryId: string;\n pageIndex: number;\n width: number;\n dpr?: number;\n style?: CSSProperties;\n};\n\nexport function StampImg({ libraryId, pageIndex, width, dpr, style, ...props }: StampImgProps) {\n const { provides } = useStampCapability();\n const [url, setUrl] = useState<string>();\n const urlRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (!provides) return;\n\n const task = provides.renderStamp(libraryId, pageIndex, width, dpr ?? window.devicePixelRatio);\n\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef.current = objectUrl;\n setUrl(objectUrl);\n }, ignore);\n\n return () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled stamp render task',\n });\n }\n };\n }, [provides, libraryId, pageIndex, width, dpr]);\n\n const handleImageLoad = () => {\n if (urlRef.current) {\n URL.revokeObjectURL(urlRef.current);\n urlRef.current = null;\n }\n };\n\n return url ? <img src={url} onLoad={handleImageLoad} style={style} {...props} /> : null;\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { StampPluginPackage as BaseStampPackage } from '@embedpdf/plugin-stamp';\nimport { StampRendererRegistration } from './components/stamp-renderer-registration';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-stamp';\n\nexport const StampPluginPackage = createPluginPackage(BaseStampPackage)\n .addUtility(StampRendererRegistration)\n .build();\n"],"names":["BaseStampPackage"],"mappings":";;;;;;;;AAIO,MAAM,wBAAmD;AAAA,EAC9D,eAAwC;AAAA,IACtC,IAAI;AAAA,IACJ,gBAAgB,CAAC,MAAM,EAAE,SAAS,qBAAqB;AAAA,IACvD,eAAe,CAAC,EAAE,WAAW;AAC3B,YAAM,eAAgB,IAAI,KAAK,gBAAgB,IAAK;AACpD,aACE;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,KAAK,KAAK;AAAA,UACV,OAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,SAAS;AAAA,YACT,WAAW;AAAA,YACX,eAAe;AAAA,YACf,WAAW,cAAc,UAAU,WAAW,SAAS;AAAA,UAAA;AAAA,UAEzD,KAAI;AAAA,QAAA;AAAA,MAAA;AAAA,IAGV;AAAA,EAAA,CACD;AACH;ACvBO,SAAS,4BAA4B;AAC1C,uBAAqB,qBAAqB;AAC1C,SAAO;AACT;ACFO,MAAM,iBAAiB,MAAM,UAAuB,YAAY,EAAE;AAClE,MAAM,qBAAqB,MAAM,cAA2B,YAAY,EAAE;AAE1E,MAAM,oBAAoB,MAAM;AACrC,QAAM,EAAE,SAAA,IAAa,mBAAA;AACrB,QAAM,CAAC,WAAW,YAAY,IAAI,UAAyB,qCAAU,mBAAkB,EAAE;AAEzF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AACf,iBAAa,SAAS,cAAc;AACpC,WAAO,SAAS,gBAAgB,CAAC,SAAS;AACxC,mBAAa,IAAI;AAAA,IACnB,CAAC;AAAA,EACH,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO,EAAE,WAAW,SAAA;AACtB;AAEO,MAAM,sBAAsB,CAAC,aAAqB;AACvD,QAAM,EAAE,SAAA,IAAa,mBAAA;AACrB,QAAM,CAAC,QAAQ,SAAS,IAA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|
3
|
+
libraryId: string;
|
|
4
|
+
pageIndex: number;
|
|
5
|
+
width: number;
|
|
6
|
+
dpr?: number;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
};
|
|
9
|
+
export declare function StampImg({ libraryId, pageIndex, width, dpr, style, ...props }: StampImgProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function StampRendererRegistration(): null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-stamp';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StampPlugin, StampLibrary, ResolvedStamp, ActiveStampInfo } from '../../index.ts';
|
|
2
|
+
export declare const useStampPlugin: () => {
|
|
3
|
+
plugin: StampPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useStampCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../index.ts').StampCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const useStampLibraries: () => {
|
|
13
|
+
libraries: StampLibrary[];
|
|
14
|
+
provides: Readonly<import('../../index.ts').StampCapability> | null;
|
|
15
|
+
};
|
|
16
|
+
export declare const useStampsByCategory: (category: string) => ResolvedStamp[];
|
|
17
|
+
export declare const useStampsByLibrary: (libraryId?: string, category?: string) => ResolvedStamp[];
|
|
18
|
+
export declare const useActiveStamp: (documentId: string) => ActiveStampInfo | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './hooks';
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from '../index.ts';
|
|
4
|
+
export declare const StampPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../index.ts').StampPlugin, import('../index.ts').StampPluginConfig, import('../index.ts').StampState, import('../index.ts').StampAction>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTMLAttributes, CSSProperties } from '../../preact/adapter.ts';
|
|
2
|
+
type StampImgProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {
|
|
3
|
+
libraryId: string;
|
|
4
|
+
pageIndex: number;
|
|
5
|
+
width: number;
|
|
6
|
+
dpr?: number;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
};
|
|
9
|
+
export declare function StampImg({ libraryId, pageIndex, width, dpr, style, ...props }: StampImgProps): import("preact").JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function StampRendererRegistration(): null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-stamp';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StampPlugin, StampLibrary, ResolvedStamp, ActiveStampInfo } from '../../lib/index.ts';
|
|
2
|
+
export declare const useStampPlugin: () => {
|
|
3
|
+
plugin: StampPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useStampCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../lib/index.ts').StampCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const useStampLibraries: () => {
|
|
13
|
+
libraries: StampLibrary[];
|
|
14
|
+
provides: Readonly<import('../../lib/index.ts').StampCapability> | null;
|
|
15
|
+
};
|
|
16
|
+
export declare const useStampsByCategory: (category: string) => ResolvedStamp[];
|
|
17
|
+
export declare const useStampsByLibrary: (libraryId?: string, category?: string) => ResolvedStamp[];
|
|
18
|
+
export declare const useActiveStamp: (documentId: string) => ActiveStampInfo | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './hooks';
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from '../lib/index.ts';
|
|
4
|
+
export declare const StampPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').StampPlugin, import('../lib/index.ts').StampPluginConfig, import('../lib/index.ts').StampState, import('../lib/index.ts').StampAction>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTMLAttributes, CSSProperties } from '../../react/adapter.ts';
|
|
2
|
+
type StampImgProps = Omit<HTMLAttributes<HTMLImageElement>, 'style'> & {
|
|
3
|
+
libraryId: string;
|
|
4
|
+
pageIndex: number;
|
|
5
|
+
width: number;
|
|
6
|
+
dpr?: number;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
};
|
|
9
|
+
export declare function StampImg({ libraryId, pageIndex, width, dpr, style, ...props }: StampImgProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function StampRendererRegistration(): null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-stamp';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { StampPlugin, StampLibrary, ResolvedStamp, ActiveStampInfo } from '../../lib/index.ts';
|
|
2
|
+
export declare const useStampPlugin: () => {
|
|
3
|
+
plugin: StampPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useStampCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../lib/index.ts').StampCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare const useStampLibraries: () => {
|
|
13
|
+
libraries: StampLibrary[];
|
|
14
|
+
provides: Readonly<import('../../lib/index.ts').StampCapability> | null;
|
|
15
|
+
};
|
|
16
|
+
export declare const useStampsByCategory: (category: string) => ResolvedStamp[];
|
|
17
|
+
export declare const useStampsByLibrary: (libraryId?: string, category?: string) => ResolvedStamp[];
|
|
18
|
+
export declare const useActiveStamp: (documentId: string) => ActiveStampInfo | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './hooks';
|
|
2
|
+
export * from './components';
|
|
3
|
+
export * from '../lib/index.ts';
|
|
4
|
+
export declare const StampPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').StampPlugin, import('../lib/index.ts').StampPluginConfig, import('../lib/index.ts').StampState, import('../lib/index.ts').StampAction>>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTMLImgAttributes } from 'svelte/elements';
|
|
2
|
+
interface Props extends HTMLImgAttributes {
|
|
3
|
+
libraryId: string;
|
|
4
|
+
pageIndex: number;
|
|
5
|
+
width: number;
|
|
6
|
+
dpr?: number;
|
|
7
|
+
}
|
|
8
|
+
declare const StampImg: import('svelte', { with: { "resolution-mode": "import" } }).Component<Props, {}, "">;
|
|
9
|
+
type StampImg = ReturnType<typeof StampImg>;
|
|
10
|
+
export default StampImg;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Rect } from '@embedpdf/models';
|
|
2
|
+
import { StampPreviewData } from '../../lib/index.ts';
|
|
3
|
+
interface StampPreviewProps {
|
|
4
|
+
data: StampPreviewData;
|
|
5
|
+
bounds: Rect;
|
|
6
|
+
scale: number;
|
|
7
|
+
}
|
|
8
|
+
declare const StampPreview: import('svelte', { with: { "resolution-mode": "import" } }).Component<StampPreviewProps, {}, "">;
|
|
9
|
+
type StampPreview = ReturnType<typeof StampPreview>;
|
|
10
|
+
export default StampPreview;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const StampRendererRegistration: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type StampRendererRegistration = InstanceType<typeof StampRendererRegistration>;
|
|
18
|
+
export default StampRendererRegistration;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-stamp.svelte';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StampPlugin, ResolvedStamp, StampLibrary, ActiveStampInfo } from '../../lib/index.ts';
|
|
2
|
+
export declare const useStampPlugin: () => {
|
|
3
|
+
plugin: StampPlugin | null;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
ready: Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
export declare const useStampCapability: () => {
|
|
8
|
+
provides: Readonly<import('../../lib/index.ts').StampCapability> | null;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
ready: Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export declare function useStampLibraries(): {
|
|
13
|
+
readonly libraries: StampLibrary[];
|
|
14
|
+
};
|
|
15
|
+
export declare function useStampsByCategory(getCategory: () => string): {
|
|
16
|
+
readonly stamps: ResolvedStamp[];
|
|
17
|
+
};
|
|
18
|
+
export declare function useStampsByLibrary(getLibraryId: () => string | undefined, getCategory?: () => string | undefined): {
|
|
19
|
+
readonly stamps: ResolvedStamp[];
|
|
20
|
+
};
|
|
21
|
+
export declare function useActiveStamp(getDocumentId: () => string): {
|
|
22
|
+
readonly activeStamp: ActiveStampInfo | null;
|
|
23
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-stamp");require("svelte/internal/disclose-version"),require("svelte/internal/flags/legacy");const r=require("svelte/internal/client"),n=require("svelte"),s=require("@embedpdf/plugin-annotation/svelte"),i=require("@embedpdf/models"),o=require("@embedpdf/core/svelte");function a(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const p=a(r);var c=p.from_html('<img alt=""/>');const d=[s.createRenderer({id:"stampPreview",matchesPreview:e=>e.type===i.PdfAnnotationSubtype.STAMP,renderPreview:function(e,t){p.push(t,!0);const r=p.derived(()=>(4-t.data.pageRotation)%4*90);var n=c();let s;p.template_effect(()=>{p.set_attribute(n,"src",t.data.ghostUrl),s=p.set_style(n,"",s,{width:"100%",height:"100%",opacity:"0.6","object-fit":"contain","pointer-events":"none",transform:p.get(r)?`rotate(${p.get(r)}deg)`:void 0})}),p.append(e,n),p.pop()}})];function u(e,t){p.push(t,!1);const r=s.getRendererRegistry();n.onMount(()=>{if(r)return r.register(d)}),p.init(),p.pop()}const l=()=>o.useCapability(t.StampPlugin.id);var g=p.from_html("<img/>");const f=e.createPluginPackage(t.StampPluginPackage).addUtility(u).build();exports.StampImg=function(e,t){p.push(t,!0);const r=p.rest_props(t,["$$slots","$$events","$$legacy","libraryId","pageIndex","width","dpr"]),n=l();let s=p.state(void 0),o=null;p.user_effect(()=>{if(!n.provides)return;const e=n.provides.renderStamp(t.libraryId,t.pageIndex,t.width,t.dpr??window.devicePixelRatio);return e.wait(e=>{const t=URL.createObjectURL(e);o=t,p.set(s,t,!0)},i.ignore),()=>{o?(URL.revokeObjectURL(o),o=null):e.abort({code:i.PdfErrorCode.Cancelled,message:"canceled stamp render task"})}});const a=()=>{o&&(URL.revokeObjectURL(o),o=null)};var c=p.comment(),d=p.first_child(c),u=e=>{var t=g();p.attribute_effect(t,()=>({src:p.get(s),onload:a,...r,alt:"Stamp preview"})),p.replay_events(t),p.append(e,t)};p.if(d,e=>{p.get(s)&&e(u)}),p.append(e,c),p.pop()},exports.StampPluginPackage=f,exports.StampRendererRegistration=u,exports.useActiveStamp=function(e){const t=l();let r=p.state(null);const n=p.derived(e);return p.user_effect(()=>{if(!t.provides||!p.get(n))return void p.set(r,null);const e=t.provides.forDocument(p.get(n));return p.set(r,e.getActiveStamp(),!0),e.onActiveStampChange(e=>{p.set(r,e,!0)})}),{get activeStamp(){return p.get(r)}}},exports.useStampCapability=l,exports.useStampLibraries=function(){const e=l();let t=p.state(p.proxy([]));return p.user_effect(()=>{if(e.provides)return p.set(t,e.provides.getLibraries(),!0),e.provides.onLibraryChange(e=>{p.set(t,e,!0)});p.set(t,[],!0)}),{get libraries(){return p.get(t)}}},exports.useStampPlugin=()=>o.usePlugin(t.StampPlugin.id),exports.useStampsByCategory=function(e){const t=l();let r=p.state(p.proxy([]));const n=p.derived(e);return p.user_effect(()=>{if(t.provides)return p.set(r,t.provides.getStampsByCategory(p.get(n)),!0),t.provides.onLibraryChange(()=>{p.set(r,t.provides.getStampsByCategory(p.get(n)),!0)});p.set(r,[],!0)}),{get stamps(){return p.get(r)}}},exports.useStampsByLibrary=function(e,t){const r=l();let n=p.state(p.proxy([]));const s=p.derived(e),i=p.derived(()=>null==t?void 0:t());return p.user_effect(()=>{if(!r.provides)return void p.set(n,[],!0);const e=()=>{var e,t;const o=r.provides.getLibraries(),a=[];for(const r of o)if(!p.get(s)||"all"===p.get(s)||r.id===p.get(s))for(const n of r.stamps){if(p.get(i)){const s=(null==(e=r.categories)?void 0:e.includes(p.get(i)))??!1,o=(null==(t=n.categories)?void 0:t.includes(p.get(i)))??!1;if(!s&&!o)continue}a.push({library:r,stamp:n})}p.set(n,a,!0)};return e(),r.provides.onLibraryChange(e)}),{get stamps(){return p.get(n)}}},Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/svelte/components/stamp-preview-renderers.ts","../../src/svelte/components/StampPreview.svelte","../../src/svelte/components/StampRendererRegistration.svelte","../../src/svelte/hooks/use-stamp.svelte.ts","../../src/svelte/index.ts","../../src/svelte/components/StampImg.svelte"],"sourcesContent":["import { PdfAnnotationSubtype } from '@embedpdf/models';\nimport type { StampPreviewData } from '@embedpdf/plugin-stamp';\nimport type { BoxedAnnotationRenderer } from '@embedpdf/plugin-annotation/svelte';\nimport { createRenderer } from '@embedpdf/plugin-annotation/svelte';\nimport StampPreview from './StampPreview.svelte';\n\nexport const stampPreviewRenderers: BoxedAnnotationRenderer[] = [\n createRenderer<never, StampPreviewData>({\n id: 'stampPreview',\n matchesPreview: (p) => p.type === PdfAnnotationSubtype.STAMP,\n renderPreview: StampPreview,\n }),\n];\n","<script lang=\"ts\">\n import type { Rect } from '@embedpdf/models';\n import type { StampPreviewData } from '@embedpdf/plugin-stamp';\n\n interface StampPreviewProps {\n data: StampPreviewData;\n bounds: Rect;\n scale: number;\n }\n\n let { data }: StampPreviewProps = $props();\n\n const rotationDeg = $derived(((4 - data.pageRotation) % 4) * 90);\n</script>\n\n<img\n src={data.ghostUrl}\n style:width=\"100%\"\n style:height=\"100%\"\n style:opacity=\"0.6\"\n style:object-fit=\"contain\"\n style:pointer-events=\"none\"\n style:transform={rotationDeg ? `rotate(${rotationDeg}deg)` : undefined}\n alt=\"\"\n/>\n","<script lang=\"ts\">\n import { onMount } from 'svelte';\n import { getRendererRegistry } from '@embedpdf/plugin-annotation/svelte';\n import { stampPreviewRenderers } from './stamp-preview-renderers';\n\n const registry = getRendererRegistry();\n\n onMount(() => {\n if (!registry) return;\n return registry.register(stampPreviewRenderers);\n });\n</script>\n","import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { StampPlugin } from '@embedpdf/plugin-stamp';\nimport type { ResolvedStamp, StampLibrary, ActiveStampInfo } from '@embedpdf/plugin-stamp';\n\nexport const useStampPlugin = () => usePlugin<StampPlugin>(StampPlugin.id);\nexport const useStampCapability = () => useCapability<StampPlugin>(StampPlugin.id);\n\nexport function useStampLibraries() {\n const capability = useStampCapability();\n let libraries = $state<StampLibrary[]>([]);\n\n $effect(() => {\n if (!capability.provides) {\n libraries = [];\n return;\n }\n\n libraries = capability.provides.getLibraries();\n return capability.provides.onLibraryChange((libs) => {\n libraries = libs;\n });\n });\n\n return {\n get libraries() {\n return libraries;\n },\n };\n}\n\nexport function useStampsByCategory(getCategory: () => string) {\n const capability = useStampCapability();\n let stamps = $state<ResolvedStamp[]>([]);\n const category = $derived(getCategory());\n\n $effect(() => {\n if (!capability.provides) {\n stamps = [];\n return;\n }\n\n stamps = capability.provides.getStampsByCategory(category);\n return capability.provides.onLibraryChange(() => {\n stamps = capability.provides!.getStampsByCategory(category);\n });\n });\n\n return {\n get stamps() {\n return stamps;\n },\n };\n}\n\nexport function useStampsByLibrary(\n getLibraryId: () => string | undefined,\n getCategory?: () => string | undefined,\n) {\n const capability = useStampCapability();\n let stamps = $state<ResolvedStamp[]>([]);\n const libraryId = $derived(getLibraryId());\n const category = $derived(getCategory?.());\n\n $effect(() => {\n if (!capability.provides) {\n stamps = [];\n return;\n }\n\n const derive = () => {\n const libraries = capability.provides!.getLibraries();\n const results: ResolvedStamp[] = [];\n\n for (const library of libraries) {\n if (libraryId && libraryId !== 'all' && library.id !== libraryId) continue;\n\n for (const stamp of library.stamps) {\n if (category) {\n const libraryMatches = library.categories?.includes(category) ?? false;\n const stampMatches = stamp.categories?.includes(category) ?? false;\n if (!libraryMatches && !stampMatches) continue;\n }\n results.push({ library, stamp });\n }\n }\n\n stamps = results;\n };\n\n derive();\n return capability.provides.onLibraryChange(derive);\n });\n\n return {\n get stamps() {\n return stamps;\n },\n };\n}\n\nexport function useActiveStamp(getDocumentId: () => string) {\n const capability = useStampCapability();\n let activeStamp = $state<ActiveStampInfo | null>(null);\n const documentId = $derived(getDocumentId());\n\n $effect(() => {\n if (!capability.provides || !documentId) {\n activeStamp = null;\n return;\n }\n\n const scope = capability.provides.forDocument(documentId);\n activeStamp = scope.getActiveStamp();\n return scope.onActiveStampChange((stamp) => {\n activeStamp = stamp;\n });\n });\n\n return {\n get activeStamp() {\n return activeStamp;\n },\n };\n}\n","import { createPluginPackage } from '@embedpdf/core';\nimport { StampPluginPackage as BaseStampPackage } from '@embedpdf/plugin-stamp';\nimport StampRendererRegistration from './components/StampRendererRegistration.svelte';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-stamp';\n\nexport const StampPluginPackage = createPluginPackage(BaseStampPackage)\n .addUtility(StampRendererRegistration)\n .build();\n","<script lang=\"ts\">\n import { ignore, PdfErrorCode } from '@embedpdf/models';\n import { useStampCapability } from '../hooks';\n import type { HTMLImgAttributes } from 'svelte/elements';\n\n interface Props extends HTMLImgAttributes {\n libraryId: string;\n pageIndex: number;\n width: number;\n dpr?: number;\n }\n\n const { libraryId, pageIndex, width, dpr, ...imgProps }: Props = $props();\n\n const stampCapability = useStampCapability();\n\n let url = $state<string | undefined>(undefined);\n let urlRef: string | null = null;\n\n $effect(() => {\n if (!stampCapability.provides) return;\n\n const task = stampCapability.provides.renderStamp(\n libraryId,\n pageIndex,\n width,\n dpr ?? window.devicePixelRatio,\n );\n\n task.wait((blob) => {\n const objectUrl = URL.createObjectURL(blob);\n urlRef = objectUrl;\n url = objectUrl;\n }, ignore);\n\n return () => {\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n } else {\n task.abort({\n code: PdfErrorCode.Cancelled,\n message: 'canceled stamp render task',\n });\n }\n };\n });\n\n const handleImageLoad = () => {\n if (urlRef) {\n URL.revokeObjectURL(urlRef);\n urlRef = null;\n }\n };\n</script>\n\n{#if url}\n <img src={url} onload={handleImageLoad} {...imgProps} alt=\"Stamp preview\" />\n{/if}\n"],"names":["stampPreviewRenderers","createRenderer","id","matchesPreview","p","type","PdfAnnotationSubtype","STAMP","renderPreview","rotationDeg","$$props","data","pageRotation","img","root","$","set_attribute","ghostUrl","styles","get","registry","getRendererRegistry","onMount","register","useStampCapability","useCapability","StampPlugin","StampPluginPackage","createPluginPackage","BaseStampPackage","addUtility","StampRendererRegistration","build","imgProps","rest_props","stampCapability","url","state","urlRef","user_effect","provides","task","renderStamp","libraryId","pageIndex","width","dpr","window","devicePixelRatio","wait","blob","objectUrl","URL","createObjectURL","set","ignore","revokeObjectURL","abort","code","PdfErrorCode","Cancelled","message","handleImageLoad","root_1","consequent","getDocumentId","capability","activeStamp","documentId","scope","forDocument","getActiveStamp","onActiveStampChange","stamp","libraries","proxy","getLibraries","onLibraryChange","libs","usePlugin","getCategory","stamps","category","getStampsByCategory","getLibraryId","derive","results","library","libraryMatches","_a","categories","includes","stampMatches","_b","push"],"mappings":"otBAMO,MAAMA,EAAmD,CAC9DC,iBAAwC,CACtCC,GAAI,eACJC,eAAiBC,GAAMA,EAAEC,OAASC,EAAAA,qBAAqBC,MACvDC,yCCEI,MAAAC,iBAAyB,EAACC,EAAAC,KAAQC,cAAgB,EAAK,QAG9DC,EAAEC,iCAAFC,EAAAC,cAAAH,eACWI,wBADXJ,EAAE,GAAAK,EAAA,yGAOgBT,GAAW,UAAAM,EAAAI,IAAaV,cAAoB,iBAP9DI,UAFO,kCCRA,MAAAO,EAAWC,EAAAA,sBAEjBC,EAAAA,QAAO,QACAF,SACEA,EAASG,SAASvB,qBAErB,CCPK,MACAwB,EAAA,IAA2BC,gBAA2BC,EAAAA,YAAYxB,gCCGxE,MAAMyB,EAAqBC,EAAAA,oBAAoBC,EAAAA,oBACnDC,WAAWC,GACXC,0DCE4CC,EAAQlB,EAAAmB,WAAAxB,EAAA,yEAE/CyB,EAAkBX,QAEpBY,EAAMrB,EAAAsB,WAA2B,GACjCC,EAAwB,KAE5BvB,EAAAwB,YAAO,KACA,IAAAJ,EA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ib/index.ts';
|
|
4
|
+
export declare const StampPluginPackage: import('@embedpdf/core').WithAutoMount<import('@embedpdf/core').PluginPackage<import('../lib/index.ts').StampPlugin, import('../lib/index.ts').StampPluginConfig, import('../lib/index.ts').StampState, import('../lib/index.ts').StampAction>>;
|