zabi-components 8.0.0 → 8.1.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/CHANGELOG.md +1924 -0
- package/README.md +243 -10
- package/THEME.md +149 -332
- package/THEMING.md +1192 -266
- package/dist/atoms/ActionPanel.svelte +15 -5
- package/dist/atoms/Avatar.svelte +104 -0
- package/dist/atoms/Avatar.svelte.d.ts +34 -0
- package/dist/atoms/Badge.svelte +36 -7
- package/dist/atoms/Badge.svelte.d.ts +2 -2
- package/dist/atoms/Button.svelte +177 -27
- package/dist/atoms/Button.svelte.d.ts +30 -2
- package/dist/atoms/Card.svelte +4 -4
- package/dist/atoms/CardHeader.svelte +16 -4
- package/dist/atoms/Checkbox.svelte +48 -21
- package/dist/atoms/Checkbox.svelte.d.ts +4 -2
- package/dist/atoms/CodeBlock.svelte +20 -2
- package/dist/atoms/CodeBlock.svelte.d.ts +4 -0
- package/dist/atoms/ColorPicker.svelte +259 -49
- package/dist/atoms/ColorPicker.svelte.d.ts +3 -0
- package/dist/atoms/Container.svelte +16 -8
- package/dist/atoms/DateField.svelte +107 -0
- package/dist/atoms/DateField.svelte.d.ts +53 -0
- package/dist/atoms/FieldMessages.svelte +69 -0
- package/dist/atoms/FieldMessages.svelte.d.ts +23 -0
- package/dist/atoms/FloatingActionButton.svelte +174 -0
- package/dist/atoms/FloatingActionButton.svelte.d.ts +51 -0
- package/dist/atoms/Heading.svelte +37 -5
- package/dist/atoms/Heading.svelte.d.ts +7 -0
- package/dist/atoms/IconButton.svelte +220 -24
- package/dist/atoms/IconButton.svelte.d.ts +49 -4
- package/dist/atoms/Input.svelte +253 -52
- package/dist/atoms/Input.svelte.d.ts +32 -2
- package/dist/atoms/List.svelte +4 -1
- package/dist/atoms/ListItem.svelte +44 -11
- package/dist/atoms/ListItem.svelte.d.ts +5 -0
- package/dist/atoms/Progress.svelte +27 -8
- package/dist/atoms/Progress.svelte.d.ts +4 -0
- package/dist/atoms/Radio.svelte +19 -3
- package/dist/atoms/Radio.svelte.d.ts +4 -2
- package/dist/atoms/Rating.svelte +494 -0
- package/dist/atoms/Rating.svelte.d.ts +56 -0
- package/dist/atoms/Select.svelte +433 -91
- package/dist/atoms/Select.svelte.d.ts +49 -3
- package/dist/atoms/SelectionControl.svelte +94 -17
- package/dist/atoms/SelectionControl.svelte.d.ts +4 -3
- package/dist/atoms/Skeleton.svelte +1 -1
- package/dist/atoms/Slider.svelte +309 -0
- package/dist/atoms/Slider.svelte.d.ts +40 -0
- package/dist/atoms/Spinner.svelte +57 -0
- package/dist/atoms/Spinner.svelte.d.ts +19 -0
- package/dist/atoms/Table.svelte +151 -6
- package/dist/atoms/Table.svelte.d.ts +15 -3
- package/dist/atoms/TemporalField.svelte +140 -0
- package/dist/atoms/TemporalField.svelte.d.ts +32 -0
- package/dist/atoms/Text.svelte +23 -11
- package/dist/atoms/Text.svelte.d.ts +6 -3
- package/dist/atoms/Textarea.svelte +55 -44
- package/dist/atoms/Textarea.svelte.d.ts +14 -2
- package/dist/atoms/ThemeToggle.svelte +223 -44
- package/dist/atoms/ThemeToggle.svelte.d.ts +26 -3
- package/dist/atoms/TimeField.svelte +108 -0
- package/dist/atoms/TimeField.svelte.d.ts +54 -0
- package/dist/atoms/Toast.svelte +17 -4
- package/dist/atoms/Toast.svelte.d.ts +2 -0
- package/dist/atoms/Toggle.svelte +41 -8
- package/dist/atoms/Toggle.svelte.d.ts +11 -2
- package/dist/atoms/Tooltip.svelte +508 -23
- package/dist/atoms/Tooltip.svelte.d.ts +11 -0
- package/dist/atoms/ZabiStringsProvider.svelte +45 -0
- package/dist/atoms/ZabiStringsProvider.svelte.d.ts +27 -0
- package/dist/atoms/index.d.ts +17 -0
- package/dist/atoms/index.js +12 -0
- package/dist/atoms/selection-control.styles.d.ts +36 -5
- package/dist/atoms/selection-control.styles.js +40 -9
- package/dist/components/atoms/index.d.ts +17 -0
- package/dist/components/atoms/index.d.ts.map +1 -1
- package/dist/components/atoms/selection-control.styles.d.ts +36 -5
- package/dist/components/atoms/selection-control.styles.d.ts.map +1 -1
- package/dist/components/index.d.ts +80 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/molecules/index.d.ts +46 -0
- package/dist/components/molecules/index.d.ts.map +1 -1
- package/dist/components/molecules/toast-store.d.ts +53 -7
- package/dist/components/molecules/toast-store.d.ts.map +1 -1
- package/dist/components/organisms/index.d.ts +5 -0
- package/dist/components/organisms/index.d.ts.map +1 -1
- package/dist/components/types/variants.d.ts +15 -1
- package/dist/components/types/variants.d.ts.map +1 -1
- package/dist/components/util/app-shell.d.ts +28 -0
- package/dist/components/util/app-shell.d.ts.map +1 -0
- package/dist/components/util/avatar.d.ts +36 -0
- package/dist/components/util/avatar.d.ts.map +1 -0
- package/dist/components/util/bottom-sheet.d.ts +30 -0
- package/dist/components/util/bottom-sheet.d.ts.map +1 -0
- package/dist/components/util/bottom-tab-bar.d.ts +35 -0
- package/dist/components/util/bottom-tab-bar.d.ts.map +1 -0
- package/dist/components/util/calendar.d.ts +56 -0
- package/dist/components/util/calendar.d.ts.map +1 -0
- package/dist/components/util/collapsible.d.ts +58 -0
- package/dist/components/util/collapsible.d.ts.map +1 -0
- package/dist/components/util/confirm-dialog.d.ts +12 -0
- package/dist/components/util/confirm-dialog.d.ts.map +1 -0
- package/dist/components/util/date.d.ts +96 -0
- package/dist/components/util/date.d.ts.map +1 -0
- package/dist/components/util/drawer.d.ts +13 -0
- package/dist/components/util/drawer.d.ts.map +1 -0
- package/dist/components/util/dropdown.d.ts +47 -0
- package/dist/components/util/dropdown.d.ts.map +1 -0
- package/dist/components/util/field.d.ts +39 -0
- package/dist/components/util/field.d.ts.map +1 -0
- package/dist/components/util/fit-in-viewport.d.ts +201 -0
- package/dist/components/util/fit-in-viewport.d.ts.map +1 -0
- package/dist/components/util/focus-utils.d.ts +75 -2
- package/dist/components/util/focus-utils.d.ts.map +1 -1
- package/dist/components/util/hydration.d.ts +45 -0
- package/dist/components/util/hydration.d.ts.map +1 -0
- package/dist/components/util/keyboard-inset.d.ts +18 -0
- package/dist/components/util/keyboard-inset.d.ts.map +1 -0
- package/dist/components/util/media-grid.d.ts +51 -0
- package/dist/components/util/media-grid.d.ts.map +1 -0
- package/dist/components/util/media.d.ts +6 -0
- package/dist/components/util/media.d.ts.map +1 -0
- package/dist/components/util/overlay-chrome.d.ts +53 -0
- package/dist/components/util/overlay-chrome.d.ts.map +1 -0
- package/dist/components/util/overlay.d.ts +72 -0
- package/dist/components/util/overlay.d.ts.map +1 -0
- package/dist/components/util/photo.d.ts +215 -0
- package/dist/components/util/photo.d.ts.map +1 -0
- package/dist/components/util/portal.d.ts +23 -0
- package/dist/components/util/portal.d.ts.map +1 -0
- package/dist/components/util/pull-to-refresh.d.ts +27 -0
- package/dist/components/util/pull-to-refresh.d.ts.map +1 -0
- package/dist/components/util/radio-keys.d.ts +25 -0
- package/dist/components/util/radio-keys.d.ts.map +1 -0
- package/dist/components/util/rating.d.ts +23 -0
- package/dist/components/util/rating.d.ts.map +1 -0
- package/dist/components/util/ready-made-strings.d.ts +77 -0
- package/dist/components/util/ready-made-strings.d.ts.map +1 -0
- package/dist/components/util/scroll-padding.d.ts +20 -0
- package/dist/components/util/scroll-padding.d.ts.map +1 -0
- package/dist/components/util/segmented-control.d.ts +16 -0
- package/dist/components/util/segmented-control.d.ts.map +1 -0
- package/dist/components/util/select.d.ts +41 -0
- package/dist/components/util/select.d.ts.map +1 -0
- package/dist/components/util/sheet-drag.d.ts +60 -0
- package/dist/components/util/sheet-drag.d.ts.map +1 -0
- package/dist/components/util/sidebar.d.ts +63 -0
- package/dist/components/util/sidebar.d.ts.map +1 -0
- package/dist/components/util/sortable-list.d.ts +65 -0
- package/dist/components/util/sortable-list.d.ts.map +1 -0
- package/dist/components/util/stepper.d.ts +40 -0
- package/dist/components/util/stepper.d.ts.map +1 -0
- package/dist/components/util/swipeable-list-item.d.ts +36 -0
- package/dist/components/util/swipeable-list-item.d.ts.map +1 -0
- package/dist/components/util/theme-mode.d.ts +80 -0
- package/dist/components/util/theme-mode.d.ts.map +1 -0
- package/dist/components/util/toaster.d.ts +93 -0
- package/dist/components/util/toaster.d.ts.map +1 -0
- package/dist/components/util/tooltip.d.ts +10 -0
- package/dist/components/util/tooltip.d.ts.map +1 -0
- package/dist/components/util/top-navbar.d.ts +11 -0
- package/dist/components/util/top-navbar.d.ts.map +1 -0
- package/dist/components/util/touch-target.d.ts +31 -0
- package/dist/components/util/touch-target.d.ts.map +1 -0
- package/dist/components/util/zabi-strings.d.ts +133 -0
- package/dist/components/util/zabi-strings.d.ts.map +1 -0
- package/dist/create-theme/cli.js +169 -0
- package/dist/create-theme/index.d.ts +176 -0
- package/dist/create-theme/index.js +817 -0
- package/dist/create-theme/lib/ramp-math.js +128 -0
- package/dist/create-theme/lib/resolve.js +141 -0
- package/dist/create-theme/theme-data.js +1116 -0
- package/dist/index.d.ts +80 -2
- package/dist/index.js +57 -2
- package/dist/molecules/Alert.svelte +33 -5
- package/dist/molecules/Alert.svelte.d.ts +2 -0
- package/dist/molecules/AppBar.svelte +415 -0
- package/dist/molecules/AppBar.svelte.d.ts +69 -0
- package/dist/molecules/AvatarGroup.svelte +116 -0
- package/dist/molecules/AvatarGroup.svelte.d.ts +40 -0
- package/dist/molecules/BottomSheet.svelte +540 -0
- package/dist/molecules/BottomSheet.svelte.d.ts +93 -0
- package/dist/molecules/BottomTabBar.svelte +297 -0
- package/dist/molecules/BottomTabBar.svelte.d.ts +64 -0
- package/dist/molecules/Calendar.svelte +597 -0
- package/dist/molecules/Calendar.svelte.d.ts +72 -0
- package/dist/molecules/Collapsible.svelte +243 -0
- package/dist/molecules/Collapsible.svelte.d.ts +44 -0
- package/dist/molecules/CollapsibleGroup.svelte +126 -0
- package/dist/molecules/CollapsibleGroup.svelte.d.ts +14 -0
- package/dist/molecules/ComponentDemo.svelte +16 -4
- package/dist/molecules/ComponentDemo.svelte.d.ts +3 -0
- package/dist/molecules/ConfirmDialog.svelte +253 -0
- package/dist/molecules/ConfirmDialog.svelte.d.ts +55 -0
- package/dist/molecules/ContactForm.svelte +34 -17
- package/dist/molecules/ContactForm.svelte.d.ts +8 -0
- package/dist/molecules/Drawer.svelte +394 -0
- package/dist/molecules/Drawer.svelte.d.ts +55 -0
- package/dist/molecules/Dropdown.svelte +509 -48
- package/dist/molecules/Dropdown.svelte.d.ts +45 -6
- package/dist/molecules/DropdownItem.svelte +122 -0
- package/dist/molecules/DropdownItem.svelte.d.ts +28 -0
- package/dist/molecules/EmptyState.svelte +55 -10
- package/dist/molecules/EmptyState.svelte.d.ts +8 -0
- package/dist/molecules/FormField.svelte +9 -1
- package/dist/molecules/FormField.svelte.d.ts +2 -0
- package/dist/molecules/Header.svelte +1 -1
- package/dist/molecules/ImageUpload.svelte +383 -70
- package/dist/molecules/ImageUpload.svelte.d.ts +47 -2
- package/dist/molecules/MediaGrid.svelte +527 -0
- package/dist/molecules/MediaGrid.svelte.d.ts +77 -0
- package/dist/molecules/Modal.svelte +288 -72
- package/dist/molecules/Modal.svelte.d.ts +51 -2
- package/dist/molecules/NavigationMenuContent.svelte +58 -1
- package/dist/molecules/NavigationMenuItem.svelte +0 -1
- package/dist/molecules/NavigationMenuLink.svelte +1 -1
- package/dist/molecules/NavigationMenuList.svelte +10 -3
- package/dist/molecules/NavigationMenuTrigger.svelte +2 -2
- package/dist/molecules/Page.svelte +32 -2
- package/dist/molecules/Page.svelte.d.ts +11 -0
- package/dist/molecules/PhotoGrid.svelte +433 -0
- package/dist/molecules/PhotoGrid.svelte.d.ts +62 -0
- package/dist/molecules/PhotoViewer.svelte +1116 -0
- package/dist/molecules/PhotoViewer.svelte.d.ts +56 -0
- package/dist/molecules/PropsTable.svelte +22 -10
- package/dist/molecules/PropsTable.svelte.d.ts +3 -0
- package/dist/molecules/PullToRefresh.svelte +263 -0
- package/dist/molecules/PullToRefresh.svelte.d.ts +52 -0
- package/dist/molecules/RadioGroup.svelte +52 -14
- package/dist/molecules/RadioGroup.svelte.d.ts +14 -3
- package/dist/molecules/Section.svelte +1 -1
- package/dist/molecules/SegmentedControl.svelte +323 -0
- package/dist/molecules/SegmentedControl.svelte.d.ts +34 -0
- package/dist/molecules/SidebarBrandHeader.svelte +11 -1
- package/dist/molecules/SidebarBrandHeader.svelte.d.ts +3 -0
- package/dist/molecules/SidebarFooter.svelte +29 -6
- package/dist/molecules/SidebarFooter.svelte.d.ts +3 -0
- package/dist/molecules/SlideUp.svelte +220 -61
- package/dist/molecules/SlideUp.svelte.d.ts +26 -0
- package/dist/molecules/SortableList.svelte +632 -0
- package/dist/molecules/SortableList.svelte.d.ts +69 -0
- package/dist/molecules/Stepper.svelte +548 -0
- package/dist/molecules/Stepper.svelte.d.ts +39 -0
- package/dist/molecules/StickyActionBar.svelte +191 -0
- package/dist/molecules/StickyActionBar.svelte.d.ts +65 -0
- package/dist/molecules/SwipeableListItem.svelte +334 -0
- package/dist/molecules/SwipeableListItem.svelte.d.ts +54 -0
- package/dist/molecules/Tabs.svelte +233 -9
- package/dist/molecules/Tabs.svelte.d.ts +7 -0
- package/dist/molecules/Toaster.svelte +350 -5
- package/dist/molecules/Toaster.svelte.d.ts +95 -2
- package/dist/molecules/ToasterToast.svelte +253 -67
- package/dist/molecules/ToasterToast.svelte.d.ts +9 -0
- package/dist/molecules/UnsavedChangesBar.svelte +212 -0
- package/dist/molecules/UnsavedChangesBar.svelte.d.ts +43 -0
- package/dist/molecules/index.d.ts +46 -0
- package/dist/molecules/index.js +27 -0
- package/dist/molecules/toast-store.d.ts +53 -7
- package/dist/molecules/toast-store.js +21 -0
- package/dist/organisms/AppShell.svelte +196 -0
- package/dist/organisms/AppShell.svelte.d.ts +61 -0
- package/dist/organisms/SidebarAccountPanel.svelte +107 -12
- package/dist/organisms/SidebarAccountPanel.svelte.d.ts +19 -0
- package/dist/organisms/SidebarNavigation.svelte +96 -15
- package/dist/organisms/SidebarNavigation.svelte.d.ts +29 -1
- package/dist/organisms/SidebarPanel.svelte +31 -10
- package/dist/organisms/SidebarShell.svelte +162 -11
- package/dist/organisms/SidebarShell.svelte.d.ts +56 -2
- package/dist/organisms/TopNavbar.svelte +256 -31
- package/dist/organisms/TopNavbar.svelte.d.ts +26 -0
- package/dist/organisms/index.d.ts +5 -0
- package/dist/organisms/index.js +3 -0
- package/dist/types/components.d.ts +4 -0
- package/dist/types/components.d.ts.map +1 -1
- package/dist/types/index.d.ts +605 -25
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/variants.ts +17 -1
- package/dist/util/app-shell.d.ts +27 -0
- package/dist/util/app-shell.js +72 -0
- package/dist/util/avatar.d.ts +35 -0
- package/dist/util/avatar.js +52 -0
- package/dist/util/bottom-sheet.d.ts +29 -0
- package/dist/util/bottom-sheet.js +43 -0
- package/dist/util/bottom-tab-bar.d.ts +34 -0
- package/dist/util/bottom-tab-bar.js +54 -0
- package/dist/util/calendar.d.ts +55 -0
- package/dist/util/calendar.js +74 -0
- package/dist/util/collapsible.d.ts +57 -0
- package/dist/util/collapsible.js +23 -0
- package/dist/util/confirm-dialog.d.ts +11 -0
- package/dist/util/confirm-dialog.js +2 -0
- package/dist/util/date.d.ts +95 -0
- package/dist/util/date.js +237 -0
- package/dist/util/drawer.d.ts +12 -0
- package/dist/util/drawer.js +7 -0
- package/dist/util/dropdown.d.ts +46 -0
- package/dist/util/dropdown.js +21 -0
- package/dist/util/field.d.ts +38 -0
- package/dist/util/field.js +38 -0
- package/dist/util/fit-in-viewport.d.ts +200 -0
- package/dist/util/fit-in-viewport.js +399 -0
- package/dist/util/focus-utils.d.ts +75 -2
- package/dist/util/focus-utils.js +182 -9
- package/dist/util/hydration.d.ts +44 -0
- package/dist/util/hydration.js +58 -0
- package/dist/util/keyboard-inset.d.ts +17 -0
- package/dist/util/keyboard-inset.js +53 -0
- package/dist/util/media-grid.d.ts +50 -0
- package/dist/util/media-grid.js +81 -0
- package/dist/util/media.d.ts +5 -0
- package/dist/util/media.js +10 -0
- package/dist/util/overlay-chrome.d.ts +52 -0
- package/dist/util/overlay-chrome.js +56 -0
- package/dist/util/overlay.d.ts +71 -0
- package/dist/util/overlay.js +240 -0
- package/dist/util/photo.d.ts +214 -0
- package/dist/util/photo.js +206 -0
- package/dist/util/portal.d.ts +22 -0
- package/dist/util/portal.js +50 -0
- package/dist/util/pull-to-refresh.d.ts +26 -0
- package/dist/util/pull-to-refresh.js +30 -0
- package/dist/util/radio-keys.d.ts +24 -0
- package/dist/util/radio-keys.js +49 -0
- package/dist/util/rating.d.ts +22 -0
- package/dist/util/rating.js +26 -0
- package/dist/util/ready-made-strings.d.ts +76 -0
- package/dist/util/ready-made-strings.js +67 -0
- package/dist/util/scroll-padding.d.ts +19 -0
- package/dist/util/scroll-padding.js +44 -0
- package/dist/util/segmented-control.d.ts +15 -0
- package/dist/util/segmented-control.js +1 -0
- package/dist/util/select.d.ts +40 -0
- package/dist/util/select.js +63 -0
- package/dist/util/sheet-drag.d.ts +59 -0
- package/dist/util/sheet-drag.js +241 -0
- package/dist/util/sidebar.d.ts +62 -0
- package/dist/util/sidebar.js +38 -0
- package/dist/util/sortable-list.d.ts +64 -0
- package/dist/util/sortable-list.js +53 -0
- package/dist/util/stepper.d.ts +39 -0
- package/dist/util/stepper.js +38 -0
- package/dist/util/swipeable-list-item.d.ts +35 -0
- package/dist/util/swipeable-list-item.js +32 -0
- package/dist/util/theme-mode.d.ts +79 -0
- package/dist/util/theme-mode.js +121 -0
- package/dist/util/toaster.d.ts +92 -0
- package/dist/util/toaster.js +75 -0
- package/dist/util/tooltip.d.ts +9 -0
- package/dist/util/tooltip.js +18 -0
- package/dist/util/top-navbar.d.ts +10 -0
- package/dist/util/top-navbar.js +5 -0
- package/dist/util/touch-target.d.ts +30 -0
- package/dist/util/touch-target.js +30 -0
- package/dist/util/zabi-strings.d.ts +132 -0
- package/dist/util/zabi-strings.js +105 -0
- package/dist/zabi-components-colors.css +5 -2
- package/dist/zabi-components-theme-dark-only.css +543 -241
- package/dist/zabi-components-theme-dark.css +543 -241
- package/dist/zabi-components-theme-only.css +1584 -367
- package/dist/zabi-components-theme.css +1584 -367
- package/dist/zabi-components.css +3885 -518
- package/docs/lucide-icons.md +40 -17
- package/docs/theme-imports.md +81 -11
- package/package.json +35 -8
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chrome of an overlay at large text: the header of a BottomSheet, Drawer,
|
|
3
|
+
* Modal or SlideUp, and the padding of its footer.
|
|
4
|
+
*
|
|
5
|
+
* Tailwind's spacing is in rem, so at `html { font-size: 200% }` the gutters,
|
|
6
|
+
* the gap above the title, the title and the close button all doubled. On a
|
|
7
|
+
* phone that left a third of a half-height sheet to what the sheet was opened
|
|
8
|
+
* for. This is navigation chrome, as the app bar is (see AppBar): it says
|
|
9
|
+
* where you are and how to leave, and it is not what the user enlarged the
|
|
10
|
+
* text to read. So it is laid out in px, and its title grows to 1.3 times its
|
|
11
|
+
* size and stops. The content, and whatever the app puts in the footer, scale
|
|
12
|
+
* in full. docs/ACCESSIBILITY.md has the reasoning against WCAG 1.4.4.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* On the header box: the spacing scale in px for everything inside it, so
|
|
16
|
+
* `px-6`, `gap-4`, `size-8` and the 44px of `TOUCH_HIT_AREA` are the sizes
|
|
17
|
+
* they are at 100% text. Only for a box that holds chrome alone: an app's
|
|
18
|
+
* Button inside it would stop growing too, which is why a footer spells its
|
|
19
|
+
* padding out in px instead.
|
|
20
|
+
*/
|
|
21
|
+
export const OVERLAY_CHROME = "[--spacing:4px]";
|
|
22
|
+
/**
|
|
23
|
+
* How a title wraps: onto as many lines as it needs, between words, and a
|
|
24
|
+
* word wider than the whole line is cut rather than left sticking out.
|
|
25
|
+
*/
|
|
26
|
+
export const OVERLAY_TITLE_WRAP = "[overflow-wrap:break-word]";
|
|
27
|
+
/**
|
|
28
|
+
* On the title while the text is enlarged (`textIsEnlarged`): a word that does
|
|
29
|
+
* not fit at the end of a line is hyphenated by the rules of the page's
|
|
30
|
+
* `lang`, where the browser has them, before it is cut.
|
|
31
|
+
*
|
|
32
|
+
* Not at the default text size, and not narrowed with `hyphenate-limit-chars`:
|
|
33
|
+
* `hyphens: auto` hyphenates at the end of every line, not only where a word
|
|
34
|
+
* is too wide, and what a browser offers as a hyphenation point is the
|
|
35
|
+
* platform's ("sett-ings", "histor-y" in Chromium on macOS). A title that
|
|
36
|
+
* wraps between words today would get those. A limit, where it is supported
|
|
37
|
+
* at all (not in Safari), turns a hyphenated break of a shorter word into a
|
|
38
|
+
* plain cut.
|
|
39
|
+
*/
|
|
40
|
+
export const OVERLAY_TITLE_HYPHENS = "hyphens-auto";
|
|
41
|
+
/**
|
|
42
|
+
* Whether the reader has enlarged the text: the root font size is above the
|
|
43
|
+
* 16px every browser starts from. Read when an overlay opens. False on the
|
|
44
|
+
* server and until then, which is the layout at the default size.
|
|
45
|
+
*/
|
|
46
|
+
export function textIsEnlarged() {
|
|
47
|
+
if (typeof document === "undefined")
|
|
48
|
+
return false;
|
|
49
|
+
return parseFloat(getComputedStyle(document.documentElement).fontSize) > 16;
|
|
50
|
+
}
|
|
51
|
+
/** A title of 20px (`text-xl`): up to 26px, on the same 1.4 line. */
|
|
52
|
+
export const OVERLAY_TITLE_XL = "text-[length:min(1.25rem,26px)] leading-[1.4]";
|
|
53
|
+
/** A title of 24px (`text-2xl`): up to 31.2px, on the same 4/3 line. */
|
|
54
|
+
export const OVERLAY_TITLE_2XL = "text-[length:min(1.5rem,31.2px)] leading-[calc(4/3)]";
|
|
55
|
+
/** The "×" of a close button: a control, so the size it is at 100%. */
|
|
56
|
+
export const OVERLAY_CLOSE_GLYPH = "text-[24px] leading-[32px]";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Modal, SlideUp and Drawer share beyond `focus-utils.ts`: the scroll
|
|
3
|
+
* lock on `<body>` and the Tab cycle inside the panel. One copy, so the
|
|
4
|
+
* overlays cannot drift apart and keep working when nested in any order.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Stops the page behind an overlay from scrolling. Ref-counted on `<body>`
|
|
8
|
+
* (`data-zabi-scroll-lock`), so nested overlays share one lock and the page
|
|
9
|
+
* scrolls again only when the last one has released it.
|
|
10
|
+
*
|
|
11
|
+
* Call it when the overlay opens, in the browser, and call the returned
|
|
12
|
+
* function when it closes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function lockBodyScroll(): () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Keeps Tab inside `container`: call it from the panel's `keydown` handler.
|
|
17
|
+
* Focusables are re-queried on every Tab, so content added while the overlay
|
|
18
|
+
* is open stays inside the cycle. A Tab that comes from a dialog nested in the
|
|
19
|
+
* container is left to that dialog. The toasts on screen are in the cycle too,
|
|
20
|
+
* after the container's own controls: see `getToastFocusables`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function trapTabKey(container: HTMLElement | undefined, event: KeyboardEvent): void;
|
|
23
|
+
/**
|
|
24
|
+
* Watches a scrolling box in an overlay and reports whether it has to be a
|
|
25
|
+
* Tab stop itself: true when its content is taller than it and holds nothing
|
|
26
|
+
* that can take focus, so the keyboard would otherwise have no way to scroll
|
|
27
|
+
* it. The answer changes with the viewport and with the content, so it is
|
|
28
|
+
* reported again whenever either does.
|
|
29
|
+
*
|
|
30
|
+
* Call it when the overlay opens, in the browser; the returned function stops it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function watchScrollerNeedsFocus(box: HTMLElement, onChange: (needsFocus: boolean) => void): () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Keeps an overlay on the part of the screen the on-screen keyboard leaves.
|
|
35
|
+
*
|
|
36
|
+
* Where the keyboard covers the page instead of shrinking it (iOS Safari,
|
|
37
|
+
* Chrome on Android), a panel at the bottom of a `fixed inset-0` root ends up
|
|
38
|
+
* behind it, footer and all. This moves the root's bottom edge up to the top
|
|
39
|
+
* of the keyboard (and its top edge down, if the browser has panned the
|
|
40
|
+
* screen), so everything laid out against the root follows: a sheet's height,
|
|
41
|
+
* a pinned footer, a drawer's end. `data-keyboard-open` is set on the root
|
|
42
|
+
* meanwhile. The field that has focus is scrolled back into view once the
|
|
43
|
+
* root has its new size. Where the page shrinks by itself, nothing is done.
|
|
44
|
+
*
|
|
45
|
+
* The root is usually the backdrop as well: while it is moved, its dimming is
|
|
46
|
+
* carried on past its edges, so the page does not show undimmed where the
|
|
47
|
+
* keyboard was while that slides away.
|
|
48
|
+
*
|
|
49
|
+
* `root` is the overlay's outermost, fixed element. Call it when the overlay
|
|
50
|
+
* opens, in the browser; the returned function stops it and puts the root back.
|
|
51
|
+
*/
|
|
52
|
+
export declare function followKeyboard(root: HTMLElement): () => void;
|
|
53
|
+
/**
|
|
54
|
+
* Says that `footer` is pinned to the bottom of an open overlay, so what is
|
|
55
|
+
* drawn over the overlays (the toast stack) can stay off it. Call it when the
|
|
56
|
+
* footer is rendered, in the browser; the returned function withdraws it.
|
|
57
|
+
*/
|
|
58
|
+
export declare function registerOverlayFooter(footer: HTMLElement): () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Says that `header` is the top of an open overlay and holds its close
|
|
61
|
+
* button, so the toast stack starts below it and never lies over the one
|
|
62
|
+
* control that always closes the overlay. Call it when the header is
|
|
63
|
+
* rendered, in the browser; the returned function withdraws it.
|
|
64
|
+
*/
|
|
65
|
+
export declare function registerOverlayHeader(header: HTMLElement): () => void;
|
|
66
|
+
/** The footer of the overlay on top, if it has one. */
|
|
67
|
+
export declare function topOverlayFooter(): HTMLElement | null;
|
|
68
|
+
/** The header of the overlay on top, if it has one. */
|
|
69
|
+
export declare function topOverlayHeader(): HTMLElement | null;
|
|
70
|
+
/** Calls `listener` whenever a registered header or footer appears, goes, moves or changes size. */
|
|
71
|
+
export declare function watchOverlayFooters(listener: () => void): () => void;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Modal, SlideUp and Drawer share beyond `focus-utils.ts`: the scroll
|
|
3
|
+
* lock on `<body>` and the Tab cycle inside the panel. One copy, so the
|
|
4
|
+
* overlays cannot drift apart and keep working when nested in any order.
|
|
5
|
+
*/
|
|
6
|
+
import { cycleTrappedFocus, DIALOG_SELECTOR, getFocusableElements } from "./focus-utils.js";
|
|
7
|
+
import { readKeyboardInset } from "./keyboard-inset.js";
|
|
8
|
+
/**
|
|
9
|
+
* Stops the page behind an overlay from scrolling. Ref-counted on `<body>`
|
|
10
|
+
* (`data-zabi-scroll-lock`), so nested overlays share one lock and the page
|
|
11
|
+
* scrolls again only when the last one has released it.
|
|
12
|
+
*
|
|
13
|
+
* Call it when the overlay opens, in the browser, and call the returned
|
|
14
|
+
* function when it closes.
|
|
15
|
+
*/
|
|
16
|
+
export function lockBodyScroll() {
|
|
17
|
+
const body = document.body;
|
|
18
|
+
const count = Number(body.dataset.zabiScrollLock ?? "0");
|
|
19
|
+
if (count === 0) {
|
|
20
|
+
body.dataset.zabiScrollLockOverflow = body.style.overflow;
|
|
21
|
+
body.style.overflow = "hidden";
|
|
22
|
+
}
|
|
23
|
+
body.dataset.zabiScrollLock = String(count + 1);
|
|
24
|
+
return () => {
|
|
25
|
+
const next = Number(body.dataset.zabiScrollLock ?? "1") - 1;
|
|
26
|
+
if (next <= 0) {
|
|
27
|
+
body.style.overflow = body.dataset.zabiScrollLockOverflow ?? "";
|
|
28
|
+
delete body.dataset.zabiScrollLock;
|
|
29
|
+
delete body.dataset.zabiScrollLockOverflow;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
body.dataset.zabiScrollLock = String(next);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Keeps Tab inside `container`: call it from the panel's `keydown` handler.
|
|
38
|
+
* Focusables are re-queried on every Tab, so content added while the overlay
|
|
39
|
+
* is open stays inside the cycle. A Tab that comes from a dialog nested in the
|
|
40
|
+
* container is left to that dialog. The toasts on screen are in the cycle too,
|
|
41
|
+
* after the container's own controls: see `getToastFocusables`.
|
|
42
|
+
*/
|
|
43
|
+
export function trapTabKey(container, event) {
|
|
44
|
+
if (event.key !== "Tab" || !container)
|
|
45
|
+
return;
|
|
46
|
+
// A nested dialog handles its own Tab cycle.
|
|
47
|
+
const owner = event.target?.closest?.(DIALOG_SELECTOR);
|
|
48
|
+
if (owner && owner !== container)
|
|
49
|
+
return;
|
|
50
|
+
cycleTrappedFocus(container, event);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Watches a scrolling box in an overlay and reports whether it has to be a
|
|
54
|
+
* Tab stop itself: true when its content is taller than it and holds nothing
|
|
55
|
+
* that can take focus, so the keyboard would otherwise have no way to scroll
|
|
56
|
+
* it. The answer changes with the viewport and with the content, so it is
|
|
57
|
+
* reported again whenever either does.
|
|
58
|
+
*
|
|
59
|
+
* Call it when the overlay opens, in the browser; the returned function stops it.
|
|
60
|
+
*/
|
|
61
|
+
export function watchScrollerNeedsFocus(box, onChange) {
|
|
62
|
+
const measure = () => {
|
|
63
|
+
onChange(box.scrollHeight > box.clientHeight && getFocusableElements(box).length === 0);
|
|
64
|
+
};
|
|
65
|
+
measure();
|
|
66
|
+
const resize = typeof ResizeObserver === "function" ? new ResizeObserver(measure) : undefined;
|
|
67
|
+
resize?.observe(box);
|
|
68
|
+
const mutation = new MutationObserver(measure);
|
|
69
|
+
mutation.observe(box, { childList: true, subtree: true, characterData: true });
|
|
70
|
+
return () => {
|
|
71
|
+
resize?.disconnect();
|
|
72
|
+
mutation.disconnect();
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Keeps an overlay on the part of the screen the on-screen keyboard leaves.
|
|
77
|
+
*
|
|
78
|
+
* Where the keyboard covers the page instead of shrinking it (iOS Safari,
|
|
79
|
+
* Chrome on Android), a panel at the bottom of a `fixed inset-0` root ends up
|
|
80
|
+
* behind it, footer and all. This moves the root's bottom edge up to the top
|
|
81
|
+
* of the keyboard (and its top edge down, if the browser has panned the
|
|
82
|
+
* screen), so everything laid out against the root follows: a sheet's height,
|
|
83
|
+
* a pinned footer, a drawer's end. `data-keyboard-open` is set on the root
|
|
84
|
+
* meanwhile. The field that has focus is scrolled back into view once the
|
|
85
|
+
* root has its new size. Where the page shrinks by itself, nothing is done.
|
|
86
|
+
*
|
|
87
|
+
* The root is usually the backdrop as well: while it is moved, its dimming is
|
|
88
|
+
* carried on past its edges, so the page does not show undimmed where the
|
|
89
|
+
* keyboard was while that slides away.
|
|
90
|
+
*
|
|
91
|
+
* `root` is the overlay's outermost, fixed element. Call it when the overlay
|
|
92
|
+
* opens, in the browser; the returned function stops it and puts the root back.
|
|
93
|
+
*/
|
|
94
|
+
export function followKeyboard(root) {
|
|
95
|
+
if (typeof window === "undefined")
|
|
96
|
+
return () => { };
|
|
97
|
+
const viewport = window.visualViewport;
|
|
98
|
+
const restore = () => {
|
|
99
|
+
root.style.bottom = "";
|
|
100
|
+
root.style.top = "";
|
|
101
|
+
root.style.boxShadow = "";
|
|
102
|
+
delete root.dataset.keyboardOpen;
|
|
103
|
+
};
|
|
104
|
+
let last = "";
|
|
105
|
+
const update = () => {
|
|
106
|
+
const inset = readKeyboardInset();
|
|
107
|
+
// How far the browser has panned the screen to show the field. It
|
|
108
|
+
// counts when the pan is complete as well: nothing of the page is
|
|
109
|
+
// under the keyboard then (the inset is 0), and the top of the root
|
|
110
|
+
// is as far above the screen as the keyboard is tall.
|
|
111
|
+
const shorter = !!viewport &&
|
|
112
|
+
Math.abs(viewport.scale - 1) <= 0.01 &&
|
|
113
|
+
document.documentElement.clientHeight - viewport.height > 1;
|
|
114
|
+
const panned = shorter ? Math.max(0, Math.round(viewport.offsetTop)) : 0;
|
|
115
|
+
const key = `${inset}:${panned}`;
|
|
116
|
+
if (key === last)
|
|
117
|
+
return;
|
|
118
|
+
last = key;
|
|
119
|
+
if (inset > 0 || panned > 0) {
|
|
120
|
+
root.style.bottom = inset > 0 ? `${inset}px` : "";
|
|
121
|
+
root.style.top = panned > 0 ? `${panned}px` : "";
|
|
122
|
+
root.dataset.keyboardOpen = "true";
|
|
123
|
+
// The root is the backdrop too. What it no longer covers is under
|
|
124
|
+
// the keyboard, but shows for a moment while the keyboard slides
|
|
125
|
+
// away: the dimming goes on past the root's edges.
|
|
126
|
+
const dim = getComputedStyle(root).backgroundColor;
|
|
127
|
+
root.style.boxShadow =
|
|
128
|
+
dim && dim !== "transparent" && dim !== "rgba(0, 0, 0, 0)"
|
|
129
|
+
? `0 0 0 100vmax ${dim}`
|
|
130
|
+
: "";
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
restore();
|
|
134
|
+
}
|
|
135
|
+
notifyOverlayFooters();
|
|
136
|
+
const active = document.activeElement;
|
|
137
|
+
if (inset > 0 && active instanceof HTMLElement && root.contains(active)) {
|
|
138
|
+
active.scrollIntoView?.({ block: "nearest" });
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
update();
|
|
142
|
+
viewport?.addEventListener("resize", update);
|
|
143
|
+
viewport?.addEventListener("scroll", update);
|
|
144
|
+
window.addEventListener("resize", update);
|
|
145
|
+
return () => {
|
|
146
|
+
viewport?.removeEventListener("resize", update);
|
|
147
|
+
viewport?.removeEventListener("scroll", update);
|
|
148
|
+
window.removeEventListener("resize", update);
|
|
149
|
+
restore();
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const overlayParts = [];
|
|
153
|
+
const footerListeners = new Set();
|
|
154
|
+
function notifyOverlayFooters() {
|
|
155
|
+
for (const listener of footerListeners)
|
|
156
|
+
listener();
|
|
157
|
+
}
|
|
158
|
+
function registerOverlayPart(part, element) {
|
|
159
|
+
const panel = element.closest(DIALOG_SELECTOR);
|
|
160
|
+
let entry = panel ? overlayParts.find((candidate) => candidate.panel === panel) : undefined;
|
|
161
|
+
if (!entry) {
|
|
162
|
+
entry = { panel };
|
|
163
|
+
overlayParts.push(entry);
|
|
164
|
+
}
|
|
165
|
+
const mine = entry;
|
|
166
|
+
mine[part] = element;
|
|
167
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(notifyOverlayFooters) : undefined;
|
|
168
|
+
observer?.observe(element);
|
|
169
|
+
notifyOverlayFooters();
|
|
170
|
+
// An overlay that slides in is still on its way when its parts are
|
|
171
|
+
// rendered, and a move is not a change of size: say so again once the
|
|
172
|
+
// panel has come to rest.
|
|
173
|
+
let frame = 0;
|
|
174
|
+
const settle = () => {
|
|
175
|
+
frame = 0;
|
|
176
|
+
if (typeof panel?.getAnimations === "function" && panel.getAnimations().length > 0) {
|
|
177
|
+
frame = requestAnimationFrame(settle);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
notifyOverlayFooters();
|
|
181
|
+
};
|
|
182
|
+
if (panel && typeof requestAnimationFrame === "function")
|
|
183
|
+
frame = requestAnimationFrame(settle);
|
|
184
|
+
return () => {
|
|
185
|
+
if (frame)
|
|
186
|
+
cancelAnimationFrame(frame);
|
|
187
|
+
observer?.disconnect();
|
|
188
|
+
if (mine[part] === element)
|
|
189
|
+
delete mine[part];
|
|
190
|
+
if (!mine.header && !mine.footer) {
|
|
191
|
+
const index = overlayParts.indexOf(mine);
|
|
192
|
+
if (index !== -1)
|
|
193
|
+
overlayParts.splice(index, 1);
|
|
194
|
+
}
|
|
195
|
+
notifyOverlayFooters();
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Says that `footer` is pinned to the bottom of an open overlay, so what is
|
|
200
|
+
* drawn over the overlays (the toast stack) can stay off it. Call it when the
|
|
201
|
+
* footer is rendered, in the browser; the returned function withdraws it.
|
|
202
|
+
*/
|
|
203
|
+
export function registerOverlayFooter(footer) {
|
|
204
|
+
return registerOverlayPart("footer", footer);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Says that `header` is the top of an open overlay and holds its close
|
|
208
|
+
* button, so the toast stack starts below it and never lies over the one
|
|
209
|
+
* control that always closes the overlay. Call it when the header is
|
|
210
|
+
* rendered, in the browser; the returned function withdraws it.
|
|
211
|
+
*/
|
|
212
|
+
export function registerOverlayHeader(header) {
|
|
213
|
+
return registerOverlayPart("header", header);
|
|
214
|
+
}
|
|
215
|
+
/** The parts of the overlay opened last that has registered any. */
|
|
216
|
+
function topOverlayParts() {
|
|
217
|
+
for (let index = overlayParts.length - 1; index >= 0; index -= 1) {
|
|
218
|
+
const entry = overlayParts[index];
|
|
219
|
+
if (entry.header?.isConnected || entry.footer?.isConnected)
|
|
220
|
+
return entry;
|
|
221
|
+
}
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
/** The footer of the overlay on top, if it has one. */
|
|
225
|
+
export function topOverlayFooter() {
|
|
226
|
+
const footer = topOverlayParts()?.footer;
|
|
227
|
+
return footer?.isConnected ? footer : null;
|
|
228
|
+
}
|
|
229
|
+
/** The header of the overlay on top, if it has one. */
|
|
230
|
+
export function topOverlayHeader() {
|
|
231
|
+
const header = topOverlayParts()?.header;
|
|
232
|
+
return header?.isConnected ? header : null;
|
|
233
|
+
}
|
|
234
|
+
/** Calls `listener` whenever a registered header or footer appears, goes, moves or changes size. */
|
|
235
|
+
export function watchOverlayFooters(listener) {
|
|
236
|
+
footerListeners.add(listener);
|
|
237
|
+
return () => {
|
|
238
|
+
footerListeners.delete(listener);
|
|
239
|
+
};
|
|
240
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types and pure helpers for `PhotoGrid` and `PhotoViewer`.
|
|
3
|
+
*
|
|
4
|
+
* Everything a gesture means is worked out here, on numbers: where a pinch
|
|
5
|
+
* leaves the photo, how far it may be panned, whether a swipe turns the page.
|
|
6
|
+
* The components only feed pointers in and apply the result, so the
|
|
7
|
+
* arithmetic can be tested without a browser.
|
|
8
|
+
*/
|
|
9
|
+
import type { Component } from "svelte";
|
|
10
|
+
export type PhotoKey = string | number;
|
|
11
|
+
/** One photo. `PhotoGrid` and `PhotoViewer` take the same array. */
|
|
12
|
+
export interface Photo {
|
|
13
|
+
/** Stable identity, when the same `src` may appear twice or may change. Without it, `src` is the identity. */
|
|
14
|
+
id?: PhotoKey;
|
|
15
|
+
/** The full image, shown in the viewer. */
|
|
16
|
+
src: string;
|
|
17
|
+
/** A small version for the grid, and for the viewer while the full image loads. Without it, `src`. */
|
|
18
|
+
thumbSrc?: string;
|
|
19
|
+
/** What the photo shows, for those who cannot see it. */
|
|
20
|
+
alt: string;
|
|
21
|
+
/** Width of the full image in px. With `height` it reserves the photo's box before it has loaded. */
|
|
22
|
+
width: number;
|
|
23
|
+
/** Height of the full image in px. */
|
|
24
|
+
height: number;
|
|
25
|
+
/** Shown under the photo in the viewer. */
|
|
26
|
+
caption?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function photoKey(photo: Photo): PhotoKey;
|
|
29
|
+
/** Payload of PhotoGrid's `onselect`. */
|
|
30
|
+
export interface PhotoGridSelectDetail {
|
|
31
|
+
photo: Photo;
|
|
32
|
+
index: number;
|
|
33
|
+
/** False when the press cleared the photo's selection (only in `multiple`). */
|
|
34
|
+
selected: boolean;
|
|
35
|
+
/** Every selected key after the change: one or none in `single`. */
|
|
36
|
+
keys: PhotoKey[];
|
|
37
|
+
}
|
|
38
|
+
/** Every built-in string of PhotoGrid. Pass a partial object to `strings` to translate. */
|
|
39
|
+
export interface PhotoGridStrings {
|
|
40
|
+
/** Visible label and name of the tile that adds a photo. */
|
|
41
|
+
addPhoto: string;
|
|
42
|
+
/** Name of a photo that has no `alt`. */
|
|
43
|
+
photoName: (position: number, total: number) => string;
|
|
44
|
+
/** Name of the last tile when it stands for the photos not shown. */
|
|
45
|
+
morePhotos: (count: number) => string;
|
|
46
|
+
/** Name of the button that opens a photo, in a grid where a press selects. */
|
|
47
|
+
openPhoto: (name: string) => string;
|
|
48
|
+
/** How to get around by keyboard. Read once when focus enters the grid, and shown while it has keyboard focus. */
|
|
49
|
+
keyboardHint: string;
|
|
50
|
+
}
|
|
51
|
+
export declare const PHOTO_GRID_STRINGS: PhotoGridStrings;
|
|
52
|
+
/** What the user did to close the viewer. `swipe` is a swipe down on the photo. */
|
|
53
|
+
export type PhotoViewerCloseReason = "escape" | "close-button" | "swipe";
|
|
54
|
+
/** Something to do with the photo that is showing: share it, delete it. */
|
|
55
|
+
export interface PhotoViewerAction {
|
|
56
|
+
id: string;
|
|
57
|
+
label: string;
|
|
58
|
+
/** An icon component, as `@lucide/svelte` icons are. */
|
|
59
|
+
icon?: Component<{
|
|
60
|
+
size?: number;
|
|
61
|
+
class?: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** `danger` for a destructive action such as Delete. */
|
|
64
|
+
tone?: "danger";
|
|
65
|
+
disabled?: boolean;
|
|
66
|
+
onclick: (photo: Photo, index: number) => void;
|
|
67
|
+
}
|
|
68
|
+
/** Every built-in string of PhotoViewer. Pass a partial object to `strings` to translate. */
|
|
69
|
+
export interface PhotoViewerStrings {
|
|
70
|
+
close: string;
|
|
71
|
+
previous: string;
|
|
72
|
+
next: string;
|
|
73
|
+
/** The counter that is shown: "3 / 12". */
|
|
74
|
+
counter: (position: number, total: number) => string;
|
|
75
|
+
/** The same for a screen reader, read out after the photo's `alt`: "3 of 12". */
|
|
76
|
+
position: (position: number, total: number) => string;
|
|
77
|
+
/** Announced, with a spinner, when a photo takes a while to load. */
|
|
78
|
+
loading: string;
|
|
79
|
+
/** Shown when a photo cannot be loaded. */
|
|
80
|
+
loadError: string;
|
|
81
|
+
retry: string;
|
|
82
|
+
/** Name of the menu that holds the actions that do not fit in the bar. */
|
|
83
|
+
moreActions: string;
|
|
84
|
+
/** The button that shows all of a long caption, and the one that folds it again. */
|
|
85
|
+
showMore: string;
|
|
86
|
+
showLess: string;
|
|
87
|
+
/** Name of a photo that has no `alt`. */
|
|
88
|
+
photoName: (position: number, total: number) => string;
|
|
89
|
+
}
|
|
90
|
+
export declare const PHOTO_VIEWER_STRINGS: PhotoViewerStrings;
|
|
91
|
+
/** How many actions the viewer's bar shows before the rest go into a menu. */
|
|
92
|
+
export declare const MAX_BAR_ACTIONS = 3;
|
|
93
|
+
/** The actions shown in the bar, and those that go into the menu. */
|
|
94
|
+
export declare function splitActions<T>(actions: readonly T[], max?: number): {
|
|
95
|
+
bar: T[];
|
|
96
|
+
menu: T[];
|
|
97
|
+
};
|
|
98
|
+
/** An index held inside a list of `count` photos; -1 for an empty list. */
|
|
99
|
+
export declare function clampIndex(index: number, count: number): number;
|
|
100
|
+
/** What the grid shows of `total` photos under `max`, and how many the last tile stands for. */
|
|
101
|
+
export declare function visibleCount(total: number, max: number | undefined): {
|
|
102
|
+
shown: number;
|
|
103
|
+
hidden: number;
|
|
104
|
+
};
|
|
105
|
+
export interface Size {
|
|
106
|
+
width: number;
|
|
107
|
+
height: number;
|
|
108
|
+
}
|
|
109
|
+
export interface Point {
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Where the photo is. `scale` 1 is the photo fitted to the screen. `x` and
|
|
115
|
+
* `y` are how far its centre is from the centre of the screen, in px.
|
|
116
|
+
*/
|
|
117
|
+
export interface PhotoTransform {
|
|
118
|
+
scale: number;
|
|
119
|
+
x: number;
|
|
120
|
+
y: number;
|
|
121
|
+
}
|
|
122
|
+
export declare const REST: PhotoTransform;
|
|
123
|
+
export declare const MIN_SCALE = 1;
|
|
124
|
+
export declare const MAX_SCALE = 4;
|
|
125
|
+
/** What a double tap zooms to. */
|
|
126
|
+
export declare const DOUBLE_TAP_SCALE = 2.5;
|
|
127
|
+
export declare const isZoomed: (transform: PhotoTransform) => boolean;
|
|
128
|
+
/** The largest size a photo of `photo` px takes inside `view` without being cropped. */
|
|
129
|
+
export declare function fitSize(photo: Size, view: Size): Size;
|
|
130
|
+
/**
|
|
131
|
+
* The transform with its pan held to the photo's edges: an edge of the photo
|
|
132
|
+
* never comes further in than the edge of the screen, and a side that is
|
|
133
|
+
* narrower than the screen stays centred. `fit` is the photo's size at scale 1.
|
|
134
|
+
*/
|
|
135
|
+
export declare function clampPan(transform: PhotoTransform, fit: Size, view: Size): PhotoTransform;
|
|
136
|
+
/**
|
|
137
|
+
* Zooms to `scale` so that the point of the photo under `point` stays under
|
|
138
|
+
* it. `point` is measured from the centre of the screen.
|
|
139
|
+
*/
|
|
140
|
+
export declare function zoomAbout(transform: PhotoTransform, scale: number, point: Point, fit: Size, view: Size): PhotoTransform;
|
|
141
|
+
/** Two fingers on the glass: the point between them, and how far apart they are. */
|
|
142
|
+
export interface PinchSample {
|
|
143
|
+
centre: Point;
|
|
144
|
+
distance: number;
|
|
145
|
+
}
|
|
146
|
+
export declare function pinchSample(first: Point, second: Point): PinchSample;
|
|
147
|
+
/**
|
|
148
|
+
* Where a pinch has taken the photo: scaled by how much the fingers have
|
|
149
|
+
* spread, about the point that was between them when it began, and moved with
|
|
150
|
+
* that point. Points are measured from the centre of the screen.
|
|
151
|
+
*/
|
|
152
|
+
export declare function pinchTransform(start: PhotoTransform, from: PinchSample, now: PinchSample, fit: Size, view: Size): PhotoTransform;
|
|
153
|
+
/** A pinch let go a hair above the fitted size is the fitted size. */
|
|
154
|
+
export declare function settleZoom(transform: PhotoTransform, fit: Size, view: Size): PhotoTransform;
|
|
155
|
+
/** A double tap: in to 2.5 times about the tap from the fitted photo, and back to fitted from any zoom. */
|
|
156
|
+
export declare function doubleTapTransform(transform: PhotoTransform, point: Point, fit: Size, view: Size): PhotoTransform;
|
|
157
|
+
/** The photo moved by `delta` px, held to its edges. */
|
|
158
|
+
export declare function panBy(transform: PhotoTransform, delta: Point, fit: Size, view: Size): PhotoTransform;
|
|
159
|
+
/** One step of the keyboard or the wheel: in or out by half again, about the centre. */
|
|
160
|
+
export declare const ZOOM_STEP = 1.5;
|
|
161
|
+
/** Movement under this many px is a press, not a drag. */
|
|
162
|
+
export declare const TAP_SLOP = 8;
|
|
163
|
+
/** A press shorter than this is a tap, and two taps closer together than this are a double tap. */
|
|
164
|
+
export declare const TAP_MS = 300;
|
|
165
|
+
/** Two taps further apart than this are two taps. */
|
|
166
|
+
export declare const DOUBLE_TAP_RADIUS = 32;
|
|
167
|
+
export declare function isDoubleTap(previous: {
|
|
168
|
+
time: number;
|
|
169
|
+
point: Point;
|
|
170
|
+
} | null, now: {
|
|
171
|
+
time: number;
|
|
172
|
+
point: Point;
|
|
173
|
+
}): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Which way a drag on the fitted photo is going, once it has gone far enough
|
|
176
|
+
* to tell: `x` turns the page, `down` closes, and null is not yet known. A
|
|
177
|
+
* drag upwards is neither, and stays null.
|
|
178
|
+
*/
|
|
179
|
+
export declare function dragAxis(delta: Point, slop?: number): "x" | "down" | null;
|
|
180
|
+
/** Part of the screen's width a slow swipe has to cross to turn the page. */
|
|
181
|
+
export declare const TURN_DISTANCE = 0.25;
|
|
182
|
+
/** Part of the screen's height a slow swipe down has to cross to close. */
|
|
183
|
+
export declare const CLOSE_DISTANCE = 0.2;
|
|
184
|
+
/**
|
|
185
|
+
* What a horizontal swipe does when the finger lifts. A flick decides by its
|
|
186
|
+
* direction; a slow one by how far it went. Swiping left shows the next
|
|
187
|
+
* photo, and the previous one in a right-to-left layout. At either end there
|
|
188
|
+
* is nothing to turn to.
|
|
189
|
+
*/
|
|
190
|
+
export declare function swipeTurn(options: {
|
|
191
|
+
/** px moved; negative is to the left. */
|
|
192
|
+
distance: number;
|
|
193
|
+
/** px per ms at release; negative is to the left. */
|
|
194
|
+
velocity: number;
|
|
195
|
+
width: number;
|
|
196
|
+
index: number;
|
|
197
|
+
count: number;
|
|
198
|
+
rtl?: boolean;
|
|
199
|
+
flick: number;
|
|
200
|
+
}): -1 | 0 | 1;
|
|
201
|
+
/** Whether a swipe down closes the viewer when the finger lifts. */
|
|
202
|
+
export declare function swipeCloses(options: {
|
|
203
|
+
/** px moved down. */
|
|
204
|
+
distance: number;
|
|
205
|
+
/** px per ms at release; positive is down. */
|
|
206
|
+
velocity: number;
|
|
207
|
+
height: number;
|
|
208
|
+
flick: number;
|
|
209
|
+
}): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* How far a drag past the first or last photo moves it: a third of the
|
|
212
|
+
* finger's travel, so it gives but does not come away.
|
|
213
|
+
*/
|
|
214
|
+
export declare function resist(distance: number): number;
|