@inkbar/vue 0.4.0 → 0.5.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.
- package/README.md +3 -5
- package/dist/components/InkAnnotation.js.map +1 -1
- package/dist/components/InkAnnotation.vue.d.ts.map +1 -1
- package/dist/components/InkAnnotation.vue_vue_type_script_setup_true_lang.js +16 -24
- package/dist/components/InkAnnotation.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkColorMenu.js.map +1 -1
- package/dist/components/InkColorMenu.vue.d.ts +2 -0
- package/dist/components/InkColorMenu.vue.d.ts.map +1 -1
- package/dist/components/InkColorMenu.vue_vue_type_script_setup_true_lang.js +3 -2
- package/dist/components/InkColorMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkHighlightMenu.js.map +1 -1
- package/dist/components/InkHighlightMenu.vue.d.ts +2 -2
- package/dist/components/InkHighlightMenu.vue.d.ts.map +1 -1
- package/dist/components/InkHighlightMenu.vue_vue_type_script_setup_true_lang.js +118 -108
- package/dist/components/InkHighlightMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkRoot.js.map +1 -1
- package/dist/components/InkRoot.vue.d.ts +408 -424
- package/dist/components/InkRoot.vue.d.ts.map +1 -1
- package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js +33 -27
- package/dist/components/InkRoot.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkShapeMenu.js.map +1 -1
- package/dist/components/InkShapeMenu.vue.d.ts +2 -2
- package/dist/components/InkShapeMenu.vue.d.ts.map +1 -1
- package/dist/components/InkShapeMenu.vue_vue_type_script_setup_true_lang.js +99 -91
- package/dist/components/InkShapeMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkSignatureMenu.js.map +1 -1
- package/dist/components/InkSignatureMenu.vue.d.ts +2 -2
- package/dist/components/InkSignatureMenu.vue.d.ts.map +1 -1
- package/dist/components/InkSignatureMenu.vue_vue_type_script_setup_true_lang.js +156 -151
- package/dist/components/InkSignatureMenu.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/components/InkViewport.js.map +1 -1
- package/dist/components/InkViewport.vue.d.ts.map +1 -1
- package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js +9 -2
- package/dist/components/InkViewport.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/composables/useAnnotations.d.ts +915 -1386
- package/dist/composables/useAnnotations.d.ts.map +1 -1
- package/dist/composables/useAnnotations.js +13 -18
- package/dist/composables/useAnnotations.js.map +1 -1
- package/dist/context.d.ts +8 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/package.json +5 -5
- package/dist/components/InkSuggestionCard.js +0 -7
- package/dist/components/InkSuggestionCard.js.map +0 -1
- package/dist/components/InkSuggestionCard.vue.d.ts +0 -16
- package/dist/components/InkSuggestionCard.vue.d.ts.map +0 -1
- package/dist/components/InkSuggestionCard.vue_vue_type_script_setup_true_lang.js +0 -85
- package/dist/components/InkSuggestionCard.vue_vue_type_script_setup_true_lang.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkSignatureMenu.js","names":["_sfc_main","InkSignatureMenu_vue_vue_type_script_setup_true_lang_default","InkSignatureMenu_default"],"sources":["../../src/components/InkSignatureMenu.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * A split button for the signature tool. The main part activates the tool with the chosen\n * signature, or opens the menu when none is chosen; the chevron opens the saved signatures as\n * previews, each with a remove button, and \"Create signature\", which opens\n * `InkSignatureDialog`. Choosing a signature switches to the tool with it.\n */\nimport {\n focusInitialMenuItem,\n handleMenuKeys,\n menuItems,\n SIGNATURE_LABELS,\n signatureMenuModel,\n signaturePreview,\n} from '@inkbar/core/dom'\nimport { ChevronDown, Plus, Signature, Trash2 } from '@inkbar/icons'\nimport {\n PopoverContent,\n PopoverPortal,\n PopoverRoot,\n PopoverTrigger,\n ToolbarButton,\n} from 'reka-ui'\nimport { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n\nimport { useTool } from '../composables/useTool'\nimport { useToolOptions } from '../composables/useToolOptions'\nimport { useInkContext } from '../context'\nimport { useReadable } from '../use-readable'\n\nimport InkIcon from './InkIcon.vue'\nimport InkSignatureDialog from './InkSignatureDialog.vue'\n\nimport type { SignatureOptions, SignatureTemplate } from '@inkbar/core'\n\nconst props = defineProps<{\n /** The fonts the dialog's Type tab offers. Default: InkRoot's `signatureFonts`. */\n fonts?: readonly string[] | undefined\n}>()\n\nconst NO_TEMPLATES: readonly SignatureTemplate[] = []\n\nconst { tool, setTool } = useTool()\nconst { options, setOptions } = useToolOptions<SignatureOptions>('signature')\nconst ctx = useInkContext('InkSignatureMenu')\nconst templates = useReadable(() => ctx.signatures.value.templates, NO_TEMPLATES)\nconst removeError = useReadable(() => ctx.signatures.value.removeError, undefined)\nconst model = computed(() => signatureMenuModel(templates.value, options.value))\nconst active = computed(() => tool.value === 'signature')\nconst open = ref(false)\nconst creating = ref(false)\n// An old removal error is not news when the menu opens again.\nwatch(open, (isOpen) => {\n if (isOpen) ctx.signatures.value.clearRemoveError()\n})\nconst main = useTemplateRef<{ $el: HTMLElement }>('main')\n\n/** A saved signature drawn small: ink as filled outlines. */\nconst previews = computed(() =>\n model.value.items.map((item) =>\n item.template.kind === 'ink' ? signaturePreview(item.template) : null\n )\n)\n\n/** ArrowDown opens on the first item; a click opens on the checked one. */\nlet focusFirst = false\n/** Set while the menu closes for the dialog, which takes focus instead of the trigger. */\nlet toDialog = false\n\nfunction onTriggerKeydown(e: KeyboardEvent): void {\n if (e.key !== 'ArrowDown' || e.defaultPrevented || open.value) return\n e.preventDefault()\n focusFirst = true\n open.value = true\n}\n\nconst panel = (): HTMLElement | null =>\n document.querySelector<HTMLElement>('[data-ink-menu=\"signature\"] [role=\"menu\"]')\n\nfunction onOpenAutoFocus(e: Event): void {\n e.preventDefault()\n const menu = panel()\n if (menu) {\n if (focusFirst) menuItems(menu)[0]?.focus({ preventScroll: true })\n else focusInitialMenuItem(menu)\n }\n focusFirst = false\n}\n\nfunction onCloseAutoFocus(e: Event): void {\n if (toDialog) e.preventDefault()\n toDialog = false\n}\n\nfunction onMain(): void {\n if (model.value.selected) setTool('signature')\n else open.value = true\n}\n\nfunction choose(id: string): void {\n setOptions({ templateId: id })\n setTool('signature')\n open.value = false\n}\n\n/** Removes a template; focus moves to the signature now in its row, else \"Create signature\". */\nfunction remove(id: string, row: number): void {\n ctx.signatures.value.remove(id).then(\n async () => {\n await nextTick()\n const menu = panel()\n if (!menu) return\n const rows = menu.querySelectorAll<HTMLElement>('.ink-signature-item')\n const next =\n rows[Math.min(row, rows.length - 1)] ??\n menu.querySelector<HTMLElement>('[data-ink-signature-create]')\n next?.focus({ preventScroll: true })\n },\n () => {\n // The host's store refused: the signature stays.\n }\n )\n}\n\nfunction create(): void {\n toDialog = true\n open.value = false\n creating.value = true\n}\n\nfunction onDialogCloseAutoFocus(e: Event): void {\n e.preventDefault()\n main.value?.$el.focus({ preventScroll: true })\n}\n\n// Reka's typed props stop at its own; ARIA and listeners go through bound objects.\nconst mainAttrs = computed(() => ({\n 'aria-pressed': String(active.value),\n 'aria-label': SIGNATURE_LABELS.sign,\n title: SIGNATURE_LABELS.sign,\n onClick: onMain,\n}))\nconst triggerAttrs = {\n 'aria-label': SIGNATURE_LABELS.trigger,\n title: SIGNATURE_LABELS.trigger,\n 'aria-haspopup': 'menu' as const,\n onKeydown: onTriggerKeydown,\n}\nconst menuAttrs = { 'aria-label': SIGNATURE_LABELS.menu }\nconst innerAttrs = {\n role: 'menu',\n 'aria-label': SIGNATURE_LABELS.menu,\n onKeydown: (e: KeyboardEvent) => handleMenuKeys(e, e.currentTarget as HTMLElement),\n}\n</script>\n\n<template>\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.sign\"\n class=\"ink-split-button ink-signature-menu\"\n data-ink-signature-menu\n >\n <ToolbarButton\n ref=\"main\"\n class=\"ink-tool-button ink-signature-button\"\n data-ink-tool-button\n data-ink-signature-button\n data-tool=\"signature\"\n :data-state=\"active ? 'on' : 'off'\"\n v-bind=\"mainAttrs\"\n >\n <slot :active=\"active\"><InkIcon :icon=\"Signature\" /></slot>\n </ToolbarButton>\n <PopoverRoot v-model:open=\"open\">\n <ToolbarButton as-child>\n <PopoverTrigger as-child>\n <button\n type=\"button\"\n class=\"ink-menu-trigger ink-signature-menu-trigger\"\n data-ink-signature-menu-trigger\n :data-state=\"open ? 'open' : 'closed'\"\n v-bind=\"triggerAttrs\"\n >\n <InkIcon :icon=\"ChevronDown\" />\n </button>\n </PopoverTrigger>\n </ToolbarButton>\n <PopoverPortal>\n <PopoverContent\n class=\"ink-select-content ink-menu-content\"\n data-ink-select-content\n data-ink-menu=\"signature\"\n side=\"bottom\"\n align=\"start\"\n :side-offset=\"4\"\n :collision-padding=\"8\"\n v-bind=\"menuAttrs\"\n @open-auto-focus=\"onOpenAutoFocus\"\n @close-auto-focus=\"onCloseAutoFocus\"\n >\n <div v-bind=\"innerAttrs\">\n <template v-if=\"model.items.length > 0\">\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.saved\"\n class=\"ink-signature-list\"\n data-ink-menu-columns=\"2\"\n >\n <template v-for=\"(item, row) in model.items\" :key=\"item.id\">\n <button\n type=\"button\"\n role=\"menuitemradio\"\n :aria-checked=\"item.checked\"\n :aria-label=\"item.label\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-item\"\n data-ink-select-item\n :data-key=\"item.id\"\n :data-state=\"item.checked ? 'checked' : 'unchecked'\"\n @click=\"choose(item.id)\"\n >\n <span class=\"ink-signature-preview\" :data-kind=\"item.template.kind\">\n <img\n v-if=\"item.template.kind === 'image'\"\n :src=\"item.template.imagedata\"\n alt=\"\"\n draggable=\"false\"\n />\n <svg v-else :viewBox=\"previews[row]?.viewBox\" aria-hidden=\"true\">\n <path\n v-for=\"(d, i) in previews[row]?.paths ?? []\"\n :key=\"i\"\n :d=\"d\"\n fill=\"currentColor\"\n />\n </svg>\n </span>\n </button>\n <button\n type=\"button\"\n role=\"menuitem\"\n :aria-label=\"item.removeLabel\"\n :title=\"item.removeLabel\"\n tabindex=\"-1\"\n class=\"ink-menu-item ink-signature-remove\"\n data-ink-signature-remove\n :data-key=\"item.id\"\n @click=\"remove(item.id, row)\"\n >\n <InkIcon :icon=\"Trash2\" :size=\"16\" />\n </button>\n </template>\n </div>\n <div role=\"separator\" class=\"ink-select-separator\" />\n </template>\n <button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-create\"\n data-ink-select-item\n data-ink-signature-create\n @click=\"create\"\n >\n <InkIcon :icon=\"Plus\" :size=\"16\" />\n {{ SIGNATURE_LABELS.create }}\n </button>\n <p\n v-if=\"removeError\"\n class=\"ink-field-error ink-signature-remove-error\"\n role=\"alert\"\n data-ink-signature-remove-error\n >\n {{ removeError }}\n </p>\n </div>\n </PopoverContent>\n </PopoverPortal>\n </PopoverRoot>\n <InkSignatureDialog\n v-model:open=\"creating\"\n :fonts=\"props.fonts\"\n @close-auto-focus=\"onDialogCloseAutoFocus\"\n />\n </div>\n</template>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"InkSignatureMenu.js","names":["_sfc_main","InkSignatureMenu_vue_vue_type_script_setup_true_lang_default","InkSignatureMenu_default"],"sources":["../../src/components/InkSignatureMenu.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * A split button for the signature tool. The main part activates the tool with the chosen\n * signature, or opens the menu when none is chosen; the chevron opens the saved signatures as\n * previews, each with a remove button, and \"Create signature\", which opens\n * `InkSignatureDialog`. Choosing a signature switches to the tool with it.\n */\nimport {\n focusInitialMenuItem,\n handleMenuKeys,\n menuItems,\n SIGNATURE_LABELS,\n signatureMenuModel,\n signaturePreview,\n} from '@inkbar/core/dom'\nimport { ChevronDown, Plus, Signature, Trash2 } from '@inkbar/icons'\nimport {\n PopoverAnchor,\n PopoverContent,\n PopoverPortal,\n PopoverRoot,\n PopoverTrigger,\n ToolbarButton,\n} from 'reka-ui'\nimport { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n\nimport { useTool } from '../composables/useTool'\nimport { useToolOptions } from '../composables/useToolOptions'\nimport { useInkContext } from '../context'\nimport { useReadable } from '../use-readable'\n\nimport InkIcon from './InkIcon.vue'\nimport InkSignatureDialog from './InkSignatureDialog.vue'\n\nimport type { SignatureOptions, SignatureTemplate } from '@inkbar/core'\n\ndefineOptions({ inheritAttrs: false })\nconst props = defineProps<{\n /** The fonts the dialog's Type tab offers. Default: InkRoot's `signatureFonts`. */\n fonts?: readonly string[] | undefined\n}>()\n\nconst NO_TEMPLATES: readonly SignatureTemplate[] = []\n\nconst { tool, setTool } = useTool()\nconst { options, setOptions } = useToolOptions<SignatureOptions>('signature')\nconst ctx = useInkContext('InkSignatureMenu')\nconst templates = useReadable(() => ctx.signatures.value.templates, NO_TEMPLATES)\nconst removeError = useReadable(() => ctx.signatures.value.removeError, undefined)\nconst model = computed(() => signatureMenuModel(templates.value, options.value))\nconst active = computed(() => tool.value === 'signature')\nconst open = ref(false)\nconst creating = ref(false)\n// An old removal error is not news when the menu opens again.\nwatch(open, (isOpen) => {\n if (isOpen) ctx.signatures.value.clearRemoveError()\n})\nconst main = useTemplateRef<{ $el: HTMLElement }>('main')\n\n/** A saved signature drawn small: ink as filled outlines. */\nconst previews = computed(() =>\n model.value.items.map((item) =>\n item.template.kind === 'ink' ? signaturePreview(item.template) : null\n )\n)\n\n/** ArrowDown opens on the first item; a click opens on the checked one. */\nlet focusFirst = false\n/** Set while the menu closes for the dialog, which takes focus instead of the trigger. */\nlet toDialog = false\n\nfunction onTriggerKeydown(e: KeyboardEvent): void {\n if (e.key !== 'ArrowDown' || e.defaultPrevented || open.value) return\n e.preventDefault()\n focusFirst = true\n open.value = true\n}\n\nconst panel = (): HTMLElement | null =>\n document.querySelector<HTMLElement>('[data-ink-menu=\"signature\"] [role=\"menu\"]')\n\nfunction onOpenAutoFocus(e: Event): void {\n e.preventDefault()\n const menu = panel()\n if (menu) {\n if (focusFirst) menuItems(menu)[0]?.focus({ preventScroll: true })\n else focusInitialMenuItem(menu)\n }\n focusFirst = false\n}\n\nfunction onCloseAutoFocus(e: Event): void {\n if (toDialog) e.preventDefault()\n toDialog = false\n}\n\nfunction onMain(): void {\n if (model.value.selected) setTool('signature')\n else open.value = true\n}\n\nfunction choose(id: string): void {\n setOptions({ templateId: id })\n setTool('signature')\n open.value = false\n}\n\n/** Removes a template; focus moves to the signature now in its row, else \"Create signature\". */\nfunction remove(id: string, row: number): void {\n ctx.signatures.value.remove(id).then(\n async () => {\n await nextTick()\n const menu = panel()\n if (!menu) return\n const rows = menu.querySelectorAll<HTMLElement>('.ink-signature-item')\n const next =\n rows[Math.min(row, rows.length - 1)] ??\n menu.querySelector<HTMLElement>('[data-ink-signature-create]')\n next?.focus({ preventScroll: true })\n },\n () => {\n // The host's store refused: the signature stays.\n }\n )\n}\n\nfunction create(): void {\n toDialog = true\n open.value = false\n creating.value = true\n}\n\nfunction onDialogCloseAutoFocus(e: Event): void {\n e.preventDefault()\n main.value?.$el.focus({ preventScroll: true })\n}\n\n// Reka's typed props stop at its own; ARIA and listeners go through bound objects.\nconst mainAttrs = computed(() => ({\n 'aria-pressed': String(active.value),\n 'aria-label': SIGNATURE_LABELS.sign,\n title: SIGNATURE_LABELS.sign,\n onClick: onMain,\n}))\nconst triggerAttrs = {\n 'aria-label': SIGNATURE_LABELS.trigger,\n title: SIGNATURE_LABELS.trigger,\n 'aria-haspopup': 'menu' as const,\n onKeydown: onTriggerKeydown,\n}\nconst menuAttrs = { 'aria-label': SIGNATURE_LABELS.menu }\nconst innerAttrs = {\n role: 'menu',\n 'aria-label': SIGNATURE_LABELS.menu,\n onKeydown: (e: KeyboardEvent) => handleMenuKeys(e, e.currentTarget as HTMLElement),\n}\n</script>\n\n<template>\n <PopoverRoot v-model:open=\"open\">\n <PopoverAnchor as-child>\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.sign\"\n class=\"ink-split-button ink-signature-menu\"\n data-ink-signature-menu\n v-bind=\"$attrs\"\n >\n <ToolbarButton\n ref=\"main\"\n class=\"ink-tool-button ink-signature-button\"\n data-ink-tool-button\n data-ink-signature-button\n data-tool=\"signature\"\n :data-state=\"active ? 'on' : 'off'\"\n v-bind=\"mainAttrs\"\n >\n <slot :active=\"active\"><InkIcon :icon=\"Signature\" /></slot>\n </ToolbarButton>\n <ToolbarButton as-child>\n <PopoverTrigger as-child>\n <button\n type=\"button\"\n class=\"ink-menu-trigger ink-signature-menu-trigger\"\n data-ink-signature-menu-trigger\n :data-state=\"open ? 'open' : 'closed'\"\n v-bind=\"triggerAttrs\"\n >\n <InkIcon :icon=\"ChevronDown\" />\n </button>\n </PopoverTrigger>\n </ToolbarButton>\n <PopoverPortal>\n <PopoverContent\n class=\"ink-select-content ink-menu-content\"\n data-ink-select-content\n data-ink-menu=\"signature\"\n side=\"bottom\"\n align=\"start\"\n :side-offset=\"4\"\n :collision-padding=\"8\"\n v-bind=\"menuAttrs\"\n @open-auto-focus=\"onOpenAutoFocus\"\n @close-auto-focus=\"onCloseAutoFocus\"\n >\n <div v-bind=\"innerAttrs\">\n <template v-if=\"model.items.length > 0\">\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.saved\"\n class=\"ink-signature-list\"\n data-ink-menu-columns=\"2\"\n >\n <template v-for=\"(item, row) in model.items\" :key=\"item.id\">\n <button\n type=\"button\"\n role=\"menuitemradio\"\n :aria-checked=\"item.checked\"\n :aria-label=\"item.label\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-item\"\n data-ink-select-item\n :data-key=\"item.id\"\n :data-state=\"item.checked ? 'checked' : 'unchecked'\"\n @click=\"choose(item.id)\"\n >\n <span class=\"ink-signature-preview\" :data-kind=\"item.template.kind\">\n <img\n v-if=\"item.template.kind === 'image'\"\n :src=\"item.template.imagedata\"\n alt=\"\"\n draggable=\"false\"\n />\n <svg v-else :viewBox=\"previews[row]?.viewBox\" aria-hidden=\"true\">\n <path\n v-for=\"(d, i) in previews[row]?.paths ?? []\"\n :key=\"i\"\n :d=\"d\"\n fill=\"currentColor\"\n />\n </svg>\n </span>\n </button>\n <button\n type=\"button\"\n role=\"menuitem\"\n :aria-label=\"item.removeLabel\"\n :title=\"item.removeLabel\"\n tabindex=\"-1\"\n class=\"ink-menu-item ink-signature-remove\"\n data-ink-signature-remove\n :data-key=\"item.id\"\n @click=\"remove(item.id, row)\"\n >\n <InkIcon :icon=\"Trash2\" :size=\"16\" />\n </button>\n </template>\n </div>\n <div role=\"separator\" class=\"ink-select-separator\" />\n </template>\n <button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-create\"\n data-ink-select-item\n data-ink-signature-create\n @click=\"create\"\n >\n <InkIcon :icon=\"Plus\" :size=\"16\" />\n {{ SIGNATURE_LABELS.create }}\n </button>\n <p\n v-if=\"removeError\"\n class=\"ink-field-error ink-signature-remove-error\"\n role=\"alert\"\n data-ink-signature-remove-error\n >\n {{ removeError }}\n </p>\n </div>\n </PopoverContent>\n </PopoverPortal>\n <InkSignatureDialog\n v-model:open=\"creating\"\n :fonts=\"props.fonts\"\n @close-auto-focus=\"onDialogCloseAutoFocus\"\n />\n </div>\n </PopoverAnchor>\n </PopoverRoot>\n</template>\n"],"mappings":""}
|
|
@@ -2,11 +2,11 @@ type __VLS_Props = {
|
|
|
2
2
|
/** The fonts the dialog's Type tab offers. Default: InkRoot's `signatureFonts`. */
|
|
3
3
|
fonts?: readonly string[] | undefined;
|
|
4
4
|
};
|
|
5
|
-
declare var
|
|
5
|
+
declare var __VLS_21: {
|
|
6
6
|
active: boolean;
|
|
7
7
|
};
|
|
8
8
|
type __VLS_Slots = {} & {
|
|
9
|
-
default?: (props: typeof
|
|
9
|
+
default?: (props: typeof __VLS_21) => any;
|
|
10
10
|
};
|
|
11
11
|
declare const __VLS_base: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
12
12
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkSignatureMenu.vue.d.ts","sourceRoot":"","sources":["../../src/components/InkSignatureMenu.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InkSignatureMenu.vue.d.ts","sourceRoot":"","sources":["../../src/components/InkSignatureMenu.vue"],"names":[],"mappings":"AA2UA,KAAK,WAAW,GAAG;IACjB,mFAAmF;IACnF,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAA;CACtC,CAAC;AA2dF,QAAA,IAAI,QAAQ;;CAAY,CAAC;AACzB,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAGhD,QAAA,MAAM,UAAU,kSAEd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -4,210 +4,215 @@ import { useTool as n } from "../composables/useTool.js";
|
|
|
4
4
|
import { useToolOptions as r } from "../composables/useToolOptions.js";
|
|
5
5
|
import i from "./InkIcon.js";
|
|
6
6
|
import ee from "./InkSignatureDialog.js";
|
|
7
|
-
import { Fragment as a, computed as o, createCommentVNode as s, createElementBlock as c, createElementVNode as l, createTextVNode as
|
|
8
|
-
import { SIGNATURE_LABELS as b, focusInitialMenuItem as
|
|
9
|
-
import { PopoverContent as
|
|
10
|
-
import { ChevronDown as
|
|
7
|
+
import { Fragment as a, computed as o, createBlock as te, createCommentVNode as s, createElementBlock as c, createElementVNode as l, createTextVNode as u, createVNode as d, defineComponent as f, guardReactiveProps as ne, mergeProps as p, nextTick as re, normalizeProps as ie, openBlock as m, ref as h, renderList as g, renderSlot as ae, toDisplayString as _, unref as v, useTemplateRef as oe, watch as se, withCtx as y } from "vue";
|
|
8
|
+
import { SIGNATURE_LABELS as b, focusInitialMenuItem as ce, handleMenuKeys as le, menuItems as ue, signatureMenuModel as de, signaturePreview as fe } from "@inkbar/core/dom";
|
|
9
|
+
import { PopoverAnchor as pe, PopoverContent as x, PopoverPortal as S, PopoverRoot as C, PopoverTrigger as w, ToolbarButton as T } from "reka-ui";
|
|
10
|
+
import { ChevronDown as E, Plus as D, Signature as O, Trash2 as k } from "@inkbar/icons";
|
|
11
11
|
//#region src/components/InkSignatureMenu.vue?vue&type=script&setup=true&lang.ts
|
|
12
|
-
var
|
|
12
|
+
var A = ["aria-label"], j = ["data-state"], M = ["aria-label"], N = [
|
|
13
13
|
"aria-checked",
|
|
14
14
|
"aria-label",
|
|
15
15
|
"data-key",
|
|
16
16
|
"data-state",
|
|
17
17
|
"onClick"
|
|
18
|
-
],
|
|
18
|
+
], P = ["data-kind"], F = ["src"], I = ["viewBox"], L = ["d"], R = [
|
|
19
19
|
"aria-label",
|
|
20
20
|
"title",
|
|
21
21
|
"data-key",
|
|
22
22
|
"onClick"
|
|
23
|
-
],
|
|
23
|
+
], z = {
|
|
24
24
|
key: 1,
|
|
25
25
|
class: "ink-field-error ink-signature-remove-error",
|
|
26
26
|
role: "alert",
|
|
27
27
|
"data-ink-signature-remove-error": ""
|
|
28
|
-
},
|
|
28
|
+
}, B = /*@__PURE__*/ f({
|
|
29
|
+
inheritAttrs: !1,
|
|
29
30
|
__name: "InkSignatureMenu",
|
|
30
31
|
props: { fonts: {} },
|
|
31
|
-
setup(
|
|
32
|
-
let
|
|
33
|
-
|
|
32
|
+
setup(f) {
|
|
33
|
+
let B = f, me = [], { tool: he, setTool: V } = n(), { options: ge, setOptions: _e } = r("signature"), H = e("InkSignatureMenu"), ve = t(() => H.signatures.value.templates, me), U = t(() => H.signatures.value.removeError, void 0), W = o(() => de(ve.value, ge.value)), G = o(() => he.value === "signature"), K = h(!1), q = h(!1);
|
|
34
|
+
se(K, (e) => {
|
|
34
35
|
e && H.signatures.value.clearRemoveError();
|
|
35
36
|
});
|
|
36
|
-
let J =
|
|
37
|
-
function
|
|
37
|
+
let J = oe("main"), Y = o(() => W.value.items.map((e) => e.template.kind === "ink" ? fe(e.template) : null)), X = !1, Z = !1;
|
|
38
|
+
function ye(e) {
|
|
38
39
|
e.key !== "ArrowDown" || e.defaultPrevented || K.value || (e.preventDefault(), X = !0, K.value = !0);
|
|
39
40
|
}
|
|
40
41
|
let Q = () => document.querySelector("[data-ink-menu=\"signature\"] [role=\"menu\"]");
|
|
41
|
-
function
|
|
42
|
+
function be(e) {
|
|
42
43
|
e.preventDefault();
|
|
43
44
|
let t = Q();
|
|
44
|
-
t && (X ?
|
|
45
|
+
t && (X ? ue(t)[0]?.focus({ preventScroll: !0 }) : ce(t)), X = !1;
|
|
45
46
|
}
|
|
46
|
-
function
|
|
47
|
+
function xe(e) {
|
|
47
48
|
Z && e.preventDefault(), Z = !1;
|
|
48
49
|
}
|
|
49
|
-
function
|
|
50
|
+
function Se() {
|
|
50
51
|
W.value.selected ? V("signature") : K.value = !0;
|
|
51
52
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
53
|
+
function Ce(e) {
|
|
54
|
+
_e({ templateId: e }), V("signature"), K.value = !1;
|
|
54
55
|
}
|
|
55
|
-
function
|
|
56
|
+
function $(e, t) {
|
|
56
57
|
H.signatures.value.remove(e).then(async () => {
|
|
57
|
-
await
|
|
58
|
+
await re();
|
|
58
59
|
let e = Q();
|
|
59
60
|
if (!e) return;
|
|
60
61
|
let n = e.querySelectorAll(".ink-signature-item");
|
|
61
62
|
(n[Math.min(t, n.length - 1)] ?? e.querySelector("[data-ink-signature-create]"))?.focus({ preventScroll: !0 });
|
|
62
63
|
}, () => {});
|
|
63
64
|
}
|
|
64
|
-
function
|
|
65
|
+
function we() {
|
|
65
66
|
Z = !0, K.value = !1, q.value = !0;
|
|
66
67
|
}
|
|
67
|
-
function
|
|
68
|
+
function Te(e) {
|
|
68
69
|
e.preventDefault(), J.value?.$el.focus({ preventScroll: !0 });
|
|
69
70
|
}
|
|
70
|
-
let
|
|
71
|
+
let Ee = o(() => ({
|
|
71
72
|
"aria-pressed": String(G.value),
|
|
72
73
|
"aria-label": b.sign,
|
|
73
74
|
title: b.sign,
|
|
74
|
-
onClick:
|
|
75
|
-
})),
|
|
75
|
+
onClick: Se
|
|
76
|
+
})), De = {
|
|
76
77
|
"aria-label": b.trigger,
|
|
77
78
|
title: b.trigger,
|
|
78
79
|
"aria-haspopup": "menu",
|
|
79
|
-
onKeydown:
|
|
80
|
-
},
|
|
80
|
+
onKeydown: ye
|
|
81
|
+
}, Oe = { "aria-label": b.menu }, ke = {
|
|
81
82
|
role: "menu",
|
|
82
83
|
"aria-label": b.menu,
|
|
83
|
-
onKeydown: (e) =>
|
|
84
|
+
onKeydown: (e) => le(e, e.currentTarget)
|
|
84
85
|
};
|
|
85
|
-
return (e, t) => (m(),
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
default: y(() => [
|
|
110
|
-
|
|
111
|
-
class: "ink-menu-trigger ink-signature-menu-trigger",
|
|
112
|
-
"data-ink-signature-menu-trigger": "",
|
|
113
|
-
"data-state": K.value ? "open" : "closed"
|
|
114
|
-
}, Te), [u(i, { icon: v(w) }, null, 8, ["icon"])], 16, k)]),
|
|
115
|
-
_: 1
|
|
116
|
-
})]),
|
|
117
|
-
_: 1
|
|
118
|
-
}), u(v(pe), null, {
|
|
119
|
-
default: y(() => [u(v(fe), p({
|
|
120
|
-
class: "ink-select-content ink-menu-content",
|
|
121
|
-
"data-ink-select-content": "",
|
|
122
|
-
"data-ink-menu": "signature",
|
|
123
|
-
side: "bottom",
|
|
124
|
-
align: "start",
|
|
125
|
-
"side-offset": 4,
|
|
126
|
-
"collision-padding": 8
|
|
127
|
-
}, Ee, {
|
|
128
|
-
onOpenAutoFocus: ve,
|
|
129
|
-
onCloseAutoFocus: ye
|
|
130
|
-
}), {
|
|
131
|
-
default: y(() => [l("div", re(f(De)), [
|
|
132
|
-
W.value.items.length > 0 ? (m(), c(a, { key: 0 }, [l("div", {
|
|
133
|
-
role: "group",
|
|
134
|
-
"aria-label": v(b).saved,
|
|
135
|
-
class: "ink-signature-list",
|
|
136
|
-
"data-ink-menu-columns": "2"
|
|
137
|
-
}, [(m(!0), c(a, null, g(W.value.items, (e, t) => (m(), c(a, { key: e.id }, [l("button", {
|
|
138
|
-
type: "button",
|
|
139
|
-
role: "menuitemradio",
|
|
140
|
-
"aria-checked": e.checked,
|
|
141
|
-
"aria-label": e.label,
|
|
142
|
-
tabindex: "-1",
|
|
143
|
-
class: "ink-select-item ink-menu-item ink-signature-item",
|
|
144
|
-
"data-ink-select-item": "",
|
|
145
|
-
"data-key": e.id,
|
|
146
|
-
"data-state": e.checked ? "checked" : "unchecked",
|
|
147
|
-
onClick: (t) => xe(e.id)
|
|
148
|
-
}, [l("span", {
|
|
149
|
-
class: "ink-signature-preview",
|
|
150
|
-
"data-kind": e.template.kind
|
|
151
|
-
}, [e.template.kind === "image" ? (m(), c("img", {
|
|
152
|
-
key: 0,
|
|
153
|
-
src: e.template.imagedata,
|
|
154
|
-
alt: "",
|
|
155
|
-
draggable: "false"
|
|
156
|
-
}, null, 8, N)) : (m(), c("svg", {
|
|
157
|
-
key: 1,
|
|
158
|
-
viewBox: Y.value[t]?.viewBox,
|
|
159
|
-
"aria-hidden": "true"
|
|
160
|
-
}, [(m(!0), c(a, null, g(Y.value[t]?.paths ?? [], (e, t) => (m(), c("path", {
|
|
161
|
-
key: t,
|
|
162
|
-
d: e,
|
|
163
|
-
fill: "currentColor"
|
|
164
|
-
}, null, 8, F))), 128))], 8, P))], 8, M)], 8, j), l("button", {
|
|
165
|
-
type: "button",
|
|
166
|
-
role: "menuitem",
|
|
167
|
-
"aria-label": e.removeLabel,
|
|
168
|
-
title: e.removeLabel,
|
|
169
|
-
tabindex: "-1",
|
|
170
|
-
class: "ink-menu-item ink-signature-remove",
|
|
171
|
-
"data-ink-signature-remove": "",
|
|
172
|
-
"data-key": e.id,
|
|
173
|
-
onClick: (n) => Se(e.id, t)
|
|
174
|
-
}, [u(i, {
|
|
175
|
-
icon: v(D),
|
|
176
|
-
size: 16
|
|
177
|
-
}, null, 8, ["icon"])], 8, I)], 64))), 128))], 8, A), t[2] ||= l("div", {
|
|
178
|
-
role: "separator",
|
|
179
|
-
class: "ink-select-separator"
|
|
180
|
-
}, null, -1)], 64)) : s("", !0),
|
|
181
|
-
l("button", {
|
|
86
|
+
return (e, t) => (m(), te(v(C), {
|
|
87
|
+
open: K.value,
|
|
88
|
+
"onUpdate:open": t[1] ||= (e) => K.value = e
|
|
89
|
+
}, {
|
|
90
|
+
default: y(() => [d(v(pe), { "as-child": "" }, {
|
|
91
|
+
default: y(() => [l("div", p({
|
|
92
|
+
role: "group",
|
|
93
|
+
"aria-label": v(b).sign,
|
|
94
|
+
class: "ink-split-button ink-signature-menu",
|
|
95
|
+
"data-ink-signature-menu": ""
|
|
96
|
+
}, e.$attrs), [
|
|
97
|
+
d(v(T), p({
|
|
98
|
+
ref_key: "main",
|
|
99
|
+
ref: J,
|
|
100
|
+
class: "ink-tool-button ink-signature-button",
|
|
101
|
+
"data-ink-tool-button": "",
|
|
102
|
+
"data-ink-signature-button": "",
|
|
103
|
+
"data-tool": "signature",
|
|
104
|
+
"data-state": G.value ? "on" : "off"
|
|
105
|
+
}, Ee.value), {
|
|
106
|
+
default: y(() => [ae(e.$slots, "default", { active: G.value }, () => [d(i, { icon: v(O) }, null, 8, ["icon"])])]),
|
|
107
|
+
_: 3
|
|
108
|
+
}, 16, ["data-state"]),
|
|
109
|
+
d(v(T), { "as-child": "" }, {
|
|
110
|
+
default: y(() => [d(v(w), { "as-child": "" }, {
|
|
111
|
+
default: y(() => [l("button", p({
|
|
182
112
|
type: "button",
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}, [u(i, {
|
|
190
|
-
icon: v(T),
|
|
191
|
-
size: 16
|
|
192
|
-
}, null, 8, ["icon"]), te(" " + _(v(b).create), 1)]),
|
|
193
|
-
v(U) ? (m(), c("p", L, _(v(U)), 1)) : s("", !0)
|
|
194
|
-
], 16)]),
|
|
113
|
+
class: "ink-menu-trigger ink-signature-menu-trigger",
|
|
114
|
+
"data-ink-signature-menu-trigger": "",
|
|
115
|
+
"data-state": K.value ? "open" : "closed"
|
|
116
|
+
}, De), [d(i, { icon: v(E) }, null, 8, ["icon"])], 16, j)]),
|
|
117
|
+
_: 1
|
|
118
|
+
})]),
|
|
195
119
|
_: 1
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
120
|
+
}),
|
|
121
|
+
d(v(S), null, {
|
|
122
|
+
default: y(() => [d(v(x), p({
|
|
123
|
+
class: "ink-select-content ink-menu-content",
|
|
124
|
+
"data-ink-select-content": "",
|
|
125
|
+
"data-ink-menu": "signature",
|
|
126
|
+
side: "bottom",
|
|
127
|
+
align: "start",
|
|
128
|
+
"side-offset": 4,
|
|
129
|
+
"collision-padding": 8
|
|
130
|
+
}, Oe, {
|
|
131
|
+
onOpenAutoFocus: be,
|
|
132
|
+
onCloseAutoFocus: xe
|
|
133
|
+
}), {
|
|
134
|
+
default: y(() => [l("div", ie(ne(ke)), [
|
|
135
|
+
W.value.items.length > 0 ? (m(), c(a, { key: 0 }, [l("div", {
|
|
136
|
+
role: "group",
|
|
137
|
+
"aria-label": v(b).saved,
|
|
138
|
+
class: "ink-signature-list",
|
|
139
|
+
"data-ink-menu-columns": "2"
|
|
140
|
+
}, [(m(!0), c(a, null, g(W.value.items, (e, t) => (m(), c(a, { key: e.id }, [l("button", {
|
|
141
|
+
type: "button",
|
|
142
|
+
role: "menuitemradio",
|
|
143
|
+
"aria-checked": e.checked,
|
|
144
|
+
"aria-label": e.label,
|
|
145
|
+
tabindex: "-1",
|
|
146
|
+
class: "ink-select-item ink-menu-item ink-signature-item",
|
|
147
|
+
"data-ink-select-item": "",
|
|
148
|
+
"data-key": e.id,
|
|
149
|
+
"data-state": e.checked ? "checked" : "unchecked",
|
|
150
|
+
onClick: (t) => Ce(e.id)
|
|
151
|
+
}, [l("span", {
|
|
152
|
+
class: "ink-signature-preview",
|
|
153
|
+
"data-kind": e.template.kind
|
|
154
|
+
}, [e.template.kind === "image" ? (m(), c("img", {
|
|
155
|
+
key: 0,
|
|
156
|
+
src: e.template.imagedata,
|
|
157
|
+
alt: "",
|
|
158
|
+
draggable: "false"
|
|
159
|
+
}, null, 8, F)) : (m(), c("svg", {
|
|
160
|
+
key: 1,
|
|
161
|
+
viewBox: Y.value[t]?.viewBox,
|
|
162
|
+
"aria-hidden": "true"
|
|
163
|
+
}, [(m(!0), c(a, null, g(Y.value[t]?.paths ?? [], (e, t) => (m(), c("path", {
|
|
164
|
+
key: t,
|
|
165
|
+
d: e,
|
|
166
|
+
fill: "currentColor"
|
|
167
|
+
}, null, 8, L))), 128))], 8, I))], 8, P)], 8, N), l("button", {
|
|
168
|
+
type: "button",
|
|
169
|
+
role: "menuitem",
|
|
170
|
+
"aria-label": e.removeLabel,
|
|
171
|
+
title: e.removeLabel,
|
|
172
|
+
tabindex: "-1",
|
|
173
|
+
class: "ink-menu-item ink-signature-remove",
|
|
174
|
+
"data-ink-signature-remove": "",
|
|
175
|
+
"data-key": e.id,
|
|
176
|
+
onClick: (n) => $(e.id, t)
|
|
177
|
+
}, [d(i, {
|
|
178
|
+
icon: v(k),
|
|
179
|
+
size: 16
|
|
180
|
+
}, null, 8, ["icon"])], 8, R)], 64))), 128))], 8, M), t[2] ||= l("div", {
|
|
181
|
+
role: "separator",
|
|
182
|
+
class: "ink-select-separator"
|
|
183
|
+
}, null, -1)], 64)) : s("", !0),
|
|
184
|
+
l("button", {
|
|
185
|
+
type: "button",
|
|
186
|
+
role: "menuitem",
|
|
187
|
+
tabindex: "-1",
|
|
188
|
+
class: "ink-select-item ink-menu-item ink-signature-create",
|
|
189
|
+
"data-ink-select-item": "",
|
|
190
|
+
"data-ink-signature-create": "",
|
|
191
|
+
onClick: we
|
|
192
|
+
}, [d(i, {
|
|
193
|
+
icon: v(D),
|
|
194
|
+
size: 16
|
|
195
|
+
}, null, 8, ["icon"]), u(" " + _(v(b).create), 1)]),
|
|
196
|
+
v(U) ? (m(), c("p", z, _(v(U)), 1)) : s("", !0)
|
|
197
|
+
], 16)]),
|
|
198
|
+
_: 1
|
|
199
|
+
}, 16)]),
|
|
200
|
+
_: 1
|
|
201
|
+
}),
|
|
202
|
+
d(ee, {
|
|
203
|
+
open: q.value,
|
|
204
|
+
"onUpdate:open": t[0] ||= (e) => q.value = e,
|
|
205
|
+
fonts: B.fonts,
|
|
206
|
+
onCloseAutoFocus: Te
|
|
207
|
+
}, null, 8, ["open", "fonts"])
|
|
208
|
+
], 16, A)]),
|
|
209
|
+
_: 3
|
|
210
|
+
})]),
|
|
211
|
+
_: 3
|
|
212
|
+
}, 8, ["open"]));
|
|
208
213
|
}
|
|
209
214
|
});
|
|
210
215
|
//#endregion
|
|
211
|
-
export {
|
|
216
|
+
export { B as default };
|
|
212
217
|
|
|
213
218
|
//# sourceMappingURL=InkSignatureMenu.vue_vue_type_script_setup_true_lang.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkSignatureMenu.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createElementBlock","_unref","_createVNode","_mergeProps","_withCtx","_renderSlot","InkIcon","_createElementVNode","_normalizeProps","_guardReactiveProps","_Fragment","_renderList","_createCommentVNode","_createTextVNode","_toDisplayString","InkSignatureDialog","InkIcon_default","InkSignatureDialog_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","InkSignatureMenu_vue_vue_type_script_setup_true_lang_default","props","__props","NO_TEMPLATES","useTool","useToolOptions","ctx","useInkContext","templates","useReadable","removeError","model","computed","signatureMenuModel","options","active","tool","open","ref","creating","isOpen","main","useTemplateRef","previews","item","signaturePreview","focusFirst","toDialog","onTriggerKeydown","panel","onOpenAutoFocus","menu","menuItems","focusInitialMenuItem","onCloseAutoFocus","onMain","setTool","choose","setOptions","id","remove","nextTick","rows","row","create","onDialogCloseAutoFocus","mainAttrs","SIGNATURE_LABELS","triggerAttrs","menuAttrs","innerAttrs","handleMenuKeys","openBlock","createElementBlock","unref","createVNode","ToolbarButton","mergeProps","withCtx","renderSlot","_ctx","Signature","PopoverRoot","_cache","$event","PopoverTrigger","createElementVNode","ChevronDown","PopoverPortal","PopoverContent","normalizeProps","guardReactiveProps","Fragment","renderList","i","Trash2","createCommentVNode","Plus","createTextVNode","toDisplayString"],"sources":["../../src/components/InkSignatureMenu.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * A split button for the signature tool. The main part activates the tool with the chosen\n * signature, or opens the menu when none is chosen; the chevron opens the saved signatures as\n * previews, each with a remove button, and \"Create signature\", which opens\n * `InkSignatureDialog`. Choosing a signature switches to the tool with it.\n */\nimport {\n focusInitialMenuItem,\n handleMenuKeys,\n menuItems,\n SIGNATURE_LABELS,\n signatureMenuModel,\n signaturePreview,\n} from '@inkbar/core/dom'\nimport { ChevronDown, Plus, Signature, Trash2 } from '@inkbar/icons'\nimport {\n PopoverContent,\n PopoverPortal,\n PopoverRoot,\n PopoverTrigger,\n ToolbarButton,\n} from 'reka-ui'\nimport { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n\nimport { useTool } from '../composables/useTool'\nimport { useToolOptions } from '../composables/useToolOptions'\nimport { useInkContext } from '../context'\nimport { useReadable } from '../use-readable'\n\nimport InkIcon from './InkIcon.vue'\nimport InkSignatureDialog from './InkSignatureDialog.vue'\n\nimport type { SignatureOptions, SignatureTemplate } from '@inkbar/core'\n\nconst props = defineProps<{\n /** The fonts the dialog's Type tab offers. Default: InkRoot's `signatureFonts`. */\n fonts?: readonly string[] | undefined\n}>()\n\nconst NO_TEMPLATES: readonly SignatureTemplate[] = []\n\nconst { tool, setTool } = useTool()\nconst { options, setOptions } = useToolOptions<SignatureOptions>('signature')\nconst ctx = useInkContext('InkSignatureMenu')\nconst templates = useReadable(() => ctx.signatures.value.templates, NO_TEMPLATES)\nconst removeError = useReadable(() => ctx.signatures.value.removeError, undefined)\nconst model = computed(() => signatureMenuModel(templates.value, options.value))\nconst active = computed(() => tool.value === 'signature')\nconst open = ref(false)\nconst creating = ref(false)\n// An old removal error is not news when the menu opens again.\nwatch(open, (isOpen) => {\n if (isOpen) ctx.signatures.value.clearRemoveError()\n})\nconst main = useTemplateRef<{ $el: HTMLElement }>('main')\n\n/** A saved signature drawn small: ink as filled outlines. */\nconst previews = computed(() =>\n model.value.items.map((item) =>\n item.template.kind === 'ink' ? signaturePreview(item.template) : null\n )\n)\n\n/** ArrowDown opens on the first item; a click opens on the checked one. */\nlet focusFirst = false\n/** Set while the menu closes for the dialog, which takes focus instead of the trigger. */\nlet toDialog = false\n\nfunction onTriggerKeydown(e: KeyboardEvent): void {\n if (e.key !== 'ArrowDown' || e.defaultPrevented || open.value) return\n e.preventDefault()\n focusFirst = true\n open.value = true\n}\n\nconst panel = (): HTMLElement | null =>\n document.querySelector<HTMLElement>('[data-ink-menu=\"signature\"] [role=\"menu\"]')\n\nfunction onOpenAutoFocus(e: Event): void {\n e.preventDefault()\n const menu = panel()\n if (menu) {\n if (focusFirst) menuItems(menu)[0]?.focus({ preventScroll: true })\n else focusInitialMenuItem(menu)\n }\n focusFirst = false\n}\n\nfunction onCloseAutoFocus(e: Event): void {\n if (toDialog) e.preventDefault()\n toDialog = false\n}\n\nfunction onMain(): void {\n if (model.value.selected) setTool('signature')\n else open.value = true\n}\n\nfunction choose(id: string): void {\n setOptions({ templateId: id })\n setTool('signature')\n open.value = false\n}\n\n/** Removes a template; focus moves to the signature now in its row, else \"Create signature\". */\nfunction remove(id: string, row: number): void {\n ctx.signatures.value.remove(id).then(\n async () => {\n await nextTick()\n const menu = panel()\n if (!menu) return\n const rows = menu.querySelectorAll<HTMLElement>('.ink-signature-item')\n const next =\n rows[Math.min(row, rows.length - 1)] ??\n menu.querySelector<HTMLElement>('[data-ink-signature-create]')\n next?.focus({ preventScroll: true })\n },\n () => {\n // The host's store refused: the signature stays.\n }\n )\n}\n\nfunction create(): void {\n toDialog = true\n open.value = false\n creating.value = true\n}\n\nfunction onDialogCloseAutoFocus(e: Event): void {\n e.preventDefault()\n main.value?.$el.focus({ preventScroll: true })\n}\n\n// Reka's typed props stop at its own; ARIA and listeners go through bound objects.\nconst mainAttrs = computed(() => ({\n 'aria-pressed': String(active.value),\n 'aria-label': SIGNATURE_LABELS.sign,\n title: SIGNATURE_LABELS.sign,\n onClick: onMain,\n}))\nconst triggerAttrs = {\n 'aria-label': SIGNATURE_LABELS.trigger,\n title: SIGNATURE_LABELS.trigger,\n 'aria-haspopup': 'menu' as const,\n onKeydown: onTriggerKeydown,\n}\nconst menuAttrs = { 'aria-label': SIGNATURE_LABELS.menu }\nconst innerAttrs = {\n role: 'menu',\n 'aria-label': SIGNATURE_LABELS.menu,\n onKeydown: (e: KeyboardEvent) => handleMenuKeys(e, e.currentTarget as HTMLElement),\n}\n</script>\n\n<template>\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.sign\"\n class=\"ink-split-button ink-signature-menu\"\n data-ink-signature-menu\n >\n <ToolbarButton\n ref=\"main\"\n class=\"ink-tool-button ink-signature-button\"\n data-ink-tool-button\n data-ink-signature-button\n data-tool=\"signature\"\n :data-state=\"active ? 'on' : 'off'\"\n v-bind=\"mainAttrs\"\n >\n <slot :active=\"active\"><InkIcon :icon=\"Signature\" /></slot>\n </ToolbarButton>\n <PopoverRoot v-model:open=\"open\">\n <ToolbarButton as-child>\n <PopoverTrigger as-child>\n <button\n type=\"button\"\n class=\"ink-menu-trigger ink-signature-menu-trigger\"\n data-ink-signature-menu-trigger\n :data-state=\"open ? 'open' : 'closed'\"\n v-bind=\"triggerAttrs\"\n >\n <InkIcon :icon=\"ChevronDown\" />\n </button>\n </PopoverTrigger>\n </ToolbarButton>\n <PopoverPortal>\n <PopoverContent\n class=\"ink-select-content ink-menu-content\"\n data-ink-select-content\n data-ink-menu=\"signature\"\n side=\"bottom\"\n align=\"start\"\n :side-offset=\"4\"\n :collision-padding=\"8\"\n v-bind=\"menuAttrs\"\n @open-auto-focus=\"onOpenAutoFocus\"\n @close-auto-focus=\"onCloseAutoFocus\"\n >\n <div v-bind=\"innerAttrs\">\n <template v-if=\"model.items.length > 0\">\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.saved\"\n class=\"ink-signature-list\"\n data-ink-menu-columns=\"2\"\n >\n <template v-for=\"(item, row) in model.items\" :key=\"item.id\">\n <button\n type=\"button\"\n role=\"menuitemradio\"\n :aria-checked=\"item.checked\"\n :aria-label=\"item.label\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-item\"\n data-ink-select-item\n :data-key=\"item.id\"\n :data-state=\"item.checked ? 'checked' : 'unchecked'\"\n @click=\"choose(item.id)\"\n >\n <span class=\"ink-signature-preview\" :data-kind=\"item.template.kind\">\n <img\n v-if=\"item.template.kind === 'image'\"\n :src=\"item.template.imagedata\"\n alt=\"\"\n draggable=\"false\"\n />\n <svg v-else :viewBox=\"previews[row]?.viewBox\" aria-hidden=\"true\">\n <path\n v-for=\"(d, i) in previews[row]?.paths ?? []\"\n :key=\"i\"\n :d=\"d\"\n fill=\"currentColor\"\n />\n </svg>\n </span>\n </button>\n <button\n type=\"button\"\n role=\"menuitem\"\n :aria-label=\"item.removeLabel\"\n :title=\"item.removeLabel\"\n tabindex=\"-1\"\n class=\"ink-menu-item ink-signature-remove\"\n data-ink-signature-remove\n :data-key=\"item.id\"\n @click=\"remove(item.id, row)\"\n >\n <InkIcon :icon=\"Trash2\" :size=\"16\" />\n </button>\n </template>\n </div>\n <div role=\"separator\" class=\"ink-select-separator\" />\n </template>\n <button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-create\"\n data-ink-select-item\n data-ink-signature-create\n @click=\"create\"\n >\n <InkIcon :icon=\"Plus\" :size=\"16\" />\n {{ SIGNATURE_LABELS.create }}\n </button>\n <p\n v-if=\"removeError\"\n class=\"ink-field-error ink-signature-remove-error\"\n role=\"alert\"\n data-ink-signature-remove-error\n >\n {{ removeError }}\n </p>\n </div>\n </PopoverContent>\n </PopoverPortal>\n </PopoverRoot>\n <InkSignatureDialog\n v-model:open=\"creating\"\n :fonts=\"props.fonts\"\n @close-auto-focus=\"onDialogCloseAutoFocus\"\n />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCA,IAAM8B,IAAQC,GAKRC,IAA6C,CAAC,GAE9C,EAAE,SAAM,eAAYC,EAAQ,GAC5B,EAAE,aAAS,m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OAE3BrE,GAAAA,CAAAA,EAAqCI,GAAA;QAA3B,MAAML,EAAAsG,CAAA;QAAS,MAAM;2CAIrC,GAAA,GAAA,EAAA,GAAA,GAAAnF,CAAA,GAAA,AAAAuE,EAAA,OAAApF,EAAqD,OAAA;QAAhD,MAAK;QAAY,OAAM;;OAE9BA,EAWS,UAAA;QAVP,MAAK;QACL,MAAK;QACL,UAAS;QACT,OAAM;QACN,wBAAA;QACA,6BAAA;QACC,SAAOiE;OAERtE,GAAAA,CAAAA,EAAmCI,GAAA;QAAzB,MAAML,EAAAwG,CAAA;QAAO,MAAM;OAAM5F,GAAAA,MAAAA,GAAAA,CAAAA,MAAAA,CAAAA,GAAAA,GAAA,MACnCC,EAAGb,EAAA0E,CAAA,CAAgB,CAAC,MAAM,GAAA,CAAA,CAAA,CAAA;OAGpB1E,EAAAqC,CAAA,KADRvC,EAAA,GAAAC,EAOI,KAPJ2B,GAOIb,EADCb,EAAAqC,CAAA,CAAW,GAAA,CAAA,KAAAkE,EAAA,IAAA,EAAA;;;;;;;;GAMxBtG,EAIEa,IAAA;IAHQ,MAAMgC,EAAA;IAAA,iBAAA,AAAA4C,EAAA,QAAA,MAAA,EAAQ,QAAAC;IACrB,OAAO/D,EAAM;IACb,kBAAkB4C"}
|
|
1
|
+
{"version":3,"file":"InkSignatureMenu.vue_vue_type_script_setup_true_lang.js","names":["$attrs","_openBlock","_createBlock","_unref","_withCtx","_createVNode","_createElementVNode","_mergeProps","_renderSlot","InkIcon","_normalizeProps","_guardReactiveProps","_createElementBlock","_Fragment","_renderList","_createCommentVNode","_createTextVNode","_toDisplayString","InkSignatureDialog","InkIcon_default","InkSignatureDialog_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","_hoisted_10","InkSignatureMenu_vue_vue_type_script_setup_true_lang_default","props","__props","NO_TEMPLATES","useTool","useToolOptions","ctx","useInkContext","templates","useReadable","removeError","model","computed","signatureMenuModel","options","active","tool","open","ref","creating","isOpen","main","useTemplateRef","previews","item","signaturePreview","focusFirst","toDialog","onTriggerKeydown","panel","onOpenAutoFocus","menu","menuItems","focusInitialMenuItem","onCloseAutoFocus","onMain","setTool","choose","setOptions","id","remove","nextTick","rows","row","create","onDialogCloseAutoFocus","mainAttrs","SIGNATURE_LABELS","triggerAttrs","menuAttrs","innerAttrs","handleMenuKeys","openBlock","createBlock","unref","PopoverRoot","_cache","$event","withCtx","createVNode","PopoverAnchor","createElementVNode","mergeProps","_ctx","ToolbarButton","renderSlot","Signature","PopoverTrigger","ChevronDown","PopoverPortal","PopoverContent","normalizeProps","guardReactiveProps","createElementBlock","Fragment","renderList","i","Trash2","createCommentVNode","Plus","createTextVNode","toDisplayString"],"sources":["../../src/components/InkSignatureMenu.vue"],"sourcesContent":["<script setup lang=\"ts\">\n/*\n * A split button for the signature tool. The main part activates the tool with the chosen\n * signature, or opens the menu when none is chosen; the chevron opens the saved signatures as\n * previews, each with a remove button, and \"Create signature\", which opens\n * `InkSignatureDialog`. Choosing a signature switches to the tool with it.\n */\nimport {\n focusInitialMenuItem,\n handleMenuKeys,\n menuItems,\n SIGNATURE_LABELS,\n signatureMenuModel,\n signaturePreview,\n} from '@inkbar/core/dom'\nimport { ChevronDown, Plus, Signature, Trash2 } from '@inkbar/icons'\nimport {\n PopoverAnchor,\n PopoverContent,\n PopoverPortal,\n PopoverRoot,\n PopoverTrigger,\n ToolbarButton,\n} from 'reka-ui'\nimport { computed, nextTick, ref, useTemplateRef, watch } from 'vue'\n\nimport { useTool } from '../composables/useTool'\nimport { useToolOptions } from '../composables/useToolOptions'\nimport { useInkContext } from '../context'\nimport { useReadable } from '../use-readable'\n\nimport InkIcon from './InkIcon.vue'\nimport InkSignatureDialog from './InkSignatureDialog.vue'\n\nimport type { SignatureOptions, SignatureTemplate } from '@inkbar/core'\n\ndefineOptions({ inheritAttrs: false })\nconst props = defineProps<{\n /** The fonts the dialog's Type tab offers. Default: InkRoot's `signatureFonts`. */\n fonts?: readonly string[] | undefined\n}>()\n\nconst NO_TEMPLATES: readonly SignatureTemplate[] = []\n\nconst { tool, setTool } = useTool()\nconst { options, setOptions } = useToolOptions<SignatureOptions>('signature')\nconst ctx = useInkContext('InkSignatureMenu')\nconst templates = useReadable(() => ctx.signatures.value.templates, NO_TEMPLATES)\nconst removeError = useReadable(() => ctx.signatures.value.removeError, undefined)\nconst model = computed(() => signatureMenuModel(templates.value, options.value))\nconst active = computed(() => tool.value === 'signature')\nconst open = ref(false)\nconst creating = ref(false)\n// An old removal error is not news when the menu opens again.\nwatch(open, (isOpen) => {\n if (isOpen) ctx.signatures.value.clearRemoveError()\n})\nconst main = useTemplateRef<{ $el: HTMLElement }>('main')\n\n/** A saved signature drawn small: ink as filled outlines. */\nconst previews = computed(() =>\n model.value.items.map((item) =>\n item.template.kind === 'ink' ? signaturePreview(item.template) : null\n )\n)\n\n/** ArrowDown opens on the first item; a click opens on the checked one. */\nlet focusFirst = false\n/** Set while the menu closes for the dialog, which takes focus instead of the trigger. */\nlet toDialog = false\n\nfunction onTriggerKeydown(e: KeyboardEvent): void {\n if (e.key !== 'ArrowDown' || e.defaultPrevented || open.value) return\n e.preventDefault()\n focusFirst = true\n open.value = true\n}\n\nconst panel = (): HTMLElement | null =>\n document.querySelector<HTMLElement>('[data-ink-menu=\"signature\"] [role=\"menu\"]')\n\nfunction onOpenAutoFocus(e: Event): void {\n e.preventDefault()\n const menu = panel()\n if (menu) {\n if (focusFirst) menuItems(menu)[0]?.focus({ preventScroll: true })\n else focusInitialMenuItem(menu)\n }\n focusFirst = false\n}\n\nfunction onCloseAutoFocus(e: Event): void {\n if (toDialog) e.preventDefault()\n toDialog = false\n}\n\nfunction onMain(): void {\n if (model.value.selected) setTool('signature')\n else open.value = true\n}\n\nfunction choose(id: string): void {\n setOptions({ templateId: id })\n setTool('signature')\n open.value = false\n}\n\n/** Removes a template; focus moves to the signature now in its row, else \"Create signature\". */\nfunction remove(id: string, row: number): void {\n ctx.signatures.value.remove(id).then(\n async () => {\n await nextTick()\n const menu = panel()\n if (!menu) return\n const rows = menu.querySelectorAll<HTMLElement>('.ink-signature-item')\n const next =\n rows[Math.min(row, rows.length - 1)] ??\n menu.querySelector<HTMLElement>('[data-ink-signature-create]')\n next?.focus({ preventScroll: true })\n },\n () => {\n // The host's store refused: the signature stays.\n }\n )\n}\n\nfunction create(): void {\n toDialog = true\n open.value = false\n creating.value = true\n}\n\nfunction onDialogCloseAutoFocus(e: Event): void {\n e.preventDefault()\n main.value?.$el.focus({ preventScroll: true })\n}\n\n// Reka's typed props stop at its own; ARIA and listeners go through bound objects.\nconst mainAttrs = computed(() => ({\n 'aria-pressed': String(active.value),\n 'aria-label': SIGNATURE_LABELS.sign,\n title: SIGNATURE_LABELS.sign,\n onClick: onMain,\n}))\nconst triggerAttrs = {\n 'aria-label': SIGNATURE_LABELS.trigger,\n title: SIGNATURE_LABELS.trigger,\n 'aria-haspopup': 'menu' as const,\n onKeydown: onTriggerKeydown,\n}\nconst menuAttrs = { 'aria-label': SIGNATURE_LABELS.menu }\nconst innerAttrs = {\n role: 'menu',\n 'aria-label': SIGNATURE_LABELS.menu,\n onKeydown: (e: KeyboardEvent) => handleMenuKeys(e, e.currentTarget as HTMLElement),\n}\n</script>\n\n<template>\n <PopoverRoot v-model:open=\"open\">\n <PopoverAnchor as-child>\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.sign\"\n class=\"ink-split-button ink-signature-menu\"\n data-ink-signature-menu\n v-bind=\"$attrs\"\n >\n <ToolbarButton\n ref=\"main\"\n class=\"ink-tool-button ink-signature-button\"\n data-ink-tool-button\n data-ink-signature-button\n data-tool=\"signature\"\n :data-state=\"active ? 'on' : 'off'\"\n v-bind=\"mainAttrs\"\n >\n <slot :active=\"active\"><InkIcon :icon=\"Signature\" /></slot>\n </ToolbarButton>\n <ToolbarButton as-child>\n <PopoverTrigger as-child>\n <button\n type=\"button\"\n class=\"ink-menu-trigger ink-signature-menu-trigger\"\n data-ink-signature-menu-trigger\n :data-state=\"open ? 'open' : 'closed'\"\n v-bind=\"triggerAttrs\"\n >\n <InkIcon :icon=\"ChevronDown\" />\n </button>\n </PopoverTrigger>\n </ToolbarButton>\n <PopoverPortal>\n <PopoverContent\n class=\"ink-select-content ink-menu-content\"\n data-ink-select-content\n data-ink-menu=\"signature\"\n side=\"bottom\"\n align=\"start\"\n :side-offset=\"4\"\n :collision-padding=\"8\"\n v-bind=\"menuAttrs\"\n @open-auto-focus=\"onOpenAutoFocus\"\n @close-auto-focus=\"onCloseAutoFocus\"\n >\n <div v-bind=\"innerAttrs\">\n <template v-if=\"model.items.length > 0\">\n <div\n role=\"group\"\n :aria-label=\"SIGNATURE_LABELS.saved\"\n class=\"ink-signature-list\"\n data-ink-menu-columns=\"2\"\n >\n <template v-for=\"(item, row) in model.items\" :key=\"item.id\">\n <button\n type=\"button\"\n role=\"menuitemradio\"\n :aria-checked=\"item.checked\"\n :aria-label=\"item.label\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-item\"\n data-ink-select-item\n :data-key=\"item.id\"\n :data-state=\"item.checked ? 'checked' : 'unchecked'\"\n @click=\"choose(item.id)\"\n >\n <span class=\"ink-signature-preview\" :data-kind=\"item.template.kind\">\n <img\n v-if=\"item.template.kind === 'image'\"\n :src=\"item.template.imagedata\"\n alt=\"\"\n draggable=\"false\"\n />\n <svg v-else :viewBox=\"previews[row]?.viewBox\" aria-hidden=\"true\">\n <path\n v-for=\"(d, i) in previews[row]?.paths ?? []\"\n :key=\"i\"\n :d=\"d\"\n fill=\"currentColor\"\n />\n </svg>\n </span>\n </button>\n <button\n type=\"button\"\n role=\"menuitem\"\n :aria-label=\"item.removeLabel\"\n :title=\"item.removeLabel\"\n tabindex=\"-1\"\n class=\"ink-menu-item ink-signature-remove\"\n data-ink-signature-remove\n :data-key=\"item.id\"\n @click=\"remove(item.id, row)\"\n >\n <InkIcon :icon=\"Trash2\" :size=\"16\" />\n </button>\n </template>\n </div>\n <div role=\"separator\" class=\"ink-select-separator\" />\n </template>\n <button\n type=\"button\"\n role=\"menuitem\"\n tabindex=\"-1\"\n class=\"ink-select-item ink-menu-item ink-signature-create\"\n data-ink-select-item\n data-ink-signature-create\n @click=\"create\"\n >\n <InkIcon :icon=\"Plus\" :size=\"16\" />\n {{ SIGNATURE_LABELS.create }}\n </button>\n <p\n v-if=\"removeError\"\n class=\"ink-field-error ink-signature-remove-error\"\n role=\"alert\"\n data-ink-signature-remove-error\n >\n {{ removeError }}\n </p>\n </div>\n </PopoverContent>\n </PopoverPortal>\n <InkSignatureDialog\n v-model:open=\"creating\"\n :fonts=\"props.fonts\"\n @close-auto-focus=\"onDialogCloseAutoFocus\"\n />\n </div>\n </PopoverAnchor>\n </PopoverRoot>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCA,IAAMgC,IAAQC,GAKRC,KAA6C,CAAC,GAE9C,EAAE,UAAM,eAAYC,EAAQ,GAC5B,EAAE,aAAS,mBAAeC,EAAiC,WAAW,GACtEC,IAAMC,EAAc,kBAAkB,GACtCC,KAAYC,QAAkBH,EAAI,WAAW,MAAM,WAAWH,EAAY,GAC1EO,IAAcD,QAAkBH,EAAI,WAAW,MAAM,aAAa,KAAA,CAAS,GAC3EK,IAAQC,QAAeC,GAAmBL,GAAU,OAAOM,GAAQ,KAAK,CAAC,GACzEC,IAASH,QAAeI,GAAK,UAAU,WAAW,GAClDC,IAAOC,EAAI,EAAK,GAChBC,IAAWD,EAAI,EAAK;EAE1B,GAAMD,IAAO,MAAW;GACtB,AAAIG,KAAQd,EAAI,WAAW,MAAM,iBAAiB;EACpD,CAAC;EACD,IAAMe,IAAOC,GAAqC,MAAM,GAGlDC,IAAWX,QACfD,EAAM,MAAM,MAAM,KAAK,MACrBa,EAAK,SAAS,SAAS,QAAQC,GAAiBD,EAAK,QAAQ,IAAI,IACnE,CACF,GAGIE,IAAa,IAEbC,IAAW;EAEf,SAASC,G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AC,MAAM,GAAA,CAAA,CAAA,CAAA;QAGpB3E,EAAAsC,CAAA,KADRxC,EAAA,GAAAW,EAOI,KAPJkB,GAOIb,EADCd,EAAAsC,CAAA,CAAW,GAAA,CAAA,KAAAoE,EAAA,IAAA,EAAA;;;;;;KAKtBxG,EAIEa,IAAA;MAHQ,MAAMgC,EAAA;MAAA,iBAAA,AAAAqC,EAAA,QAAA,MAAA,EAAQ,QAAAC;MACrB,OAAOxD,EAAM;MACb,kBAAkB4C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkViewport.js","names":["_sfc_main","InkViewport_vue_vue_type_script_setup_true_lang_default","InkViewport_default"],"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 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 ...(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 stops = [vp.zoom.subscribe(reportZoom), vp.currentPage.subscribe(reportPage)]\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\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":""}
|
|
1
|
+
{"version":3,"file":"InkViewport.js","names":["_sfc_main","InkViewport_vue_vue_type_script_setup_true_lang_default","InkViewport_default"],"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":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InkViewport.vue.d.ts","sourceRoot":"","sources":["../../src/components/InkViewport.vue"],"names":[],"mappings":"
|
|
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,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|