@zonsh/ui 0.0.0 → 0.4.1
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 +43 -0
- package/README.md +81 -1
- package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
- package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
- package/assets/illustrations/drawing/bracket-construction.svg +77 -0
- package/assets/illustrations/drawing/crescent-dark.svg +28 -0
- package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
- package/assets/illustrations/drawing/crescent-guides.svg +33 -0
- package/assets/illustrations/drawing/crescent.svg +28 -0
- package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
- package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
- package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
- package/assets/illustrations/drawing/eclipse.svg +187 -0
- package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
- package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
- package/assets/illustrations/drawing/elevation-guides.svg +31 -0
- package/assets/illustrations/drawing/horizon-dark.svg +30 -0
- package/assets/illustrations/drawing/horizon.svg +30 -0
- package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
- package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
- package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
- package/assets/illustrations/drawing/nib-study.svg +107 -0
- package/assets/illustrations/editorial/assistant-640.webp +0 -0
- package/assets/illustrations/editorial/assistant.webp +0 -0
- package/assets/illustrations/editorial/automation-640.webp +0 -0
- package/assets/illustrations/editorial/automation.webp +0 -0
- package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-left.webp +0 -0
- package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
- package/assets/illustrations/editorial/bracket-right.webp +0 -0
- package/assets/illustrations/editorial/custom-software-640.webp +0 -0
- package/assets/illustrations/editorial/custom-software.webp +0 -0
- package/assets/illustrations/editorial/digitalization-640.webp +0 -0
- package/assets/illustrations/editorial/digitalization.webp +0 -0
- package/assets/illustrations/editorial/integration-640.webp +0 -0
- package/assets/illustrations/editorial/integration.webp +0 -0
- package/assets/illustrations/editorial/problem-640.webp +0 -0
- package/assets/illustrations/editorial/problem.webp +0 -0
- package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
- package/assets/illustrations/editorial/process-analysis.webp +0 -0
- package/assets/illustrations/editorial/process-concept-640.webp +0 -0
- package/assets/illustrations/editorial/process-concept.webp +0 -0
- package/assets/illustrations/editorial/process-development-640.webp +0 -0
- package/assets/illustrations/editorial/process-development.webp +0 -0
- package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
- package/assets/illustrations/editorial/process-discovery.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
- package/assets/illustrations/editorial/process-maintenance.webp +0 -0
- package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
- package/assets/illustrations/editorial/process-prototype.webp +0 -0
- package/assets/illustrations/editorial/process-testing-640.webp +0 -0
- package/assets/illustrations/editorial/process-testing.webp +0 -0
- package/assets/illustrations/iso/automation-dark.svg +6 -0
- package/assets/illustrations/iso/automation.svg +6 -0
- package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
- package/assets/illustrations/iso/bar-chart.svg +6 -0
- package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
- package/assets/illustrations/iso/brackets-classic.svg +6 -0
- package/assets/illustrations/iso/brackets-dark.svg +6 -0
- package/assets/illustrations/iso/brackets.svg +6 -0
- package/assets/illustrations/iso/city-dark.svg +6 -0
- package/assets/illustrations/iso/city.svg +6 -0
- package/assets/illustrations/iso/conveyor-dark.svg +6 -0
- package/assets/illustrations/iso/conveyor.svg +6 -0
- package/assets/illustrations/iso/database-dark.svg +6 -0
- package/assets/illustrations/iso/database.svg +6 -0
- package/assets/illustrations/iso/documents-dark.svg +6 -0
- package/assets/illustrations/iso/documents.svg +6 -0
- package/assets/illustrations/iso/inbox-dark.svg +6 -0
- package/assets/illustrations/iso/inbox.svg +6 -0
- package/assets/illustrations/iso/laptop-dark.svg +6 -0
- package/assets/illustrations/iso/laptop.svg +6 -0
- package/assets/illustrations/iso/monitor-dark.svg +6 -0
- package/assets/illustrations/iso/monitor.svg +6 -0
- package/assets/illustrations/iso/pipeline-dark.svg +6 -0
- package/assets/illustrations/iso/pipeline.svg +6 -0
- package/assets/illustrations/iso/platform-dark.svg +6 -0
- package/assets/illustrations/iso/platform.svg +6 -0
- package/assets/illustrations/iso/server-dark.svg +6 -0
- package/assets/illustrations/iso/server.svg +6 -0
- package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
- package/assets/illustrations/iso/spreadsheet.svg +6 -0
- package/assets/illustrations/iso/timeline-dark.svg +6 -0
- package/assets/illustrations/iso/timeline.svg +6 -0
- package/assets/illustrations/sheet/construction.svg +115 -0
- package/assets/illustrations/sheet/crescent.svg +40 -0
- package/assets/illustrations/sheet/limb.svg +42 -0
- package/assets/illustrations/sheet/stress-axis.svg +119 -0
- package/assets/illustrations/sheet/totality.svg +215 -0
- package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
- package/assets/logo-left.svg +1 -0
- package/assets/logo-right.svg +1 -0
- package/assets/logo.svg +1 -0
- package/dist/components/_overlay.d.ts +47 -0
- package/dist/components/_overlay.js +59 -0
- package/dist/components/accordion.d.ts +32 -0
- package/dist/components/accordion.js +39 -0
- package/dist/components/alert-dialog.d.ts +45 -0
- package/dist/components/alert-dialog.js +56 -0
- package/dist/components/alert.d.ts +35 -0
- package/dist/components/alert.js +42 -0
- package/dist/components/ascii-field.d.ts +34 -0
- package/dist/components/ascii-field.js +410 -0
- package/dist/components/aspect-ratio.d.ts +14 -0
- package/dist/components/aspect-ratio.js +17 -0
- package/dist/components/avatar.d.ts +42 -0
- package/dist/components/avatar.js +55 -0
- package/dist/components/badge.d.ts +70 -0
- package/dist/components/badge.js +62 -0
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +31 -0
- package/dist/components/breadcrumb.js +37 -0
- package/dist/components/button-group.d.ts +30 -0
- package/dist/components/button-group.js +47 -0
- package/dist/components/button.d.ts +53 -0
- package/dist/components/button.js +130 -0
- package/dist/components/calendar.d.ts +26 -0
- package/dist/components/calendar.js +179 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +109 -0
- package/dist/components/carousel.js +231 -0
- package/dist/components/chart.d.ts +189 -0
- package/dist/components/chart.js +323 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +55 -0
- package/dist/components/code-block.js +100 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +107 -0
- package/dist/components/color-picker.js +428 -0
- package/dist/components/combobox.d.ts +99 -0
- package/dist/components/combobox.js +172 -0
- package/dist/components/command.d.ts +132 -0
- package/dist/components/command.js +257 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +36 -0
- package/dist/components/conversation.js +303 -0
- package/dist/components/copy-button.d.ts +55 -0
- package/dist/components/copy-button.js +133 -0
- package/dist/components/data-table.d.ts +235 -0
- package/dist/components/data-table.js +655 -0
- package/dist/components/date-picker.d.ts +160 -0
- package/dist/components/date-picker.js +338 -0
- package/dist/components/dialog.d.ts +57 -0
- package/dist/components/dialog.js +95 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +69 -0
- package/dist/components/drawer.js +79 -0
- package/dist/components/empty.d.ts +31 -0
- package/dist/components/empty.js +50 -0
- package/dist/components/feature-list.d.ts +54 -0
- package/dist/components/feature-list.js +43 -0
- package/dist/components/field.d.ts +34 -0
- package/dist/components/field.js +81 -0
- package/dist/components/file-drop.d.ts +77 -0
- package/dist/components/file-drop.js +258 -0
- package/dist/components/filter-bar.d.ts +153 -0
- package/dist/components/filter-bar.js +334 -0
- package/dist/components/form.d.ts +35 -0
- package/dist/components/form.js +56 -0
- package/dist/components/graph.d.ts +146 -0
- package/dist/components/graph.js +825 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +138 -0
- package/dist/components/input-group.js +312 -0
- package/dist/components/input.d.ts +16 -0
- package/dist/components/input.js +25 -0
- package/dist/components/item.d.ts +64 -0
- package/dist/components/item.js +116 -0
- package/dist/components/kbd.d.ts +50 -0
- package/dist/components/kbd.js +45 -0
- package/dist/components/label.d.ts +12 -0
- package/dist/components/label.js +24 -0
- package/dist/components/layout.d.ts +136 -0
- package/dist/components/layout.js +162 -0
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +439 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.d.ts +54 -0
- package/dist/components/logo.js +96 -0
- package/dist/components/menu.d.ts +60 -0
- package/dist/components/menu.js +140 -0
- package/dist/components/menubar.d.ts +62 -0
- package/dist/components/menubar.js +223 -0
- package/dist/components/message.d.ts +42 -0
- package/dist/components/message.js +59 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +27 -0
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/native-select.d.ts +26 -0
- package/dist/components/native-select.js +35 -0
- package/dist/components/navigation-menu.d.ts +42 -0
- package/dist/components/navigation-menu.js +97 -0
- package/dist/components/number-field.d.ts +55 -0
- package/dist/components/number-field.js +164 -0
- package/dist/components/otp-field.d.ts +48 -0
- package/dist/components/otp-field.js +102 -0
- package/dist/components/pagination.d.ts +37 -0
- package/dist/components/pagination.js +81 -0
- package/dist/components/pdf-viewer.d.ts +134 -0
- package/dist/components/pdf-viewer.js +996 -0
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.d.ts +33 -0
- package/dist/components/popover.js +48 -0
- package/dist/components/preview-card.d.ts +25 -0
- package/dist/components/preview-card.js +22 -0
- package/dist/components/progress.d.ts +27 -0
- package/dist/components/progress.js +25 -0
- package/dist/components/prompt-input.d.ts +156 -0
- package/dist/components/prompt-input.js +415 -0
- package/dist/components/quote.d.ts +22 -0
- package/dist/components/quote.js +15 -0
- package/dist/components/radio-group.d.ts +18 -0
- package/dist/components/radio-group.js +34 -0
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +46 -0
- package/dist/components/reasoning.js +73 -0
- package/dist/components/resizable.d.ts +47 -0
- package/dist/components/resizable.js +44 -0
- package/dist/components/response.d.ts +41 -0
- package/dist/components/response.js +566 -0
- package/dist/components/scroll-area.d.ts +33 -0
- package/dist/components/scroll-area.js +31 -0
- package/dist/components/select.d.ts +35 -0
- package/dist/components/select.js +71 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +163 -0
- package/dist/components/sidebar.js +505 -0
- package/dist/components/site-header.d.ts +93 -0
- package/dist/components/site-header.js +121 -0
- package/dist/components/skeleton.d.ts +31 -0
- package/dist/components/skeleton.js +29 -0
- package/dist/components/slider.d.ts +24 -0
- package/dist/components/slider.js +131 -0
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1258 -0
- package/dist/components/sources.d.ts +40 -0
- package/dist/components/sources.js +42 -0
- package/dist/components/spinner.d.ts +48 -0
- package/dist/components/spinner.js +75 -0
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/suggestions.d.ts +20 -0
- package/dist/components/suggestions.js +18 -0
- package/dist/components/switch.d.ts +14 -0
- package/dist/components/switch.js +26 -0
- package/dist/components/table.d.ts +172 -0
- package/dist/components/table.js +895 -0
- package/dist/components/tabs.d.ts +25 -0
- package/dist/components/tabs.js +162 -0
- package/dist/components/tag.d.ts +41 -0
- package/dist/components/tag.js +88 -0
- package/dist/components/tags-input.d.ts +56 -0
- package/dist/components/tags-input.js +271 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +55 -0
- package/dist/components/theme.js +120 -0
- package/dist/components/time-field.d.ts +70 -0
- package/dist/components/time-field.js +450 -0
- package/dist/components/timeline.d.ts +92 -0
- package/dist/components/timeline.js +108 -0
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +88 -0
- package/dist/components/toast.js +205 -0
- package/dist/components/toggle-group.d.ts +41 -0
- package/dist/components/toggle-group.js +140 -0
- package/dist/components/toggle.d.ts +23 -0
- package/dist/components/toggle.js +35 -0
- package/dist/components/tool-call.d.ts +63 -0
- package/dist/components/tool-call.js +68 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +39 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +648 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +649 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +284 -0
- package/dist/components/video-player.js +1392 -0
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +94 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +18 -0
- package/dist/lib/code-highlight.js +174 -0
- package/dist/lib/code-theme.d.ts +19 -0
- package/dist/lib/code-theme.js +140 -0
- package/dist/lib/collapse-row.d.ts +9 -0
- package/dist/lib/collapse-row.js +129 -0
- package/dist/lib/digit-roll.d.ts +21 -0
- package/dist/lib/digit-roll.js +31 -0
- package/dist/lib/editorial-assets.d.ts +16 -0
- package/dist/lib/editorial-assets.js +56 -0
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/figure/catalog.d.ts +127 -0
- package/dist/lib/figure/catalog.js +130 -0
- package/dist/lib/figure/figures/automation.d.ts +7 -0
- package/dist/lib/figure/figures/automation.js +143 -0
- package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
- package/dist/lib/figure/figures/bar-chart.js +99 -0
- package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
- package/dist/lib/figure/figures/brackets-classic.js +170 -0
- package/dist/lib/figure/figures/brackets.d.ts +8 -0
- package/dist/lib/figure/figures/brackets.js +84 -0
- package/dist/lib/figure/figures/city.d.ts +7 -0
- package/dist/lib/figure/figures/city.js +93 -0
- package/dist/lib/figure/figures/conveyor.d.ts +7 -0
- package/dist/lib/figure/figures/conveyor.js +97 -0
- package/dist/lib/figure/figures/database.d.ts +7 -0
- package/dist/lib/figure/figures/database.js +65 -0
- package/dist/lib/figure/figures/documents.d.ts +7 -0
- package/dist/lib/figure/figures/documents.js +83 -0
- package/dist/lib/figure/figures/inbox.d.ts +7 -0
- package/dist/lib/figure/figures/inbox.js +92 -0
- package/dist/lib/figure/figures/laptop.d.ts +7 -0
- package/dist/lib/figure/figures/laptop.js +67 -0
- package/dist/lib/figure/figures/monitor.d.ts +7 -0
- package/dist/lib/figure/figures/monitor.js +59 -0
- package/dist/lib/figure/figures/pipeline.d.ts +8 -0
- package/dist/lib/figure/figures/pipeline.js +117 -0
- package/dist/lib/figure/figures/platform.d.ts +7 -0
- package/dist/lib/figure/figures/platform.js +117 -0
- package/dist/lib/figure/figures/server.d.ts +7 -0
- package/dist/lib/figure/figures/server.js +115 -0
- package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
- package/dist/lib/figure/figures/spreadsheet.js +87 -0
- package/dist/lib/figure/figures/timeline.d.ts +7 -0
- package/dist/lib/figure/figures/timeline.js +65 -0
- package/dist/lib/figure/kernel.d.ts +152 -0
- package/dist/lib/figure/kernel.js +576 -0
- package/dist/lib/figure/parts.d.ts +42 -0
- package/dist/lib/figure/parts.js +126 -0
- package/dist/lib/form-reset.d.ts +11 -0
- package/dist/lib/form-reset.js +22 -0
- package/dist/lib/glide.d.ts +53 -0
- package/dist/lib/glide.js +138 -0
- package/dist/lib/graph-layout.d.ts +58 -0
- package/dist/lib/graph-layout.js +209 -0
- package/dist/lib/illustration-drawings.d.ts +89 -0
- package/dist/lib/illustration-drawings.js +539 -0
- package/dist/lib/illustration-info.d.ts +37 -0
- package/dist/lib/illustration-info.js +22 -0
- package/dist/lib/illustration-library.d.ts +87 -0
- package/dist/lib/illustration-library.js +352 -0
- package/dist/lib/logo-geometry.d.ts +29 -0
- package/dist/lib/logo-geometry.js +67 -0
- package/dist/lib/markdown-guard.d.ts +16 -0
- package/dist/lib/markdown-guard.js +123 -0
- package/dist/lib/merge-refs.d.ts +10 -0
- package/dist/lib/merge-refs.js +26 -0
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/motion.d.ts +6 -0
- package/dist/lib/motion.js +12 -0
- package/dist/lib/pdf-worker.d.ts +1 -0
- package/dist/lib/pdf-worker.js +6 -0
- package/dist/lib/pdf.d.ts +19 -0
- package/dist/lib/pdf.js +58 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +38 -0
- package/dist/lib/platform.js +75 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +596 -0
- package/dist/lib/theme-script.d.ts +31 -0
- package/dist/lib/theme-script.js +49 -0
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +203 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +207 -0
- package/dist/styles/material.css +317 -0
- package/dist/styles/parts/ai.css +361 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +774 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +340 -0
- package/dist/styles/parts/foundations.css +166 -0
- package/dist/styles/parts/graph.css +214 -0
- package/dist/styles/parts/inputs.css +261 -0
- package/dist/styles/parts/isometric.css +124 -0
- package/dist/styles/parts/navigation.css +424 -0
- package/dist/styles/parts/overlays.css +250 -0
- package/dist/styles/parts/pdf.css +154 -0
- package/dist/styles/parts/react-flow.css +519 -0
- package/dist/styles/tokens.css +299 -0
- package/dist/vite.d.ts +66 -0
- package/dist/vite.js +29 -0
- package/package.json +183 -5
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The engine behind `<Table fit>`: which columns keep their own column at the container's width
|
|
3
|
+
* (the fit), and how cells glide to their new places when that changes (FLIP).
|
|
4
|
+
*
|
|
5
|
+
* Columns step out one at a time, lowest `priority` first, the moment the widest title no longer
|
|
6
|
+
* fits on one line beside them; an `inline` column moves into the title cell instead. Only once
|
|
7
|
+
* every column that can step out has done so may titles wrap.
|
|
8
|
+
*/
|
|
9
|
+
/* ── Fit ───────────────────────────────────────────────────────────────────── */
|
|
10
|
+
/** The columns that can step out, in the order they do. The title never does. */
|
|
11
|
+
export function removalOrder(columns, title) {
|
|
12
|
+
return columns
|
|
13
|
+
.map((c, i) => ({ c, i }))
|
|
14
|
+
.filter(({ c }) => c.id !== title && (c.priority != null || c.inline || (c.minWidth ?? 0) > 0))
|
|
15
|
+
.sort((a, b) => (a.c.priority ?? 0) - (b.c.priority ?? 0) || b.i - a.i)
|
|
16
|
+
.map(({ c }) => c);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The order columns are drawn in: those before the title as given, the title, then its inline
|
|
20
|
+
* columns in the order they step out, then the others as given. Rows keep this DOM order at
|
|
21
|
+
* every width, so what is read matches what is seen.
|
|
22
|
+
*/
|
|
23
|
+
export function drawOrder(columns, title) {
|
|
24
|
+
const at = columns.findIndex((c) => c.id === title);
|
|
25
|
+
const before = columns.slice(0, Math.max(at, 0));
|
|
26
|
+
const after = columns.slice(at + 1);
|
|
27
|
+
const inline = removalOrder(after, title).filter((c) => c.inline);
|
|
28
|
+
return [...before, ...columns.slice(at, at + 1), ...inline, ...after.filter((c) => !c.inline)];
|
|
29
|
+
}
|
|
30
|
+
export function layoutFor(step, order, columns) {
|
|
31
|
+
const out = new Set(order.slice(0, step).map((c) => c.id));
|
|
32
|
+
const modes = {};
|
|
33
|
+
for (const c of columns)
|
|
34
|
+
modes[c.id] = !out.has(c.id) ? "column" : c.inline ? "inline" : "hidden";
|
|
35
|
+
return {
|
|
36
|
+
step,
|
|
37
|
+
final: step >= order.length,
|
|
38
|
+
modes,
|
|
39
|
+
inlined: Object.values(modes).includes("inline"),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Restoring a column needs this much more room than keeping it: no flicker at the boundary. */
|
|
43
|
+
const HYSTERESIS_PX = 8;
|
|
44
|
+
const UNCLIP = "position:static;display:inline-flex;width:max-content;min-width:0;height:auto;overflow:visible;" +
|
|
45
|
+
"clip:auto;clip-path:none;margin:0;padding:0;white-space:nowrap;";
|
|
46
|
+
/**
|
|
47
|
+
* The rows a fitting table measures: every row — rows of closed groups too, so opening a group
|
|
48
|
+
* never changes the layout. A virtual body (`TableVirtualBody`) holds only the rows in view, and
|
|
49
|
+
* its sizer rows stand in for all the others: there the header and the sizer rows are measured.
|
|
50
|
+
*/
|
|
51
|
+
export function measuredRows(body) {
|
|
52
|
+
const virtual = !!body.querySelector("[data-slot=table-sizer]");
|
|
53
|
+
return [
|
|
54
|
+
...body.querySelectorAll(virtual
|
|
55
|
+
? "[data-slot=table-header] [data-slot=table-row], [data-slot=table-sizer] [data-slot=table-row]"
|
|
56
|
+
: "[data-slot=table-row]"),
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Clones every measured title and cell (`measuredRows`) into a hidden probe with
|
|
61
|
+
* `white-space: nowrap`, reads all widths in one pass and removes the probe — before anything
|
|
62
|
+
* paints.
|
|
63
|
+
*/
|
|
64
|
+
export function measureMetrics(root, body, columns) {
|
|
65
|
+
const probe = document.createElement("div");
|
|
66
|
+
probe.setAttribute("aria-hidden", "true");
|
|
67
|
+
probe.className = "font-body text-sm";
|
|
68
|
+
probe.style.cssText =
|
|
69
|
+
"position:absolute;top:0;left:0;visibility:hidden;pointer-events:none;white-space:nowrap;width:max-content;contain:layout style;";
|
|
70
|
+
// The space a row puts between its title and an inline cell (INLINE_SPACE in table.tsx).
|
|
71
|
+
const space = probe.appendChild(document.createElement("span"));
|
|
72
|
+
space.style.cssText = "white-space:pre;word-spacing:0.215em;";
|
|
73
|
+
space.textContent = " ";
|
|
74
|
+
const grids = new Map();
|
|
75
|
+
for (const c of columns) {
|
|
76
|
+
const grid = probe.appendChild(document.createElement("div"));
|
|
77
|
+
grid.style.cssText = `display:grid;width:max-content;grid-template-columns:${c.width ?? "auto"};`;
|
|
78
|
+
grids.set(c.id, grid);
|
|
79
|
+
}
|
|
80
|
+
// A title takes its type from its cell (an eyebrow in the header, 13px in a dense row).
|
|
81
|
+
const fonts = new Map();
|
|
82
|
+
const fontOf = (cell) => {
|
|
83
|
+
let font = fonts.get(cell.className);
|
|
84
|
+
if (font == null) {
|
|
85
|
+
const cs = getComputedStyle(cell);
|
|
86
|
+
font = `font:${cs.font};letter-spacing:${cs.letterSpacing};text-transform:${cs.textTransform};`;
|
|
87
|
+
fonts.set(cell.className, font);
|
|
88
|
+
}
|
|
89
|
+
return font;
|
|
90
|
+
};
|
|
91
|
+
const rows = measuredRows(body);
|
|
92
|
+
const probes = rows.map((row) => {
|
|
93
|
+
const text = row.querySelector("[data-slot=table-title-text]");
|
|
94
|
+
const cell = text?.closest("[data-title]");
|
|
95
|
+
const title = text ? text.cloneNode(true) : null;
|
|
96
|
+
if (title) {
|
|
97
|
+
title.style.cssText = UNCLIP + (cell ? fontOf(cell) : "");
|
|
98
|
+
probe.append(title);
|
|
99
|
+
}
|
|
100
|
+
const cells = [];
|
|
101
|
+
for (const el of row.querySelectorAll("[data-column]")) {
|
|
102
|
+
const id = el.getAttribute("data-column");
|
|
103
|
+
const clone = el.cloneNode(true);
|
|
104
|
+
clone.style.cssText = UNCLIP;
|
|
105
|
+
grids.get(id)?.append(clone);
|
|
106
|
+
cells.push([id, clone]);
|
|
107
|
+
}
|
|
108
|
+
return { title, cells, head: !!row.closest("[data-slot=table-header]") };
|
|
109
|
+
});
|
|
110
|
+
root.append(probe);
|
|
111
|
+
const metrics = {
|
|
112
|
+
space: space.getBoundingClientRect().width,
|
|
113
|
+
tracks: Object.fromEntries([...grids].map(([id, g]) => [id, g.getBoundingClientRect().width])),
|
|
114
|
+
rows: probes.map((p) => ({
|
|
115
|
+
title: p.title?.getBoundingClientRect().width ?? 0,
|
|
116
|
+
cells: Object.fromEntries(p.cells.map(([id, el]) => [id, el.getBoundingClientRect().width])),
|
|
117
|
+
head: p.head,
|
|
118
|
+
})),
|
|
119
|
+
};
|
|
120
|
+
probe.remove();
|
|
121
|
+
return metrics;
|
|
122
|
+
}
|
|
123
|
+
/** The width a layout needs with every title on one line. */
|
|
124
|
+
function widthNeeded(layout, drawn, title, m, edge, gap) {
|
|
125
|
+
const inline = drawn.filter((c) => layout.modes[c.id] === "inline");
|
|
126
|
+
const own = drawn.filter((c) => layout.modes[c.id] === "column");
|
|
127
|
+
let widest = 0;
|
|
128
|
+
for (const row of m.rows) {
|
|
129
|
+
let w = row.title;
|
|
130
|
+
if (!row.head)
|
|
131
|
+
for (const c of inline)
|
|
132
|
+
w += m.space + (row.cells[c.id] ?? 0);
|
|
133
|
+
widest = Math.max(widest, w);
|
|
134
|
+
}
|
|
135
|
+
// The rows' padding sits inside the edge tracks, which it grows when they size to their
|
|
136
|
+
// content (the title's, an `auto` one) and squeezes into when they are fixed.
|
|
137
|
+
const grows = (c) => !c || c.id === title || (c.width ?? "auto") === "auto";
|
|
138
|
+
const tracks = own.reduce((sum, c) => sum + (c.id === title ? Math.ceil(widest) : (m.tracks[c.id] ?? 0)), 0);
|
|
139
|
+
return (tracks + gap * Math.max(own.length - 1, 0) + (grows(own[0]) ? edge : 0) + (grows(own.at(-1)) ? edge : 0));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The final layout's room for the title's track: the width less the columns that keep their own,
|
|
143
|
+
* the gaps, and the padding of a last track that sizes to its content. Null before the final
|
|
144
|
+
* layout, or when the title is the only column left.
|
|
145
|
+
*/
|
|
146
|
+
export function titleRoom(layout, drawn, title, m, available, edge, gap) {
|
|
147
|
+
if (!layout.final)
|
|
148
|
+
return null;
|
|
149
|
+
const own = drawn.filter((c) => layout.modes[c.id] === "column");
|
|
150
|
+
const others = own.filter((c) => c.id !== title);
|
|
151
|
+
if (!others.length)
|
|
152
|
+
return null;
|
|
153
|
+
const last = own.at(-1);
|
|
154
|
+
const tail = last.id !== title && (last.width ?? "auto") === "auto" ? edge : 0;
|
|
155
|
+
const taken = others.reduce((sum, c) => sum + (m.tracks[c.id] ?? 0), 0) + gap * others.length + tail;
|
|
156
|
+
return Math.max(0, Math.floor(available - taken));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The fewest columns to step out so the widest title stays on one line. Stepping out happens
|
|
160
|
+
* the moment it no longer fits; stepping back needs `HYSTERESIS_PX` to spare.
|
|
161
|
+
*/
|
|
162
|
+
export function fitStep(options) {
|
|
163
|
+
const { available, current, order, columns, drawn, title, metrics, edge, gap, widthRem } = options;
|
|
164
|
+
let floor = 0;
|
|
165
|
+
order.forEach((c, i) => {
|
|
166
|
+
if ((c.minWidth ?? 0) > widthRem)
|
|
167
|
+
floor = i + 1;
|
|
168
|
+
});
|
|
169
|
+
for (let step = floor; step < order.length; step++) {
|
|
170
|
+
const need = widthNeeded(layoutFor(step, order, columns), drawn, title, metrics, edge, gap);
|
|
171
|
+
if (need + (step < current ? HYSTERESIS_PX : 0) <= available)
|
|
172
|
+
return step;
|
|
173
|
+
}
|
|
174
|
+
return order.length;
|
|
175
|
+
}
|
|
176
|
+
/* ── FLIP ──────────────────────────────────────────────────────────────────── */
|
|
177
|
+
/**
|
|
178
|
+
* One beat for the whole row: a leaving cell fades over exactly the time its neighbours take to
|
|
179
|
+
* glide into the space it frees, on the same curve and from the same start, so the gap closes as
|
|
180
|
+
* the cell goes. Entering cells start a moment later and land with them.
|
|
181
|
+
*/
|
|
182
|
+
const MOVE_MS = 280;
|
|
183
|
+
const ENTER_DELAY_MS = 40;
|
|
184
|
+
const ENTER_MS = MOVE_MS - ENTER_DELAY_MS;
|
|
185
|
+
/**
|
|
186
|
+
* Fades run on a gentle standard curve, not the brand's front-loaded ease-out: on that curve a
|
|
187
|
+
* fade is ~85% done in the first frames, so a returning column seemed to pop straight in.
|
|
188
|
+
*/
|
|
189
|
+
const FADE_EASING = "cubic-bezier(0.4, 0, 0.2, 1)";
|
|
190
|
+
const EXIT_MS = MOVE_MS;
|
|
191
|
+
/** How far a leaving cell drifts towards its own side as it fades. */
|
|
192
|
+
const EXIT_DRIFT_PX = 8;
|
|
193
|
+
/** Delay between one row (or band) and the next, top to bottom — exits and glides alike. */
|
|
194
|
+
const STAGGER_MS = 30;
|
|
195
|
+
/** The last row in view starts by then, so a long table still settles within ~520ms. */
|
|
196
|
+
const SPREAD_MS = 240;
|
|
197
|
+
const ZERO = { x: 0, y: 0 };
|
|
198
|
+
const keyOf = (el) => el.getAttribute("data-flip-key") ?? el;
|
|
199
|
+
/** Rows of a closed group are not drawn, nor a virtual body's sizer rows. */
|
|
200
|
+
const CLOSED = "[data-slot=table-group][data-closed] > [data-slot=table-row]";
|
|
201
|
+
const isDrawn = (el) => !el.closest("[data-mode=hidden]") && !el.closest(CLOSED) && !el.closest("[data-slot=table-sizer]");
|
|
202
|
+
/** The band or row a piece belongs to: its place in the top-to-bottom cascade. */
|
|
203
|
+
const seqOf = (el) => el.closest("[data-flip=row],[data-flip=band]");
|
|
204
|
+
/** Where a piece is anchored: the side it scales from, and its vertical middle. */
|
|
205
|
+
const anchorOf = (rect, side) => ({
|
|
206
|
+
x: side === "right center" ? rect.right : rect.left,
|
|
207
|
+
y: rect.top + rect.height / 2,
|
|
208
|
+
});
|
|
209
|
+
/**
|
|
210
|
+
* The glide. Tracked pieces carry `data-flip`. Each is measured relative to its nearest tracked
|
|
211
|
+
* parent (bands and rows relative to the scroll content), so a cell glides inside its row while
|
|
212
|
+
* the row glides inside the table, and a stuck band stays stuck.
|
|
213
|
+
*
|
|
214
|
+
* - `tier()` wraps a layout change: measure where everything is drawn, commit the new layout,
|
|
215
|
+
* measure again, animate the difference. The bands and rows in view go top to bottom, up to
|
|
216
|
+
* 30ms apart; every piece of a row starts with its row, its leaving cells included. Entering
|
|
217
|
+
* cells fade and grow in; leaving cells are cloned where they stood and fade out as their
|
|
218
|
+
* neighbours glide over. Interrupted, it starts again from what is drawn: positions
|
|
219
|
+
* mid-glide, cells mid-fade, ghosts still fading out.
|
|
220
|
+
* - `reflow()` runs on every other resize. In the final layout, where titles wrap, a piece that
|
|
221
|
+
* changed line glides there instead of jumping; pieces that only follow the width keep
|
|
222
|
+
* following the pointer.
|
|
223
|
+
*
|
|
224
|
+
* Each pass reads every rect first and writes after, so there is one forced layout per change.
|
|
225
|
+
*/
|
|
226
|
+
export class Flip {
|
|
227
|
+
root;
|
|
228
|
+
body;
|
|
229
|
+
layer;
|
|
230
|
+
anims = new Map();
|
|
231
|
+
ghosts = new Map();
|
|
232
|
+
cache = new Map();
|
|
233
|
+
active = 0;
|
|
234
|
+
/** Right to left: a column's end is on the left. Read at the start of every glide. */
|
|
235
|
+
rtl = false;
|
|
236
|
+
constructor(root, body, layer) {
|
|
237
|
+
this.root = root;
|
|
238
|
+
this.body = body;
|
|
239
|
+
this.layer = layer;
|
|
240
|
+
}
|
|
241
|
+
/** The side a piece is anchored to: its column's end (the right, or the left right to left) or start. */
|
|
242
|
+
sideOf(el) {
|
|
243
|
+
return (el.getAttribute("data-align") === "end") !== this.rtl ? "right center" : "left center";
|
|
244
|
+
}
|
|
245
|
+
direction() {
|
|
246
|
+
this.rtl = getComputedStyle(this.root).direction === "rtl";
|
|
247
|
+
}
|
|
248
|
+
easing() {
|
|
249
|
+
return getComputedStyle(this.root).getPropertyValue("--ease").trim() || "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
250
|
+
}
|
|
251
|
+
track(a) {
|
|
252
|
+
if (this.active++ === 0)
|
|
253
|
+
this.root.setAttribute("data-gliding", "");
|
|
254
|
+
const done = () => {
|
|
255
|
+
if (--this.active === 0)
|
|
256
|
+
this.root.removeAttribute("data-gliding");
|
|
257
|
+
};
|
|
258
|
+
a.finished.then(done, done);
|
|
259
|
+
return a;
|
|
260
|
+
}
|
|
261
|
+
run(el, keyframes, options) {
|
|
262
|
+
this.anims.get(el)?.cancel();
|
|
263
|
+
const a = this.track(el.animate(keyframes, { fill: "backwards", ...options }));
|
|
264
|
+
this.anims.set(el, a);
|
|
265
|
+
a.finished.then(() => this.anims.get(el) === a && this.anims.delete(el), () => undefined);
|
|
266
|
+
}
|
|
267
|
+
dropGhost(key) {
|
|
268
|
+
const ghost = this.ghosts.get(key);
|
|
269
|
+
if (!ghost)
|
|
270
|
+
return;
|
|
271
|
+
this.ghosts.delete(key);
|
|
272
|
+
ghost.anim.cancel();
|
|
273
|
+
ghost.clone.remove();
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Where a piece's box starts without the scale it is drawn at. A piece fading in is scaled from
|
|
277
|
+
* its side's vertical middle, which moves its drawn top; read as is, that looked like a change
|
|
278
|
+
* of line, and the next resize replaced the fade-in with a glide, so the cell popped in.
|
|
279
|
+
*/
|
|
280
|
+
unscaled(el, r) {
|
|
281
|
+
const a = this.anims.get(el);
|
|
282
|
+
const s = a?.playState === "running" ? parseFloat(getComputedStyle(el).scale) : NaN;
|
|
283
|
+
if (!s || s === 1)
|
|
284
|
+
return { x: r.left, y: r.top };
|
|
285
|
+
const { offsetWidth: w, offsetHeight: h } = el;
|
|
286
|
+
return {
|
|
287
|
+
x: this.sideOf(el) === "right center" ? r.right - w : r.left,
|
|
288
|
+
y: r.top + r.height / 2 - h / 2,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/** Every drawn piece, its rect, and its position in its parent — less `offsets`, a glide in progress. */
|
|
292
|
+
measure(offsets) {
|
|
293
|
+
const box = this.body.getBoundingClientRect();
|
|
294
|
+
const content = { x: box.left - this.body.scrollLeft, y: box.top - this.body.scrollTop };
|
|
295
|
+
const els = [...this.root.querySelectorAll("[data-flip]")].filter(isDrawn);
|
|
296
|
+
const rects = new Map(els.map((el) => [el, el.getBoundingClientRect()]));
|
|
297
|
+
const rel = new Map();
|
|
298
|
+
for (const el of els) {
|
|
299
|
+
const r = this.unscaled(el, rects.get(el));
|
|
300
|
+
const own = offsets?.get(el) ?? ZERO;
|
|
301
|
+
const parent = el.parentElement?.closest("[data-flip]");
|
|
302
|
+
const p = parent ? rects.get(parent) : undefined;
|
|
303
|
+
const base = p ? { x: p.left, y: p.top } : content;
|
|
304
|
+
rel.set(keyOf(el), { x: r.x - own.x - base.x, y: r.y - own.y - base.y });
|
|
305
|
+
}
|
|
306
|
+
return { els, rects, rel, view: box };
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The cascade: bands and rows in view count 0, 1, 2… from the top; those above the view start
|
|
310
|
+
* at once, those below with the last one in view.
|
|
311
|
+
*/
|
|
312
|
+
cascade(rects, view) {
|
|
313
|
+
const index = new Map();
|
|
314
|
+
const below = [];
|
|
315
|
+
let count = 0;
|
|
316
|
+
for (const el of this.root.querySelectorAll("[data-flip=band],[data-flip=row]")) {
|
|
317
|
+
const r = rects.get(el);
|
|
318
|
+
if (!r)
|
|
319
|
+
continue;
|
|
320
|
+
if (r.bottom <= view.top)
|
|
321
|
+
index.set(el, 0);
|
|
322
|
+
else if (r.top >= view.bottom)
|
|
323
|
+
below.push(el);
|
|
324
|
+
else
|
|
325
|
+
index.set(el, count++);
|
|
326
|
+
}
|
|
327
|
+
for (const el of below)
|
|
328
|
+
index.set(el, Math.max(0, count - 1));
|
|
329
|
+
const gap = count > 1 ? Math.min(STAGGER_MS, SPREAD_MS / (count - 1)) : 0;
|
|
330
|
+
return (seq) => (seq ? (index.get(seq) ?? 0) * gap : 0);
|
|
331
|
+
}
|
|
332
|
+
/** Forget the last positions: something other than the width moved things (scroll, data, a group). */
|
|
333
|
+
invalidate() {
|
|
334
|
+
this.cache.clear();
|
|
335
|
+
}
|
|
336
|
+
cancel() {
|
|
337
|
+
for (const a of this.anims.values())
|
|
338
|
+
a.cancel();
|
|
339
|
+
this.anims.clear();
|
|
340
|
+
for (const key of [...this.ghosts.keys()])
|
|
341
|
+
this.dropGhost(key);
|
|
342
|
+
}
|
|
343
|
+
/** Glides from what is drawn now to the layout that `commit` applies (synchronously) for `next`. */
|
|
344
|
+
tier(next, commit) {
|
|
345
|
+
const easing = this.easing();
|
|
346
|
+
this.direction();
|
|
347
|
+
// Read: positions (mid-glide included), the fade of anything mid-entrance, the ghosts still
|
|
348
|
+
// fading out, and clones of the pieces about to step out.
|
|
349
|
+
const first = this.measure();
|
|
350
|
+
const faded = new Map();
|
|
351
|
+
for (const [el, a] of this.anims) {
|
|
352
|
+
if (a.playState !== "running" || !first.rects.has(el))
|
|
353
|
+
continue;
|
|
354
|
+
const cs = getComputedStyle(el);
|
|
355
|
+
faded.set(keyOf(el), { opacity: parseFloat(cs.opacity), scale: parseFloat(cs.scale) || 1 });
|
|
356
|
+
}
|
|
357
|
+
const fading = new Map();
|
|
358
|
+
for (const [key, { clone }] of this.ghosts) {
|
|
359
|
+
const cs = getComputedStyle(clone);
|
|
360
|
+
fading.set(key, {
|
|
361
|
+
rect: clone.getBoundingClientRect(),
|
|
362
|
+
opacity: parseFloat(cs.opacity),
|
|
363
|
+
scale: parseFloat(cs.scale) || 1,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
const leaving = first.els
|
|
367
|
+
.filter((el) => {
|
|
368
|
+
const column = el.getAttribute("data-column");
|
|
369
|
+
if (!column)
|
|
370
|
+
return false;
|
|
371
|
+
// A header leaves with its column, and when the column moves into the titles.
|
|
372
|
+
const mode = next.modes[column];
|
|
373
|
+
return el.hasAttribute("data-head") ? mode !== "column" : mode === "hidden";
|
|
374
|
+
})
|
|
375
|
+
.map((el) => ({
|
|
376
|
+
el,
|
|
377
|
+
key: el.getAttribute("data-flip-key"),
|
|
378
|
+
seq: seqOf(el),
|
|
379
|
+
side: this.sideOf(el),
|
|
380
|
+
rect: first.rects.get(el),
|
|
381
|
+
size: { w: el.offsetWidth, h: el.offsetHeight },
|
|
382
|
+
from: faded.get(keyOf(el)) ?? { opacity: 1, scale: 1 },
|
|
383
|
+
clone: el.cloneNode(true),
|
|
384
|
+
}));
|
|
385
|
+
for (const a of this.anims.values())
|
|
386
|
+
a.cancel();
|
|
387
|
+
this.anims.clear();
|
|
388
|
+
commit();
|
|
389
|
+
// Read the new layout once, then write every animation.
|
|
390
|
+
const last = this.measure();
|
|
391
|
+
const delay = this.cascade(last.rects, last.view);
|
|
392
|
+
const origin = this.layer.getBoundingClientRect();
|
|
393
|
+
for (const el of last.els) {
|
|
394
|
+
const wait = delay(seqOf(el));
|
|
395
|
+
const side = this.sideOf(el);
|
|
396
|
+
const key = el.getAttribute("data-flip-key");
|
|
397
|
+
let from = first.rel.get(keyOf(el));
|
|
398
|
+
let start = faded.get(keyOf(el));
|
|
399
|
+
const ghost = !from && key ? fading.get(key) : undefined;
|
|
400
|
+
if (!from && ghost) {
|
|
401
|
+
// Back before its ghost faded out: carry on from the ghost, where and as it is drawn.
|
|
402
|
+
const parent = el.parentElement?.closest("[data-flip]");
|
|
403
|
+
const pFirst = parent && first.rects.get(parent);
|
|
404
|
+
const pLast = parent && last.rects.get(parent);
|
|
405
|
+
const g = anchorOf(ghost.rect, side);
|
|
406
|
+
const now = anchorOf(last.rects.get(el), side);
|
|
407
|
+
const shift = pFirst && pLast ? { x: pFirst.left - pLast.left, y: pFirst.top - pLast.top } : ZERO;
|
|
408
|
+
const to = last.rel.get(keyOf(el));
|
|
409
|
+
from = { x: to.x + g.x - now.x - shift.x, y: to.y + g.y - now.y - shift.y };
|
|
410
|
+
start = { opacity: ghost.opacity, scale: ghost.scale };
|
|
411
|
+
this.dropGhost(key);
|
|
412
|
+
}
|
|
413
|
+
if (!from) {
|
|
414
|
+
this.run(el, [
|
|
415
|
+
{ opacity: 0, scale: "0.6", transformOrigin: side },
|
|
416
|
+
{ opacity: 1, scale: "1", transformOrigin: side },
|
|
417
|
+
], { duration: ENTER_MS, delay: wait + ENTER_DELAY_MS, easing: FADE_EASING });
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const to = last.rel.get(keyOf(el));
|
|
421
|
+
const dx = from.x - to.x;
|
|
422
|
+
const dy = from.y - to.y;
|
|
423
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5 && !start)
|
|
424
|
+
continue;
|
|
425
|
+
const fade = start
|
|
426
|
+
? [
|
|
427
|
+
{ opacity: start.opacity, scale: String(start.scale), transformOrigin: side },
|
|
428
|
+
{ opacity: 1, scale: "1", transformOrigin: side },
|
|
429
|
+
]
|
|
430
|
+
: [{}, {}];
|
|
431
|
+
this.run(el, [
|
|
432
|
+
{ translate: `${dx}px ${dy}px`, ...fade[0] },
|
|
433
|
+
{ translate: "0px 0px", ...fade[1] },
|
|
434
|
+
], { duration: MOVE_MS, delay: wait, easing });
|
|
435
|
+
}
|
|
436
|
+
for (const l of leaving) {
|
|
437
|
+
if (l.key)
|
|
438
|
+
this.dropGhost(l.key);
|
|
439
|
+
const { clone, rect, size, side } = l;
|
|
440
|
+
clone.removeAttribute("data-flip");
|
|
441
|
+
clone.removeAttribute("id");
|
|
442
|
+
clone.removeAttribute("role");
|
|
443
|
+
Object.assign(clone.style, {
|
|
444
|
+
position: "absolute",
|
|
445
|
+
margin: "0",
|
|
446
|
+
left: `${(side === "right center" ? rect.right - size.w : rect.left) - origin.left}px`,
|
|
447
|
+
top: `${rect.top + rect.height / 2 - size.h / 2 - origin.top}px`,
|
|
448
|
+
width: `${size.w}px`,
|
|
449
|
+
height: `${size.h}px`,
|
|
450
|
+
});
|
|
451
|
+
this.layer.append(clone);
|
|
452
|
+
const anim = this.track(clone.animate([
|
|
453
|
+
{
|
|
454
|
+
opacity: l.from.opacity,
|
|
455
|
+
scale: String(l.from.scale),
|
|
456
|
+
translate: "0px 0px",
|
|
457
|
+
transformOrigin: side,
|
|
458
|
+
offset: 0,
|
|
459
|
+
},
|
|
460
|
+
// Shrink a little and drift towards its own side as it fades, in step with the glide.
|
|
461
|
+
{
|
|
462
|
+
opacity: 0,
|
|
463
|
+
scale: "0.9",
|
|
464
|
+
translate: `${side === "right center" ? EXIT_DRIFT_PX : -EXIT_DRIFT_PX}px 0px`,
|
|
465
|
+
transformOrigin: side,
|
|
466
|
+
offset: 1,
|
|
467
|
+
},
|
|
468
|
+
], { duration: EXIT_MS, delay: delay(l.seq), easing, fill: "both" }));
|
|
469
|
+
const ghost = { clone, anim };
|
|
470
|
+
if (l.key)
|
|
471
|
+
this.ghosts.set(l.key, ghost);
|
|
472
|
+
anim.finished.then(() => {
|
|
473
|
+
clone.remove();
|
|
474
|
+
if (l.key && this.ghosts.get(l.key) === ghost)
|
|
475
|
+
this.ghosts.delete(l.key);
|
|
476
|
+
}, () => undefined);
|
|
477
|
+
}
|
|
478
|
+
this.cache = last.rel;
|
|
479
|
+
}
|
|
480
|
+
/** A resize within a layout: glide what changed line, from where it is drawn now. */
|
|
481
|
+
reflow() {
|
|
482
|
+
this.direction();
|
|
483
|
+
const offsets = new Map();
|
|
484
|
+
const faded = new Map();
|
|
485
|
+
for (const [el, a] of this.anims) {
|
|
486
|
+
if (a.playState !== "running")
|
|
487
|
+
continue;
|
|
488
|
+
const cs = getComputedStyle(el);
|
|
489
|
+
const [x = "0", y = "0"] = cs.translate.split(" ");
|
|
490
|
+
offsets.set(el, { x: parseFloat(x) || 0, y: parseFloat(y) || 0 });
|
|
491
|
+
const opacity = parseFloat(cs.opacity);
|
|
492
|
+
const scale = parseFloat(cs.scale) || 1;
|
|
493
|
+
if (opacity < 1 || scale !== 1)
|
|
494
|
+
faded.set(el, { opacity, scale });
|
|
495
|
+
}
|
|
496
|
+
const now = this.measure(offsets);
|
|
497
|
+
if (this.cache.size) {
|
|
498
|
+
const easing = this.easing();
|
|
499
|
+
for (const el of now.els) {
|
|
500
|
+
const prev = this.cache.get(keyOf(el));
|
|
501
|
+
if (!prev)
|
|
502
|
+
continue;
|
|
503
|
+
const to = now.rel.get(keyOf(el));
|
|
504
|
+
// A changed line moves a piece; so does any shift of an inline cell, which only moves when
|
|
505
|
+
// a word wraps. Columns shift smoothly with the width and keep following it.
|
|
506
|
+
const inline = el.getAttribute("data-mode") === "inline";
|
|
507
|
+
if (Math.abs(prev.y - to.y) < 1 && !(inline && Math.abs(prev.x - to.x) >= 1))
|
|
508
|
+
continue;
|
|
509
|
+
const own = offsets.get(el) ?? ZERO;
|
|
510
|
+
const dx = prev.x - to.x + own.x;
|
|
511
|
+
const dy = prev.y - to.y + own.y;
|
|
512
|
+
// A piece still fading in carries on fading as it glides.
|
|
513
|
+
const start = faded.get(el);
|
|
514
|
+
const side = this.sideOf(el);
|
|
515
|
+
const fade = start
|
|
516
|
+
? [
|
|
517
|
+
{ opacity: start.opacity, scale: String(start.scale), transformOrigin: side },
|
|
518
|
+
{ opacity: 1, scale: "1", transformOrigin: side },
|
|
519
|
+
]
|
|
520
|
+
: [{}, {}];
|
|
521
|
+
this.run(el, [
|
|
522
|
+
{ translate: `${dx}px ${dy}px`, ...fade[0] },
|
|
523
|
+
{ translate: "0px 0px", ...fade[1] },
|
|
524
|
+
], { duration: MOVE_MS, easing });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
this.cache = now.rel;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
export const reducedMotion = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
531
|
+
/* ── Virtual rows ──────────────────────────────────────────────────────────── */
|
|
532
|
+
/** East Asian wide characters (CJK, Hangul, full-width forms): drawn about twice as wide. */
|
|
533
|
+
const WIDE = /[ᄀ-ᅟ⺀-가-힣豈-︰-﹏-⦆¢-₩]/g;
|
|
534
|
+
/** No character a wide one could be: most values, checked faster than counting. */
|
|
535
|
+
const ASCII = /^[\x00-\u10ff]*$/;
|
|
536
|
+
/** How long a value reads, in characters (wide ones twice): a stand-in for how wide its cell is drawn. */
|
|
537
|
+
function textLength(value) {
|
|
538
|
+
if (value == null)
|
|
539
|
+
return 0;
|
|
540
|
+
if (typeof value === "string")
|
|
541
|
+
return value.length + (ASCII.test(value) ? 0 : (value.match(WIDE)?.length ?? 0));
|
|
542
|
+
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean")
|
|
543
|
+
return String(value).length;
|
|
544
|
+
if (value instanceof Date)
|
|
545
|
+
return 16;
|
|
546
|
+
if (Array.isArray(value))
|
|
547
|
+
return value.reduce((sum, v) => sum + textLength(v) + 2, 0);
|
|
548
|
+
return 0;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* The rows that size a virtual table's columns: for each value of a row (`valuesOf`, one per
|
|
552
|
+
* column), the `per` rows where it is longest, and the `per` rows longest in all (a title with
|
|
553
|
+
* its inline cells). Rendered out of view, they stand in for every row, so a column keeps its
|
|
554
|
+
* width while rows scroll in and out. Returns indices into `rows`, in order.
|
|
555
|
+
*/
|
|
556
|
+
export function widestRows(rows, valuesOf, per = 2) {
|
|
557
|
+
// Slot 0 is the whole row; slot j + 1 its j-th value. Each keeps its `per` longest, longest first.
|
|
558
|
+
const best = [];
|
|
559
|
+
const keep = (slot, len, at) => {
|
|
560
|
+
const list = (best[slot] ??= []);
|
|
561
|
+
if (list.length === per && len <= list[per - 1].len)
|
|
562
|
+
return;
|
|
563
|
+
const i = list.findIndex((entry) => len > entry.len);
|
|
564
|
+
list.splice(i < 0 ? list.length : i, 0, { len, at });
|
|
565
|
+
if (list.length > per)
|
|
566
|
+
list.pop();
|
|
567
|
+
};
|
|
568
|
+
const visit = (at) => {
|
|
569
|
+
let total = 0;
|
|
570
|
+
valuesOf(rows[at]).forEach((value, j) => {
|
|
571
|
+
const len = textLength(value);
|
|
572
|
+
total += len;
|
|
573
|
+
if (len > 0)
|
|
574
|
+
keep(j + 1, len, at);
|
|
575
|
+
});
|
|
576
|
+
keep(0, total, at);
|
|
577
|
+
};
|
|
578
|
+
// Every row, up to SAMPLE_FROM; past it, the first and last rows and an even spread between —
|
|
579
|
+
// reading a million values would hold up the table's first paint for the width of a column.
|
|
580
|
+
if (rows.length <= SAMPLE_FROM)
|
|
581
|
+
for (let at = 0; at < rows.length; at++)
|
|
582
|
+
visit(at);
|
|
583
|
+
else {
|
|
584
|
+
const ends = 1000;
|
|
585
|
+
const step = (rows.length - 2 * ends) / (SAMPLE_FROM - 2 * ends);
|
|
586
|
+
for (let at = 0; at < ends; at++)
|
|
587
|
+
visit(at);
|
|
588
|
+
for (let x = ends; x < rows.length - ends; x += step)
|
|
589
|
+
visit(Math.floor(x));
|
|
590
|
+
for (let at = rows.length - ends; at < rows.length; at++)
|
|
591
|
+
visit(at);
|
|
592
|
+
}
|
|
593
|
+
return [...new Set(best.flat().map((entry) => entry.at))].sort((a, b) => a - b);
|
|
594
|
+
}
|
|
595
|
+
/** Past this many rows, `widestRows` reads a sample of them. */
|
|
596
|
+
const SAMPLE_FROM = 50_000;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type ThemeMode = "light" | "dark" | "system";
|
|
2
|
+
/** localStorage key the provider and `themeScript` share. */
|
|
3
|
+
export declare const THEME_STORAGE_KEY = "zon-theme";
|
|
4
|
+
/** The media query `system` follows. Not part of the public API. */
|
|
5
|
+
export declare const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
6
|
+
/**
|
|
7
|
+
* The page ground as one flat colour in each theme, --page-tone in tokens.css: what the grain
|
|
8
|
+
* over the background averages to. The browser's own bars (the status bar and toolbar on a
|
|
9
|
+
* phone) take it through `<meta name="theme-color">`, so they match the page.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PAGE_TONE: {
|
|
12
|
+
readonly light: "#f9f9f9";
|
|
13
|
+
readonly dark: "#141414";
|
|
14
|
+
};
|
|
15
|
+
/** The `theme-color` meta that names no media, made if the page has none. Not part of the public API. */
|
|
16
|
+
export declare function setThemeColor(dark: boolean): void;
|
|
17
|
+
/**
|
|
18
|
+
* Build the no-flash script for `<head>`. It applies `.dark` before first paint, using the
|
|
19
|
+
* same storage key and default as `ThemeProvider`, and sets `<meta name="theme-color">` to the
|
|
20
|
+
* theme's page tone (making the tag if there is none). Pass the same options to both.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createThemeScript({ storageKey, defaultTheme, themeColor, }?: {
|
|
23
|
+
storageKey?: string;
|
|
24
|
+
defaultTheme?: ThemeMode;
|
|
25
|
+
themeColor?: boolean;
|
|
26
|
+
}): string;
|
|
27
|
+
/**
|
|
28
|
+
* Inline this in `<head>`, before any stylesheet paints, to avoid a flash of the wrong theme:
|
|
29
|
+
* `<script dangerouslySetInnerHTML={{ __html: themeScript }} />`.
|
|
30
|
+
*/
|
|
31
|
+
export declare const themeScript: string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The theme's no-flash script, kept apart from ThemeProvider so it stays plain code: a server
|
|
3
|
+
* component (a Next.js root layout) can inline it, while the provider is a client component.
|
|
4
|
+
*/
|
|
5
|
+
/** localStorage key the provider and `themeScript` share. */
|
|
6
|
+
export const THEME_STORAGE_KEY = "zon-theme";
|
|
7
|
+
/** The media query `system` follows. Not part of the public API. */
|
|
8
|
+
export const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
9
|
+
/**
|
|
10
|
+
* The page ground as one flat colour in each theme, --page-tone in tokens.css: what the grain
|
|
11
|
+
* over the background averages to. The browser's own bars (the status bar and toolbar on a
|
|
12
|
+
* phone) take it through `<meta name="theme-color">`, so they match the page.
|
|
13
|
+
*/
|
|
14
|
+
export const PAGE_TONE = { light: "#f9f9f9", dark: "#141414" };
|
|
15
|
+
/** The `theme-color` meta that names no media, made if the page has none. Not part of the public API. */
|
|
16
|
+
export function setThemeColor(dark) {
|
|
17
|
+
let meta = document.querySelector('meta[name="theme-color"]:not([media])');
|
|
18
|
+
if (!meta) {
|
|
19
|
+
meta = document.createElement("meta");
|
|
20
|
+
meta.name = "theme-color";
|
|
21
|
+
document.head.appendChild(meta);
|
|
22
|
+
}
|
|
23
|
+
meta.content = dark ? PAGE_TONE.dark : PAGE_TONE.light;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A value as a JavaScript literal that is safe inside an HTML `<script>`: its JSON, with `<`
|
|
27
|
+
* written as `\u003c`, so a `</script>` or `<!--` in it cannot end the element or change how
|
|
28
|
+
* the browser reads it. `>`, `&` and the two line separators old engines reject in a string
|
|
29
|
+
* are escaped too, as frameworks do when they inline JSON.
|
|
30
|
+
*/
|
|
31
|
+
const literal = (value) => JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
32
|
+
/**
|
|
33
|
+
* Build the no-flash script for `<head>`. It applies `.dark` before first paint, using the
|
|
34
|
+
* same storage key and default as `ThemeProvider`, and sets `<meta name="theme-color">` to the
|
|
35
|
+
* theme's page tone (making the tag if there is none). Pass the same options to both.
|
|
36
|
+
*/
|
|
37
|
+
export function createThemeScript({ storageKey = THEME_STORAGE_KEY, defaultTheme = "system", themeColor = true, } = {}) {
|
|
38
|
+
const key = literal(storageKey);
|
|
39
|
+
const fallback = literal(defaultTheme);
|
|
40
|
+
const meta = themeColor
|
|
41
|
+
? `var m=document.querySelector('meta[name="theme-color"]:not([media])');if(!m){m=document.createElement("meta");m.name="theme-color";document.head.appendChild(m)}m.content=d?${literal(PAGE_TONE.dark)}:${literal(PAGE_TONE.light)};`
|
|
42
|
+
: "";
|
|
43
|
+
return `(function(){var t=null;try{t=localStorage.getItem(${key})}catch(e){}if(t!=="light"&&t!=="dark"&&t!=="system")t=${fallback};var d=t==="dark";if(t==="system"){try{d=matchMedia(${literal(DARK_QUERY)}).matches}catch(e){}}document.documentElement.classList.toggle("dark",d);${meta}})();`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Inline this in `<head>`, before any stylesheet paints, to avoid a flash of the wrong theme:
|
|
47
|
+
* `<script dangerouslySetInnerHTML={{ __html: themeScript }} />`.
|
|
48
|
+
*/
|
|
49
|
+
export const themeScript = createThemeScript();
|