@inkbar/vue 0.5.0 → 0.6.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 (39) hide show
  1. package/README.md +20 -2
  2. package/dist/components/InkCommand.js +7 -0
  3. package/dist/components/InkCommand.js.map +1 -0
  4. package/dist/components/InkCommand.vue.d.ts +23 -0
  5. package/dist/components/InkCommand.vue.d.ts.map +1 -0
  6. package/dist/components/InkCommand.vue_vue_type_script_setup_true_lang.js +51 -0
  7. package/dist/components/InkCommand.vue_vue_type_script_setup_true_lang.js.map +1 -0
  8. package/dist/components/InkPageInput.js.map +1 -1
  9. package/dist/components/InkPageInput.vue.d.ts.map +1 -1
  10. package/dist/components/InkPageInput.vue_vue_type_script_setup_true_lang.js +1 -1
  11. package/dist/components/InkPageInput.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 +8 -1
  14. package/dist/components/InkRoot.vue.d.ts.map +1 -1
  15. package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js +141 -104
  16. package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js.map +1 -1
  17. package/dist/components/InkToolButton.js.map +1 -1
  18. package/dist/components/InkToolButton.vue.d.ts.map +1 -1
  19. package/dist/components/InkToolButton.vue_vue_type_script_setup_true_lang.js +36 -35
  20. package/dist/components/InkToolButton.vue_vue_type_script_setup_true_lang.js.map +1 -1
  21. package/dist/components/InkViewport.js.map +1 -1
  22. package/dist/components/InkViewport.vue.d.ts.map +1 -1
  23. package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js +5 -2
  24. package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js.map +1 -1
  25. package/dist/composables/useCommand.d.ts +23 -0
  26. package/dist/composables/useCommand.d.ts.map +1 -0
  27. package/dist/composables/useCommand.js +22 -0
  28. package/dist/composables/useCommand.js.map +1 -0
  29. package/dist/context.d.ts +15 -4
  30. package/dist/context.d.ts.map +1 -1
  31. package/dist/context.js.map +1 -1
  32. package/dist/index.d.ts +4 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +27 -25
  35. package/dist/ref-history.d.ts +12 -3
  36. package/dist/ref-history.d.ts.map +1 -1
  37. package/dist/ref-history.js +27 -16
  38. package/dist/ref-history.js.map +1 -1
  39. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"InkViewport.vue.d.ts","sourceRoot":"","sources":["../../src/components/InkViewport.vue"],"names":[],"mappings":"AAmUA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EACV,UAAU,EAIV,YAAY,EAEb,MAAM,kBAAkB,CAAA;AAGzB,KAAK,WAAW,GAAG;IACf,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,iCAAiC;IACjC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAC;AAMJ,KAAK,WAAW,GAAG;IACjB,OAAO,CAAC,IAAI,OAAO,CAAA;IACnB,KAAK,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAA;IAC3C,KAAK,CAAC,IAAI,OAAO,CAAA;IACjB,UAAU,CAAC,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAA;IAChD,wFAAwF;IACxF,YAAY,CAAC,CAAC,KAAK,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAA;CACjE,CAAC;AA6TF,QAAA,MAAM,UAAU;;;;;6EAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO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C,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -49,6 +49,7 @@ var T = ["data-state"], E = {
49
49
  buffer: A.buffer,
50
50
  tool: M.tool.value,
51
51
  ...M.hostTools.value ? { tools: M.hostTools.value } : {},
52
+ ...M.pluginHost.value ? { plugins: M.pluginHost.value } : {},
52
53
  decorateAnnotation: (e) => M.decorateAnnotation.value?.(e),
53
54
  ...M.toolStyle.value ? { toolStyle: M.toolStyle.value } : {},
54
55
  toolHistory: { batch: (e) => M.history.batch(e) },
@@ -95,7 +96,7 @@ var T = ["data-state"], E = {
95
96
  });
96
97
  }
97
98
  return m(() => {
98
- S([() => M.document.value, () => M.status.value.state], G, { immediate: !0 });
99
+ M.viewportEl.value = N.value, S([() => M.document.value, () => M.status.value.state], G, { immediate: !0 });
99
100
  }), S(() => M.decorateAnnotation.value, () => L.value?.redecorate()), S(() => M.zoomModel.value, (e) => {
100
101
  let t = L.value?.viewport;
101
102
  t && e !== void 0 && e !== t.zoom.get() && t.setZoom(e);
@@ -112,7 +113,9 @@ var T = ["data-state"], E = {
112
113
  })), p(() => {
113
114
  let e = !!j.annotation;
114
115
  L.value && e !== z && W({ customAnnotations: e });
115
- }), f(U), (e, r) => (h(), o("div", {
116
+ }), f(() => {
117
+ U(), M.viewportEl.value === N.value && (M.viewportEl.value = null);
118
+ }), (e, r) => (h(), o("div", {
116
119
  class: "ink-viewport-root",
117
120
  "data-ink-viewport-root": "",
118
121
  "data-state": F.value
@@ -1 +1 @@
1
- {"version":3,"file":"InkViewport.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_renderSlot","_createTextVNode","_createElementVNode","_toDisplayString","_createCommentVNode","_Fragment","_renderList","_createBlock","InkPage","_createSlots","_withCtx","_mergeProps","InkPage_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","InkViewport_vue_vue_type_script_setup_true_lang_default","props","__props","slots","useSlots","ctx","injectInkContext","scroll","useTemplateRef","pages","shallowRef","state","computed","error","engine","build","custom","stops","lastReportedZoom","lastReportedPage","teardown","stop","rebuild","e","opts","setup","doc","el","first","mountViewer","a","fn","id","vp","tc","reportZoom","z","reportPage","p","page","err","onMounted","watch","t","m","r","gap","buffer","onBeforeUpdate","next","onBeforeUnmount","openBlock","createElementBlock","renderSlot","_ctx","_cache","createTextVNode","createElementVNode","toDisplayString","createCommentVNode","Fragment","renderList","createBlock","createSlots","withCtx","mergeProps","slotProps"],"sources":["../../src/components/InkViewport.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * The scroll element is handed to core's `mountViewer`, which builds the viewport, the page\n * layers, the tool controller and the keyboard shortcuts in it; Vue never renders children\n * into it. The engine reports each page host it mounts, and InkPage components rendered here\n * (they render nothing in place) teleport the page-error and custom-annotation slots into them.\n *\n * Two-way zoom and page: the viewport's own changes are reported through the context, and\n * the host's v-model values are applied only when they differ from the viewport's state, so\n * the echo of a reported value does nothing.\n */\nimport { mountViewer } from '@inkbar/core/dom'\nimport {\n computed,\n onBeforeUnmount,\n onBeforeUpdate,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nimport { injectInkContext } from '../context'\n\nimport InkPage from './InkPage.vue'\n\nimport type { AnnotationSlotProps } from './annotation-slot'\nimport type { InkError } from '@inkbar/core'\nimport type {\n LayoutMode,\n PageMount,\n ToolId,\n ViewerEngine,\n ViewRotation,\n ZoomValue,\n} from '@inkbar/core/dom'\n\nconst props = withDefaults(\n defineProps<{\n mode?: LayoutMode\n rotation?: ViewRotation\n /** Gap between pages, CSS px. */\n gap?: number\n /** Pages kept mounted either side of the visible ones. */\n buffer?: number\n }>(),\n { mode: 'continuous', rotation: 0, gap: 16, buffer: 2 }\n)\n\nconst slots = defineSlots<{\n loading?(): unknown\n error?(props: { error: InkError }): unknown\n empty?(): unknown\n annotation?(props: AnnotationSlotProps): unknown\n /** Shown inside a page that failed to render. The rest of the document stays usable. */\n 'page-error'?(props: { error: InkError; page: number }): unknown\n}>()\n\nconst ctx = injectInkContext()\nconst scroll = useTemplateRef<HTMLElement>('scroll')\n\ninterface MountedPage {\n /** The engine build the host belongs to; part of the InkPage key. */\n build: number\n page: number\n host: HTMLElement\n mount: PageMount\n error: InkError | null\n /** Whether the build that mounted the page renders the annotation slot. */\n custom: boolean\n}\n/** Page hosts, mounts and errors the engine reported; InkPage renders Teleports for them. */\nconst pages = shallowRef<MountedPage[]>([])\n\nconst state = computed(() => ctx.status.value.state)\nconst error = computed<InkError | null>(() =>\n ctx.status.value.state === 'error' ? ctx.status.value.error : null\n)\n\nconst engine = shallowRef<ViewerEngine | null>(null)\n/**\n * Numbered before each build starts, so the pages a build mounts carry its own number. A\n * rebuild gives each page a new host and mount, so pages from an earlier build must remount,\n * not be reused.\n */\nlet build = 0\n/** Whether the current build renders the annotation slot. */\nlet custom = false\nlet stops: (() => void)[] = []\n/** The zoom and page last reported to the host. */\nlet lastReportedZoom: ZoomValue | undefined\nlet lastReportedPage: number | undefined\n\nfunction teardown(): void {\n for (const stop of stops) stop()\n stops = []\n // Unmounts every page, which empties `pages` through `onPageUnmount`.\n engine.value?.destroy()\n engine.value = null\n if (ctx.viewport.value) ctx.viewport.value = null\n if (ctx.tools.value) ctx.tools.value = null\n pages.value = []\n}\n\nfunction rebuild(opts: Parameters<ViewerEngine['rebuild']>[0]): void {\n const e = engine.value\n if (!e) return\n build += 1\n if (opts.customAnnotations !== undefined) custom = opts.customAnnotations\n e.rebuild(opts)\n}\n\n// Build for a new document or status; the previous engine is torn down first.\nfunction setup(): void {\n teardown()\n lastReportedZoom = undefined\n lastReportedPage = undefined\n const doc = ctx.document.value\n const el = scroll.value\n if (!doc || !el || ctx.status.value.state !== 'ready') return\n let first = true\n build += 1\n custom = !!slots.annotation\n engine.value = mountViewer({\n container: el,\n document: doc,\n zoom: ctx.zoomModel.value ?? 'fit-width',\n ...(ctx.pageModel.value === undefined ? {} : { page: ctx.pageModel.value }),\n mode: props.mode,\n rotation: props.rotation,\n gap: props.gap,\n buffer: props.buffer,\n tool: ctx.tool.value,\n ...(ctx.hostTools.value ? { tools: ctx.hostTools.value } : {}),\n // Read through, so the watch below can re-apply a new function without a rebuild.\n decorateAnnotation: (a) => ctx.decorateAnnotation.value?.(a),\n ...(ctx.toolStyle.value ? { toolStyle: ctx.toolStyle.value } : {}),\n toolHistory: { batch: (fn) => ctx.history.batch(fn) },\n toolOptions: ctx.toolOptions,\n fonts: [...ctx.fonts.value],\n // Read through, so a new `signatures` store reaches the tool as well as the menus.\n signatureLibrary: () => ctx.signatures.value,\n customAnnotations: custom,\n onActivate: (id) => ctx.setActivated(id),\n onBuild: (vp, tc) => {\n ctx.viewport.value = vp\n ctx.tools.value = tc\n if (first) {\n // A new document starts from where the viewport opens (its zoom, on the first page:\n // `createViewport` always starts at page 0); only later changes are reported, the\n // restored page among them, since the engine has already scrolled to it.\n first = false\n lastReportedZoom = vp.zoom.get()\n lastReportedPage = 0\n }\n for (const stop of stops) stop()\n const reportZoom = (z: ZoomValue): void => {\n if (z === lastReportedZoom) return\n lastReportedZoom = z\n ctx.reportZoom(z)\n }\n const reportPage = (p: number): void => {\n if (p === lastReportedPage) return\n lastReportedPage = p\n ctx.reportPage(p)\n }\n // A tool that switches itself (a one-shot tool once used) is reported as a pick.\n const followTool = (id: ToolId): void => {\n if (id !== ctx.tool.value) ctx.setTool(id)\n }\n stops = [\n vp.zoom.subscribe(reportZoom),\n vp.currentPage.subscribe(reportPage),\n tc.active.subscribe(followTool),\n ]\n // Whatever the build restored is reported once; nothing is when it matched.\n reportZoom(vp.zoom.get())\n reportPage(vp.currentPage.get())\n },\n onPageMount: (page, mount, host) => {\n pages.value = [...pages.value, { build, page, host, mount, error: null, custom }]\n },\n onPageUnmount: (page) => {\n pages.value = pages.value.filter((p) => p.page !== page)\n },\n onPageError: (page, err) => {\n pages.value = pages.value.map((p) => (p.page === page ? { ...p, error: err } : p))\n },\n })\n}\n\nonMounted(() => {\n watch([() => ctx.document.value, () => ctx.status.value.state], setup, {\n immediate: true,\n })\n})\n\n// A new decorateAnnotation re-applies to the mounted annotation elements at once.\nwatch(\n () => ctx.decorateAnnotation.value,\n () => engine.value?.redecorate()\n)\nwatch(\n () => ctx.zoomModel.value,\n (z: ZoomValue | undefined) => {\n const vp = engine.value?.viewport\n if (vp && z !== undefined && z !== vp.zoom.get()) vp.setZoom(z)\n }\n)\nwatch(\n () => ctx.pageModel.value,\n (p) => {\n const vp = engine.value?.viewport\n if (!vp || p === undefined || p === lastReportedPage) return\n if (p !== vp.currentPage.get()) vp.scrollToPage(p)\n }\n)\nwatch(\n () => ctx.tool.value,\n (t) => {\n const tc = engine.value?.tools\n if (tc && tc.active.get() !== t) tc.set(t)\n }\n)\nwatch(\n () => props.mode,\n (m) => engine.value?.viewport.setMode(m)\n)\nwatch(\n () => props.rotation,\n (r) => engine.value?.viewport.setRotation(r)\n)\n// Gap and buffer are construction options: rebuild for the same document, keeping zoom and page.\n// The slots are already updated when this runs, so it carries the annotation slot too: a slot\n// toggle in the same tick is then recorded here and `onBeforeUpdate` finds nothing left to do.\nwatch([() => props.gap, () => props.buffer], ([gap, buffer]) =>\n rebuild({ gap, buffer, customAnnotations: !!slots.annotation })\n)\n\n// Slots are not reactive, so a change to whether the annotation slot is given is caught here.\n// `onBeforeUpdate` runs after the new slots are in place and before this render: the rebuild\n// swaps `pages` for the new build's pages synchronously, so the render that follows never pairs\n// the annotation slot with an overlay built without it (or the reverse). The rebuild keeps the\n// scroll position.\nonBeforeUpdate(() => {\n const next = !!slots.annotation\n if (engine.value && next !== custom) rebuild({ customAnnotations: next })\n})\n\nonBeforeUnmount(teardown)\n</script>\n\n<template>\n <div class=\"ink-viewport-root\" data-ink-viewport-root :data-state=\"state\">\n <div v-if=\"state === 'loading'\" class=\"ink-status\" role=\"status\" aria-live=\"polite\">\n <slot name=\"loading\">Loading document…</slot>\n </div>\n <div v-else-if=\"error\" class=\"ink-status ink-error\" role=\"alert\">\n <slot name=\"error\" :error=\"error\">\n <p class=\"ink-error-title\">This document could not be opened.</p>\n <!-- The message comes from the PDF engine and is not written for readers: it stays\n off the page, on the code's tooltip. -->\n <p>\n <code class=\"ink-error-code\" :title=\"error.message\">{{ error.code }}</code>\n </p>\n </slot>\n </div>\n <div v-else-if=\"state === 'idle'\" class=\"ink-status ink-empty\">\n <slot name=\"empty\" />\n </div>\n <div\n ref=\"scroll\"\n class=\"ink-scroll\"\n data-ink-scroll\n tabindex=\"0\"\n role=\"document\"\n aria-label=\"Document\"\n />\n <InkPage\n v-for=\"p in pages\"\n :key=\"`${p.build}:${p.page}`\"\n :page=\"p.page\"\n :host=\"p.host\"\n :mount=\"p.mount\"\n :error=\"p.error\"\n :custom-annotations=\"p.custom\"\n >\n <template v-if=\"slots.annotation\" #annotation=\"slotProps\">\n <slot name=\"annotation\" v-bind=\"slotProps\" />\n </template>\n <template v-if=\"slots['page-error']\" #page-error=\"slotProps\">\n <slot name=\"page-error\" v-bind=\"slotProps\" />\n </template>\n </InkPage>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAqCA,IAAMsB,IAAQC,GAYRC,IAAQxB,EAAA,GASR0B,IAAMC,EAAiB,GACvBC,IAASC,EAA4B,QAAQ,GAa7CC,IAAQC,EAA0B,CAAC,CAAC,GAEpCC,IAAQC,QAAeP,EAAI,OAAO,MAAM,KAAK,GAC7CQ,IAAQD,QACZP,EAAI,OAAO,MAAM,UAAU,UAAUA,EAAI,OAAO,MAAM,QAAQ,IAChE,GAEMS,IAASJ,EAAgC,IAAI,GAM/CK,IAAQ,GAERC,IAAS,IACTC,IAAwB,CAAC,GAEzBC,GACAC;EAEJ,SAASC,IAAiB;GACxB,KAAK,IAAMC,KAAQJ,GAAO,EAAK;GAO/B,AANA,IAAQ,CAAC,GAETH,EAAO,OAAO,QAAQ,GACtB,EAAO,QAAQ,MACXT,EAAI,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E,CAAS,CAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"InkViewport.vue_vue_type_script_setup_true_lang.js","names":["_useSlots","_openBlock","_createElementBlock","_renderSlot","_createTextVNode","_createElementVNode","_toDisplayString","_createCommentVNode","_Fragment","_renderList","_createBlock","InkPage","_createSlots","_withCtx","_mergeProps","InkPage_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","InkViewport_vue_vue_type_script_setup_true_lang_default","props","__props","slots","useSlots","ctx","injectInkContext","scroll","useTemplateRef","pages","shallowRef","state","computed","error","engine","build","custom","stops","lastReportedZoom","lastReportedPage","teardown","stop","rebuild","e","opts","setup","doc","el","first","mountViewer","a","fn","id","vp","tc","reportZoom","z","reportPage","p","page","err","onMounted","watch","t","m","r","gap","buffer","onBeforeUpdate","next","onBeforeUnmount","openBlock","createElementBlock","renderSlot","_ctx","_cache","createTextVNode","createElementVNode","toDisplayString","createCommentVNode","Fragment","renderList","createBlock","createSlots","withCtx","mergeProps","slotProps"],"sources":["../../src/components/InkViewport.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * The scroll element is handed to core's `mountViewer`, which builds the viewport, the page\n * layers, the tool controller and the keyboard shortcuts in it; Vue never renders children\n * into it. The engine reports each page host it mounts, and InkPage components rendered here\n * (they render nothing in place) teleport the page-error and custom-annotation slots into them.\n *\n * Two-way zoom and page: the viewport's own changes are reported through the context, and\n * the host's v-model values are applied only when they differ from the viewport's state, so\n * the echo of a reported value does nothing.\n */\nimport { mountViewer } from '@inkbar/core/dom'\nimport {\n computed,\n onBeforeUnmount,\n onBeforeUpdate,\n onMounted,\n shallowRef,\n useTemplateRef,\n watch,\n} from 'vue'\n\nimport { injectInkContext } from '../context'\n\nimport InkPage from './InkPage.vue'\n\nimport type { AnnotationSlotProps } from './annotation-slot'\nimport type { InkError } from '@inkbar/core'\nimport type {\n LayoutMode,\n PageMount,\n ToolId,\n ViewerEngine,\n ViewRotation,\n ZoomValue,\n} from '@inkbar/core/dom'\n\nconst props = withDefaults(\n defineProps<{\n mode?: LayoutMode\n rotation?: ViewRotation\n /** Gap between pages, CSS px. */\n gap?: number\n /** Pages kept mounted either side of the visible ones. */\n buffer?: number\n }>(),\n { mode: 'continuous', rotation: 0, gap: 16, buffer: 2 }\n)\n\nconst slots = defineSlots<{\n loading?(): unknown\n error?(props: { error: InkError }): unknown\n empty?(): unknown\n annotation?(props: AnnotationSlotProps): unknown\n /** Shown inside a page that failed to render. The rest of the document stays usable. */\n 'page-error'?(props: { error: InkError; page: number }): unknown\n}>()\n\nconst ctx = injectInkContext()\nconst scroll = useTemplateRef<HTMLElement>('scroll')\n\ninterface MountedPage {\n /** The engine build the host belongs to; part of the InkPage key. */\n build: number\n page: number\n host: HTMLElement\n mount: PageMount\n error: InkError | null\n /** Whether the build that mounted the page renders the annotation slot. */\n custom: boolean\n}\n/** Page hosts, mounts and errors the engine reported; InkPage renders Teleports for them. */\nconst pages = shallowRef<MountedPage[]>([])\n\nconst state = computed(() => ctx.status.value.state)\nconst error = computed<InkError | null>(() =>\n ctx.status.value.state === 'error' ? ctx.status.value.error : null\n)\n\nconst engine = shallowRef<ViewerEngine | null>(null)\n/**\n * Numbered before each build starts, so the pages a build mounts carry its own number. A\n * rebuild gives each page a new host and mount, so pages from an earlier build must remount,\n * not be reused.\n */\nlet build = 0\n/** Whether the current build renders the annotation slot. */\nlet custom = false\nlet stops: (() => void)[] = []\n/** The zoom and page last reported to the host. */\nlet lastReportedZoom: ZoomValue | undefined\nlet lastReportedPage: number | undefined\n\nfunction teardown(): void {\n for (const stop of stops) stop()\n stops = []\n // Unmounts every page, which empties `pages` through `onPageUnmount`.\n engine.value?.destroy()\n engine.value = null\n if (ctx.viewport.value) ctx.viewport.value = null\n if (ctx.tools.value) ctx.tools.value = null\n pages.value = []\n}\n\nfunction rebuild(opts: Parameters<ViewerEngine['rebuild']>[0]): void {\n const e = engine.value\n if (!e) return\n build += 1\n if (opts.customAnnotations !== undefined) custom = opts.customAnnotations\n e.rebuild(opts)\n}\n\n// Build for a new document or status; the previous engine is torn down first.\nfunction setup(): void {\n teardown()\n lastReportedZoom = undefined\n lastReportedPage = undefined\n const doc = ctx.document.value\n const el = scroll.value\n if (!doc || !el || ctx.status.value.state !== 'ready') return\n let first = true\n build += 1\n custom = !!slots.annotation\n engine.value = mountViewer({\n container: el,\n document: doc,\n zoom: ctx.zoomModel.value ?? 'fit-width',\n ...(ctx.pageModel.value === undefined ? {} : { page: ctx.pageModel.value }),\n mode: props.mode,\n rotation: props.rotation,\n gap: props.gap,\n buffer: props.buffer,\n tool: ctx.tool.value,\n ...(ctx.hostTools.value ? { tools: ctx.hostTools.value } : {}),\n // The engine adds the plugins' tools and layers, and decorates through the host, which\n // reads `decorateAnnotation` first.\n ...(ctx.pluginHost.value ? { plugins: ctx.pluginHost.value } : {}),\n // Read through, so the watch below can re-apply a new function without a rebuild.\n decorateAnnotation: (a) => ctx.decorateAnnotation.value?.(a),\n ...(ctx.toolStyle.value ? { toolStyle: ctx.toolStyle.value } : {}),\n toolHistory: { batch: (fn) => ctx.history.batch(fn) },\n toolOptions: ctx.toolOptions,\n fonts: [...ctx.fonts.value],\n // Read through, so a new `signatures` store reaches the tool as well as the menus.\n signatureLibrary: () => ctx.signatures.value,\n customAnnotations: custom,\n onActivate: (id) => ctx.setActivated(id),\n onBuild: (vp, tc) => {\n ctx.viewport.value = vp\n ctx.tools.value = tc\n if (first) {\n // A new document starts from where the viewport opens (its zoom, on the first page:\n // `createViewport` always starts at page 0); only later changes are reported, the\n // restored page among them, since the engine has already scrolled to it.\n first = false\n lastReportedZoom = vp.zoom.get()\n lastReportedPage = 0\n }\n for (const stop of stops) stop()\n const reportZoom = (z: ZoomValue): void => {\n if (z === lastReportedZoom) return\n lastReportedZoom = z\n ctx.reportZoom(z)\n }\n const reportPage = (p: number): void => {\n if (p === lastReportedPage) return\n lastReportedPage = p\n ctx.reportPage(p)\n }\n // A tool that switches itself (a one-shot tool once used) is reported as a pick.\n const followTool = (id: ToolId): void => {\n if (id !== ctx.tool.value) ctx.setTool(id)\n }\n stops = [\n vp.zoom.subscribe(reportZoom),\n vp.currentPage.subscribe(reportPage),\n tc.active.subscribe(followTool),\n ]\n // Whatever the build restored is reported once; nothing is when it matched.\n reportZoom(vp.zoom.get())\n reportPage(vp.currentPage.get())\n },\n onPageMount: (page, mount, host) => {\n pages.value = [...pages.value, { build, page, host, mount, error: null, custom }]\n },\n onPageUnmount: (page) => {\n pages.value = pages.value.filter((p) => p.page !== page)\n },\n onPageError: (page, err) => {\n pages.value = pages.value.map((p) => (p.page === page ? { ...p, error: err } : p))\n },\n })\n}\n\nonMounted(() => {\n ctx.viewportEl.value = scroll.value\n watch([() => ctx.document.value, () => ctx.status.value.state], setup, {\n immediate: true,\n })\n})\n\n// A new decorateAnnotation re-applies to the mounted annotation elements at once.\nwatch(\n () => ctx.decorateAnnotation.value,\n () => engine.value?.redecorate()\n)\nwatch(\n () => ctx.zoomModel.value,\n (z: ZoomValue | undefined) => {\n const vp = engine.value?.viewport\n if (vp && z !== undefined && z !== vp.zoom.get()) vp.setZoom(z)\n }\n)\nwatch(\n () => ctx.pageModel.value,\n (p) => {\n const vp = engine.value?.viewport\n if (!vp || p === undefined || p === lastReportedPage) return\n if (p !== vp.currentPage.get()) vp.scrollToPage(p)\n }\n)\nwatch(\n () => ctx.tool.value,\n (t) => {\n const tc = engine.value?.tools\n if (tc && tc.active.get() !== t) tc.set(t)\n }\n)\nwatch(\n () => props.mode,\n (m) => engine.value?.viewport.setMode(m)\n)\nwatch(\n () => props.rotation,\n (r) => engine.value?.viewport.setRotation(r)\n)\n// Gap and buffer are construction options: rebuild for the same document, keeping zoom and page.\n// The slots are already updated when this runs, so it carries the annotation slot too: a slot\n// toggle in the same tick is then recorded here and `onBeforeUpdate` finds nothing left to do.\nwatch([() => props.gap, () => props.buffer], ([gap, buffer]) =>\n rebuild({ gap, buffer, customAnnotations: !!slots.annotation })\n)\n\n// Slots are not reactive, so a change to whether the annotation slot is given is caught here.\n// `onBeforeUpdate` runs after the new slots are in place and before this render: the rebuild\n// swaps `pages` for the new build's pages synchronously, so the render that follows never pairs\n// the annotation slot with an overlay built without it (or the reverse). The rebuild keeps the\n// scroll position.\nonBeforeUpdate(() => {\n const next = !!slots.annotation\n if (engine.value && next !== custom) rebuild({ customAnnotations: next })\n})\n\nonBeforeUnmount(() => {\n teardown()\n if (ctx.viewportEl.value === scroll.value) ctx.viewportEl.value = null\n})\n</script>\n\n<template>\n <div class=\"ink-viewport-root\" data-ink-viewport-root :data-state=\"state\">\n <div v-if=\"state === 'loading'\" class=\"ink-status\" role=\"status\" aria-live=\"polite\">\n <slot name=\"loading\">Loading document…</slot>\n </div>\n <div v-else-if=\"error\" class=\"ink-status ink-error\" role=\"alert\">\n <slot name=\"error\" :error=\"error\">\n <p class=\"ink-error-title\">This document could not be opened.</p>\n <!-- The message comes from the PDF engine and is not written for readers: it stays\n off the page, on the code's tooltip. -->\n <p>\n <code class=\"ink-error-code\" :title=\"error.message\">{{ error.code }}</code>\n </p>\n </slot>\n </div>\n <div v-else-if=\"state === 'idle'\" class=\"ink-status ink-empty\">\n <slot name=\"empty\" />\n </div>\n <div\n ref=\"scroll\"\n class=\"ink-scroll\"\n data-ink-scroll\n tabindex=\"0\"\n role=\"document\"\n aria-label=\"Document\"\n />\n <InkPage\n v-for=\"p in pages\"\n :key=\"`${p.build}:${p.page}`\"\n :page=\"p.page\"\n :host=\"p.host\"\n :mount=\"p.mount\"\n :error=\"p.error\"\n :custom-annotations=\"p.custom\"\n >\n <template v-if=\"slots.annotation\" #annotation=\"slotProps\">\n <slot name=\"annotation\" v-bind=\"slotProps\" />\n </template>\n <template v-if=\"slots['page-error']\" #page-error=\"slotProps\">\n <slot name=\"page-error\" v-bind=\"slotProps\" />\n </template>\n </InkPage>\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAqCA,IAAMsB,IAAQC,GAYRC,IAAQxB,EAAA,GASR0B,IAAMC,E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AA;IACA,UAAS;IACT,MAAK;IACL,cAAW;;IAEb3B,EAAA,EAAA,GAAAC,EAeUM,GAAA,MAAAC,EAdIqB,EAAA,QAAL,OADT7B,EAAA,GAAAS,EAeUC,GAAA;IAbP,KAAG,GAAKgD,EAAE,MAAK,GAAIA,EAAE;IACrB,MAAMA,EAAE;IACR,MAAMA,EAAE;IACR,OAAOA,EAAE;IACT,OAAOA,EAAE;IACT,sBAAoBA,EAAE;GAEP,GAAAyB,EAAA,EAAA,GAAA,EAAA,GAAA,CAAA5D,EAAM,aAAA;IAAa,MAAA;IACjC,IAAAX,GAD6C,MAAS,CACtDV,EAA6CwE,EAAA,QAAA,cAA7C7D,EAA6C,EAAA,SAAA,GAAA,GAAbyE,CAAS,CAAA,CAAA,CAAA;;GAE3B,IAAA,KAAA,GAAA/D,EAAK,gBAAA;IAAiB,MAAA;IACpC,IAAAX,GADgD,MAAS,CACzDV,EAA6CwE,EAAA,QAAA,cAA7C7D,EAA6C,EAAA,SAAA,GAAA,GAAbyE,CAAS,CAAA,CAAA,CAAA"}
@@ -0,0 +1,23 @@
1
+ import { IconNode } from '@inkbar/icons';
2
+ import { Ref } from 'vue';
3
+ export interface CommandHandle {
4
+ /** Runs the command; does nothing while it is busy or disabled. Never rejects. */
5
+ run(): Promise<void>;
6
+ /** A ready document (or the plugin's own condition), and not busy. */
7
+ enabled: Readonly<Ref<boolean>>;
8
+ busy: Readonly<Ref<boolean>>;
9
+ /** The command's progress or result message, `''` without one. */
10
+ status: Readonly<Ref<string>>;
11
+ /** `''` until the plugins are set up. */
12
+ label: Readonly<Ref<string>>;
13
+ icon: Readonly<Ref<IconNode | undefined>>;
14
+ }
15
+ /**
16
+ * A plugin command by its namespaced id (`sandbox.suggest`), for hosts building their own
17
+ * control. Plugins are set up once InkRoot has mounted, so until then (and on the server) the
18
+ * command is disabled with no label; it fills in then. Once they are set up, an id no plugin
19
+ * passed to InkRoot registered stays that way, and logs `InkError('UnknownCommand')` to the
20
+ * console once.
21
+ */
22
+ export declare function useCommand(id: string): CommandHandle;
23
+ //# sourceMappingURL=useCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCommand.d.ts","sourceRoot":"","sources":["../../src/composables/useCommand.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAE9B,MAAM,WAAW,aAAa;IAC5B,kFAAkF;IAClF,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACpB,sEAAsE;IACtE,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/B,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5B,kEAAkE;IAClE,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IAC7B,yCAAyC;IACzC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAA;CAC1C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,CAmBpD"}
@@ -0,0 +1,22 @@
1
+ import { useInkContext as e } from "../context.js";
2
+ import { useReadable as t } from "../use-readable.js";
3
+ import { computed as n, watch as r } from "vue";
4
+ import { unknownCommand as i } from "@inkbar/core/dom";
5
+ //#region src/composables/useCommand.ts
6
+ function a(a) {
7
+ let o = e("useCommand()").pluginHost, s = n(() => o.value?.command(a));
8
+ return r(o, (e) => {
9
+ e && !e.command(a) && console.error(i(a, [...e.commands.keys()]));
10
+ }, { immediate: !0 }), {
11
+ run: async () => s.value?.run(),
12
+ enabled: t(() => s.value?.enabled, !1),
13
+ busy: t(() => s.value?.busy, !1),
14
+ status: t(() => s.value?.status, ""),
15
+ label: n(() => s.value?.label ?? ""),
16
+ icon: n(() => s.value?.icon)
17
+ };
18
+ }
19
+ //#endregion
20
+ export { a as useCommand };
21
+
22
+ //# sourceMappingURL=useCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCommand.js","names":["useCommand","host","useInkContext","command","computed","id","watch","set","unknownCommand","useReadable"],"sources":["../../src/composables/useCommand.ts"],"sourcesContent":["import { unknownCommand } from '@inkbar/core/dom'\nimport { computed, watch } from 'vue'\n\nimport { useInkContext } from '../context'\nimport { useReadable } from '../use-readable'\n\nimport type { IconNode } from '@inkbar/icons'\nimport type { Ref } from 'vue'\n\nexport interface CommandHandle {\n /** Runs the command; does nothing while it is busy or disabled. Never rejects. */\n run(): Promise<void>\n /** A ready document (or the plugin's own condition), and not busy. */\n enabled: Readonly<Ref<boolean>>\n busy: Readonly<Ref<boolean>>\n /** The command's progress or result message, `''` without one. */\n status: Readonly<Ref<string>>\n /** `''` until the plugins are set up. */\n label: Readonly<Ref<string>>\n icon: Readonly<Ref<IconNode | undefined>>\n}\n\n/**\n * A plugin command by its namespaced id (`sandbox.suggest`), for hosts building their own\n * control. Plugins are set up once InkRoot has mounted, so until then (and on the server) the\n * command is disabled with no label; it fills in then. Once they are set up, an id no plugin\n * passed to InkRoot registered stays that way, and logs `InkError('UnknownCommand')` to the\n * console once.\n */\nexport function useCommand(id: string): CommandHandle {\n const host = useInkContext('useCommand()').pluginHost\n const command = computed(() => host.value?.command(id))\n watch(\n host,\n (set) => {\n if (set && !set.command(id))\n console.error(unknownCommand(id, [...set.commands.keys()]))\n },\n { immediate: true }\n )\n return {\n run: async () => command.value?.run(),\n enabled: useReadable(() => command.value?.enabled, false),\n busy: useReadable(() => command.value?.busy, false),\n status: useReadable(() => command.value?.status, ''),\n label: computed(() => command.value?.label ?? ''),\n icon: computed(() => command.value?.icon),\n }\n}\n"],"mappings":";;;;;AA6BA,SAAgBA,EAAW,GAA2B;CACpD,IAAMC,IAAOC,EAAc,cAAc,CAAC,CAAC,YACrCC,IAAUC,QAAeH,EAAK,OAAO,QAAQI,CAAE,CAAC;CAStD,OARAC,EACEL,IACC,MAAQ;EACP,AAAIM,KAAO,CAACA,EAAI,QAAQF,CAAE,KACxB,QAAQ,MAAMG,EAAeH,GAAI,CAAC,GAAGE,EAAI,SAAS,KAAK,CAAC,CAAC,CAAC;CAC9D,GACA,EAAE,WAAW,GAAK,CACpB,GACO;EACL,KAAK,YAAYJ,EAAQ,OAAO,IAAI;EACpC,SAASM,QAAkBN,EAAQ,OAAO,SAAS,EAAK;EACxD,MAAMM,QAAkBN,EAAQ,OAAO,MAAM,EAAK;EAClD,QAAQM,QAAkBN,EAAQ,OAAO,QAAQ,EAAE;EACnD,OAAOC,QAAeD,EAAQ,OAAO,SAAS,EAAE;EAChD,MAAMC,QAAeD,EAAQ,OAAO,IAAI;CAC1C;AACF"}
package/dist/context.d.ts CHANGED
@@ -1,9 +1,12 @@
1
- import { Annotation, InkDocument, InkStatus, PdfAssets, SignatureLibrary } from '@inkbar/core';
2
- import { DecorateAnnotation, Tool, ToolController, ToolId, ToolOptions, ToolStyle, Viewport, ZoomValue } from '@inkbar/core/dom';
1
+ import { Annotation, InkDocument, InkStatus, PdfAssets, PluginHistory, SignatureLibrary } from '@inkbar/core';
2
+ import { DecorateAnnotation, PluginHost, Tool, ToolController, ToolId, ToolOptions, ToolStyle, Viewport, ZoomValue } from '@inkbar/core/dom';
3
3
  import { Ref, ShallowRef } from 'vue';
4
4
  export type { InkStatus };
5
- /** Undo and redo for the current document, whichever mode its annotations are in. */
6
- export interface InkHistory {
5
+ /**
6
+ * Undo and redo for the current document, whichever mode its annotations are in. `track` and
7
+ * `react` (from `PluginHistory`) reach the same history, so plugin stores undo with the edits.
8
+ */
9
+ export interface InkHistory extends PluginHistory {
7
10
  canUndo: Readonly<Ref<boolean>>;
8
11
  canRedo: Readonly<Ref<boolean>>;
9
12
  undo: () => void;
@@ -24,6 +27,14 @@ export interface InkContext {
24
27
  status: Readonly<Ref<InkStatus>>;
25
28
  annotations: Readonly<Ref<readonly Annotation[]>>;
26
29
  selection: Readonly<Ref<readonly string[]>>;
30
+ /**
31
+ * The plugins from InkRoot's `plugins` prop, set up once the root has mounted and kept for
32
+ * its life; `null` before that (and on the server) and once it unmounts. InkViewport hands it
33
+ * to the engine; InkCommand places its commands.
34
+ */
35
+ pluginHost: Readonly<ShallowRef<PluginHost | null>>;
36
+ /** InkViewport's scroll element while it is mounted: the plugins' `root`. */
37
+ viewportEl: ShallowRef<HTMLElement | null>;
27
38
  /** Set by InkViewport once it has mounted its viewport and tool controller. */
28
39
  viewport: ShallowRef<Viewport | null>;
29
40
  tools: ShallowRef<ToolController | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,SAAS,EACT,gBAAgB,EACjB,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EACV,kBAAkB,EAClB,IAAI,EACJ,cAAc,EACd,MAAM,EACN,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACV,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAE1C,YAAY,EAAE,SAAS,EAAE,CAAA;AAEzB,qFAAqF;AACrF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/B,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/B,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,IAAI,EAAE,MAAM,IAAI,CAAA;IAChB,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB;;;;;OAKG;IACH,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,KAAK,IAAI,CA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,iBAAiB,0CAAwC,CAAA;AAEzF;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAO1D"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","names":["injectInkContext","provideInkContext","createContext","useInkContext","ctx","getCurrentInstance","consumer"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'reka-ui'\nimport { getCurrentInstance } from 'vue'\n\nimport type {\n Annotation,\n InkDocument,\n InkStatus,\n PdfAssets,\n SignatureLibrary,\n} from '@inkbar/core'\nimport type {\n DecorateAnnotation,\n Tool,\n ToolController,\n ToolId,\n ToolOptions,\n ToolStyle,\n Viewport,\n ZoomValue,\n} from '@inkbar/core/dom'\nimport type { Ref, ShallowRef } from 'vue'\n\nexport type { InkStatus }\n\n/** Undo and redo for the current document, whichever mode its annotations are in. */\nexport interface InkHistory {\n canUndo: Readonly<Ref<boolean>>\n canRedo: Readonly<Ref<boolean>>\n undo: () => void\n redo: () => void\n clear: () => void\n /**\n * Runs `fn` and records what it changes as one undo step. The host still receives one change\n * per add. Controlled, the history groups the resulting list changes into one step, and\n * `canUndo` updates once the current task ends. Any other change the host applies in that\n * same window joins the step.\n */\n batch: (fn: () => void) => void\n}\n\nexport interface InkContext {\n assets: Readonly<Ref<PdfAssets>>\n document: Readonly<ShallowRef<InkDocument | null>>\n /** `loading` from the moment a document starts opening, then the document's own status. */\n status: Readonly<Ref<InkStatus>>\n annotations: Readonly<Ref<readonly Annotation[]>>\n selection: Readonly<Ref<readonly string[]>>\n /** Set by InkViewport once it has mounted its viewport and tool controller. */\n viewport: ShallowRef<Viewport | null>\n tools: ShallowRef<ToolController | null>\n /** Desired tool; InkViewport applies it to the controller. */\n tool: Readonly<Ref<ToolId>>\n setTool(id: ToolId): void\n /** Host tools from InkRoot's `tools` prop; InkViewport registers them. */\n hostTools: Readonly<Ref<Tool[] | undefined>>\n /** InkRoot's `decorateAnnotation` prop. InkViewport re-applies decorations when it changes. */\n decorateAnnotation: Readonly<Ref<DecorateAnnotation | undefined>>\n /** The font families text boxes offer: InkRoot's `fonts`, else `FONT_FAMILIES`. */\n fonts: Readonly<Ref<readonly string[]>>\n /** The tools' options for InkRoot's life, so they persist across documents. */\n toolOptions: ToolOptions\n /** The saved signatures, from InkRoot's `signatures` store (memory by default). */\n signatures: Readonly<ShallowRef<SignatureLibrary>>\n /** The fonts a typed signature offers: InkRoot's `signatureFonts`, else `SIGNATURE_FONTS`. */\n signatureFonts: Readonly<Ref<readonly string[]>>\n /** The open document's tool style; `null` while no document is open. */\n toolStyle: Readonly<ShallowRef<ToolStyle | null>>\n /** Desired zoom and page from the host's v-models; InkViewport applies and reports back. */\n zoomModel: Readonly<Ref<ZoomValue | undefined>>\n pageModel: Readonly<Ref<number | undefined>>\n reportZoom(z: ZoomValue): void\n reportPage(p: number): void\n /** Last activated annotation (Enter, click with the note tool, etc.). Popovers key off this. */\n activated: Readonly<Ref<string | null>>\n /**\n * Activates annotation `id`, or clears the activation with `null`. This is the context's\n * own: unlike core's `Viewer.setActivated`, it emits InkRoot's `activate` for an id, and it\n * does not check that the id is in the document.\n */\n setActivated(id: string | null): void\n history: InkHistory\n rootEl: Readonly<Ref<HTMLElement | null>>\n}\n\nexport const [injectInkContext, provideInkContext] = createContext<InkContext>('InkRoot')\n\n/**\n * The context for composables: throws a readable error when called outside a component\n * rendered inside `InkRoot`, instead of Vue's injection warning.\n */\nexport function useInkContext(consumer: string): InkContext {\n const ctx = getCurrentInstance() ? injectInkContext(null) : null\n if (!ctx)\n throw new Error(\n `[inkbar] ${consumer} must be called in a component inside <InkRoot>.`\n )\n return ctx\n}\n"],"mappings":";;;AAoFA,IAAa,CAACA,GAAkBC,KAAqBC,EAA0B,SAAS;AAMxF,SAAgBC,EAAc,GAA8B;CAC1D,IAAMC,IAAMC,EAAmB,IAAIL,EAAiB,IAAI,IAAI;CAC5D,IAAI,CAACI,GACH,MAAU,MACR,YAAYE,EAAS,iDACvB;CACF,OAAOF;AACT"}
1
+ {"version":3,"file":"context.js","names":["injectInkContext","provideInkContext","createContext","useInkContext","ctx","getCurrentInstance","consumer"],"sources":["../src/context.ts"],"sourcesContent":["import { createContext } from 'reka-ui'\nimport { getCurrentInstance } from 'vue'\n\nimport type {\n Annotation,\n InkDocument,\n InkStatus,\n PdfAssets,\n PluginHistory,\n SignatureLibrary,\n} from '@inkbar/core'\nimport type {\n DecorateAnnotation,\n PluginHost,\n Tool,\n ToolController,\n ToolId,\n ToolOptions,\n ToolStyle,\n Viewport,\n ZoomValue,\n} from '@inkbar/core/dom'\nimport type { Ref, ShallowRef } from 'vue'\n\nexport type { InkStatus }\n\n/**\n * Undo and redo for the current document, whichever mode its annotations are in. `track` and\n * `react` (from `PluginHistory`) reach the same history, so plugin stores undo with the edits.\n */\nexport interface InkHistory extends PluginHistory {\n canUndo: Readonly<Ref<boolean>>\n canRedo: Readonly<Ref<boolean>>\n undo: () => void\n redo: () => void\n clear: () => void\n /**\n * Runs `fn` and records what it changes as one undo step. The host still receives one change\n * per add. Controlled, the history groups the resulting list changes into one step, and\n * `canUndo` updates once the current task ends. Any other change the host applies in that\n * same window joins the step.\n */\n batch: (fn: () => void) => void\n}\n\nexport interface InkContext {\n assets: Readonly<Ref<PdfAssets>>\n document: Readonly<ShallowRef<InkDocument | null>>\n /** `loading` from the moment a document starts opening, then the document's own status. */\n status: Readonly<Ref<InkStatus>>\n annotations: Readonly<Ref<readonly Annotation[]>>\n selection: Readonly<Ref<readonly string[]>>\n /**\n * The plugins from InkRoot's `plugins` prop, set up once the root has mounted and kept for\n * its life; `null` before that (and on the server) and once it unmounts. InkViewport hands it\n * to the engine; InkCommand places its commands.\n */\n pluginHost: Readonly<ShallowRef<PluginHost | null>>\n /** InkViewport's scroll element while it is mounted: the plugins' `root`. */\n viewportEl: ShallowRef<HTMLElement | null>\n /** Set by InkViewport once it has mounted its viewport and tool controller. */\n viewport: ShallowRef<Viewport | null>\n tools: ShallowRef<ToolController | null>\n /** Desired tool; InkViewport applies it to the controller. */\n tool: Readonly<Ref<ToolId>>\n setTool(id: ToolId): void\n /** Host tools from InkRoot's `tools` prop; InkViewport registers them. */\n hostTools: Readonly<Ref<Tool[] | undefined>>\n /** InkRoot's `decorateAnnotation` prop. InkViewport re-applies decorations when it changes. */\n decorateAnnotation: Readonly<Ref<DecorateAnnotation | undefined>>\n /** The font families text boxes offer: InkRoot's `fonts`, else `FONT_FAMILIES`. */\n fonts: Readonly<Ref<readonly string[]>>\n /** The tools' options for InkRoot's life, so they persist across documents. */\n toolOptions: ToolOptions\n /** The saved signatures, from InkRoot's `signatures` store (memory by default). */\n signatures: Readonly<ShallowRef<SignatureLibrary>>\n /** The fonts a typed signature offers: InkRoot's `signatureFonts`, else `SIGNATURE_FONTS`. */\n signatureFonts: Readonly<Ref<readonly string[]>>\n /** The open document's tool style; `null` while no document is open. */\n toolStyle: Readonly<ShallowRef<ToolStyle | null>>\n /** Desired zoom and page from the host's v-models; InkViewport applies and reports back. */\n zoomModel: Readonly<Ref<ZoomValue | undefined>>\n pageModel: Readonly<Ref<number | undefined>>\n reportZoom(z: ZoomValue): void\n reportPage(p: number): void\n /** Last activated annotation (Enter, click with the note tool, etc.). Popovers key off this. */\n activated: Readonly<Ref<string | null>>\n /**\n * Activates annotation `id`, or clears the activation with `null`. This is the context's\n * own: unlike core's `Viewer.setActivated`, it emits InkRoot's `activate` for an id, and it\n * does not check that the id is in the document.\n */\n setActivated(id: string | null): void\n history: InkHistory\n rootEl: Readonly<Ref<HTMLElement | null>>\n}\n\nexport const [injectInkContext, provideInkContext] = createContext<InkContext>('InkRoot')\n\n/**\n * The context for composables: throws a readable error when called outside a component\n * rendered inside `InkRoot`, instead of Vue's injection warning.\n */\nexport function useInkContext(consumer: string): InkContext {\n const ctx = getCurrentInstance() ? injectInkContext(null) : null\n if (!ctx)\n throw new Error(\n `[inkbar] ${consumer} must be called in a component inside <InkRoot>.`\n )\n return ctx\n}\n"],"mappings":";;;AAiGA,IAAa,CAACA,GAAkBC,KAAqBC,EAA0B,SAAS;AAMxF,SAAgBC,EAAc,GAA8B;CAC1D,IAAMC,IAAMC,EAAmB,IAAIL,EAAiB,IAAI,IAAI;CAC5D,IAAI,CAACI,GACH,MAAU,MACR,YAAYE,EAAS,iDACvB;CACF,OAAOF;AACT"}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { default as InkRoot } from './components/InkRoot.vue';
2
2
  export { injectInkContext } from './context';
3
3
  export type { InkContext, InkHistory, InkStatus } from './context';
4
- export type { AnnotationDecoration, DecorateAnnotation } from '@inkbar/core/dom';
4
+ export type { AnnotationDecoration, DecorateAnnotation, InkPlugin, } from '@inkbar/core/dom';
5
5
  export { useReadable } from './use-readable';
6
6
  export { useDocument } from './composables/useDocument';
7
7
  export { useAnnotations } from './composables/useAnnotations';
@@ -14,6 +14,8 @@ export { useZoom } from './composables/useZoom';
14
14
  export { usePage } from './composables/usePage';
15
15
  export { useHistory } from './composables/useHistory';
16
16
  export { useEmbedded } from './composables/useEmbedded';
17
+ export { useCommand } from './composables/useCommand';
18
+ export type { CommandHandle } from './composables/useCommand';
17
19
  export { default as InkViewport } from './components/InkViewport.vue';
18
20
  export { default as InkPage } from './components/InkPage.vue';
19
21
  export { default as InkAnnotation } from './components/InkAnnotation.vue';
@@ -21,6 +23,7 @@ export type { AnnotationSlotProps, AnnotationState } from './components/annotati
21
23
  export { default as InkToolbar } from './components/InkToolbar.vue';
22
24
  export { default as InkIcon } from './components/InkIcon.vue';
23
25
  export { default as InkToolButton } from './components/InkToolButton.vue';
26
+ export { default as InkCommand } from './components/InkCommand.vue';
24
27
  export { default as InkToolbarSeparator } from './components/InkToolbarSeparator.vue';
25
28
  export { default as InkUndo } from './components/InkUndo.vue';
26
29
  export { default as InkRedo } from './components/InkRedo.vue';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MA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E,MAAM,+BAA+B,CAAA;AACvE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACvE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAC/E,YAAY,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA"}
package/dist/index.js CHANGED
@@ -11,28 +11,30 @@ import { useZoom as l } from "./composables/useZoom.js";
11
11
  import { usePage as u } from "./composables/usePage.js";
12
12
  import { useHistory as d } from "./composables/useHistory.js";
13
13
  import { useEmbedded as f } from "./composables/useEmbedded.js";
14
- import p from "./components/InkAnnotation.js";
15
- import m from "./components/InkPage.js";
16
- import h from "./components/InkViewport.js";
17
- import g from "./components/InkToolbar.js";
18
- import _ from "./components/InkIcon.js";
19
- import v from "./components/InkToolButton.js";
20
- import y from "./components/InkToolbarSeparator.js";
21
- import b from "./components/InkUndo.js";
22
- import x from "./components/InkRedo.js";
23
- import S from "./components/InkColorMenu.js";
24
- import C from "./components/InkShapeMenu.js";
25
- import w from "./components/InkSignatureDialog.js";
26
- import T from "./components/InkSignatureMenu.js";
27
- import E from "./components/InkHighlightMenu.js";
28
- import D from "./components/InkLineStyleMenu.js";
29
- import O from "./components/InkTextStyleMenu.js";
30
- import k from "./components/InkZoomIn.js";
31
- import A from "./components/InkZoomOut.js";
32
- import j from "./components/InkZoomSelect.js";
33
- import M from "./components/InkPageInput.js";
34
- import N from "./components/InkPageCount.js";
35
- import P from "./components/InkPrevPage.js";
36
- import F from "./components/InkNextPage.js";
37
- import I from "./components/InkThreadPopover.js";
38
- export { p as InkAnnotation, S as InkColorMenu, E as InkHighlightMenu, _ as InkIcon, D as InkLineStyleMenu, F as InkNextPage, m as InkPage, N as InkPageCount, M as InkPageInput, P as InkPrevPage, x as InkRedo, n as InkRoot, C as InkShapeMenu, w as InkSignatureDialog, T as InkSignatureMenu, O as InkTextStyleMenu, I as InkThreadPopover, v as InkToolButton, g as InkToolbar, y as InkToolbarSeparator, b as InkUndo, h as InkViewport, k as InkZoomIn, A as InkZoomOut, j as InkZoomSelect, e as injectInkContext, i as useAnnotations, r as useDocument, f as useEmbedded, d as useHistory, u as usePage, t as useReadable, c as useSelection, a as useTool, s as useToolOptions, o as useToolStyle, l as useZoom };
14
+ import { useCommand as p } from "./composables/useCommand.js";
15
+ import m from "./components/InkAnnotation.js";
16
+ import h from "./components/InkPage.js";
17
+ import g from "./components/InkViewport.js";
18
+ import _ from "./components/InkToolbar.js";
19
+ import v from "./components/InkIcon.js";
20
+ import y from "./components/InkToolButton.js";
21
+ import b from "./components/InkCommand.js";
22
+ import x from "./components/InkToolbarSeparator.js";
23
+ import S from "./components/InkUndo.js";
24
+ import C from "./components/InkRedo.js";
25
+ import w from "./components/InkColorMenu.js";
26
+ import T from "./components/InkShapeMenu.js";
27
+ import E from "./components/InkSignatureDialog.js";
28
+ import D from "./components/InkSignatureMenu.js";
29
+ import O from "./components/InkHighlightMenu.js";
30
+ import k from "./components/InkLineStyleMenu.js";
31
+ import A from "./components/InkTextStyleMenu.js";
32
+ import j from "./components/InkZoomIn.js";
33
+ import M from "./components/InkZoomOut.js";
34
+ import N from "./components/InkZoomSelect.js";
35
+ import P from "./components/InkPageInput.js";
36
+ import F from "./components/InkPageCount.js";
37
+ import I from "./components/InkPrevPage.js";
38
+ import L from "./components/InkNextPage.js";
39
+ import R from "./components/InkThreadPopover.js";
40
+ export { m as InkAnnotation, w as InkColorMenu, b as InkCommand, O as InkHighlightMenu, v as InkIcon, k as InkLineStyleMenu, L as InkNextPage, h as InkPage, F as InkPageCount, P as InkPageInput, I as InkPrevPage, C as InkRedo, n as InkRoot, T as InkShapeMenu, E as InkSignatureDialog, D as InkSignatureMenu, A as InkTextStyleMenu, R as InkThreadPopover, y as InkToolButton, _ as InkToolbar, x as InkToolbarSeparator, S as InkUndo, g as InkViewport, j as InkZoomIn, M as InkZoomOut, N as InkZoomSelect, e as injectInkContext, i as useAnnotations, p as useCommand, r as useDocument, f as useEmbedded, d as useHistory, u as usePage, t as useReadable, c as useSelection, a as useTool, s as useToolOptions, o as useToolStyle, l as useZoom };
@@ -1,18 +1,27 @@
1
1
  import { Ref } from 'vue';
2
2
  import { InkHistory } from './context';
3
- import { Annotation } from '@inkbar/core';
3
+ import { Annotation, AnnotationStore } from '@inkbar/core';
4
4
  export interface RefHistoryOptions {
5
5
  /** The host's list (the `annotations` v-model). Undefined when the host does not control it. */
6
6
  source: () => readonly Annotation[] | undefined;
7
7
  /** Proposes a list to the host; the step only counts once the host applies it. */
8
8
  apply: (list: Annotation[]) => void;
9
9
  enabled: Readonly<Ref<boolean>>;
10
+ /**
11
+ * The open document's controlled store, if any. Its user edits run the plugins' reactions
12
+ * inside the edit's step, with or without `enabled`.
13
+ */
14
+ store?: () => AnnotationStore | null | undefined;
10
15
  limit?: number;
11
16
  }
17
+ export interface RefHistory extends InkHistory {
18
+ /** Runs the reactions for the store's user edits; returns a function that detaches it. */
19
+ attach(store: AnnotationStore): () => void;
20
+ }
12
21
  /**
13
22
  * Snapshot undo and redo over a host-owned annotation list, for controlled hosts. The stacks
14
23
  * live in core's `createSnapshotHistory`; this wrapper feeds it from a watch on the host's list
15
- * and exposes refs.
24
+ * and exposes refs. Plugin stores it tracks are snapshotted with each step.
16
25
  */
17
- export declare function createRefHistory(opts: RefHistoryOptions): InkHistory;
26
+ export declare function createRefHistory(opts: RefHistoryOptions): RefHistory;
18
27
  //# sourceMappingURL=ref-history.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ref-history.d.ts","sourceRoot":"","sources":["../src/ref-history.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,GAAG,EAAE,MAAM,KAAK,CAAA;AAI/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C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,GAAG,UAAU,CAmCpE"}
@@ -1,25 +1,36 @@
1
1
  import { useReadable as e } from "./use-readable.js";
2
- import { computed as t, watch as n } from "vue";
3
- import { createSnapshotHistory as r } from "@inkbar/core";
2
+ import { computed as t, onScopeDispose as n, watch as r } from "vue";
3
+ import { createSnapshotHistory as i } from "@inkbar/core";
4
4
  //#region src/ref-history.ts
5
- function i(i) {
6
- let a = r({
7
- apply: i.apply,
8
- enabled: () => i.enabled.value,
9
- ...i.limit === void 0 ? {} : { limit: i.limit }
5
+ function a(a) {
6
+ let o = i({
7
+ apply: a.apply,
8
+ enabled: () => a.enabled.value,
9
+ ...a.limit === void 0 ? {} : { limit: a.limit }
10
10
  });
11
- a.observe(i.source()), n(i.source, (e) => a.observe(e));
12
- let o = e(a.canUndo, !1), s = e(a.canRedo, !1);
11
+ if (o.observe(a.source()), r(a.source, (e) => o.observe(e)), a.store) {
12
+ let e;
13
+ r(a.store, (t) => {
14
+ e?.(), e = t ? o.attach(t) : void 0;
15
+ }, {
16
+ immediate: !0,
17
+ flush: "sync"
18
+ }), n(() => e?.());
19
+ }
20
+ let s = e(o.canUndo, !1), c = e(o.canRedo, !1);
13
21
  return {
14
- canUndo: t(() => i.enabled.value && o.value),
15
- canRedo: t(() => i.enabled.value && s.value),
16
- undo: () => a.undo(),
17
- redo: () => a.redo(),
18
- clear: () => a.clear(),
19
- batch: (e) => a.batch(e)
22
+ canUndo: t(() => a.enabled.value && s.value),
23
+ canRedo: t(() => a.enabled.value && c.value),
24
+ undo: () => o.undo(),
25
+ redo: () => o.redo(),
26
+ clear: () => o.clear(),
27
+ batch: (e) => o.batch(e),
28
+ track: (e) => o.track(e),
29
+ react: (e) => o.react(e),
30
+ attach: (e) => o.attach(e)
20
31
  };
21
32
  }
22
33
  //#endregion
23
- export { i as createRefHistory };
34
+ export { a as createRefHistory };
24
35
 
25
36
  //# sourceMappingURL=ref-history.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ref-history.js","names":["createRefHistory","history","createSnapshotHistory","opts","watch","next","canUndo","useReadable","canRedo","computed","fn"],"sources":["../src/ref-history.ts"],"sourcesContent":["import { createSnapshotHistory } from '@inkbar/core'\nimport { computed, watch, type Ref } from 'vue'\n\nimport { useReadable } from './use-readable'\n\nimport type { InkHistory } from './context'\nimport type { Annotation } from '@inkbar/core'\n\nexport interface RefHistoryOptions {\n /** The host's list (the `annotations` v-model). Undefined when the host does not control it. */\n source: () => readonly Annotation[] | undefined\n /** Proposes a list to the host; the step only counts once the host applies it. */\n apply: (list: Annotation[]) => void\n enabled: Readonly<Ref<boolean>>\n limit?: number\n}\n\n/**\n * Snapshot undo and redo over a host-owned annotation list, for controlled hosts. The stacks\n * live in core's `createSnapshotHistory`; this wrapper feeds it from a watch on the host's list\n * and exposes refs.\n */\nexport function createRefHistory(opts: RefHistoryOptions): InkHistory {\n const history = createSnapshotHistory({\n apply: opts.apply,\n enabled: () => opts.enabled.value,\n ...(opts.limit === undefined ? {} : { limit: opts.limit }),\n })\n // Seeds the current list; later changes are steps.\n history.observe(opts.source())\n watch(opts.source, (next) => history.observe(next))\n const canUndo = useReadable(history.canUndo, false)\n const canRedo = useReadable(history.canRedo, false)\n return {\n canUndo: computed(() => opts.enabled.value && canUndo.value),\n canRedo: computed(() => opts.enabled.value && canRedo.value),\n undo: () => history.undo(),\n redo: () => history.redo(),\n clear: () => history.clear(),\n batch: (fn) => history.batch(fn),\n }\n}\n"],"mappings":";;;;AAsBA,SAAgBA,EAAiB,GAAqC;CACpE,IAAMC,IAAUC,EAAsB;EACpC,OAAOC,EAAK;EACZ,eAAeA,EAAK,QAAQ;EAC5B,GAAIA,EAAK,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAOA,EAAK,MAAM;CAC1D,CAAC;CAGD,AADAF,EAAQ,QAAQE,EAAK,OAAO,CAAC,GAC7BC,EAAMD,EAAK,SAAS,MAASF,EAAQ,QAAQI,CAAI,CAAC;CAClD,IAAMC,IAAUC,EAAYN,EAAQ,SAAS,EAAK,GAC5CO,IAAUD,EAAYN,EAAQ,SAAS,EAAK;CAClD,OAAO;EACL,SAASQ,QAAeN,EAAK,QAAQ,SAASG,EAAQ,KAAK;EAC3D,SAASG,QAAeN,EAAK,QAAQ,SAASK,EAAQ,KAAK;EAC3D,YAAYP,EAAQ,KAAK;EACzB,YAAYA,EAAQ,KAAK;EACzB,aAAaA,EAAQ,MAAM;EAC3B,QAAQ,MAAOA,EAAQ,MAAMS,CAAE;CACjC;AACF"}
1
+ {"version":3,"file":"ref-history.js","names":["createRefHistory","history","createSnapshotHistory","opts","watch","next","detach","store","onScopeDispose","canUndo","useReadable","canRedo","computed","fn"],"sources":["../src/ref-history.ts"],"sourcesContent":["import { createSnapshotHistory } from '@inkbar/core'\nimport { computed, onScopeDispose, watch, type Ref } from 'vue'\n\nimport { useReadable } from './use-readable'\n\nimport type { InkHistory } from './context'\nimport type { Annotation, AnnotationStore } from '@inkbar/core'\n\nexport interface RefHistoryOptions {\n /** The host's list (the `annotations` v-model). Undefined when the host does not control it. */\n source: () => readonly Annotation[] | undefined\n /** Proposes a list to the host; the step only counts once the host applies it. */\n apply: (list: Annotation[]) => void\n enabled: Readonly<Ref<boolean>>\n /**\n * The open document's controlled store, if any. Its user edits run the plugins' reactions\n * inside the edit's step, with or without `enabled`.\n */\n store?: () => AnnotationStore | null | undefined\n limit?: number\n}\n\nexport interface RefHistory extends InkHistory {\n /** Runs the reactions for the store's user edits; returns a function that detaches it. */\n attach(store: AnnotationStore): () => void\n}\n\n/**\n * Snapshot undo and redo over a host-owned annotation list, for controlled hosts. The stacks\n * live in core's `createSnapshotHistory`; this wrapper feeds it from a watch on the host's list\n * and exposes refs. Plugin stores it tracks are snapshotted with each step.\n */\nexport function createRefHistory(opts: RefHistoryOptions): RefHistory {\n const history = createSnapshotHistory({\n apply: opts.apply,\n enabled: () => opts.enabled.value,\n ...(opts.limit === undefined ? {} : { limit: opts.limit }),\n })\n // Seeds the current list; later changes are steps.\n history.observe(opts.source())\n watch(opts.source, (next) => history.observe(next))\n if (opts.store) {\n // Sync, so the store is attached before anyone can edit through it.\n let detach: (() => void) | undefined\n watch(\n opts.store,\n (store) => {\n detach?.()\n detach = store ? history.attach(store) : undefined\n },\n { immediate: true, flush: 'sync' }\n )\n onScopeDispose(() => detach?.())\n }\n const canUndo = useReadable(history.canUndo, false)\n const canRedo = useReadable(history.canRedo, false)\n return {\n canUndo: computed(() => opts.enabled.value && canUndo.value),\n canRedo: computed(() => opts.enabled.value && canRedo.value),\n undo: () => history.undo(),\n redo: () => history.redo(),\n clear: () => history.clear(),\n batch: (fn) => history.batch(fn),\n track: (store) => history.track(store),\n react: (fn) => history.react(fn),\n attach: (store) => history.attach(store),\n }\n}\n"],"mappings":";;;;AAgCA,SAAgBA,EAAiB,GAAqC;CACpE,IAAMC,IAAUC,EAAsB;EACpC,OAAOC,EAAK;EACZ,eAAeA,EAAK,QAAQ;EAC5B,GAAIA,EAAK,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,OAAOA,EAAK,MAAM;CAC1D,CAAC;CAID,IAFAF,EAAQ,QAAQE,EAAK,OAAO,CAAC,GAC7BC,EAAMD,EAAK,SAAS,MAASF,EAAQ,QAAQI,CAAI,CAAC,GAC9CF,EAAK,OAAO;EAEd,IAAIG;EASJ,AARAF,EACED,EAAK,QACJ,MAAU;GAET,AADAG,IAAS,GACT,IAASC,IAAQN,EAAQ,OAAOM,CAAK,IAAI,KAAA;EAC3C,GACA;GAAE,WAAW;GAAM,OAAO;EAAO,CACnC,GACAC,QAAqBF,IAAS,CAAC;CACjC;CACA,IAAMG,IAAUC,EAAYT,EAAQ,SAAS,EAAK,GAC5CU,IAAUD,EAAYT,EAAQ,SAAS,EAAK;CAClD,OAAO;EACL,SAASW,QAAeT,EAAK,QAAQ,SAASM,EAAQ,KAAK;EAC3D,SAASG,QAAeT,EAAK,QAAQ,SAASQ,EAAQ,KAAK;EAC3D,YAAYV,EAAQ,KAAK;EACzB,YAAYA,EAAQ,KAAK;EACzB,aAAaA,EAAQ,MAAM;EAC3B,QAAQ,MAAOA,EAAQ,MAAMY,CAAE;EAC/B,QAAQ,MAAUZ,EAAQ,MAAMM,CAAK;EACrC,QAAQ,MAAON,EAAQ,MAAMY,CAAE;EAC/B,SAAS,MAAUZ,EAAQ,OAAOM,CAAK;CACzC;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkbar/vue",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Vue 3 components and composables for Inkbar, the browser PDF viewer and editor.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://inkbar.dev",
@@ -24,17 +24,17 @@
24
24
  "./package.json": "./package.json"
25
25
  },
26
26
  "dependencies": {
27
- "@inkbar/icons": "^0.5.0",
27
+ "@inkbar/icons": "^0.6.0",
28
28
  "reka-ui": "^2.11.0"
29
29
  },
30
30
  "peerDependencies": {
31
- "@inkbar/core": "^0.5.0",
31
+ "@inkbar/core": "^0.6.0",
32
32
  "vue": "^3.5.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@inkbar/core": "0.5.0",
35
+ "@inkbar/core": "0.6.0",
36
36
  "@inkbar/fixtures": "0.0.0",
37
- "@inkbar/theme": "0.5.0",
37
+ "@inkbar/theme": "0.6.0",
38
38
  "@playwright/experimental-ct-vue": "1.62.1",
39
39
  "@playwright/test": "1.62.1",
40
40
  "@vitejs/plugin-vue": "^6.0.10",