mood-ui 0.14.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/data-display/table/Table.cjs +1 -1
- package/dist/components/data-display/table/Table.cjs.map +1 -1
- package/dist/components/data-display/table/Table.mjs +1 -1
- package/dist/components/data-display/table/Table.mjs.map +1 -1
- package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.cjs +37 -1
- package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.mjs +38 -2
- package/dist/components/data-display/table/Table.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/table/TablePagination.cjs.map +1 -1
- package/dist/components/data-display/table/TablePagination.mjs.map +1 -1
- package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.cjs +24 -16
- package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.mjs +24 -16
- package/dist/components/data-display/table/TablePagination.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/EmptyState.cjs.map +1 -1
- package/dist/components/feedback/EmptyState.mjs.map +1 -1
- package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/feedback/EmptyState.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.cjs +369 -0
- package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.mjs +368 -0
- package/dist/components/feedback/tour/Tour.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/feedback/tour/Tour2.cjs +6 -0
- package/dist/components/feedback/tour/Tour2.cjs.map +1 -0
- package/dist/components/feedback/tour/Tour2.mjs +7 -0
- package/dist/components/feedback/tour/Tour2.mjs.map +1 -0
- package/dist/components/feedback/tour/TourCard.cjs +6 -0
- package/dist/components/feedback/tour/TourCard.cjs.map +1 -0
- package/dist/components/feedback/tour/TourCard.mjs +7 -0
- package/dist/components/feedback/tour/TourCard.mjs.map +1 -0
- package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.cjs +102 -0
- package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.cjs.map +1 -0
- package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.mjs +101 -0
- package/dist/components/feedback/tour/TourCard.vue_vue_type_script_setup_true_lang.mjs.map +1 -0
- package/dist/components/feedback/tour/tourAnchor.cjs +75 -0
- package/dist/components/feedback/tour/tourAnchor.cjs.map +1 -0
- package/dist/components/feedback/tour/tourAnchor.mjs +72 -0
- package/dist/components/feedback/tour/tourAnchor.mjs.map +1 -0
- package/dist/components/feedback/tour/tourPlace.cjs +108 -0
- package/dist/components/feedback/tour/tourPlace.cjs.map +1 -0
- package/dist/components/feedback/tour/tourPlace.mjs +107 -0
- package/dist/components/feedback/tour/tourPlace.mjs.map +1 -0
- package/dist/components/feedback/tour/tourShape.cjs +121 -0
- package/dist/components/feedback/tour/tourShape.cjs.map +1 -0
- package/dist/components/feedback/tour/tourShape.mjs +118 -0
- package/dist/components/feedback/tour/tourShape.mjs.map +1 -0
- package/dist/components/feedback/tour/useTourSpotlight.cjs +60 -0
- package/dist/components/feedback/tour/useTourSpotlight.cjs.map +1 -0
- package/dist/components/feedback/tour/useTourSpotlight.mjs +59 -0
- package/dist/components/feedback/tour/useTourSpotlight.mjs.map +1 -0
- package/dist/components/feedback/tour/useTourSteps.cjs +108 -0
- package/dist/components/feedback/tour/useTourSteps.cjs.map +1 -0
- package/dist/components/feedback/tour/useTourSteps.mjs +107 -0
- package/dist/components/feedback/tour/useTourSteps.mjs.map +1 -0
- package/dist/components/forms/Button.cjs +1 -1
- package/dist/components/forms/Button.cjs.map +1 -1
- package/dist/components/forms/Button.mjs +1 -1
- package/dist/components/forms/Button.mjs.map +1 -1
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/Button.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/FileInput.cjs +1 -1
- package/dist/components/forms/FileInput.cjs.map +1 -1
- package/dist/components/forms/FileInput.mjs +1 -1
- package/dist/components/forms/FileInput.mjs.map +1 -1
- package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.cjs +34 -17
- package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.mjs +34 -17
- package/dist/components/forms/FileInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/MultiSelect.cjs +1 -1
- package/dist/components/forms/MultiSelect.cjs.map +1 -1
- package/dist/components/forms/MultiSelect.mjs +1 -1
- package/dist/components/forms/MultiSelect.mjs.map +1 -1
- package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.cjs +2 -1
- package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.mjs +2 -1
- package/dist/components/forms/MultiSelect.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/TagInput.cjs.map +1 -1
- package/dist/components/forms/TagInput.mjs.map +1 -1
- package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.cjs +1 -0
- package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.mjs +1 -0
- package/dist/components/forms/TagInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Textarea.cjs.map +1 -1
- package/dist/components/forms/Textarea.mjs.map +1 -1
- package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/forms/Textarea.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/Canvas.cjs +1 -1
- package/dist/components/layout/Canvas.cjs.map +1 -1
- package/dist/components/layout/Canvas.mjs +1 -1
- package/dist/components/layout/Canvas.mjs.map +1 -1
- package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/layout/Canvas.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.cjs +1 -1
- package/dist/components/layout/PopoverPanel.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.mjs +1 -1
- package/dist/components/layout/PopoverPanel.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/popover/PopoverTrigger.cjs.map +1 -1
- package/dist/components/layout/popover/PopoverTrigger.mjs.map +1 -1
- package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/layout/popover/PopoverTrigger.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/DropdownMenu.cjs +1 -1
- package/dist/components/navigation/DropdownMenu.cjs.map +1 -1
- package/dist/components/navigation/DropdownMenu.mjs +1 -1
- package/dist/components/navigation/DropdownMenu.mjs.map +1 -1
- package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/navigation/DropdownMenu.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/Switcher.cjs.map +1 -1
- package/dist/components/navigation/Switcher.mjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs +77 -45
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs +77 -45
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/menu/MenuTrigger.cjs.map +1 -1
- package/dist/components/navigation/menu/MenuTrigger.mjs.map +1 -1
- package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/navigation/menu/MenuTrigger.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/composables/useField.cjs +28 -8
- package/dist/composables/useField.cjs.map +1 -1
- package/dist/composables/useField.mjs +28 -8
- package/dist/composables/useField.mjs.map +1 -1
- package/dist/config/ModoLocale.cjs +10 -1
- package/dist/config/ModoLocale.cjs.map +1 -1
- package/dist/config/ModoLocale.mjs +10 -1
- package/dist/config/ModoLocale.mjs.map +1 -1
- package/dist/config/locales/es.cjs +10 -1
- package/dist/config/locales/es.cjs.map +1 -1
- package/dist/config/locales/es.mjs +10 -1
- package/dist/config/locales/es.mjs.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.mjs +3 -1
- package/dist/mood-ui.css +289 -103
- package/dist/types/components/data-display/surface-card/SurfaceCardBody.vue.d.ts +1 -1
- package/dist/types/components/data-display/surface-card/SurfaceCardFooter.vue.d.ts +1 -1
- package/dist/types/components/data-display/surface-card/SurfaceCardHeader.vue.d.ts +1 -1
- package/dist/types/components/feedback/dialog/DialogContent.vue.d.ts +1 -1
- package/dist/types/components/feedback/tour/Tour.vue.d.ts +31 -0
- package/dist/types/components/feedback/tour/TourCard.vue.d.ts +25 -0
- package/dist/types/components/feedback/tour/index.d.ts +2 -0
- package/dist/types/components/feedback/tour/tourAnchor.d.ts +12 -0
- package/dist/types/components/feedback/tour/tourPlace.d.ts +60 -0
- package/dist/types/components/feedback/tour/tourShape.d.ts +36 -0
- package/dist/types/components/feedback/tour/useTourSpotlight.d.ts +14 -0
- package/dist/types/components/feedback/tour/useTourSteps.d.ts +31 -0
- package/dist/types/components/layout/Canvas.vue.d.ts +1 -1
- package/dist/types/components/layout/popover/PopoverContent.vue.d.ts +1 -1
- package/dist/types/components/navigation/menu/MenuContent.vue.d.ts +1 -1
- package/dist/types/composables/useField.d.ts +23 -0
- package/dist/types/config/ModoLocale.d.ts +14 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/interfaces/feedback/Tour.interface.d.ts +73 -0
- package/dist/types/interfaces/navigation/Switcher.interface.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tourShape.cjs","names":[],"sources":["../../../../src/components/feedback/tour/tourShape.ts"],"sourcesContent":["/** The room around a target inside the spotlight's cut. */\nconst PADDING = 8;\n\n/** mood-ui's corners (PopoverPanel's rounded-sm, -md, -xl and -2xl) in pixels, so the cut wears the person's radius. */\nconst RADII: Record<string, number> = { none: 0, small: 4, medium: 6, large: 12, full: 16 };\n\nexport interface Viewport {\n width: number;\n height: number;\n}\n\nexport interface Hole {\n x: number;\n y: number;\n width: number;\n height: number;\n radius: number;\n /** A card sits over the hole's foot: what lies at or right of `x` and at or below `y` (screen pixels) is not cut. */\n notch?: { x: number; y: number };\n}\n\n/** The corner's radius in pixels of mood-ui's radius name; medium when there is none. */\nexport function radiusOf(radius: string | undefined): number {\n return RADII[radius ?? \"medium\"] ?? 6;\n}\n\n/**\n * The cut around a target's box: padded, kept inside the screen, its corners never rounder than half its side. `cover` is the corner of\n * the screen a card holds: the cut loses only what lies there (a step down for a card under the target's right part, a plain trim when\n * the card spans the target's whole width or height), so the rest of a wide target stays lit.\n */\nexport function holeAround(\n box: { left: number; top: number; width: number; height: number },\n radius: number,\n viewport: Viewport,\n cover: { left: number; top: number } | null = null,\n): Hole {\n const x = Math.max(0, box.left - PADDING);\n const y = Math.max(0, box.top - PADDING);\n let width = Math.max(0, Math.min(viewport.width, box.left + box.width + PADDING) - x);\n let height = Math.max(0, Math.min(viewport.height, box.top + box.height + PADDING) - y);\n let notch: Hole[\"notch\"];\n if (cover && cover.left < x + width && cover.top < y + height) {\n if (cover.left <= x) height = Math.max(0, cover.top - y);\n else if (cover.top <= y) width = Math.max(0, cover.left - x);\n else notch = { x: cover.left, y: cover.top };\n }\n const hole: Hole = { x, y, width, height, radius: Math.min(radius, width / 2, height / 2) };\n return notch ? { ...hole, notch } : hole;\n}\n\ntype Point = [number, number];\n\n/** The cut's corners, clockwise: a rectangle, or an L when a card takes its bottom right corner. */\nfunction corners({ x, y, width: w, height: h, notch }: Hole): Point[] {\n if (!notch) return [[x, y], [x + w, y], [x + w, y + h], [x, y + h]];\n return [[x, y], [x + w, y], [x + w, notch.y], [notch.x, notch.y], [notch.x, y + h], [x, y + h]];\n}\n\n/** The closed outline of the cut, every corner rounded by the hole's radius (less where an edge is short), the arcs turning with the corner. */\nfunction outline(hole: Hole): string {\n const points = corners(hole);\n const r = Math.max(0, hole.radius);\n const bends = points.map((at, i) => {\n const before = points[(i + points.length - 1) % points.length]!;\n const after = points[(i + 1) % points.length]!;\n const lengthIn = Math.abs(at[0] - before[0]) + Math.abs(at[1] - before[1]);\n const lengthOut = Math.abs(after[0] - at[0]) + Math.abs(after[1] - at[1]);\n const radius = Math.min(r, lengthIn / 2, lengthOut / 2);\n const inward: Point = [Math.sign(at[0] - before[0]), Math.sign(at[1] - before[1])];\n const outward: Point = [Math.sign(after[0] - at[0]), Math.sign(after[1] - at[1])];\n return {\n radius,\n from: [at[0] - inward[0] * radius, at[1] - inward[1] * radius] as Point,\n to: [at[0] + outward[0] * radius, at[1] + outward[1] * radius] as Point,\n sweep: inward[0] * outward[1] - inward[1] * outward[0] > 0 ? 1 : 0,\n };\n });\n const first = bends[0]!;\n let path = `M${first.to[0]} ${first.to[1]}`;\n let at = first.to;\n for (const bend of [...bends.slice(1), first]) {\n path += `${at[1] === bend.from[1] ? \"H\" : \"V\"}${at[1] === bend.from[1] ? bend.from[0] : bend.from[1]}`;\n path += `A${bend.radius} ${bend.radius} 0 0 ${bend.sweep} ${bend.to[0]} ${bend.to[1]}`;\n at = bend.to;\n }\n return `${path}Z`;\n}\n\n/** The shade over the screen with the hole cut out (drawn after it, for `fill-rule=\"evenodd\"`), or the whole screen without one. */\nexport function spotlightPath(viewport: Viewport, hole: Hole | null): string {\n const screen = `M0 0H${viewport.width}V${viewport.height}H0Z`;\n if (!hole || hole.width <= 0 || hole.height <= 0) return screen;\n return `${screen}${outline(hole)}`;\n}\n\n/** The line round the cut, `inset` pixels inside it (half the stroke's width keeps a stroke wholly inside the cut), or null with no cut. */\nexport function ringPath(hole: Hole | null, inset: number): string | null {\n if (!hole || hole.width <= 2 * inset || hole.height <= 2 * inset) return null;\n const inner: Hole = { x: hole.x + inset, y: hole.y + inset, width: hole.width - 2 * inset, height: hole.height - 2 * inset, radius: Math.max(0, hole.radius - inset) };\n return outline(hole.notch ? { ...inner, notch: { x: hole.notch.x - inset, y: hole.notch.y - inset } } : inner);\n}\n"],"mappings":";;AACA,IAAM,UAAU;;AAGhB,IAAM,QAAgC;CAAE,MAAM;CAAG,OAAO;CAAG,QAAQ;CAAG,OAAO;CAAI,MAAM;CAAI;;AAkB3F,SAAgB,SAAS,QAAoC;CAC3D,OAAO,MAAM,UAAU,aAAa;;;;;;;AAQtC,SAAgB,WACd,KACA,QACA,UACA,QAA8C,MACxC;CACN,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,OAAO,QAAQ;CACzC,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,MAAM,QAAQ;CACxC,IAAI,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,OAAO,IAAI,OAAO,IAAI,QAAQ,QAAQ,GAAG,EAAE;CACrF,IAAI,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,QAAQ,IAAI,MAAM,IAAI,SAAS,QAAQ,GAAG,EAAE;CACvF,IAAI;CACJ,IAAI,SAAS,MAAM,OAAO,IAAI,SAAS,MAAM,MAAM,IAAI,QACrD,IAAI,MAAM,QAAQ,GAAG,SAAS,KAAK,IAAI,GAAG,MAAM,MAAM,EAAE;MACnD,IAAI,MAAM,OAAO,GAAG,QAAQ,KAAK,IAAI,GAAG,MAAM,OAAO,EAAE;MACvD,QAAQ;EAAE,GAAG,MAAM;EAAM,GAAG,MAAM;EAAK;CAE9C,MAAM,OAAa;EAAE;EAAG;EAAG;EAAO;EAAQ,QAAQ,KAAK,IAAI,QAAQ,QAAQ,GAAG,SAAS,EAAE;EAAE;CAC3F,OAAO,QAAQ;EAAE,GAAG;EAAM;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AAG,KAAK,MAAM,IAAI;GAAO,GAAG,KAAK,MAAM,IAAI;GAAO;EAAE,GAAG,MAAM"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//#region src/components/feedback/tour/tourShape.ts
|
|
2
|
+
/** The room around a target inside the spotlight's cut. */
|
|
3
|
+
var PADDING = 8;
|
|
4
|
+
/** mood-ui's corners (PopoverPanel's rounded-sm, -md, -xl and -2xl) in pixels, so the cut wears the person's radius. */
|
|
5
|
+
var RADII = {
|
|
6
|
+
none: 0,
|
|
7
|
+
small: 4,
|
|
8
|
+
medium: 6,
|
|
9
|
+
large: 12,
|
|
10
|
+
full: 16
|
|
11
|
+
};
|
|
12
|
+
/** The corner's radius in pixels of mood-ui's radius name; medium when there is none. */
|
|
13
|
+
function radiusOf(radius) {
|
|
14
|
+
return RADII[radius ?? "medium"] ?? 6;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The cut around a target's box: padded, kept inside the screen, its corners never rounder than half its side. `cover` is the corner of
|
|
18
|
+
* the screen a card holds: the cut loses only what lies there (a step down for a card under the target's right part, a plain trim when
|
|
19
|
+
* the card spans the target's whole width or height), so the rest of a wide target stays lit.
|
|
20
|
+
*/
|
|
21
|
+
function holeAround(box, radius, viewport, cover = null) {
|
|
22
|
+
const x = Math.max(0, box.left - PADDING);
|
|
23
|
+
const y = Math.max(0, box.top - PADDING);
|
|
24
|
+
let width = Math.max(0, Math.min(viewport.width, box.left + box.width + PADDING) - x);
|
|
25
|
+
let height = Math.max(0, Math.min(viewport.height, box.top + box.height + PADDING) - y);
|
|
26
|
+
let notch;
|
|
27
|
+
if (cover && cover.left < x + width && cover.top < y + height) if (cover.left <= x) height = Math.max(0, cover.top - y);
|
|
28
|
+
else if (cover.top <= y) width = Math.max(0, cover.left - x);
|
|
29
|
+
else notch = {
|
|
30
|
+
x: cover.left,
|
|
31
|
+
y: cover.top
|
|
32
|
+
};
|
|
33
|
+
const hole = {
|
|
34
|
+
x,
|
|
35
|
+
y,
|
|
36
|
+
width,
|
|
37
|
+
height,
|
|
38
|
+
radius: Math.min(radius, width / 2, height / 2)
|
|
39
|
+
};
|
|
40
|
+
return notch ? {
|
|
41
|
+
...hole,
|
|
42
|
+
notch
|
|
43
|
+
} : hole;
|
|
44
|
+
}
|
|
45
|
+
/** The cut's corners, clockwise: a rectangle, or an L when a card takes its bottom right corner. */
|
|
46
|
+
function corners({ x, y, width: w, height: h, notch }) {
|
|
47
|
+
if (!notch) return [
|
|
48
|
+
[x, y],
|
|
49
|
+
[x + w, y],
|
|
50
|
+
[x + w, y + h],
|
|
51
|
+
[x, y + h]
|
|
52
|
+
];
|
|
53
|
+
return [
|
|
54
|
+
[x, y],
|
|
55
|
+
[x + w, y],
|
|
56
|
+
[x + w, notch.y],
|
|
57
|
+
[notch.x, notch.y],
|
|
58
|
+
[notch.x, y + h],
|
|
59
|
+
[x, y + h]
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
/** The closed outline of the cut, every corner rounded by the hole's radius (less where an edge is short), the arcs turning with the corner. */
|
|
63
|
+
function outline(hole) {
|
|
64
|
+
const points = corners(hole);
|
|
65
|
+
const r = Math.max(0, hole.radius);
|
|
66
|
+
const bends = points.map((at, i) => {
|
|
67
|
+
const before = points[(i + points.length - 1) % points.length];
|
|
68
|
+
const after = points[(i + 1) % points.length];
|
|
69
|
+
const lengthIn = Math.abs(at[0] - before[0]) + Math.abs(at[1] - before[1]);
|
|
70
|
+
const lengthOut = Math.abs(after[0] - at[0]) + Math.abs(after[1] - at[1]);
|
|
71
|
+
const radius = Math.min(r, lengthIn / 2, lengthOut / 2);
|
|
72
|
+
const inward = [Math.sign(at[0] - before[0]), Math.sign(at[1] - before[1])];
|
|
73
|
+
const outward = [Math.sign(after[0] - at[0]), Math.sign(after[1] - at[1])];
|
|
74
|
+
return {
|
|
75
|
+
radius,
|
|
76
|
+
from: [at[0] - inward[0] * radius, at[1] - inward[1] * radius],
|
|
77
|
+
to: [at[0] + outward[0] * radius, at[1] + outward[1] * radius],
|
|
78
|
+
sweep: inward[0] * outward[1] - inward[1] * outward[0] > 0 ? 1 : 0
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
const first = bends[0];
|
|
82
|
+
let path = `M${first.to[0]} ${first.to[1]}`;
|
|
83
|
+
let at = first.to;
|
|
84
|
+
for (const bend of [...bends.slice(1), first]) {
|
|
85
|
+
path += `${at[1] === bend.from[1] ? "H" : "V"}${at[1] === bend.from[1] ? bend.from[0] : bend.from[1]}`;
|
|
86
|
+
path += `A${bend.radius} ${bend.radius} 0 0 ${bend.sweep} ${bend.to[0]} ${bend.to[1]}`;
|
|
87
|
+
at = bend.to;
|
|
88
|
+
}
|
|
89
|
+
return `${path}Z`;
|
|
90
|
+
}
|
|
91
|
+
/** The shade over the screen with the hole cut out (drawn after it, for `fill-rule="evenodd"`), or the whole screen without one. */
|
|
92
|
+
function spotlightPath(viewport, hole) {
|
|
93
|
+
const screen = `M0 0H${viewport.width}V${viewport.height}H0Z`;
|
|
94
|
+
if (!hole || hole.width <= 0 || hole.height <= 0) return screen;
|
|
95
|
+
return `${screen}${outline(hole)}`;
|
|
96
|
+
}
|
|
97
|
+
/** The line round the cut, `inset` pixels inside it (half the stroke's width keeps a stroke wholly inside the cut), or null with no cut. */
|
|
98
|
+
function ringPath(hole, inset) {
|
|
99
|
+
if (!hole || hole.width <= 2 * inset || hole.height <= 2 * inset) return null;
|
|
100
|
+
const inner = {
|
|
101
|
+
x: hole.x + inset,
|
|
102
|
+
y: hole.y + inset,
|
|
103
|
+
width: hole.width - 2 * inset,
|
|
104
|
+
height: hole.height - 2 * inset,
|
|
105
|
+
radius: Math.max(0, hole.radius - inset)
|
|
106
|
+
};
|
|
107
|
+
return outline(hole.notch ? {
|
|
108
|
+
...inner,
|
|
109
|
+
notch: {
|
|
110
|
+
x: hole.notch.x - inset,
|
|
111
|
+
y: hole.notch.y - inset
|
|
112
|
+
}
|
|
113
|
+
} : inner);
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { holeAround, radiusOf, ringPath, spotlightPath };
|
|
117
|
+
|
|
118
|
+
//# sourceMappingURL=tourShape.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tourShape.mjs","names":[],"sources":["../../../../src/components/feedback/tour/tourShape.ts"],"sourcesContent":["/** The room around a target inside the spotlight's cut. */\nconst PADDING = 8;\n\n/** mood-ui's corners (PopoverPanel's rounded-sm, -md, -xl and -2xl) in pixels, so the cut wears the person's radius. */\nconst RADII: Record<string, number> = { none: 0, small: 4, medium: 6, large: 12, full: 16 };\n\nexport interface Viewport {\n width: number;\n height: number;\n}\n\nexport interface Hole {\n x: number;\n y: number;\n width: number;\n height: number;\n radius: number;\n /** A card sits over the hole's foot: what lies at or right of `x` and at or below `y` (screen pixels) is not cut. */\n notch?: { x: number; y: number };\n}\n\n/** The corner's radius in pixels of mood-ui's radius name; medium when there is none. */\nexport function radiusOf(radius: string | undefined): number {\n return RADII[radius ?? \"medium\"] ?? 6;\n}\n\n/**\n * The cut around a target's box: padded, kept inside the screen, its corners never rounder than half its side. `cover` is the corner of\n * the screen a card holds: the cut loses only what lies there (a step down for a card under the target's right part, a plain trim when\n * the card spans the target's whole width or height), so the rest of a wide target stays lit.\n */\nexport function holeAround(\n box: { left: number; top: number; width: number; height: number },\n radius: number,\n viewport: Viewport,\n cover: { left: number; top: number } | null = null,\n): Hole {\n const x = Math.max(0, box.left - PADDING);\n const y = Math.max(0, box.top - PADDING);\n let width = Math.max(0, Math.min(viewport.width, box.left + box.width + PADDING) - x);\n let height = Math.max(0, Math.min(viewport.height, box.top + box.height + PADDING) - y);\n let notch: Hole[\"notch\"];\n if (cover && cover.left < x + width && cover.top < y + height) {\n if (cover.left <= x) height = Math.max(0, cover.top - y);\n else if (cover.top <= y) width = Math.max(0, cover.left - x);\n else notch = { x: cover.left, y: cover.top };\n }\n const hole: Hole = { x, y, width, height, radius: Math.min(radius, width / 2, height / 2) };\n return notch ? { ...hole, notch } : hole;\n}\n\ntype Point = [number, number];\n\n/** The cut's corners, clockwise: a rectangle, or an L when a card takes its bottom right corner. */\nfunction corners({ x, y, width: w, height: h, notch }: Hole): Point[] {\n if (!notch) return [[x, y], [x + w, y], [x + w, y + h], [x, y + h]];\n return [[x, y], [x + w, y], [x + w, notch.y], [notch.x, notch.y], [notch.x, y + h], [x, y + h]];\n}\n\n/** The closed outline of the cut, every corner rounded by the hole's radius (less where an edge is short), the arcs turning with the corner. */\nfunction outline(hole: Hole): string {\n const points = corners(hole);\n const r = Math.max(0, hole.radius);\n const bends = points.map((at, i) => {\n const before = points[(i + points.length - 1) % points.length]!;\n const after = points[(i + 1) % points.length]!;\n const lengthIn = Math.abs(at[0] - before[0]) + Math.abs(at[1] - before[1]);\n const lengthOut = Math.abs(after[0] - at[0]) + Math.abs(after[1] - at[1]);\n const radius = Math.min(r, lengthIn / 2, lengthOut / 2);\n const inward: Point = [Math.sign(at[0] - before[0]), Math.sign(at[1] - before[1])];\n const outward: Point = [Math.sign(after[0] - at[0]), Math.sign(after[1] - at[1])];\n return {\n radius,\n from: [at[0] - inward[0] * radius, at[1] - inward[1] * radius] as Point,\n to: [at[0] + outward[0] * radius, at[1] + outward[1] * radius] as Point,\n sweep: inward[0] * outward[1] - inward[1] * outward[0] > 0 ? 1 : 0,\n };\n });\n const first = bends[0]!;\n let path = `M${first.to[0]} ${first.to[1]}`;\n let at = first.to;\n for (const bend of [...bends.slice(1), first]) {\n path += `${at[1] === bend.from[1] ? \"H\" : \"V\"}${at[1] === bend.from[1] ? bend.from[0] : bend.from[1]}`;\n path += `A${bend.radius} ${bend.radius} 0 0 ${bend.sweep} ${bend.to[0]} ${bend.to[1]}`;\n at = bend.to;\n }\n return `${path}Z`;\n}\n\n/** The shade over the screen with the hole cut out (drawn after it, for `fill-rule=\"evenodd\"`), or the whole screen without one. */\nexport function spotlightPath(viewport: Viewport, hole: Hole | null): string {\n const screen = `M0 0H${viewport.width}V${viewport.height}H0Z`;\n if (!hole || hole.width <= 0 || hole.height <= 0) return screen;\n return `${screen}${outline(hole)}`;\n}\n\n/** The line round the cut, `inset` pixels inside it (half the stroke's width keeps a stroke wholly inside the cut), or null with no cut. */\nexport function ringPath(hole: Hole | null, inset: number): string | null {\n if (!hole || hole.width <= 2 * inset || hole.height <= 2 * inset) return null;\n const inner: Hole = { x: hole.x + inset, y: hole.y + inset, width: hole.width - 2 * inset, height: hole.height - 2 * inset, radius: Math.max(0, hole.radius - inset) };\n return outline(hole.notch ? { ...inner, notch: { x: hole.notch.x - inset, y: hole.notch.y - inset } } : inner);\n}\n"],"mappings":";;AACA,IAAM,UAAU;;AAGhB,IAAM,QAAgC;CAAE,MAAM;CAAG,OAAO;CAAG,QAAQ;CAAG,OAAO;CAAI,MAAM;CAAI;;AAkB3F,SAAgB,SAAS,QAAoC;CAC3D,OAAO,MAAM,UAAU,aAAa;;;;;;;AAQtC,SAAgB,WACd,KACA,QACA,UACA,QAA8C,MACxC;CACN,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,OAAO,QAAQ;CACzC,MAAM,IAAI,KAAK,IAAI,GAAG,IAAI,MAAM,QAAQ;CACxC,IAAI,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,OAAO,IAAI,OAAO,IAAI,QAAQ,QAAQ,GAAG,EAAE;CACrF,IAAI,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,SAAS,QAAQ,IAAI,MAAM,IAAI,SAAS,QAAQ,GAAG,EAAE;CACvF,IAAI;CACJ,IAAI,SAAS,MAAM,OAAO,IAAI,SAAS,MAAM,MAAM,IAAI,QACrD,IAAI,MAAM,QAAQ,GAAG,SAAS,KAAK,IAAI,GAAG,MAAM,MAAM,EAAE;MACnD,IAAI,MAAM,OAAO,GAAG,QAAQ,KAAK,IAAI,GAAG,MAAM,OAAO,EAAE;MACvD,QAAQ;EAAE,GAAG,MAAM;EAAM,GAAG,MAAM;EAAK;CAE9C,MAAM,OAAa;EAAE;EAA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AAO,QAAQ,KAAK,IAAI,GAAG,KAAK,SAAS,MAAM;EAAE;CACtK,OAAO,QAAQ,KAAK,QAAQ;EAAE,GAAG;EAAO,OAAO;GAAE,GAAG,KAAK,MAAM,IAAI;GAAO,GAAG,KAAK,MAAM,IAAI;GAAO;EAAE,GAAG,MAAM"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
const require_useModoConfig = require("../../../composables/useModoConfig.cjs");
|
|
3
|
+
const require_tourShape = require("./tourShape.cjs");
|
|
4
|
+
let vue = require("vue");
|
|
5
|
+
//#region src/components/feedback/tour/useTourSpotlight.ts
|
|
6
|
+
/**
|
|
7
|
+
* The tour's shade over the screen, the target cut out at the provider's corners; it follows scrolls, resizes and the target's size.
|
|
8
|
+
* `cover` (the corner a pinned card holds) is what the cut does not take: only the part of the target the card sits over goes dark.
|
|
9
|
+
*/
|
|
10
|
+
function useTourSpotlight(target, cover = (0, vue.ref)(null)) {
|
|
11
|
+
const radius = require_useModoConfig.useResolvedRadius(() => void 0);
|
|
12
|
+
const viewport = (0, vue.ref)({
|
|
13
|
+
width: 0,
|
|
14
|
+
height: 0
|
|
15
|
+
});
|
|
16
|
+
const box = (0, vue.shallowRef)(null);
|
|
17
|
+
let observer = null;
|
|
18
|
+
function measure() {
|
|
19
|
+
if (typeof window === "undefined") return;
|
|
20
|
+
viewport.value = {
|
|
21
|
+
width: window.innerWidth,
|
|
22
|
+
height: window.innerHeight
|
|
23
|
+
};
|
|
24
|
+
box.value = target.value ? target.value.getBoundingClientRect() : null;
|
|
25
|
+
}
|
|
26
|
+
(0, vue.watch)(target, (element) => {
|
|
27
|
+
observer?.disconnect();
|
|
28
|
+
observer = element && typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null;
|
|
29
|
+
if (element) observer?.observe(element);
|
|
30
|
+
measure();
|
|
31
|
+
}, {
|
|
32
|
+
immediate: true,
|
|
33
|
+
flush: "post"
|
|
34
|
+
});
|
|
35
|
+
(0, vue.onMounted)(() => {
|
|
36
|
+
window.addEventListener("scroll", measure, true);
|
|
37
|
+
window.addEventListener("resize", measure);
|
|
38
|
+
});
|
|
39
|
+
(0, vue.onBeforeUnmount)(() => {
|
|
40
|
+
window.removeEventListener("scroll", measure, true);
|
|
41
|
+
window.removeEventListener("resize", measure);
|
|
42
|
+
observer?.disconnect();
|
|
43
|
+
});
|
|
44
|
+
/** The cut around the target (null with none): the shade's path and the ring that outlines it follow the same box. */
|
|
45
|
+
const hole = (0, vue.computed)(() => box.value ? require_tourShape.holeAround(box.value, require_tourShape.radiusOf(radius.value), viewport.value, cover.value) : null);
|
|
46
|
+
const path = (0, vue.computed)(() => require_tourShape.spotlightPath(viewport.value, hole.value));
|
|
47
|
+
/** The ring that outlines the cut: its stroke (2px) lies inside it. */
|
|
48
|
+
const ring = (0, vue.computed)(() => require_tourShape.ringPath(hole.value, 1));
|
|
49
|
+
(0, vue.watch)(cover, measure);
|
|
50
|
+
return {
|
|
51
|
+
path,
|
|
52
|
+
hole,
|
|
53
|
+
ring,
|
|
54
|
+
measure
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.useTourSpotlight = useTourSpotlight;
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=useTourSpotlight.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTourSpotlight.cjs","names":[],"sources":["../../../../src/components/feedback/tour/useTourSpotlight.ts"],"sourcesContent":["import { computed, onBeforeUnmount, onMounted, ref, shallowRef, watch, type Ref } from \"vue\";\nimport { useResolvedRadius } from \"../../../composables/useModoConfig\";\nimport { holeAround, radiusOf, ringPath, spotlightPath, type Viewport } from \"./tourShape\";\n\n/**\n * The tour's shade over the screen, the target cut out at the provider's corners; it follows scrolls, resizes and the target's size.\n * `cover` (the corner a pinned card holds) is what the cut does not take: only the part of the target the card sits over goes dark.\n */\nexport function useTourSpotlight(target: Ref<HTMLElement | null>, cover: Ref<{ left: number; top: number } | null> = ref(null)) {\n const radius = useResolvedRadius(() => undefined);\n const viewport = ref<Viewport>({ width: 0, height: 0 });\n const box = shallowRef<DOMRect | null>(null);\n let observer: ResizeObserver | null = null;\n\n function measure(): void {\n if (typeof window === \"undefined\") return;\n viewport.value = { width: window.innerWidth, height: window.innerHeight };\n box.value = target.value ? target.value.getBoundingClientRect() : null;\n }\n\n watch(\n target,\n (element) => {\n observer?.disconnect();\n observer = element && typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(measure) : null;\n if (element) observer?.observe(element);\n measure();\n },\n { immediate: true, flush: \"post\" },\n );\n\n onMounted(() => {\n window.addEventListener(\"scroll\", measure, true);\n window.addEventListener(\"resize\", measure);\n });\n onBeforeUnmount(() => {\n window.removeEventListener(\"scroll\", measure, true);\n window.removeEventListener(\"resize\", measure);\n observer?.disconnect();\n });\n\n /** The cut around the target (null with none): the shade's path and the ring that outlines it follow the same box. */\n const hole = computed(() => (box.value ? holeAround(box.value, radiusOf(radius.value), viewport.value, cover.value) : null));\n const path = computed(() => spotlightPath(viewport.value, hole.value));\n /** The ring that outlines the cut: its stroke (2px) lies inside it. */\n const ring = computed(() => ringPath(hole.value, 1));\n watch(cover, measure);\n return { path, hole, ring, measure };\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,iBAAiB,QAAiC,SAAA,GAAA,IAAA,KAAuD,KAAK,EAAE;CAC9H,MAAM,SAAS,sBAAA,wBAAwB,KAAA,EAAU;CACjD,MAAM,YAAA,GAAA,IAAA,KAAyB;EAAE,OAAO;EAAG,QAAQ;EAAG,CAAC;CACvD,MAAM,OAAA,GAAA,IAAA,YAAiC,KAAK;CAC5C,IAAI,WAAkC;CAEtC,SAAS,UAAgB;EACvB,IAAI,OAAO,WAAW,aAAa;EACnC,SAAS,QAAQ;GAAE,OAAO,OAAO;GAAY,QAAQ,OAAO;GAAa;EACzE,IAAI,QAAQ,OAAO,QAAQ,OAAO,MAAM,uBAAuB,GAAG;;CAGpE,CAAA,GAAA,IAAA,OACE,SACC,YAAY;EACX,UAAU,YAAY;EACtB,WAAW,WAAW,OAAO,mBAAmB,cAAc,IAAI,eAAe,QAAQ,GAAG;EAC5F,IAAI,SAAS,UAAU,QAAQ,QAAQ;EACvC,SAAS;IAEX;EAAE,WAAW;EAAM,OAAO;EAAQ,CACnC;CAED,CAAA,GAAA,IAAA,iBAAgB;EACd,OAAO,iBAAiB,UAAU,SAAS,KAAK;EAChD,OAAO,iBAAiB,UAAU,QAAQ;GAC1C;CACF,CAAA,GAAA,IAAA,uBAAsB;EACpB,OAAO,oBAAoB,UAAU,SAAS,KAAK;EACnD,OAAO,oBAAoB,UAAU,QAAQ;EAC7C,UAAU,YAAY;GACtB;;CAGF,MAAM,QAAA,GAAA,IAAA,gBAAuB,IAAI,QAAQ,kBAAA,WAAW,IAAI,OAAO,kBAAA,SAAS,OAAO,MAAM,EAAE,SAAS,OAAO,MAAM,MAAM,GAAG,KAAM;CAC5H,MAAM,QAAA,GAAA,IAAA,gBAAsB,kBAAA,cAAc,SAAS,OAAO,KAAK,MAAM,CAAC;;CAEtE,MAAM,QAAA,GAAA,IAAA,gBAAsB,kBAAA,SAAS,KAAK,OAAO,EAAE,CAAC;CACpD,CAAA,GAAA,IAAA,OAAM,OAAO,QAAQ;CACrB,OAAO;EAAE;EAAM;EAAM;EAAM;EAAS"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useResolvedRadius } from "../../../composables/useModoConfig.mjs";
|
|
2
|
+
import { holeAround, radiusOf, ringPath, spotlightPath } from "./tourShape.mjs";
|
|
3
|
+
import { computed, onBeforeUnmount, onMounted, ref, shallowRef, watch } from "vue";
|
|
4
|
+
//#region src/components/feedback/tour/useTourSpotlight.ts
|
|
5
|
+
/**
|
|
6
|
+
* The tour's shade over the screen, the target cut out at the provider's corners; it follows scrolls, resizes and the target's size.
|
|
7
|
+
* `cover` (the corner a pinned card holds) is what the cut does not take: only the part of the target the card sits over goes dark.
|
|
8
|
+
*/
|
|
9
|
+
function useTourSpotlight(target, cover = ref(null)) {
|
|
10
|
+
const radius = useResolvedRadius(() => void 0);
|
|
11
|
+
const viewport = ref({
|
|
12
|
+
width: 0,
|
|
13
|
+
height: 0
|
|
14
|
+
});
|
|
15
|
+
const box = shallowRef(null);
|
|
16
|
+
let observer = null;
|
|
17
|
+
function measure() {
|
|
18
|
+
if (typeof window === "undefined") return;
|
|
19
|
+
viewport.value = {
|
|
20
|
+
width: window.innerWidth,
|
|
21
|
+
height: window.innerHeight
|
|
22
|
+
};
|
|
23
|
+
box.value = target.value ? target.value.getBoundingClientRect() : null;
|
|
24
|
+
}
|
|
25
|
+
watch(target, (element) => {
|
|
26
|
+
observer?.disconnect();
|
|
27
|
+
observer = element && typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null;
|
|
28
|
+
if (element) observer?.observe(element);
|
|
29
|
+
measure();
|
|
30
|
+
}, {
|
|
31
|
+
immediate: true,
|
|
32
|
+
flush: "post"
|
|
33
|
+
});
|
|
34
|
+
onMounted(() => {
|
|
35
|
+
window.addEventListener("scroll", measure, true);
|
|
36
|
+
window.addEventListener("resize", measure);
|
|
37
|
+
});
|
|
38
|
+
onBeforeUnmount(() => {
|
|
39
|
+
window.removeEventListener("scroll", measure, true);
|
|
40
|
+
window.removeEventListener("resize", measure);
|
|
41
|
+
observer?.disconnect();
|
|
42
|
+
});
|
|
43
|
+
/** The cut around the target (null with none): the shade's path and the ring that outlines it follow the same box. */
|
|
44
|
+
const hole = computed(() => box.value ? holeAround(box.value, radiusOf(radius.value), viewport.value, cover.value) : null);
|
|
45
|
+
const path = computed(() => spotlightPath(viewport.value, hole.value));
|
|
46
|
+
/** The ring that outlines the cut: its stroke (2px) lies inside it. */
|
|
47
|
+
const ring = computed(() => ringPath(hole.value, 1));
|
|
48
|
+
watch(cover, measure);
|
|
49
|
+
return {
|
|
50
|
+
path,
|
|
51
|
+
hole,
|
|
52
|
+
ring,
|
|
53
|
+
measure
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { useTourSpotlight };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=useTourSpotlight.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTourSpotlight.mjs","names":[],"sources":["../../../../src/components/feedback/tour/useTourSpotlight.ts"],"sourcesContent":["import { computed, onBeforeUnmount, onMounted, ref, shallowRef, watch, type Ref } from \"vue\";\nimport { useResolvedRadius } from \"../../../composables/useModoConfig\";\nimport { holeAround, radiusOf, ringPath, spotlightPath, type Viewport } from \"./tourShape\";\n\n/**\n * The tour's shade over the screen, the target cut out at the provider's corners; it follows scrolls, resizes and the target's size.\n * `cover` (the corner a pinned card holds) is what the cut does not take: only the part of the target the card sits over goes dark.\n */\nexport function useTourSpotlight(target: Ref<HTMLElement | null>, cover: Ref<{ left: number; top: number } | null> = ref(null)) {\n const radius = useResolvedRadius(() => undefined);\n const viewport = ref<Viewport>({ width: 0, height: 0 });\n const box = shallowRef<DOMRect | null>(null);\n let observer: ResizeObserver | null = null;\n\n function measure(): void {\n if (typeof window === \"undefined\") return;\n viewport.value = { width: window.innerWidth, height: window.innerHeight };\n box.value = target.value ? target.value.getBoundingClientRect() : null;\n }\n\n watch(\n target,\n (element) => {\n observer?.disconnect();\n observer = element && typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(measure) : null;\n if (element) observer?.observe(element);\n measure();\n },\n { immediate: true, flush: \"post\" },\n );\n\n onMounted(() => {\n window.addEventListener(\"scroll\", measure, true);\n window.addEventListener(\"resize\", measure);\n });\n onBeforeUnmount(() => {\n window.removeEventListener(\"scroll\", measure, true);\n window.removeEventListener(\"resize\", measure);\n observer?.disconnect();\n });\n\n /** The cut around the target (null with none): the shade's path and the ring that outlines it follow the same box. */\n const hole = computed(() => (box.value ? holeAround(box.value, radiusOf(radius.value), viewport.value, cover.value) : null));\n const path = computed(() => spotlightPath(viewport.value, hole.value));\n /** The ring that outlines the cut: its stroke (2px) lies inside it. */\n const ring = computed(() => ringPath(hole.value, 1));\n watch(cover, measure);\n return { path, hole, ring, measure };\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,iBAAiB,QAAiC,QAAmD,IAAI,KAAK,EAAE;CAC9H,MAAM,SAAS,wBAAwB,KAAA,EAAU;CACjD,MAAM,WAAW,IAAc;EAAE,OAAO;EAAG,QAAQ;EAAG,CAAC;CACvD,MAAM,MAAM,WAA2B,KAAK;CAC5C,IAAI,WAAkC;CAEtC,SAAS,UAAgB;EACvB,IAAI,OAAO,WAAW,aAAa;EACnC,SAAS,QAAQ;GAAE,OAAO,OAAO;GAAY,QAAQ,OAAO;GAAa;EACzE,IAAI,QAAQ,OAAO,QAAQ,OAAO,MAAM,uBAAuB,GAAG;;CAGpE,MACE,SACC,YAAY;EACX,UAAU,YAAY;EACtB,WAAW,WAAW,OAAO,mBAAmB,cAAc,IAAI,eAAe,QAAQ,GAAG;EAC5F,IAAI,SAAS,UAAU,QAAQ,QAAQ;EACvC,SAAS;IAEX;EAAE,WAAW;EAAM,OAAO;EAAQ,CACnC;CAED,gBAAgB;EACd,OAAO,iBAAiB,UAAU,SAAS,KAAK;EAChD,OAAO,iBAAiB,UAAU,QAAQ;GAC1C;CACF,sBAAsB;EACpB,OAAO,oBAAoB,UAAU,SAAS,KAAK;EACnD,OAAO,oBAAoB,UAAU,QAAQ;EAC7C,UAAU,YAAY;GACtB;;CAGF,MAAM,OAAO,eAAgB,IAAI,QAAQ,WAAW,IAAI,OAAO,SAAS,OAAO,MAAM,EAAE,SAAS,OAAO,MAAM,MAAM,GAAG,KAAM;CAC5H,MAAM,OAAO,eAAe,cAAc,SAAS,OAAO,KAAK,MAAM,CAAC;;CAEtE,MAAM,OAAO,eAAe,SAAS,KAAK,OAAO,EAAE,CAAC;CACpD,MAAM,OAAO,QAAQ;CACrB,OAAO;EAAE;EAAM;EAAM;EAAM;EAAS"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require("../../../_virtual/_rolldown/runtime.cjs");
|
|
2
|
+
let vue = require("vue");
|
|
3
|
+
//#region src/components/feedback/tour/useTourSteps.ts
|
|
4
|
+
/** A step's `when`; one that throws says no. */
|
|
5
|
+
function allowed(item) {
|
|
6
|
+
try {
|
|
7
|
+
return item.when ? item.when() === true : true;
|
|
8
|
+
} catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The machine of a tour, with no screen in it. `start` keeps the steps that can show (their `when`, and for a step with no `before` a
|
|
14
|
+
* target that is there after a short wait), `next` and `back` show one at a time and drop a step that cannot show when its turn
|
|
15
|
+
* comes, and `stop` ends it. A newer move wins over one still waiting for its target, and a tour with nothing to show does not begin.
|
|
16
|
+
*/
|
|
17
|
+
function useTourSteps(options) {
|
|
18
|
+
const running = (0, vue.ref)(false);
|
|
19
|
+
const planned = (0, vue.shallowRef)([]);
|
|
20
|
+
const index = (0, vue.ref)(0);
|
|
21
|
+
const target = (0, vue.shallowRef)(null);
|
|
22
|
+
const step = (0, vue.computed)(() => running.value ? planned.value[index.value] ?? null : null);
|
|
23
|
+
const total = (0, vue.computed)(() => planned.value.length);
|
|
24
|
+
const shown = /* @__PURE__ */ new Set();
|
|
25
|
+
let lastId = null;
|
|
26
|
+
let turn = 0;
|
|
27
|
+
/** Runs a step's `before`, then finds its target: the element, undefined for a card with no target, null when it cannot show. */
|
|
28
|
+
async function reach(item) {
|
|
29
|
+
try {
|
|
30
|
+
await item.before?.();
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return item.target === void 0 ? void 0 : options.locate(item);
|
|
35
|
+
}
|
|
36
|
+
/** Starts a tour; `stale` when one is running or a newer call came first. */
|
|
37
|
+
async function start() {
|
|
38
|
+
if (running.value) return "stale";
|
|
39
|
+
const mine = ++turn;
|
|
40
|
+
const candidates = options.steps().filter(allowed);
|
|
41
|
+
const present = await Promise.all(candidates.map((each) => each.target !== void 0 && !each.before ? options.locate(each) : Promise.resolve(true)));
|
|
42
|
+
const keep = candidates.filter((_, at) => present[at] !== null);
|
|
43
|
+
if (mine !== turn || running.value) return "stale";
|
|
44
|
+
if (keep.length === 0) return "nothing";
|
|
45
|
+
shown.clear();
|
|
46
|
+
lastId = null;
|
|
47
|
+
planned.value = keep;
|
|
48
|
+
index.value = 0;
|
|
49
|
+
target.value = null;
|
|
50
|
+
running.value = true;
|
|
51
|
+
return show(0);
|
|
52
|
+
}
|
|
53
|
+
/** Shows the step at `at`, or the next one that can show. */
|
|
54
|
+
async function show(at) {
|
|
55
|
+
const mine = ++turn;
|
|
56
|
+
while (at < planned.value.length) {
|
|
57
|
+
const item = planned.value[at];
|
|
58
|
+
const found = await reach(item);
|
|
59
|
+
if (mine !== turn) return "stale";
|
|
60
|
+
if (found !== null) {
|
|
61
|
+
index.value = at;
|
|
62
|
+
target.value = found ?? null;
|
|
63
|
+
shown.add(item.id);
|
|
64
|
+
lastId = item.id;
|
|
65
|
+
options.onShow?.(at, item, planned.value.length);
|
|
66
|
+
return "shown";
|
|
67
|
+
}
|
|
68
|
+
planned.value = planned.value.filter((_, each) => each !== at);
|
|
69
|
+
}
|
|
70
|
+
return "empty";
|
|
71
|
+
}
|
|
72
|
+
/** The next step; `empty` after the last (the tour is done). */
|
|
73
|
+
function next() {
|
|
74
|
+
return index.value >= planned.value.length - 1 ? Promise.resolve("empty") : show(index.value + 1);
|
|
75
|
+
}
|
|
76
|
+
/** The step before, if there is one. */
|
|
77
|
+
function back() {
|
|
78
|
+
return index.value > 0 ? show(index.value - 1) : Promise.resolve("stale");
|
|
79
|
+
}
|
|
80
|
+
/** Ends the tour and cancels any move still waiting; what it showed, or null when none was running. */
|
|
81
|
+
function stop() {
|
|
82
|
+
turn++;
|
|
83
|
+
if (!running.value) return null;
|
|
84
|
+
running.value = false;
|
|
85
|
+
planned.value = [];
|
|
86
|
+
target.value = null;
|
|
87
|
+
return {
|
|
88
|
+
shown: shown.size,
|
|
89
|
+
lastId
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
running,
|
|
94
|
+
step,
|
|
95
|
+
index,
|
|
96
|
+
total,
|
|
97
|
+
target,
|
|
98
|
+
start,
|
|
99
|
+
show,
|
|
100
|
+
next,
|
|
101
|
+
back,
|
|
102
|
+
stop
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
exports.useTourSteps = useTourSteps;
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=useTourSteps.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTourSteps.cjs","names":[],"sources":["../../../../src/components/feedback/tour/useTourSteps.ts"],"sourcesContent":["import { computed, ref, shallowRef } from \"vue\";\nimport type { TourItem } from \"../../../interfaces/feedback/Tour.interface\";\n\nexport interface TourStepsOptions {\n /** The steps as the app gave them, asked each time a tour starts. */\n steps: () => TourItem[];\n /** The element of a step that has a target, once it shows; null when it never does. */\n locate: (item: TourItem) => Promise<HTMLElement | null>;\n /** A step is on screen. `total` is how many will show, which falls when a step turns out not to. */\n onShow?: (at: number, item: TourItem, total: number) => void;\n}\n\n/** `shown`: a step is up. `stale`: a newer move won. `empty`: no step is left to show. `nothing`: no step could show, so the tour never began. */\nexport type TourMove = \"shown\" | \"stale\" | \"empty\" | \"nothing\";\n\n/** A step's `when`; one that throws says no. */\nfunction allowed(item: TourItem): boolean {\n try {\n return item.when ? item.when() === true : true;\n } catch {\n return false;\n }\n}\n\n/**\n * The machine of a tour, with no screen in it. `start` keeps the steps that can show (their `when`, and for a step with no `before` a\n * target that is there after a short wait), `next` and `back` show one at a time and drop a step that cannot show when its turn\n * comes, and `stop` ends it. A newer move wins over one still waiting for its target, and a tour with nothing to show does not begin.\n */\nexport function useTourSteps(options: TourStepsOptions) {\n const running = ref(false);\n const planned = shallowRef<TourItem[]>([]);\n const index = ref(0);\n const target = shallowRef<HTMLElement | null>(null);\n const step = computed(() => (running.value ? (planned.value[index.value] ?? null) : null));\n const total = computed(() => planned.value.length);\n const shown = new Set<string>();\n let lastId: string | null = null;\n let turn = 0;\n\n /** Runs a step's `before`, then finds its target: the element, undefined for a card with no target, null when it cannot show. */\n async function reach(item: TourItem): Promise<HTMLElement | undefined | null> {\n try {\n await item.before?.();\n } catch {\n return null;\n }\n return item.target === undefined ? undefined : options.locate(item);\n }\n\n /** Starts a tour; `stale` when one is running or a newer call came first. */\n async function start(): Promise<TourMove> {\n if (running.value) return \"stale\";\n const mine = ++turn;\n const candidates = options.steps().filter(allowed);\n const present = await Promise.all(candidates.map((each) => (each.target !== undefined && !each.before ? options.locate(each) : Promise.resolve(true))));\n const keep = candidates.filter((_, at) => present[at] !== null);\n if (mine !== turn || running.value) return \"stale\";\n if (keep.length === 0) return \"nothing\";\n shown.clear();\n lastId = null;\n planned.value = keep;\n index.value = 0;\n target.value = null;\n running.value = true;\n return show(0);\n }\n\n /** Shows the step at `at`, or the next one that can show. */\n async function show(at: number): Promise<TourMove> {\n const mine = ++turn;\n while (at < planned.value.length) {\n const item = planned.value[at]!;\n const found = await reach(item);\n if (mine !== turn) return \"stale\";\n if (found !== null) {\n index.value = at;\n target.value = found ?? null;\n shown.add(item.id);\n lastId = item.id;\n options.onShow?.(at, item, planned.value.length);\n return \"shown\";\n }\n planned.value = planned.value.filter((_, each) => each !== at);\n }\n return \"empty\";\n }\n\n /** The next step; `empty` after the last (the tour is done). */\n function next(): Promise<TourMove> {\n return index.value >= planned.value.length - 1 ? Promise.resolve(\"empty\") : show(index.value + 1);\n }\n\n /** The step before, if there is one. */\n function back(): Promise<TourMove> {\n return index.value > 0 ? show(index.value - 1) : Promise.resolve(\"stale\");\n }\n\n /** Ends the tour and cancels any move still waiting; what it showed, or null when none was running. */\n function stop(): { shown: number; lastId: string | null } | null {\n turn++;\n if (!running.value) return null;\n running.value = false;\n planned.value = [];\n target.value = null;\n return { shown: shown.size, lastId };\n }\n\n return { running, step, index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,QAAQ;EACf,QAAQ,QAAQ;EAChB,OAAO,KAAK,EAAE;;;CAIhB,eAAe,KAAK,IAA+B;EACjD,MAAM,OAAO,EAAE;EACf,OAAO,KAAK,QAAQ,MAAM,QAAQ;GAChC,MAAM,OAAO,QAAQ,MAAM;GAC3B,MAAM,QAAQ,MAAM,MAAM,KAAK;GAC/B,IAAI,SAAS,MAAM,OAAO;GAC1B,IAAI,UAAU,MAAM;IAClB,MAAM,QAAQ;IACd,OAAO,QAAQ,SAAS;IACxB,MAAM,IAAI,KAAK,GAAG;IAClB,SAAS,KAAK;IACd,QAAQ,SAAS,IAAI,MAAM,QAAQ,MAAM,OAAO;IAChD,OAAO;;GAET,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,GAAG,SAAS,SAAS,GAAG;;EAEhE,OAAO;;;CAIT,SAAS,OAA0B;EACjC,OAAO,MAAM,SAAS,QAAQ,MAAM,SAAS,IAAI,QAAQ,QAAQ,QAAQ,GAAG,KAAK,MAAM,QAAQ,EAAE;;;CAInG,SAAS,OAA0B;EACjC,OAAO,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,EAAE,GAAG,QAAQ,QAAQ,QAAQ;;;CAI3E,SAAS,OAAwD;EAC/D;EACA,IAAI,CAAC,QAAQ,OAAO,OAAO;EAC3B,QAAQ,QAAQ;EAChB,QAAQ,QAAQ,EAAE;EAClB,OAAO,QAAQ;EACf,OAAO;GAAE,OAAO,MAAM;GAAM;GAAQ;;CAGtC,OAAO;EAAE;EAAS;EAAM;EAAO;EAAO;EAAQ;EAAO;EAAM;EAAM;EAAM;EAAM"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { computed, ref, shallowRef } from "vue";
|
|
2
|
+
//#region src/components/feedback/tour/useTourSteps.ts
|
|
3
|
+
/** A step's `when`; one that throws says no. */
|
|
4
|
+
function allowed(item) {
|
|
5
|
+
try {
|
|
6
|
+
return item.when ? item.when() === true : true;
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The machine of a tour, with no screen in it. `start` keeps the steps that can show (their `when`, and for a step with no `before` a
|
|
13
|
+
* target that is there after a short wait), `next` and `back` show one at a time and drop a step that cannot show when its turn
|
|
14
|
+
* comes, and `stop` ends it. A newer move wins over one still waiting for its target, and a tour with nothing to show does not begin.
|
|
15
|
+
*/
|
|
16
|
+
function useTourSteps(options) {
|
|
17
|
+
const running = ref(false);
|
|
18
|
+
const planned = shallowRef([]);
|
|
19
|
+
const index = ref(0);
|
|
20
|
+
const target = shallowRef(null);
|
|
21
|
+
const step = computed(() => running.value ? planned.value[index.value] ?? null : null);
|
|
22
|
+
const total = computed(() => planned.value.length);
|
|
23
|
+
const shown = /* @__PURE__ */ new Set();
|
|
24
|
+
let lastId = null;
|
|
25
|
+
let turn = 0;
|
|
26
|
+
/** Runs a step's `before`, then finds its target: the element, undefined for a card with no target, null when it cannot show. */
|
|
27
|
+
async function reach(item) {
|
|
28
|
+
try {
|
|
29
|
+
await item.before?.();
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return item.target === void 0 ? void 0 : options.locate(item);
|
|
34
|
+
}
|
|
35
|
+
/** Starts a tour; `stale` when one is running or a newer call came first. */
|
|
36
|
+
async function start() {
|
|
37
|
+
if (running.value) return "stale";
|
|
38
|
+
const mine = ++turn;
|
|
39
|
+
const candidates = options.steps().filter(allowed);
|
|
40
|
+
const present = await Promise.all(candidates.map((each) => each.target !== void 0 && !each.before ? options.locate(each) : Promise.resolve(true)));
|
|
41
|
+
const keep = candidates.filter((_, at) => present[at] !== null);
|
|
42
|
+
if (mine !== turn || running.value) return "stale";
|
|
43
|
+
if (keep.length === 0) return "nothing";
|
|
44
|
+
shown.clear();
|
|
45
|
+
lastId = null;
|
|
46
|
+
planned.value = keep;
|
|
47
|
+
index.value = 0;
|
|
48
|
+
target.value = null;
|
|
49
|
+
running.value = true;
|
|
50
|
+
return show(0);
|
|
51
|
+
}
|
|
52
|
+
/** Shows the step at `at`, or the next one that can show. */
|
|
53
|
+
async function show(at) {
|
|
54
|
+
const mine = ++turn;
|
|
55
|
+
while (at < planned.value.length) {
|
|
56
|
+
const item = planned.value[at];
|
|
57
|
+
const found = await reach(item);
|
|
58
|
+
if (mine !== turn) return "stale";
|
|
59
|
+
if (found !== null) {
|
|
60
|
+
index.value = at;
|
|
61
|
+
target.value = found ?? null;
|
|
62
|
+
shown.add(item.id);
|
|
63
|
+
lastId = item.id;
|
|
64
|
+
options.onShow?.(at, item, planned.value.length);
|
|
65
|
+
return "shown";
|
|
66
|
+
}
|
|
67
|
+
planned.value = planned.value.filter((_, each) => each !== at);
|
|
68
|
+
}
|
|
69
|
+
return "empty";
|
|
70
|
+
}
|
|
71
|
+
/** The next step; `empty` after the last (the tour is done). */
|
|
72
|
+
function next() {
|
|
73
|
+
return index.value >= planned.value.length - 1 ? Promise.resolve("empty") : show(index.value + 1);
|
|
74
|
+
}
|
|
75
|
+
/** The step before, if there is one. */
|
|
76
|
+
function back() {
|
|
77
|
+
return index.value > 0 ? show(index.value - 1) : Promise.resolve("stale");
|
|
78
|
+
}
|
|
79
|
+
/** Ends the tour and cancels any move still waiting; what it showed, or null when none was running. */
|
|
80
|
+
function stop() {
|
|
81
|
+
turn++;
|
|
82
|
+
if (!running.value) return null;
|
|
83
|
+
running.value = false;
|
|
84
|
+
planned.value = [];
|
|
85
|
+
target.value = null;
|
|
86
|
+
return {
|
|
87
|
+
shown: shown.size,
|
|
88
|
+
lastId
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
running,
|
|
93
|
+
step,
|
|
94
|
+
index,
|
|
95
|
+
total,
|
|
96
|
+
target,
|
|
97
|
+
start,
|
|
98
|
+
show,
|
|
99
|
+
next,
|
|
100
|
+
back,
|
|
101
|
+
stop
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { useTourSteps };
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=useTourSteps.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTourSteps.mjs","names":[],"sources":["../../../../src/components/feedback/tour/useTourSteps.ts"],"sourcesContent":["import { computed, ref, shallowRef } from \"vue\";\nimport type { TourItem } from \"../../../interfaces/feedback/Tour.interface\";\n\nexport interface TourStepsOptions {\n /** The steps as the app gave them, asked each time a tour starts. */\n steps: () => TourItem[];\n /** The element of a step that has a target, once it shows; null when it never does. */\n locate: (item: TourItem) => Promise<HTMLElement | null>;\n /** A step is on screen. `total` is how many will show, which falls when a step turns out not to. */\n onShow?: (at: number, item: TourItem, total: number) => void;\n}\n\n/** `shown`: a step is up. `stale`: a newer move won. `empty`: no step is left to show. `nothing`: no step could show, so the tour never began. */\nexport type TourMove = \"shown\" | \"stale\" | \"empty\" | \"nothing\";\n\n/** A step's `when`; one that throws says no. */\nfunction allowed(item: TourItem): boolean {\n try {\n return item.when ? item.when() === true : true;\n } catch {\n return false;\n }\n}\n\n/**\n * The machine of a tour, with no screen in it. `start` keeps the steps that can show (their `when`, and for a step with no `before` a\n * target that is there after a short wait), `next` and `back` show one at a time and drop a step that cannot show when its turn\n * comes, and `stop` ends it. A newer move wins over one still waiting for its target, and a tour with nothing to show does not begin.\n */\nexport function useTourSteps(options: TourStepsOptions) {\n const running = ref(false);\n const planned = shallowRef<TourItem[]>([]);\n const index = ref(0);\n const target = shallowRef<HTMLElement | null>(null);\n const step = computed(() => (running.value ? (planned.value[index.value] ?? null) : null));\n const total = computed(() => planned.value.length);\n const shown = new Set<string>();\n let lastId: string | null = null;\n let turn = 0;\n\n /** Runs a step's `before`, then finds its target: the element, undefined for a card with no target, null when it cannot show. */\n async function reach(item: TourItem): Promise<HTMLElement | undefined | null> {\n try {\n await item.before?.();\n } catch {\n return null;\n }\n return item.target === undefined ? undefined : options.locate(item);\n }\n\n /** Starts a tour; `stale` when one is running or a newer call came first. */\n async function start(): Promise<TourMove> {\n if (running.value) return \"stale\";\n const mine = ++turn;\n const candidates = options.steps().filter(allowed);\n const present = await Promise.all(candidates.map((each) => (each.target !== undefined && !each.before ? options.locate(each) : Promise.resolve(true))));\n const keep = candidates.filter((_, at) => present[at] !== null);\n if (mine !== turn || running.value) return \"stale\";\n if (keep.length === 0) return \"nothing\";\n shown.clear();\n lastId = null;\n planned.value = keep;\n index.value = 0;\n target.value = null;\n running.value = true;\n return show(0);\n }\n\n /** Shows the step at `at`, or the next one that can show. */\n async function show(at: number): Promise<TourMove> {\n const mine = ++turn;\n while (at < planned.value.length) {\n const item = planned.value[at]!;\n const found = await reach(item);\n if (mine !== turn) return \"stale\";\n if (found !== null) {\n index.value = at;\n target.value = found ?? null;\n shown.add(item.id);\n lastId = item.id;\n options.onShow?.(at, item, planned.value.length);\n return \"shown\";\n }\n planned.value = planned.value.filter((_, each) => each !== at);\n }\n return \"empty\";\n }\n\n /** The next step; `empty` after the last (the tour is done). */\n function next(): Promise<TourMove> {\n return index.value >= planned.value.length - 1 ? Promise.resolve(\"empty\") : show(index.value + 1);\n }\n\n /** The step before, if there is one. */\n function back(): Promise<TourMove> {\n return index.value > 0 ? show(index.value - 1) : Promise.resolve(\"stale\");\n }\n\n /** Ends the tour and cancels any move still waiting; what it showed, or null when none was running. */\n function stop(): { shown: number; lastId: string | null } | null {\n turn++;\n if (!running.value) return null;\n running.value = false;\n planned.value = [];\n target.value = null;\n return { shown: shown.size, lastId };\n }\n\n return { running, step, index, total, target, start, show, next, back, stop };\n}\n"],"mappings":";;;AAgBA,SAAS,QAAQ,MAAyB;CACxC,IAAI;EACF,OAAO,KAAK,OAAO,KAAK,MAAM,KAAK,OAAO;SACpC;EACN,OAAO;;;;;;;;AASX,SAAgB,aAAa,SAA2B;CACtD,MAAM,UAAU,IAAI,MAAM;CAC1B,MAAM,UAAU,WAAuB,EAAE,CAAC;CAC1C,MAAM,QAAQ,IAAI,EAAE;CACpB,MAAM,SAAS,WAA+B,KAA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AAI,MAAM,QAAQ,MAAM,OAAO;IAChD,OAAO;;GAET,QAAQ,QAAQ,QAAQ,MAAM,QAAQ,GAAG,SAAS,SAAS,GAAG;;EAEhE,OAAO;;;CAIT,SAAS,OAA0B;EACjC,OAAO,MAAM,SAAS,QAAQ,MAAM,SAAS,IAAI,QAAQ,QAAQ,QAAQ,GAAG,KAAK,MAAM,QAAQ,EAAE;;;CAInG,SAAS,OAA0B;EACjC,OAAO,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,EAAE,GAAG,QAAQ,QAAQ,QAAQ;;;CAI3E,SAAS,OAAwD;EAC/D;EACA,IAAI,CAAC,QAAQ,OAAO,OAAO;EAC3B,QAAQ,QAAQ;EAChB,QAAQ,QAAQ,EAAE;EAClB,OAAO,QAAQ;EACf,OAAO;GAAE,OAAO,MAAM;GAAM;GAAQ;;CAGtC,OAAO;EAAE;EAAS;EAAM;EAAO;EAAO;EAAQ;EAAO;EAAM;EAAM;EAAM;EAAM"}
|
|
@@ -2,7 +2,7 @@ const require__plugin_vue_export_helper = require("../../_virtual/_plugin-vue_ex
|
|
|
2
2
|
const require_Button_vue_vue_type_script_setup_true_lang = require("./Button.vue_vue_type_script_setup_true_lang.cjs");
|
|
3
3
|
;/* empty css */
|
|
4
4
|
//#region src/components/forms/Button.vue
|
|
5
|
-
var Button_default = /* @__PURE__ */ require__plugin_vue_export_helper.default(require_Button_vue_vue_type_script_setup_true_lang.default, [["__scopeId", "data-v-
|
|
5
|
+
var Button_default = /* @__PURE__ */ require__plugin_vue_export_helper.default(require_Button_vue_vue_type_script_setup_true_lang.default, [["__scopeId", "data-v-2410a1f6"]]);
|
|
6
6
|
//#endregion
|
|
7
7
|
exports.default = Button_default;
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.cjs","names":[],"sources":["../../../src/components/forms/Button.vue"],"sourcesContent":["<template>\n <!-- Skeleton placeholder — mirrors the real button's footprint (size, \n radius, fullWidth). Useful for action rows that load after the \n page paints. -->\n <Skeleton\n v-if=\"skeleton\"\n shape=\"button\"\n :size=\"forwardSize\"\n :radius=\"radius\"\n :fullWidth=\"fullWidth\"\n />\n\n <component\n :is=\"rootTag\"\n v-else\n :type=\"isLink ? undefined : type\"\n :href=\"linkHref\"\n :target=\"isLink ? target : undefined\"\n :rel=\"isLink ? rel : undefined\"\n :disabled=\"isLink ? undefined : isDisabled || loading\"\n :aria-disabled=\"isLink && isEffectivelyDisabled ? 'true' : undefined\"\n :tabindex=\"isLink && isEffectivelyDisabled ? -1 : undefined\"\n :aria-busy=\"loading || undefined\"\n :aria-label=\"resolvedAriaLabel\"\n :class=\"[\n baseClasses,\n variantClasses,\n colorClasses,\n haloClasses,\n sizeClasses,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isLink && isEffectivelyDisabled\n ? 'opacity-40 pointer-events-none cursor-not-allowed'\n : '',\n ]\"\n >\n <Loader\n v-if=\"loading && iconPosition === 'left'\"\n :variant=\"variant\"\n :size=\"forwardSize\"\n />\n <component\n :is=\"icon\"\n v-if=\"icon && !loading && iconPosition === 'left'\"\n :class=\"iconSizeClasses\"\n />\n\n <template v-if=\"loading\">{{\n loadingText || label || \"Loading...\"\n }}</template>\n <template v-else>\n <slot>{{ label }}</slot>\n </template>\n <Loader\n v-if=\"loading && iconPosition === 'right'\"\n :variant=\"variant\"\n :size=\"forwardSize\"\n />\n <component\n :is=\"icon\"\n v-if=\"icon && !loading && iconPosition === 'right'\"\n :class=\"iconSizeClasses\"\n />\n </component>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, inject, useSlots } from \"vue\";\nimport type { Button } from \"../../interfaces/forms/Button.interface\";\nimport type { ModoSize } from \"../../config/ModoConfig\";\nimport {\n useResolvedColor,\n useResolvedHalo,\n useResolvedRadius,\n useModoConfig,\n useSizeTokens,\n} from \"../../composables/useModoConfig\";\nimport { CONTROL_FOCUS_RING } from \"../../composables/useField\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\n\nconst groupProps = inject<{\n variant?: string;\n color?: string;\n size?: string;\n radius?: string;\n disabled?: boolean;\n gradient?: boolean;\n fullWidth?: boolean;\n}>(\"buttonGroup\", {});\nconst isInGroup = computed(() => Object.keys(groupProps).length > 0);\n\nconst props = withDefaults(defineProps<Button>(), {\n disabled: false,\n loading: false,\n variant: \"normal\",\n color: \"default\",\n gradient: false,\n type: \"button\",\n as: \"button\",\n fullWidth: false,\n iconPosition: \"left\",\n skeleton: false,\n});\n\n// Render as a real anchor when `as=\"a\"` (navigation links). A `<button>` can't\n// carry `href`, and an `<a>` can't carry `type`/`disabled` — so we swap the root\n// tag and route the tag-specific attributes accordingly.\nconst isLink = computed(() => props.as === \"a\");\nconst isEffectivelyDisabled = computed(() => isDisabled.value || props.loading);\nconst rootTag = computed(() => (isLink.value ? \"a\" : \"button\"));\n// A disabled link drops its href (so it isn't navigable) and relies on\n// aria-disabled + pointer-events-none for the disabled affordance.\nconst linkHref = computed(() =>\n isLink.value && !isEffectivelyDisabled.value ? props.href : undefined,\n);\n\nconst variant = computed(\n () => (groupProps.variant as Button[\"variant\"]) ?? props.variant,\n);\nconst color = useResolvedColor(() => {\n // Child button can override group color when explicitly set\n if (props.color !== \"default\") return props.color;\n return (groupProps.color as Button[\"color\"]) ?? props.color;\n});\n// Inside a ButtonGroup the group's radius wins over the provider default\n// so all corners (including the buttons' outer ones) match.\nconst radius = useResolvedRadius(\n () => (groupProps.radius as Button[\"radius\"]) ?? props.radius,\n);\nconst halo = useResolvedHalo();\nconst cfg = useModoConfig();\nconst size = computed<Button[\"size\"]>(\n () =>\n (groupProps.size as Button[\"size\"]) ??\n props.size ??\n cfg?.value.size ??\n \"medium\",\n);\nconst sz = useSizeTokens(\n () => {\n const s = (groupProps.size as Button[\"size\"]) ?? props.size ?? cfg?.value.size ?? \"medium\";\n // normalizeSize handles the legacy 'xs' alias — cast to satisfy useSizeTokens signature\n return s === \"xs\" ? \"small\" : s as ModoSize;\n },\n);\n// Loader/Skeleton don't have an 'xs'/'xsmall' size — collapse to 'small' when\n// forwarding so the visual footprint of `<Button size=\"xs\" loading>` stays compact.\nconst forwardSize = computed<\"xsmall\" | \"small\" | \"medium\" | \"large\">(() =>\n size.value === \"xs\" ? \"small\" : (size.value as \"xsmall\" | \"small\" | \"medium\" | \"large\"),\n);\nconst isDisabled = computed(() => groupProps.disabled ?? props.disabled);\nconst gradient = computed(() => groupProps.gradient ?? props.gradient);\nconst fullWidth = computed(() => groupProps.fullWidth ?? props.fullWidth);\n\n// Accessible name resolution:\n// - explicit `ariaLabel` wins\n// - else fall back to visible `label`\n// - icon-only buttons without either will emit a dev warning so consumers notice\nconst slots = useSlots();\n\nconst resolvedAriaLabel = computed(() => {\n if (props.ariaLabel) return props.ariaLabel;\n if (props.label) return undefined; // visible text via prop\n if (slots.default) return undefined; // visible text via slot\n if (import.meta.env.DEV && props.icon) {\n console.warn(\n \"[mood-ui] <Button> is icon-only but has no `ariaLabel` — add one for screen readers.\",\n );\n }\n return undefined;\n});\n\nconst baseClasses =\n `${CONTROL_FOCUS_RING} transition-colors duration-300 ease-in-out inline-flex items-center justify-center gap-2 cursor-pointer disabled:cursor-not-allowed`;\n\nconst variantClasses = computed(() => {\n switch (variant.value) {\n case \"outline\":\n return \"border font-medium\";\n case \"ghost\":\n return \"font-medium\";\n case \"text\":\n return \"font-medium\";\n default:\n return \"font-medium\";\n }\n});\n\nconst haloClasses = computed(() => {\n // Persistent (idle) halo, opt-in via 'neutral'/'tinted'. The FOCUS ring is\n // handled uniformly by `baseClasses` (CONTROL_FOCUS_RING), so these maps only\n // describe the resting + hover ring — no per-component focus ring here.\n // Suppressed inside a ButtonGroup (adjacent buttons would overlap rings).\n if (isInGroup.value) return \"\";\n if (variant.value !== \"normal\" && variant.value !== \"outline\") return \"\";\n\n const haloMode = halo.value;\n\n // 'off' (default): no idle/hover halo. Focus still shows the unified ring.\n if (haloMode === \"off\") return \"\";\n\n // 'neutral': idle grey ring.\n if (haloMode === \"neutral\") {\n return \"ring-[3px] ring-foreground/10 hover:ring-foreground/15\";\n }\n\n // 'tinted' (legacy): idle ring tinted to the color.\n const map: Record<string, string> = {\n default: \"ring-[3px] ring-foreground/10 hover:ring-foreground/15\",\n primary: \"ring-[3px] ring-primary/15 hover:ring-primary/25\",\n danger: \"ring-[3px] ring-destructive/15 hover:ring-destructive/25\",\n success: \"ring-[3px] ring-success/15 hover:ring-success/25\",\n warning: \"ring-[3px] ring-warning/15 hover:ring-warning/25\",\n };\n return map[color.value] ?? map.default;\n});\n\nconst colorClasses = computed(() => {\n const isGradient = gradient.value;\n const map: Record<string, Record<string, string>> = {\n default: {\n normal: isGradient\n ? \"text-background bg-gradient-to-r from-foreground via-foreground/90 to-foreground/90 hover:from-foreground/90 hover:via-foreground/80 hover:to-foreground/80 active:from-foreground/80 active:via-foreground/70 active:to-foreground/70 disabled:opacity-40\"\n : \"text-background bg-foreground hover:bg-foreground/90 active:bg-foreground/80 disabled:opacity-40\",\n outline:\n \"border-border text-foreground hover:bg-muted active:bg-muted-hover disabled:text-muted-foreground disabled:border-border disabled:bg-muted/60\",\n ghost:\n \"text-foreground bg-muted hover:bg-muted-hover active:bg-accent-hover disabled:text-muted-foreground disabled:bg-muted/60\",\n text: \"text-foreground hover:bg-muted active:bg-muted-hover disabled:text-muted-foreground\",\n },\n primary: {\n normal: isGradient\n ? \"text-primary-foreground bg-gradient-to-r from-primary via-primary/90 to-primary/90 hover:from-primary-hover hover:via-primary-hover/90 hover:to-primary-hover/90 active:from-primary-active active:via-primary-active/90 active:to-primary-active/90 disabled:opacity-40\"\n : \"text-primary-foreground bg-primary hover:bg-primary-hover active:bg-primary-active disabled:opacity-40\",\n outline:\n \"border-primary/40 text-primary hover:bg-primary-subtle active:bg-primary/20 disabled:text-primary/50 disabled:border-primary/20 disabled:bg-primary/5\",\n ghost:\n \"text-primary bg-primary-subtle hover:bg-primary/20 active:bg-primary/25 disabled:text-primary/50 disabled:bg-primary/5\",\n text: \"text-primary hover:bg-primary-subtle active:bg-primary/20 disabled:text-primary/50\",\n },\n danger: {\n normal: isGradient\n ? \"text-destructive-foreground bg-gradient-to-r from-destructive via-destructive/90 to-destructive/90 hover:from-destructive-hover hover:via-destructive-hover/90 hover:to-destructive-hover/90 active:from-destructive-active active:via-destructive-active/90 active:to-destructive-active/90 disabled:opacity-40\"\n : \"text-destructive-foreground bg-destructive hover:bg-destructive-hover active:bg-destructive-active disabled:opacity-40\",\n outline:\n \"border-destructive/40 text-destructive hover:bg-destructive-subtle active:bg-destructive/20 disabled:text-destructive/50 disabled:border-destructive/20 disabled:bg-destructive/5\",\n ghost:\n \"text-destructive bg-destructive-subtle hover:bg-destructive/20 active:bg-destructive/25 disabled:text-destructive/50 disabled:bg-destructive/5\",\n text: \"text-destructive hover:bg-destructive-subtle active:bg-destructive/20 disabled:text-destructive/50\",\n },\n success: {\n normal: isGradient\n ? \"text-success-foreground bg-gradient-to-r from-success via-success/90 to-success/90 hover:from-success-hover hover:via-success-hover/90 hover:to-success-hover/90 active:from-success-active active:via-success-active/90 active:to-success-active/90 disabled:opacity-40\"\n : \"text-success-foreground bg-success hover:bg-success-hover active:bg-success-active disabled:opacity-40\",\n outline:\n \"border-success/40 text-success hover:bg-success-subtle active:bg-success/20 disabled:text-success/50 disabled:border-success/20 disabled:bg-success/5\",\n ghost:\n \"text-success bg-success-subtle hover:bg-success/20 active:bg-success/25 disabled:text-success/50 disabled:bg-success/5\",\n text: \"text-success hover:bg-success-subtle active:bg-success/20 disabled:text-success/50\",\n },\n warning: {\n normal: isGradient\n ? \"text-warning-foreground bg-gradient-to-r from-warning via-warning/90 to-warning/90 hover:from-warning-hover hover:via-warning-hover/90 hover:to-warning-hover/90 active:from-warning-active active:via-warning-active/90 active:to-warning-active/90 disabled:opacity-40\"\n : \"text-warning-foreground bg-warning hover:bg-warning-hover active:bg-warning-active disabled:opacity-40\",\n outline:\n \"border-warning/40 text-warning hover:bg-warning-subtle active:bg-warning/20 disabled:text-warning/50 disabled:border-warning/20 disabled:bg-warning/5\",\n ghost:\n \"text-warning bg-warning-subtle hover:bg-warning/20 active:bg-warning/25 disabled:text-warning/50 disabled:bg-warning/5\",\n text: \"text-warning hover:bg-warning-subtle active:bg-warning/20 disabled:text-warning/50\",\n },\n };\n return map[color.value]?.[variant.value] ?? map.default.normal;\n});\n\nconst sizeClasses = computed(() => {\n if (!props.label && !slots.default && props.icon) {\n // icon-only button: square, height = control height\n return `${sz.value.control} aspect-square justify-center ${sz.value.text}`;\n }\n // text button: fixed control height (the anchor) + horizontal padding from tokens\n return `${sz.value.control} ${sz.value.text} ${sz.value.padX}`;\n});\n\nconst radiusClasses = computed(() => {\n switch (radius.value) {\n case \"none\":\n return \"rounded-none\";\n case \"small\":\n return \"rounded-sm\";\n case \"large\":\n return \"rounded-lg\";\n case \"full\":\n return \"rounded-[999px]\";\n default:\n return \"rounded-md\";\n }\n});\n\nconst iconSizeClasses = computed(() => sz.value.icon);\n</script>\n\n<style scoped>\nbutton,\na {\n transition-property:\n background-color, border-color, color, box-shadow, --tw-ring-color,\n --tw-ring-shadow;\n transition-duration: 220ms;\n transition-timing-function: cubic-bezier(0.2, 0, 0, 1);\n}\n@media (prefers-reduced-motion: reduce) {\n button,\n a {\n transition: none;\n }\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Button.cjs","names":[],"sources":["../../../src/components/forms/Button.vue"],"sourcesContent":["<template>\n <!-- Skeleton placeholder — mirrors the real button's footprint (size, \n radius, fullWidth). Useful for action rows that load after the \n page paints. -->\n <Skeleton\n v-if=\"skeleton\"\n shape=\"button\"\n :size=\"forwardSize\"\n :radius=\"radius\"\n :fullWidth=\"fullWidth\"\n />\n\n <component\n :is=\"rootTag\"\n v-else\n :type=\"isLink ? undefined : type\"\n :href=\"linkHref\"\n :target=\"isLink ? target : undefined\"\n :rel=\"isLink ? rel : undefined\"\n :disabled=\"isLink ? undefined : isDisabled || loading\"\n :aria-disabled=\"isLink && isEffectivelyDisabled ? 'true' : undefined\"\n :tabindex=\"isLink && isEffectivelyDisabled ? -1 : undefined\"\n :aria-busy=\"loading || undefined\"\n :aria-label=\"resolvedAriaLabel\"\n :class=\"[\n baseClasses,\n variantClasses,\n colorClasses,\n haloClasses,\n sizeClasses,\n radiusClasses,\n fullWidth ? 'w-full' : '',\n isLink && isEffectivelyDisabled\n ? 'opacity-40 pointer-events-none cursor-not-allowed'\n : '',\n ]\"\n >\n <Loader\n v-if=\"loading && iconPosition === 'left'\"\n :variant=\"variant\"\n :size=\"forwardSize\"\n />\n <component\n :is=\"icon\"\n v-if=\"icon && !loading && iconPosition === 'left'\"\n :class=\"iconSizeClasses\"\n />\n\n <template v-if=\"loading\">{{\n loadingText || label || \"Loading...\"\n }}</template>\n <template v-else>\n <slot>{{ label }}</slot>\n </template>\n <Loader\n v-if=\"loading && iconPosition === 'right'\"\n :variant=\"variant\"\n :size=\"forwardSize\"\n />\n <component\n :is=\"icon\"\n v-if=\"icon && !loading && iconPosition === 'right'\"\n :class=\"iconSizeClasses\"\n />\n </component>\n</template>\n\n<script setup lang=\"ts\">\nimport { computed, inject, useSlots } from \"vue\";\nimport type { Button } from \"../../interfaces/forms/Button.interface\";\nimport type { ModoSize } from \"../../config/ModoConfig\";\nimport {\n useResolvedColor,\n useResolvedHalo,\n useResolvedRadius,\n useModoConfig,\n useSizeTokens,\n} from \"../../composables/useModoConfig\";\nimport { CONTROL_FOCUS_RING } from \"../../composables/useField\";\nimport Loader from \"../feedback/Loader.vue\";\nimport Skeleton from \"../feedback/Skeleton.vue\";\n\nconst groupProps = inject<{\n variant?: string;\n color?: string;\n size?: string;\n radius?: string;\n disabled?: boolean;\n gradient?: boolean;\n fullWidth?: boolean;\n}>(\"buttonGroup\", {});\nconst isInGroup = computed(() => Object.keys(groupProps).length > 0);\n\nconst props = withDefaults(defineProps<Button>(), {\n disabled: false,\n loading: false,\n variant: \"normal\",\n color: \"default\",\n gradient: false,\n type: \"button\",\n as: \"button\",\n fullWidth: false,\n iconPosition: \"left\",\n skeleton: false,\n});\n\n// Render as a real anchor when `as=\"a\"` (navigation links). A `<button>` can't\n// carry `href`, and an `<a>` can't carry `type`/`disabled` — so we swap the root\n// tag and route the tag-specific attributes accordingly.\nconst isLink = computed(() => props.as === \"a\");\nconst isEffectivelyDisabled = computed(() => isDisabled.value || props.loading);\nconst rootTag = computed(() => (isLink.value ? \"a\" : \"button\"));\n// A disabled link drops its href (so it isn't navigable) and relies on\n// aria-disabled + pointer-events-none for the disabled affordance.\nconst linkHref = computed(() =>\n isLink.value && !isEffectivelyDisabled.value ? props.href : undefined,\n);\n\nconst variant = computed(\n () => (groupProps.variant as Button[\"variant\"]) ?? props.variant,\n);\nconst color = useResolvedColor(() => {\n // Child button can override group color when explicitly set\n if (props.color !== \"default\") return props.color;\n return (groupProps.color as Button[\"color\"]) ?? props.color;\n});\n// Inside a ButtonGroup the group's radius wins over the provider default\n// so all corners (including the buttons' outer ones) match.\nconst radius = useResolvedRadius(\n () => (groupProps.radius as Button[\"radius\"]) ?? props.radius,\n);\nconst halo = useResolvedHalo();\nconst cfg = useModoConfig();\nconst size = computed<Button[\"size\"]>(\n () =>\n (groupProps.size as Button[\"size\"]) ??\n props.size ??\n cfg?.value.size ??\n \"medium\",\n);\nconst sz = useSizeTokens(\n () => {\n const s = (groupProps.size as Button[\"size\"]) ?? props.size ?? cfg?.value.size ?? \"medium\";\n // normalizeSize handles the legacy 'xs' alias — cast to satisfy useSizeTokens signature\n return s === \"xs\" ? \"small\" : s as ModoSize;\n },\n);\n// Loader/Skeleton don't have an 'xs'/'xsmall' size — collapse to 'small' when\n// forwarding so the visual footprint of `<Button size=\"xs\" loading>` stays compact.\nconst forwardSize = computed<\"xsmall\" | \"small\" | \"medium\" | \"large\">(() =>\n size.value === \"xs\" ? \"small\" : (size.value as \"xsmall\" | \"small\" | \"medium\" | \"large\"),\n);\nconst isDisabled = computed(() => groupProps.disabled ?? props.disabled);\nconst gradient = computed(() => groupProps.gradient ?? props.gradient);\nconst fullWidth = computed(() => groupProps.fullWidth ?? props.fullWidth);\n\n// Accessible name resolution:\n// - explicit `ariaLabel` wins\n// - else fall back to visible `label`\n// - icon-only buttons without either will emit a dev warning so consumers notice\nconst slots = useSlots();\n\nconst resolvedAriaLabel = computed(() => {\n if (props.ariaLabel) return props.ariaLabel;\n if (props.label) return undefined; // visible text via prop\n if (slots.default) return undefined; // visible text via slot\n if (import.meta.env.DEV && props.icon) {\n console.warn(\n \"[mood-ui] <Button> is icon-only but has no `ariaLabel` — add one for screen readers.\",\n );\n }\n return undefined;\n});\n\nconst baseClasses =\n `${CONTROL_FOCUS_RING} transition-colors duration-300 ease-in-out inline-flex items-center justify-center gap-2 cursor-pointer disabled:cursor-not-allowed`;\n\nconst variantClasses = computed(() => {\n switch (variant.value) {\n case \"outline\":\n return \"border font-medium\";\n case \"ghost\":\n return \"font-medium\";\n case \"text\":\n return \"font-medium\";\n default:\n return \"font-medium\";\n }\n});\n\nconst haloClasses = computed(() => {\n // Persistent (idle) halo, opt-in via 'neutral'/'tinted'. The FOCUS ring is\n // handled uniformly by `baseClasses` (CONTROL_FOCUS_RING), so these maps only\n // describe the resting + hover ring — no per-component focus ring here.\n // Suppressed inside a ButtonGroup (adjacent buttons would overlap rings).\n if (isInGroup.value) return \"\";\n if (variant.value !== \"normal\" && variant.value !== \"outline\") return \"\";\n\n const haloMode = halo.value;\n\n // 'off' (default): no idle/hover halo. Focus still shows the unified ring.\n if (haloMode === \"off\") return \"\";\n\n // 'neutral': idle grey ring.\n if (haloMode === \"neutral\") {\n return \"ring-[3px] ring-foreground/10 hover:ring-foreground/15\";\n }\n\n // 'tinted' (legacy): idle ring tinted to the color.\n const map: Record<string, string> = {\n default: \"ring-[3px] ring-foreground/10 hover:ring-foreground/15\",\n primary: \"ring-[3px] ring-primary/15 hover:ring-primary/25\",\n danger: \"ring-[3px] ring-destructive/15 hover:ring-destructive/25\",\n success: \"ring-[3px] ring-success/15 hover:ring-success/25\",\n warning: \"ring-[3px] ring-warning/15 hover:ring-warning/25\",\n };\n return map[color.value] ?? map.default;\n});\n\nconst colorClasses = computed(() => {\n const isGradient = gradient.value;\n const map: Record<string, Record<string, string>> = {\n default: {\n normal: isGradient\n ? \"text-background bg-gradient-to-r from-foreground via-foreground/90 to-foreground/90 hover:from-foreground/90 hover:via-foreground/80 hover:to-foreground/80 active:from-foreground/80 active:via-foreground/70 active:to-foreground/70 disabled:opacity-40\"\n : \"text-background bg-foreground hover:bg-foreground/90 active:bg-foreground/80 disabled:opacity-40\",\n outline:\n \"border-input hover:border-input-hover text-foreground hover:bg-muted active:bg-muted-hover disabled:text-muted-foreground disabled:border-input disabled:bg-muted/60\",\n ghost:\n \"text-foreground bg-muted hover:bg-muted-hover active:bg-accent-hover disabled:text-muted-foreground disabled:bg-muted/60\",\n text: \"text-foreground hover:bg-muted active:bg-muted-hover disabled:text-muted-foreground\",\n },\n primary: {\n normal: isGradient\n ? \"text-primary-foreground bg-gradient-to-r from-primary via-primary/90 to-primary/90 hover:from-primary-hover hover:via-primary-hover/90 hover:to-primary-hover/90 active:from-primary-active active:via-primary-active/90 active:to-primary-active/90 disabled:opacity-40\"\n : \"text-primary-foreground bg-primary hover:bg-primary-hover active:bg-primary-active disabled:opacity-40\",\n outline:\n \"border-primary/40 text-primary hover:bg-primary-subtle active:bg-primary/20 disabled:text-primary/50 disabled:border-primary/20 disabled:bg-primary/5\",\n ghost:\n \"text-primary bg-primary-subtle hover:bg-primary/20 active:bg-primary/25 disabled:text-primary/50 disabled:bg-primary/5\",\n text: \"text-primary hover:bg-primary-subtle active:bg-primary/20 disabled:text-primary/50\",\n },\n danger: {\n normal: isGradient\n ? \"text-destructive-foreground bg-gradient-to-r from-destructive via-destructive/90 to-destructive/90 hover:from-destructive-hover hover:via-destructive-hover/90 hover:to-destructive-hover/90 active:from-destructive-active active:via-destructive-active/90 active:to-destructive-active/90 disabled:opacity-40\"\n : \"text-destructive-foreground bg-destructive hover:bg-destructive-hover active:bg-destructive-active disabled:opacity-40\",\n outline:\n \"border-destructive/40 text-destructive hover:bg-destructive-subtle active:bg-destructive/20 disabled:text-destructive/50 disabled:border-destructive/20 disabled:bg-destructive/5\",\n ghost:\n \"text-destructive bg-destructive-subtle hover:bg-destructive/20 active:bg-destructive/25 disabled:text-destructive/50 disabled:bg-destructive/5\",\n text: \"text-destructive hover:bg-destructive-subtle active:bg-destructive/20 disabled:text-destructive/50\",\n },\n success: {\n normal: isGradient\n ? \"text-success-foreground bg-gradient-to-r from-success via-success/90 to-success/90 hover:from-success-hover hover:via-success-hover/90 hover:to-success-hover/90 active:from-success-active active:via-success-active/90 active:to-success-active/90 disabled:opacity-40\"\n : \"text-success-foreground bg-success hover:bg-success-hover active:bg-success-active disabled:opacity-40\",\n outline:\n \"border-success/40 text-success hover:bg-success-subtle active:bg-success/20 disabled:text-success/50 disabled:border-success/20 disabled:bg-success/5\",\n ghost:\n \"text-success bg-success-subtle hover:bg-success/20 active:bg-success/25 disabled:text-success/50 disabled:bg-success/5\",\n text: \"text-success hover:bg-success-subtle active:bg-success/20 disabled:text-success/50\",\n },\n warning: {\n normal: isGradient\n ? \"text-warning-foreground bg-gradient-to-r from-warning via-warning/90 to-warning/90 hover:from-warning-hover hover:via-warning-hover/90 hover:to-warning-hover/90 active:from-warning-active active:via-warning-active/90 active:to-warning-active/90 disabled:opacity-40\"\n : \"text-warning-foreground bg-warning hover:bg-warning-hover active:bg-warning-active disabled:opacity-40\",\n outline:\n \"border-warning/40 text-warning hover:bg-warning-subtle active:bg-warning/20 disabled:text-warning/50 disabled:border-warning/20 disabled:bg-warning/5\",\n ghost:\n \"text-warning bg-warning-subtle hover:bg-warning/20 active:bg-warning/25 disabled:text-warning/50 disabled:bg-warning/5\",\n text: \"text-warning hover:bg-warning-subtle active:bg-warning/20 disabled:text-warning/50\",\n },\n };\n return map[color.value]?.[variant.value] ?? map.default.normal;\n});\n\nconst sizeClasses = computed(() => {\n if (!props.label && !slots.default && props.icon) {\n // icon-only button: square, height = control height\n return `${sz.value.control} aspect-square justify-center ${sz.value.text}`;\n }\n // text button: fixed control height (the anchor) + horizontal padding from tokens\n return `${sz.value.control} ${sz.value.text} ${sz.value.padX}`;\n});\n\nconst radiusClasses = computed(() => {\n switch (radius.value) {\n case \"none\":\n return \"rounded-none\";\n case \"small\":\n return \"rounded-sm\";\n case \"large\":\n return \"rounded-lg\";\n case \"full\":\n return \"rounded-[999px]\";\n default:\n return \"rounded-md\";\n }\n});\n\nconst iconSizeClasses = computed(() => sz.value.icon);\n</script>\n\n<style scoped>\nbutton,\na {\n transition-property:\n background-color, border-color, color, box-shadow, --tw-ring-color,\n --tw-ring-shadow;\n transition-duration: 220ms;\n transition-timing-function: cubic-bezier(0.2, 0, 0, 1);\n}\n@media (prefers-reduced-motion: reduce) {\n button,\n a {\n transition: none;\n }\n}\n</style>\n"],"mappings":""}
|