@embedpdf/web 3.0.0-next.10 → 3.0.0-next.12

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/dist/index.d.cts CHANGED
@@ -216,6 +216,39 @@ declare function svgCursor({ svg, hotspot, fallback }: SvgCursorOptions): string
216
216
  */
217
217
  declare function sanitizeExternalUri(uri: string, allowedSchemes?: Iterable<string>): string | null;
218
218
  //#endregion
219
+ //#region src/actions-ui.d.ts
220
+ /** Structural twin of plugin-actions' `ActionOrigin`. */
221
+ type ActionsUiOrigin = 'user' | 'hover' | 'lifecycle';
222
+ /** Structural twin of plugin-actions' `ActionUiContext`. */
223
+ interface ActionsUiEffectContext {
224
+ origin: ActionsUiOrigin;
225
+ phase: 'boot' | 'user';
226
+ }
227
+ /** Structural twin of plugin-actions' `ActionUiAdapter`. */
228
+ interface ActionsUiAdapterShape {
229
+ openUri(uri: string, opts: {
230
+ isMap: boolean;
231
+ origin: ActionsUiOrigin;
232
+ }): void;
233
+ print(opts?: ActionsUiEffectContext): void;
234
+ alert?(message: string, opts: ActionsUiEffectContext & {
235
+ icon: number;
236
+ title?: string;
237
+ }): void;
238
+ gotoPage?(page: number, opts: ActionsUiEffectContext): void;
239
+ }
240
+ interface DefaultActionsUiAdapterOptions {
241
+ /**
242
+ * Per-handler overrides. Pass a FUNCTION for late binding (a binding's
243
+ * mutable handlers ref) — it is consulted on every effect, so a fresh
244
+ * closure never needs a reinstall.
245
+ */
246
+ overrides?: Partial<ActionsUiAdapterShape> | (() => Partial<ActionsUiAdapterShape> | undefined);
247
+ /** Navigation default for script `this.pageNum = n` requests. */
248
+ goToPage?: (page: number) => void;
249
+ }
250
+ declare const createDefaultActionsUiAdapter: (options?: DefaultActionsUiAdapterOptions) => ActionsUiAdapterShape;
251
+ //#endregion
219
252
  //#region src/painted-image.d.ts
220
253
  /** A browser image source whose object URL has an explicit lifetime. */
221
254
  interface ObjectUrlImageSource {
@@ -557,5 +590,31 @@ interface WheelSample {
557
590
  /** Zoom factor for a ctrl/cmd wheel event (the caller decides zoom vs pan). */
558
591
  declare function wheelZoomFactor(e: WheelSample): number;
559
592
  //#endregion
560
- export { type AnchorTarget, type AnchoredPlacement, type AnchoredPoint, type AnchoredPosition, type AnchoredRect, type AttachSelectionHandleOptions, type ClipboardSelectionSource, type ObjectUrlImageSource, type PaintedImageCallbacks, type PickFileOptions, type SelectionClipboardOptions, type SelectionHandleSession, type StageGestureHost, type StageGestureOptions, type StageGestureSink, type StagePointerKind, type StageSurfaceHost, type StageSurfaceHub, type StageSurfaceOptions, type StageSurfaceSample, type StageWheelSample, type SvgCursorOptions, type ViewProjector, type WebPlatformFeedback, type WheelSample, attachSelectionHandle, bindPaintedImage, computeReleaseVelocity, copySelection, createStageGestureController, createStageSurface, observeClientGeometry, pickFile, pickImageFile, positionAnchoredRect, projectAnchoredTarget, sanitizeExternalUri, saveFile, svgCursor, vibrationFeedback, wheelZoomFactor, wireSelectionClipboard, wkFeedback };
593
+ //#region src/byte-store.d.ts
594
+ /**
595
+ * A bytes-by-id store over IndexedDB — the browser's answer to "keep these
596
+ * blobs for me". Structurally the store port a plugin declares for its own
597
+ * persistence (e.g. `StampLibraryStore` in `@embedpdf/plugin-stamp`); declared
598
+ * here as a twin so this package stays plugin-free, per the layering law.
599
+ *
600
+ * IndexedDB rather than localStorage: a library or an image is binary, and a
601
+ * localStorage string store caps at a few MB. One database, one object store,
602
+ * keys are the caller's ids, values are the bytes as stored.
603
+ */
604
+ interface ByteStore {
605
+ list(): Promise<Array<{
606
+ id: string;
607
+ bytes: Uint8Array;
608
+ }>>;
609
+ put(id: string, bytes: Uint8Array): Promise<void>;
610
+ delete(id: string): Promise<void>;
611
+ }
612
+ interface IndexedDbByteStoreOptions {
613
+ /** Object store name inside the database. Default `'bytes'`. */
614
+ storeName?: string;
615
+ }
616
+ /** Open (creating on first use) one IndexedDB object store keyed by id. */
617
+ declare function indexedDbByteStore(dbName: string, opts?: IndexedDbByteStoreOptions): ByteStore;
618
+ //#endregion
619
+ export { type ActionsUiAdapterShape, type ActionsUiEffectContext, type ActionsUiOrigin, type AnchorTarget, type AnchoredPlacement, type AnchoredPoint, type AnchoredPosition, type AnchoredRect, type AttachSelectionHandleOptions, type ByteStore, type ClipboardSelectionSource, type DefaultActionsUiAdapterOptions, type IndexedDbByteStoreOptions, type ObjectUrlImageSource, type PaintedImageCallbacks, type PickFileOptions, type SelectionClipboardOptions, type SelectionHandleSession, type StageGestureHost, type StageGestureOptions, type StageGestureSink, type StagePointerKind, type StageSurfaceHost, type StageSurfaceHub, type StageSurfaceOptions, type StageSurfaceSample, type StageWheelSample, type SvgCursorOptions, type ViewProjector, type WebPlatformFeedback, type WheelSample, attachSelectionHandle, bindPaintedImage, computeReleaseVelocity, copySelection, createDefaultActionsUiAdapter, createStageGestureController, createStageSurface, indexedDbByteStore, observeClientGeometry, pickFile, pickImageFile, positionAnchoredRect, projectAnchoredTarget, sanitizeExternalUri, saveFile, svgCursor, vibrationFeedback, wheelZoomFactor, wireSelectionClipboard, wkFeedback };
561
620
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -216,6 +216,39 @@ declare function svgCursor({ svg, hotspot, fallback }: SvgCursorOptions): string
216
216
  */
217
217
  declare function sanitizeExternalUri(uri: string, allowedSchemes?: Iterable<string>): string | null;
218
218
  //#endregion
219
+ //#region src/actions-ui.d.ts
220
+ /** Structural twin of plugin-actions' `ActionOrigin`. */
221
+ type ActionsUiOrigin = 'user' | 'hover' | 'lifecycle';
222
+ /** Structural twin of plugin-actions' `ActionUiContext`. */
223
+ interface ActionsUiEffectContext {
224
+ origin: ActionsUiOrigin;
225
+ phase: 'boot' | 'user';
226
+ }
227
+ /** Structural twin of plugin-actions' `ActionUiAdapter`. */
228
+ interface ActionsUiAdapterShape {
229
+ openUri(uri: string, opts: {
230
+ isMap: boolean;
231
+ origin: ActionsUiOrigin;
232
+ }): void;
233
+ print(opts?: ActionsUiEffectContext): void;
234
+ alert?(message: string, opts: ActionsUiEffectContext & {
235
+ icon: number;
236
+ title?: string;
237
+ }): void;
238
+ gotoPage?(page: number, opts: ActionsUiEffectContext): void;
239
+ }
240
+ interface DefaultActionsUiAdapterOptions {
241
+ /**
242
+ * Per-handler overrides. Pass a FUNCTION for late binding (a binding's
243
+ * mutable handlers ref) — it is consulted on every effect, so a fresh
244
+ * closure never needs a reinstall.
245
+ */
246
+ overrides?: Partial<ActionsUiAdapterShape> | (() => Partial<ActionsUiAdapterShape> | undefined);
247
+ /** Navigation default for script `this.pageNum = n` requests. */
248
+ goToPage?: (page: number) => void;
249
+ }
250
+ declare const createDefaultActionsUiAdapter: (options?: DefaultActionsUiAdapterOptions) => ActionsUiAdapterShape;
251
+ //#endregion
219
252
  //#region src/painted-image.d.ts
220
253
  /** A browser image source whose object URL has an explicit lifetime. */
221
254
  interface ObjectUrlImageSource {
@@ -557,5 +590,31 @@ interface WheelSample {
557
590
  /** Zoom factor for a ctrl/cmd wheel event (the caller decides zoom vs pan). */
558
591
  declare function wheelZoomFactor(e: WheelSample): number;
559
592
  //#endregion
560
- export { type AnchorTarget, type AnchoredPlacement, type AnchoredPoint, type AnchoredPosition, type AnchoredRect, type AttachSelectionHandleOptions, type ClipboardSelectionSource, type ObjectUrlImageSource, type PaintedImageCallbacks, type PickFileOptions, type SelectionClipboardOptions, type SelectionHandleSession, type StageGestureHost, type StageGestureOptions, type StageGestureSink, type StagePointerKind, type StageSurfaceHost, type StageSurfaceHub, type StageSurfaceOptions, type StageSurfaceSample, type StageWheelSample, type SvgCursorOptions, type ViewProjector, type WebPlatformFeedback, type WheelSample, attachSelectionHandle, bindPaintedImage, computeReleaseVelocity, copySelection, createStageGestureController, createStageSurface, observeClientGeometry, pickFile, pickImageFile, positionAnchoredRect, projectAnchoredTarget, sanitizeExternalUri, saveFile, svgCursor, vibrationFeedback, wheelZoomFactor, wireSelectionClipboard, wkFeedback };
593
+ //#region src/byte-store.d.ts
594
+ /**
595
+ * A bytes-by-id store over IndexedDB — the browser's answer to "keep these
596
+ * blobs for me". Structurally the store port a plugin declares for its own
597
+ * persistence (e.g. `StampLibraryStore` in `@embedpdf/plugin-stamp`); declared
598
+ * here as a twin so this package stays plugin-free, per the layering law.
599
+ *
600
+ * IndexedDB rather than localStorage: a library or an image is binary, and a
601
+ * localStorage string store caps at a few MB. One database, one object store,
602
+ * keys are the caller's ids, values are the bytes as stored.
603
+ */
604
+ interface ByteStore {
605
+ list(): Promise<Array<{
606
+ id: string;
607
+ bytes: Uint8Array;
608
+ }>>;
609
+ put(id: string, bytes: Uint8Array): Promise<void>;
610
+ delete(id: string): Promise<void>;
611
+ }
612
+ interface IndexedDbByteStoreOptions {
613
+ /** Object store name inside the database. Default `'bytes'`. */
614
+ storeName?: string;
615
+ }
616
+ /** Open (creating on first use) one IndexedDB object store keyed by id. */
617
+ declare function indexedDbByteStore(dbName: string, opts?: IndexedDbByteStoreOptions): ByteStore;
618
+ //#endregion
619
+ export { type ActionsUiAdapterShape, type ActionsUiEffectContext, type ActionsUiOrigin, type AnchorTarget, type AnchoredPlacement, type AnchoredPoint, type AnchoredPosition, type AnchoredRect, type AttachSelectionHandleOptions, type ByteStore, type ClipboardSelectionSource, type DefaultActionsUiAdapterOptions, type IndexedDbByteStoreOptions, type ObjectUrlImageSource, type PaintedImageCallbacks, type PickFileOptions, type SelectionClipboardOptions, type SelectionHandleSession, type StageGestureHost, type StageGestureOptions, type StageGestureSink, type StagePointerKind, type StageSurfaceHost, type StageSurfaceHub, type StageSurfaceOptions, type StageSurfaceSample, type StageWheelSample, type SvgCursorOptions, type ViewProjector, type WebPlatformFeedback, type WheelSample, attachSelectionHandle, bindPaintedImage, computeReleaseVelocity, copySelection, createDefaultActionsUiAdapter, createStageGestureController, createStageSurface, indexedDbByteStore, observeClientGeometry, pickFile, pickImageFile, positionAnchoredRect, projectAnchoredTarget, sanitizeExternalUri, saveFile, svgCursor, vibrationFeedback, wheelZoomFactor, wireSelectionClipboard, wkFeedback };
561
620
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -234,6 +234,56 @@ function sanitizeExternalUri(uri, allowedSchemes = DEFAULT_ALLOWED_SCHEMES) {
234
234
  }
235
235
  }
236
236
  //#endregion
237
+ //#region src/actions-ui.ts
238
+ /**
239
+ * The DEFAULT actions UI adapter — the origin×phase visibility matrix plus
240
+ * the browser fallbacks, written ONCE here so every framework binding
241
+ * (react, angular, …) ships the SAME policy instead of forking it per
242
+ * framework. Types are structural twins of `@embedpdf/plugin-actions`'
243
+ * adapter contract (declared here so this package stays plugin-free, per
244
+ * the layering law); assignability is checked where a binding installs it.
245
+ *
246
+ * The matrix (defaults only — an embedder override receives EVERY effect
247
+ * with its context attached and decides for itself):
248
+ * - URIs open through `sanitizeExternalUri` in a new tab (the dispatcher
249
+ * already policy-gated the node; blocked schemes are dropped here).
250
+ * - Print: hover/lifecycle-origin requests never open the dialog; user
251
+ * requests fall back to `globalThis.print`. The `doc.print` AUTHORITY
252
+ * gate is upstream in the plugin and not overridable.
253
+ * - Alert: document-open nags (lifecycle origin, boot phase) never reach
254
+ * `window.alert` — the boot-nag gap, closed.
255
+ * - gotoPage: delegates to the binding-supplied navigator (the stage).
256
+ */
257
+ const createDefaultActionsUiAdapter = (options = {}) => {
258
+ const overridesOf = () => typeof options.overrides === "function" ? options.overrides() : options.overrides;
259
+ return {
260
+ openUri: (uri, opts) => {
261
+ const current = overridesOf();
262
+ if (current?.openUri) {
263
+ current.openUri(uri, opts);
264
+ return;
265
+ }
266
+ const href = sanitizeExternalUri(uri);
267
+ if (href && typeof window !== "undefined") window.open(href, "_blank", "noopener,noreferrer");
268
+ },
269
+ print: (opts) => {
270
+ const current = overridesOf();
271
+ if (current?.print) current.print(opts);
272
+ else if (opts && opts.origin !== "user") {} else if (typeof globalThis.print === "function") globalThis.print();
273
+ },
274
+ alert: (message, opts) => {
275
+ const current = overridesOf();
276
+ if (current?.alert) current.alert(message, opts);
277
+ else if (opts.origin === "lifecycle" || opts.phase === "boot") {} else if (typeof globalThis.alert === "function") globalThis.alert(message);
278
+ },
279
+ gotoPage: (page, opts) => {
280
+ const current = overridesOf();
281
+ if (current?.gotoPage) current.gotoPage(page, opts);
282
+ else options.goToPage?.(page);
283
+ }
284
+ };
285
+ };
286
+ //#endregion
237
287
  //#region src/painted-image.ts
238
288
  /**
239
289
  * Bind a raster source to an <img> without ever painting its incomplete-image
@@ -1069,6 +1119,44 @@ function createStageSurface(el, stage, options = {}) {
1069
1119
  };
1070
1120
  }
1071
1121
  //#endregion
1072
- export { attachSelectionHandle, bindPaintedImage, computeReleaseVelocity, copySelection, createStageGestureController, createStageSurface, observeClientGeometry, pickFile, pickImageFile, positionAnchoredRect, projectAnchoredTarget, sanitizeExternalUri, saveFile, svgCursor, vibrationFeedback, wheelZoomFactor, wireSelectionClipboard, wkFeedback };
1122
+ //#region src/byte-store.ts
1123
+ /** Open (creating on first use) one IndexedDB object store keyed by id. */
1124
+ function indexedDbByteStore(dbName, opts = {}) {
1125
+ const storeName = opts.storeName ?? "bytes";
1126
+ const open = () => new Promise((resolve, reject) => {
1127
+ const request = indexedDB.open(dbName, 1);
1128
+ request.onupgradeneeded = () => {
1129
+ if (!request.result.objectStoreNames.contains(storeName)) request.result.createObjectStore(storeName);
1130
+ };
1131
+ request.onsuccess = () => resolve(request.result);
1132
+ request.onerror = () => reject(request.error ?? /* @__PURE__ */ new Error("indexedDB.open failed"));
1133
+ });
1134
+ const run = async (mode, body) => {
1135
+ const db = await open();
1136
+ try {
1137
+ return await new Promise((resolve, reject) => {
1138
+ const request = body(db.transaction(storeName, mode).objectStore(storeName));
1139
+ request.onsuccess = () => resolve(request.result);
1140
+ request.onerror = () => reject(request.error ?? /* @__PURE__ */ new Error("indexedDB request failed"));
1141
+ });
1142
+ } finally {
1143
+ db.close();
1144
+ }
1145
+ };
1146
+ return {
1147
+ list: async () => {
1148
+ const keys = await run("readonly", (store) => store.getAllKeys());
1149
+ const values = await run("readonly", (store) => store.getAll());
1150
+ return keys.map((key, i) => ({
1151
+ id: String(key),
1152
+ bytes: new Uint8Array(values[i])
1153
+ }));
1154
+ },
1155
+ put: (id, bytes) => run("readwrite", (store) => store.put(new Uint8Array(bytes), id)).then(() => void 0),
1156
+ delete: (id) => run("readwrite", (store) => store.delete(id)).then(() => void 0)
1157
+ };
1158
+ }
1159
+ //#endregion
1160
+ export { attachSelectionHandle, bindPaintedImage, computeReleaseVelocity, copySelection, createDefaultActionsUiAdapter, createStageGestureController, createStageSurface, indexedDbByteStore, observeClientGeometry, pickFile, pickImageFile, positionAnchoredRect, projectAnchoredTarget, sanitizeExternalUri, saveFile, svgCursor, vibrationFeedback, wheelZoomFactor, wireSelectionClipboard, wkFeedback };
1073
1161
 
1074
1162
  //# sourceMappingURL=index.js.map