@embedpdf/plugin-annotation 1.0.11 → 1.0.13

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 (109) hide show
  1. package/dist/index.cjs +2 -693
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -266
  4. package/dist/index.js +509 -164
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/actions.d.ts +104 -0
  7. package/dist/lib/annotation-plugin.d.ts +34 -0
  8. package/dist/lib/helpers.d.ts +18 -0
  9. package/dist/lib/index.d.ts +12 -0
  10. package/dist/lib/manifest.d.ts +4 -0
  11. package/dist/lib/patching/derived-rect.d.ts +2 -0
  12. package/dist/lib/patching/index.d.ts +4 -0
  13. package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
  14. package/dist/lib/patching/line-endings.d.ts +13 -0
  15. package/dist/lib/patching/patch-utils.d.ts +7 -0
  16. package/dist/lib/reducer.d.ts +5 -0
  17. package/dist/lib/selectors.d.ts +25 -0
  18. package/dist/lib/types.d.ts +168 -0
  19. package/dist/lib/utils.d.ts +11 -0
  20. package/dist/lib/variant-key.d.ts +8 -0
  21. package/dist/preact/adapter.d.ts +8 -0
  22. package/dist/preact/core.d.ts +1 -0
  23. package/dist/preact/index.cjs +2 -1038
  24. package/dist/preact/index.cjs.map +1 -1
  25. package/dist/preact/index.d.ts +1 -28
  26. package/dist/preact/index.js +2150 -539
  27. package/dist/preact/index.js.map +1 -1
  28. package/dist/preact/interaction-manager.d.ts +1 -0
  29. package/dist/preact/selection.d.ts +1 -0
  30. package/dist/react/adapter.d.ts +2 -0
  31. package/dist/react/core.d.ts +1 -0
  32. package/dist/react/index.cjs +2 -0
  33. package/dist/react/index.cjs.map +1 -0
  34. package/dist/react/index.d.ts +1 -0
  35. package/dist/react/index.js +2624 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/react/interaction-manager.d.ts +1 -0
  38. package/dist/react/selection.d.ts +1 -0
  39. package/dist/shared-preact/components/annotation-container.d.ts +24 -0
  40. package/dist/shared-preact/components/annotation-layer.d.ts +13 -0
  41. package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
  42. package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
  43. package/dist/shared-preact/components/annotations/ink-highlight-paint.d.ts +0 -0
  44. package/dist/shared-preact/components/annotations/ink-paint.d.ts +18 -0
  45. package/dist/shared-preact/components/annotations/ink.d.ts +25 -0
  46. package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
  47. package/dist/shared-preact/components/annotations/line.d.ts +33 -0
  48. package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
  49. package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
  50. package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
  51. package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
  52. package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
  53. package/dist/shared-preact/components/annotations/square.d.ts +29 -0
  54. package/dist/shared-preact/components/annotations.d.ts +11 -0
  55. package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
  56. package/dist/shared-preact/components/index.d.ts +1 -0
  57. package/dist/shared-preact/components/render-annotation.d.ts +11 -0
  58. package/dist/shared-preact/components/resize-handles.d.ts +9 -0
  59. package/dist/shared-preact/components/text-markup/highlight.d.ts +13 -0
  60. package/dist/shared-preact/components/text-markup/squiggly.d.ts +13 -0
  61. package/dist/shared-preact/components/text-markup/strikeout.d.ts +13 -0
  62. package/dist/shared-preact/components/text-markup/underline.d.ts +13 -0
  63. package/dist/shared-preact/components/text-markup.d.ts +6 -0
  64. package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
  65. package/dist/shared-preact/hooks/index.d.ts +1 -0
  66. package/dist/shared-preact/hooks/use-annotation.d.ts +11 -0
  67. package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
  68. package/dist/shared-preact/index.d.ts +2 -0
  69. package/dist/shared-preact/patch-ink.d.ts +16 -0
  70. package/dist/shared-preact/patchers.d.ts +9 -0
  71. package/dist/shared-preact/types.d.ts +12 -0
  72. package/dist/shared-preact/vertex-patchers.d.ts +10 -0
  73. package/dist/shared-react/components/annotation-container.d.ts +24 -0
  74. package/dist/shared-react/components/annotation-layer.d.ts +13 -0
  75. package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
  76. package/dist/shared-react/components/annotations/circle.d.ts +29 -0
  77. package/dist/shared-react/components/annotations/ink-highlight-paint.d.ts +0 -0
  78. package/dist/shared-react/components/annotations/ink-paint.d.ts +17 -0
  79. package/dist/shared-react/components/annotations/ink.d.ts +25 -0
  80. package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
  81. package/dist/shared-react/components/annotations/line.d.ts +33 -0
  82. package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
  83. package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
  84. package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
  85. package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
  86. package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
  87. package/dist/shared-react/components/annotations/square.d.ts +29 -0
  88. package/dist/shared-react/components/annotations.d.ts +11 -0
  89. package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
  90. package/dist/shared-react/components/index.d.ts +1 -0
  91. package/dist/shared-react/components/render-annotation.d.ts +11 -0
  92. package/dist/shared-react/components/resize-handles.d.ts +9 -0
  93. package/dist/shared-react/components/text-markup/highlight.d.ts +13 -0
  94. package/dist/shared-react/components/text-markup/squiggly.d.ts +13 -0
  95. package/dist/shared-react/components/text-markup/strikeout.d.ts +13 -0
  96. package/dist/shared-react/components/text-markup/underline.d.ts +13 -0
  97. package/dist/shared-react/components/text-markup.d.ts +6 -0
  98. package/dist/shared-react/components/vertex-editor.d.ts +19 -0
  99. package/dist/shared-react/hooks/index.d.ts +1 -0
  100. package/dist/shared-react/hooks/use-annotation.d.ts +11 -0
  101. package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
  102. package/dist/shared-react/index.d.ts +2 -0
  103. package/dist/shared-react/patch-ink.d.ts +16 -0
  104. package/dist/shared-react/patchers.d.ts +9 -0
  105. package/dist/shared-react/types.d.ts +12 -0
  106. package/dist/shared-react/vertex-patchers.d.ts +10 -0
  107. package/package.json +17 -15
  108. package/dist/index.d.cts +0 -266
  109. package/dist/preact/index.d.cts +0 -28
@@ -0,0 +1,168 @@
1
+ import { BasePluginConfig, EventHook } from '@embedpdf/core';
2
+ import { PdfAnnotationObject, PdfErrorReason, Task, PdfAnnotationSubtype, WebAlphaColor, Rotation, ImageConversionTypes, AppearanceMode, PdfBlendMode, PdfAnnotationBorderStyle, LineEndings } from '@embedpdf/models';
3
+ export type CommitState = 'new' | 'dirty' | 'deleted' | 'synced' | 'ignored';
4
+ export interface TrackedAnnotation<T extends PdfAnnotationObject = PdfAnnotationObject> {
5
+ /** A stable, client-side unique identifier for history and state management. */
6
+ localId: number;
7
+ /**
8
+ * If the engine has already created the annotation in the PDF
9
+ * this is the definitive id coming from the engine.
10
+ * It is **never** cleared once set.
11
+ */
12
+ pdfId?: number;
13
+ /** local commit bookkeeping */
14
+ commitState: CommitState;
15
+ /** the actual annotation object */
16
+ object: T;
17
+ }
18
+ export interface RenderAnnotationOptions {
19
+ pageIndex: number;
20
+ annotation: PdfAnnotationObject;
21
+ scaleFactor?: number;
22
+ rotation?: Rotation;
23
+ dpr?: number;
24
+ mode?: AppearanceMode;
25
+ imageType?: ImageConversionTypes;
26
+ }
27
+ export interface BaseAnnotationDefaults extends WebAlphaColor {
28
+ name: string;
29
+ subtype: PdfAnnotationSubtype;
30
+ interaction: {
31
+ mode: string;
32
+ exclusive: boolean;
33
+ cursor?: string;
34
+ };
35
+ textSelection?: boolean;
36
+ blendMode?: PdfBlendMode;
37
+ }
38
+ export type TextMarkupSubtype = PdfAnnotationSubtype.HIGHLIGHT | PdfAnnotationSubtype.UNDERLINE | PdfAnnotationSubtype.STRIKEOUT | PdfAnnotationSubtype.SQUIGGLY;
39
+ export interface TextMarkupDefaults extends BaseAnnotationDefaults {
40
+ subtype: TextMarkupSubtype;
41
+ blendMode: PdfBlendMode;
42
+ }
43
+ export interface InkDefaults extends BaseAnnotationDefaults {
44
+ subtype: PdfAnnotationSubtype.INK;
45
+ strokeWidth: number;
46
+ intent?: string;
47
+ }
48
+ export interface TextDefaults extends BaseAnnotationDefaults {
49
+ subtype: PdfAnnotationSubtype.FREETEXT;
50
+ fontSize: number;
51
+ }
52
+ export interface CircleDefaults extends BaseAnnotationDefaults {
53
+ subtype: PdfAnnotationSubtype.CIRCLE;
54
+ strokeWidth: number;
55
+ strokeColor: string;
56
+ strokeStyle: PdfAnnotationBorderStyle;
57
+ strokeDashArray?: number[];
58
+ }
59
+ export interface SquareDefaults extends BaseAnnotationDefaults {
60
+ subtype: PdfAnnotationSubtype.SQUARE;
61
+ strokeWidth: number;
62
+ strokeColor: string;
63
+ strokeStyle: PdfAnnotationBorderStyle;
64
+ strokeDashArray?: number[];
65
+ }
66
+ export interface LineDefaults extends BaseAnnotationDefaults {
67
+ subtype: PdfAnnotationSubtype.LINE;
68
+ intent?: string;
69
+ strokeWidth: number;
70
+ strokeColor: string;
71
+ strokeStyle: PdfAnnotationBorderStyle;
72
+ strokeDashArray?: number[];
73
+ lineEndings?: LineEndings;
74
+ }
75
+ export interface PolylineDefaults extends BaseAnnotationDefaults {
76
+ subtype: PdfAnnotationSubtype.POLYLINE;
77
+ strokeWidth: number;
78
+ strokeColor: string;
79
+ strokeStyle: PdfAnnotationBorderStyle;
80
+ strokeDashArray?: number[];
81
+ lineEndings?: LineEndings;
82
+ }
83
+ export interface PolygonDefaults extends BaseAnnotationDefaults {
84
+ subtype: PdfAnnotationSubtype.POLYGON;
85
+ strokeWidth: number;
86
+ strokeColor: string;
87
+ strokeStyle: PdfAnnotationBorderStyle;
88
+ strokeDashArray?: number[];
89
+ }
90
+ export type AnnotationDefaults = TextMarkupDefaults | InkDefaults | TextDefaults | CircleDefaults | SquareDefaults | LineDefaults | PolylineDefaults | PolygonDefaults;
91
+ export type ToolDefaultsByMode = {
92
+ [K in string]: AnnotationDefaults;
93
+ };
94
+ export type ActiveTool = {
95
+ variantKey: null;
96
+ defaults: null;
97
+ } | {
98
+ [K in string]: {
99
+ variantKey: K;
100
+ defaults: ToolDefaultsByMode[K];
101
+ };
102
+ }[string];
103
+ export interface AnnotationState {
104
+ pages: Record<number, string[]>;
105
+ byUid: Record<string, TrackedAnnotation>;
106
+ selectedUid: string | null;
107
+ activeVariant: string | null;
108
+ toolDefaults: Record<string, AnnotationDefaults>;
109
+ colorPresets: string[];
110
+ hasPendingChanges: boolean;
111
+ }
112
+ export interface AnnotationPluginConfig extends BasePluginConfig {
113
+ toolDefaults?: Record<string, AnnotationDefaults>;
114
+ colorPresets?: string[];
115
+ /**
116
+ * When `false` mutations are kept in memory and must be
117
+ * flushed with `commitPendingChanges()`.
118
+ */
119
+ autoCommit?: boolean;
120
+ }
121
+ export interface AnnotationCapability {
122
+ getPageAnnotations: (options: GetPageAnnotationsOptions) => Task<PdfAnnotationObject[], PdfErrorReason>;
123
+ getSelectedAnnotation: () => TrackedAnnotation | null;
124
+ selectAnnotation: (pageIndex: number, annotationId: number) => void;
125
+ deselectAnnotation: () => void;
126
+ getActiveVariant: () => string | null;
127
+ setActiveVariant: (variantKey: string | null) => void;
128
+ /** strongly typed – only sub-types we have defaults for */
129
+ getToolDefaults: (variantKey: string) => AnnotationDefaults;
130
+ getToolDefaultsBySubtypeAndIntent: <Sub extends AnnotationDefaults['subtype']>(subtype: Sub, intent?: string | null) => Extract<AnnotationDefaults, {
131
+ subtype: Sub;
132
+ }>;
133
+ getToolDefaultsBySubtype: <Sub extends AnnotationDefaults['subtype']>(subtype: Sub) => Extract<AnnotationDefaults, {
134
+ subtype: Sub;
135
+ }>;
136
+ /** Return the subtype and intent for a given variant key */
137
+ getSubtypeAndIntentByVariant: (variantKey: string) => {
138
+ subtype: PdfAnnotationSubtype;
139
+ intent?: string;
140
+ };
141
+ /** Partially patch a single tool’s defaults */
142
+ setToolDefaults: (variantKey: string, patch: Partial<AnnotationDefaults>) => void;
143
+ /** current palette – UI just reads this */
144
+ getColorPresets: () => string[];
145
+ /** append a swatch (deduped by RGBA) */
146
+ addColorPreset: (color: string) => void;
147
+ createAnnotation: (pageIndex: number, annotation: PdfAnnotationObject) => void;
148
+ updateAnnotation: (pageIndex: number, annotationId: number, patch: Partial<PdfAnnotationObject>) => void;
149
+ deleteAnnotation: (pageIndex: number, annotationId: number) => void;
150
+ renderAnnotation: (options: RenderAnnotationOptions) => Task<Blob, PdfErrorReason>;
151
+ /** undo / redo */
152
+ onStateChange: EventHook<AnnotationState>;
153
+ onActiveVariantChange: EventHook<string | null>;
154
+ onActiveToolChange: EventHook<ActiveTool>;
155
+ commit: () => void;
156
+ }
157
+ export interface SelectedAnnotation<T extends PdfAnnotationObject = PdfAnnotationObject> {
158
+ pageIndex: number;
159
+ localId: number;
160
+ annotation: T;
161
+ }
162
+ export interface GetPageAnnotationsOptions {
163
+ pageIndex: number;
164
+ }
165
+ export interface UpdateAnnotationColorOptions extends WebAlphaColor {
166
+ pageIndex: number;
167
+ annotationId: number;
168
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Creates a stable, document-wide unique ID from a page index and a stable local ID.
3
+ */
4
+ export declare const makeUid: (pageIndex: number, localId: number) => string;
5
+ /**
6
+ * Parses a UID string back into its constituent page index and stable local ID.
7
+ */
8
+ export declare const parseUid: (uid: string) => {
9
+ pageIndex: number;
10
+ localId: number;
11
+ };
@@ -0,0 +1,8 @@
1
+ import { PdfAnnotationSubtype, PdfAnnotationObject } from '@embedpdf/models';
2
+ export type VariantKey = string;
3
+ export declare const makeVariantKey: (subtype: PdfAnnotationSubtype, intent?: string | null | undefined) => VariantKey;
4
+ export declare const parseVariantKey: (key: VariantKey) => {
5
+ subtype: PdfAnnotationSubtype;
6
+ intent?: string;
7
+ };
8
+ export declare const variantKeyFromAnnotation: (a: PdfAnnotationObject) => VariantKey;
@@ -0,0 +1,8 @@
1
+ import { JSX, Fragment } from 'preact';
2
+ export { useEffect, useRef, useState, useCallback, useMemo, useLayoutEffect } from 'preact/hooks';
3
+ export type { ComponentChildren as ReactNode, JSX } from 'preact';
4
+ export { Fragment };
5
+ export type CSSProperties = import('preact').JSX.CSSProperties;
6
+ export type HTMLAttributes<T = any> = import('preact').JSX.HTMLAttributes<T extends EventTarget ? T : never>;
7
+ export type MouseEvent<T = Element> = JSX.TargetedMouseEvent<T extends EventTarget ? T : never>;
8
+ export type PointerEvent<T = Element> = JSX.TargetedPointerEvent<T extends EventTarget ? T : never>;
@@ -0,0 +1 @@
1
+ export * from '@embedpdf/core/preact';