@embedpdf/plugin-stamp 2.14.4 → 3.0.0-next.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.
Files changed (66) hide show
  1. package/LICENSE +192 -21
  2. package/dist/index.cjs +591 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +187 -0
  5. package/dist/index.d.ts +187 -1
  6. package/dist/index.js +584 -975
  7. package/dist/index.js.map +1 -1
  8. package/package.json +23 -61
  9. package/dist/lib/actions.d.ts +0 -14
  10. package/dist/lib/defaults/name-map.d.ts +0 -2
  11. package/dist/lib/handlers/rubber-stamp.handler.d.ts +0 -4
  12. package/dist/lib/index.d.ts +0 -11
  13. package/dist/lib/manifest.d.ts +0 -4
  14. package/dist/lib/reducer.d.ts +0 -5
  15. package/dist/lib/stamp-plugin.d.ts +0 -54
  16. package/dist/lib/tools.d.ts +0 -58
  17. package/dist/lib/types.d.ts +0 -130
  18. package/dist/preact/adapter.d.ts +0 -5
  19. package/dist/preact/annotation.d.ts +0 -1
  20. package/dist/preact/core.d.ts +0 -1
  21. package/dist/preact/index.cjs +0 -2
  22. package/dist/preact/index.cjs.map +0 -1
  23. package/dist/preact/index.d.ts +0 -1
  24. package/dist/preact/index.js +0 -116
  25. package/dist/preact/index.js.map +0 -1
  26. package/dist/react/adapter.d.ts +0 -2
  27. package/dist/react/annotation.d.ts +0 -1
  28. package/dist/react/core.d.ts +0 -1
  29. package/dist/react/index.cjs +0 -2
  30. package/dist/react/index.cjs.map +0 -1
  31. package/dist/react/index.d.ts +0 -1
  32. package/dist/react/index.js +0 -115
  33. package/dist/react/index.js.map +0 -1
  34. package/dist/shared/components/index.d.ts +0 -1
  35. package/dist/shared/components/stamp-img.d.ts +0 -10
  36. package/dist/shared/hooks/index.d.ts +0 -1
  37. package/dist/shared/hooks/use-stamp.d.ts +0 -18
  38. package/dist/shared/index.d.ts +0 -4
  39. package/dist/shared-preact/components/index.d.ts +0 -1
  40. package/dist/shared-preact/components/stamp-img.d.ts +0 -10
  41. package/dist/shared-preact/hooks/index.d.ts +0 -1
  42. package/dist/shared-preact/hooks/use-stamp.d.ts +0 -18
  43. package/dist/shared-preact/index.d.ts +0 -4
  44. package/dist/shared-react/components/index.d.ts +0 -1
  45. package/dist/shared-react/components/stamp-img.d.ts +0 -10
  46. package/dist/shared-react/hooks/index.d.ts +0 -1
  47. package/dist/shared-react/hooks/use-stamp.d.ts +0 -18
  48. package/dist/shared-react/index.d.ts +0 -4
  49. package/dist/svelte/components/StampImg.svelte.d.ts +0 -10
  50. package/dist/svelte/components/index.d.ts +0 -1
  51. package/dist/svelte/hooks/index.d.ts +0 -1
  52. package/dist/svelte/hooks/use-stamp.svelte.d.ts +0 -23
  53. package/dist/svelte/index.cjs +0 -2
  54. package/dist/svelte/index.cjs.map +0 -1
  55. package/dist/svelte/index.d.ts +0 -4
  56. package/dist/svelte/index.js +0 -182
  57. package/dist/svelte/index.js.map +0 -1
  58. package/dist/vue/components/index.d.ts +0 -1
  59. package/dist/vue/components/stamp-img.vue.d.ts +0 -9
  60. package/dist/vue/hooks/index.d.ts +0 -1
  61. package/dist/vue/hooks/use-stamp.d.ts +0 -460
  62. package/dist/vue/index.cjs +0 -2
  63. package/dist/vue/index.cjs.map +0 -1
  64. package/dist/vue/index.d.ts +0 -4
  65. package/dist/vue/index.js +0 -189
  66. package/dist/vue/index.js.map +0 -1
@@ -1,23 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/plugin-stamp"),r=require("svelte/internal/client"),s=require("@embedpdf/core/svelte");require("svelte/internal/disclose-version");const o=require("@embedpdf/models");function i(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const n=i(r),a=()=>s.useCapability(t.StampPlugin.id);var p=n.from_html("<img/>");const c=e.createPluginPackage(t.StampPluginPackage).build();exports.StampImg=function(e,t){n.push(t,!0);const r=n.rest_props(t,["$$slots","$$events","$$legacy","libraryId","pageIndex","width","dpr"]),s=a();let i=n.state(void 0),c=null;n.user_effect(()=>{if(!s.provides)return;const e=s.provides.renderStamp(t.libraryId,t.pageIndex,t.width,t.dpr??window.devicePixelRatio);return e.wait(e=>{const t=URL.createObjectURL(e);c=t,n.set(i,t,!0)},o.ignore),()=>{c?(URL.revokeObjectURL(c),c=null):e.abort({code:o.PdfErrorCode.Cancelled,message:"canceled stamp render task"})}});const u=()=>{c&&(URL.revokeObjectURL(c),c=null)};var l=n.comment(),d=n.first_child(l),g=e=>{var t=p();n.attribute_effect(t,()=>({src:n.get(i),onload:u,...r,alt:"Stamp preview"})),n.replay_events(t),n.append(e,t)};n.if(d,e=>{n.get(i)&&e(g)}),n.append(e,l),n.pop()},exports.StampPluginPackage=c,exports.useActiveStamp=function(e){const t=a();let r=n.state(null);const s=n.derived(e);return n.user_effect(()=>{if(!t.provides||!n.get(s))return void n.set(r,null);const e=t.provides.forDocument(n.get(s));return n.set(r,e.getActiveStamp(),!0),e.onActiveStampChange(e=>{n.set(r,e,!0)})}),{get activeStamp(){return n.get(r)}}},exports.useStampCapability=a,exports.useStampLibraries=function(){const e=a();let t=n.state(n.proxy([]));return n.user_effect(()=>{if(e.provides)return n.set(t,e.provides.getLibraries(),!0),e.provides.onLibraryChange(e=>{n.set(t,e,!0)});n.set(t,[],!0)}),{get libraries(){return n.get(t)}}},exports.useStampPlugin=()=>s.usePlugin(t.StampPlugin.id),exports.useStampsByCategory=function(e){const t=a();let r=n.state(n.proxy([]));const s=n.derived(e);return n.user_effect(()=>{if(t.provides)return n.set(r,t.provides.getStampsByCategory(n.get(s)),!0),t.provides.onLibraryChange(()=>{n.set(r,t.provides.getStampsByCategory(n.get(s)),!0)});n.set(r,[],!0)}),{get stamps(){return n.get(r)}}},exports.useStampsByLibrary=function(e,t){const r=a();let s=n.state(n.proxy([]));const o=n.derived(e),i=n.derived(()=>null==t?void 0:t());return n.user_effect(()=>{if(!r.provides)return void n.set(s,[],!0);const e=()=>{var e,t;const a=r.provides.getLibraries(),p=[];for(const r of a)if(!n.get(o)||"all"===n.get(o)||r.id===n.get(o))for(const s of r.stamps){if(n.get(i)){const o=(null==(e=r.categories)?void 0:e.includes(n.get(i)))??!1,a=(null==(t=s.categories)?void 0:t.includes(n.get(i)))??!1;if(!o&&!a)continue}p.push({library:r,stamp:s})}n.set(s,p,!0)};return e(),r.provides.onLibraryChange(e)}),{get stamps(){return n.get(s)}}},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
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-stamp.svelte.ts","../../src/svelte/index.ts","../../src/svelte/components/StampImg.svelte"],"sourcesContent":["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';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-stamp';\n\nexport const StampPluginPackage = createPluginPackage(BaseStampPackage).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":["useStampCapability","useCapability","StampPlugin","id","StampPluginPackage","createPluginPackage","BaseStampPackage","build","imgProps","$","rest_props","$$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","img","root_1","consequent","getDocumentId","capability","activeStamp","documentId","get","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":"qkBAKaA,EAAA,IAA2BC,gBAA2BC,EAAAA,YAAYC,gCCExE,MAAMC,EAAqBC,EAAAA,oBAAoBC,EAAAA,oBAAkBC,0DCKzBC,EAAQC,EAAAC,WAAAC,EAAA,yEAE/CC,EAAkBZ,QAEpBa,EAAMJ,EAAAK,WAA2B,GACjCC,EAAwB,KAE5BN,EAAAO,YAAO,KACA,IAAAJ,EAAgBK,SAAQ,aAEvBC,EAAON,EAAgBK,SAASE,YAAWR,EAAAS,UAAAT,EAAAU,UAAAV,EAAAW,MAAAX,EAAAY,KAIxCC,OAAOC,kBASH,OANbP,EAAKQ,KAAMC,IACH,MAAAC,EAAYC,IAAIC,gBAAgBH,GACtCZ,EAASa,EACTnB,EAAAsB,IAAAlB,EAAMe,GAAS,IACdI,EAAAA,QAEU,KACPjB,GACFc,IAAII,gBAAgBlB,GACpBA,EAAS,MAETG,EAAKgB,MAAK,CACRC,KAAMC,EAAAA,aAAaC,UACnBC,QAAS,kCAMX,MAAAC,EAAe,KACfxB,IACFc,IAAII,gBAAgBlB,GACpBA,EAAS,sDAMZyB,EAAGC,uBAAHD,EAAG,KAAA,WAAM3B,UAAa0B,KAAqB/B,yCAA3CgC,cAAAA,qBADE3B,MAAG6B,0BAFA,+DF8CuBC,GACvB,MAAAC,EAAa5C,QACf6C,EAAcpC,EAAAK,MAA+B,MAC3C,MAAAgC,YAAsBH,UA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ChBjC,IAA2B,QAA3BX,EAAAsC,IAAa3B,IAAuB8C,EAAQ/D,WAAOiB,GAE5C,IAAA,MAAAgC,KAASc,EAAQN,OAAQ,CAC9B,GAAAnD,EAAAsC,IAAAc,GAAU,OACNM,GAAiB,OAAAC,IAAQC,iBAAR,EAAAD,EAAoBE,SAAA7D,EAAAsC,IAASc,OAAa,EAC3DU,GAAe,OAAAC,IAAMH,iBAAN,EAAAG,EAAkBF,SAAA7D,EAAAsC,IAASc,OAAa,EACxD,IAAAM,IAAmBI,EAAA,QAC1B,CACAN,EAAQQ,KAAA,CAAOP,UAASd,SAC1B,CAGF3C,EAAAsB,IAAA6B,EAASK,GAAA,IAIJ,OADPD,IACOpB,EAAW3B,SAASuC,gBAAgBQ,MAIvC,UAAAJ,gBACKA,EACT,EAEJ"}
@@ -1,4 +0,0 @@
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>>;
@@ -1,182 +0,0 @@
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 * as $ from "svelte/internal/client";
5
- import { usePlugin, useCapability } from "@embedpdf/core/svelte";
6
- import "svelte/internal/disclose-version";
7
- import { ignore, PdfErrorCode } from "@embedpdf/models";
8
- const useStampPlugin = () => usePlugin(StampPlugin.id);
9
- const useStampCapability = () => useCapability(StampPlugin.id);
10
- function useStampLibraries() {
11
- const capability = useStampCapability();
12
- let libraries = $.state($.proxy([]));
13
- $.user_effect(() => {
14
- if (!capability.provides) {
15
- $.set(libraries, [], true);
16
- return;
17
- }
18
- $.set(libraries, capability.provides.getLibraries(), true);
19
- return capability.provides.onLibraryChange((libs) => {
20
- $.set(libraries, libs, true);
21
- });
22
- });
23
- return {
24
- get libraries() {
25
- return $.get(libraries);
26
- }
27
- };
28
- }
29
- function useStampsByCategory(getCategory) {
30
- const capability = useStampCapability();
31
- let stamps = $.state($.proxy([]));
32
- const category = $.derived(getCategory);
33
- $.user_effect(() => {
34
- if (!capability.provides) {
35
- $.set(stamps, [], true);
36
- return;
37
- }
38
- $.set(stamps, capability.provides.getStampsByCategory($.get(category)), true);
39
- return capability.provides.onLibraryChange(() => {
40
- $.set(stamps, capability.provides.getStampsByCategory($.get(category)), true);
41
- });
42
- });
43
- return {
44
- get stamps() {
45
- return $.get(stamps);
46
- }
47
- };
48
- }
49
- function useStampsByLibrary(getLibraryId, getCategory) {
50
- const capability = useStampCapability();
51
- let stamps = $.state($.proxy([]));
52
- const libraryId = $.derived(getLibraryId);
53
- const category = $.derived(() => getCategory == null ? void 0 : getCategory());
54
- $.user_effect(() => {
55
- if (!capability.provides) {
56
- $.set(stamps, [], true);
57
- return;
58
- }
59
- const derive = () => {
60
- var _a, _b;
61
- const libraries = capability.provides.getLibraries();
62
- const results = [];
63
- for (const library of libraries) {
64
- if ($.get(libraryId) && $.get(libraryId) !== "all" && library.id !== $.get(libraryId)) continue;
65
- for (const stamp of library.stamps) {
66
- if ($.get(category)) {
67
- const libraryMatches = ((_a = library.categories) == null ? void 0 : _a.includes($.get(category))) ?? false;
68
- const stampMatches = ((_b = stamp.categories) == null ? void 0 : _b.includes($.get(category))) ?? false;
69
- if (!libraryMatches && !stampMatches) continue;
70
- }
71
- results.push({ library, stamp });
72
- }
73
- }
74
- $.set(stamps, results, true);
75
- };
76
- derive();
77
- return capability.provides.onLibraryChange(derive);
78
- });
79
- return {
80
- get stamps() {
81
- return $.get(stamps);
82
- }
83
- };
84
- }
85
- function useActiveStamp(getDocumentId) {
86
- const capability = useStampCapability();
87
- let activeStamp = $.state(null);
88
- const documentId = $.derived(getDocumentId);
89
- $.user_effect(() => {
90
- if (!capability.provides || !$.get(documentId)) {
91
- $.set(activeStamp, null);
92
- return;
93
- }
94
- const scope = capability.provides.forDocument($.get(documentId));
95
- $.set(activeStamp, scope.getActiveStamp(), true);
96
- return scope.onActiveStampChange((stamp) => {
97
- $.set(activeStamp, stamp, true);
98
- });
99
- });
100
- return {
101
- get activeStamp() {
102
- return $.get(activeStamp);
103
- }
104
- };
105
- }
106
- var root_1 = $.from_html(`<img/>`);
107
- function StampImg($$anchor, $$props) {
108
- $.push($$props, true);
109
- const imgProps = $.rest_props($$props, [
110
- "$$slots",
111
- "$$events",
112
- "$$legacy",
113
- "libraryId",
114
- "pageIndex",
115
- "width",
116
- "dpr"
117
- ]);
118
- const stampCapability = useStampCapability();
119
- let url = $.state(void 0);
120
- let urlRef = null;
121
- $.user_effect(() => {
122
- if (!stampCapability.provides) return;
123
- const task = stampCapability.provides.renderStamp($$props.libraryId, $$props.pageIndex, $$props.width, $$props.dpr ?? window.devicePixelRatio);
124
- task.wait(
125
- (blob) => {
126
- const objectUrl = URL.createObjectURL(blob);
127
- urlRef = objectUrl;
128
- $.set(url, objectUrl, true);
129
- },
130
- ignore
131
- );
132
- return () => {
133
- if (urlRef) {
134
- URL.revokeObjectURL(urlRef);
135
- urlRef = null;
136
- } else {
137
- task.abort({
138
- code: PdfErrorCode.Cancelled,
139
- message: "canceled stamp render task"
140
- });
141
- }
142
- };
143
- });
144
- const handleImageLoad = () => {
145
- if (urlRef) {
146
- URL.revokeObjectURL(urlRef);
147
- urlRef = null;
148
- }
149
- };
150
- var fragment = $.comment();
151
- var node = $.first_child(fragment);
152
- {
153
- var consequent = ($$anchor2) => {
154
- var img = root_1();
155
- $.attribute_effect(img, () => ({
156
- src: $.get(url),
157
- onload: handleImageLoad,
158
- ...imgProps,
159
- alt: "Stamp preview"
160
- }));
161
- $.replay_events(img);
162
- $.append($$anchor2, img);
163
- };
164
- $.if(node, ($$render) => {
165
- if ($.get(url)) $$render(consequent);
166
- });
167
- }
168
- $.append($$anchor, fragment);
169
- $.pop();
170
- }
171
- const StampPluginPackage = createPluginPackage(StampPluginPackage$1).build();
172
- export {
173
- StampImg,
174
- StampPluginPackage,
175
- useActiveStamp,
176
- useStampCapability,
177
- useStampLibraries,
178
- useStampPlugin,
179
- useStampsByCategory,
180
- useStampsByLibrary
181
- };
182
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-stamp.svelte.ts","../../src/svelte/components/StampImg.svelte","../../src/svelte/index.ts"],"sourcesContent":["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","<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","import { createPluginPackage } from '@embedpdf/core';\nimport { StampPluginPackage as BaseStampPackage } from '@embedpdf/plugin-stamp';\n\nexport * from './hooks';\nexport * from './components';\nexport * from '@embedpdf/plugin-stamp';\n\nexport const StampPluginPackage = createPluginPackage(BaseStampPackage).build();\n"],"names":["BaseStampPackage"],"mappings":";;;;;;;AAIa,MAAA,iBAAA,MAAuB,UAAuB,YAAY,EAAE;AAC5D,MAAA,qBAAA,MAA2B,cAA2B,YAAY,EAAE;AAEjE,SAAA,oBAAoB;AAC5B,QAAA,aAAa,mBAAA;AACf,MAAA,YAAY,EAAA,MAAA,EAAA,MAAA,CAAA,CAAA,CAAA;AAEhB,IAAA,kBAAc;SACP,WAAW,UAAU;YACxB,WAAA,CAAA,GAAA,IAAA;;IAEF;AAEA,MAAA,IAAA,WAAY,WAAW,SAAS,aAAA,GAAA,IAAA;AACzB,WAAA,WAAW,SAAS,gBAAA,CAAiB,SAAS;AACnD,QAAA,IAAA,WAAY,MAAA,IAAA;AAAA,IACd,CAAC;AAAA,EACH,CAAC;;IAGK,IAAA,YAAY;mBACP,SAAA;AAAA,IACT;AAAA;AAEJ;SAEgB,oBAAoB,aAA2B;AACvD,QAAA,aAAa,mBAAA;AACf,MAAA,SAAS,EAAA,MAAA,EAAA,MAAA,CAAA,CAAA,CAAA;AACP,QAAA,qBAAoB,WAAA;AAE1B,IAAA,kBAAc;SACP,WAAW,UAAU;YACxB,QAAA,CAAA,GAAA,IAAA;;IAEF;AAEA,MAAA,IAAA,QAAS,WAAW,SAAS,0BAAoB,QAAQ,CAAA,GAAA,IAAA;AAClD,WAAA,WAAW,SAAS,sBAAsB;AAC/C,QAAA,IAAA,QAAS,WAAW,SAAU,0BAAoB,QAAQ,CAAA,GAAA,IAAA;AAAA,IAC5D,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 -1,9 +0,0 @@
1
- interface StampImgProps {
2
- libraryId: string;
3
- pageIndex: number;
4
- width: number;
5
- dpr?: number;
6
- }
7
- declare const __VLS_export: import('vue').DefineComponent<StampImgProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<StampImgProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
8
- declare const _default: typeof __VLS_export;
9
- export default _default;
@@ -1 +0,0 @@
1
- export * from './use-stamp';