@scalar/components 0.37.1 → 0.38.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 (31) hide show
  1. package/dist/components/ScalarDialog/ScalarDialog.vue.d.ts +2 -0
  2. package/dist/components/ScalarDialog/ScalarDialog.vue.d.ts.map +1 -1
  3. package/dist/components/ScalarDialog/ScalarDialog.vue.js +11 -8
  4. package/dist/components/ScalarDialog/ScalarDialog.vue.js.map +1 -1
  5. package/dist/components/ScalarDialog/useScrollLock.d.ts +2 -1
  6. package/dist/components/ScalarDialog/useScrollLock.d.ts.map +1 -1
  7. package/dist/components/ScalarDialog/useScrollLock.js +6 -3
  8. package/dist/components/ScalarDialog/useScrollLock.js.map +1 -1
  9. package/dist/components/ScalarFloating/ScalarFloating.vue.d.ts.map +1 -1
  10. package/dist/components/ScalarFloating/ScalarFloating.vue.js +3 -1
  11. package/dist/components/ScalarFloating/ScalarFloating.vue.js.map +1 -1
  12. package/dist/components/ScalarListbox/ScalarListbox.vue.d.ts.map +1 -1
  13. package/dist/components/ScalarListbox/ScalarListbox.vue.js +13 -2
  14. package/dist/components/ScalarListbox/ScalarListbox.vue.js.map +1 -1
  15. package/dist/components/ScalarTeleport/ScalarTeleport.vue.js +1 -1
  16. package/dist/components/ScalarThemeSwatches/ScalarThemeSwatches.vue.d.ts +4 -0
  17. package/dist/components/ScalarThemeSwatches/ScalarThemeSwatches.vue.d.ts.map +1 -1
  18. package/dist/components/ScalarThemeSwatches/ScalarThemeSwatches.vue.js +5 -2
  19. package/dist/components/ScalarThemeSwatches/ScalarThemeSwatches.vue.js.map +1 -1
  20. package/dist/components/ScalarThemeSwatches/useThemeSwatches.d.ts +3 -1
  21. package/dist/components/ScalarThemeSwatches/useThemeSwatches.d.ts.map +1 -1
  22. package/dist/components/ScalarThemeSwatches/useThemeSwatches.js +47 -8
  23. package/dist/components/ScalarThemeSwatches/useThemeSwatches.js.map +1 -1
  24. package/dist/components/ScalarTooltip/ScalarTooltip.vue.d.ts.map +1 -1
  25. package/dist/components/ScalarTooltip/ScalarTooltip.vue.js.map +1 -1
  26. package/dist/components/ScalarTooltip/useTooltip.d.ts.map +1 -1
  27. package/dist/components/ScalarTooltip/useTooltip.js +58 -33
  28. package/dist/components/ScalarTooltip/useTooltip.js.map +1 -1
  29. package/dist/style.css +10 -10
  30. package/dist/vue-styles.css +10 -10
  31. package/package.json +6 -6
@@ -32,12 +32,14 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<Scalar
32
32
  "update:open": (value: boolean) => any;
33
33
  } & {
34
34
  close: () => any;
35
+ dismiss: (event?: KeyboardEvent | undefined) => any;
35
36
  }, string, import("vue").PublicProps, Readonly<ScalarDialogProps & {
36
37
  /** Whether the dialog is open. Drives the native `showModal()` and `close()` calls. */
37
38
  open?: boolean;
38
39
  }> & Readonly<{
39
40
  onClose?: (() => any) | undefined;
40
41
  "onUpdate:open"?: ((value: boolean) => any) | undefined;
42
+ onDismiss?: ((event?: KeyboardEvent | undefined) => any) | undefined;
41
43
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
42
44
  /** The dialog contents. Compose your own header, body, and footer here. */
43
45
  default(): unknown;
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarDialog.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/ScalarDialog.vue"],"names":[],"mappings":"AAiNA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAKhD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;IAgKlB,uFAAuF;WAC9E,OAAO;;;;;;IADhB,uFAAuF;WAC9E,OAAO;;;;;IArJd,2EAA2E;eAChE,OAAO;EAwNhB,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarDialog.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/ScalarDialog.vue"],"names":[],"mappings":"AAyNA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAKhD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;IAwKlB,uFAAuF;WAC9E,OAAO;;;;;;;IADhB,uFAAuF;WAC9E,OAAO;;;;;;IA3Jd,2EAA2E;eAChE,OAAO;EA8NhB,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -16,7 +16,7 @@ var ScalarDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
16
16
  },
17
17
  "openModifiers": {}
18
18
  }),
19
- emits: /*@__PURE__*/ mergeModels(["close"], ["update:open"]),
19
+ emits: /*@__PURE__*/ mergeModels(["close", "dismiss"], ["update:open"]),
20
20
  setup(__props, { emit: __emit }) {
21
21
  const emit = __emit;
22
22
  /** Whether the dialog is open. Drives the native `showModal()` and `close()` calls. */
@@ -71,6 +71,12 @@ var ScalarDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
71
71
  wasOpen = false;
72
72
  }
73
73
  });
74
+ /** Update the model and report a dismissal once, even when a native close event follows. */
75
+ const dismiss = (event) => {
76
+ if (!open.value) return;
77
+ open.value = false;
78
+ emit("dismiss", event);
79
+ };
74
80
  /**
75
81
  * Mirror native closes (a form submit, or the browser force-closing the dialog) back into the model.
76
82
  *
@@ -79,8 +85,7 @@ var ScalarDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
79
85
  * dialog is open keeps that stale event from closing it.
80
86
  */
81
87
  const handleClose = () => {
82
- if (dialogRef.value?.open) return;
83
- open.value = false;
88
+ if (!dialogRef.value?.open) dismiss();
84
89
  };
85
90
  /**
86
91
  * Close on Escape, unless something inside the dialog already handled it.
@@ -95,7 +100,7 @@ var ScalarDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
95
100
  if (event.defaultPrevented || event.isComposing) return;
96
101
  event.preventDefault();
97
102
  event.stopPropagation();
98
- open.value = false;
103
+ dismiss(event);
99
104
  };
100
105
  /**
101
106
  * Route other close requests, such as the Android back gesture, through the model.
@@ -105,16 +110,14 @@ var ScalarDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ def
105
110
  */
106
111
  const handleCancel = (event) => {
107
112
  event.preventDefault();
108
- open.value = false;
113
+ dismiss();
109
114
  };
110
115
  /**
111
116
  * Close when the backdrop is clicked. The composable ignores text-selection drags
112
117
  * and keyboard-activated controls; setting `open` to false lets the puppet bridge
113
118
  * run the native `close()` so the flow matches Escape and programmatic closes.
114
119
  */
115
- const { handlePointerDown, handleClick } = useBackdropClick(dialogRef, () => {
116
- open.value = false;
117
- });
120
+ const { handlePointerDown, handleClick } = useBackdropClick(dialogRef, dismiss);
118
121
  return (_ctx, _cache) => {
119
122
  return openBlock(), createElementBlock("dialog", mergeProps({
120
123
  ref_key: "dialogRef",
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarDialog.vue.js","names":["_useModel","_openBlock","_createElementBlock","_mergeProps","_unref","_withKeys","_createBlock","ScalarTeleportRoot","_withCtx","_renderSlot"],"sources":["../../../src/components/ScalarDialog/ScalarDialog.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Dialog\n *\n * A modal dialog built on the native `<dialog>` element. It calls `showModal()`\n * under the hood, so the dialog is promoted to the browser top layer (escaping\n * ancestor stacking, overflow, and transform contexts), traps and restores focus,\n * makes the rest of the page inert, and closes on Escape — all natively, with no\n * teleport. It also locks page scrolling while open, and gives popovers inside it a\n * teleport target within the dialog so they render above it rather than under the\n * top layer.\n *\n * Control it with `v-model:open` and compose the contents with the default slot.\n * Restyle or resize it by passing your own `class`; the defaults are intentionally\n * minimal so consumers compose rather than configure.\n *\n * Give the dialog an accessible name, ideally by pointing `aria-labelledby` at its\n * visible heading so screen readers announce the same title sighted users see.\n *\n * @example\n * <ScalarDialog v-model:open=\"open\">\n * <h2>Title</h2>\n * <p>Some content</p>\n * </ScalarDialog>\n */\nexport default {}\n</script>\n\n<script setup lang=\"ts\">\nimport { cva, useBindCx } from '@scalar/use-hooks/useBindCx'\nimport { ref, watchPostEffect } from 'vue'\n\nimport { ScalarTeleportRoot } from '../ScalarTeleport'\nimport type { ScalarDialogProps } from './types'\nimport { useBackdropClick } from './useBackdropClick'\nimport { useScrollLock } from './useScrollLock'\n\nconst { persist = false } = defineProps<ScalarDialogProps>()\n\nconst emit = defineEmits<{\n /** Emitted whenever the dialog closes, whether via Escape, a backdrop click, or `open` being set to false. */\n (e: 'close'): void\n}>()\n\ndefineSlots<{\n /** The dialog contents. Compose your own header, body, and footer here. */\n default(): unknown\n}>()\n\n/** Whether the dialog is open. Drives the native `showModal()` and `close()` calls. */\nconst open = defineModel<boolean>('open', { default: false })\n\nconst dialog = cva({\n base: [\n // Reset the native dialog chrome and center it within the top layer\n 'scalar-dialog m-auto rounded-lg border-0 p-3 shadow-lg',\n // Keep a closed dialog hidden even when a consumer class sets its display, such as `flex`\n 'not-open:hidden',\n // Surface colors\n 'bg-b-1 text-c-1',\n // Theme the native ::backdrop via Tailwind's backdrop variant\n 'backdrop:bg-backdrop dark:backdrop:bg-backdrop-dark',\n // Constrain the size and let long content scroll\n 'custom-scroll max-h-[85svh] w-[calc(100dvw-2rem)] max-w-md overflow-auto',\n ],\n})\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n\nconst dialogRef = ref<HTMLDialogElement | null>(null)\n\n/**\n * Open the dialog as a modal, or just mark it open where the dialog API is missing.\n *\n * jsdom (and so every consumer's component tests) and very old browsers do not implement\n * `showModal()`. Toggling the `open` attribute there keeps the contents rendering and the model\n * working, without the top layer, focus trap or inert background the real API adds.\n */\nconst showModal = (element: HTMLDialogElement): void => {\n if (typeof element.showModal === 'function') {\n element.showModal()\n } else {\n element.setAttribute('open', '')\n }\n}\n\n/** Close the dialog, falling back to removing the `open` attribute like {@link showModal}. */\nconst closeDialog = (element: HTMLDialogElement): void => {\n if (typeof element.close === 'function') {\n element.close()\n } else {\n element.removeAttribute('open')\n }\n}\n\nconst { lock, unlock } = useScrollLock()\n\n/** Whether the dialog was open on the last run of the bridge, so `close` fires once per close. */\nlet wasOpen = false\n\n/**\n * Puppet the native dialog from the reactive `open` model.\n *\n * `watchPostEffect` runs after the DOM updates, so the slotted content (and any\n * `autofocus` target) is mounted before `showModal()` moves focus into it. The\n * guards against `dialog.open` avoid the `InvalidStateError` the browser throws\n * when `showModal()` is called on an already-open dialog.\n */\nwatchPostEffect(() => {\n const element = dialogRef.value\n if (!element) {\n return\n }\n\n if (open.value) {\n if (!element.open) {\n showModal(element)\n }\n lock(element)\n wasOpen = true\n } else {\n if (element.open) {\n closeDialog(element)\n }\n unlock()\n // Emit here rather than from the native `close` event, which is queued and never\n // arrives if the dialog is reopened before it fires\n if (wasOpen) {\n emit('close')\n }\n wasOpen = false\n }\n})\n\n/**\n * Mirror native closes (a form submit, or the browser force-closing the dialog) back into the model.\n *\n * The `close` event is queued rather than fired synchronously, so when the dialog is closed and\n * reopened in quick succession the event lands after it is open again. Ignoring it while the\n * dialog is open keeps that stale event from closing it.\n */\nconst handleClose = (): void => {\n if (dialogRef.value?.open) {\n return\n }\n open.value = false\n}\n\n/**\n * Close on Escape, unless something inside the dialog already handled it.\n *\n * Child widgets such as listboxes and comboboxes use Escape to close themselves and mark the event\n * as handled, so the dialog leaves those alone. The same goes for Escape cancelling an IME\n * composition, which should not also close the dialog. Stopping propagation means only the innermost of\n * several nested dialogs closes. Preventing the default also stops a search input from clearing\n * its value on the same keypress that dismisses the dialog.\n */\nconst handleEscape = (event: KeyboardEvent): void => {\n if (event.defaultPrevented || event.isComposing) {\n return\n }\n event.preventDefault()\n event.stopPropagation()\n open.value = false\n}\n\n/**\n * Route other close requests, such as the Android back gesture, through the model.\n *\n * The browser would otherwise close the dialog itself. Going through `open` keeps every close on\n * the same path, so the scroll lock is released and the contents unmount in step.\n */\nconst handleCancel = (event: Event): void => {\n event.preventDefault()\n open.value = false\n}\n\n/**\n * Close when the backdrop is clicked. The composable ignores text-selection drags\n * and keyboard-activated controls; setting `open` to false lets the puppet bridge\n * run the native `close()` so the flow matches Escape and programmatic closes.\n */\nconst { handlePointerDown, handleClick } = useBackdropClick(dialogRef, () => {\n open.value = false\n})\n</script>\n\n<template>\n <dialog\n ref=\"dialogRef\"\n v-bind=\"cx(dialog())\"\n @cancel=\"handleCancel\"\n @click=\"handleClick\"\n @close=\"handleClose\"\n @keydown.esc=\"handleEscape\"\n @pointerdown=\"handlePointerDown\">\n <ScalarTeleportRoot v-if=\"persist || open\">\n <slot />\n </ScalarTeleportRoot>\n </dialog>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAuCA,MAAM,OAAO;;EAWb,MAAM,OAAOA,SAAoB,SAAC,MAA0B;EAE5D,MAAM,SAAS,IAAI,EACjB,MAAM;GAEJ;GAEA;GAEA;GAEA;GAEA;EACF,EACF,CAAC;EAGD,MAAM,EAAE,OAAO,UAAU;EAEzB,MAAM,YAAY,IAA8B,IAAI;;;;;;;;EASpD,MAAM,aAAa,YAAqC;GACtD,IAAI,OAAO,QAAQ,cAAc,YAC/B,QAAQ,UAAU;QAElB,QAAQ,aAAa,QAAQ,EAAE;EAEnC;;EAGA,MAAM,eAAe,YAAqC;GACxD,IAAI,OAAO,QAAQ,UAAU,YAC3B,QAAQ,MAAM;QAEd,QAAQ,gBAAgB,MAAM;EAElC;EAEA,MAAM,EAAE,MAAM,WAAW,cAAc;;EAGvC,IAAI,UAAU;;;;;;;;;EAUd,sBAAsB;GACpB,MAAM,UAAU,UAAU;GAC1B,IAAI,CAAC,SACH;GA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Block","_mergeProps","_unref","_withKeys","_createBlock","ScalarTeleportRoot","_withCtx","_renderSlot"],"sources":["../../../src/components/ScalarDialog/ScalarDialog.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Dialog\n *\n * A modal dialog built on the native `<dialog>` element. It calls `showModal()`\n * under the hood, so the dialog is promoted to the browser top layer (escaping\n * ancestor stacking, overflow, and transform contexts), traps and restores focus,\n * makes the rest of the page inert, and closes on Escape — all natively, with no\n * teleport. It also locks page scrolling while open, and gives popovers inside it a\n * teleport target within the dialog so they render above it rather than under the\n * top layer.\n *\n * Control it with `v-model:open` and compose the contents with the default slot.\n * Restyle or resize it by passing your own `class`; the defaults are intentionally\n * minimal so consumers compose rather than configure.\n *\n * Give the dialog an accessible name, ideally by pointing `aria-labelledby` at its\n * visible heading so screen readers announce the same title sighted users see.\n *\n * @example\n * <ScalarDialog v-model:open=\"open\">\n * <h2>Title</h2>\n * <p>Some content</p>\n * </ScalarDialog>\n */\nexport default {}\n</script>\n\n<script setup lang=\"ts\">\nimport { cva, useBindCx } from '@scalar/use-hooks/useBindCx'\nimport { ref, watchPostEffect } from 'vue'\n\nimport { ScalarTeleportRoot } from '../ScalarTeleport'\nimport type { ScalarDialogProps } from './types'\nimport { useBackdropClick } from './useBackdropClick'\nimport { useScrollLock } from './useScrollLock'\n\nconst { persist = false } = defineProps<ScalarDialogProps>()\n\nconst emit = defineEmits<{\n /** Emitted whenever the dialog closes, whether via Escape, a backdrop click, or `open` being set to false. */\n (e: 'close'): void\n /** Emitted when the dialog initiates a close, with the original keydown event for Escape. */\n (e: 'dismiss', event?: KeyboardEvent): void\n}>()\n\ndefineSlots<{\n /** The dialog contents. Compose your own header, body, and footer here. */\n default(): unknown\n}>()\n\n/** Whether the dialog is open. Drives the native `showModal()` and `close()` calls. */\nconst open = defineModel<boolean>('open', { default: false })\n\nconst dialog = cva({\n base: [\n // Reset the native dialog chrome and center it within the top layer\n 'scalar-dialog m-auto rounded-lg border-0 p-3 shadow-lg',\n // Keep a closed dialog hidden even when a consumer class sets its display, such as `flex`\n 'not-open:hidden',\n // Surface colors\n 'bg-b-1 text-c-1',\n // Theme the native ::backdrop via Tailwind's backdrop variant\n 'backdrop:bg-backdrop dark:backdrop:bg-backdrop-dark',\n // Constrain the size and let long content scroll\n 'custom-scroll max-h-[85svh] w-[calc(100dvw-2rem)] max-w-md overflow-auto',\n ],\n})\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n\nconst dialogRef = ref<HTMLDialogElement | null>(null)\n\n/**\n * Open the dialog as a modal, or just mark it open where the dialog API is missing.\n *\n * jsdom (and so every consumer's component tests) and very old browsers do not implement\n * `showModal()`. Toggling the `open` attribute there keeps the contents rendering and the model\n * working, without the top layer, focus trap or inert background the real API adds.\n */\nconst showModal = (element: HTMLDialogElement): void => {\n if (typeof element.showModal === 'function') {\n element.showModal()\n } else {\n element.setAttribute('open', '')\n }\n}\n\n/** Close the dialog, falling back to removing the `open` attribute like {@link showModal}. */\nconst closeDialog = (element: HTMLDialogElement): void => {\n if (typeof element.close === 'function') {\n element.close()\n } else {\n element.removeAttribute('open')\n }\n}\n\nconst { lock, unlock } = useScrollLock()\n\n/** Whether the dialog was open on the last run of the bridge, so `close` fires once per close. */\nlet wasOpen = false\n\n/**\n * Puppet the native dialog from the reactive `open` model.\n *\n * `watchPostEffect` runs after the DOM updates, so the slotted content (and any\n * `autofocus` target) is mounted before `showModal()` moves focus into it. The\n * guards against `dialog.open` avoid the `InvalidStateError` the browser throws\n * when `showModal()` is called on an already-open dialog.\n */\nwatchPostEffect(() => {\n const element = dialogRef.value\n if (!element) {\n return\n }\n\n if (open.value) {\n if (!element.open) {\n showModal(element)\n }\n lock(element)\n wasOpen = true\n } else {\n if (element.open) {\n closeDialog(element)\n }\n unlock()\n // Emit here rather than from the native `close` event, which is queued and never\n // arrives if the dialog is reopened before it fires\n if (wasOpen) {\n emit('close')\n }\n wasOpen = false\n }\n})\n\n/** Update the model and report a dismissal once, even when a native close event follows. */\nconst dismiss = (event?: KeyboardEvent): void => {\n if (!open.value) {\n return\n }\n open.value = false\n emit('dismiss', event)\n}\n\n/**\n * Mirror native closes (a form submit, or the browser force-closing the dialog) back into the model.\n *\n * The `close` event is queued rather than fired synchronously, so when the dialog is closed and\n * reopened in quick succession the event lands after it is open again. Ignoring it while the\n * dialog is open keeps that stale event from closing it.\n */\nconst handleClose = (): void => {\n if (!dialogRef.value?.open) {\n dismiss()\n }\n}\n\n/**\n * Close on Escape, unless something inside the dialog already handled it.\n *\n * Child widgets such as listboxes and comboboxes use Escape to close themselves and mark the event\n * as handled, so the dialog leaves those alone. The same goes for Escape cancelling an IME\n * composition, which should not also close the dialog. Stopping propagation means only the innermost of\n * several nested dialogs closes. Preventing the default also stops a search input from clearing\n * its value on the same keypress that dismisses the dialog.\n */\nconst handleEscape = (event: KeyboardEvent): void => {\n if (event.defaultPrevented || event.isComposing) {\n return\n }\n event.preventDefault()\n event.stopPropagation()\n dismiss(event)\n}\n\n/**\n * Route other close requests, such as the Android back gesture, through the model.\n *\n * The browser would otherwise close the dialog itself. Going through `open` keeps every close on\n * the same path, so the scroll lock is released and the contents unmount in step.\n */\nconst handleCancel = (event: Event): void => {\n event.preventDefault()\n dismiss()\n}\n\n/**\n * Close when the backdrop is clicked. The composable ignores text-selection drags\n * and keyboard-activated controls; setting `open` to false lets the puppet bridge\n * run the native `close()` so the flow matches Escape and programmatic closes.\n */\nconst { handlePointerDown, handleClick } = useBackdropClick(dialogRef, dismiss)\n</script>\n\n<template>\n <dialog\n ref=\"dialogRef\"\n v-bind=\"cx(dialog())\"\n @cancel=\"handleCancel\"\n @click=\"handleClick\"\n @close=\"handleClose\"\n @keydown.esc=\"handleEscape\"\n @pointerdown=\"handlePointerDown\">\n <ScalarTeleportRoot v-if=\"persist || open\">\n <slot />\n </ScalarTeleportRoot>\n </dialog>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAuCA,MAAM,OAAO;;EAab,MAAM,OAAOA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,mBAWS,UAXTC,WAWS;IAVH,SAAA;IAAJ,KAAI;GACI,GAAAC,MAAA,EAAA,CAAE,CAACA,MAAA,MAAA,CAAM,CAAA,CAAA,GAAA;IAChB,UAAQ;IACR,SAAK,OAAA,OAAA,OAAA,MAAE,GAAA,SAAAA,MAAA,WAAA,KAAAA,MAAA,WAAA,CAAA,CAAA,GAAA,IAAA;IACP,SAAO;IACP,WAAOC,SAAM,cAAY,CAAA,KAAA,CAAA;IACzB,eAAW,OAAA,OAAA,OAAA,MAAE,GAAA,SAAAD,MAAA,iBAAA,KAAAA,MAAA,iBAAA,CAAA,CAAA,GAAA,IAAA;G,KACY,QAAA,WAAW,KAAA,SAArCH,UAAA,GAAAK,YAEqBF,MAAAG,0BAAA,GAAA,EAAA,KAAA,EAAA,GAAA;IADnB,SAAAC,cAAQ,CAARC,WAAQ,KAAA,QAAA,SAAA,C"}
@@ -4,7 +4,8 @@
4
4
  * A native `<dialog>` makes the page inert but does not stop it scrolling, so a wheel or touch
5
5
  * gesture over the backdrop would scroll the content underneath. This sets `overflow: hidden` on
6
6
  * the document element and pads it by the scrollbar width, so the page does not shift sideways when
7
- * its scrollbar disappears. The lock is released automatically when the calling scope is disposed.
7
+ * its scrollbar disappears. A stable scrollbar gutter already reserves that space when overflow
8
+ * is hidden. The lock is released automatically when the calling scope is disposed.
8
9
  *
9
10
  * @returns `lock` to take the lock for a given element's document and `unlock` to release it.
10
11
  * Both are idempotent, so calling either twice in a row is safe.
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollLock.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/useScrollLock.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,QAAO;IAC/B,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAChC,MAAM,EAAE,MAAM,IAAI,CAAA;CA0DnB,CAAA"}
1
+ {"version":3,"file":"useScrollLock.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarDialog/useScrollLock.ts"],"names":[],"mappings":"AAoBA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,QAAO;IAC/B,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAChC,MAAM,EAAE,MAAM,IAAI,CAAA;CA4DnB,CAAA"}
@@ -14,7 +14,8 @@ var locks = /* @__PURE__ */ new WeakMap();
14
14
  * A native `<dialog>` makes the page inert but does not stop it scrolling, so a wheel or touch
15
15
  * gesture over the backdrop would scroll the content underneath. This sets `overflow: hidden` on
16
16
  * the document element and pads it by the scrollbar width, so the page does not shift sideways when
17
- * its scrollbar disappears. The lock is released automatically when the calling scope is disposed.
17
+ * its scrollbar disappears. A stable scrollbar gutter already reserves that space when overflow
18
+ * is hidden. The lock is released automatically when the calling scope is disposed.
18
19
  *
19
20
  * @returns `lock` to take the lock for a given element's document and `unlock` to release it.
20
21
  * Both are idempotent, so calling either twice in a row is safe.
@@ -32,8 +33,10 @@ var useScrollLock = () => {
32
33
  existing.count++;
33
34
  return;
34
35
  }
35
- const scrollbarWidth = view ? view.innerWidth - root.clientWidth : 0;
36
- const paddingRight = view ? Number.parseFloat(view.getComputedStyle(root).paddingRight) || 0 : 0;
36
+ const rootStyle = view?.getComputedStyle(root);
37
+ const keepsGutter = rootStyle?.scrollbarGutter?.startsWith("stable") ?? false;
38
+ const scrollbarWidth = view && !keepsGutter ? view.innerWidth - root.clientWidth : 0;
39
+ const paddingRight = Number.parseFloat(rootStyle?.paddingRight ?? "") || 0;
37
40
  locks.set(root, {
38
41
  count: 1,
39
42
  overflow: root.style.getPropertyValue("overflow"),
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollLock.js","names":[],"sources":["../../../src/components/ScalarDialog/useScrollLock.ts"],"sourcesContent":["import { onScopeDispose } from 'vue'\n\n/** The inline styles a lock overrides, saved so the last release can put them back. */\ntype SavedStyles = {\n count: number\n overflow: string\n overflowPriority: string\n paddingRight: string\n paddingRightPriority: string\n}\n\n/**\n * Active locks, keyed by the root element they lock.\n *\n * Keyed per root rather than global because a dialog inside an iframe locks that iframe's own\n * document. A dialog in a shadow root shares its host's document, so it locks the page. The count lets nested and stacked dialogs share one lock, so closing the inner dialog\n * does not unlock the page while the outer one is still open.\n */\nconst locks = new WeakMap<HTMLElement, SavedStyles>()\n\n/**\n * Lock scrolling on the document behind a modal.\n *\n * A native `<dialog>` makes the page inert but does not stop it scrolling, so a wheel or touch\n * gesture over the backdrop would scroll the content underneath. This sets `overflow: hidden` on\n * the document element and pads it by the scrollbar width, so the page does not shift sideways when\n * its scrollbar disappears. The lock is released automatically when the calling scope is disposed.\n *\n * @returns `lock` to take the lock for a given element's document and `unlock` to release it.\n * Both are idempotent, so calling either twice in a row is safe.\n */\nexport const useScrollLock = (): {\n lock: (element: Element) => void\n unlock: () => void\n} => {\n /** The root this instance currently holds a lock on, if any. */\n let lockedRoot: HTMLElement | undefined\n\n const lock = (element: Element): void => {\n if (lockedRoot) {\n return\n }\n\n const root = element.ownerDocument.documentElement\n const view = element.ownerDocument.defaultView\n lockedRoot = root\n\n const existing = locks.get(root)\n if (existing) {\n existing.count++\n return\n }\n\n // Measure before hiding the overflow, since hiding it is what removes the scrollbar\n const scrollbarWidth = view ? view.innerWidth - root.clientWidth : 0\n const paddingRight = view ? Number.parseFloat(view.getComputedStyle(root).paddingRight) || 0 : 0\n\n locks.set(root, {\n count: 1,\n overflow: root.style.getPropertyValue('overflow'),\n overflowPriority: root.style.getPropertyPriority('overflow'),\n paddingRight: root.style.getPropertyValue('padding-right'),\n paddingRightPriority: root.style.getPropertyPriority('padding-right'),\n })\n\n root.style.setProperty('overflow', 'hidden')\n if (scrollbarWidth > 0) {\n root.style.setProperty('padding-right', `${paddingRight + scrollbarWidth}px`)\n }\n }\n\n const unlock = (): void => {\n const root = lockedRoot\n if (!root) {\n return\n }\n lockedRoot = undefined\n\n const saved = locks.get(root)\n if (!saved || --saved.count > 0) {\n return\n }\n locks.delete(root)\n\n restore(root, 'overflow', saved.overflow, saved.overflowPriority)\n restore(root, 'padding-right', saved.paddingRight, saved.paddingRightPriority)\n }\n\n onScopeDispose(unlock)\n\n return { lock, unlock }\n}\n\n/** Put an inline style back the way it was, removing it if it was not set before. */\nconst restore = (element: HTMLElement, property: string, value: string, priority: string): void => {\n if (value) {\n element.style.setProperty(property, value, priority)\n } else {\n element.style.removeProperty(property)\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAM,wBAAQ,IAAI,QAAkC;;;;;;;;;;;;AAapD,IAAa,sBAGR;;CAEH,IAAI;CAEJ,MAAM,QAAQ,YAA2B;EACvC,IAAI,YACF;EAGF,MAAM,OAAO,QAAQ,cAAc;EACnC,MAAM,OAAO,QAAQ,cAAc;EACnC,aAAa;EAEb,MAAM,WAAW,MAAM,IAAI,IAAI;EAC/B,IAAI,UAAU;GACZ,SAAS;GACT;EACF;EAGA,MAAM,iBAAiB,OAAO,KAAK,aAAa,KAAK,cAAc;EACnE,MAAM,eAAe,OAAO,OAAO,WAAW,KAAK,iBAAiB,IAAI,CAAC,CAAC,YAAY,KAAK,IAAI;EAE/F,MAAM,IAAI,MAAM;GACd,OAAO;GACP,UAAU,KAAK,MAAM,iBAAiB,UAAU;GAChD,kBAAkB,KAAK,MAAM,oBAAoB,UAAU;GAC3D,cAAc,KAAK,MAAM,iBAAiB,eAAe;GACzD,sBAAsB,KAAK,MAAM,oBAAoB,eAAe;EACtE,CAAC;EAED,KAAK,MAAM,YAAY,YAAY,QAAQ;EAC3C,IAAI,iBAAiB,GACnB,KAAK,MAAM,YAAY,iBAAiB,GAAG,eAAe,eAAe,GAAG;CAEhF;CAEA,MAAM,eAAqB;EACzB,MAAM,OAAO;EACb,IAAI,CAAC,MACH;EAEF,aAAa,KAAA;EAEb,MAAM,QAAQ,MAAM,IAAI,IAAI;EAC5B,IAAI,CAAC,SAAS,EAAE,MAAM,QAAQ,GAC5B;EAEF,MAAM,OAAO,IAAI;EAEjB,QAAQ,MAAM,YAAY,MAAM,UAAU,MAAM,gBAAgB;EAChE,QAAQ,MAAM,iBAAiB,MAAM,cAAc,MAAM,oBAAoB;CAC/E;CAEA,eAAe,MAAM;CAErB,OAAO;EAAE;EAAM;CAAO;AACxB;;AAGA,IAAM,WAAW,SAAsB,UAAkB,OAAe,aAA2B;CACjG,IAAI,OACF,QAAQ,MAAM,YAAY,UAAU,OAAO,QAAQ;MAEnD,QAAQ,MAAM,eAAe,QAAQ;AAEzC"}
1
+ {"version":3,"file":"useScrollLock.js","names":[],"sources":["../../../src/components/ScalarDialog/useScrollLock.ts"],"sourcesContent":["import { onScopeDispose } from 'vue'\n\n/** The inline styles a lock overrides, saved so the last release can put them back. */\ntype SavedStyles = {\n count: number\n overflow: string\n overflowPriority: string\n paddingRight: string\n paddingRightPriority: string\n}\n\n/**\n * Active locks, keyed by the root element they lock.\n *\n * Keyed per root rather than global because a dialog inside an iframe locks that iframe's own\n * document. A dialog in a shadow root shares its host's document, so it locks the page. The count lets nested and stacked dialogs share one lock, so closing the inner dialog\n * does not unlock the page while the outer one is still open.\n */\nconst locks = new WeakMap<HTMLElement, SavedStyles>()\n\n/**\n * Lock scrolling on the document behind a modal.\n *\n * A native `<dialog>` makes the page inert but does not stop it scrolling, so a wheel or touch\n * gesture over the backdrop would scroll the content underneath. This sets `overflow: hidden` on\n * the document element and pads it by the scrollbar width, so the page does not shift sideways when\n * its scrollbar disappears. A stable scrollbar gutter already reserves that space when overflow\n * is hidden. The lock is released automatically when the calling scope is disposed.\n *\n * @returns `lock` to take the lock for a given element's document and `unlock` to release it.\n * Both are idempotent, so calling either twice in a row is safe.\n */\nexport const useScrollLock = (): {\n lock: (element: Element) => void\n unlock: () => void\n} => {\n /** The root this instance currently holds a lock on, if any. */\n let lockedRoot: HTMLElement | undefined\n\n const lock = (element: Element): void => {\n if (lockedRoot) {\n return\n }\n\n const root = element.ownerDocument.documentElement\n const view = element.ownerDocument.defaultView\n lockedRoot = root\n\n const existing = locks.get(root)\n if (existing) {\n existing.count++\n return\n }\n\n // Measure before hiding overflow so the scrollbar is still present.\n const rootStyle = view?.getComputedStyle(root)\n const keepsGutter = rootStyle?.scrollbarGutter?.startsWith('stable') ?? false\n const scrollbarWidth = view && !keepsGutter ? view.innerWidth - root.clientWidth : 0\n const paddingRight = Number.parseFloat(rootStyle?.paddingRight ?? '') || 0\n\n locks.set(root, {\n count: 1,\n overflow: root.style.getPropertyValue('overflow'),\n overflowPriority: root.style.getPropertyPriority('overflow'),\n paddingRight: root.style.getPropertyValue('padding-right'),\n paddingRightPriority: root.style.getPropertyPriority('padding-right'),\n })\n\n root.style.setProperty('overflow', 'hidden')\n if (scrollbarWidth > 0) {\n root.style.setProperty('padding-right', `${paddingRight + scrollbarWidth}px`)\n }\n }\n\n const unlock = (): void => {\n const root = lockedRoot\n if (!root) {\n return\n }\n lockedRoot = undefined\n\n const saved = locks.get(root)\n if (!saved || --saved.count > 0) {\n return\n }\n locks.delete(root)\n\n restore(root, 'overflow', saved.overflow, saved.overflowPriority)\n restore(root, 'padding-right', saved.paddingRight, saved.paddingRightPriority)\n }\n\n onScopeDispose(unlock)\n\n return { lock, unlock }\n}\n\n/** Put an inline style back the way it was, removing it if it was not set before. */\nconst restore = (element: HTMLElement, property: string, value: string, priority: string): void => {\n if (value) {\n element.style.setProperty(property, value, priority)\n } else {\n element.style.removeProperty(property)\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAM,wBAAQ,IAAI,QAAkC;;;;;;;;;;;;;AAcpD,IAAa,sBAGR;;CAEH,IAAI;CAEJ,MAAM,QAAQ,YAA2B;EACvC,IAAI,YACF;EAGF,MAAM,OAAO,QAAQ,cAAc;EACnC,MAAM,OAAO,QAAQ,cAAc;EACnC,aAAa;EAEb,MAAM,WAAW,MAAM,IAAI,IAAI;EAC/B,IAAI,UAAU;GACZ,SAAS;GACT;EACF;EAGA,MAAM,YAAY,MAAM,iBAAiB,IAAI;EAC7C,MAAM,cAAc,WAAW,iBAAiB,WAAW,QAAQ,KA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wBAAyC;AAGzC,QAAA,MAAM,YAAY;IAkIhB,kCAAkC;;;IArHlC,kEAAkE;eACvD,OAAO;IAClB,2BAA2B;qBACV;QACf,4FAA4F;QAC5F,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,6FAA6F;QAC7F,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,gDAAgD;QAChD,IAAI,CAAC,EAAE,cAAc,CAAA;KACtB,GAAG,OAAO;EAoLT,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarFloating.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarFloating/ScalarFloating.vue"],"names":[],"mappings":"AA8LA,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,kBAAkB,CAAA;AAKzB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C;;;;;;;;;;;GAWG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;IAmIhB,kCAAkC;;;IAtHlC,kEAAkE;eACvD,OAAO;IAClB,2BAA2B;qBACV;QACf,4FAA4F;QAC5F,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,6FAA6F;QAC7F,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,gDAAgD;QAChD,IAAI,CAAC,EAAE,cAAc,CAAA;KACtB,GAAG,OAAO;EAqLT,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -3,6 +3,7 @@ import { useResizeWithTarget } from "./useResizeWithTarget.js";
3
3
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, defineComponent, nextTick, normalizeClass, normalizeStyle, openBlock, ref, renderSlot, unref, withCtx } from "vue";
4
4
  import { getSideAxis } from "@floating-ui/utils";
5
5
  import { autoUpdate, flip, offset, shift, size, useFloating } from "@floating-ui/vue";
6
+ import { isShadowRoot } from "@scalar/helpers/dom/is-shadow-root";
6
7
  var ScalarFloating_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
7
8
  inheritAttrs: false,
8
9
  __name: "ScalarFloating",
@@ -34,7 +35,8 @@ var ScalarFloating_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
34
35
  const targetRef = computed(() => {
35
36
  if (typeof window !== "undefined" && wrapperRef.value) {
36
37
  if (typeof __props.target === "string") {
37
- const t = document.getElementById(__props.target);
38
+ const root = wrapperRef.value.getRootNode();
39
+ const t = (isShadowRoot(root) ? root : document).getElementById(__props.target);
38
40
  if (t) return t;
39
41
  console.warn(`ScalarFloating: Target with id="${__props.target}" not found`);
40
42
  } else if (__props.target instanceof HTMLElement) return __props.target;
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarFloating.vue.js","names":["$slots","offsetMiddleware","_openBlock","_createElementVNode","_normalizeClass","_renderSlot","_createBlock","_unref","ScalarTeleport","_withCtx","_normalizeStyle"],"sources":["../../../src/components/ScalarFloating/ScalarFloating.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Floating component\n *\n * Positions a floating element relative to a reference element\n * using Floating UI. Handles placement, offset, flipping, and resizing.\n *\n * @example\n * <ScalarFloating placement=\"bottom\">\n * <button>Reference</button>\n * <template #floating>Floating content</template>\n * </ScalarFloating>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { getSideAxis } from '@floating-ui/utils'\nimport {\n autoUpdate,\n flip,\n offset as offsetMiddleware,\n shift,\n size,\n useFloating,\n type MiddlewareData,\n} from '@floating-ui/vue'\nimport { computed, nextTick, ref, type Ref } from 'vue'\n\nimport { ScalarTeleport } from '../ScalarTeleport'\nimport type { FloatingOptions } from './types'\nimport { useResizeWithTarget } from './useResizeWithTarget'\n\nconst {\n placement,\n offset = 5,\n resize = false,\n middleware = [],\n target,\n teleport,\n} = defineProps<FloatingOptions>()\n\ndefineSlots<{\n /** The reference element for the element in the #floating slot */\n default(): unknown\n /** The floating element */\n floating?(props: {\n /** The width of the reference element if `resize` is true and placement is on the y axis */\n width?: string\n /** The height of the reference element if `resize` is true and placement is on the x axis */\n height?: string\n /** The middleware data return by Floating UI */\n data?: MiddlewareData\n }): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\n\nconst floatingRef: Ref<HTMLElement | null> = ref(null)\nconst wrapperRef: Ref<HTMLElement | null> = ref(null)\n\nconst targetRef = computed<HTMLElement | undefined>(() => {\n if (typeof window !== 'undefined' && wrapperRef.value) {\n // If target is a string (id), try to find it in the document\n if (typeof target === 'string') {\n const t = document.getElementById(target)\n if (t) {\n return t\n }\n console.warn(`ScalarFloating: Target with id=\"${target}\" not found`)\n }\n // If target is an HTMLElement, return it\n else if (target instanceof HTMLElement) {\n return target\n }\n // Fallback to div wrapper if no child element is provided\n const firstChild = wrapperRef.value.children?.[0]\n if (firstChild instanceof HTMLElement) {\n return firstChild\n }\n return wrapperRef.value\n }\n // Return undefined if nothing is found\n return undefined\n})\n\nconst targetSize = useResizeWithTarget(targetRef, {\n enabled: computed(() => resize),\n})\n\nconst targetWidth = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'y'\n ? targetSize.width.value\n : undefined,\n)\n\nconst targetHeight = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'x'\n ? targetSize.height.value\n : undefined,\n)\n\n/**\n * Starts Floating UI's `autoUpdate` one tick after both elements exist.\n *\n * `useFloating` attaches `autoUpdate` from a synchronous watch the moment the\n * template refs resolve, and `autoUpdate` positions the element right away.\n * Template refs resolve in the post-render phase of a flush, so that first\n * `computePosition` reads layout while the same flush is still mounting other\n * components: every floating element mounted together (for example the closed\n * listboxes of a schema with many compositions) forces its own style recalc and\n * layout on a tree that was dirtied again in between. Waiting for `nextTick`\n * runs every first positioning back-to-back once the flush has settled, so the\n * browser recalculates the tree once for all of them. The tick resolves before\n * the next paint, so an element that mounts open is positioned in the same task.\n */\nconst deferredAutoUpdate: typeof autoUpdate = (\n reference,\n floating,\n update,\n options,\n) => {\n let cleanup: (() => void) | undefined\n let disposed = false\n\n void nextTick(() => {\n if (!disposed) {\n cleanup = autoUpdate(reference, floating, update, options)\n }\n })\n\n return () => {\n disposed = true\n cleanup?.()\n }\n}\n\nconst { floatingStyles, middlewareData } = useFloating(targetRef, floatingRef, {\n placement: computed(() => placement ?? 'bottom'),\n whileElementsMounted: deferredAutoUpdate,\n middleware: computed(() => [\n offsetMiddleware(offset),\n flip({ padding: 48 }),\n shift({ padding: 8 }),\n size({\n apply({ availableWidth, availableHeight, elements }) {\n // Assign the max width and height to the floating element\n // @see https://floating-ui.com/docs/size\n Object.assign(elements.floating.style, {\n maxWidth: `${Math.max(0, availableWidth) - 16}px`,\n maxHeight: `${Math.max(0, availableHeight) - 16}px`,\n })\n },\n }),\n ...middleware,\n ]),\n})\n\ndefineExpose({\n /** The resolved target element */\n targetRef,\n})\n</script>\n<template>\n <div\n ref=\"wrapperRef\"\n :class=\"{ contents: !!$slots.default }\">\n <slot />\n </div>\n <ScalarTeleport\n v-if=\"$slots.floating\"\n :disabled=\"!teleport\"\n :to=\"typeof teleport === 'string' ? teleport : undefined\">\n <div\n ref=\"floatingRef\"\n class=\"z-context relative\"\n :style=\"floatingStyles\">\n <slot\n :data=\"middlewareData\"\n :height=\"targetHeight\"\n name=\"floating\"\n :width=\"targetWidth\" />\n </div>\n </ScalarTeleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDA,MAAM,cAAuC,IAAI,IAAI;EACrD,MAAM,aAAsC,IAAI,IAAI;EAEpD,MAAM,YAAY,eAAwC;GACxD,IAAI,OAAO,WAAW,eAAe,WAAW,OAAO;IAErD,IAAI,OAAO,QAAA,WAAW,UAAU;KAC9B,MAAM,IAAI,SAAS,eAAe,QAAA,MAAM;KAC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HA,SAAA;IAAJ,KAAI;IACH,OAAKC,eAAA,EAAA,UAAA,CAAA,CAAgBJ,KAAAA,OAAO,QAAO,CAAA;G,IACpCK,WAAQ,KAAA,QAAA,SAAA,C,OAGFL,KAAAA,OAAO,YADfE,UAAA,GAAAI,YAciBC,MAAAC,sBAAA,GAAA;;IAZd,UAAQ,CAAG,QAAA;IACX,IAAE,OAAS,QAAA,aAAQ,WAAgB,QAAA,WAAW,KAAA;;IAC/C,SAAAC,cASM,CATNN,mBASM,OAAA;KARA,SAAA;KAAJ,KAAI;KACJ,OAAM;KACL,OAAKO,eAAEH,MAAA,cAAA,CAAc;I,IACtBF,WAIyB,KAAA,QAAA,YAAA;KAHtB,MAAME,MAAA,cAAA;KACN,QAAQ,aAAA;KAER,OAAO,YAAA"}
1
+ {"version":3,"file":"ScalarFloating.vue.js","names":["$slots","offsetMiddleware","_openBlock","_createElementVNode","_normalizeClass","_renderSlot","_createBlock","_unref","ScalarTeleport","_withCtx","_normalizeStyle"],"sources":["../../../src/components/ScalarFloating/ScalarFloating.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Floating component\n *\n * Positions a floating element relative to a reference element\n * using Floating UI. Handles placement, offset, flipping, and resizing.\n *\n * @example\n * <ScalarFloating placement=\"bottom\">\n * <button>Reference</button>\n * <template #floating>Floating content</template>\n * </ScalarFloating>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { getSideAxis } from '@floating-ui/utils'\nimport {\n autoUpdate,\n flip,\n offset as offsetMiddleware,\n shift,\n size,\n useFloating,\n type MiddlewareData,\n} from '@floating-ui/vue'\nimport { isShadowRoot } from '@scalar/helpers/dom/is-shadow-root'\nimport { computed, nextTick, ref, type Ref } from 'vue'\n\nimport { ScalarTeleport } from '../ScalarTeleport'\nimport type { FloatingOptions } from './types'\nimport { useResizeWithTarget } from './useResizeWithTarget'\n\nconst {\n placement,\n offset = 5,\n resize = false,\n middleware = [],\n target,\n teleport,\n} = defineProps<FloatingOptions>()\n\ndefineSlots<{\n /** The reference element for the element in the #floating slot */\n default(): unknown\n /** The floating element */\n floating?(props: {\n /** The width of the reference element if `resize` is true and placement is on the y axis */\n width?: string\n /** The height of the reference element if `resize` is true and placement is on the x axis */\n height?: string\n /** The middleware data return by Floating UI */\n data?: MiddlewareData\n }): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\n\nconst floatingRef: Ref<HTMLElement | null> = ref(null)\nconst wrapperRef: Ref<HTMLElement | null> = ref(null)\n\nconst targetRef = computed<HTMLElement | undefined>(() => {\n if (typeof window !== 'undefined' && wrapperRef.value) {\n // If target is a string (id), try to find it in the shadow root we are in, or the document\n if (typeof target === 'string') {\n const root = wrapperRef.value.getRootNode()\n const t = (isShadowRoot(root) ? root : document).getElementById(target)\n if (t) {\n return t\n }\n console.warn(`ScalarFloating: Target with id=\"${target}\" not found`)\n }\n // If target is an HTMLElement, return it\n else if (target instanceof HTMLElement) {\n return target\n }\n // Fallback to div wrapper if no child element is provided\n const firstChild = wrapperRef.value.children?.[0]\n if (firstChild instanceof HTMLElement) {\n return firstChild\n }\n return wrapperRef.value\n }\n // Return undefined if nothing is found\n return undefined\n})\n\nconst targetSize = useResizeWithTarget(targetRef, {\n enabled: computed(() => resize),\n})\n\nconst targetWidth = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'y'\n ? targetSize.width.value\n : undefined,\n)\n\nconst targetHeight = computed(() =>\n getSideAxis(placement ?? 'bottom') === 'x'\n ? targetSize.height.value\n : undefined,\n)\n\n/**\n * Starts Floating UI's `autoUpdate` one tick after both elements exist.\n *\n * `useFloating` attaches `autoUpdate` from a synchronous watch the moment the\n * template refs resolve, and `autoUpdate` positions the element right away.\n * Template refs resolve in the post-render phase of a flush, so that first\n * `computePosition` reads layout while the same flush is still mounting other\n * components: every floating element mounted together (for example the closed\n * listboxes of a schema with many compositions) forces its own style recalc and\n * layout on a tree that was dirtied again in between. Waiting for `nextTick`\n * runs every first positioning back-to-back once the flush has settled, so the\n * browser recalculates the tree once for all of them. The tick resolves before\n * the next paint, so an element that mounts open is positioned in the same task.\n */\nconst deferredAutoUpdate: typeof autoUpdate = (\n reference,\n floating,\n update,\n options,\n) => {\n let cleanup: (() => void) | undefined\n let disposed = false\n\n void nextTick(() => {\n if (!disposed) {\n cleanup = autoUpdate(reference, floating, update, options)\n }\n })\n\n return () => {\n disposed = true\n cleanup?.()\n }\n}\n\nconst { floatingStyles, middlewareData } = useFloating(targetRef, floatingRef, {\n placement: computed(() => placement ?? 'bottom'),\n whileElementsMounted: deferredAutoUpdate,\n middleware: computed(() => [\n offsetMiddleware(offset),\n flip({ padding: 48 }),\n shift({ padding: 8 }),\n size({\n apply({ availableWidth, availableHeight, elements }) {\n // Assign the max width and height to the floating element\n // @see https://floating-ui.com/docs/size\n Object.assign(elements.floating.style, {\n maxWidth: `${Math.max(0, availableWidth) - 16}px`,\n maxHeight: `${Math.max(0, availableHeight) - 16}px`,\n })\n },\n }),\n ...middleware,\n ]),\n})\n\ndefineExpose({\n /** The resolved target element */\n targetRef,\n})\n</script>\n<template>\n <div\n ref=\"wrapperRef\"\n :class=\"{ contents: !!$slots.default }\">\n <slot />\n </div>\n <ScalarTeleport\n v-if=\"$slots.floating\"\n :disabled=\"!teleport\"\n :to=\"typeof teleport === 'string' ? teleport : undefined\">\n <div\n ref=\"floatingRef\"\n class=\"z-context relative\"\n :style=\"floatingStyles\">\n <slot\n :data=\"middlewareData\"\n :height=\"targetHeight\"\n name=\"floating\"\n :width=\"targetWidth\" />\n </div>\n </ScalarTeleport>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0DA,MAAM,cAAuC,IAAI,IAAI;EACrD,MAAM,aAAsC,IAAI,IAAI;EAEpD,MAAM,YAAY,eAAwC;GACxD,IAAI,OAAO,WAAW,eAAe,WAAW,OAAO;IAErD,IAAI,OAAO,QAAA,WAAW,UAAU;KAC9B,MAAM,OAAO,WAAW,MAAM,YAAY;KAC1C,MAAM,KAAK,a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mBAC7B;QACb,yCAAyC;QACzC,IAAI,EAAE,OAAO,CAAA;KACd,GAAG,OAAO;EAoLT,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarListbox.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarListbox/ScalarListbox.vue"],"names":[],"mappings":"AAqIA,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC;;;;;;;;;;GAUG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;aAYL,MAAM,EAAE;SACZ,MAAM;YACH,MAAM;;eAZL,KAAK,GAAG,SAAS;iBACf,MAAM,GAAG,SAAS;;aASpB,MAAM,EAAE;SACZ,MAAM;YACH,MAAM;;cAPN,IAAI;iBACD,MAAM,EAAE,GAAG,SAAS;;;;aAItB,MAAM,EAAE;SACZ,MAAM;YACH,MAAM;;eAZL,KAAK,GAAG,SAAS;iBACf,MAAM,GAAG,SAAS;;aASpB,MAAM,EAAE;SACZ,MAAM;YACH,MAAM;;cAPN,IAAI;iBACD,MAAM,EAAE,GAAG,SAAS;;;;IAmBjC,4CAA4C;mBAC7B;QACb,yCAAyC;QACzC,IAAI,EAAE,OAAO,CAAA;KACd,GAAG,OAAO;EAwMT,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -32,6 +32,14 @@ var ScalarListbox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ de
32
32
  emits: ["update:modelValue"],
33
33
  setup(__props) {
34
34
  const { cx } = useBindCx();
35
+ /**
36
+ * Headless UI waits two animation frames to focus the listbox after a click.
37
+ * Focus the mounted options immediately so Escape reaches the listbox before
38
+ * the enclosing dialog can handle it.
39
+ */
40
+ const focusOptions = ({ el }) => {
41
+ if (el instanceof HTMLElement) el.focus({ preventScroll: true });
42
+ };
35
43
  return (_ctx, _cache) => {
36
44
  return openBlock(), createBlock(unref(Listbox), {
37
45
  modelValue: __props.modelValue,
@@ -48,7 +56,10 @@ var ScalarListbox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ de
48
56
  floating: withCtx(({ width }) => [open ? (openBlock(), createElementBlock("div", mergeProps({
49
57
  key: 0,
50
58
  style: { width }
51
- }, unref(cx)("relative flex max-h-[inherit] w-40 max-w-[inherit] rounded-xl bg-b-1 dark:bg-b-1.5 text-sm shadow-md inset-shadow-border")), [createElementVNode("div", _hoisted_1, [createVNode(unref(ListboxOptions), { class: "flex flex-col gap-0.75 p-0.75 -outline-offset-1" }, {
59
+ }, unref(cx)("relative flex max-h-[inherit] w-40 max-w-[inherit] rounded-xl bg-b-1 dark:bg-b-1.5 text-sm shadow-md inset-shadow-border")), [createElementVNode("div", _hoisted_1, [createVNode(unref(ListboxOptions), {
60
+ class: "flex flex-col gap-0.75 p-0.75 -outline-offset-1",
61
+ onVnodeMounted: focusOptions
62
+ }, {
52
63
  default: withCtx(() => [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.options, (option) => {
53
64
  return openBlock(), createBlock(ScalarListboxItem_default, {
54
65
  key: option.id,
@@ -57,7 +68,7 @@ var ScalarListbox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ de
57
68
  }, null, 8, ["multiselect", "option"]);
58
69
  }), 128))]),
59
70
  _: 1
60
- })])], 16)) : createCommentVNode("", true)]),
71
+ }, 512)])], 16)) : createCommentVNode("", true)]),
61
72
  default: withCtx(() => [createVNode(unref(ListboxButton), {
62
73
  id: __props.id,
63
74
  as: "template"
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarListbox.vue.js","names":["$emit","$props","_openBlock","_createBlock","_unref","_withCtx","_createTextVNode","_toDisplayString","_createVNode","ScalarFloating","_mergeProps","_createElementBlock","_createElementVNode","_Fragment","_renderList","ScalarListboxOption","_renderSlot"],"sources":["../../../src/components/ScalarListbox/ScalarListbox.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Listbox component\n *\n * A dropdown select component built on HeadlessUI Listbox.\n * Supports single and multiple selection modes.\n *\n * @example\n * <ScalarListbox v-model=\"selected\" :options=\"options\">\n * <ScalarButton>{{ selected?.label ?? 'Select' }}</ScalarButton>\n * </ScalarListbox>\n */\nexport default {}\n</script>\n\n<script setup lang=\"ts\">\nimport {\n Listbox,\n ListboxButton,\n ListboxLabel,\n ListboxOptions,\n} from '@headlessui/vue'\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\n\nimport { ScalarFloating, type ScalarFloatingOptions } from '../ScalarFloating'\nimport ScalarListboxOption from './ScalarListboxItem.vue'\nimport type { Option } from './types'\n\ntype SingleSelectListboxProps = {\n multiple?: false | undefined\n modelValue?: Option | undefined\n}\n\ntype MultipleSelectListboxProps = {\n multiple: true\n modelValue?: Option[] | undefined\n}\n\ndefineProps<\n {\n options: Option[]\n id?: string\n label?: string\n } & (SingleSelectListboxProps | MultipleSelectListboxProps) &\n ScalarFloatingOptions\n>()\n\ndefineEmits<{\n (e: 'update:modelValue', v: Option): void\n}>()\n\ndefineSlots<{\n /** The reference element for the listbox */\n default(props: {\n /** Whether or not the listbox is open */\n open: boolean\n }): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n</script>\n<template>\n <Listbox\n v-slot=\"{ open }\"\n :modelValue=\"modelValue\"\n :multiple=\"multiple\"\n @update:modelValue=\"(v) => $emit('update:modelValue', v)\">\n <ListboxLabel\n v-if=\"label\"\n class=\"sr-only\">\n {{ label }}\n </ListboxLabel>\n <ScalarFloating\n v-bind=\"$props\"\n :placement=\"placement ?? 'bottom-start'\">\n <ListboxButton\n :id=\"id\"\n as=\"template\">\n <slot :open=\"open\" />\n </ListboxButton>\n <template #floating=\"{ width }\">\n <!-- Background container -->\n <div\n v-if=\"open\"\n :style=\"{ width }\"\n v-bind=\"\n cx(\n 'relative flex max-h-[inherit] w-40 max-w-[inherit] rounded-xl bg-b-1 dark:bg-b-1.5 text-sm shadow-md inset-shadow-border',\n )\n \">\n <!-- Scroll container -->\n <div class=\"custom-scroll min-h-0 flex-1 rounded-[inherit]\">\n <!-- Options list -->\n <ListboxOptions\n class=\"flex flex-col gap-0.75 p-0.75 -outline-offset-1\">\n <ScalarListboxOption\n v-for=\"option in options\"\n :key=\"option.id\"\n :multiselect=\"multiple\"\n :option=\"option\" />\n </ListboxOptions>\n </div>\n </div>\n </template>\n </ScalarFloating>\n </Listbox>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4DA,MAAM,EAAE,OAAO,UAAU;;GAGvB,OAAAE,UAAA,GAAAC,YA2CUC,MAAA,OAAA,GAAA;IAzCP,YAAY,QAAA;IACZ,UAAU,QAAA;IACV,uBAAiB,OAAA,OAAA,OAAA,MAAG,MAAMJ,KAAAA,MAAK,qBAAsB,CAAC;;IACvD,SAAAK,SAIe,EARL,WAAI,CAKN,QAAA,SADRH,UAAA,GAAAC,YAIeC,MAAA,YAAA,GAAA;;KAFb,OAAM;;KACN,SAAAC,cAAW,CAARC,gBAAAC,gBAAA,QAAA,KAAK,GAAA,CAAA,C;;I,oCAEVC,YAgCiBJ,MAAAK,sBAAA,GAhCjBC,WACUT,KA+BO,QA/BD,EACb,WAAW,QAAA,aAAS,e;KAMV,UAAQI,SAsBX,EAtBe,YAAK,CAGlB,QADRH,UAAA,GAAAS,mBAoBM,OApBND,WAoBM;;MAlBH,OAAK,EAAI,MAAK;K,GACMN,MAAA,EAAA,CAAE,C,+HAMvBQ,mBAUM,OAVN,YAUM,CARJJ,YAOiBJ,MAAA,cAAA,GAAA,EANf,OAAM,kDAAiD,GAAA;MAErD,SAAAC,cAAyB,EAD3BH,UAAA,IAAA,GAAAS,mBAIqBE,UAAA,MAAAC,WAHF,QAAA,UAAV,WAAM;OADf,OAAAZ,UAAA,GAAAC,YAIqBY,2BAAA;QAFlB,KAAK,OAAO;QACZ,aAAa,QAAA;QACL;;;;;KAxBnB,SAAAV,cAIgB,CAJhBG,YAIgBJ,MAAA,aAAA,GAAA;MAHb,IAAI,QAAA;MACL,IAAG;;MACH,SAAAC,cAAqB,CAArBW,WAAqB,KAAA,QAAA,WAAA,EAAR,KAAI,CAAA,C"}
1
+ {"version":3,"file":"ScalarListbox.vue.js","names":["$emit","$props","_openBlock","_createBlock","_unref","_withCtx","_createTextVNode","_toDisplayString","_createVNode","ScalarFloating","_mergeProps","_createElementBlock","_createElementVNode","_Fragment","_renderList","ScalarListboxOption","_renderSlot"],"sources":["../../../src/components/ScalarListbox/ScalarListbox.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Listbox component\n *\n * A dropdown select component built on HeadlessUI Listbox.\n * Supports single and multiple selection modes.\n *\n * @example\n * <ScalarListbox v-model=\"selected\" :options=\"options\">\n * <ScalarButton>{{ selected?.label ?? 'Select' }}</ScalarButton>\n * </ScalarListbox>\n */\nexport default {}\n</script>\n\n<script setup lang=\"ts\">\nimport {\n Listbox,\n ListboxButton,\n ListboxLabel,\n ListboxOptions,\n} from '@headlessui/vue'\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\nimport type { VNode } from 'vue'\n\nimport { ScalarFloating, type ScalarFloatingOptions } from '../ScalarFloating'\nimport ScalarListboxOption from './ScalarListboxItem.vue'\nimport type { Option } from './types'\n\ntype SingleSelectListboxProps = {\n multiple?: false | undefined\n modelValue?: Option | undefined\n}\n\ntype MultipleSelectListboxProps = {\n multiple: true\n modelValue?: Option[] | undefined\n}\n\ndefineProps<\n {\n options: Option[]\n id?: string\n label?: string\n } & (SingleSelectListboxProps | MultipleSelectListboxProps) &\n ScalarFloatingOptions\n>()\n\ndefineEmits<{\n (e: 'update:modelValue', v: Option): void\n}>()\n\ndefineSlots<{\n /** The reference element for the listbox */\n default(props: {\n /** Whether or not the listbox is open */\n open: boolean\n }): unknown\n}>()\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n\n/**\n * Headless UI waits two animation frames to focus the listbox after a click.\n * Focus the mounted options immediately so Escape reaches the listbox before\n * the enclosing dialog can handle it.\n */\nconst focusOptions = ({ el }: VNode): void => {\n if (el instanceof HTMLElement) {\n el.focus({ preventScroll: true })\n }\n}\n</script>\n<template>\n <Listbox\n v-slot=\"{ open }\"\n :modelValue=\"modelValue\"\n :multiple=\"multiple\"\n @update:modelValue=\"(v) => $emit('update:modelValue', v)\">\n <ListboxLabel\n v-if=\"label\"\n class=\"sr-only\">\n {{ label }}\n </ListboxLabel>\n <ScalarFloating\n v-bind=\"$props\"\n :placement=\"placement ?? 'bottom-start'\">\n <ListboxButton\n :id=\"id\"\n as=\"template\">\n <slot :open=\"open\" />\n </ListboxButton>\n <template #floating=\"{ width }\">\n <!-- Background container -->\n <div\n v-if=\"open\"\n :style=\"{ width }\"\n v-bind=\"\n cx(\n 'relative flex max-h-[inherit] w-40 max-w-[inherit] rounded-xl bg-b-1 dark:bg-b-1.5 text-sm shadow-md inset-shadow-border',\n )\n \">\n <!-- Scroll container -->\n <div class=\"custom-scroll min-h-0 flex-1 rounded-[inherit]\">\n <!-- Options list -->\n <ListboxOptions\n class=\"flex flex-col gap-0.75 p-0.75 -outline-offset-1\"\n @vue:mounted=\"focusOptions\">\n <ScalarListboxOption\n v-for=\"option in options\"\n :key=\"option.id\"\n :multiselect=\"multiple\"\n :option=\"option\" />\n </ListboxOptions>\n </div>\n </div>\n </template>\n </ScalarFloating>\n </Listbox>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6DA,MAAM,EAAE,OAAO,UAAU;;;;;;EAOzB,MAAM,gBAAgB,EAAE,SAAsB;GAC5C,IAAI,cAAc,aAChB,GAAG,MAAM,EAAE,eAAe,KAAK,CAAC;EAEpC;;GAGE,OAAAE,UAAA,GAAAC,YA4CUC,MAAA,OAAA,GAAA;IA1CP,YAAY,QAAA;IACZ,UAAU,QAAA;IACV,uBAAiB,OAAA,OAAA,OAAA,MAAG,MAAMJ,KAAAA,MAAK,qBAAsB,CAAC;;IACvD,SAAAK,SAIe,EARL,WAAI,CAKN,QAAA,SADRH,UAAA,GAAAC,YAIeC,MAAA,YAAA,GAAA;;KAFb,OAAM;;KACN,SAAAC,cAAW,CAARC,gBAAAC,gBAAA,QAAA,KAAK,GAAA,CAAA,C;;I,oCAEVC,YAiCiBJ,MAAAK,sBAAA,GAjCjBC,WACUT,KAgCO,QAhCD,EACb,WAAW,QAAA,aAAS,e;KAMV,UAAQI,SAuBX,EAvBe,YAAK,CAGlB,QADRH,UAAA,GAAAS,mBAqBM,OArBND,WAqBM;;MAnBH,OAAK,EAAI,MAAK;K,GACMN,MAAA,EAAA,CAAE,C,+HAMvBQ,mBAWM,OAXN,YAWM,CATJJ,YAQiBJ,MAAA,cAAA,GAAA;MAPf,OAAM;MACL,gBAAa;;MAEZ,SAAAC,cAAyB,EAD3BH,UAAA,IAAA,GAAAS,mBAIqBE,UAAA,MAAAC,WAHF,QAAA,UAAV,WAAM;OADf,OAAAZ,UAAA,GAAAC,YAIqBY,2BAAA;QAFlB,KAAK,OAAO;QACZ,aAAa,QAAA;QACL;;;;;KAzBnB,SAAAV,cAIgB,CAJhBG,YAIgBJ,MAAA,aAAA,GAAA;MAHb,IAAI,QAAA;MACL,IAAG;;MACH,SAAAC,cAAqB,CAArBW,WAAqB,KAAA,QAAA,WAAA,EAAR,KAAI,CAAA,C"}
@@ -1,7 +1,7 @@
1
1
  import { useTeleport } from "./useTeleport.js";
2
2
  import { Teleport, computed, createBlock, createElementVNode, defineComponent, getCurrentInstance, inject, mergeProps, nextTick, onMounted, openBlock, ref, renderSlot, shallowRef, ssrContextKey, useTemplateRef, watch } from "vue";
3
- import { getActiveElement } from "@scalar/helpers/dom/get-active-element";
4
3
  import { isShadowRoot } from "@scalar/helpers/dom/is-shadow-root";
4
+ import { getActiveElement } from "@scalar/helpers/dom/get-active-element";
5
5
  import { useDocumentRoot } from "@scalar/use-hooks/useDocumentRoot";
6
6
  var ScalarTeleport_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
7
7
  inheritAttrs: false,
@@ -10,7 +10,11 @@ declare const _default: typeof __VLS_export;
10
10
  export default _default;
11
11
  declare const __VLS_export: import("vue").DefineComponent<{
12
12
  css: string;
13
+ /** The theme CSS this one sits on top of, used for any color `css` leaves out */
14
+ baseCss?: string;
13
15
  }, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{
14
16
  css: string;
17
+ /** The theme CSS this one sits on top of, used for any color `css` leaves out */
18
+ baseCss?: string;
15
19
  }> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
16
20
  //# sourceMappingURL=ScalarThemeSwatches.vue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarThemeSwatches.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarThemeSwatches/ScalarThemeSwatches.vue"],"names":[],"mappings":"AAoDA;;;;;;;GAOG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;SAEX,MAAM;;SAAN,MAAM;iGA2DT,CAAC"}
1
+ {"version":3,"file":"ScalarThemeSwatches.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarThemeSwatches/ScalarThemeSwatches.vue"],"names":[],"mappings":"AAyDA;;;;;;;GAOG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;SAEX,MAAM;IACX,iFAAiF;cACvE,MAAM;;SAFX,MAAM;IACX,iFAAiF;cACvE,MAAM;iGA8Dd,CAAC"}
@@ -4,9 +4,12 @@ import { Fragment, createElementBlock, defineComponent, mergeProps, normalizeSty
4
4
  var ScalarThemeSwatches_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
5
5
  inheritAttrs: false,
6
6
  __name: "ScalarThemeSwatches",
7
- props: { css: {} },
7
+ props: {
8
+ css: {},
9
+ baseCss: { default: "" }
10
+ },
8
11
  setup(__props) {
9
- const { colors } = useThemeSwatches(() => __props.css);
12
+ const { colors } = useThemeSwatches(() => __props.css, () => __props.baseCss);
10
13
  const { cx } = useBindCx();
11
14
  return (_ctx, _cache) => {
12
15
  return openBlock(), createElementBlock("div", mergeProps({ style: {
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarThemeSwatches.vue.js","names":["_openBlock","_createElementBlock","_mergeProps","_unref","_Fragment","_renderList","_normalizeStyle"],"sources":["../../../src/components/ScalarThemeSwatches/ScalarThemeSwatches.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Theme Swatches component\n *\n * Displays the light and dark mode swatches for a given theme CSS string\n *\n * @example\n * <ScalarThemeSwatches :css=\"theme\" />\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\n\nimport { THEME_CSS_VARS, useThemeSwatches } from './useThemeSwatches'\n\nconst { css } = defineProps<{\n css: string\n}>()\n\nconst { colors } = useThemeSwatches(() => css)\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n</script>\n<template>\n <div\n :style=\"{\n '--bg-light': colors.light['--scalar-background-1'],\n '--bg-dark': colors.dark['--scalar-background-1'],\n }\"\n v-bind=\"\n cx(\n 'flex *:size-3 overflow-hidden rounded',\n 'bg-(--bg-light) dark:bg-(--bg-dark)',\n )\n \">\n <div\n v-for=\"v in THEME_CSS_VARS\"\n :key=\"v\"\n class=\"bg-(--bg-light) dark:bg-(--bg-dark)\"\n :style=\"{ '--bg-light': colors.light[v], '--bg-dark': colors.dark[v] }\" />\n </div>\n</template>\n"],"mappings":";;;;;;;;EAoBA,MAAM,EAAE,WAAW,uBAAuB,QAAA,GAAG;EAG7C,MAAM,EAAE,OAAO,UAAU;;GAGvB,OAAAA,UAAA,GAAAC,mBAgBM,OAhBNC,WAgBM,EAfH,OAAK;IAAwB,cAAAC,MAAA,MAAA,CAAM,CAAC,MAAK;IAA8C,aAAAA,MAAA,MAAA,CAAM,CAAC,KAAI;G,KAIpFA,MAAA,EAAA,CAAE,C,oFAMjBH,UAAA,IAAA,GAAAC,mBAI4EG,UAAA,MAAAC,WAH9DF,MAAA,cAAA,IAAL,MAAC;IADV,OAAAH,UAAA,GAAAC,mBAI4E,OAAA;KAFzE,KAAK;KACN,OAAM;KACL,OAAKK,eAAA;MAAA,cAAkBH,MAAA,MAAA,CAAM,CAAC,MAAM;MAAC,aAAgBA,MAAA,MAAA,CAAM,CAAC,KAAK;KAAC,CAAA"}
1
+ {"version":3,"file":"ScalarThemeSwatches.vue.js","names":["_openBlock","_createElementBlock","_mergeProps","_unref","_Fragment","_renderList","_normalizeStyle"],"sources":["../../../src/components/ScalarThemeSwatches/ScalarThemeSwatches.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar Theme Swatches component\n *\n * Displays the light and dark mode swatches for a given theme CSS string\n *\n * @example\n * <ScalarThemeSwatches :css=\"theme\" />\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { useBindCx } from '@scalar/use-hooks/useBindCx'\n\nimport { THEME_CSS_VARS, useThemeSwatches } from './useThemeSwatches'\n\nconst { css, baseCss = '' } = defineProps<{\n css: string\n /** The theme CSS this one sits on top of, used for any color `css` leaves out */\n baseCss?: string\n}>()\n\nconst { colors } = useThemeSwatches(\n () => css,\n () => baseCss,\n)\n\ndefineOptions({ inheritAttrs: false })\nconst { cx } = useBindCx()\n</script>\n<template>\n <div\n :style=\"{\n '--bg-light': colors.light['--scalar-background-1'],\n '--bg-dark': colors.dark['--scalar-background-1'],\n }\"\n v-bind=\"\n cx(\n 'flex *:size-3 overflow-hidden rounded',\n 'bg-(--bg-light) dark:bg-(--bg-dark)',\n )\n \">\n <div\n v-for=\"v in THEME_CSS_VARS\"\n :key=\"v\"\n class=\"bg-(--bg-light) dark:bg-(--bg-dark)\"\n :style=\"{ '--bg-light': colors.light[v], '--bg-dark': colors.dark[v] }\" />\n </div>\n</template>\n"],"mappings":";;;;;;;;;;;EAsBA,MAAM,EAAE,WAAW,uBACX,QAAA,WACA,QAAA,OACR;EAGA,MAAM,EAAE,OAAO,UAAU;;GAGvB,OAAAA,UAAA,GAAAC,mBAgBM,OAhBNC,WAgBM,EAfH,OAAK;IAAwB,cAAAC,MAAA,MAAA,CAAM,CAAC,MAAK;IAA8C,aAAAA,MAAA,MAAA,CAAM,CAAC,KAAI;G,KAIpFA,MAAA,EAAA,CAAE,C,oFAMjBH,UAAA,IAAA,GAAAC,mBAI4EG,UAAA,MAAAC,WAH9DF,MAAA,cAAA,IAAL,MAAC;IADV,OAAAH,UAAA,GAAAC,mBAI4E,OAAA;KAFzE,KAAK;KACN,OAAM;KACL,OAAKK,eAAA;MAAA,cAAkBH,MAAA,MAAA,CAAM,CAAC,MAAM;MAAC,aAAgBA,MAAA,MAAA,CAAM,CAAC,KAAK;KAAC,CAAA"}
@@ -20,8 +20,10 @@ type ThemeCssVars = Partial<Record<ThemeCssVar, string>>;
20
20
  export declare const THEME_CSS_VARS: ["--scalar-color-1", "--scalar-color-2", "--scalar-color-3", "--scalar-background-1", "--scalar-background-2", "--scalar-background-3", "--scalar-color-accent"];
21
21
  /**
22
22
  * Returns the light and dark colors for a given css string
23
+ *
24
+ * Colors the css leaves out come from the base css, the way a partial theme renders on top of another one
23
25
  */
24
- export declare function useThemeSwatches(css: MaybeRefOrGetter<string>): {
26
+ export declare function useThemeSwatches(css: MaybeRefOrGetter<string>, baseCss?: MaybeRefOrGetter<string>): {
25
27
  colors: import("vue").ComputedRef<ThemeColors>;
26
28
  };
27
29
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"useThemeSwatches.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarThemeSwatches/useThemeSwatches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,KAAK,CAAA;AAE9D,qBAAqB;AACrB,KAAK,UAAU,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAE3B;;GAEG;AACH,KAAK,WAAW,GAAG,kBAAkB,UAAU,EAAE,GAAG,uBAAuB,UAAU,EAAE,GAAG,uBAAuB,CAAA;AAEjH;;GAEG;AACH,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,YAAY,CAAA;IACnB,IAAI,EAAE,YAAY,CAAA;CACnB,CAAA;AAED;;GAEG;AACH,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAA;AAExD,0BAA0B;AAC1B,eAAO,MAAM,cAAc,kKAQO,CAAA;AA2BlC;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC;;EAO7D"}
1
+ {"version":3,"file":"useThemeSwatches.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarThemeSwatches/useThemeSwatches.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,KAAK,CAAA;AAE9D,qBAAqB;AACrB,KAAK,UAAU,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAE3B;;GAEG;AACH,KAAK,WAAW,GAAG,kBAAkB,UAAU,EAAE,GAAG,uBAAuB,UAAU,EAAE,GAAG,uBAAuB,CAAA;AAEjH;;GAEG;AACH,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,YAAY,CAAA;IACnB,IAAI,EAAE,YAAY,CAAA;CACnB,CAAA;AAED;;GAEG;AACH,KAAK,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAA;AAExD,0BAA0B;AAC1B,eAAO,MAAM,cAAc,kKAQO,CAAA;AAyDlC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,GAAE,gBAAgB,CAAC,MAAM,CAAM;;EAWrG"}
@@ -1,4 +1,5 @@
1
1
  import { computed, toValue } from "vue";
2
+ import { getColorModesFromSelectors } from "@scalar/helpers/theme/load-css-variables";
2
3
  // src/components/ScalarThemeSwatches/useThemeSwatches.ts
3
4
  /** Theme CSS variables */
4
5
  var THEME_CSS_VARS = [
@@ -12,17 +13,18 @@ var THEME_CSS_VARS = [
12
13
  ];
13
14
  /**
14
15
  * Parses a given css string for a css variable regexp
16
+ *
17
+ * Whitespace and the last semicolon are optional, so minified css works too
15
18
  */
16
19
  function getVars(cssVarPattern, css) {
17
- const matches = [...css.matchAll(new RegExp(`(${cssVarPattern}): ([^;]+);`, "gm"))];
20
+ const matches = [...css.matchAll(new RegExp(`(${cssVarPattern})\\s*:\\s*([^;}]+)`, "gm"))];
18
21
  if (matches.length === 0) return {};
19
- return Object.fromEntries(matches.map((match) => [match[1], match[2]]));
22
+ return Object.fromEntries(matches.map((match) => [match[1], match[2]?.trim()]));
20
23
  }
21
24
  /**
22
25
  * Parses a given css string for the variables we want
23
26
  */
24
27
  function parseRules(css) {
25
- if (!css) return {};
26
28
  return {
27
29
  ...getVars("--scalar-color-[1-3]", css),
28
30
  ...getVars("--scalar-background-[1-3]", css),
@@ -30,13 +32,50 @@ function parseRules(css) {
30
32
  };
31
33
  }
32
34
  /**
35
+ * Parses the light and dark colors from a given css string
36
+ */
37
+ function parseColors(css) {
38
+ const colors = {
39
+ light: {},
40
+ dark: {}
41
+ };
42
+ const rules = css.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]*)\{|([^{}]*)\}/gy);
43
+ let depth = 0;
44
+ let modes = [];
45
+ for (const [, selectorList, declarations] of rules) {
46
+ if (selectorList !== void 0) {
47
+ if (depth === 0) modes = getColorModesFromSelectors(selectorList);
48
+ depth++;
49
+ continue;
50
+ }
51
+ depth--;
52
+ if (depth === 0 && declarations && modes.length > 0) {
53
+ const variables = parseRules(declarations);
54
+ for (const mode of modes) Object.assign(colors[mode], variables);
55
+ }
56
+ }
57
+ return colors;
58
+ }
59
+ /**
33
60
  * Returns the light and dark colors for a given css string
61
+ *
62
+ * Colors the css leaves out come from the base css, the way a partial theme renders on top of another one
34
63
  */
35
- function useThemeSwatches(css) {
36
- return { colors: computed(() => ({
37
- light: parseRules(toValue(css).match(/\.light-mode[^{]*{[^}]*}/m)?.[0]),
38
- dark: parseRules(toValue(css).match(/\.dark-mode[^{]*{[^}]*}/m)?.[0])
39
- })) };
64
+ function useThemeSwatches(css, baseCss = "") {
65
+ return { colors: computed(() => {
66
+ const base = parseColors(toValue(baseCss));
67
+ const theme = parseColors(toValue(css));
68
+ return {
69
+ light: {
70
+ ...base.light,
71
+ ...theme.light
72
+ },
73
+ dark: {
74
+ ...base.dark,
75
+ ...theme.dark
76
+ }
77
+ };
78
+ }) };
40
79
  }
41
80
  export { THEME_CSS_VARS, useThemeSwatches };
42
81
 
@@ -1 +1 @@
1
- {"version":3,"file":"useThemeSwatches.js","names":[],"sources":["../../../src/components/ScalarThemeSwatches/useThemeSwatches.ts"],"sourcesContent":["import { type MaybeRefOrGetter, computed, toValue } from 'vue'\n\n/** Numbers 1 to 3 */\ntype OneToThree = 1 | 2 | 3\n\n/**\n * CSS variable names that can be extracted from theme CSS\n */\ntype ThemeCssVar = `--scalar-color-${OneToThree}` | `--scalar-background-${OneToThree}` | '--scalar-color-accent'\n\n/**\n * Theme colors for light and dark modes\n */\ntype ThemeColors = {\n light: ThemeCssVars\n dark: ThemeCssVars\n}\n\n/**\n * Record of theme CSS variables to their values (partial)\n */\ntype ThemeCssVars = Partial<Record<ThemeCssVar, string>>\n\n/** Theme CSS variables */\nexport const THEME_CSS_VARS = [\n '--scalar-color-1',\n '--scalar-color-2',\n '--scalar-color-3',\n '--scalar-background-1',\n '--scalar-background-2',\n '--scalar-background-3',\n '--scalar-color-accent',\n] as const satisfies ThemeCssVar[]\n\n/**\n * Parses a given css string for a css variable regexp\n */\nfunction getVars(cssVarPattern: string, css: string): Partial<Record<ThemeCssVar, string>> {\n const matches = [...css.matchAll(new RegExp(`(${cssVarPattern}): ([^;]+);`, 'gm'))]\n if (matches.length === 0) {\n return {}\n }\n return Object.fromEntries(matches.map((match) => [match[1], match[2]]))\n}\n\n/**\n * Parses a given css string for the variables we want\n */\nfunction parseRules(css?: string): ThemeCssVars {\n if (!css) {\n return {}\n }\n return {\n ...getVars('--scalar-color-[1-3]', css),\n ...getVars('--scalar-background-[1-3]', css),\n ...getVars('--scalar-color-accent', css),\n }\n}\n\n/**\n * Returns the light and dark colors for a given css string\n */\nexport function useThemeSwatches(css: MaybeRefOrGetter<string>) {\n return {\n colors: computed<ThemeColors>(() => ({\n light: parseRules(toValue(css).match(/\\.light-mode[^{]*{[^}]*}/m)?.[0]),\n dark: parseRules(toValue(css).match(/\\.dark-mode[^{]*{[^}]*}/m)?.[0]),\n })),\n }\n}\n"],"mappings":";;;AAwBA,IAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;AAKA,SAAS,QAAQ,eAAuB,KAAmD;CACzF,MAAM,UAAU,CAAC,GAAG,IAAI,SAAS,IAAI,OAAO,IAAI,cAAc,cAAc,IAAI,CAAC,CAAC;CAClF,IAAI,QAAQ,WAAW,GACrB,OAAO,CAAC;CAEV,OAAO,OAAO,YAAY,QAAQ,KAAK,UAAU,CAAC,MAAM,IAAI,MAAM,EAAE,CAAC,CAAC;AACxE;;;;AAKA,SAAS,WAAW,KAA4B;CAC9C,IAAI,CAAC,KACH,OAAO,CAAC;CAEV,OAAO;EACL,GAAG,QAAQ,wBAAwB,GAAG;EACtC,GAAG,QAAQ,6BAA6B,GAAG;EAC3C,GAAG,QAAQ,yBAAyB,GAAG;CACzC;AACF;;;;AAKA,SAAgB,iBAAiB,KAA+B;CAC9D,OAAO,EACL,QAAQ,gBAA6B;EACnC,OAAO,WAAW,QAAQ,GAAG,CAAC,CAAC,MAAM,2BAA2B,CAAC,GAAG,EAAE;EACtE,MAAM,WAAW,QAAQ,GAAG,CAAC,CAAC,MAAM,0BAA0B,CAAC,GAAG,EAAE;CACtE,EAAE,EACJ;AACF"}
1
+ {"version":3,"file":"useThemeSwatches.js","names":[],"sources":["../../../src/components/ScalarThemeSwatches/useThemeSwatches.ts"],"sourcesContent":["import { getColorModesFromSelectors } from '@scalar/helpers/theme/load-css-variables'\nimport { type MaybeRefOrGetter, computed, toValue } from 'vue'\n\n/** Numbers 1 to 3 */\ntype OneToThree = 1 | 2 | 3\n\n/**\n * CSS variable names that can be extracted from theme CSS\n */\ntype ThemeCssVar = `--scalar-color-${OneToThree}` | `--scalar-background-${OneToThree}` | '--scalar-color-accent'\n\n/**\n * Theme colors for light and dark modes\n */\ntype ThemeColors = {\n light: ThemeCssVars\n dark: ThemeCssVars\n}\n\n/**\n * Record of theme CSS variables to their values (partial)\n */\ntype ThemeCssVars = Partial<Record<ThemeCssVar, string>>\n\n/** Theme CSS variables */\nexport const THEME_CSS_VARS = [\n '--scalar-color-1',\n '--scalar-color-2',\n '--scalar-color-3',\n '--scalar-background-1',\n '--scalar-background-2',\n '--scalar-background-3',\n '--scalar-color-accent',\n] as const satisfies ThemeCssVar[]\n\n/**\n * Parses a given css string for a css variable regexp\n *\n * Whitespace and the last semicolon are optional, so minified css works too\n */\nfunction getVars(cssVarPattern: string, css: string): Partial<Record<ThemeCssVar, string>> {\n const matches = [...css.matchAll(new RegExp(`(${cssVarPattern})\\\\s*:\\\\s*([^;}]+)`, 'gm'))]\n if (matches.length === 0) {\n return {}\n }\n return Object.fromEntries(matches.map((match) => [match[1], match[2]?.trim()]))\n}\n\n/**\n * Parses a given css string for the variables we want\n */\nfunction parseRules(css: string): ThemeCssVars {\n return {\n ...getVars('--scalar-color-[1-3]', css),\n ...getVars('--scalar-background-[1-3]', css),\n ...getVars('--scalar-color-accent', css),\n }\n}\n\n/**\n * Parses the light and dark colors from a given css string\n */\nfunction parseColors(css: string): ThemeColors {\n const colors: ThemeColors = { light: {}, dark: {} }\n const rules = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '').matchAll(/([^{}]*)\\{|([^{}]*)\\}/gy)\n let depth = 0\n let modes: (keyof ThemeColors)[] = []\n\n // Swatches represent the top-level palette. Conditional and descendant rules\n // depend on the page context, which is not available during server rendering.\n for (const [, selectorList, declarations] of rules) {\n if (selectorList !== undefined) {\n if (depth === 0) {\n modes = getColorModesFromSelectors(selectorList)\n }\n depth++\n continue\n }\n\n depth--\n if (depth === 0 && declarations && modes.length > 0) {\n const variables = parseRules(declarations)\n for (const mode of modes) {\n Object.assign(colors[mode], variables)\n }\n }\n }\n return colors\n}\n\n/**\n * Returns the light and dark colors for a given css string\n *\n * Colors the css leaves out come from the base css, the way a partial theme renders on top of another one\n */\nexport function useThemeSwatches(css: MaybeRefOrGetter<string>, baseCss: MaybeRefOrGetter<string> = '') {\n return {\n colors: computed<ThemeColors>(() => {\n const base = parseColors(toValue(baseCss))\n const theme = parseColors(toValue(css))\n return {\n light: { ...base.light, ...theme.light },\n dark: { ...base.dark, ...theme.dark },\n }\n }),\n }\n}\n"],"mappings":";;;;AAyBA,IAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;AAOA,SAAS,QAAQ,eAAuB,KAAmD;CACzF,MAAM,UAAU,CAAC,GAAG,IAAI,SAAS,IAAI,OAAO,IAAI,cAAc,qBAAqB,IAAI,CAAC,CAAC;CACzF,IAAI,QAAQ,WAAW,GACrB,OAAO,CAAC;CAEV,OAAO,OAAO,YAAY,QAAQ,KAAK,UAAU,CAAC,MAAM,IAAI,MAAM,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;AAChF;;;;AAKA,SAAS,WAAW,KAA2B;CAC7C,OAAO;EACL,GAAG,QAAQ,wBAAwB,GAAG;EACtC,GAAG,QAAQ,6BAA6B,GAAG;EAC3C,G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CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"ScalarTooltip.vue.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarTooltip/ScalarTooltip.vue"],"names":[],"mappings":"AAqIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIjD;;;;;;;;;GASG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;cA6CJ,CAAC,KAAK,IAAgB,KAAK,GAAG;EAWxC,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ScalarTooltip.vue.js","names":["$slots","_openBlock","_createElementBlock","_normalizeClass","_renderSlot"],"sources":["../../../src/components/ScalarTooltip/ScalarTooltip.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar tooltip component\n *\n * Adds a tooltip to an interactive element\n *\n * @example\n * <ScalarTooltip content=\"This is a tooltip\">\n * <ScalarButton>Hover Me</ScalarButton>\n * </ScalarTooltip>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { computed, ref, type Ref } from 'vue'\n\nimport { DEFAULT_DELAY, DEFAULT_OFFSET } from './constants'\nimport type { ScalarTooltipProps } from './types'\nimport { useTooltip } from './useTooltip'\n\nconst {\n delay = DEFAULT_DELAY,\n content = '',\n placement = 'top',\n offset = DEFAULT_OFFSET,\n} = defineProps<ScalarTooltipProps>()\n\nconst wrapperRef: Ref<HTMLElement | null> = ref(null)\n\nuseTooltip({\n content: computed(() => content),\n delay: computed(() => delay),\n placement: computed(() => placement),\n offset: computed(() => offset),\n targetRef: computed(\n () => wrapperRef.value?.children?.[0] || wrapperRef.value || undefined,\n ),\n})\n</script>\n<template>\n <div\n ref=\"wrapperRef\"\n :class=\"{ contents: !!$slots.default }\">\n <slot />\n </div>\n</template>\n<style>\n@reference \"../../style.css\";\n\n/**\n * Global styles for the tooltip\n *\n * The tooltip element normally sits directly on the body, but it moves into a <dialog>\n * opened with showModal() so it can paint above the top layer. Both parents have to be\n * matched here or the tooltip loses every one of these styles the moment it is\n * reparented, and renders as unstyled text on a transparent background.\n */\n:where(body, dialog) > .scalar-tooltip {\n --scalar-tooltip-padding-x: 8px;\n --scalar-tooltip-padding-y: 6px;\n\n padding: var(--scalar-tooltip-padding-y) var(--scalar-tooltip-padding-x);\n\n @apply z-tooltip text-c-tooltip max-w-xs text-xs/4 font-normal break-words;\n}\n\n/**\n * The offset is the gap between the target and the tooltip, so it only belongs\n * on the side facing the target (opposite the placement side). Applying it to\n * every side shifts the visible box inward on `-start` / `-end` placements,\n * where Floating UI aligns the floating element's edge with the target's edge.\n */\n:where(body, dialog) > .scalar-tooltip[data-side='top'] {\n padding-bottom: calc(\n var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset)\n );\n}\n:where(body, dialog) > .scalar-tooltip[data-side='bottom'] {\n padding-top: calc(\n var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset)\n );\n}\n:where(body, dialog) > .scalar-tooltip[data-side='left'] {\n padding-right: calc(\n var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset)\n );\n}\n:where(body, dialog) > .scalar-tooltip[data-side='right'] {\n padding-left: calc(\n var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset)\n );\n}\n\n/*\n * The hairline is spelled out: the preflight that gives `border` its theme colour only reaches\n * descendants of `.scalar-app`, and this element is the `.scalar-app` root itself, so the\n * utility alone would fall back to currentColor (black on light, white on dark).\n */\n:where(body, dialog) > .scalar-tooltip:before {\n content: '';\n inset: 0;\n border: var(--scalar-border-width) solid var(--scalar-border-color);\n @apply bg-b-tooltip absolute -z-1 rounded-lg shadow backdrop-blur;\n}\n\n/* Leave the gap on the target-facing side so the other edges stay flush */\n:where(body, dialog) > .scalar-tooltip[data-side='top']:before {\n bottom: var(--scalar-tooltip-offset);\n}\n:where(body, dialog) > .scalar-tooltip[data-side='bottom']:before {\n top: var(--scalar-tooltip-offset);\n}\n:where(body, dialog) > .scalar-tooltip[data-side='left']:before {\n right: var(--scalar-tooltip-offset);\n}\n:where(body, dialog) > .scalar-tooltip[data-side='right']:before {\n left: var(--scalar-tooltip-offset);\n}\n</style>\n"],"mappings":";;;;;;;;;;;EA2BA,MAAM,aAAsC,IAAI,IAAI;EAEpD,WAAW;GACT,SAAS,eAAe,QAAA,OAAO;GAC/B,OAAO,eAAe,QAAA,KAAK;GAC3B,WAAW,eAAe,QAAA,SAAS;GACnC,QAAQ,eAAe,QAAA,MAAM;GAC7B,WAAW,eACH,WAAW,OAAO,WAAW,MAAM,WAAW,SAAS,KAAA,CAC/D;EACF,CAAC;;GAGC,OAAAC,UAAA,GAAAC,mBAIM,OAAA;IAHA,SAAA;IAAJ,KAAI;IACH,OAAKC,eAAA,EAAA,UAAA,CAAA,CAAgBH,KAAAA,OAAO,QAAO,CAAA;G,IACpCI,WAAQ,KAAA,QAAA,SAAA,C"}
1
+ {"version":3,"file":"ScalarTooltip.vue.js","names":["$slots","_openBlock","_createElementBlock","_normalizeClass","_renderSlot"],"sources":["../../../src/components/ScalarTooltip/ScalarTooltip.vue"],"sourcesContent":["<script lang=\"ts\">\n/**\n * Scalar tooltip component\n *\n * Adds a tooltip to an interactive element\n *\n * @example\n * <ScalarTooltip content=\"This is a tooltip\">\n * <ScalarButton>Hover Me</ScalarButton>\n * </ScalarTooltip>\n */\nexport default {}\n</script>\n<script setup lang=\"ts\">\nimport { computed, ref, type Ref } from 'vue'\n\nimport { DEFAULT_DELAY, DEFAULT_OFFSET } from './constants'\nimport type { ScalarTooltipProps } from './types'\nimport { useTooltip } from './useTooltip'\n\nconst {\n delay = DEFAULT_DELAY,\n content = '',\n placement = 'top',\n offset = DEFAULT_OFFSET,\n} = defineProps<ScalarTooltipProps>()\n\nconst wrapperRef: Ref<HTMLElement | null> = ref(null)\n\nuseTooltip({\n content: computed(() => content),\n delay: computed(() => delay),\n placement: computed(() => placement),\n offset: computed(() => offset),\n targetRef: computed(\n () => wrapperRef.value?.children?.[0] || wrapperRef.value || undefined,\n ),\n})\n</script>\n<template>\n <div\n ref=\"wrapperRef\"\n :class=\"{ contents: !!$slots.default }\">\n <slot />\n </div>\n</template>\n<style>\n@reference \"../../style.css\";\n\n/**\n * Global styles for the tooltip\n *\n * The tooltip element normally sits directly on the body, but it moves into a <dialog>\n * opened with showModal() so it can paint above the top layer, and into the teleport root\n * when its target is inside a shadow root. Every one of these parents has to be matched\n * here or the tooltip loses all of these styles the moment it is reparented, and renders\n * as unstyled text on a transparent background.\n */\n:where(body, dialog, .scalar-teleport-root) > .scalar-tooltip {\n --scalar-tooltip-padding-x: 8px;\n --scalar-tooltip-padding-y: 6px;\n\n padding: var(--scalar-tooltip-padding-y) var(--scalar-tooltip-padding-x);\n\n @apply z-tooltip text-c-tooltip max-w-xs text-xs/4 font-normal break-words;\n}\n\n/**\n * The offset is the gap between the target and the tooltip, so it only belongs\n * on the side facing the target (opposite the placement side). Applying it to\n * every side shifts the visible box inward on `-start` / `-end` placements,\n * where Floating UI aligns the floating element's edge with the target's edge.\n */\n:where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side='top'] {\n padding-bottom: calc(\n var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset)\n );\n}\n:where(body, dialog, .scalar-teleport-root)\n > .scalar-tooltip[data-side='bottom'] {\n padding-top: calc(\n var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset)\n );\n}\n:where(body, dialog, .scalar-teleport-root)\n > .scalar-tooltip[data-side='left'] {\n padding-right: calc(\n var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset)\n );\n}\n:where(body, dialog, .scalar-teleport-root)\n > .scalar-tooltip[data-side='right'] {\n padding-left: calc(\n var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset)\n );\n}\n\n/*\n * The hairline is spelled out: the preflight that gives `border` its theme colour only reaches\n * descendants of `.scalar-app`, and this element is the `.scalar-app` root itself, so the\n * utility alone would fall back to currentColor (black on light, white on dark).\n */\n:where(body, dialog, .scalar-teleport-root) > .scalar-tooltip:before {\n content: '';\n inset: 0;\n border: var(--scalar-border-width) solid var(--scalar-border-color);\n @apply bg-b-tooltip absolute -z-1 rounded-lg shadow backdrop-blur;\n}\n\n/* Leave the gap on the target-facing side so the other edges stay flush */\n:where(body, dialog, .scalar-teleport-root)\n > .scalar-tooltip[data-side='top']:before {\n bottom: var(--scalar-tooltip-offset);\n}\n:where(body, dialog, .scalar-teleport-root)\n > .scalar-tooltip[data-side='bottom']:before {\n top: var(--scalar-tooltip-offset);\n}\n:where(body, dialog, .scalar-teleport-root)\n > .scalar-tooltip[data-side='left']:before {\n right: var(--scalar-tooltip-offset);\n}\n:where(body, dialog, .scalar-teleport-root)\n > .scalar-tooltip[data-side='right']:before {\n left: var(--scalar-tooltip-offset);\n}\n</style>\n"],"mappings":";;;;;;;;;;;EA2BA,MAAM,aAAsC,IAAI,IAAI;EAEpD,WAAW;GACT,SAAS,eAAe,QAAA,OAAO;GAC/B,OAAO,eAAe,QAAA,KAAK;GAC3B,WAAW,eAAe,QAAA,SAAS;GACnC,QAAQ,eAAe,QAAA,MAAM;GAC7B,WAAW,eACH,WAAW,OAAO,WAAW,MAAM,WAAW,SAAS,KAAA,CAC/D;EACF,CAAC;;GAGC,OAAAC,UAAA,GAAAC,mBAIM,OAAA;IAHA,SAAA;IAAJ,KAAI;IACH,OAAKC,eAAA,EAAA,UAAA,CAAA,CAAgBH,KAAAA,OAAO,QAAO,CAAA;G,IACpCI,WAAQ,KAAA,QAAA,SAAA,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarTooltip/useTooltip.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAS,oBAAoB,EAAE,MAAM,SAAS,CAAA;AA4J1D;;GAEG;AACH,wBAAgB,qBAAqB,SAGpC;AA0ID;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,oBAAoB,QA8EpD"}
1
+ {"version":3,"file":"useTooltip.d.ts","sourceRoot":"","sources":["../../../src/components/ScalarTooltip/useTooltip.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAS,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAsK1D;;GAEG;AACH,wBAAgB,qBAAqB,SAKpC;AAkKD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,oBAAoB,QA0FpD"}
@@ -1,13 +1,15 @@
1
+ import { useTeleport } from "../ScalarTeleport/useTeleport.js";
1
2
  import { ELEMENT_CLASS, ELEMENT_ID } from "./constants.js";
2
- import { computed, onScopeDispose, ref, unref, watch } from "vue";
3
+ import { computed, hasInjectionContext, onScopeDispose, ref, unref, watch } from "vue";
3
4
  import { autoUpdate, flip, shift, useFloating } from "@floating-ui/vue";
5
+ import { isShadowRoot } from "@scalar/helpers/dom/is-shadow-root";
4
6
  // src/components/ScalarTooltip/useTooltip.ts
5
7
  /**
6
8
  * The delay timer for the tooltip
7
9
  *
8
10
  * If there's not a timer running it should be undefined
9
11
  */
10
- var timer = ref();
12
+ var timer;
11
13
  /**
12
14
  * A reference to the tooltip element
13
15
  *
@@ -20,8 +22,8 @@ var el = ref();
20
22
  * If no tooltip is active it should be undefined
21
23
  */
22
24
  var config = ref();
23
- var { floatingStyles, placement, update } = useFloating(computed(() => unref(config.value?.targetRef)), el, {
24
- placement: computed(() => unref(config.value?.placement)),
25
+ var { floatingStyles, placement, update } = useFloating(computed(() => unref(config.value?.options.targetRef)), el, {
26
+ placement: computed(() => unref(config.value?.options.placement)),
25
27
  whileElementsMounted: autoUpdate,
26
28
  middleware: computed(() => [flip(), shift()])
27
29
  });
@@ -37,21 +39,22 @@ watch(floatingStyles, () => {
37
39
  el.value.style.transform = floatingStyles.value.transform ?? "";
38
40
  el.value.style.willChange = floatingStyles.value.willChange ?? "";
39
41
  });
40
- watch(config, (opts) => {
42
+ watch(config, (activeTooltip) => {
41
43
  if (!el.value) return;
42
- if (opts) {
43
- if (moveTooltipToHost(unref(opts.targetRef))) update();
44
- const contentTarget = unref(opts?.contentTarget) ?? "textContent";
45
- el.value[contentTarget] = unref(opts?.content) ?? "";
46
- const offset = unref(opts?.offset) ?? 4;
44
+ if (activeTooltip) {
45
+ const { options, teleportTarget } = activeTooltip;
46
+ if (moveTooltipToHost(unref(options.targetRef), teleportTarget)) update();
47
+ const contentTarget = unref(options.contentTarget) ?? "textContent";
48
+ el.value[contentTarget] = unref(options.content) ?? "";
49
+ const offset = unref(options.offset) ?? 4;
47
50
  el.value.style.setProperty("--scalar-tooltip-offset", `${offset}px`);
48
- el.value.dataset.side = (unref(opts?.placement) ?? "bottom").split("-")[0];
51
+ el.value.dataset.side = (unref(options.placement) ?? "bottom").split("-")[0];
49
52
  el.value.style.setProperty("display", "block");
50
53
  } else {
51
54
  el.value.innerHTML = "";
52
55
  el.value.style.removeProperty("--scalar-tooltip-offset");
53
56
  el.value.style.setProperty("display", "none");
54
- moveTooltipToHost(void 0);
57
+ moveTooltipToHost();
55
58
  }
56
59
  }, { deep: true });
57
60
  /**
@@ -83,6 +86,11 @@ function initializeTooltipElement() {
83
86
  function hideTooltip(_e) {
84
87
  if (!isMovingOffElements(_e)) return;
85
88
  clearTimer();
89
+ clearTooltip();
90
+ }
91
+ /** Clear the active tooltip and stop listening for the escape key */
92
+ function clearTooltip() {
93
+ document.removeEventListener("keydown", handleEscape, { capture: true });
86
94
  config.value = void 0;
87
95
  }
88
96
  /**
@@ -91,13 +99,13 @@ function hideTooltip(_e) {
91
99
  * If the escape key is pressed while the tooltip is showing we need to hide it, and only it.
92
100
  * Preventing the default stops the browser from also turning the key into a `cancel` request
93
101
  * for a surrounding modal `<dialog>`, which stopping propagation alone does not do. The listener
94
- * outlives a tooltip hidden by blur or mouseleave, so an Escape with no tooltip showing is left
95
- * alone for whatever else wants it.
102
+ * is only attached while a tooltip is showing, so any other Escape is left alone for whatever else
103
+ * wants it.
96
104
  *
97
105
  * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/tooltip_role#keyboard_interactions
98
106
  */
99
107
  function handleEscape(e) {
100
- if (e.key === "Escape" && config.value) {
108
+ if (e.key === "Escape") {
101
109
  e.preventDefault();
102
110
  e.stopPropagation();
103
111
  hideTooltip(e);
@@ -121,29 +129,41 @@ function getModalDialog(target) {
121
129
  }
122
130
  }
123
131
  /**
124
- * Move the tooltip element into the host it needs to paint above
132
+ * Find the teleport root for an element inside a shadow root, if there is one
133
+ *
134
+ * The target is looked up in the element's own shadow root, because the host page can have
135
+ * an element with the same id. On a normal page the tooltip does not use the teleport root.
136
+ */
137
+ function getShadowTeleportRoot(target, selector) {
138
+ const root = target?.getRootNode();
139
+ if (!isShadowRoot(root) || selector === "body") return null;
140
+ return selector.startsWith("#") ? root.getElementById(selector.slice(1)) : root.querySelector(selector);
141
+ }
142
+ /**
143
+ * Move the tooltip element into the host it needs to be in for its target
125
144
  *
126
145
  * Top layer content paints above the rest of the document whatever `z-index` anything
127
146
  * else carries, so the only way to sit above a modal dialog is to live inside it.
128
- * Everywhere else the tooltip belongs on the body.
147
+ * The styles of a shadow root only reach what is inside it, so there the tooltip goes into
148
+ * the teleport root. Everywhere else the tooltip belongs on the body.
129
149
  *
130
150
  * This doubles as a repair step: appending an element that is no longer in the document
131
151
  * puts it back, which covers a dialog being unmounted while the tooltip sat inside it.
132
152
  *
133
153
  * Returns whether the element actually moved.
134
154
  */
135
- function moveTooltipToHost(target) {
155
+ function moveTooltipToHost(target, teleportTarget = "body") {
136
156
  if (!el.value) return false;
137
- const host = getModalDialog(target) ?? document.body;
157
+ const host = getModalDialog(target) ?? getShadowTeleportRoot(target, teleportTarget) ?? document.body;
138
158
  if (el.value.parentElement === host) return false;
139
159
  host.appendChild(el.value);
140
160
  return true;
141
161
  }
142
162
  /** Clears the current timer */
143
163
  function clearTimer() {
144
- if (timer.value) {
145
- clearTimeout(timer.value);
146
- timer.value = void 0;
164
+ if (timer) {
165
+ clearTimeout(timer);
166
+ timer = void 0;
147
167
  }
148
168
  }
149
169
  /** Get all the parents of an element */
@@ -163,7 +183,7 @@ function getAllParents(el) {
163
183
  * inside a button, say) counts as landing on the target: the pointer never left it.
164
184
  */
165
185
  function isMovingOffElements(e) {
166
- const target = unref(config.value?.targetRef);
186
+ const target = unref(config.value?.options.targetRef);
167
187
  if (e instanceof MouseEvent && e.relatedTarget instanceof Element && target) {
168
188
  const relatedTargetParents = getAllParents(e.relatedTarget);
169
189
  return e.relatedTarget.id !== "scalar-tooltip" && !relatedTargetParents.some((parent) => parent.id === "scalar-tooltip") && !target.contains(e.relatedTarget);
@@ -177,26 +197,31 @@ function isMovingOffElements(e) {
177
197
  */
178
198
  function useTooltip(opts) {
179
199
  initializeTooltipElement();
200
+ const tooltip = {
201
+ options: opts,
202
+ teleportTarget: hasInjectionContext() ? useTeleport() : "body"
203
+ };
204
+ /** The last delay timer this tooltip started, which may no longer be the running one */
205
+ let ownTimer;
180
206
  /**
181
207
  * Show the tooltip after the delay if configured
182
208
  */
183
209
  function showTooltipAfterDelay(_e) {
184
210
  const delay = unref(opts.delay) ?? 300;
185
211
  clearTimer();
186
- if (delay > 0) timer.value = setTimeout(() => showTooltip(_e), delay);
187
- else showTooltip(_e);
212
+ if (delay > 0) {
213
+ ownTimer = setTimeout(() => showTooltip(_e), delay);
214
+ timer = ownTimer;
215
+ } else showTooltip(_e);
188
216
  }
189
217
  /**
190
218
  * Show the tooltip
191
219
  */
192
220
  function showTooltip(_e) {
193
221
  clearTimer();
194
- document.addEventListener("keydown", handleEscape, {
195
- once: true,
196
- capture: true
197
- });
198
- moveTooltipToHost(unref(opts.targetRef));
199
- config.value = opts;
222
+ document.addEventListener("keydown", handleEscape, { capture: true });
223
+ moveTooltipToHost(unref(opts.targetRef), tooltip.teleportTarget);
224
+ config.value = tooltip;
200
225
  }
201
226
  watch(() => unref(opts.targetRef), (newRef, oldRef) => {
202
227
  if (oldRef) {
@@ -215,7 +240,7 @@ function useTooltip(opts) {
215
240
  }
216
241
  }, { immediate: true });
217
242
  onScopeDispose(() => {
218
- clearTimer();
243
+ if (timer === ownTimer) clearTimer();
219
244
  const target = unref(opts.targetRef);
220
245
  if (target) {
221
246
  target.removeEventListener("mouseenter", showTooltipAfterDelay);
@@ -224,7 +249,7 @@ function useTooltip(opts) {
224
249
  target.removeEventListener("blur", hideTooltip);
225
250
  target.removeAttribute("aria-describedby");
226
251
  }
227
- if (unref(config.value?.targetRef) === unref(opts.targetRef)) config.value = void 0;
252
+ if (config.value && unref(config.value.options.targetRef) === unref(opts.targetRef)) clearTooltip();
228
253
  });
229
254
  }
230
255
  export { useTooltip };
@@ -1 +1 @@
1
- {"version":3,"file":"useTooltip.js","names":[],"sources":["../../../src/components/ScalarTooltip/useTooltip.ts"],"sourcesContent":["import { autoUpdate, flip, shift, useFloating } from '@floating-ui/vue'\nimport { computed, onScopeDispose, ref, unref, watch } from 'vue'\n\nimport { DEFAULT_DELAY, DEFAULT_OFFSET, ELEMENT_CLASS, ELEMENT_ID } from './constants'\nimport type { Timer, TooltipConfiguration } from './types'\n\n// ---------------------------------------------------------------------------\n// State\n// ---------------------------------------------------------------------------\n\n/**\n * The delay timer for the tooltip\n *\n * If there's not a timer running it should be undefined\n */\nconst timer = ref<Timer>()\n\n/**\n * A reference to the tooltip element\n *\n * If the hook hasn't been initialized it should be undefined\n */\nconst el = ref<HTMLElement>()\n\n/**\n * The configuration for the active tooltip\n *\n * If no tooltip is active it should be undefined\n */\nconst config = ref<TooltipConfiguration>()\n\n// ---------------------------------------------------------------------------\n// Core watcher and floating UI setup\n// ---------------------------------------------------------------------------\n\n// Set up floating UI\nconst { floatingStyles, placement, update } = useFloating(\n computed(() => unref(config.value?.targetRef)),\n el,\n {\n placement: computed(() => unref(config.value?.placement)),\n whileElementsMounted: autoUpdate,\n middleware: computed(() => [flip(), shift()]),\n },\n)\n\n// Expose the resolved placement side (post-flip) so the CSS can apply the offset\n// gap only on the side facing the target. We key off the side (the part before\n// the '-') because that is where the tooltip sits relative to the target. The\n// initial side is set synchronously when the tooltip is shown (see the config\n// watcher below); this watcher keeps it in sync once Floating UI flips it.\nwatch(placement, (value) => {\n if (!el.value || !value) {\n return\n }\n el.value.dataset.side = value.split('-')[0]\n})\n\n// Update the tooltip element's positioning when Floating UI updates the styles\nwatch(floatingStyles, () => {\n if (!el.value) {\n return\n }\n\n el.value.style.position = floatingStyles.value.position\n el.value.style.top = floatingStyles.value.top\n el.value.style.left = floatingStyles.value.left\n el.value.style.transform = floatingStyles.value.transform ?? ''\n el.value.style.willChange = floatingStyles.value.willChange ?? ''\n})\n\n// Show or hide the tooltip when the config changes\nwatch(\n config,\n (opts) => {\n if (!el.value) {\n return\n }\n\n if (opts) {\n // Keep the element in the right host if the target moved into or out of a modal\n // dialog while the tooltip was already showing. Opening a tooltip is handled in\n // `showTooltip` before the config is assigned, so this only fires when `targetRef`\n // changes underneath an open tooltip, and it has to ask Floating UI for a fresh\n // position because a reparent is neither a scroll nor a resize.\n if (moveTooltipToHost(unref(opts.targetRef))) {\n update()\n }\n\n const contentTarget = unref(opts?.contentTarget) ?? 'textContent'\n\n // Update the tooltip content\n el.value[contentTarget] = unref(opts?.content) ?? ''\n\n // Show the tooltip\n const offset = unref(opts?.offset) ?? DEFAULT_OFFSET\n el.value.style.setProperty('--scalar-tooltip-offset', `${offset}px`)\n\n // Set the side the tooltip sits on so the offset gap is only applied to\n // the target-facing side. Floating UI defaults to 'bottom' when no\n // placement is provided; the placement watcher above refines this after\n // any flip.\n el.value.dataset.side = (unref(opts?.placement) ?? 'bottom').split('-')[0]\n\n el.value.style.setProperty('display', 'block')\n } else {\n // Clear the tooltip content\n el.value.innerHTML = ''\n\n // Hide the tooltip\n el.value.style.removeProperty('--scalar-tooltip-offset')\n el.value.style.setProperty('display', 'none')\n\n // Park the element back on the body. Left inside a dialog it would be removed from\n // the document when that dialog unmounts, taking the shared tooltip with it.\n moveTooltipToHost(undefined)\n }\n },\n { deep: true },\n)\n\n// ---------------------------------------------------------------------------\n// Lifecycle Functions\n// ---------------------------------------------------------------------------\n\n/**\n * Initialize the tooltip element\n *\n * If the tooltip is already initialized it will be ignored\n */\nfunction initializeTooltipElement(): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') {\n // Skip tooltip initialization during SSR\n return\n }\n\n if (el.value) {\n // Tooltip already initialized\n return\n }\n\n // See if the tooltip element already exists\n // (Sometimes this happens with HMR)\n const existingTooltipElement = document.getElementById(ELEMENT_ID)\n\n if (existingTooltipElement) {\n el.value = existingTooltipElement\n } else {\n // Create the tooltip element\n el.value = document.createElement('div')\n el.value.role = 'tooltip'\n el.value.id = ELEMENT_ID\n el.value.classList.add(ELEMENT_CLASS)\n el.value.classList.add('scalar-app')\n el.value.style.setProperty('display', 'none')\n el.value.addEventListener('mouseleave', hideTooltip)\n document.body.appendChild(el.value)\n }\n}\n\n/**\n * Cleanup and reset the tooltip element\n */\nexport function cleanupTooltipElement() {\n document.getElementById(ELEMENT_ID)?.remove()\n el.value = undefined\n}\n\n// ---------------------------------------------------------------------------\n// Helper Functions\n// ---------------------------------------------------------------------------\n\n/**\n * Hide the tooltip\n *\n * If the mouse is moving between the tooltip and the target we don't hide the tooltip\n */\nfunction hideTooltip(_e: Event) {\n if (!isMovingOffElements(_e)) {\n // Don't hide the tooltip if the mouse is moving between the tooltip and the target\n return\n }\n\n // Clear any existing timer\n clearTimer()\n\n // Hide the tooltip\n config.value = undefined\n}\n\n/**\n * Handle the escape key\n *\n * If the escape key is pressed while the tooltip is showing we need to hide it, and only it.\n * Preventing the default stops the browser from also turning the key into a `cancel` request\n * for a surrounding modal `<dialog>`, which stopping propagation alone does not do. The listener\n * outlives a tooltip hidden by blur or mouseleave, so an Escape with no tooltip showing is left\n * alone for whatever else wants it.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/tooltip_role#keyboard_interactions\n */\nfunction handleEscape(e: KeyboardEvent) {\n if (e.key === 'Escape' && config.value) {\n e.preventDefault()\n e.stopPropagation()\n hideTooltip(e)\n }\n}\n\n/**\n * Find the modal dialog containing an element, if there is one\n *\n * Only a dialog opened with `showModal()` is promoted to the browser's top layer, and\n * `:modal` matches exactly those. The `open` property is not a substitute: it is also\n * true for `dialog.show()`, which leaves the dialog in the normal flow where the\n * tooltip already paints correctly.\n */\nfunction getModalDialog(target: Element | undefined | null): HTMLDialogElement | undefined {\n const dialog = target?.closest('dialog')\n\n if (!dialog) {\n return undefined\n }\n\n try {\n return dialog.matches(':modal') ? dialog : undefined\n } catch {\n // `:modal` reached Safari a couple of releases after `showModal()` did, and an\n // unknown pseudo-class throws. Treating it as \"not modal\" degrades to the old\n // behaviour for that one case instead of breaking every tooltip on the page.\n return undefined\n }\n}\n\n/**\n * Move the tooltip element into the host it needs to paint above\n *\n * Top layer content paints above the rest of the document whatever `z-index` anything\n * else carries, so the only way to sit above a modal dialog is to live inside it.\n * Everywhere else the tooltip belongs on the body.\n *\n * This doubles as a repair step: appending an element that is no longer in the document\n * puts it back, which covers a dialog being unmounted while the tooltip sat inside it.\n *\n * Returns whether the element actually moved.\n */\nfunction moveTooltipToHost(target: Element | undefined | null): boolean {\n if (!el.value) {\n return false\n }\n\n const host = getModalDialog(target) ?? document.body\n\n if (el.value.parentElement === host) {\n return false\n }\n\n host.appendChild(el.value)\n\n return true\n}\n\n/** Clears the current timer */\nfunction clearTimer() {\n if (timer.value) {\n clearTimeout(timer.value)\n timer.value = undefined\n }\n}\n\n/** Get all the parents of an element */\nfunction getAllParents(el: Element): Element[] {\n const parents: Element[] = []\n let parent = el.parentElement\n while (parent) {\n parents.push(parent)\n parent = parent.parentElement\n }\n return parents\n}\n\n/**\n * Check if the mouse moved off the target and the tooltip altogether\n *\n * Moving between the two keeps the tooltip open. Landing on a child of the target (an icon\n * inside a button, say) counts as landing on the target: the pointer never left it.\n */\nfunction isMovingOffElements(e: Event): boolean {\n const target = unref(config.value?.targetRef)\n if (e instanceof MouseEvent && e.relatedTarget instanceof Element && target) {\n const relatedTargetParents = getAllParents(e.relatedTarget)\n return (\n e.relatedTarget.id !== ELEMENT_ID &&\n !relatedTargetParents.some((parent) => parent.id === ELEMENT_ID) &&\n !target.contains(e.relatedTarget)\n )\n }\n return true\n}\n\n// ---------------------------------------------------------------------------\n// Tooltip Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Create a tooltip\n *\n * If there isn't a tooltip element it will be created\n */\nexport function useTooltip(opts: TooltipConfiguration) {\n initializeTooltipElement()\n\n /**\n * Show the tooltip after the delay if configured\n */\n function showTooltipAfterDelay(_e: Event) {\n const delay = unref(opts.delay) ?? DEFAULT_DELAY\n clearTimer()\n\n // Show the tooltip after the delay\n if (delay > 0) {\n timer.value = setTimeout(() => showTooltip(_e), delay)\n } else {\n showTooltip(_e)\n }\n }\n\n /**\n * Show the tooltip\n */\n function showTooltip(_e: Event) {\n clearTimer()\n\n // Handle the escape key\n document.addEventListener('keydown', handleEscape, { once: true, capture: true })\n\n // Move the element before the config is assigned, not after. Floating UI watches the\n // target with `flush: 'sync'`, so it measures the position the instant the config\n // lands, and that measurement has to happen with the tooltip already in its final\n // parent or the first frame is positioned against the wrong offset parent.\n moveTooltipToHost(unref(opts.targetRef))\n\n // Show the tooltip\n config.value = opts\n }\n\n watch(\n () => unref(opts.targetRef),\n (newRef, oldRef) => {\n if (oldRef) {\n oldRef.removeEventListener('mouseenter', showTooltipAfterDelay)\n oldRef.removeEventListener('mouseleave', hideTooltip)\n oldRef.removeEventListener('focus', showTooltip)\n oldRef.removeEventListener('blur', hideTooltip)\n\n oldRef.removeAttribute('aria-describedby')\n }\n if (newRef) {\n newRef.addEventListener('mouseenter', showTooltipAfterDelay)\n newRef.addEventListener('mouseleave', hideTooltip)\n newRef.addEventListener('focus', showTooltip)\n newRef.addEventListener('blur', hideTooltip)\n\n newRef.setAttribute('aria-describedby', ELEMENT_ID)\n }\n },\n { immediate: true },\n )\n\n // Cleanup the tooltip when the component is unmounted\n onScopeDispose(() => {\n clearTimer()\n\n const target = unref(opts.targetRef)\n if (target) {\n target.removeEventListener('mouseenter', showTooltipAfterDelay)\n target.removeEventListener('mouseleave', hideTooltip)\n target.removeEventListener('focus', showTooltip)\n target.removeEventListener('blur', hideTooltip)\n target.removeAttribute('aria-describedby')\n }\n\n // If the tooltip is showing on this target hide it\n if (unref(config.value?.targetRef) === unref(opts.targetRef)) {\n config.value = undefined\n }\n })\n}\n"],"mappings":";;;;;;;;;AAeA,IAAM,QAAQ,IAAW;;;;;;AAOzB,IAAM,KAAK,IAAiB;;;;;;AAO5B,IAAM,SAAS,IAA0B;AAOzC,IAAM,EAAE,gBAAgB,WAAW,WAAW,YAC5C,eAAe,MAAM,OAAO,OAAO,SAAS,CAAC,GAC7C,IACA;CACE,WAAW,eAAe,MAAM,OAAO,OAAO,SAAS,CAAC;CACxD,sBAAsB;CACtB,YAAY,eAAe,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;AAC9C,CACF;AAOA,MAAM,YAAY,UAAU;CAC1B,IAAI,CAAC,GAAG,SAAS,CAAC,OAChB;CAEF,GAAG,MAAM,QAAQ,OAAO,MAAM,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAGD,MAAM,sBAAsB;CAC1B,IAAI,CAAC,GAAG,OACN;CAGF,GAAG,MAAM,MAAM,WAAW,eAAe,MAAM;CAC/C,GAAG,MAAM,MAAM,MAAM,eAAe,MAAM;CAC1C,GAAG,MAAM,MAAM,OAAO,eAAe,MAAM;CAC3C,GAAG,MAAM,MAAM,YAAY,eAAe,MAAM,aAAa;CAC7D,GAAG,MAAM,MAAM,aAAa,eAAe,MAAM,cAAc;AACjE,CAAC;AAGD,MACE,SACC,SAAS;CACR,IAAI,CAAC,GAAG,OACN;CAGF,IAAI,MAAM;EAMR,IAAI,kBAAkB,MAAM,KAAK,SAAS,CAAC,GAC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;;;CAKA,SAAS,YAAY,IAAW;EAC9B,WAAW;EAGX,SAAS,iBAAiB,WAAW,cAAc;GAAE,MAAM;GAAM,SAAS;EAAK,CAAC;EAMhF,kBAAkB,MAAM,KAAK,SAAS,CAAC;EAGvC,OAAO,QAAQ;CACjB;CAEA,YACQ,MAAM,KAAK,SAAS,IACzB,QAAQ,WAAW;EAClB,IAAI,QAAQ;GACV,OAAO,oBAAoB,cAAc,qBAAqB;GAC9D,OAAO,oBAAoB,cAAc,WAAW;GACpD,OAAO,oBAAoB,SAAS,WAAW;GAC/C,OAAO,oBAAoB,QAAQ,WAAW;GAE9C,OAAO,gBAAgB,kBAAkB;EAC3C;EACA,IAAI,QAAQ;GACV,OAAO,iBAAiB,cAAc,qBAAqB;GAC3D,OAAO,iBAAiB,cAAc,WAAW;GACjD,OAAO,iBAAiB,SAAS,WAAW;GAC5C,OAAO,iBAAiB,QAAQ,WAAW;GAE3C,OAAO,aAAa,oBAAoB,UAAU;EACpD;CACF,GACA,EAAE,WAAW,KAAK,CACpB;CAGA,qBAAqB;EACnB,WAAW;EAEX,MAAM,SAAS,MAAM,KAAK,SAAS;EACnC,IAAI,QAAQ;GACV,OAAO,oBAAoB,cAAc,qBAAqB;GAC9D,OAAO,oBAAoB,cAAc,WAAW;GACpD,OAAO,oBAAoB,SAAS,WAAW;GAC/C,OAAO,oBAAoB,QAAQ,WAAW;GAC9C,OAAO,gBAAgB,kBAAkB;EAC3C;EAGA,IAAI,MAAM,OAAO,OAAO,SAAS,MAAM,MAAM,KAAK,SAAS,GACzD,OAAO,QAAQ,KAAA;CAEnB,CAAC;AACH"}
1
+ {"version":3,"file":"useTooltip.js","names":[],"sources":["../../../src/components/ScalarTooltip/useTooltip.ts"],"sourcesContent":["import { autoUpdate, flip, shift, useFloating } from '@floating-ui/vue'\nimport { isShadowRoot } from '@scalar/helpers/dom/is-shadow-root'\nimport { computed, hasInjectionContext, onScopeDispose, ref, unref, watch } from 'vue'\n\nimport { useTeleport } from '../ScalarTeleport'\nimport { DEFAULT_DELAY, DEFAULT_OFFSET, ELEMENT_CLASS, ELEMENT_ID } from './constants'\nimport type { Timer, TooltipConfiguration } from './types'\n\n/** A tooltip's configuration, with the teleport target of the component it belongs to */\ntype ActiveTooltip = {\n /** Keep the original options so reactive properties continue to update */\n options: TooltipConfiguration\n /** Target for the nearest teleport root, or `body` if there is none */\n teleportTarget: string\n}\n\n// ---------------------------------------------------------------------------\n// State\n// ---------------------------------------------------------------------------\n\n/**\n * The delay timer for the tooltip\n *\n * If there's not a timer running it should be undefined\n */\nlet timer: Timer | undefined\n\n/**\n * A reference to the tooltip element\n *\n * If the hook hasn't been initialized it should be undefined\n */\nconst el = ref<HTMLElement>()\n\n/**\n * The configuration for the active tooltip\n *\n * If no tooltip is active it should be undefined\n */\nconst config = ref<ActiveTooltip>()\n\n// ---------------------------------------------------------------------------\n// Core watcher and floating UI setup\n// ---------------------------------------------------------------------------\n\n// Set up floating UI\nconst { floatingStyles, placement, update } = useFloating(\n computed(() => unref(config.value?.options.targetRef)),\n el,\n {\n placement: computed(() => unref(config.value?.options.placement)),\n whileElementsMounted: autoUpdate,\n middleware: computed(() => [flip(), shift()]),\n },\n)\n\n// Expose the resolved placement side (post-flip) so the CSS can apply the offset\n// gap only on the side facing the target. We key off the side (the part before\n// the '-') because that is where the tooltip sits relative to the target. The\n// initial side is set synchronously when the tooltip is shown (see the config\n// watcher below); this watcher keeps it in sync once Floating UI flips it.\nwatch(placement, (value) => {\n if (!el.value || !value) {\n return\n }\n el.value.dataset.side = value.split('-')[0]\n})\n\n// Update the tooltip element's positioning when Floating UI updates the styles\nwatch(floatingStyles, () => {\n if (!el.value) {\n return\n }\n\n el.value.style.position = floatingStyles.value.position\n el.value.style.top = floatingStyles.value.top\n el.value.style.left = floatingStyles.value.left\n el.value.style.transform = floatingStyles.value.transform ?? ''\n el.value.style.willChange = floatingStyles.value.willChange ?? ''\n})\n\n// Show or hide the tooltip when the config changes\nwatch(\n config,\n (activeTooltip) => {\n if (!el.value) {\n return\n }\n\n if (activeTooltip) {\n const { options, teleportTarget } = activeTooltip\n\n // Keep the element in the right host if the target moved into or out of a modal\n // dialog or shadow root while the tooltip was already showing. Opening a tooltip is handled in\n // `showTooltip` before the config is assigned, so this only fires when `targetRef`\n // changes underneath an open tooltip, and it has to ask Floating UI for a fresh\n // position because a reparent is neither a scroll nor a resize.\n if (moveTooltipToHost(unref(options.targetRef), teleportTarget)) {\n update()\n }\n\n const contentTarget = unref(options.contentTarget) ?? 'textContent'\n\n // Update the tooltip content\n el.value[contentTarget] = unref(options.content) ?? ''\n\n // Show the tooltip\n const offset = unref(options.offset) ?? DEFAULT_OFFSET\n el.value.style.setProperty('--scalar-tooltip-offset', `${offset}px`)\n\n // Set the side the tooltip sits on so the offset gap is only applied to\n // the target-facing side. Floating UI defaults to 'bottom' when no\n // placement is provided; the placement watcher above refines this after\n // any flip.\n el.value.dataset.side = (unref(options.placement) ?? 'bottom').split('-')[0]\n\n el.value.style.setProperty('display', 'block')\n } else {\n // Clear the tooltip content\n el.value.innerHTML = ''\n\n // Hide the tooltip\n el.value.style.removeProperty('--scalar-tooltip-offset')\n el.value.style.setProperty('display', 'none')\n\n // Park the element back on the body. Left inside a dialog or a shadow root it would be\n // removed from the document when that unmounts, taking the shared tooltip with it.\n moveTooltipToHost()\n }\n },\n { deep: true },\n)\n\n// ---------------------------------------------------------------------------\n// Lifecycle Functions\n// ---------------------------------------------------------------------------\n\n/**\n * Initialize the tooltip element\n *\n * If the tooltip is already initialized it will be ignored\n */\nfunction initializeTooltipElement(): void {\n if (typeof document === 'undefined' || typeof window === 'undefined') {\n // Skip tooltip initialization during SSR\n return\n }\n\n if (el.value) {\n // Tooltip already initialized\n return\n }\n\n // See if the tooltip element already exists\n // (Sometimes this happens with HMR)\n const existingTooltipElement = document.getElementById(ELEMENT_ID)\n\n if (existingTooltipElement) {\n el.value = existingTooltipElement\n } else {\n // Create the tooltip element\n el.value = document.createElement('div')\n el.value.role = 'tooltip'\n el.value.id = ELEMENT_ID\n el.value.classList.add(ELEMENT_CLASS)\n el.value.classList.add('scalar-app')\n el.value.style.setProperty('display', 'none')\n el.value.addEventListener('mouseleave', hideTooltip)\n document.body.appendChild(el.value)\n }\n}\n\n/**\n * Cleanup and reset the tooltip element\n */\nexport function cleanupTooltipElement() {\n clearTimer()\n clearTooltip()\n el.value?.remove()\n el.value = undefined\n}\n\n// ---------------------------------------------------------------------------\n// Helper Functions\n// ---------------------------------------------------------------------------\n\n/**\n * Hide the tooltip\n *\n * If the mouse is moving between the tooltip and the target we don't hide the tooltip\n */\nfunction hideTooltip(_e: Event) {\n if (!isMovingOffElements(_e)) {\n // Don't hide the tooltip if the mouse is moving between the tooltip and the target\n return\n }\n\n // Clear any existing timer\n clearTimer()\n\n // Hide the tooltip\n clearTooltip()\n}\n\n/** Clear the active tooltip and stop listening for the escape key */\nfunction clearTooltip(): void {\n document.removeEventListener('keydown', handleEscape, { capture: true })\n config.value = undefined\n}\n\n/**\n * Handle the escape key\n *\n * If the escape key is pressed while the tooltip is showing we need to hide it, and only it.\n * Preventing the default stops the browser from also turning the key into a `cancel` request\n * for a surrounding modal `<dialog>`, which stopping propagation alone does not do. The listener\n * is only attached while a tooltip is showing, so any other Escape is left alone for whatever else\n * wants it.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/tooltip_role#keyboard_interactions\n */\nfunction handleEscape(e: KeyboardEvent) {\n if (e.key === 'Escape') {\n e.preventDefault()\n e.stopPropagation()\n hideTooltip(e)\n }\n}\n\n/**\n * Find the modal dialog containing an element, if there is one\n *\n * Only a dialog opened with `showModal()` is promoted to the browser's top layer, and\n * `:modal` matches exactly those. The `open` property is not a substitute: it is also\n * true for `dialog.show()`, which leaves the dialog in the normal flow where the\n * tooltip already paints correctly.\n */\nfunction getModalDialog(target: Element | undefined | null): HTMLDialogElement | undefined {\n const dialog = target?.closest('dialog')\n\n if (!dialog) {\n return undefined\n }\n\n try {\n return dialog.matches(':modal') ? dialog : undefined\n } catch {\n // `:modal` reached Safari a couple of releases after `showModal()` did, and an\n // unknown pseudo-class throws. Treating it as \"not modal\" degrades to the old\n // behaviour for that one case instead of breaking every tooltip on the page.\n return undefined\n }\n}\n\n/**\n * Find the teleport root for an element inside a shadow root, if there is one\n *\n * The target is looked up in the element's own shadow root, because the host page can have\n * an element with the same id. On a normal page the tooltip does not use the teleport root.\n */\nfunction getShadowTeleportRoot(target: Element | undefined | null, selector: string): Element | null {\n const root = target?.getRootNode()\n\n if (!isShadowRoot(root) || selector === 'body') {\n return null\n }\n\n // ScalarTeleportRoot provides a literal id prefixed with #. It can contain CSS syntax.\n return selector.startsWith('#') ? root.getElementById(selector.slice(1)) : root.querySelector(selector)\n}\n\n/**\n * Move the tooltip element into the host it needs to be in for its target\n *\n * Top layer content paints above the rest of the document whatever `z-index` anything\n * else carries, so the only way to sit above a modal dialog is to live inside it.\n * The styles of a shadow root only reach what is inside it, so there the tooltip goes into\n * the teleport root. Everywhere else the tooltip belongs on the body.\n *\n * This doubles as a repair step: appending an element that is no longer in the document\n * puts it back, which covers a dialog being unmounted while the tooltip sat inside it.\n *\n * Returns whether the element actually moved.\n */\nfunction moveTooltipToHost(target?: Element | null, teleportTarget = 'body'): boolean {\n if (!el.value) {\n return false\n }\n\n const host = getModalDialog(target) ?? getShadowTeleportRoot(target, teleportTarget) ?? document.body\n\n if (el.value.parentElement === host) {\n return false\n }\n\n host.appendChild(el.value)\n\n return true\n}\n\n/** Clears the current timer */\nfunction clearTimer() {\n if (timer) {\n clearTimeout(timer)\n timer = undefined\n }\n}\n\n/** Get all the parents of an element */\nfunction getAllParents(el: Element): Element[] {\n const parents: Element[] = []\n let parent = el.parentElement\n while (parent) {\n parents.push(parent)\n parent = parent.parentElement\n }\n return parents\n}\n\n/**\n * Check if the mouse moved off the target and the tooltip altogether\n *\n * Moving between the two keeps the tooltip open. Landing on a child of the target (an icon\n * inside a button, say) counts as landing on the target: the pointer never left it.\n */\nfunction isMovingOffElements(e: Event): boolean {\n const target = unref(config.value?.options.targetRef)\n if (e instanceof MouseEvent && e.relatedTarget instanceof Element && target) {\n const relatedTargetParents = getAllParents(e.relatedTarget)\n return (\n e.relatedTarget.id !== ELEMENT_ID &&\n !relatedTargetParents.some((parent) => parent.id === ELEMENT_ID) &&\n !target.contains(e.relatedTarget)\n )\n }\n return true\n}\n\n// ---------------------------------------------------------------------------\n// Tooltip Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Create a tooltip\n *\n * If there isn't a tooltip element it will be created\n */\nexport function useTooltip(opts: TooltipConfiguration) {\n initializeTooltipElement()\n\n const tooltip: ActiveTooltip = {\n options: opts,\n teleportTarget: hasInjectionContext() ? useTeleport() : 'body',\n }\n\n /** The last delay timer this tooltip started, which may no longer be the running one */\n let ownTimer: Timer | undefined\n\n /**\n * Show the tooltip after the delay if configured\n */\n function showTooltipAfterDelay(_e: Event) {\n const delay = unref(opts.delay) ?? DEFAULT_DELAY\n clearTimer()\n\n // Show the tooltip after the delay\n if (delay > 0) {\n ownTimer = setTimeout(() => showTooltip(_e), delay)\n timer = ownTimer\n } else {\n showTooltip(_e)\n }\n }\n\n /**\n * Show the tooltip\n */\n function showTooltip(_e: Event) {\n clearTimer()\n\n // Handle the escape key until the tooltip is hidden\n document.addEventListener('keydown', handleEscape, { capture: true })\n\n // Move the element before the config is assigned, not after. Floating UI watches the\n // target with `flush: 'sync'`, so it measures the position the instant the config\n // lands, and that measurement has to happen with the tooltip already in its final\n // parent or the first frame is positioned against the wrong offset parent.\n moveTooltipToHost(unref(opts.targetRef), tooltip.teleportTarget)\n\n // Show the tooltip\n config.value = tooltip\n }\n\n watch(\n () => unref(opts.targetRef),\n (newRef, oldRef) => {\n if (oldRef) {\n oldRef.removeEventListener('mouseenter', showTooltipAfterDelay)\n oldRef.removeEventListener('mouseleave', hideTooltip)\n oldRef.removeEventListener('focus', showTooltip)\n oldRef.removeEventListener('blur', hideTooltip)\n\n oldRef.removeAttribute('aria-describedby')\n }\n if (newRef) {\n newRef.addEventListener('mouseenter', showTooltipAfterDelay)\n newRef.addEventListener('mouseleave', hideTooltip)\n newRef.addEventListener('focus', showTooltip)\n newRef.addEventListener('blur', hideTooltip)\n\n newRef.setAttribute('aria-describedby', ELEMENT_ID)\n }\n },\n { immediate: true },\n )\n\n // Cleanup the tooltip when the component is unmounted\n onScopeDispose(() => {\n // Leave the timer alone if it is another tooltip's delay\n if (timer === ownTimer) {\n clearTimer()\n }\n\n const target = unref(opts.targetRef)\n if (target) {\n target.removeEventListener('mouseenter', showTooltipAfterDelay)\n target.removeEventListener('mouseleave', hideTooltip)\n target.removeEventListener('focus', showTooltip)\n target.removeEventListener('blur', hideTooltip)\n target.removeAttribute('aria-describedby')\n }\n\n // If the tooltip is showing on this target hide it\n if (config.value && unref(config.value.options.targetRef) === unref(opts.targetRef)) {\n clearTooltip()\n }\n })\n}\n"],"mappings":";;;;;;;;;;;AAyBA,IAAI;;;;;;AAOJ,IAAM,KAAK,IAAiB;;;;;;AAO5B,IAAM,SAAS,IAAmB;AAOlC,IAAM,EAAE,gBAAgB,WAAW,WAAW,YAC5C,eAAe,MAAM,OAAO,OAAO,QAAQ,SAAS,CAAC,GACrD,IACA;CACE,WAAW,eAAe,MAAM,OAAO,OAAO,QAAQ,SAAS,CAAC;CAChE,sBAAsB;CACtB,YAAY,eAAe,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC;AAC9C,CACF;AAOA,MAAM,YAAY,UAAU;CAC1B,IAAI,CAAC,GAAG,SAAS,CAAC,OAChB;CAEF,GAAG,MAAM,QAAQ,OAAO,MAAM,MAAM,GAAG,CAAC,CAAC;AAC3C,CAAC;AAGD,MAAM,sBAAsB;CAC1B,IAAI,CAAC,GAAG,OACN;CAGF,GAAG,MAAM,MAAM,WAAW,eAAe,MAAM;CAC/C,GAAG,MAAM,MAAM,MAAM,eAAe,MAAM;CAC1C,GAAG,MAAM,MAAM,OAAO,eAAe,MAAM;CAC3C,GAAG,MAAM,MAAM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AC5C,OAAO,iBAAiB,QAAQ,WAAW;GAE3C,OAAO,aAAa,oBAAoB,UAAU;EACpD;CACF,GACA,EAAE,WAAW,KAAK,CACpB;CAGA,qBAAqB;EAEnB,IAAI,UAAU,UACZ,WAAW;EAGb,MAAM,SAAS,MAAM,KAAK,SAAS;EACnC,IAAI,QAAQ;GACV,OAAO,oBAAoB,cAAc,qBAAqB;GAC9D,OAAO,oBAAoB,cAAc,WAAW;GACpD,OAAO,oBAAoB,SAAS,WAAW;GAC/C,OAAO,oBAAoB,QAAQ,WAAW;GAC9C,OAAO,gBAAgB,kBAAkB;EAC3C;EAGA,IAAI,OAAO,SAAS,MAAM,OAAO,MAAM,QAAQ,SAAS,MAAM,MAAM,KAAK,SAAS,GAChF,aAAa;CAEjB,CAAC;AACH"}
package/dist/style.css CHANGED
@@ -4934,7 +4934,7 @@ to {
4934
4934
  }
4935
4935
  }
4936
4936
  }
4937
- :where(body, dialog) > .scalar-tooltip {
4937
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip {
4938
4938
  --scalar-tooltip-padding-x: 8px;
4939
4939
  --scalar-tooltip-padding-y: 6px;
4940
4940
  padding: var(--scalar-tooltip-padding-y) var(--scalar-tooltip-padding-x);
@@ -4947,19 +4947,19 @@ to {
4947
4947
  overflow-wrap: break-word;
4948
4948
  color: var(--scalar-tooltip-color);
4949
4949
  }
4950
- :where(body, dialog) > .scalar-tooltip[data-side="top"] {
4950
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="top"] {
4951
4951
  padding-bottom: calc(var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset));
4952
4952
  }
4953
- :where(body, dialog) > .scalar-tooltip[data-side="bottom"] {
4953
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="bottom"] {
4954
4954
  padding-top: calc(var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset));
4955
4955
  }
4956
- :where(body, dialog) > .scalar-tooltip[data-side="left"] {
4956
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="left"] {
4957
4957
  padding-right: calc(var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset));
4958
4958
  }
4959
- :where(body, dialog) > .scalar-tooltip[data-side="right"] {
4959
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="right"] {
4960
4960
  padding-left: calc(var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset));
4961
4961
  }
4962
- :where(body, dialog) > .scalar-tooltip:before {
4962
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip:before {
4963
4963
  content: "";
4964
4964
  border: var(--scalar-border-width) solid var(--scalar-border-color);
4965
4965
  z-index: calc(1 * -1);
@@ -4973,16 +4973,16 @@ to {
4973
4973
  position: absolute;
4974
4974
  inset: 0;
4975
4975
  }
4976
- :where(body, dialog) > .scalar-tooltip[data-side="top"]:before {
4976
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="top"]:before {
4977
4977
  bottom: var(--scalar-tooltip-offset);
4978
4978
  }
4979
- :where(body, dialog) > .scalar-tooltip[data-side="bottom"]:before {
4979
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="bottom"]:before {
4980
4980
  top: var(--scalar-tooltip-offset);
4981
4981
  }
4982
- :where(body, dialog) > .scalar-tooltip[data-side="left"]:before {
4982
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="left"]:before {
4983
4983
  right: var(--scalar-tooltip-offset);
4984
4984
  }
4985
- :where(body, dialog) > .scalar-tooltip[data-side="right"]:before {
4985
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="right"]:before {
4986
4986
  left: var(--scalar-tooltip-offset);
4987
4987
  }
4988
4988
  @property --tw-font-weight {
@@ -1252,7 +1252,7 @@ to {
1252
1252
  }
1253
1253
  }
1254
1254
  }
1255
- :where(body, dialog) > .scalar-tooltip {
1255
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip {
1256
1256
  --scalar-tooltip-padding-x: 8px;
1257
1257
  --scalar-tooltip-padding-y: 6px;
1258
1258
  padding: var(--scalar-tooltip-padding-y) var(--scalar-tooltip-padding-x);
@@ -1265,19 +1265,19 @@ to {
1265
1265
  overflow-wrap: break-word;
1266
1266
  color: var(--scalar-tooltip-color);
1267
1267
  }
1268
- :where(body, dialog) > .scalar-tooltip[data-side="top"] {
1268
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="top"] {
1269
1269
  padding-bottom: calc(var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset));
1270
1270
  }
1271
- :where(body, dialog) > .scalar-tooltip[data-side="bottom"] {
1271
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="bottom"] {
1272
1272
  padding-top: calc(var(--scalar-tooltip-padding-y) + var(--scalar-tooltip-offset));
1273
1273
  }
1274
- :where(body, dialog) > .scalar-tooltip[data-side="left"] {
1274
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="left"] {
1275
1275
  padding-right: calc(var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset));
1276
1276
  }
1277
- :where(body, dialog) > .scalar-tooltip[data-side="right"] {
1277
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="right"] {
1278
1278
  padding-left: calc(var(--scalar-tooltip-padding-x) + var(--scalar-tooltip-offset));
1279
1279
  }
1280
- :where(body, dialog) > .scalar-tooltip:before {
1280
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip:before {
1281
1281
  content: "";
1282
1282
  border: var(--scalar-border-width) solid var(--scalar-border-color);
1283
1283
  z-index: calc(1 * -1);
@@ -1291,16 +1291,16 @@ to {
1291
1291
  position: absolute;
1292
1292
  inset: 0;
1293
1293
  }
1294
- :where(body, dialog) > .scalar-tooltip[data-side="top"]:before {
1294
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="top"]:before {
1295
1295
  bottom: var(--scalar-tooltip-offset);
1296
1296
  }
1297
- :where(body, dialog) > .scalar-tooltip[data-side="bottom"]:before {
1297
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="bottom"]:before {
1298
1298
  top: var(--scalar-tooltip-offset);
1299
1299
  }
1300
- :where(body, dialog) > .scalar-tooltip[data-side="left"]:before {
1300
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="left"]:before {
1301
1301
  right: var(--scalar-tooltip-offset);
1302
1302
  }
1303
- :where(body, dialog) > .scalar-tooltip[data-side="right"]:before {
1303
+ :where(body, dialog, .scalar-teleport-root) > .scalar-tooltip[data-side="right"]:before {
1304
1304
  left: var(--scalar-tooltip-offset);
1305
1305
  }
1306
1306
  @property --tw-font-weight {
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "url": "git+https://github.com/scalar/scalar.git",
11
11
  "directory": "packages/components"
12
12
  },
13
- "version": "0.37.1",
13
+ "version": "0.38.0",
14
14
  "engines": {
15
15
  "node": ">=22"
16
16
  },
@@ -221,12 +221,12 @@
221
221
  "@floating-ui/vue": "2.0.1",
222
222
  "@headlessui/tailwindcss": "^0.2.2",
223
223
  "@headlessui/vue": "1.7.23",
224
- "@scalar/helpers": "0.21.1",
224
+ "@scalar/helpers": "0.21.2",
225
225
  "@scalar/highlight": "0.9.0",
226
226
  "@scalar/icons": "0.7.12",
227
- "@scalar/markdown": "0.1.4",
228
- "@scalar/themes": "0.22.0",
229
- "@scalar/use-hooks": "0.5.3",
227
+ "@scalar/markdown": "0.2.0",
228
+ "@scalar/themes": "0.23.0",
229
+ "@scalar/use-hooks": "0.5.4",
230
230
  "@vueuse/core": "15.1.0",
231
231
  "cva": "1.0.0-beta.4",
232
232
  "radix-vue": "^1.9.17",
@@ -235,7 +235,7 @@
235
235
  },
236
236
  "devDependencies": {
237
237
  "@playwright/test": "1.65.1",
238
- "@scalar/use-toasts": "0.10.12",
238
+ "@scalar/use-toasts": "0.11.0",
239
239
  "@storybook/addon-docs": "10.6.9",
240
240
  "@storybook/addon-links": "10.6.9",
241
241
  "@storybook/vue3-vite": "10.6.9",