@dumiflex/wp-kit 0.0.0-stage → 0.4.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 (128) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +674 -0
  3. package/README.md +72 -2
  4. package/package.json +76 -4
  5. package/src/Avatar.vue +83 -0
  6. package/src/Badge.vue +97 -0
  7. package/src/Banner.vue +118 -0
  8. package/src/BookmarkButton.vue +27 -0
  9. package/src/BundleMeta.vue +51 -0
  10. package/src/Button.vue +103 -0
  11. package/src/Card.vue +68 -0
  12. package/src/Checkbox.vue +109 -0
  13. package/src/Chip.vue +163 -0
  14. package/src/ChoiceCards.vue +133 -0
  15. package/src/CloseButton.vue +69 -0
  16. package/src/CodeBlock.vue +119 -0
  17. package/src/ColorField.vue +188 -0
  18. package/src/ColorPicker.vue +201 -0
  19. package/src/Combobox.vue +331 -0
  20. package/src/ConfirmDialog.vue +165 -0
  21. package/src/ConfirmModal.vue +147 -0
  22. package/src/ConstraintMatrixPreview.vue +708 -0
  23. package/src/ContextMenu.vue +386 -0
  24. package/src/CopyButton.vue +156 -0
  25. package/src/DataTable.vue +292 -0
  26. package/src/DatePicker.vue +234 -0
  27. package/src/DescriptionList.vue +73 -0
  28. package/src/DiffView.vue +68 -0
  29. package/src/Disclosure.vue +166 -0
  30. package/src/DragHandle.vue +49 -0
  31. package/src/Drawer.vue +131 -0
  32. package/src/DropZone.vue +196 -0
  33. package/src/DropdownMenu.vue +72 -0
  34. package/src/EmptyState.vue +111 -0
  35. package/src/Field.vue +28 -0
  36. package/src/HsvPicker.vue +208 -0
  37. package/src/Icon.vue +39 -0
  38. package/src/IconPicker.vue +209 -0
  39. package/src/ImageGrid.vue +125 -0
  40. package/src/InlineEdit.vue +183 -0
  41. package/src/Input.vue +99 -0
  42. package/src/Kbd.vue +56 -0
  43. package/src/Lightbox.vue +173 -0
  44. package/src/ListFilter.vue +85 -0
  45. package/src/ListRow.vue +204 -0
  46. package/src/LoadingMark.vue +175 -0
  47. package/src/Logo.vue +60 -0
  48. package/src/Modal.vue +78 -0
  49. package/src/ModalShell.vue +109 -0
  50. package/src/Pagination.vue +106 -0
  51. package/src/Popover.vue +180 -0
  52. package/src/PostCard.vue +210 -0
  53. package/src/ProgressBar.vue +90 -0
  54. package/src/RadioGroup.vue +177 -0
  55. package/src/RangeSlider.vue +183 -0
  56. package/src/RelativeDate.vue +35 -0
  57. package/src/ResizeHandle.vue +143 -0
  58. package/src/SearchInput.vue +192 -0
  59. package/src/Select.vue +644 -0
  60. package/src/Separator.vue +54 -0
  61. package/src/Skeleton.vue +82 -0
  62. package/src/Slider.vue +198 -0
  63. package/src/SortableList.vue +260 -0
  64. package/src/SplitPane.vue +68 -0
  65. package/src/StarButton.vue +40 -0
  66. package/src/Stepper.vue +141 -0
  67. package/src/SupportLinks.vue +93 -0
  68. package/src/TagInput.vue +297 -0
  69. package/src/Textarea.vue +57 -0
  70. package/src/Timeline.vue +92 -0
  71. package/src/ToastCard.vue +119 -0
  72. package/src/ToastHost.vue +40 -0
  73. package/src/Toggle.vue +36 -0
  74. package/src/TokenizedValue.vue +310 -0
  75. package/src/Toolbar.vue +110 -0
  76. package/src/VirtualList.vue +87 -0
  77. package/src/VisuallyHidden.vue +29 -0
  78. package/src/WpButton.vue +75 -0
  79. package/src/WpCheck.vue +104 -0
  80. package/src/WpIconButton.vue +107 -0
  81. package/src/WpImageZoom.vue +544 -0
  82. package/src/WpNumber.vue +178 -0
  83. package/src/WpSegmented.vue +175 -0
  84. package/src/WpSelect.vue +93 -0
  85. package/src/WpSwitch.vue +163 -0
  86. package/src/WpTabs.vue +188 -0
  87. package/src/_modal-motion.css +33 -0
  88. package/src/_skeleton.css +50 -0
  89. package/src/axis-color.ts +42 -0
  90. package/src/button.css +169 -0
  91. package/src/calendar.ts +59 -0
  92. package/src/clipboard.ts +50 -0
  93. package/src/colour-presets.ts +12 -0
  94. package/src/diff.ts +51 -0
  95. package/src/drop-zone.ts +41 -0
  96. package/src/field.css +50 -0
  97. package/src/flip.ts +237 -0
  98. package/src/floating-layer.ts +48 -0
  99. package/src/floating.ts +99 -0
  100. package/src/hsv.ts +100 -0
  101. package/src/icon-catalog.ts +52 -0
  102. package/src/image-zoom.ts +93 -0
  103. package/src/kind-colour.ts +28 -0
  104. package/src/logo-paths.ts +21 -0
  105. package/src/matrix-axis.ts +91 -0
  106. package/src/pagination.ts +27 -0
  107. package/src/platform-keys.ts +29 -0
  108. package/src/rich-tokenize.ts +357 -0
  109. package/src/select-types.ts +32 -0
  110. package/src/slider-math.ts +45 -0
  111. package/src/sortable.ts +22 -0
  112. package/src/theme/fonts/OFL-Fraunces.txt +93 -0
  113. package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -0
  114. package/src/theme/fonts/OFL-Manrope.txt +93 -0
  115. package/src/theme/fonts/fraunces-latin-wght-normal.woff2 +0 -0
  116. package/src/theme/fonts/jetbrains-mono-latin.woff2 +0 -0
  117. package/src/theme/fonts/manrope-latin-wght-normal.woff2 +0 -0
  118. package/src/theme/looks.css +428 -0
  119. package/src/theme/palettes.css +254 -0
  120. package/src/theme/tokens.css +2896 -0
  121. package/src/tokens.ts +56 -0
  122. package/src/tooltip.css +43 -0
  123. package/src/tooltip.ts +146 -0
  124. package/src/useDialogFocus.ts +73 -0
  125. package/src/useGrowableField.ts +357 -0
  126. package/src/useModalKeyShield.ts +116 -0
  127. package/src/useToast.ts +48 -0
  128. package/src/wp-logo.svg +14 -0
@@ -0,0 +1,125 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A grid of image tiles that fills its width (tiles at least `min-size`
4
+ * wide). A click or Enter opens the image in a Lightbox, where ← / → step
5
+ * through the rest. With `selectable` each tile gets a check box in its
6
+ * corner and `v-model:selected` holds the picked ids.
7
+ *
8
+ * <ImageGrid :images="outputs" />
9
+ * <ImageGrid v-model:selected="keep" :images="frames" selectable :min-size="96" />
10
+ *
11
+ * Tiles are buttons in reading order (one Tab stop each); a tile with no
12
+ * `src` draws a Skeleton-like block while it loads.
13
+ */
14
+ import { computed, ref } from "vue";
15
+ import Lightbox from "./Lightbox.vue";
16
+ import WpCheck from "./WpCheck.vue";
17
+
18
+ export interface GridImage { id: string; src: string; alt: string; thumb?: string; caption?: string }
19
+
20
+ const props = withDefaults(defineProps<{
21
+ images: GridImage[];
22
+ /** Smallest tile width in px. */
23
+ minSize?: number | undefined;
24
+ /** Width / height of a tile. */
25
+ aspect?: number | undefined;
26
+ gap?: "sm" | "md" | undefined;
27
+ selectable?: boolean | undefined;
28
+ selected?: string[] | undefined;
29
+ /** Open the Lightbox on a click (off: emit `open` and do your own thing). */
30
+ lightbox?: boolean | undefined;
31
+ ariaLabel?: string | undefined;
32
+ }>(), { minSize: 120, aspect: 1, gap: "md", selectable: false, selected: () => [], lightbox: true, ariaLabel: "Images" });
33
+
34
+ const emit = defineEmits<{
35
+ (e: "update:selected", v: string[]): void;
36
+ (e: "open", index: number): void;
37
+ }>();
38
+
39
+ const open = ref(false);
40
+ const at = ref(0);
41
+ const shots = computed(() => props.images.map((i) => ({ src: i.src, alt: i.alt, caption: i.caption })));
42
+
43
+ function show(i: number): void {
44
+ emit("open", i);
45
+ if (!props.lightbox) return;
46
+ at.value = i;
47
+ open.value = true;
48
+ }
49
+
50
+ function toggle(id: string, on: boolean): void {
51
+ emit("update:selected", on ? [...props.selected, id] : props.selected.filter((x) => x !== id));
52
+ }
53
+ </script>
54
+
55
+ <template>
56
+ <div class="wp-image-grid">
57
+ <ul
58
+ class="wp-image-grid__list"
59
+ :data-gap="gap"
60
+ :aria-label="ariaLabel"
61
+ :style="{ '--_min': `${minSize}px`, '--_aspect': String(aspect) }"
62
+ >
63
+ <li
64
+ v-for="(img, i) in images"
65
+ :key="img.id"
66
+ class="wp-image-grid__tile"
67
+ :data-selected="(selectable && props.selected.includes(img.id)) || undefined"
68
+ >
69
+ <button
70
+ type="button"
71
+ class="wp-image-grid__open"
72
+ :aria-label="selectable ? `Open ${img.alt}` : img.alt"
73
+ @click="show(i)"
74
+ >
75
+ <img v-if="img.thumb || img.src" class="wp-image-grid__img" :src="img.thumb || img.src" alt="" loading="lazy">
76
+ <span v-else class="wp-image-grid__empty" aria-hidden="true" />
77
+ </button>
78
+ <WpCheck
79
+ v-if="selectable"
80
+ class="wp-image-grid__check"
81
+ :model-value="props.selected.includes(img.id)"
82
+ :aria-label="`Select ${img.alt}`"
83
+ @update:model-value="toggle(img.id, $event)"
84
+ />
85
+ <span v-if="img.caption" class="wp-image-grid__caption">{{ img.caption }}</span>
86
+ </li>
87
+ </ul>
88
+ <Lightbox v-if="lightbox" v-model:open="open" v-model:index="at" :images="shots" />
89
+ </div>
90
+ </template>
91
+
92
+ <style scoped>
93
+ .wp-image-grid { min-width: 0; }
94
+ .wp-image-grid__list {
95
+ display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--_min), 1fr));
96
+ gap: var(--wp-space-3); margin: 0; padding: 0; list-style: none;
97
+ }
98
+ .wp-image-grid__list[data-gap="sm"] { gap: var(--wp-space-1); }
99
+ .wp-image-grid__tile { position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
100
+ .wp-image-grid__open {
101
+ display: block; width: 100%; aspect-ratio: var(--_aspect); padding: 0; overflow: hidden;
102
+ border: 1px solid var(--wp-border); border-radius: var(--wp-radius);
103
+ background: var(--wp-bg-2); cursor: zoom-in;
104
+ transition: border-color var(--wp-motion-hover), box-shadow var(--wp-motion-hover);
105
+ }
106
+ .wp-image-grid__open:hover { border-color: var(--wp-border-strong); }
107
+ .wp-image-grid__open:focus-visible { outline: none; border-color: var(--wp-border-focus); box-shadow: var(--wp-focus-ring); }
108
+ .wp-image-grid__tile[data-selected] .wp-image-grid__open { border-color: var(--wp-accent); box-shadow: 0 0 0 2px var(--wp-accent-glow); }
109
+ .wp-image-grid__img { display: block; width: 100%; height: 100%; object-fit: cover; }
110
+ .wp-image-grid__empty {
111
+ display: block; width: 100%; height: 100%;
112
+ background: linear-gradient(90deg, var(--wp-bg-2) 0%, var(--wp-bg-3) 50%, var(--wp-bg-2) 100%);
113
+ background-size: 200% 100%; animation: wp-image-grid-shimmer var(--wp-motion-shimmer) infinite;
114
+ }
115
+ @keyframes wp-image-grid-shimmer { to { background-position: -200% 0; } }
116
+ .wp-image-grid__check { position: absolute; top: 6px; left: 6px; }
117
+ .wp-image-grid__caption {
118
+ overflow: hidden; color: var(--wp-text-muted); font: 400 var(--wp-text-xs)/1.3 var(--wp-font-sans);
119
+ text-overflow: ellipsis; white-space: nowrap;
120
+ }
121
+ @media (prefers-reduced-motion: reduce) {
122
+ .wp-image-grid__open { transition: none; }
123
+ .wp-image-grid__empty { animation: none; }
124
+ }
125
+ </style>
@@ -0,0 +1,183 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Inline edit: a name that turns into a text box where it stands. Click it
4
+ * (or focus it and press Enter or F2), type, then Enter or a click away
5
+ * saves and Escape puts the old text back. Works on the canvas and in the
6
+ * manager.
7
+ *
8
+ * <InlineEdit v-model="mod.name" label="Wildcard name" />
9
+ * <InlineEdit v-model="title" label="Chat title" :validate="(v) => taken(v) ? 'That name is taken' : null" />
10
+ *
11
+ * Read view is a button named "Rename <label>: <value>", with a pencil on
12
+ * hover and focus. An empty or invalid value keeps the box open with the
13
+ * message under it; `update:modelValue` only fires on a saved change.
14
+ */
15
+ import { computed, nextTick, ref, useId } from "vue";
16
+
17
+ const props = withDefaults(defineProps<{
18
+ modelValue: string;
19
+ /** What is being renamed, e.g. "Wildcard name". */
20
+ label: string;
21
+ placeholder?: string | undefined;
22
+ /** Return a message to refuse the value, or null to take it. */
23
+ validate?: ((v: string) => string | null) | undefined;
24
+ /** Refuse an empty value. On by default. */
25
+ required?: boolean | undefined;
26
+ disabled?: boolean | undefined;
27
+ size?: "sm" | "md" | "lg" | undefined;
28
+ /** Trim spaces from both ends before saving. */
29
+ trim?: boolean | undefined;
30
+ maxlength?: number | undefined;
31
+ }>(), { placeholder: "Untitled", required: true, size: "md", trim: true, maxlength: undefined });
32
+
33
+ const emit = defineEmits<{
34
+ (e: "update:modelValue", v: string): void;
35
+ (e: "edit"): void;
36
+ (e: "cancel"): void;
37
+ }>();
38
+
39
+ const editing = ref(false);
40
+ const draft = ref("");
41
+ const error = ref<string | null>(null);
42
+ const inputEl = ref<HTMLInputElement | null>(null);
43
+ const readEl = ref<HTMLButtonElement | null>(null);
44
+ const errId = `wp-inline-edit-${useId()}`;
45
+
46
+ const shown = computed(() => props.modelValue || props.placeholder);
47
+
48
+ async function open(): Promise<void> {
49
+ if (props.disabled || editing.value) return;
50
+ draft.value = props.modelValue;
51
+ error.value = null;
52
+ editing.value = true;
53
+ emit("edit");
54
+ await nextTick();
55
+ inputEl.value?.focus();
56
+ inputEl.value?.select();
57
+ }
58
+
59
+ function check(v: string): string | null {
60
+ if (props.required && !v) return `${props.label} can't be empty`;
61
+ return props.validate?.(v) ?? null;
62
+ }
63
+
64
+ async function close(): Promise<void> {
65
+ editing.value = false;
66
+ error.value = null;
67
+ await nextTick();
68
+ readEl.value?.focus();
69
+ }
70
+
71
+ function save(refocus = true): void {
72
+ if (!editing.value) return;
73
+ const v = props.trim ? draft.value.trim() : draft.value;
74
+ const msg = check(v);
75
+ if (msg) {
76
+ error.value = msg;
77
+ return;
78
+ }
79
+ if (v !== props.modelValue) emit("update:modelValue", v);
80
+ if (refocus) void close();
81
+ else { editing.value = false; error.value = null; }
82
+ }
83
+
84
+ function cancel(): void {
85
+ if (!editing.value) return;
86
+ emit("cancel");
87
+ void close();
88
+ }
89
+
90
+ function onBlur(): void {
91
+ // A click away saves; a value that can't be saved is put back instead of
92
+ // leaving a box open that nobody is looking at.
93
+ if (!editing.value) return;
94
+ const v = props.trim ? draft.value.trim() : draft.value;
95
+ if (check(v)) { editing.value = false; error.value = null; emit("cancel"); return; }
96
+ save(false);
97
+ }
98
+
99
+ function onKeydown(ev: KeyboardEvent): void {
100
+ if (ev.key === "Enter") { ev.preventDefault(); save(); }
101
+ else if (ev.key === "Escape") { ev.preventDefault(); ev.stopPropagation(); cancel(); }
102
+ }
103
+
104
+ function onReadKey(ev: KeyboardEvent): void {
105
+ if (ev.key === "F2") { ev.preventDefault(); void open(); }
106
+ }
107
+ </script>
108
+
109
+ <template>
110
+ <span class="wp-inline-edit" :data-size="size" :data-editing="editing || undefined">
111
+ <template v-if="editing">
112
+ <input
113
+ ref="inputEl"
114
+ v-model="draft"
115
+ class="wp-inline-edit__input"
116
+ type="text"
117
+ :aria-label="label"
118
+ :aria-invalid="error ? 'true' : undefined"
119
+ :aria-describedby="error ? errId : undefined"
120
+ :placeholder="placeholder"
121
+ :maxlength="maxlength"
122
+ @keydown="onKeydown"
123
+ @blur="onBlur"
124
+ >
125
+ <span v-if="error" :id="errId" class="wp-inline-edit__error" role="alert">{{ error }}</span>
126
+ </template>
127
+ <button
128
+ v-else
129
+ ref="readEl"
130
+ type="button"
131
+ class="wp-inline-edit__read"
132
+ :data-empty="!modelValue || undefined"
133
+ :aria-label="`Rename ${label}: ${modelValue || placeholder}`"
134
+ :disabled="disabled"
135
+ @click="open"
136
+ @keydown="onReadKey"
137
+ >
138
+ <span class="wp-inline-edit__text">{{ shown }}</span>
139
+ <i class="pi pi-pencil wp-inline-edit__pen" aria-hidden="true" />
140
+ </button>
141
+ </span>
142
+ </template>
143
+
144
+ <style scoped>
145
+ .wp-inline-edit {
146
+ --_h: var(--wp-control-h-md);
147
+ position: relative; display: inline-flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 100%;
148
+ /* The padding of the hover box sits outside the text's line. */
149
+ margin-left: calc(var(--wp-space-3) * -1);
150
+ font: inherit; vertical-align: middle;
151
+ }
152
+ .wp-inline-edit[data-size="sm"] { --_h: var(--wp-control-h-sm); }
153
+ .wp-inline-edit[data-size="lg"] { --_h: var(--wp-control-h-lg); }
154
+ .wp-inline-edit__read, .wp-inline-edit__input {
155
+ box-sizing: border-box; height: var(--_h); margin: 0; min-width: 0;
156
+ padding: 0 var(--wp-space-3); border-radius: var(--wp-radius-sm);
157
+ font: inherit; color: var(--wp-text);
158
+ }
159
+ .wp-inline-edit__read {
160
+ display: inline-flex; align-items: center; gap: var(--wp-space-3); max-width: 100%;
161
+ border: 1px solid transparent; background: transparent; cursor: text; text-align: left;
162
+ transition: background var(--wp-motion-hover), border-color var(--wp-motion-hover);
163
+ }
164
+ .wp-inline-edit__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
165
+ .wp-inline-edit__read[data-empty] .wp-inline-edit__text { color: var(--wp-text-dim); font-style: italic; }
166
+ .wp-inline-edit__pen { flex: none; font-size: 0.8em; color: var(--wp-text-dim); opacity: 0; transition: opacity var(--wp-motion-hover); }
167
+ .wp-inline-edit__read:hover:not(:disabled) { background: var(--wp-row-hover); border-color: var(--wp-border-soft); }
168
+ .wp-inline-edit__read:hover .wp-inline-edit__pen, .wp-inline-edit__read:focus-visible .wp-inline-edit__pen { opacity: 1; }
169
+ .wp-inline-edit__read:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
170
+ .wp-inline-edit__read:disabled { cursor: default; }
171
+ .wp-inline-edit__input {
172
+ width: 100%; min-width: 12ch;
173
+ border: 1px solid var(--wp-border-focus); background: var(--wp-bg-1); outline: none;
174
+ box-shadow: var(--wp-focus-ring);
175
+ }
176
+ .wp-inline-edit__input[aria-invalid="true"] { border-color: var(--wp-error-border); box-shadow: 0 0 0 3px color-mix(in srgb, var(--wp-danger) 22%, transparent); }
177
+ .wp-inline-edit__error {
178
+ margin-top: 2px; color: var(--wp-error-text); font: 400 var(--wp-text-xs)/1.3 var(--wp-font-sans);
179
+ }
180
+ @media (prefers-reduced-motion: reduce) {
181
+ .wp-inline-edit__read, .wp-inline-edit__pen { transition: none; }
182
+ }
183
+ </style>
package/src/Input.vue ADDED
@@ -0,0 +1,99 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Text field. Number fields use WpNumber (`WpNumber.vue`)
4
+ * and search boxes use SearchInput; this one no longer has a number mode.
5
+ */
6
+ import { computed } from "vue";
7
+ import Icon from "./Icon.vue";
8
+
9
+ interface Props {
10
+ modelValue: string;
11
+ type?: "text" | "email" | "url" | "password" | "tel" | undefined;
12
+ placeholder?: string | undefined;
13
+ disabled?: boolean | undefined;
14
+ /** Shown but not editable: dimmer fill, no focus ring, a lock icon. */
15
+ readonly?: boolean | undefined;
16
+ error?: boolean | undefined;
17
+ /** Height on the control scale: sm 24 / md 32 / lg 40. */
18
+ size?: "sm" | "md" | "lg" | undefined;
19
+ /** Icon before the text (a search glass). Drawn inline, no box. */
20
+ icon?: string | undefined;
21
+ /** Text before the value, e.g. `$` for a variable name. */
22
+ prefix?: string | undefined;
23
+ /** Text after the value, e.g. a unit. */
24
+ suffix?: string | undefined;
25
+ id?: string | undefined;
26
+ ariaLabel?: string | undefined;
27
+ }
28
+ const props = withDefaults(defineProps<Props>(), {
29
+ type: "text",
30
+ size: "md",
31
+ });
32
+
33
+ const emit = defineEmits<{
34
+ (e: "update:modelValue", v: string): void;
35
+ (e: "blur", evt: FocusEvent): void;
36
+ (e: "focus", evt: FocusEvent): void;
37
+ }>();
38
+
39
+ const inputClasses = computed(() => [
40
+ "wp-input",
41
+ props.size === "sm" && "wp-input--sm",
42
+ props.size === "lg" && "wp-input--lg",
43
+ ]);
44
+
45
+ const wrapped = computed(() => Boolean(props.icon || props.prefix || props.suffix || props.readonly));
46
+ const groupClasses = computed(() => [
47
+ "wp-input-group",
48
+ props.size === "sm" && "wp-input-group--sm",
49
+ props.size === "lg" && "wp-input-group--lg",
50
+ props.readonly && "wp-input-group--readonly",
51
+ props.disabled && "wp-input-group--disabled",
52
+ ]);
53
+
54
+ function onInput(e: Event) {
55
+ emit("update:modelValue", (e.target as HTMLInputElement).value);
56
+ }
57
+ </script>
58
+
59
+ <template>
60
+ <div v-if="wrapped" :class="groupClasses" :aria-invalid="error || undefined">
61
+ <span v-if="icon" class="wp-input-group__icon" aria-hidden="true">
62
+ <Icon :name="icon" />
63
+ </span>
64
+ <span v-if="prefix" class="wp-input-group__affix wp-input-group__affix--prefix" aria-hidden="true">{{ prefix }}</span>
65
+ <input
66
+ :id="id"
67
+ :class="inputClasses"
68
+ :type="type"
69
+ :value="modelValue"
70
+ :placeholder="placeholder"
71
+ :disabled="disabled"
72
+ :readonly="readonly"
73
+ :aria-label="ariaLabel"
74
+ :aria-invalid="error || undefined"
75
+ @input="onInput"
76
+ @blur="(e) => emit('blur', e)"
77
+ @focus="(e) => emit('focus', e)"
78
+ />
79
+ <span v-if="suffix" class="wp-input-group__affix wp-input-group__affix--suffix" aria-hidden="true">{{ suffix }}</span>
80
+ <span v-if="readonly" class="wp-input-group__lock" aria-hidden="true">
81
+ <Icon name="pi-lock" :size="11" />
82
+ </span>
83
+ </div>
84
+ <input
85
+ v-else
86
+ :id="id"
87
+ :class="inputClasses"
88
+ :type="type"
89
+ :value="modelValue"
90
+ :placeholder="placeholder"
91
+ :disabled="disabled"
92
+ :readonly="readonly"
93
+ :aria-label="ariaLabel"
94
+ :aria-invalid="error || undefined"
95
+ @input="onInput"
96
+ @blur="(e) => emit('blur', e)"
97
+ @focus="(e) => emit('focus', e)"
98
+ />
99
+ </template>
package/src/Kbd.vue ADDED
@@ -0,0 +1,56 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Kbd: a keyboard shortcut drawn as keys. `Mod` reads ⌘ on a Mac and Ctrl
4
+ * elsewhere (from `platform-keys.ts`), so one string fits everyone. Works on
5
+ * the canvas and in the manager.
6
+ *
7
+ * <Kbd keys="Mod+K" />
8
+ * <Kbd :keys="['Shift', 'Enter']" />
9
+ *
10
+ * Screen readers hear the whole chord once ("Control plus K"); the key caps
11
+ * themselves are hidden from them.
12
+ */
13
+ import { computed } from "vue";
14
+ import { isApplePlatform } from "./platform-keys";
15
+
16
+ const props = withDefaults(defineProps<{
17
+ /** "Mod+Shift+P" or ["Mod", "Shift", "P"]. */
18
+ keys: string | string[];
19
+ size?: "sm" | "md" | undefined;
20
+ }>(), { size: "md" });
21
+
22
+ const MAC: Record<string, string> = { Mod: "⌘", Ctrl: "⌃", Alt: "⌥", Shift: "⇧", Enter: "↵" };
23
+ const SPOKEN: Record<string, string> = {
24
+ "⌘": "Command", Ctrl: "Control", "⌃": "Control", Alt: "Alt", "⌥": "Option", Shift: "Shift", "⇧": "Shift",
25
+ Enter: "Enter", "↵": "Enter", Esc: "Escape", "↑": "Up", "↓": "Down", "←": "Left", "→": "Right",
26
+ };
27
+
28
+ const caps = computed(() => {
29
+ const list = Array.isArray(props.keys) ? props.keys : props.keys.split(/\+(?!$)/);
30
+ const mac = isApplePlatform();
31
+ return list.map((k) => k.trim()).filter(Boolean).map((k) => (k === "Mod" ? (mac ? "⌘" : "Ctrl") : mac ? MAC[k] ?? k : k));
32
+ });
33
+ const spoken = computed(() => caps.value.map((k) => SPOKEN[k] ?? k).join(" plus "));
34
+ </script>
35
+
36
+ <template>
37
+ <kbd class="wp-kbd-keys" :data-size="size" :aria-label="spoken">
38
+ <template v-for="(k, i) in caps" :key="i">
39
+ <span v-if="i > 0" class="wp-kbd-keys__plus" aria-hidden="true">+</span>
40
+ <kbd class="wp-kbd-keys__cap" aria-hidden="true">{{ k }}</kbd>
41
+ </template>
42
+ </kbd>
43
+ </template>
44
+
45
+ <style scoped>
46
+ .wp-kbd-keys { display: inline-flex; align-items: center; gap: 2px; font: inherit; vertical-align: baseline; }
47
+ .wp-kbd-keys__plus { color: var(--wp-text-dim); font-size: var(--wp-text-xs); }
48
+ .wp-kbd-keys__cap {
49
+ display: inline-grid; place-items: center; box-sizing: border-box;
50
+ min-width: 20px; height: 20px; padding: 0 5px;
51
+ border: 1px solid var(--wp-border-strong); border-bottom-width: 2px; border-radius: var(--wp-radius-sm);
52
+ background: var(--wp-bg-2); color: var(--wp-text-muted);
53
+ font: 500 11px/1 var(--wp-font-mono); white-space: nowrap;
54
+ }
55
+ .wp-kbd-keys[data-size="sm"] .wp-kbd-keys__cap { min-width: 16px; height: 16px; padding: 0 3px; font-size: 10px; }
56
+ </style>
@@ -0,0 +1,173 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * One image at a time, full screen, over a dimmed page: ← / → (or the side
4
+ * buttons) step through the list, Escape or the ✕ closes, and focus goes
5
+ * back to what opened it. Built on ModalShell, so keys pressed inside never
6
+ * reach ComfyUI's shortcuts. ImageGrid opens it for you; use it alone for
7
+ * a single image (a docs screenshot, a preview).
8
+ *
9
+ * <Lightbox v-model:open="open" v-model:index="at" :images="shots" />
10
+ * <Lightbox v-model:open="open" :images="frames" zoom />
11
+ *
12
+ * `zoom` shows each picture in WpImageZoom (Fit / 100% / 200%, wheel, drag,
13
+ * + − 0 1 2 keys); the level and the spot carry over as you step, so you
14
+ * can compare the same part of every frame.
15
+ */
16
+ import { computed, nextTick, ref, watch } from "vue";
17
+ import ModalShell from "./ModalShell.vue";
18
+ import WpImageZoom from "./WpImageZoom.vue";
19
+ import CloseButton from "./CloseButton.vue";
20
+ import { focusablesIn } from "./useDialogFocus";
21
+
22
+ export interface LightboxImage { src: string; alt: string; caption?: string | undefined }
23
+
24
+ const props = withDefaults(defineProps<{
25
+ open: boolean;
26
+ images: LightboxImage[];
27
+ index?: number | undefined;
28
+ /** Go round from the last image to the first. */
29
+ loop?: boolean | undefined;
30
+ /** Real zoom levels (WpImageZoom) instead of a picture fitted to the screen. */
31
+ zoom?: boolean | undefined;
32
+ }>(), { index: 0, loop: false, zoom: false });
33
+
34
+ /** The zoom level, kept across images while the viewer is open. */
35
+ const level = ref<number | null>(null);
36
+
37
+ const emit = defineEmits<{
38
+ (e: "update:open", v: boolean): void;
39
+ (e: "update:index", v: number): void;
40
+ }>();
41
+
42
+ const panelEl = ref<HTMLElement | null>(null);
43
+ let returnTo: HTMLElement | null = null;
44
+
45
+ const count = computed(() => props.images.length);
46
+ const at = computed(() => Math.min(Math.max(props.index, 0), Math.max(count.value - 1, 0)));
47
+ const image = computed(() => props.images[at.value]);
48
+ const canPrev = computed(() => count.value > 1 && (props.loop || at.value > 0));
49
+ const canNext = computed(() => count.value > 1 && (props.loop || at.value < count.value - 1));
50
+
51
+ function go(dir: 1 | -1): void {
52
+ if (dir < 0 ? !canPrev.value : !canNext.value) return;
53
+ emit("update:index", (at.value + dir + count.value) % count.value);
54
+ }
55
+
56
+ function close(): void {
57
+ emit("update:open", false);
58
+ }
59
+
60
+ function onKey(ev: KeyboardEvent): void {
61
+ if (ev.key === "ArrowLeft") { ev.preventDefault(); go(-1); }
62
+ else if (ev.key === "ArrowRight") { ev.preventDefault(); go(1); }
63
+ else if (ev.key === "Home" && count.value) { ev.preventDefault(); emit("update:index", 0); }
64
+ else if (ev.key === "End" && count.value) { ev.preventDefault(); emit("update:index", count.value - 1); }
65
+ else if (ev.key === "Tab") {
66
+ // Keep Tab inside: ModalShell stops the keys at its overlay, so this is the trap.
67
+ const els = focusablesIn(panelEl.value);
68
+ if (!els.length) return;
69
+ const first = els[0];
70
+ const last = els[els.length - 1];
71
+ if (ev.shiftKey && document.activeElement === first) { ev.preventDefault(); last.focus(); }
72
+ else if (!ev.shiftKey && document.activeElement === last) { ev.preventDefault(); first.focus(); }
73
+ }
74
+ }
75
+
76
+ watch(() => props.open, async (v, was) => {
77
+ if (typeof document === "undefined") return;
78
+ if (v) {
79
+ level.value = null;
80
+ returnTo = document.activeElement instanceof HTMLElement ? document.activeElement : null;
81
+ await nextTick();
82
+ panelEl.value?.focus();
83
+ } else if (was) {
84
+ const el = returnTo;
85
+ returnTo = null;
86
+ if (el?.isConnected) el.focus();
87
+ }
88
+ }, { immediate: true });
89
+ </script>
90
+
91
+ <template>
92
+ <ModalShell :visible="open" @close="close" @keydown="onKey">
93
+ <!-- A click on the dark area closes, like the modal's own backdrop; Escape is the keyboard way. -->
94
+ <!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
95
+ <div
96
+ ref="panelEl"
97
+ class="wp-lightbox"
98
+ tabindex="-1"
99
+ role="group"
100
+ aria-roledescription="image viewer"
101
+ :aria-label="image ? `${image.alt}, ${at + 1} of ${count}` : 'Image viewer'"
102
+ @click.self="close"
103
+ >
104
+ <div class="wp-lightbox__bar">
105
+ <span v-if="count > 1" class="wp-lightbox__count" aria-hidden="true">{{ at + 1 }} / {{ count }}</span>
106
+ <CloseButton class="wp-lightbox__close" kbd="Esc" @click="close" />
107
+ </div>
108
+ <figure v-if="image" class="wp-lightbox__figure" :data-zoom="zoom || undefined">
109
+ <WpImageZoom v-if="zoom" v-model:zoom="level" class="wp-lightbox__zoom" :src="image.src" :alt="image.alt" size="md" minimap />
110
+ <img v-else class="wp-lightbox__img" :src="image.src" :alt="image.alt">
111
+ <figcaption v-if="image.caption" class="wp-lightbox__caption">{{ image.caption }}</figcaption>
112
+ </figure>
113
+ <button
114
+ v-if="count > 1"
115
+ type="button"
116
+ class="wp-lightbox__step"
117
+ data-dir="prev"
118
+ aria-label="Previous image"
119
+ :disabled="!canPrev"
120
+ @click="go(-1)"
121
+ ><i class="pi pi-chevron-left" aria-hidden="true" /></button>
122
+ <button
123
+ v-if="count > 1"
124
+ type="button"
125
+ class="wp-lightbox__step"
126
+ data-dir="next"
127
+ aria-label="Next image"
128
+ :disabled="!canNext"
129
+ @click="go(1)"
130
+ ><i class="pi pi-chevron-right" aria-hidden="true" /></button>
131
+ </div>
132
+ </ModalShell>
133
+ </template>
134
+
135
+ <style scoped>
136
+ .wp-lightbox {
137
+ position: relative; display: flex; flex-direction: column; align-items: center;
138
+ width: min(1200px, 100%); max-height: calc(100vh - 40px); outline: none;
139
+ color: var(--wp-text); font-family: var(--wp-font-sans);
140
+ }
141
+ /* Its own near-black scrim in both themes: the shared modal one is light enough to read a dialog
142
+ over (and pale grey in light mode), too light to look at a picture on. A click on it closes. */
143
+ .wp-lightbox::before { content: ""; position: fixed; inset: 0; z-index: -1; background: rgb(0 0 0 / 0.86); }
144
+ .wp-lightbox__bar { display: flex; align-items: center; justify-content: flex-end; gap: var(--wp-space-3); align-self: stretch; padding-bottom: var(--wp-space-2); }
145
+ .wp-lightbox__count { color: rgb(255 255 255 / 0.75); font-size: var(--wp-text-sm); font-variant-numeric: tabular-nums; }
146
+ .wp-lightbox .wp-lightbox__close { color: rgb(255 255 255 / 0.85); }
147
+ .wp-lightbox__figure { display: flex; flex-direction: column; align-items: center; gap: var(--wp-space-2); min-height: 0; margin: 0; }
148
+ .wp-lightbox__figure[data-zoom] { align-self: stretch; }
149
+ .wp-lightbox__zoom {
150
+ width: 100%; height: calc(100vh - 140px);
151
+ border-radius: var(--wp-radius); overflow: hidden; background: var(--wp-bg-1); box-shadow: var(--wp-shadow-lg);
152
+ }
153
+ .wp-lightbox__img {
154
+ display: block; max-width: 100%; max-height: calc(100vh - 140px); object-fit: contain;
155
+ border-radius: var(--wp-radius); box-shadow: var(--wp-shadow-lg); background: var(--wp-bg-1);
156
+ }
157
+ .wp-lightbox__caption { color: rgb(255 255 255 / 0.8); font-size: var(--wp-text-sm); text-align: center; }
158
+ .wp-lightbox__step {
159
+ position: absolute; top: 50%; transform: translateY(-50%);
160
+ display: grid; place-items: center; width: var(--wp-control-h-lg); height: var(--wp-control-h-lg);
161
+ border: 1px solid var(--wp-border-strong); border-radius: min(50%, var(--wp-radius-cap, 999px));
162
+ background: var(--wp-bg-2); color: var(--wp-text); cursor: pointer; box-shadow: var(--wp-shadow-md);
163
+ transition: background var(--wp-motion-hover);
164
+ }
165
+ .wp-lightbox__step[data-dir="prev"] { left: var(--wp-space-2); }
166
+ .wp-lightbox__step[data-dir="next"] { right: var(--wp-space-2); }
167
+ .wp-lightbox__step:hover:not(:disabled) { background: var(--wp-bg-3); }
168
+ .wp-lightbox__step:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); border-color: var(--wp-border-focus); }
169
+ .wp-lightbox__step:disabled { opacity: 0.35; cursor: not-allowed; }
170
+ @media (prefers-reduced-motion: reduce) {
171
+ .wp-lightbox__step { transition: none; }
172
+ }
173
+ </style>