@inkbar/vue 0.7.0 → 0.9.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 (79) hide show
  1. package/README.md +14 -2
  2. package/dist/components/InkFormAlert.js +7 -0
  3. package/dist/components/InkFormAlert.js.map +1 -0
  4. package/dist/components/InkFormAlert.vue.d.ts +16 -0
  5. package/dist/components/InkFormAlert.vue.d.ts.map +1 -0
  6. package/dist/components/InkFormAlert.vue_vue_type_script_setup_true_lang.js +90 -0
  7. package/dist/components/InkFormAlert.vue_vue_type_script_setup_true_lang.js.map +1 -0
  8. package/dist/components/InkHighlightMenu.js.map +1 -1
  9. package/dist/components/InkHighlightMenu.vue.d.ts.map +1 -1
  10. package/dist/components/InkHighlightMenu.vue_vue_type_script_setup_true_lang.js +67 -65
  11. package/dist/components/InkHighlightMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  12. package/dist/components/InkRoot.js.map +1 -1
  13. package/dist/components/InkRoot.vue.d.ts +24 -5
  14. package/dist/components/InkRoot.vue.d.ts.map +1 -1
  15. package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js +197 -148
  16. package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js.map +1 -1
  17. package/dist/components/InkShapeMenu.js.map +1 -1
  18. package/dist/components/InkShapeMenu.vue.d.ts.map +1 -1
  19. package/dist/components/InkShapeMenu.vue_vue_type_script_setup_true_lang.js +58 -56
  20. package/dist/components/InkShapeMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  21. package/dist/components/InkSignFieldPopover.js +7 -0
  22. package/dist/components/InkSignFieldPopover.js.map +1 -0
  23. package/dist/components/InkSignFieldPopover.vue.d.ts +13 -0
  24. package/dist/components/InkSignFieldPopover.vue.d.ts.map +1 -0
  25. package/dist/components/InkSignFieldPopover.vue_vue_type_script_setup_true_lang.js +116 -0
  26. package/dist/components/InkSignFieldPopover.vue_vue_type_script_setup_true_lang.js.map +1 -0
  27. package/dist/components/InkSignatureDialog.js.map +1 -1
  28. package/dist/components/InkSignatureDialog.vue.d.ts +10 -1
  29. package/dist/components/InkSignatureDialog.vue.d.ts.map +1 -1
  30. package/dist/components/InkSignatureDialog.vue_vue_type_script_setup_true_lang.js +9 -2
  31. package/dist/components/InkSignatureDialog.vue_vue_type_script_setup_true_lang.js.map +1 -1
  32. package/dist/components/InkSignatureMenu.js.map +1 -1
  33. package/dist/components/InkSignatureMenu.vue.d.ts.map +1 -1
  34. package/dist/components/InkSignatureMenu.vue_vue_type_script_setup_true_lang.js +69 -154
  35. package/dist/components/InkSignatureMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
  36. package/dist/components/InkToolButton.js.map +1 -1
  37. package/dist/components/InkToolButton.vue.d.ts.map +1 -1
  38. package/dist/components/InkToolButton.vue_vue_type_script_setup_true_lang.js +39 -36
  39. package/dist/components/InkToolButton.vue_vue_type_script_setup_true_lang.js.map +1 -1
  40. package/dist/components/InkToolbarButton.js +7 -0
  41. package/dist/components/InkToolbarButton.js.map +1 -0
  42. package/dist/components/InkToolbarButton.vue.d.ts +22 -0
  43. package/dist/components/InkToolbarButton.vue.d.ts.map +1 -0
  44. package/dist/components/InkToolbarButton.vue_vue_type_script_setup_true_lang.js +32 -0
  45. package/dist/components/InkToolbarButton.vue_vue_type_script_setup_true_lang.js.map +1 -0
  46. package/dist/components/InkViewport.js.map +1 -1
  47. package/dist/components/InkViewport.vue.d.ts.map +1 -1
  48. package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js +123 -91
  49. package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js.map +1 -1
  50. package/dist/components/SignatureForm.js.map +1 -1
  51. package/dist/components/SignatureForm.vue.d.ts +5 -1
  52. package/dist/components/SignatureForm.vue.d.ts.map +1 -1
  53. package/dist/components/SignatureForm.vue_vue_type_script_setup_true_lang.js +64 -57
  54. package/dist/components/SignatureForm.vue_vue_type_script_setup_true_lang.js.map +1 -1
  55. package/dist/components/SignatureMenuPanel.js +7 -0
  56. package/dist/components/SignatureMenuPanel.js.map +1 -0
  57. package/dist/components/SignatureMenuPanel.vue.d.ts +15 -0
  58. package/dist/components/SignatureMenuPanel.vue.d.ts.map +1 -0
  59. package/dist/components/SignatureMenuPanel.vue_vue_type_script_setup_true_lang.js +116 -0
  60. package/dist/components/SignatureMenuPanel.vue_vue_type_script_setup_true_lang.js.map +1 -0
  61. package/dist/composables/useForm.d.ts +18 -0
  62. package/dist/composables/useForm.d.ts.map +1 -0
  63. package/dist/composables/useForm.js +17 -0
  64. package/dist/composables/useForm.js.map +1 -0
  65. package/dist/composables/useRegisteredTool.d.ts +21 -0
  66. package/dist/composables/useRegisteredTool.d.ts.map +1 -0
  67. package/dist/composables/useRegisteredTool.js +25 -0
  68. package/dist/composables/useRegisteredTool.js.map +1 -0
  69. package/dist/composables/useToolOptions.d.ts +8 -0
  70. package/dist/composables/useToolOptions.d.ts.map +1 -1
  71. package/dist/composables/useToolOptions.js +10 -5
  72. package/dist/composables/useToolOptions.js.map +1 -1
  73. package/dist/context.d.ts +12 -1
  74. package/dist/context.d.ts.map +1 -1
  75. package/dist/context.js.map +1 -1
  76. package/dist/index.d.ts +3 -0
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +29 -27
  79. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"InkRoot.js","names":["_sfc_main","InkRoot_vue_vue_type_script_setup_true_lang_default","InkRoot_default"],"sources":["../../src/components/InkRoot.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n createMemorySignatureStore,\n createSignatureLibrary,\n InkError,\n openDocument,\n readonly,\n writable,\n} from '@inkbar/core'\nimport {\n createPluginHost,\n createSearchController,\n createToolOptions,\n handleFindKey,\n pageSelectionText,\n viewerSearchOf,\n cssVariableDefaults,\n FONT_FAMILIES,\n SIGNATURE_FONTS,\n trackToolStyle,\n} from '@inkbar/core/dom'\nimport { Primitive } from 'reka-ui'\nimport {\n computed,\n onBeforeUnmount,\n onUnmounted,\n onMounted,\n onUpdated,\n ref,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nimport { provideInkContext, type InkHistory, type InkStatus } from '../context'\nimport { createRefHistory } from '../ref-history'\nimport { useReadable } from '../use-readable'\n\nimport type {\n Annotation,\n AnnotationChange,\n AnnotationDefaults,\n DocumentSource,\n InkDocument,\n PdfAssets,\n SignatureStore,\n} from '@inkbar/core'\nimport type {\n DecorateAnnotation,\n InkPlugin,\n PluginHost,\n SearchController,\n Tool,\n ToolController,\n ToolId,\n ToolStyle,\n Viewport,\n ZoomValue,\n} from '@inkbar/core/dom'\n\nconst props = withDefaults(\n defineProps<{\n src: DocumentSource | null\n assets: PdfAssets\n password?: string | undefined\n /** Colour defaults. Without it, the theme's CSS variables on the root element apply. */\n defaults?: AnnotationDefaults | undefined\n /**\n * Pass (with v-model) to put annotations under the host's control. The mode is fixed when a\n * document opens: passing or dropping this prop later takes effect on the next open.\n */\n annotations?: Annotation[] | undefined\n tool?: ToolId | undefined\n /**\n * Host tools, added to the built-ins; one with a built-in's id replaces it. Read when a\n * document opens.\n */\n tools?: Tool[] | undefined\n /**\n * Plugins, set up once when the root is created; a later change to this prop is not\n * applied. Their tools join `tools`, their decoration and page layers apply to every\n * document, and their commands are placed with `InkCommand` or `useCommand`.\n */\n plugins?: InkPlugin[] | undefined\n /**\n * Adds `data-*` attributes, classes and a screen-reader description to each annotation's\n * element (see `DecorateAnnotation`). Decorations re-apply whenever the annotations change\n * and when this prop changes, without rebuilding the viewer. Pass a new function when its\n * output would change for any other reason.\n */\n decorateAnnotation?: DecorateAnnotation | undefined\n /**\n * The font families text boxes offer, replacing the PDF standard families\n * (`FONT_FAMILIES`). Fonts beyond those are the PDF writer's to embed.\n */\n fonts?: string[] | undefined\n /**\n * Where saved signatures live. Default: memory, gone on reload.\n * `createLocalSignatureStore` keeps them in the browser; a host can keep them anywhere.\n * A new store takes effect at once, for the menus and the `signature` tool alike.\n */\n signatures?: SignatureStore | undefined\n /** The handwriting fonts a typed signature offers; the host loads them. */\n signatureFonts?: string[] | undefined\n page?: number | undefined\n zoom?: ZoomValue | undefined\n /** Undo history. Defaults to on for uncontrolled, off for controlled. */\n history?: boolean | undefined\n asChild?: boolean\n }>(),\n {\n password: undefined,\n defaults: undefined,\n annotations: undefined,\n tool: undefined,\n tools: undefined,\n plugins: undefined,\n decorateAnnotation: undefined,\n fonts: undefined,\n signatures: undefined,\n signatureFonts: undefined,\n page: undefined,\n zoom: undefined,\n history: undefined,\n asChild: false,\n }\n)\n\nconst emit = defineEmits<{\n 'update:annotations': [next: Annotation[]]\n change: [change: AnnotationChange]\n 'update:tool': [tool: ToolId]\n 'update:page': [page: number]\n 'update:zoom': [zoom: ZoomValue]\n ready: [doc: InkDocument]\n error: [error: InkError]\n activate: [id: string]\n}>()\n\ntype TestHookElement = HTMLElement & { __inkDocument?: InkDocument | undefined }\n\n// A template ref on Primitive is a component instance; the context needs its element.\nconst primitive = useTemplateRef<{ $el: unknown }>('primitive')\nconst rootEl = shallowRef<HTMLElement | null>(null)\nfunction syncRootEl(): void {\n const el = primitive.value?.$el\n rootEl.value = el instanceof HTMLElement ? el : null\n}\n\nconst document = shallowRef<InkDocument | null>(null)\n/** Overrides the document's status while opening, and when opening itself failed. */\nconst override = shallowRef<InkStatus | null>(null)\nconst idle: InkStatus = { state: 'idle' }\nconst documentStatus = useReadable<InkStatus>(() => document.value?.status ?? null, idle)\nconst status = computed<InkStatus>(() => override.value ?? documentStatus.value)\nconst annotationList = useReadable<readonly Annotation[]>(\n () => document.value?.annotations.list ?? null,\n []\n)\nconst selection = useReadable<readonly string[]>(\n () => document.value?.annotations.selection ?? null,\n []\n)\nconst viewport = shallowRef<Viewport | null>(null)\nconst toolController = shallowRef<ToolController | null>(null)\nconst internalTool = ref<ToolId>(props.tool ?? 'select-text')\nconst activated = ref<string | null>(null)\n\nconst controlled = computed(() => props.annotations !== undefined)\n\nfunction setActivated(id: string | null): void {\n activated.value = id\n if (id) emit('activate', id)\n}\n\nconst noop = () => {}\n\n/** Signed URLs change; the key does not. Bytes and Blobs are their own identity. */\nfunction identity(src: DocumentSource | null): unknown {\n if (src === null) return null\n if (typeof src === 'string') return src\n if ('key' in src) return src.key\n return src\n}\n\nfunction setTestHook(doc: InkDocument | undefined): void {\n if (import.meta.env.DEV && rootEl.value)\n (rootEl.value as TestHookElement).__inkDocument = doc\n}\n\nlet generation = 0\nfunction release(): void {\n // Cleared first, so the plugins close their stores while the document is still alive.\n const doc = document.value\n document.value = null\n doc?.destroy()\n setTestHook(undefined)\n}\n\nasync function open(): Promise<void> {\n const gen = ++generation\n const src = props.src\n release()\n refHistory.clear()\n if (src === null) {\n override.value = null\n return\n }\n override.value = { state: 'loading' }\n syncRootEl()\n let doc: InkDocument\n try {\n doc = await openDocument(src, {\n assets: props.assets,\n password: props.password,\n defaults:\n props.defaults ?? (rootEl.value ? cssVariableDefaults(rootEl.value) : undefined),\n // Controlled hosts get the ref history below; core's own stack stays off.\n history: controlled.value ? false : (props.history ?? true),\n annotations: controlled.value\n ? {\n mode: 'controlled',\n initial: props.annotations ?? [],\n onChange: (next, change) => {\n emit('update:annotations', next)\n emit('change', change)\n },\n }\n : { mode: 'uncontrolled' },\n })\n } catch (cause) {\n if (gen !== generation) return\n const error =\n cause instanceof InkError\n ? cause\n : new InkError(\n 'InvalidPdf',\n cause instanceof Error ? cause.message : String(cause),\n {},\n cause\n )\n override.value = { state: 'error', error }\n emit('error', error)\n return\n }\n if (gen !== generation) {\n doc.destroy()\n return\n }\n // The prop may have changed while the file loaded, when there was no store to apply it to.\n if (doc.annotations.mode === 'controlled' && props.annotations !== undefined)\n doc.annotations.setControlledValue(props.annotations)\n document.value = doc\n override.value = null\n setTestHook(doc)\n const s = doc.status.get()\n if (s.state === 'ready') emit('ready', doc)\n else if (s.state === 'error') emit('error', s.error)\n}\n\nconst refHistory = createRefHistory({\n source: () => props.annotations,\n apply: (list) => document.value?.annotations.replaceAll(list, 'history'),\n enabled: computed(() => controlled.value && props.history === true),\n store: () =>\n document.value?.annotations.mode === 'controlled' ? document.value.annotations : null,\n})\nconst coreCanUndo = useReadable(() => document.value?.history.canUndo ?? null, false)\nconst coreCanRedo = useReadable(() => document.value?.history.canRedo ?? null, false)\nconst inkHistory: InkHistory = {\n canUndo: computed(() =>\n controlled.value ? refHistory.canUndo.value : coreCanUndo.value\n ),\n canRedo: computed(() =>\n controlled.value ? refHistory.canRedo.value : coreCanRedo.value\n ),\n undo: () => (controlled.value ? refHistory.undo() : document.value?.history.undo()),\n redo: () => (controlled.value ? refHistory.redo() : document.value?.history.redo()),\n clear: () => (controlled.value ? refHistory.clear() : document.value?.history.clear()),\n batch: (fn) => {\n if (controlled.value) refHistory.batch(fn)\n else if (document.value) document.value.history.batch(fn)\n else fn()\n },\n track: (store) =>\n controlled.value\n ? refHistory.track(store)\n : (document.value?.history.track(store) ?? noop),\n react: (fn) =>\n controlled.value ? refHistory.react(fn) : (document.value?.history.react(fn) ?? noop),\n}\n\n/*\n * One plugin host for the root's life, built once mounted so that no `setup` runs on the\n * server, where nothing would clean it up. Until then `pluginHost` is null, and InkCommand\n * renders its command disabled. The host follows `hostDocument`, which is set after `document`\n * (a sync watch): when the host reads `inkHistory` for a new document, it is that document's\n * history.\n */\nconst hostDocument = writable<InkDocument | null>(null)\nwatch(document, (doc) => hostDocument.set(doc), { flush: 'sync' })\nconst viewportEl = shallowRef<HTMLElement | null>(null)\nconst hostRoot = writable<HTMLElement | null>(null)\nwatch(viewportEl, (el) => hostRoot.set(el), { flush: 'sync' })\nconst hostActivated = writable<string | null>(null)\nwatch(activated, (id) => hostActivated.set(id), { flush: 'sync' })\nconst pluginHost = shallowRef<PluginHost | null>(null)\n/** One search controller for the root's life, built with the plugin host that shares it. */\nconst search = shallowRef<SearchController | null>(null)\nfunction setUpPlugins(): void {\n const controller = createSearchController({\n document: readonly(hostDocument),\n viewport: () => viewport.value,\n })\n search.value = controller\n pluginHost.value = createPluginHost({\n plugins: props.plugins ?? [],\n document: readonly(hostDocument),\n history: () => inkHistory,\n activated: readonly(hostActivated),\n // As in `createViewer`: an id not in the open document is ignored.\n setActivated: (id) => {\n if (id === null || document.value?.annotations.get(id)) setActivated(id)\n },\n root: readonly(hostRoot),\n decorate: () => props.decorateAnnotation,\n viewport: () => viewport.value,\n search: viewerSearchOf(controller),\n })\n}\n\n// Reka's typed props stop at its own; listeners go through a bound object.\nconst rootListeners = { onKeydown }\n\n/** Ctrl/Cmd+F while focus is in the root and a find bar is mounted; else the browser's. */\nfunction onKeydown(e: KeyboardEvent): void {\n const controller = search.value\n const root = e.currentTarget\n if (controller && root instanceof HTMLElement)\n handleFindKey(e, controller, () => pageSelectionText(root))\n}\n\n/** The document's tool style; it batches through `inkHistory`, whichever mode is on. */\nconst toolStyle = shallowRef<ToolStyle | null>(null)\nlet setStyleTool: ((id: ToolId) => void) | undefined\nwatch(\n document,\n (doc) => {\n if (!doc) {\n toolStyle.value = null\n setStyleTool = undefined\n return\n }\n const tracker = trackToolStyle({\n store: doc.annotations,\n history: { batch: (fn) => inkHistory.batch(fn) },\n // The plugins' tools too, so a plugin tool's style group applies (the host is set by now:\n // it is built on mount, before the first document opens).\n tools: [...(props.tools ?? []), ...(pluginHost.value?.tools ?? [])],\n tool: internalTool.value,\n })\n setStyleTool = (id) => tracker.setTool(id)\n toolStyle.value = tracker.toolStyle\n },\n // Sync: the style is in place before InkViewport's watcher mounts the engine with it.\n { immediate: true, flush: 'sync' }\n)\nwatch(internalTool, (id) => setStyleTool?.(id))\n\n// Plugins and the document on the client only: on the server InkRoot renders its empty slot.\n// The plugins first, so the first document opens with their stores and reactions.\nonMounted(() => {\n syncRootEl()\n // A plugin whose setup throws still leaves the document to open; the error then goes to\n // Vue's error handling (`onErrorCaptured`, `app.config.errorHandler`).\n try {\n setUpPlugins()\n } finally {\n void open()\n }\n})\nonUpdated(syncRootEl)\n\n// Separate sources, so a new `{ url, key }` object with the same key compares equal.\nwatch([() => identity(props.src), () => props.password], () => void open())\n\nwatch(\n () => props.annotations,\n (next) => {\n if (next && document.value?.annotations.mode === 'controlled')\n document.value.annotations.setControlledValue(next)\n }\n)\n\nwatch(\n () => props.tool,\n (t) => {\n if (t) internalTool.value = t\n }\n)\n\nfunction setTool(id: ToolId): void {\n // Picking the active tool again starts it afresh, as after a one-shot tool's use.\n const tc = toolController.value\n if (internalTool.value === id && tc?.active.get() === id) tc.set(id)\n internalTool.value = id\n emit('update:tool', id)\n}\n\nonBeforeUnmount(() => {\n generation++\n release()\n})\n\n// After the children: InkViewport's engine, and the plugin layers with it, are gone by now, as\n// in `createViewer`, so no layer `destroy` runs after the plugins' cleanups.\nonUnmounted(() => {\n pluginHost.value?.destroy()\n pluginHost.value = null\n search.value?.destroy()\n search.value = null\n})\n\nconst signatures = computed(() =>\n createSignatureLibrary(props.signatures ?? createMemorySignatureStore())\n)\nwatch(signatures, (lib) => void lib.refresh(), { immediate: true })\n/** Tool options last as long as the root; the tool style is per document. */\nconst toolOptions = createToolOptions()\n\nprovideInkContext({\n assets: computed(() => props.assets),\n document,\n status,\n annotations: annotationList,\n selection,\n viewport,\n tools: toolController,\n tool: internalTool,\n setTool,\n hostTools: computed(() => props.tools),\n decorateAnnotation: computed(() => props.decorateAnnotation),\n fonts: computed(() => props.fonts ?? FONT_FAMILIES),\n toolOptions,\n signatures,\n signatureFonts: computed(() => props.signatureFonts ?? SIGNATURE_FONTS),\n toolStyle,\n zoomModel: computed(() => props.zoom),\n pageModel: computed(() => props.page),\n reportZoom: (z) => emit('update:zoom', z),\n reportPage: (p) => emit('update:page', p),\n activated,\n setActivated,\n pluginHost,\n search,\n viewportEl,\n history: inkHistory,\n rootEl,\n})\n\n// `history` is what `useHistory()` returns inside the root, for hosts that hold a template ref:\n// a controlled host calls `history.clear()` after loading its saved list.\ndefineExpose({ document, status, rootEl, history: inkHistory })\n</script>\n\n<template>\n <Primitive\n ref=\"primitive\"\n :as-child=\"props.asChild\"\n as=\"div\"\n data-ink-root\n :data-state=\"status.state\"\n v-bind=\"rootListeners\"\n >\n <slot :status=\"status\" :document=\"document\" />\n </Primitive>\n</template>\n"],"mappings":""}
1
+ {"version":3,"file":"InkRoot.js","names":["_sfc_main","InkRoot_vue_vue_type_script_setup_true_lang_default","InkRoot_default"],"sources":["../../src/components/InkRoot.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n createMemorySignatureStore,\n createSignatureLibrary,\n InkError,\n openDocument,\n readonly,\n writable,\n} from '@inkbar/core'\nimport {\n attachHistoryKeys,\n createPluginHost,\n createSearchController,\n createToolOptions,\n handleFindKey,\n pageSelectionText,\n viewerSearchOf,\n cssVariableDefaults,\n FONT_FAMILIES,\n keepHistoryFocus,\n SIGNATURE_FONTS,\n trackToolStyle,\n unknownTool,\n} from '@inkbar/core/dom'\nimport { Primitive } from 'reka-ui'\nimport {\n computed,\n onBeforeUnmount,\n onUnmounted,\n onMounted,\n onUpdated,\n ref,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nimport { registeredToolIds } from '../composables/useRegisteredTool'\nimport { provideInkContext, type InkHistory, type InkStatus } from '../context'\nimport { createRefHistory } from '../ref-history'\nimport { useReadable } from '../use-readable'\n\nimport type {\n Annotation,\n AnnotationChange,\n AnnotationDefaults,\n DocumentSource,\n FieldsChange,\n FieldValues,\n FormAction,\n InkDocument,\n PdfAssets,\n SignatureStore,\n} from '@inkbar/core'\nimport type {\n DecorateAnnotation,\n InkPlugin,\n PluginHost,\n SearchController,\n Tool,\n ToolController,\n ToolId,\n ToolStyle,\n Viewport,\n ZoomValue,\n} from '@inkbar/core/dom'\n\nconst props = withDefaults(\n defineProps<{\n src: DocumentSource | null\n assets: PdfAssets\n password?: string | undefined\n /** Colour defaults. Without it, the theme's CSS variables on the root element apply. */\n defaults?: AnnotationDefaults | undefined\n /**\n * Pass (with v-model) to put annotations under the host's control. The mode is fixed when a\n * document opens: passing or dropping this prop later takes effect on the next open.\n */\n annotations?: Annotation[] | undefined\n /**\n * Pass (with `v-model:fields`) to put the form's field values under the host's control. A\n * commit shows at once and is reported after; the host's push wins. The mode is fixed when\n * a document opens, as for `annotations`.\n */\n fields?: FieldValues | undefined\n /** Tints fillable form fields. Default true. A change applies to the open document in place. */\n formHighlight?: boolean | undefined\n tool?: ToolId | undefined\n /**\n * The creation tools, such as `allTools()` or a pick of the tool factories. `select-text`\n * and `select` are always present; a tool with either id replaces it. They are read when a\n * document opens: a tool added later is usable from the next open, one removed stops at\n * once. When the active tool goes, the viewer switches to `select-text` and emits\n * `update:tool`. A controlled `tool` naming a missing tool is reported back as\n * `select-text` and is not applied again when the tool appears later. Each mounted control\n * for a missing tool logs its own `UnknownTool`.\n */\n tools?: Tool[] | undefined\n /**\n * Plugins, set up once when the root is created; a later change to this prop is not\n * applied. Their tools join `tools`, their decoration and page layers apply to every\n * document, and their commands are placed with `InkCommand` or `useCommand`.\n */\n plugins?: InkPlugin[] | undefined\n /**\n * Adds `data-*` attributes, classes and a screen-reader description to each annotation's\n * element (see `DecorateAnnotation`). Decorations re-apply whenever the annotations change\n * and when this prop changes, without rebuilding the viewer. Pass a new function when its\n * output would change for any other reason.\n */\n decorateAnnotation?: DecorateAnnotation | undefined\n /**\n * The font families text boxes offer, replacing the PDF standard families\n * (`FONT_FAMILIES`). Fonts beyond those are the PDF writer's to embed.\n */\n fonts?: string[] | undefined\n /**\n * Where saved signatures live. Default: memory, gone on reload.\n * `createLocalSignatureStore` keeps them in the browser; a host can keep them anywhere.\n * A new store takes effect at once, for the menus and the `signature` tool alike.\n */\n signatures?: SignatureStore | undefined\n /** The handwriting fonts a typed signature offers; the host loads them. */\n signatureFonts?: string[] | undefined\n page?: number | undefined\n zoom?: ZoomValue | undefined\n /** Undo history. Defaults to on for uncontrolled, off for controlled. */\n history?: boolean | undefined\n asChild?: boolean\n }>(),\n {\n password: undefined,\n defaults: undefined,\n annotations: undefined,\n fields: undefined,\n formHighlight: undefined,\n tool: undefined,\n tools: undefined,\n plugins: undefined,\n decorateAnnotation: undefined,\n fonts: undefined,\n signatures: undefined,\n signatureFonts: undefined,\n page: undefined,\n zoom: undefined,\n history: undefined,\n asChild: false,\n }\n)\n\nconst emit = defineEmits<{\n 'update:annotations': [next: Annotation[]]\n change: [change: AnnotationChange]\n /** Committed field values, in full, with what changed them. */\n 'update:fields': [next: FieldValues, change: FieldsChange]\n /** The form asked to submit, open a link, send mail, print or prompt. Inkbar does none. */\n 'form-action': [action: FormAction]\n 'update:tool': [tool: ToolId]\n 'update:page': [page: number]\n 'update:zoom': [zoom: ZoomValue]\n ready: [doc: InkDocument]\n /**\n * Opening failed, or later a form script failed or a signature field refused its signing.\n * An error from while the document opened comes after `ready`.\n */\n error: [error: InkError]\n activate: [id: string]\n}>()\n\ntype TestHookElement = HTMLElement & { __inkDocument?: InkDocument | undefined }\n\n// A template ref on Primitive is a component instance; the context needs its element.\nconst primitive = useTemplateRef<{ $el: unknown }>('primitive')\nconst rootEl = shallowRef<HTMLElement | null>(null)\nfunction syncRootEl(): void {\n const el = primitive.value?.$el\n rootEl.value = el instanceof HTMLElement ? el : null\n}\n\nconst document = shallowRef<InkDocument | null>(null)\n/** Overrides the document's status while opening, and when opening itself failed. */\nconst override = shallowRef<InkStatus | null>(null)\nconst idle: InkStatus = { state: 'idle' }\nconst documentStatus = useReadable<InkStatus>(() => document.value?.status ?? null, idle)\nconst status = computed<InkStatus>(() => override.value ?? documentStatus.value)\nconst annotationList = useReadable<readonly Annotation[]>(\n () => document.value?.annotations.list ?? null,\n []\n)\nconst selection = useReadable<readonly string[]>(\n () => document.value?.annotations.selection ?? null,\n []\n)\nconst viewport = shallowRef<Viewport | null>(null)\nconst toolController = shallowRef<ToolController | null>(null)\nconst internalTool = ref<ToolId>(props.tool ?? 'select-text')\nconst activated = ref<string | null>(null)\n\nconst controlled = computed(() => props.annotations !== undefined)\nconst fieldsControlled = computed(() => props.fields !== undefined)\n\nfunction setActivated(id: string | null): void {\n activated.value = id\n if (id) emit('activate', id)\n}\n\nconst noop = () => {}\n\n/** Signed URLs change; the key does not. Bytes and Blobs are their own identity. */\nfunction identity(src: DocumentSource | null): unknown {\n if (src === null) return null\n if (typeof src === 'string') return src\n if ('key' in src) return src.key\n return src\n}\n\nfunction setTestHook(doc: InkDocument | undefined): void {\n if (import.meta.env.DEV && rootEl.value)\n (rootEl.value as TestHookElement).__inkDocument = doc\n}\n\nlet generation = 0\nlet stopFormErrors: () => void = noop\nfunction release(): void {\n stopFormErrors()\n stopFormErrors = noop\n // Cleared first, so the plugins close their stores while the document is still alive.\n const doc = document.value\n document.value = null\n doc?.destroy()\n setTestHook(undefined)\n}\n\nasync function open(): Promise<void> {\n const gen = ++generation\n const src = props.src\n release()\n refHistory.clear()\n if (src === null) {\n override.value = null\n return\n }\n override.value = { state: 'loading' }\n syncRootEl()\n let doc: InkDocument\n try {\n doc = await openDocument(src, {\n assets: props.assets,\n password: props.password,\n defaults:\n props.defaults ?? (rootEl.value ? cssVariableDefaults(rootEl.value) : undefined),\n // Controlled hosts get the ref history below; core's own stack stays off.\n history: controlled.value ? false : (props.history ?? true),\n annotations: controlled.value\n ? {\n mode: 'controlled',\n initial: props.annotations ?? [],\n onChange: (next, change) => {\n emit('update:annotations', next)\n emit('change', change)\n },\n }\n : { mode: 'uncontrolled' },\n fields: fieldsControlled.value\n ? {\n mode: 'controlled',\n initial: props.fields ?? {},\n onChange: (next, change) => emit('update:fields', next, change),\n }\n : { mode: 'uncontrolled' },\n })\n } catch (cause) {\n if (gen !== generation) return\n const error =\n cause instanceof InkError\n ? cause\n : new InkError(\n 'InvalidPdf',\n cause instanceof Error ? cause.message : String(cause),\n {},\n cause\n )\n override.value = { state: 'error', error }\n emit('error', error)\n return\n }\n if (gen !== generation) {\n doc.destroy()\n return\n }\n // The prop may have changed while the file loaded, when there was no store to apply it to.\n if (doc.annotations.mode === 'controlled' && props.annotations !== undefined)\n doc.annotations.setControlledValue(props.annotations)\n // The same for the fields; a document whose fields opened uncontrolled ignores the push.\n if (props.fields !== undefined) doc.form.setControlledValue(props.fields)\n // A form script that fails leaves the form fillable; the failure goes to `error`. Subscribed\n // before anyone hears of the document, so the form replays the errors from while it opened\n // here, not to a listener added in `ready`; they are held until `ready` has gone out.\n let held: InkError[] | undefined = []\n stopFormErrors = doc.form.on('error', (e) => {\n if (held) held.push(e)\n else emit('error', e)\n })\n document.value = doc\n override.value = null\n setTestHook(doc)\n const s = doc.status.get()\n if (s.state === 'ready') emit('ready', doc)\n else if (s.state === 'error') emit('error', s.error)\n const early = held\n held = undefined\n if (gen === generation) for (const e of early) emit('error', e)\n}\n\nconst refHistory = createRefHistory({\n source: () => props.annotations,\n apply: (list) => document.value?.annotations.replaceAll(list, 'history'),\n enabled: computed(() => controlled.value && props.history === true),\n store: () =>\n document.value?.annotations.mode === 'controlled' ? document.value.annotations : null,\n})\nconst coreCanUndo = useReadable(() => document.value?.history.canUndo ?? null, false)\nconst coreCanRedo = useReadable(() => document.value?.history.canRedo ?? null, false)\nconst inkHistory: InkHistory = {\n canUndo: computed(() =>\n controlled.value ? refHistory.canUndo.value : coreCanUndo.value\n ),\n canRedo: computed(() =>\n controlled.value ? refHistory.canRedo.value : coreCanRedo.value\n ),\n undo: () => (controlled.value ? refHistory.undo() : document.value?.history.undo()),\n redo: () => (controlled.value ? refHistory.redo() : document.value?.history.redo()),\n clear: () => (controlled.value ? refHistory.clear() : document.value?.history.clear()),\n batch: (fn) => {\n if (controlled.value) refHistory.batch(fn)\n else if (document.value) document.value.history.batch(fn)\n else fn()\n },\n track: (store) =>\n controlled.value\n ? refHistory.track(store)\n : (document.value?.history.track(store) ?? noop),\n react: (fn) =>\n controlled.value ? refHistory.react(fn) : (document.value?.history.react(fn) ?? noop),\n}\n\n// The undo and redo keys anywhere in the root do what InkUndo and InkRedo do. When either\n// button undoes or redoes the last step and disables itself, focus goes back to the document.\n// The find key listens here too.\nwatch(\n rootEl,\n (el, _prev, onCleanup) => {\n if (!el) return\n const stopKeys = attachHistoryKeys(el, () => ({\n canUndo: inkHistory.canUndo.value,\n canRedo: inkHistory.canRedo.value,\n undo: inkHistory.undo,\n redo: inkHistory.redo,\n }))\n const stopFocus = keepHistoryFocus(el, () =>\n el.querySelector<HTMLElement>('[data-ink-scroll]')\n )\n // Not a template listener: Vue leaves those on the element when it unmounts.\n el.addEventListener('keydown', onKeydown)\n onCleanup(() => {\n stopKeys()\n stopFocus()\n el.removeEventListener('keydown', onKeydown)\n })\n },\n { immediate: true }\n)\n\n/*\n * One plugin host for the root's life, built once mounted so that no `setup` runs on the\n * server, where nothing would clean it up. Until then `pluginHost` is null, and InkCommand\n * renders its command disabled. The host follows `hostDocument`, which is set after `document`\n * (a sync watch): when the host reads `inkHistory` for a new document, it is that document's\n * history.\n */\nconst hostDocument = writable<InkDocument | null>(null)\nwatch(document, (doc) => hostDocument.set(doc), { flush: 'sync' })\nconst viewportEl = shallowRef<HTMLElement | null>(null)\nconst hostRoot = writable<HTMLElement | null>(null)\nwatch(viewportEl, (el) => hostRoot.set(el), { flush: 'sync' })\nconst hostActivated = writable<string | null>(null)\nwatch(activated, (id) => hostActivated.set(id), { flush: 'sync' })\nconst pluginHost = shallowRef<PluginHost | null>(null)\n/** One search controller for the root's life, built with the plugin host that shares it. */\nconst search = shallowRef<SearchController | null>(null)\nfunction setUpPlugins(): void {\n const controller = createSearchController({\n document: readonly(hostDocument),\n viewport: () => viewport.value,\n })\n search.value = controller\n pluginHost.value = createPluginHost({\n plugins: props.plugins ?? [],\n document: readonly(hostDocument),\n history: () => inkHistory,\n activated: readonly(hostActivated),\n // As in `createViewer`: an id not in the open document is ignored.\n setActivated: (id) => {\n if (id === null || document.value?.annotations.get(id)) setActivated(id)\n },\n root: readonly(hostRoot),\n decorate: () => props.decorateAnnotation,\n viewport: () => viewport.value,\n search: viewerSearchOf(controller),\n })\n}\n\n/** Ctrl/Cmd+F while focus is in the root and a find bar is mounted; else the browser's. */\nfunction onKeydown(e: KeyboardEvent): void {\n const controller = search.value\n const root = e.currentTarget\n if (controller && root instanceof HTMLElement)\n handleFindKey(e, controller, () => pageSelectionText(root))\n}\n\n/** The document's tool style; it batches through `inkHistory`, whichever mode is on. */\nconst toolStyle = shallowRef<ToolStyle | null>(null)\nlet setStyleTool: ((id: ToolId) => void) | undefined\nwatch(\n document,\n (doc) => {\n if (!doc) {\n toolStyle.value = null\n setStyleTool = undefined\n return\n }\n const tracker = trackToolStyle({\n store: doc.annotations,\n history: { batch: (fn) => inkHistory.batch(fn) },\n // The plugins' tools too, so a plugin tool's style group applies (the host is set by now:\n // it is built on mount, before the first document opens).\n tools: [...(props.tools ?? []), ...(pluginHost.value?.tools ?? [])],\n tool: internalTool.value,\n })\n setStyleTool = (id) => tracker.setTool(id)\n toolStyle.value = tracker.toolStyle\n },\n // Sync: the style is in place before InkViewport's watcher mounts the engine with it.\n { immediate: true, flush: 'sync' }\n)\nwatch(internalTool, (id) => setStyleTool?.(id))\n\n// Plugins and the document on the client only: on the server InkRoot renders its empty slot.\n// The plugins first, so the first document opens with their stores and reactions.\nonMounted(() => {\n syncRootEl()\n // A plugin whose setup throws still leaves the document to open; the error then goes to\n // Vue's error handling (`onErrorCaptured`, `app.config.errorHandler`).\n try {\n setUpPlugins()\n } finally {\n mounted.value = true\n void open()\n }\n})\nonUpdated(syncRootEl)\n\n// Separate sources, so a new `{ url, key }` object with the same key compares equal.\nwatch([() => identity(props.src), () => props.password], () => void open())\n\nwatch(\n () => props.annotations,\n (next) => {\n if (next && document.value?.annotations.mode === 'controlled')\n document.value.annotations.setControlledValue(next)\n }\n)\n\nwatch(\n () => props.fields,\n (next) => {\n if (next) document.value?.form.setControlledValue(next)\n }\n)\n\n/*\n * The tools are known once the plugins are set up on mount. A tool id nobody registered is\n * logged as `UnknownTool`; as the active tool, from a `tool` prop or because it left `tools`,\n * it falls back to `select-text`, reported through `update:tool`. A controlled `tool` that\n * stays on the missing id is not applied again.\n */\nconst mounted = ref(false)\n/** The ids of the tools the current viewer was built with; InkViewport sets them. */\nconst openedToolIds = shallowRef<readonly ToolId[] | null>(null)\nconst toolIds = computed(() =>\n registeredToolIds(props.tools, pluginHost.value, openedToolIds.value)\n)\nconst isRegistered = (id: ToolId): boolean => !mounted.value || toolIds.value.includes(id)\nconst logUnknownTool = (id: ToolId): void => console.error(unknownTool(id, toolIds.value))\n\nfunction fallBack(id: ToolId): void {\n logUnknownTool(id)\n internalTool.value = 'select-text'\n emit('update:tool', 'select-text')\n}\n\nwatch(\n () => props.tool,\n (t) => {\n if (!t) return\n if (isRegistered(t)) internalTool.value = t\n else fallBack(t)\n }\n)\nwatch([mounted, toolIds], () => {\n if (!isRegistered(internalTool.value)) fallBack(internalTool.value)\n})\n\nfunction setTool(id: ToolId): void {\n // As the tool controller does: a missing tool is logged and nothing changes.\n if (!isRegistered(id)) {\n logUnknownTool(id)\n return\n }\n // Picking the active tool again starts it afresh, as after a one-shot tool's use.\n const tc = toolController.value\n if (internalTool.value === id && tc?.active.get() === id) tc.set(id)\n internalTool.value = id\n emit('update:tool', id)\n}\n\nonBeforeUnmount(() => {\n generation++\n release()\n})\n\n// After the children: InkViewport's engine, and the plugin layers with it, are gone by now, as\n// in `createViewer`, so no layer `destroy` runs after the plugins' cleanups.\nonUnmounted(() => {\n pluginHost.value?.destroy()\n pluginHost.value = null\n search.value?.destroy()\n search.value = null\n})\n\nconst signatures = computed(() =>\n createSignatureLibrary(props.signatures ?? createMemorySignatureStore())\n)\nwatch(signatures, (lib) => void lib.refresh(), { immediate: true })\n/** Tool options last as long as the root; the tool style is per document. */\nconst toolOptions = createToolOptions()\n\nprovideInkContext({\n assets: computed(() => props.assets),\n document,\n status,\n annotations: annotationList,\n selection,\n viewport,\n tools: toolController,\n tool: internalTool,\n setTool,\n hostTools: computed(() => props.tools),\n openedToolIds,\n decorateAnnotation: computed(() => props.decorateAnnotation),\n fonts: computed(() => props.fonts ?? FONT_FAMILIES),\n toolOptions,\n signatures,\n signatureFonts: computed(() => props.signatureFonts ?? SIGNATURE_FONTS),\n toolStyle,\n zoomModel: computed(() => props.zoom),\n pageModel: computed(() => props.page),\n reportZoom: (z) => emit('update:zoom', z),\n reportPage: (p) => emit('update:page', p),\n activated,\n setActivated,\n pluginHost,\n search,\n viewportEl,\n history: inkHistory,\n rootEl,\n formHighlight: computed(() => props.formHighlight),\n reportFormAction: (a) => emit('form-action', a),\n reportError: (e) => emit('error', e),\n})\n\n// `history` is what `useHistory()` returns inside the root, for hosts that hold a template ref:\n// a controlled host calls `history.clear()` after loading its saved list.\ndefineExpose({ document, status, rootEl, history: inkHistory })\n</script>\n\n<template>\n <Primitive\n ref=\"primitive\"\n :as-child=\"props.asChild\"\n as=\"div\"\n data-ink-root\n :data-state=\"status.state\"\n >\n <slot :status=\"status\" :document=\"document\" />\n </Primitive>\n</template>\n"],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { InkError, Annotation, AnnotationChange, AnnotationDefaults, DocumentSource, InkDocument, PdfAssets, SignatureStore } from '@inkbar/core';
1
+ import { InkError, Annotation, AnnotationChange, AnnotationDefaults, DocumentSource, FieldsChange, FieldValues, FormAction, InkDocument, PdfAssets, SignatureStore } from '@inkbar/core';
2
2
  import { InkHistory, InkStatus } from '../context';
3
3
  import { DecorateAnnotation, InkPlugin, Tool, ToolId, ZoomValue } from '@inkbar/core/dom';
4
4
  type __VLS_Props = {
@@ -12,10 +12,23 @@ type __VLS_Props = {
12
12
  * document opens: passing or dropping this prop later takes effect on the next open.
13
13
  */
14
14
  annotations?: Annotation[] | undefined;
15
+ /**
16
+ * Pass (with `v-model:fields`) to put the form's field values under the host's control. A
17
+ * commit shows at once and is reported after; the host's push wins. The mode is fixed when
18
+ * a document opens, as for `annotations`.
19
+ */
20
+ fields?: FieldValues | undefined;
21
+ /** Tints fillable form fields. Default true. A change applies to the open document in place. */
22
+ formHighlight?: boolean | undefined;
15
23
  tool?: ToolId | undefined;
16
24
  /**
17
- * Host tools, added to the built-ins; one with a built-in's id replaces it. Read when a
18
- * document opens.
25
+ * The creation tools, such as `allTools()` or a pick of the tool factories. `select-text`
26
+ * and `select` are always present; a tool with either id replaces it. They are read when a
27
+ * document opens: a tool added later is usable from the next open, one removed stops at
28
+ * once. When the active tool goes, the viewer switches to `select-text` and emits
29
+ * `update:tool`. A controlled `tool` naming a missing tool is reported back as
30
+ * `select-text` and is not applied again when the tool appears later. Each mounted control
31
+ * for a missing tool logs its own `UnknownTool`.
19
32
  */
20
33
  tools?: Tool[] | undefined;
21
34
  /**
@@ -63,6 +76,7 @@ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {
63
76
  rootEl: import('vue').ShallowRef<HTMLElement | null, HTMLElement | null>;
64
77
  history: InkHistory;
65
78
  }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
79
+ ready: (doc: InkDocument) => any;
66
80
  "update:annotations": (next: ({
67
81
  type: "highlight" | "underline" | "strikeout" | "squiggly";
68
82
  quads: {
@@ -469,13 +483,15 @@ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {
469
483
  custom?: Record<string, unknown> | undefined;
470
484
  })[]) => any;
471
485
  change: (change: AnnotationChange) => any;
486
+ "update:fields": (next: Readonly<Record<string, import('@inkbar/core').FieldValue>>, change: FieldsChange) => any;
487
+ "form-action": (action: FormAction) => any;
472
488
  "update:tool": (tool: ToolId) => any;
473
489
  "update:page": (page: number) => any;
474
490
  "update:zoom": (zoom: ZoomValue) => any;
475
- ready: (doc: InkDocument) => any;
476
491
  error: (error: InkError) => any;
477
492
  activate: (id: string) => any;
478
493
  }, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
494
+ onReady?: (doc: InkDocument) => any;
479
495
  "onUpdate:annotations"?: (next: ({
480
496
  type: "highlight" | "underline" | "strikeout" | "squiggly";
481
497
  quads: {
@@ -882,10 +898,11 @@ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {
882
898
  custom?: Record<string, unknown> | undefined;
883
899
  })[]) => any;
884
900
  onChange?: (change: AnnotationChange) => any;
901
+ "onUpdate:fields"?: (next: Readonly<Record<string, import('@inkbar/core').FieldValue>>, change: FieldsChange) => any;
902
+ "onForm-action"?: (action: FormAction) => any;
885
903
  "onUpdate:tool"?: (tool: ToolId) => any;
886
904
  "onUpdate:page"?: (page: number) => any;
887
905
  "onUpdate:zoom"?: (zoom: ZoomValue) => any;
888
- onReady?: (doc: InkDocument) => any;
889
906
  onError?: (error: InkError) => any;
890
907
  onActivate?: (id: string) => any;
891
908
  }>, {
@@ -1297,6 +1314,8 @@ declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {
1297
1314
  intent?: "FreeText" | "FreeTextCallout" | "FreeTextTypeWriter" | "LineArrow" | "LineDimension" | "PolygonCloud" | "PolygonDimension" | "PolyLineDimension" | (string & {}) | undefined;
1298
1315
  custom?: Record<string, unknown> | undefined;
1299
1316
  })[] | undefined;
1317
+ fields: Readonly<Record<string, import('@inkbar/core').FieldValue>> | undefined;
1318
+ formHighlight: boolean | undefined;
1300
1319
  tool: ToolId | undefined;
1301
1320
  tools: Tool<object>[] | undefined;
1302
1321
  plugins: InkPlugin[] | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"InkRoot.vue.d.ts","sourceRoot":"","sources":["../../src/components/InkRoot.vue"],"names":[],"mappings":"AA+dA,OAAO,EAGL,QAAQ,EAIT,MAAM,cAAc,CAAA;AA0BrB,OAAO,EAAqB,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAA;AAI/E,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,SAAS,EACT,cAAc,EACf,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EAGT,IAAI,EAEJ,MAAM,EAGN,SAAS,EACV,MAAM,kBAAkB,CAAA;AAGzB,KAAK,WAAW,GAAG;IACf,GAAG,EAAE,cAAc,GAAG,IAAI,CAAA;IAC1B,MAAM,EAAE,SAAS,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;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,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -1,12 +1,13 @@
1
1
  import { provideInkContext as e } from "../context.js";
2
- import { useReadable as t } from "../use-readable.js";
3
- import { createRefHistory as n } from "../ref-history.js";
4
- import { computed as r, createBlock as i, defineComponent as a, mergeProps as ee, onBeforeUnmount as te, onMounted as ne, onUnmounted as re, onUpdated as ie, openBlock as ae, ref as o, renderSlot as s, shallowRef as c, unref as l, useTemplateRef as u, watch as d, withCtx as f } from "vue";
5
- import { InkError as p, createMemorySignatureStore as oe, createSignatureLibrary as se, openDocument as ce, readonly as m, writable as h } from "@inkbar/core";
6
- import { FONT_FAMILIES as le, SIGNATURE_FONTS as ue, createPluginHost as de, createSearchController as g, createToolOptions as fe, cssVariableDefaults as pe, handleFindKey as me, pageSelectionText as _, trackToolStyle as v, viewerSearchOf as y } from "@inkbar/core/dom";
7
- import { Primitive as b } from "reka-ui";
2
+ import { registeredToolIds as t } from "../composables/useRegisteredTool.js";
3
+ import { useReadable as n } from "../use-readable.js";
4
+ import { createRefHistory as r } from "../ref-history.js";
5
+ import { computed as i, createBlock as a, defineComponent as o, onBeforeUnmount as ee, onMounted as te, onUnmounted as ne, onUpdated as re, openBlock as ie, ref as s, renderSlot as ae, shallowRef as c, unref as oe, useTemplateRef as l, watch as u, withCtx as se } from "vue";
6
+ import { InkError as d, createMemorySignatureStore as ce, createSignatureLibrary as le, openDocument as ue, readonly as f, writable as p } from "@inkbar/core";
7
+ import { FONT_FAMILIES as de, SIGNATURE_FONTS as fe, attachHistoryKeys as pe, createPluginHost as me, createSearchController as he, createToolOptions as ge, cssVariableDefaults as _e, handleFindKey as ve, keepHistoryFocus as ye, pageSelectionText as be, trackToolStyle as xe, unknownTool as Se, viewerSearchOf as m } from "@inkbar/core/dom";
8
+ import { Primitive as Ce } from "reka-ui";
8
9
  //#region src/components/InkRoot.vue?vue&type=script&setup=true&lang.ts
9
- var x = /*@__PURE__*/ a({
10
+ var h = /*@__PURE__*/ o({
10
11
  __name: "InkRoot",
11
12
  props: {
12
13
  src: {},
@@ -14,6 +15,11 @@ var x = /*@__PURE__*/ a({
14
15
  password: { default: void 0 },
15
16
  defaults: { default: void 0 },
16
17
  annotations: { default: void 0 },
18
+ fields: { default: void 0 },
19
+ formHighlight: {
20
+ type: Boolean,
21
+ default: void 0
22
+ },
17
23
  tool: { default: void 0 },
18
24
  tools: { default: void 0 },
19
25
  plugins: { default: void 0 },
@@ -38,6 +44,8 @@ var x = /*@__PURE__*/ a({
38
44
  emits: [
39
45
  "update:annotations",
40
46
  "change",
47
+ "update:fields",
48
+ "form-action",
41
49
  "update:tool",
42
50
  "update:page",
43
51
  "update:zoom",
@@ -45,201 +53,242 @@ var x = /*@__PURE__*/ a({
45
53
  "error",
46
54
  "activate"
47
55
  ],
48
- setup(a, { expose: x, emit: he }) {
49
- let S = a, C = he, w = u("primitive"), T = c(null);
50
- function E() {
51
- let e = w.value?.$el;
52
- T.value = e instanceof HTMLElement ? e : null;
56
+ setup(o, { expose: h, emit: g }) {
57
+ let _ = o, v = g, y = l("primitive"), b = c(null);
58
+ function x() {
59
+ let e = y.value?.$el;
60
+ b.value = e instanceof HTMLElement ? e : null;
53
61
  }
54
- let D = c(null), O = c(null), k = t(() => D.value?.status ?? null, { state: "idle" }), A = r(() => O.value ?? k.value), j = t(() => D.value?.annotations.list ?? null, []), M = t(() => D.value?.annotations.selection ?? null, []), N = c(null), P = c(null), F = o(S.tool ?? "select-text"), I = o(null), L = r(() => S.annotations !== void 0);
55
- function R(e) {
56
- I.value = e, e && C("activate", e);
62
+ let S = c(null), C = c(null), we = n(() => S.value?.status ?? null, { state: "idle" }), w = i(() => C.value ?? we.value), Te = n(() => S.value?.annotations.list ?? null, []), Ee = n(() => S.value?.annotations.selection ?? null, []), T = c(null), E = c(null), D = s(_.tool ?? "select-text"), O = s(null), k = i(() => _.annotations !== void 0), De = i(() => _.fields !== void 0);
63
+ function A(e) {
64
+ O.value = e, e && v("activate", e);
57
65
  }
58
- let z = () => {};
59
- function ge(e) {
66
+ let j = () => {};
67
+ function Oe(e) {
60
68
  return e === null ? null : typeof e == "string" ? e : "key" in e ? e.key : e;
61
69
  }
62
- let B = 0;
63
- function V() {
64
- let e = D.value;
65
- D.value = null, e?.destroy();
70
+ let M = 0, N = j;
71
+ function P() {
72
+ N(), N = j;
73
+ let e = S.value;
74
+ S.value = null, e?.destroy();
66
75
  }
67
- async function H() {
68
- let e = ++B, t = S.src;
69
- if (V(), U.clear(), t === null) {
70
- O.value = null;
76
+ async function F() {
77
+ let e = ++M, t = _.src;
78
+ if (P(), I.clear(), t === null) {
79
+ C.value = null;
71
80
  return;
72
81
  }
73
- O.value = { state: "loading" }, E();
82
+ C.value = { state: "loading" }, x();
74
83
  let n;
75
84
  try {
76
- n = await ce(t, {
77
- assets: S.assets,
78
- password: S.password,
79
- defaults: S.defaults ?? (T.value ? pe(T.value) : void 0),
80
- history: L.value ? !1 : S.history ?? !0,
81
- annotations: L.value ? {
85
+ n = await ue(t, {
86
+ assets: _.assets,
87
+ password: _.password,
88
+ defaults: _.defaults ?? (b.value ? _e(b.value) : void 0),
89
+ history: k.value ? !1 : _.history ?? !0,
90
+ annotations: k.value ? {
82
91
  mode: "controlled",
83
- initial: S.annotations ?? [],
92
+ initial: _.annotations ?? [],
84
93
  onChange: (e, t) => {
85
- C("update:annotations", e), C("change", t);
94
+ v("update:annotations", e), v("change", t);
86
95
  }
96
+ } : { mode: "uncontrolled" },
97
+ fields: De.value ? {
98
+ mode: "controlled",
99
+ initial: _.fields ?? {},
100
+ onChange: (e, t) => v("update:fields", e, t)
87
101
  } : { mode: "uncontrolled" }
88
102
  });
89
103
  } catch (t) {
90
- if (e !== B) return;
91
- let n = t instanceof p ? t : new p("InvalidPdf", t instanceof Error ? t.message : String(t), {}, t);
92
- O.value = {
104
+ if (e !== M) return;
105
+ let n = t instanceof d ? t : new d("InvalidPdf", t instanceof Error ? t.message : String(t), {}, t);
106
+ C.value = {
93
107
  state: "error",
94
108
  error: n
95
- }, C("error", n);
109
+ }, v("error", n);
96
110
  return;
97
111
  }
98
- if (e !== B) {
112
+ if (e !== M) {
99
113
  n.destroy();
100
114
  return;
101
115
  }
102
- n.annotations.mode === "controlled" && S.annotations !== void 0 && n.annotations.setControlledValue(S.annotations), D.value = n, O.value = null;
103
- let r = n.status.get();
104
- r.state === "ready" ? C("ready", n) : r.state === "error" && C("error", r.error);
116
+ n.annotations.mode === "controlled" && _.annotations !== void 0 && n.annotations.setControlledValue(_.annotations), _.fields !== void 0 && n.form.setControlledValue(_.fields);
117
+ let r = [];
118
+ N = n.form.on("error", (e) => {
119
+ r ? r.push(e) : v("error", e);
120
+ }), S.value = n, C.value = null;
121
+ let i = n.status.get();
122
+ i.state === "ready" ? v("ready", n) : i.state === "error" && v("error", i.error);
123
+ let a = r;
124
+ if (r = void 0, e === M) for (let e of a) v("error", e);
105
125
  }
106
- let U = n({
107
- source: () => S.annotations,
108
- apply: (e) => D.value?.annotations.replaceAll(e, "history"),
109
- enabled: r(() => L.value && S.history === !0),
110
- store: () => D.value?.annotations.mode === "controlled" ? D.value.annotations : null
111
- }), _e = t(() => D.value?.history.canUndo ?? null, !1), ve = t(() => D.value?.history.canRedo ?? null, !1), W = {
112
- canUndo: r(() => L.value ? U.canUndo.value : _e.value),
113
- canRedo: r(() => L.value ? U.canRedo.value : ve.value),
114
- undo: () => L.value ? U.undo() : D.value?.history.undo(),
115
- redo: () => L.value ? U.redo() : D.value?.history.redo(),
116
- clear: () => L.value ? U.clear() : D.value?.history.clear(),
126
+ let I = r({
127
+ source: () => _.annotations,
128
+ apply: (e) => S.value?.annotations.replaceAll(e, "history"),
129
+ enabled: i(() => k.value && _.history === !0),
130
+ store: () => S.value?.annotations.mode === "controlled" ? S.value.annotations : null
131
+ }), ke = n(() => S.value?.history.canUndo ?? null, !1), Ae = n(() => S.value?.history.canRedo ?? null, !1), L = {
132
+ canUndo: i(() => k.value ? I.canUndo.value : ke.value),
133
+ canRedo: i(() => k.value ? I.canRedo.value : Ae.value),
134
+ undo: () => k.value ? I.undo() : S.value?.history.undo(),
135
+ redo: () => k.value ? I.redo() : S.value?.history.redo(),
136
+ clear: () => k.value ? I.clear() : S.value?.history.clear(),
117
137
  batch: (e) => {
118
- L.value ? U.batch(e) : D.value ? D.value.history.batch(e) : e();
138
+ k.value ? I.batch(e) : S.value ? S.value.history.batch(e) : e();
119
139
  },
120
- track: (e) => L.value ? U.track(e) : D.value?.history.track(e) ?? z,
121
- react: (e) => L.value ? U.react(e) : D.value?.history.react(e) ?? z
122
- }, G = h(null);
123
- d(D, (e) => G.set(e), { flush: "sync" });
124
- let K = c(null), q = h(null);
125
- d(K, (e) => q.set(e), { flush: "sync" });
126
- let J = h(null);
127
- d(I, (e) => J.set(e), { flush: "sync" });
128
- let Y = c(null), X = c(null);
129
- function ye() {
130
- let e = g({
131
- document: m(G),
132
- viewport: () => N.value
140
+ track: (e) => k.value ? I.track(e) : S.value?.history.track(e) ?? j,
141
+ react: (e) => k.value ? I.react(e) : S.value?.history.react(e) ?? j
142
+ };
143
+ u(b, (e, t, n) => {
144
+ if (!e) return;
145
+ let r = pe(e, () => ({
146
+ canUndo: L.canUndo.value,
147
+ canRedo: L.canRedo.value,
148
+ undo: L.undo,
149
+ redo: L.redo
150
+ })), i = ye(e, () => e.querySelector("[data-ink-scroll]"));
151
+ e.addEventListener("keydown", W), n(() => {
152
+ r(), i(), e.removeEventListener("keydown", W);
153
+ });
154
+ }, { immediate: !0 });
155
+ let R = p(null);
156
+ u(S, (e) => R.set(e), { flush: "sync" });
157
+ let z = c(null), B = p(null);
158
+ u(z, (e) => B.set(e), { flush: "sync" });
159
+ let V = p(null);
160
+ u(O, (e) => V.set(e), { flush: "sync" });
161
+ let H = c(null), U = c(null);
162
+ function je() {
163
+ let e = he({
164
+ document: f(R),
165
+ viewport: () => T.value
133
166
  });
134
- X.value = e, Y.value = de({
135
- plugins: S.plugins ?? [],
136
- document: m(G),
137
- history: () => W,
138
- activated: m(J),
167
+ U.value = e, H.value = me({
168
+ plugins: _.plugins ?? [],
169
+ document: f(R),
170
+ history: () => L,
171
+ activated: f(V),
139
172
  setActivated: (e) => {
140
- (e === null || D.value?.annotations.get(e)) && R(e);
173
+ (e === null || S.value?.annotations.get(e)) && A(e);
141
174
  },
142
- root: m(q),
143
- decorate: () => S.decorateAnnotation,
144
- viewport: () => N.value,
145
- search: y(e)
175
+ root: f(B),
176
+ decorate: () => _.decorateAnnotation,
177
+ viewport: () => T.value,
178
+ search: m(e)
146
179
  });
147
180
  }
148
- let be = { onKeydown: xe };
149
- function xe(e) {
150
- let t = X.value, n = e.currentTarget;
151
- t && n instanceof HTMLElement && me(e, t, () => _(n));
181
+ function W(e) {
182
+ let t = U.value, n = e.currentTarget;
183
+ t && n instanceof HTMLElement && ve(e, t, () => be(n));
152
184
  }
153
- let Z = c(null), Q;
154
- d(D, (e) => {
185
+ let G = c(null), K;
186
+ u(S, (e) => {
155
187
  if (!e) {
156
- Z.value = null, Q = void 0;
188
+ G.value = null, K = void 0;
157
189
  return;
158
190
  }
159
- let t = v({
191
+ let t = xe({
160
192
  store: e.annotations,
161
- history: { batch: (e) => W.batch(e) },
162
- tools: [...S.tools ?? [], ...Y.value?.tools ?? []],
163
- tool: F.value
193
+ history: { batch: (e) => L.batch(e) },
194
+ tools: [..._.tools ?? [], ...H.value?.tools ?? []],
195
+ tool: D.value
164
196
  });
165
- Q = (e) => t.setTool(e), Z.value = t.toolStyle;
197
+ K = (e) => t.setTool(e), G.value = t.toolStyle;
166
198
  }, {
167
199
  immediate: !0,
168
200
  flush: "sync"
169
- }), d(F, (e) => Q?.(e)), ne(() => {
170
- E();
201
+ }), u(D, (e) => K?.(e)), te(() => {
202
+ x();
171
203
  try {
172
- ye();
204
+ je();
173
205
  } finally {
174
- H();
206
+ q.value = !0, F();
175
207
  }
176
- }), ie(E), d([() => ge(S.src), () => S.password], () => void H()), d(() => S.annotations, (e) => {
177
- e && D.value?.annotations.mode === "controlled" && D.value.annotations.setControlledValue(e);
178
- }), d(() => S.tool, (e) => {
179
- e && (F.value = e);
208
+ }), re(x), u([() => Oe(_.src), () => _.password], () => void F()), u(() => _.annotations, (e) => {
209
+ e && S.value?.annotations.mode === "controlled" && S.value.annotations.setControlledValue(e);
210
+ }), u(() => _.fields, (e) => {
211
+ e && S.value?.form.setControlledValue(e);
180
212
  });
181
- function Se(e) {
182
- let t = P.value;
183
- F.value === e && t?.active.get() === e && t.set(e), F.value = e, C("update:tool", e);
213
+ let q = s(!1), J = c(null), Y = i(() => t(_.tools, H.value, J.value)), X = (e) => !q.value || Y.value.includes(e), Z = (e) => console.error(Se(e, Y.value));
214
+ function Q(e) {
215
+ Z(e), D.value = "select-text", v("update:tool", "select-text");
184
216
  }
185
- te(() => {
186
- B++, V();
187
- }), re(() => {
188
- Y.value?.destroy(), Y.value = null, X.value?.destroy(), X.value = null;
217
+ u(() => _.tool, (e) => {
218
+ e && (X(e) ? D.value = e : Q(e));
219
+ }), u([q, Y], () => {
220
+ X(D.value) || Q(D.value);
189
221
  });
190
- let $ = r(() => se(S.signatures ?? oe()));
191
- d($, (e) => void e.refresh(), { immediate: !0 });
192
- let Ce = fe();
222
+ function Me(e) {
223
+ if (!X(e)) {
224
+ Z(e);
225
+ return;
226
+ }
227
+ let t = E.value;
228
+ D.value === e && t?.active.get() === e && t.set(e), D.value = e, v("update:tool", e);
229
+ }
230
+ ee(() => {
231
+ M++, P();
232
+ }), ne(() => {
233
+ H.value?.destroy(), H.value = null, U.value?.destroy(), U.value = null;
234
+ });
235
+ let $ = i(() => le(_.signatures ?? ce()));
236
+ u($, (e) => void e.refresh(), { immediate: !0 });
237
+ let Ne = ge();
193
238
  return e({
194
- assets: r(() => S.assets),
195
- document: D,
196
- status: A,
197
- annotations: j,
198
- selection: M,
199
- viewport: N,
200
- tools: P,
201
- tool: F,
202
- setTool: Se,
203
- hostTools: r(() => S.tools),
204
- decorateAnnotation: r(() => S.decorateAnnotation),
205
- fonts: r(() => S.fonts ?? le),
206
- toolOptions: Ce,
239
+ assets: i(() => _.assets),
240
+ document: S,
241
+ status: w,
242
+ annotations: Te,
243
+ selection: Ee,
244
+ viewport: T,
245
+ tools: E,
246
+ tool: D,
247
+ setTool: Me,
248
+ hostTools: i(() => _.tools),
249
+ openedToolIds: J,
250
+ decorateAnnotation: i(() => _.decorateAnnotation),
251
+ fonts: i(() => _.fonts ?? de),
252
+ toolOptions: Ne,
207
253
  signatures: $,
208
- signatureFonts: r(() => S.signatureFonts ?? ue),
209
- toolStyle: Z,
210
- zoomModel: r(() => S.zoom),
211
- pageModel: r(() => S.page),
212
- reportZoom: (e) => C("update:zoom", e),
213
- reportPage: (e) => C("update:page", e),
214
- activated: I,
215
- setActivated: R,
216
- pluginHost: Y,
217
- search: X,
218
- viewportEl: K,
219
- history: W,
220
- rootEl: T
221
- }), x({
222
- document: D,
223
- status: A,
224
- rootEl: T,
225
- history: W
226
- }), (e, t) => (ae(), i(l(b), ee({
254
+ signatureFonts: i(() => _.signatureFonts ?? fe),
255
+ toolStyle: G,
256
+ zoomModel: i(() => _.zoom),
257
+ pageModel: i(() => _.page),
258
+ reportZoom: (e) => v("update:zoom", e),
259
+ reportPage: (e) => v("update:page", e),
260
+ activated: O,
261
+ setActivated: A,
262
+ pluginHost: H,
263
+ search: U,
264
+ viewportEl: z,
265
+ history: L,
266
+ rootEl: b,
267
+ formHighlight: i(() => _.formHighlight),
268
+ reportFormAction: (e) => v("form-action", e),
269
+ reportError: (e) => v("error", e)
270
+ }), h({
271
+ document: S,
272
+ status: w,
273
+ rootEl: b,
274
+ history: L
275
+ }), (e, t) => (ie(), a(oe(Ce), {
227
276
  ref_key: "primitive",
228
- ref: w,
229
- "as-child": S.asChild,
277
+ ref: y,
278
+ "as-child": _.asChild,
230
279
  as: "div",
231
280
  "data-ink-root": "",
232
- "data-state": A.value.state
233
- }, be), {
234
- default: f(() => [s(e.$slots, "default", {
235
- status: A.value,
236
- document: D.value
281
+ "data-state": w.value.state
282
+ }, {
283
+ default: se(() => [ae(e.$slots, "default", {
284
+ status: w.value,
285
+ document: S.value
237
286
  })]),
238
287
  _: 3
239
- }, 16, ["as-child", "data-state"]));
288
+ }, 8, ["as-child", "data-state"]));
240
289
  }
241
290
  });
242
291
  //#endregion
243
- export { x as default };
292
+ export { h as default };
244
293
 
245
294
  //# sourceMappingURL=InkRoot.vue_vue_type_script_setup_true_lang.js.map