@noix-dev/brix-vue 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +74 -2
- package/package.json +117 -3
- package/src/components/address-field/AddressField.vue +337 -0
- package/src/components/address-field/index.ts +1 -0
- package/src/components/appearance-picker/AppearancePicker.vue +502 -0
- package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
- package/src/components/appearance-picker/index.ts +44 -0
- package/src/components/autofill/AutoFillDialog.vue +264 -0
- package/src/components/autofill/index.ts +1 -0
- package/src/components/badge/Badge.vue +23 -0
- package/src/components/badge/index.ts +106 -0
- package/src/components/build-stamp/BuildStamp.vue +62 -0
- package/src/components/build-stamp/index.ts +1 -0
- package/src/components/button/Button.vue +31 -0
- package/src/components/button/index.ts +122 -0
- package/src/components/card/Card.vue +29 -0
- package/src/components/card/CardAction.vue +17 -0
- package/src/components/card/CardContent.vue +14 -0
- package/src/components/card/CardDescription.vue +14 -0
- package/src/components/card/CardFooter.vue +22 -0
- package/src/components/card/CardHeader.vue +22 -0
- package/src/components/card/CardTitle.vue +29 -0
- package/src/components/card/index.ts +47 -0
- package/src/components/chart/BarChart.vue +123 -0
- package/src/components/chart/StackedBarChart.vue +149 -0
- package/src/components/chart/appearanceRevision.ts +22 -0
- package/src/components/chart/chartColor.ts +59 -0
- package/src/components/chart/index.ts +6 -0
- package/src/components/checkbox/Checkbox.vue +61 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/code-editor/CodeEditor.vue +352 -0
- package/src/components/code-editor/index.ts +9 -0
- package/src/components/code-editor/syntaxTheme.ts +110 -0
- package/src/components/colour-picker/ColourPicker.vue +421 -0
- package/src/components/colour-picker/index.ts +1 -0
- package/src/components/combobox/Combobox.vue +337 -0
- package/src/components/combobox/index.ts +1 -0
- package/src/components/comments/CommentComposer.vue +302 -0
- package/src/components/comments/CommentMessage.vue +259 -0
- package/src/components/comments/CommentThread.vue +250 -0
- package/src/components/comments/commentBody.ts +185 -0
- package/src/components/comments/commentLevels.ts +139 -0
- package/src/components/comments/commentNode.ts +35 -0
- package/src/components/comments/composer.ts +20 -0
- package/src/components/comments/index.ts +29 -0
- package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
- package/src/components/confirm-dialog/index.ts +1 -0
- package/src/components/containers/Box.vue +42 -0
- package/src/components/containers/Section.vue +88 -0
- package/src/components/containers/SectionAction.vue +17 -0
- package/src/components/containers/SectionContent.vue +14 -0
- package/src/components/containers/SectionDescription.vue +14 -0
- package/src/components/containers/SectionHeader.vue +22 -0
- package/src/components/containers/SectionTitle.vue +17 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/data-table/ColumnMenu.vue +241 -0
- package/src/components/data-table/DataTable.vue +447 -0
- package/src/components/data-table/ExpandCaret.vue +34 -0
- package/src/components/data-table/SortableHead.vue +184 -0
- package/src/components/data-table/TableLoadingRow.vue +13 -0
- package/src/components/data-table/TableProgressRow.vue +26 -0
- package/src/components/data-table/columns.ts +13 -0
- package/src/components/data-table/index.ts +3 -0
- package/src/components/data-table/pinned.ts +19 -0
- package/src/components/data-table/rowActivation.ts +14 -0
- package/src/components/data-table/sort.ts +13 -0
- package/src/components/data-table/types.ts +23 -0
- package/src/components/date-picker/CalendarPanel.vue +432 -0
- package/src/components/date-picker/DateField.vue +293 -0
- package/src/components/date-picker/DatePicker.vue +147 -0
- package/src/components/date-picker/UntilDatePicker.vue +96 -0
- package/src/components/date-picker/dateFieldGuard.ts +87 -0
- package/src/components/date-picker/index.ts +4 -0
- package/src/components/date-picker/useDateField.ts +37 -0
- package/src/components/date-range-picker/DateRangePicker.vue +247 -0
- package/src/components/date-range-picker/index.ts +1 -0
- package/src/components/date-time-picker/DateTimePicker.vue +291 -0
- package/src/components/date-time-picker/index.ts +1 -0
- package/src/components/dialog/Dialog.vue +250 -0
- package/src/components/dialog/DialogSurface.vue +214 -0
- package/src/components/dialog/dialogEdges.ts +65 -0
- package/src/components/dialog/dialogSizes.ts +35 -0
- package/src/components/dialog/index.ts +12 -0
- package/src/components/dialog/toastHost.ts +18 -0
- package/src/components/dropdown/Dropdown.vue +101 -0
- package/src/components/dropdown/DropdownItems.vue +154 -0
- package/src/components/dropdown/dropdown.ts +64 -0
- package/src/components/dropdown/index.ts +2 -0
- package/src/components/file-preview/FilePreview.vue +78 -0
- package/src/components/file-preview/index.ts +1 -0
- package/src/components/file-upload/FileUpload.vue +234 -0
- package/src/components/file-upload/index.ts +1 -0
- package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
- package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
- package/src/components/filter-check-menu/index.ts +2 -0
- package/src/components/form-field/FormField.vue +74 -0
- package/src/components/form-field/index.ts +2 -0
- package/src/components/form-field/types.ts +5 -0
- package/src/components/frames/FrameCentred.vue +137 -0
- package/src/components/frames/FrameSidebar.vue +113 -0
- package/src/components/frames/FrameSplit.vue +109 -0
- package/src/components/frames/index.ts +3 -0
- package/src/components/icon/BellIcon.vue +27 -0
- package/src/components/icon/BoldIcon.vue +31 -0
- package/src/components/icon/CalendarDaysIcon.vue +33 -0
- package/src/components/icon/CheckIcon.vue +31 -0
- package/src/components/icon/ChevronDownIcon.vue +30 -0
- package/src/components/icon/ChevronLeftIcon.vue +31 -0
- package/src/components/icon/ChevronRightIcon.vue +31 -0
- package/src/components/icon/ChevronUpIcon.vue +30 -0
- package/src/components/icon/CircleAlertIcon.vue +29 -0
- package/src/components/icon/ClockIcon.vue +31 -0
- package/src/components/icon/Columns3Icon.vue +32 -0
- package/src/components/icon/FlipHorizontalIcon.vue +29 -0
- package/src/components/icon/ItalicIcon.vue +28 -0
- package/src/components/icon/LinkIcon.vue +27 -0
- package/src/components/icon/ListIcon.vue +29 -0
- package/src/components/icon/ListOrderedIcon.vue +28 -0
- package/src/components/icon/PenLineIcon.vue +31 -0
- package/src/components/icon/PlusIcon.vue +28 -0
- package/src/components/icon/RotateCcwIcon.vue +28 -0
- package/src/components/icon/RotateCwIcon.vue +28 -0
- package/src/components/icon/SearchIcon.vue +31 -0
- package/src/components/icon/StarIcon.vue +29 -0
- package/src/components/icon/TriangleAlertIcon.vue +29 -0
- package/src/components/icon/UnderlineIcon.vue +27 -0
- package/src/components/icon/Undo2Icon.vue +28 -0
- package/src/components/icon/XIcon.vue +31 -0
- package/src/components/icon/ZoomInIcon.vue +30 -0
- package/src/components/icon/ZoomOutIcon.vue +29 -0
- package/src/components/icon/index.ts +37 -0
- package/src/components/icon-picker/IconPicker.vue +560 -0
- package/src/components/icon-picker/index.ts +1 -0
- package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
- package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
- package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
- package/src/components/image-crop-dialog/index.ts +16 -0
- package/src/components/image-upload/ImageUpload.vue +345 -0
- package/src/components/image-upload/index.ts +2 -0
- package/src/components/input/Input.vue +48 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/keycap/Keycap.vue +49 -0
- package/src/components/keycap/index.ts +1 -0
- package/src/components/label/Label.vue +26 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/menu/MenuCheckboxItem.vue +63 -0
- package/src/components/menu/MenuContent.vue +45 -0
- package/src/components/menu/MenuGroup.vue +22 -0
- package/src/components/menu/MenuItem.vue +34 -0
- package/src/components/menu/MenuLabel.vue +22 -0
- package/src/components/menu/MenuRadioGroup.vue +22 -0
- package/src/components/menu/MenuRadioItem.vue +50 -0
- package/src/components/menu/MenuRoot.vue +25 -0
- package/src/components/menu/MenuSeparator.vue +27 -0
- package/src/components/menu/MenuSub.vue +29 -0
- package/src/components/menu/MenuSubContent.vue +48 -0
- package/src/components/menu/MenuSubTrigger.vue +49 -0
- package/src/components/menu/MenuTrigger.vue +22 -0
- package/src/components/menu/index.ts +20 -0
- package/src/components/menu/menuClasses.ts +74 -0
- package/src/components/morph-select/MorphSelect.vue +150 -0
- package/src/components/morph-select/index.ts +1 -0
- package/src/components/nav/NavFlyout.vue +343 -0
- package/src/components/nav/NavGroup.vue +306 -0
- package/src/components/nav/NavItem.vue +243 -0
- package/src/components/nav/NavNodes.ts +66 -0
- package/src/components/nav/NavSection.vue +105 -0
- package/src/components/nav/NavSidebar.vue +137 -0
- package/src/components/nav/index.ts +5 -0
- package/src/components/nav/navChain.ts +112 -0
- package/src/components/nav/navClasses.ts +229 -0
- package/src/components/nav/navNode.ts +10 -0
- package/src/components/nav/navRegistry.ts +24 -0
- package/src/components/notification-list/NotificationList.vue +314 -0
- package/src/components/notification-list/index.ts +2 -0
- package/src/components/notification-list/notifications.ts +21 -0
- package/src/components/pagination/Pagination.vue +296 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pin-field/PinField.vue +332 -0
- package/src/components/pin-field/index.ts +1 -0
- package/src/components/popover-panel/PopoverPanel.vue +115 -0
- package/src/components/popover-panel/index.ts +5 -0
- package/src/components/rating/Rating.vue +201 -0
- package/src/components/rating/index.ts +1 -0
- package/src/components/record-avatar/RecordAvatar.vue +76 -0
- package/src/components/record-avatar/index.ts +1 -0
- package/src/components/result-window/ResultWindow.vue +399 -0
- package/src/components/result-window/index.ts +2 -0
- package/src/components/result-window/results.ts +75 -0
- package/src/components/rich-editor/RichEditor.vue +370 -0
- package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
- package/src/components/rich-editor/index.ts +8 -0
- package/src/components/row-actions/RowActions.vue +262 -0
- package/src/components/row-actions/index.ts +2 -0
- package/src/components/row-actions/rowActions.ts +44 -0
- package/src/components/search-select/SearchSelect.vue +599 -0
- package/src/components/search-select/index.ts +2 -0
- package/src/components/search-select/types.ts +14 -0
- package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
- package/src/components/segmented-choice/index.ts +2 -0
- package/src/components/segmented-choice/segmentedOption.ts +6 -0
- package/src/components/select/Select.vue +18 -0
- package/src/components/select/SelectContent.vue +73 -0
- package/src/components/select/SelectGroup.vue +21 -0
- package/src/components/select/SelectItem.vue +47 -0
- package/src/components/select/SelectItemText.vue +12 -0
- package/src/components/select/SelectLabel.vue +17 -0
- package/src/components/select/SelectScrollDownButton.vue +36 -0
- package/src/components/select/SelectScrollUpButton.vue +36 -0
- package/src/components/select/SelectSeparator.vue +19 -0
- package/src/components/select/SelectTrigger.vue +52 -0
- package/src/components/select/SelectValue.vue +12 -0
- package/src/components/select/index.ts +11 -0
- package/src/components/session/IdleTimer.vue +71 -0
- package/src/components/session/SessionDialogs.vue +177 -0
- package/src/components/session/index.ts +2 -0
- package/src/components/split-button/SplitButton.vue +122 -0
- package/src/components/split-button/index.ts +2 -0
- package/src/components/split-button/splitButtonItem.ts +7 -0
- package/src/components/switch/Switch.vue +60 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/table/Table.vue +51 -0
- package/src/components/table/TableBody.vue +14 -0
- package/src/components/table/TableCaption.vue +17 -0
- package/src/components/table/TableCell.vue +22 -0
- package/src/components/table/TableEmpty.vue +72 -0
- package/src/components/table/TableFooter.vue +17 -0
- package/src/components/table/TableHead.vue +22 -0
- package/src/components/table/TableHeader.vue +14 -0
- package/src/components/table/TableRow.vue +22 -0
- package/src/components/table/index.ts +9 -0
- package/src/components/tabs/Tabs.vue +173 -0
- package/src/components/tabs/index.ts +2 -0
- package/src/components/tabs/tabItem.ts +12 -0
- package/src/components/textarea/LimitedTextarea.vue +81 -0
- package/src/components/textarea/TextLimitCounter.vue +107 -0
- package/src/components/textarea/Textarea.vue +42 -0
- package/src/components/textarea/index.ts +4 -0
- package/src/components/textarea/textLimit.ts +43 -0
- package/src/components/time-picker/TimePicker.vue +522 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/toast/ToastHost.vue +276 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/update-notice/UpdateNotice.vue +103 -0
- package/src/components/update-notice/index.ts +1 -0
- package/src/components/user-menu/UserMenu.vue +154 -0
- package/src/components/user-menu/index.ts +1 -0
- package/src/index.ts +182 -0
- package/src/lib/cn.ts +21 -0
- package/src/lib/panelFocus.ts +65 -0
- package/src/lib/sessionMonitor.ts +390 -0
- package/src/lib/slotContent.ts +17 -0
- package/src/lib/updateCheck.ts +133 -0
- package/src/styles.css +82 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { formatLabel, type CropRatio } from '@noix-dev/brix-core';
|
|
3
|
+
import { computed, ref } from 'vue';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The allowed aspect ratios of the crop variant that is open. Internal to the image-crop family:
|
|
7
|
+
* `ImageCropDialog` renders it and owns the labels, so they arrive here as plain strings.
|
|
8
|
+
*
|
|
9
|
+
* With several ratios it is a radio group (the one in force is `aria-checked`); with exactly one
|
|
10
|
+
* there is nothing to choose, and with none the variant is free -- both are stated as a static
|
|
11
|
+
* chip ("Only 16:9", "Free") instead. The row is never absent, so the dialog's height does not
|
|
12
|
+
* depend on which variant is open.
|
|
13
|
+
*
|
|
14
|
+
* COLOUR. Roles only, and not on the dark crop stage. The row has THREE appearances, not two:
|
|
15
|
+
* with several ratios the selected button is `--primary-foreground` on `--primary` and the rest
|
|
16
|
+
* `--foreground` on the track's `--muted`, the track edged in `--border`; with one or none, the
|
|
17
|
+
* chip replaces the whole track and is `--muted-foreground` on the panel's own `--popover`.
|
|
18
|
+
*
|
|
19
|
+
* THE UNSELECTED INK IS `--foreground`, NOT `--muted-foreground`, and that is the whole reason it
|
|
20
|
+
* is named here. A ratio is a 12px semibold word, which WCAG counts as normal text and holds to
|
|
21
|
+
* 4.5. `--muted-foreground` on `--muted` is the pairing this family's toolbar documents at 4.34
|
|
22
|
+
* to 6.56 — but documents as a GRAPHIC, against the 3:1 a glyph is held to. 4.34 is kingfisher
|
|
23
|
+
* light (4.348, which this reading rounds to 4.35 where the toolbar's note truncates), and
|
|
24
|
+
* reading a graphics-grade ink as text left the row 0.15 under AA in that one pair. `--foreground`
|
|
25
|
+
* on `--muted` measures 12.18 in graphite dark to 18.16 in kingfisher light over the six theme and
|
|
26
|
+
* mode pairs — contrast ratios of the pair over its own ground, each in the appearance it is
|
|
27
|
+
* named under, resolved through a canvas from the colours the browser computes rather than read
|
|
28
|
+
* off the token names:
|
|
29
|
+
*
|
|
30
|
+
* light: kingfisher 18.16 graphite 16.31 noix 15.96
|
|
31
|
+
* dark: kingfisher 14.50 graphite 12.18 noix 12.58
|
|
32
|
+
*
|
|
33
|
+
* The hover moves the GROUND instead, for the reason the toolbar's does: the ink is already the
|
|
34
|
+
* strongest the contract has, and a ghost hover's own `--muted` is the track's own colour here,
|
|
35
|
+
* so pointing at a ratio lifts it onto `--background`, 15.29 to 19.80 over the same six. The
|
|
36
|
+
* selected button is untouched, and measures 5.79 to 9.65 (9.34 in kingfisher light).
|
|
37
|
+
*
|
|
38
|
+
* THE CHIP'S INK IS THE PANEL'S, NOT THE TRACK'S, which is why it carries its own figures: there
|
|
39
|
+
* is no `--muted` under it. At 12px and weight 600 WCAG counts it as normal text and holds it to
|
|
40
|
+
* 4.5, and `--muted-foreground` on `--popover` measures, over the same six pairs and read the
|
|
41
|
+
* same way:
|
|
42
|
+
*
|
|
43
|
+
* light: kingfisher 4.74 graphite 5.60 noix 5.54
|
|
44
|
+
* dark: kingfisher 6.94 graphite 7.20 noix 7.61
|
|
45
|
+
*
|
|
46
|
+
* The chip's own dashed edge is `--border` on that ground, 1.26 to 1.43, far under 3:1 -- and it
|
|
47
|
+
* is held to nothing, because a row with one allowed ratio has no state to indicate and no second
|
|
48
|
+
* appearance to be told from: the chip's text names the ratio outright. No declared state on the
|
|
49
|
+
* playground page opens on a variant that draws the chip, so the contrast walk never reaches
|
|
50
|
+
* this form; the eight readings above were taken by hand from the painted chip in each
|
|
51
|
+
* appearance. Both chips are the same element, so the figures cover the free one too.
|
|
52
|
+
*/
|
|
53
|
+
const props = defineProps<{
|
|
54
|
+
ratios: CropRatio[];
|
|
55
|
+
/** The `name` of the ratio in force. */
|
|
56
|
+
current: string;
|
|
57
|
+
labels: { aspectRatio: string; only: string; free: string };
|
|
58
|
+
}>();
|
|
59
|
+
|
|
60
|
+
const emit = defineEmits<{ (e: 'pick', name: string): void }>();
|
|
61
|
+
|
|
62
|
+
const buttons = ref<HTMLButtonElement[]>([]);
|
|
63
|
+
|
|
64
|
+
/** Arrow keys move the choice (and focus) to the neighbour, wrapping at both ends. */
|
|
65
|
+
function onKey(event: KeyboardEvent, index: number) {
|
|
66
|
+
const step =
|
|
67
|
+
event.key === 'ArrowRight' || event.key === 'ArrowDown'
|
|
68
|
+
? 1
|
|
69
|
+
: event.key === 'ArrowLeft' || event.key === 'ArrowUp'
|
|
70
|
+
? -1
|
|
71
|
+
: 0;
|
|
72
|
+
if (step === 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
const count = props.ratios.length;
|
|
75
|
+
const next = (index + step + count) % count;
|
|
76
|
+
emit('pick', props.ratios[next]!.name);
|
|
77
|
+
buttons.value[next]?.focus();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The row's one-line form, and null where there is a group to draw instead. Two different silences
|
|
82
|
+
* reach it: a variant that allows exactly one ratio, which has nothing to choose, and one that
|
|
83
|
+
* allows none, which is free. Both state what is in force; the row never renders empty and never
|
|
84
|
+
* disappears, so the dialog's height does not depend on which variant is open.
|
|
85
|
+
*/
|
|
86
|
+
const chipText = computed(() => {
|
|
87
|
+
if (props.ratios.length === 0) return props.labels.free;
|
|
88
|
+
const only = props.ratios.length === 1 ? props.ratios[0]! : null;
|
|
89
|
+
return only ? formatLabel(props.labels.only, { ratio: only.label }) : null;
|
|
90
|
+
});
|
|
91
|
+
</script>
|
|
92
|
+
|
|
93
|
+
<template>
|
|
94
|
+
<div data-testid="crop-ratio-row" class="flex flex-wrap items-center gap-3 pb-3">
|
|
95
|
+
<span class="text-muted-foreground text-xs font-semibold tracking-wider uppercase">
|
|
96
|
+
{{ labels.aspectRatio }}
|
|
97
|
+
</span>
|
|
98
|
+
<span
|
|
99
|
+
v-if="chipText"
|
|
100
|
+
data-testid="crop-ratio-chip"
|
|
101
|
+
class="border-border text-muted-foreground inline-flex h-8 items-center rounded-md border border-dashed px-3 text-xs font-semibold tabular-nums"
|
|
102
|
+
>
|
|
103
|
+
{{ chipText }}
|
|
104
|
+
</span>
|
|
105
|
+
<div
|
|
106
|
+
v-else
|
|
107
|
+
role="radiogroup"
|
|
108
|
+
:aria-label="labels.aspectRatio"
|
|
109
|
+
class="bg-muted border-border inline-flex gap-0.5 rounded-md border p-0.5"
|
|
110
|
+
>
|
|
111
|
+
<button
|
|
112
|
+
v-for="(ratio, index) in ratios"
|
|
113
|
+
:key="ratio.name"
|
|
114
|
+
ref="buttons"
|
|
115
|
+
type="button"
|
|
116
|
+
role="radio"
|
|
117
|
+
:aria-checked="ratio.name === current"
|
|
118
|
+
:tabindex="ratio.name === current ? 0 : -1"
|
|
119
|
+
:class="[
|
|
120
|
+
'focus-visible:outline-ring h-7 rounded px-3 text-xs font-semibold tabular-nums focus-visible:outline-2 focus-visible:outline-offset-2',
|
|
121
|
+
ratio.name === current
|
|
122
|
+
? 'bg-primary text-primary-foreground'
|
|
123
|
+
: 'text-foreground hover:bg-background bg-transparent',
|
|
124
|
+
]"
|
|
125
|
+
@click="$emit('pick', ratio.name)"
|
|
126
|
+
@keydown="onKey($event, index)"
|
|
127
|
+
>
|
|
128
|
+
{{ ratio.label }}
|
|
129
|
+
</button>
|
|
130
|
+
</div>
|
|
131
|
+
</div>
|
|
132
|
+
</template>
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { CropSelection, CropVariant } from '@noix-dev/brix-core';
|
|
3
|
+
import { computed, ref } from 'vue';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The column of variant tiles beside the crop stage. Internal to the image-crop family:
|
|
7
|
+
* `ImageCropDialog` renders it and owns the labels, so they arrive here as plain strings.
|
|
8
|
+
*
|
|
9
|
+
* Each tile previews what its variant currently frames. The preview is CSS, not a cropper: a frame
|
|
10
|
+
* of the crop's own shape, fitted into a fixed box, holding the image scaled and offset so that
|
|
11
|
+
* only the rectangle shows. A rectangle is fractions of the image as DISPLAYED (turned by
|
|
12
|
+
* `rotate`, mirrored if `flip`), so the image is laid out in a box of the displayed size and
|
|
13
|
+
* turned inside it.
|
|
14
|
+
*
|
|
15
|
+
* COLOUR. Roles only, and two surfaces a reader can easily merge into one: the TILE is the
|
|
16
|
+
* button, the PREVIEW BOX is the fixed 84x58 span inside it. The tile's ground is `--background`;
|
|
17
|
+
* the open tile is edged and ringed in `--primary`, a closed one edged in `--border` and, under
|
|
18
|
+
* the pointer, `--primary/45`. The preview box's ground is `--muted` (not the dark crop stage,
|
|
19
|
+
* which stays the family's only fixed-palette site), and the box's own 1px edge is what carries
|
|
20
|
+
* `auto`: dashed `--muted-foreground` while the variant is still automatic, transparent once it
|
|
21
|
+
* is framed.
|
|
22
|
+
*
|
|
23
|
+
* THE DASHED EDGE IS AT FULL STRENGTH, measured rather than reasoned. At `--muted-foreground/70`
|
|
24
|
+
* it composites over the box's `--muted` to 2.58 in kingfisher light, 2.85 in graphite light and
|
|
25
|
+
* 2.85 in noix light -- under the 3:1 that WCAG 1.4.11 holds a state-bearing graphic to, while
|
|
26
|
+
* the three dark modes cleared it at 3.63, 3.81 and 4.00. Without the alpha the worst pair is
|
|
27
|
+
* 4.35 and the best 6.56. The figures come from the painted box in all six appearances, each
|
|
28
|
+
* read by compositing the computed border colour over the computed ground through the browser's
|
|
29
|
+
* own canvas: `getComputedStyle` returns `oklab(... / 0.7)` and blends nothing, so a reading
|
|
30
|
+
* taken from it names a colour the box never paints -- which is how an earlier figure for this
|
|
31
|
+
* edge came from a pairing that was not this one.
|
|
32
|
+
*
|
|
33
|
+
* ACCESSIBILITY. A tile's name must be explicit: a name built from child elements alone reaches
|
|
34
|
+
* the accessibility tree empty. It states the label, the ratio in force and, if it applies, auto.
|
|
35
|
+
*
|
|
36
|
+
* THE VISIBLE LABEL TRUNCATES, the tile does not stretch. A label is consumer text of any length
|
|
37
|
+
* and may be one unbreakable word, so a tile sized to it would be sized by its caller: measured
|
|
38
|
+
* at 140px of label in a 110px column, 21px of it painted past the tile's own border at every
|
|
39
|
+
* density, because nothing in the column truncated and a single word offers no break. The tile's
|
|
40
|
+
* geometry is what the whole strip is built on, so the label is the side that yields. It costs a
|
|
41
|
+
* screen reader nothing: the name above is the full text, and it is the `aria-label`, not the
|
|
42
|
+
* span, that reaches the accessibility tree — the two spans beside the preview are
|
|
43
|
+
* `aria-hidden`.
|
|
44
|
+
*/
|
|
45
|
+
const props = defineProps<{
|
|
46
|
+
src: string;
|
|
47
|
+
variants: CropVariant[];
|
|
48
|
+
/** Keyed by `CropVariant.name`. */
|
|
49
|
+
selections: Record<string, CropSelection>;
|
|
50
|
+
/** The `name` of the open variant. */
|
|
51
|
+
current: string;
|
|
52
|
+
/** Width / height of the image as DISPLAYED (the original's reciprocal after a quarter turn). */
|
|
53
|
+
frameAspect: number;
|
|
54
|
+
/**
|
|
55
|
+
* The image's turn, shared by every tile: the transform belongs to the image, not to a variant,
|
|
56
|
+
* so it is not read from the selections. `frameAspect` must have been computed for it.
|
|
57
|
+
*/
|
|
58
|
+
rotate: 0 | 90 | 180 | 270;
|
|
59
|
+
/** The image's mirror, shared by every tile like `rotate`. */
|
|
60
|
+
flip: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The `id` of the panel the tiles switch, the crop stage. A `tab` that controls nothing
|
|
63
|
+
* leaves a screen reader without the relationship, so the dialog hands its stage's id down;
|
|
64
|
+
* a strip rendered without one claims nothing rather than pointing at a missing element.
|
|
65
|
+
*/
|
|
66
|
+
ariaControls?: string;
|
|
67
|
+
/**
|
|
68
|
+
* One `id` per variant, in the order of `variants`, for the tiles to carry. The panel names
|
|
69
|
+
* the open tile as its own label, so the two halves of the relationship have to agree: the
|
|
70
|
+
* dialog mints both ends rather than each side building a name the other has to guess.
|
|
71
|
+
*/
|
|
72
|
+
tabIds?: string[];
|
|
73
|
+
labels: { variants: string; auto: string };
|
|
74
|
+
}>();
|
|
75
|
+
|
|
76
|
+
const emit = defineEmits<{ (e: 'pick', name: string): void }>();
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The preview box, one size for every tile. The two numbers reach the markup as inline styles
|
|
80
|
+
* rather than through a custom property the classes read back: `src/portability.test.ts` holds
|
|
81
|
+
* every custom property this package names to a role the token contract defines, which a box
|
|
82
|
+
* size is not, and binding the constants directly keeps the fit arithmetic and the box one source.
|
|
83
|
+
*/
|
|
84
|
+
const BOX_W = 84;
|
|
85
|
+
const BOX_H = 58;
|
|
86
|
+
/**
|
|
87
|
+
* Every preview box carries an edge (dashed while auto, transparent otherwise) and `box-border`
|
|
88
|
+
* puts it inside the box, so the fit below works on the box minus two of these. The width reaches
|
|
89
|
+
* the markup as an inline style and the classes carry only the style and the colour: as a
|
|
90
|
+
* `border` utility the number would be stated twice, and a later `border-2` would move the edge
|
|
91
|
+
* without moving the fit -- a frame 2px too large inside a box that did not grow.
|
|
92
|
+
*/
|
|
93
|
+
const EDGE = 1;
|
|
94
|
+
const FIT_W = BOX_W - 2 * EDGE;
|
|
95
|
+
const FIT_H = BOX_H - 2 * EDGE;
|
|
96
|
+
|
|
97
|
+
const tiles = ref<HTMLButtonElement[]>([]);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The ratio in force, named only where there is one. A variant with no selection names nothing:
|
|
101
|
+
* falling back to `ratios[0]` put the first allowed ratio in the tile's name and in its meta row
|
|
102
|
+
* as if somebody had chosen it, which is the sibling of the check mark a tile must not draw for a
|
|
103
|
+
* variant it knows nothing about. A selection whose `ratio` matches no entry is the same case --
|
|
104
|
+
* `resolveSelection` cannot produce one, but this component is handed its maps by a caller.
|
|
105
|
+
*/
|
|
106
|
+
function ratioLabel(variant: CropVariant): string {
|
|
107
|
+
const selection = props.selections[variant.name];
|
|
108
|
+
if (!selection) return '';
|
|
109
|
+
return variant.ratios.find((r) => r.name === selection.ratio)?.label ?? '';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function isAuto(variant: CropVariant): boolean {
|
|
113
|
+
return props.selections[variant.name]?.auto === true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function tileName(variant: CropVariant): string {
|
|
117
|
+
const parts = [variant.label, ratioLabel(variant)];
|
|
118
|
+
if (isAuto(variant)) parts.push(props.labels.auto);
|
|
119
|
+
return parts.filter(Boolean).join(', ');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const px = (n: number) => `${Math.round(n * 100) / 100}px`;
|
|
123
|
+
|
|
124
|
+
interface Preview {
|
|
125
|
+
frame: Record<string, string>;
|
|
126
|
+
shown: Record<string, string>;
|
|
127
|
+
img: Record<string, string>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function computePreview(variant: CropVariant): Preview | null {
|
|
131
|
+
const s = props.selections[variant.name];
|
|
132
|
+
if (!s || s.rect.width <= 0 || s.rect.height <= 0 || props.frameAspect <= 0) return null;
|
|
133
|
+
const { rect } = s;
|
|
134
|
+
|
|
135
|
+
// The crop's own shape, fitted into the box.
|
|
136
|
+
const aspect = (rect.width / rect.height) * props.frameAspect;
|
|
137
|
+
const w = aspect >= FIT_W / FIT_H ? FIT_W : FIT_H * aspect;
|
|
138
|
+
const h = w / aspect;
|
|
139
|
+
|
|
140
|
+
// The whole displayed image, scaled so the rectangle's width fills the frame.
|
|
141
|
+
const shownW = w / rect.width;
|
|
142
|
+
const shownH = shownW / props.frameAspect;
|
|
143
|
+
|
|
144
|
+
// The original's own size: its sides swap after a quarter turn.
|
|
145
|
+
const quarter = props.rotate === 90 || props.rotate === 270;
|
|
146
|
+
const imgW = quarter ? shownH : shownW;
|
|
147
|
+
const imgH = quarter ? shownW : shownH;
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
frame: { width: px(w), height: px(h) },
|
|
151
|
+
shown: {
|
|
152
|
+
width: px(shownW),
|
|
153
|
+
height: px(shownH),
|
|
154
|
+
left: px(-rect.x * shownW),
|
|
155
|
+
top: px(-rect.y * shownH),
|
|
156
|
+
},
|
|
157
|
+
img: {
|
|
158
|
+
width: px(imgW),
|
|
159
|
+
height: px(imgH),
|
|
160
|
+
// Rightmost first: turn, then mirror, then centre.
|
|
161
|
+
transform: `translate(-50%, -50%) ${props.flip ? 'scaleX(-1) ' : ''}rotate(${props.rotate}deg)`,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** One preview per variant, computed once per change; absent when nothing is known about it. */
|
|
167
|
+
const previews = computed(() => {
|
|
168
|
+
const map: Record<string, Preview | null> = {};
|
|
169
|
+
for (const variant of props.variants) map[variant.name] = computePreview(variant);
|
|
170
|
+
return map;
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/** Arrow keys move the open variant (and focus) to the neighbour, wrapping at both ends. */
|
|
174
|
+
function onKey(event: KeyboardEvent, index: number) {
|
|
175
|
+
const step = event.key === 'ArrowDown' ? 1 : event.key === 'ArrowUp' ? -1 : 0;
|
|
176
|
+
if (step === 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
const count = props.variants.length;
|
|
179
|
+
const next = (index + step + count) % count;
|
|
180
|
+
emit('pick', props.variants[next]!.name);
|
|
181
|
+
tiles.value[next]?.focus();
|
|
182
|
+
}
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<template>
|
|
186
|
+
<!-- The width is the dialog's: it reserves this column before the strip is in it, so that
|
|
187
|
+
the stage is laid out at its final width from the first frame. -->
|
|
188
|
+
<div data-testid="crop-variant-strip" class="flex w-full flex-col gap-2">
|
|
189
|
+
<div class="text-muted-foreground text-xs font-semibold tracking-wider uppercase">
|
|
190
|
+
{{ labels.variants }}
|
|
191
|
+
</div>
|
|
192
|
+
<div role="tablist" :aria-label="labels.variants" class="flex flex-col gap-2">
|
|
193
|
+
<!-- The tiles list is static while open, so the positional `ref` array stays aligned. -->
|
|
194
|
+
<button
|
|
195
|
+
v-for="(variant, index) in variants"
|
|
196
|
+
:id="tabIds?.[index]"
|
|
197
|
+
:key="variant.name"
|
|
198
|
+
ref="tiles"
|
|
199
|
+
type="button"
|
|
200
|
+
role="tab"
|
|
201
|
+
:aria-controls="ariaControls"
|
|
202
|
+
:aria-selected="variant.name === current"
|
|
203
|
+
:aria-label="tileName(variant)"
|
|
204
|
+
:tabindex="variant.name === current ? 0 : -1"
|
|
205
|
+
:style="{ gridTemplateColumns: `${px(BOX_W)} minmax(0, 1fr)` }"
|
|
206
|
+
:class="[
|
|
207
|
+
'bg-background text-foreground focus-visible:outline-ring grid w-full cursor-pointer items-center gap-3 rounded-md border p-2 text-left focus-visible:outline-2 focus-visible:outline-offset-2',
|
|
208
|
+
variant.name === current
|
|
209
|
+
? 'border-primary ring-primary ring-1'
|
|
210
|
+
: 'border-border hover:border-primary/45',
|
|
211
|
+
]"
|
|
212
|
+
@click="$emit('pick', variant.name)"
|
|
213
|
+
@keydown="onKey($event, index)"
|
|
214
|
+
>
|
|
215
|
+
<span
|
|
216
|
+
data-testid="crop-variant-preview"
|
|
217
|
+
:style="{ width: px(BOX_W), height: px(BOX_H), borderWidth: px(EDGE) }"
|
|
218
|
+
:class="[
|
|
219
|
+
'bg-muted box-border grid place-items-center overflow-hidden rounded-sm',
|
|
220
|
+
isAuto(variant)
|
|
221
|
+
? 'border-muted-foreground border-dashed'
|
|
222
|
+
: 'border-transparent border-solid',
|
|
223
|
+
]"
|
|
224
|
+
>
|
|
225
|
+
<span
|
|
226
|
+
v-if="previews[variant.name]"
|
|
227
|
+
data-testid="crop-variant-frame"
|
|
228
|
+
class="relative block overflow-hidden"
|
|
229
|
+
:style="previews[variant.name]!.frame"
|
|
230
|
+
>
|
|
231
|
+
<span
|
|
232
|
+
data-testid="crop-variant-shown"
|
|
233
|
+
class="absolute block"
|
|
234
|
+
:style="previews[variant.name]!.shown"
|
|
235
|
+
>
|
|
236
|
+
<img
|
|
237
|
+
:src="src"
|
|
238
|
+
alt=""
|
|
239
|
+
draggable="false"
|
|
240
|
+
class="absolute top-1/2 left-1/2 block max-w-none"
|
|
241
|
+
:style="previews[variant.name]!.img"
|
|
242
|
+
/>
|
|
243
|
+
</span>
|
|
244
|
+
</span>
|
|
245
|
+
</span>
|
|
246
|
+
<span class="grid min-w-0 gap-0.5" aria-hidden="true">
|
|
247
|
+
<span
|
|
248
|
+
data-testid="crop-variant-label"
|
|
249
|
+
class="truncate text-sm leading-tight font-semibold"
|
|
250
|
+
>
|
|
251
|
+
{{ variant.label }}
|
|
252
|
+
</span>
|
|
253
|
+
<span
|
|
254
|
+
class="text-muted-foreground flex flex-wrap items-center gap-x-1 text-xs tabular-nums"
|
|
255
|
+
>
|
|
256
|
+
<span>{{ ratioLabel(variant) }}</span>
|
|
257
|
+
<span v-if="isAuto(variant)" class="text-[10px] font-bold tracking-wide">
|
|
258
|
+
{{ labels.auto }}
|
|
259
|
+
</span>
|
|
260
|
+
<svg
|
|
261
|
+
v-else-if="previews[variant.name]"
|
|
262
|
+
class="text-primary size-3"
|
|
263
|
+
viewBox="0 0 12 12"
|
|
264
|
+
fill="none"
|
|
265
|
+
stroke="currentColor"
|
|
266
|
+
stroke-width="2"
|
|
267
|
+
stroke-linecap="round"
|
|
268
|
+
stroke-linejoin="round"
|
|
269
|
+
>
|
|
270
|
+
<path d="M2.5 6.5l2.5 2.5 4.5-5.5" />
|
|
271
|
+
</svg>
|
|
272
|
+
</span>
|
|
273
|
+
</span>
|
|
274
|
+
</button>
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
</template>
|