@zonsh/ui 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -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/breadcrumb.d.ts +22 -0
- package/dist/components/breadcrumb.js +32 -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 +164 -0
- package/dist/components/card.d.ts +42 -0
- package/dist/components/card.js +76 -0
- package/dist/components/carousel.d.ts +90 -0
- package/dist/components/carousel.js +213 -0
- package/dist/components/chart.d.ts +180 -0
- package/dist/components/chart.js +286 -0
- package/dist/components/checkbox.d.ts +23 -0
- package/dist/components/checkbox.js +43 -0
- package/dist/components/code-block.d.ts +45 -0
- package/dist/components/code-block.js +58 -0
- package/dist/components/code-highlight.d.ts +13 -0
- package/dist/components/code-highlight.js +107 -0
- package/dist/components/collapsible.d.ts +20 -0
- package/dist/components/collapsible.js +32 -0
- package/dist/components/color-picker.d.ts +85 -0
- package/dist/components/color-picker.js +407 -0
- package/dist/components/combobox.d.ts +81 -0
- package/dist/components/combobox.js +100 -0
- package/dist/components/command.d.ts +112 -0
- package/dist/components/command.js +212 -0
- package/dist/components/context-menu.d.ts +29 -0
- package/dist/components/context-menu.js +35 -0
- package/dist/components/conversation.d.ts +27 -0
- package/dist/components/conversation.js +293 -0
- package/dist/components/copy-button.d.ts +46 -0
- package/dist/components/copy-button.js +118 -0
- package/dist/components/data-table.d.ts +175 -0
- package/dist/components/data-table.js +302 -0
- package/dist/components/date-picker.d.ts +91 -0
- package/dist/components/date-picker.js +207 -0
- package/dist/components/dialog.d.ts +48 -0
- package/dist/components/dialog.js +92 -0
- package/dist/components/direction.d.ts +16 -0
- package/dist/components/direction.js +18 -0
- package/dist/components/drawer.d.ts +60 -0
- package/dist/components/drawer.js +76 -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 +15 -0
- package/dist/components/field.js +36 -0
- package/dist/components/file-drop.d.ts +55 -0
- package/dist/components/file-drop.js +197 -0
- package/dist/components/filter-bar.d.ts +106 -0
- package/dist/components/filter-bar.js +296 -0
- package/dist/components/form.d.ts +33 -0
- package/dist/components/form.js +34 -0
- package/dist/components/graph.d.ts +105 -0
- package/dist/components/graph.js +786 -0
- package/dist/components/illustration.d.ts +85 -0
- package/dist/components/illustration.js +165 -0
- package/dist/components/input-group.d.ts +127 -0
- package/dist/components/input-group.js +292 -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 +33 -0
- package/dist/components/kbd.js +38 -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/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 +138 -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 +56 -0
- package/dist/components/meter.d.ts +31 -0
- package/dist/components/meter.js +25 -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 +36 -0
- package/dist/components/number-field.js +153 -0
- package/dist/components/otp-field.d.ts +35 -0
- package/dist/components/otp-field.js +94 -0
- package/dist/components/pagination.d.ts +31 -0
- package/dist/components/pagination.js +70 -0
- package/dist/components/pdf-viewer.d.ts +69 -0
- package/dist/components/pdf-viewer.js +929 -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 +23 -0
- package/dist/components/prompt-input.d.ts +131 -0
- package/dist/components/prompt-input.js +403 -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/reasoning.d.ts +31 -0
- package/dist/components/reasoning.js +70 -0
- package/dist/components/resizable.d.ts +38 -0
- package/dist/components/resizable.js +41 -0
- package/dist/components/response.d.ts +30 -0
- package/dist/components/response.js +538 -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 +60 -0
- package/dist/components/separator.d.ts +14 -0
- package/dist/components/separator.js +17 -0
- package/dist/components/sidebar.d.ts +147 -0
- package/dist/components/sidebar.js +489 -0
- package/dist/components/site-header.d.ts +59 -0
- package/dist/components/site-header.js +67 -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 +129 -0
- package/dist/components/sources.d.ts +25 -0
- package/dist/components/sources.js +35 -0
- package/dist/components/spinner.d.ts +36 -0
- package/dist/components/spinner.js +72 -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 +162 -0
- package/dist/components/table.js +758 -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 +40 -0
- package/dist/components/tags-input.js +239 -0
- package/dist/components/textarea.d.ts +13 -0
- package/dist/components/textarea.js +16 -0
- package/dist/components/theme.d.ts +41 -0
- package/dist/components/theme.js +112 -0
- package/dist/components/time-field.d.ts +51 -0
- package/dist/components/time-field.js +437 -0
- package/dist/components/timeline.d.ts +76 -0
- package/dist/components/timeline.js +99 -0
- package/dist/components/toast.d.ts +72 -0
- package/dist/components/toast.js +196 -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 +52 -0
- package/dist/components/tool-call.js +57 -0
- package/dist/components/toolbar.d.ts +17 -0
- package/dist/components/toolbar.js +34 -0
- package/dist/components/tooltip.d.ts +42 -0
- package/dist/components/tooltip.js +47 -0
- package/dist/components/tree.d.ts +75 -0
- package/dist/components/tree.js +636 -0
- package/dist/components/typography.d.ts +134 -0
- package/dist/components/typography.js +176 -0
- package/dist/components/video-player.d.ts +276 -0
- package/dist/components/video-player.js +1352 -0
- package/dist/components/whiteboard.d.ts +80 -0
- package/dist/components/whiteboard.js +389 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +86 -0
- package/dist/lib/cn.d.ts +20 -0
- package/dist/lib/cn.js +38 -0
- package/dist/lib/code-highlight.d.ts +31 -0
- package/dist/lib/code-highlight.js +24 -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/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 +200 -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/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/platform.d.ts +33 -0
- package/dist/lib/platform.js +68 -0
- package/dist/lib/room.d.ts +25 -0
- package/dist/lib/room.js +46 -0
- package/dist/lib/table-fit.d.ts +143 -0
- package/dist/lib/table-fit.js +577 -0
- package/dist/lib/theme-script.d.ts +18 -0
- package/dist/lib/theme-script.js +29 -0
- package/dist/styles/expressive.css +188 -0
- package/dist/styles/fonts.css +145 -0
- package/dist/styles/index.css +206 -0
- package/dist/styles/material.css +313 -0
- package/dist/styles/parts/ai.css +360 -0
- package/dist/styles/parts/brand.css +75 -0
- package/dist/styles/parts/controls.css +725 -0
- package/dist/styles/parts/data.css +222 -0
- package/dist/styles/parts/editorial.css +120 -0
- package/dist/styles/parts/feedback.css +273 -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 +232 -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/parts/whiteboard.css +855 -0
- package/dist/styles/tokens.css +290 -0
- package/dist/vite.d.ts +116 -0
- package/dist/vite.js +129 -0
- package/package.json +188 -5
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A guard in front of marked, for text nobody controls: a model's reply. marked is quadratic on
|
|
3
|
+
* input no reply needs — thousands of `*a ` or `_a` in one paragraph, `**` nested a thousand
|
|
4
|
+
* deep, a long run of `[` — and recurses once per level of nesting, so a few thousand quotes or
|
|
5
|
+
* list markers in a row overflow the stack. A 10 KB paragraph of `*a ` took 2 s, and while a reply
|
|
6
|
+
* streams in it is parsed again on every word. Both checks read the text alone (no clock), so a
|
|
7
|
+
* server render and the first client render always agree; text under budget is never changed.
|
|
8
|
+
*/
|
|
9
|
+
/** The deepest nesting of quotes and list items the parser is given. */
|
|
10
|
+
export const MAX_DEPTH = 24;
|
|
11
|
+
/** A quote or list item indented further than this many columns starts here instead. */
|
|
12
|
+
const MAX_INDENT = 100;
|
|
13
|
+
/** A quote's `>`, or a list item's marker followed by a space or the end of the line. */
|
|
14
|
+
const MARKER = /[ \t]*(?:>[ \t]?|(?:[-+*]|\d{1,9}[.)])(?:[ \t]+|$))/y;
|
|
15
|
+
/** A fence line once its quotes and list markers are read: up to three spaces, then the fence. */
|
|
16
|
+
const FENCE = /^ {0,3}(`{3,}|~{3,})(.*)$/;
|
|
17
|
+
/**
|
|
18
|
+
* The text with no line nested deeper than MAX_DEPTH: past that many quote and list markers, the
|
|
19
|
+
* next one is escaped and the rest of the line is text. A quote or list item indented past
|
|
20
|
+
* MAX_INDENT columns is moved back to it. Code fences are left as they are, and so is any text no
|
|
21
|
+
* reply needs changed: it comes back as the same string.
|
|
22
|
+
*/
|
|
23
|
+
export function capNesting(text) {
|
|
24
|
+
const lines = text.split("\n");
|
|
25
|
+
let fence = null;
|
|
26
|
+
let changed = false;
|
|
27
|
+
for (let i = 0; i < lines.length; i++) {
|
|
28
|
+
const line = lines[i];
|
|
29
|
+
let at = 0;
|
|
30
|
+
let depth = 0;
|
|
31
|
+
let capped = line;
|
|
32
|
+
for (MARKER.lastIndex = 0;; MARKER.lastIndex = at) {
|
|
33
|
+
const marker = MARKER.exec(line);
|
|
34
|
+
if (!marker)
|
|
35
|
+
break;
|
|
36
|
+
const start = at + marker[0].search(/\S/);
|
|
37
|
+
if (depth === 0 && start > MAX_INDENT) {
|
|
38
|
+
capped = " ".repeat(MAX_INDENT) + line.slice(start);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
if (++depth > MAX_DEPTH) {
|
|
42
|
+
// Escaped, the marker is text: a bullet or `>` itself, an ordered marker's `.` or `)`.
|
|
43
|
+
const mark = /\d/.test(line[start]) ? start + /^\d+/.exec(line.slice(start))[0].length : start;
|
|
44
|
+
capped = `${line.slice(0, mark)}\\${line.slice(mark)}`;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
at += marker[0].length;
|
|
48
|
+
}
|
|
49
|
+
// Inside a fence, every line is code: only its closing fence matters.
|
|
50
|
+
const content = FENCE.exec(line.slice(at));
|
|
51
|
+
if (fence) {
|
|
52
|
+
if (content && content[1][0] === fence[0] && content[1].length >= fence.length && !content[2].trim())
|
|
53
|
+
fence = null;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (content && !(content[1][0] === "`" && content[2].includes("`")))
|
|
57
|
+
fence = content[1];
|
|
58
|
+
if (capped !== line) {
|
|
59
|
+
lines[i] = capped;
|
|
60
|
+
changed = true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return changed ? lines.join("\n") : text;
|
|
64
|
+
}
|
|
65
|
+
/** Below this length an inline run is always parsed: marked is quick on short text. */
|
|
66
|
+
const SHORT = 400;
|
|
67
|
+
/** How far marked may scan ahead for the closers of emphasis, links and tags, in delimiters (≈10 ms). */
|
|
68
|
+
const SCAN_BUDGET = 20_000;
|
|
69
|
+
/** Intraword `_` and `*`, and `!` not before `[`, times the run's length: marked reads the run again for each. */
|
|
70
|
+
const RESCAN_BUDGET = 4_000_000;
|
|
71
|
+
const space = (c) => c === undefined || /\s/.test(c);
|
|
72
|
+
const word = (c) => c !== undefined && /[\p{L}\p{N}]/u.test(c);
|
|
73
|
+
/** What closes a link's text and a tag. */
|
|
74
|
+
const CLOSERS = { "]": "[", ">": "<" };
|
|
75
|
+
/**
|
|
76
|
+
* Whether marked would take too long on one inline run — a paragraph's or a heading's text, a
|
|
77
|
+
* table cell, a list item's text. An estimate in one pass: how far each emphasis delimiter (`*`,
|
|
78
|
+
* `_`, `~`), each `[` and each `<` scans for its closer, delimiter by delimiter, with a stack per
|
|
79
|
+
* kind; and how often an intraword delimiter makes marked read the run again.
|
|
80
|
+
*/
|
|
81
|
+
export function overBudget(text) {
|
|
82
|
+
if (text.length <= SHORT)
|
|
83
|
+
return false;
|
|
84
|
+
let scans = 0;
|
|
85
|
+
let rescans = 0;
|
|
86
|
+
// Per kind: the delimiters seen so far, and the ones still open (by their number).
|
|
87
|
+
const seen = { "*": 0, _: 0, "~": 0, "[": 0, "<": 0 };
|
|
88
|
+
const open = { "*": [], _: [], "~": [], "[": [], "<": [] };
|
|
89
|
+
for (let i = 0; i < text.length; i++) {
|
|
90
|
+
const c = text[i];
|
|
91
|
+
if (c === "[" || c === "<")
|
|
92
|
+
open[c].push(seen[c]++);
|
|
93
|
+
else if (c === "]" || c === ">") {
|
|
94
|
+
const kind = CLOSERS[c];
|
|
95
|
+
const at = open[kind].pop();
|
|
96
|
+
if (at !== undefined)
|
|
97
|
+
scans += seen[kind] - at;
|
|
98
|
+
}
|
|
99
|
+
else if (c === "*" || c === "_" || c === "~") {
|
|
100
|
+
let j = i;
|
|
101
|
+
while (text[j + 1] === c)
|
|
102
|
+
j++;
|
|
103
|
+
const before = text[i - 1];
|
|
104
|
+
const after = text[j + 1];
|
|
105
|
+
const stack = open[c];
|
|
106
|
+
if (!space(before) && stack.length)
|
|
107
|
+
scans += seen[c] - stack.pop();
|
|
108
|
+
else if (!space(after))
|
|
109
|
+
stack.push(seen[c]);
|
|
110
|
+
if (c !== "~" && word(before) && word(after))
|
|
111
|
+
rescans++;
|
|
112
|
+
seen[c]++;
|
|
113
|
+
i = j;
|
|
114
|
+
}
|
|
115
|
+
else if (c === "!" && text[i + 1] !== "[")
|
|
116
|
+
rescans++;
|
|
117
|
+
}
|
|
118
|
+
// What is still open at the end was scanned to the end.
|
|
119
|
+
for (const kind in open)
|
|
120
|
+
for (const at of open[kind])
|
|
121
|
+
scans += seen[kind] - at;
|
|
122
|
+
return scans > SCAN_BUDGET || rescans * text.length > RESCAN_BUDGET;
|
|
123
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* One ref callback that sets each of `refs` — a part's own ref and the one a consumer passed.
|
|
4
|
+
* In React 19 `ref` is an ordinary prop: spread after the part's own, it would replace it.
|
|
5
|
+
*
|
|
6
|
+
* It returns a cleanup, so React 19 detaches through it rather than calling it with null: each
|
|
7
|
+
* callback ref's own cleanup runs (or it is called with null, if it returned none), and each
|
|
8
|
+
* object ref is cleared.
|
|
9
|
+
*/
|
|
10
|
+
export declare function mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]): React.RefCallback<T>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One ref callback that sets each of `refs` — a part's own ref and the one a consumer passed.
|
|
3
|
+
* In React 19 `ref` is an ordinary prop: spread after the part's own, it would replace it.
|
|
4
|
+
*
|
|
5
|
+
* It returns a cleanup, so React 19 detaches through it rather than calling it with null: each
|
|
6
|
+
* callback ref's own cleanup runs (or it is called with null, if it returned none), and each
|
|
7
|
+
* object ref is cleared.
|
|
8
|
+
*/
|
|
9
|
+
export function mergeRefs(...refs) {
|
|
10
|
+
return (node) => {
|
|
11
|
+
const cleanups = refs.map((ref) => {
|
|
12
|
+
if (typeof ref === "function") {
|
|
13
|
+
const cleanup = ref(node);
|
|
14
|
+
return typeof cleanup === "function" ? cleanup : () => ref(null);
|
|
15
|
+
}
|
|
16
|
+
if (ref) {
|
|
17
|
+
ref.current = node;
|
|
18
|
+
return () => {
|
|
19
|
+
ref.current = null;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
});
|
|
24
|
+
return () => cleanups.forEach((cleanup) => cleanup?.());
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `--duration` token in milliseconds, as an element sees it — 0 under reduced motion. Reads
|
|
3
|
+
* either unit: a build's CSS minifier writes `150ms` as `.15s`, so a bare `parseFloat` would take
|
|
4
|
+
* a production duration for 0.15ms and skip every scripted animation.
|
|
5
|
+
*/
|
|
6
|
+
export declare function cssDuration(el?: Element): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `--duration` token in milliseconds, as an element sees it — 0 under reduced motion. Reads
|
|
3
|
+
* either unit: a build's CSS minifier writes `150ms` as `.15s`, so a bare `parseFloat` would take
|
|
4
|
+
* a production duration for 0.15ms and skip every scripted animation.
|
|
5
|
+
*/
|
|
6
|
+
export function cssDuration(el = document.documentElement) {
|
|
7
|
+
const value = getComputedStyle(el).getPropertyValue("--duration").trim();
|
|
8
|
+
const number = parseFloat(value);
|
|
9
|
+
if (!Number.isFinite(number))
|
|
10
|
+
return 0;
|
|
11
|
+
return value.endsWith("ms") ? number : value.endsWith("s") ? number * 1000 : number;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "pdfjs-dist/build/pdf.worker.min.mjs";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The pdf.js worker, as its own module so bundlers (Vite, webpack 5, Rollup) can build it from
|
|
3
|
+
* `new Worker(new URL("./pdf-worker.ts", import.meta.url), { type: "module" })` in pdf.ts.
|
|
4
|
+
* Loaded in a worker, pdf.js answers the page that started it.
|
|
5
|
+
*/
|
|
6
|
+
import "pdfjs-dist/build/pdf.worker.min.mjs";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as Pdfjs from "pdfjs-dist";
|
|
2
|
+
export type PdfLib = typeof Pdfjs;
|
|
3
|
+
export type PdfDocument = Pdfjs.PDFDocumentProxy;
|
|
4
|
+
export type PdfPage = Pdfjs.PDFPageProxy;
|
|
5
|
+
export type PdfSource = string | URL | Uint8Array | ArrayBuffer;
|
|
6
|
+
export declare function loadPdfjs(): Promise<PdfLib>;
|
|
7
|
+
/**
|
|
8
|
+
* Open a document. Data is copied, because pdf.js takes ownership of the buffer it is given.
|
|
9
|
+
* pdf.js logs only errors: a broken file ends in the viewer's own error state, not a console of
|
|
10
|
+
* parser warnings (the worker's level is set where it is created, above).
|
|
11
|
+
*/
|
|
12
|
+
export declare function openPdf(src: PdfSource): Promise<{
|
|
13
|
+
task: import("pdfjs-dist/types/src/display/api").PDFDocumentLoadingTask;
|
|
14
|
+
pdfjs: typeof Pdfjs;
|
|
15
|
+
}>;
|
|
16
|
+
/** A file name for downloads: the one given, or the last part of the URL. */
|
|
17
|
+
export declare function pdfFileName(src: PdfSource, fileName?: string): string;
|
|
18
|
+
/** CSS pixels per PDF point: "100%" shows a page at its printed size on screen (96 / 72). */
|
|
19
|
+
export declare const CSS_UNITS: number;
|
package/dist/lib/pdf.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
let lib;
|
|
2
|
+
/**
|
|
3
|
+
* pdf.js and one worker shared by every document on the page. The worker is passed to each
|
|
4
|
+
* document explicitly: pdf.js then never tears it down when one document closes (a shared
|
|
5
|
+
* `GlobalWorkerOptions.workerPort` would be destroyed with the first document that closes).
|
|
6
|
+
* An app that sets `GlobalWorkerOptions.workerSrc` or `workerPort` itself keeps its own setup.
|
|
7
|
+
*/
|
|
8
|
+
function load() {
|
|
9
|
+
lib ??= import("pdfjs-dist").then(async (pdfjs) => {
|
|
10
|
+
const options = pdfjs.GlobalWorkerOptions;
|
|
11
|
+
if (options.workerPort || options.workerSrc)
|
|
12
|
+
return { pdfjs };
|
|
13
|
+
try {
|
|
14
|
+
const port = new Worker(new URL("./pdf-worker.js", import.meta.url), { type: "module" });
|
|
15
|
+
return { pdfjs, worker: pdfjs.PDFWorker.create({ port, verbosity: pdfjs.VerbosityLevel.ERRORS }) };
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// No module workers here: run pdf.js on the main thread instead (loading the worker
|
|
19
|
+
// bundle sets globalThis.pdfjsWorker, which pdf.js picks up).
|
|
20
|
+
await import("./pdf-worker.js");
|
|
21
|
+
return { pdfjs };
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return lib;
|
|
25
|
+
}
|
|
26
|
+
export async function loadPdfjs() {
|
|
27
|
+
return (await load()).pdfjs;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Open a document. Data is copied, because pdf.js takes ownership of the buffer it is given.
|
|
31
|
+
* pdf.js logs only errors: a broken file ends in the viewer's own error state, not a console of
|
|
32
|
+
* parser warnings (the worker's level is set where it is created, above).
|
|
33
|
+
*/
|
|
34
|
+
export async function openPdf(src) {
|
|
35
|
+
const { pdfjs, worker } = await load();
|
|
36
|
+
const task = pdfjs.getDocument({
|
|
37
|
+
...(typeof src === "string" || src instanceof URL
|
|
38
|
+
? { url: String(src) }
|
|
39
|
+
: { data: src instanceof ArrayBuffer ? new Uint8Array(src.slice(0)) : src.slice() }),
|
|
40
|
+
worker,
|
|
41
|
+
verbosity: pdfjs.VerbosityLevel.ERRORS,
|
|
42
|
+
});
|
|
43
|
+
return { task, pdfjs };
|
|
44
|
+
}
|
|
45
|
+
/** A file name for downloads: the one given, or the last part of the URL. */
|
|
46
|
+
export function pdfFileName(src, fileName) {
|
|
47
|
+
if (fileName)
|
|
48
|
+
return fileName;
|
|
49
|
+
if (typeof src === "string" || src instanceof URL) {
|
|
50
|
+
const path = String(src).split(/[?#]/)[0];
|
|
51
|
+
const last = decodeURIComponent(path.slice(path.lastIndexOf("/") + 1));
|
|
52
|
+
if (last)
|
|
53
|
+
return last.toLowerCase().endsWith(".pdf") ? last : `${last}.pdf`;
|
|
54
|
+
}
|
|
55
|
+
return "document.pdf";
|
|
56
|
+
}
|
|
57
|
+
/** CSS pixels per PDF point: "100%" shows a page at its printed size on screen (96 / 72). */
|
|
58
|
+
export const CSS_UNITS = 96 / 72;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apple's keyboards say ⌘ where others say Ctrl. Read from User-Agent Client Hints where the
|
|
3
|
+
* browser has them (Chromium: "macOS"), else from `navigator.platform` (Safari, Firefox).
|
|
4
|
+
*/
|
|
5
|
+
export declare function isApple(): boolean;
|
|
6
|
+
/** The modifier key for shortcuts on this device: "⌘" on Apple, "Ctrl" elsewhere. */
|
|
7
|
+
export declare const modKey: () => "Ctrl" | "⌘";
|
|
8
|
+
/**
|
|
9
|
+
* Whether a key event holds this device's shortcut modifier and not the other: ⌘ on Apple, Ctrl
|
|
10
|
+
* elsewhere. Not `metaKey || ctrlKey` — on a Mac, Ctrl+B and Ctrl+K move the caret in a text field.
|
|
11
|
+
* Read it in an event handler, never while rendering: the server cannot know the device.
|
|
12
|
+
*/
|
|
13
|
+
export declare function modPressed(event: {
|
|
14
|
+
metaKey: boolean;
|
|
15
|
+
ctrlKey: boolean;
|
|
16
|
+
}): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The device's shortcut keys, for hints: the modifier (`mod`, "⌘" or "Ctrl"), and whether it
|
|
19
|
+
* has a keyboard at all (`hasKeyboard`) — not a touch-only phone or tablet, where nobody
|
|
20
|
+
* presses ⌘V. A tablet with a keyboard and trackpad counts as having keys. On the server, and in the first client render,
|
|
21
|
+
* it answers "Ctrl" with keys, then settles on the device's own answer.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useShortcutKeys(): {
|
|
24
|
+
mod: string;
|
|
25
|
+
hasKeyboard: boolean;
|
|
26
|
+
};
|
|
27
|
+
/** Each key of a shortcut as the device's keyboard prints it: `mod` is ⌘ or Ctrl, and so on. */
|
|
28
|
+
export declare function keyNames(keys: string[], mod: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* A shortcut as text, the way each platform writes it in menus: run together on Apple ("⇧⌘Z",
|
|
31
|
+
* modifiers in Apple's order), joined with "+" elsewhere ("Ctrl+Shift+Z").
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatShortcut(keys: string[], mod: string): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Apple's keyboards say ⌘ where others say Ctrl. Read from User-Agent Client Hints where the
|
|
4
|
+
* browser has them (Chromium: "macOS"), else from `navigator.platform` (Safari, Firefox).
|
|
5
|
+
*/
|
|
6
|
+
export function isApple() {
|
|
7
|
+
if (typeof navigator === "undefined")
|
|
8
|
+
return false;
|
|
9
|
+
const hints = navigator.userAgentData;
|
|
10
|
+
return /mac|iphone|ipad|ipod/i.test(hints?.platform || navigator.platform || "");
|
|
11
|
+
}
|
|
12
|
+
/** The modifier key for shortcuts on this device: "⌘" on Apple, "Ctrl" elsewhere. */
|
|
13
|
+
export const modKey = () => (isApple() ? "⌘" : "Ctrl");
|
|
14
|
+
/**
|
|
15
|
+
* Whether a key event holds this device's shortcut modifier and not the other: ⌘ on Apple, Ctrl
|
|
16
|
+
* elsewhere. Not `metaKey || ctrlKey` — on a Mac, Ctrl+B and Ctrl+K move the caret in a text field.
|
|
17
|
+
* Read it in an event handler, never while rendering: the server cannot know the device.
|
|
18
|
+
*/
|
|
19
|
+
export function modPressed(event) {
|
|
20
|
+
return isApple() ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
|
|
21
|
+
}
|
|
22
|
+
const touchOnly = "(hover: none) and (pointer: coarse)";
|
|
23
|
+
const subscribeTouch = (onChange) => {
|
|
24
|
+
const query = window.matchMedia(touchOnly);
|
|
25
|
+
query.addEventListener("change", onChange);
|
|
26
|
+
return () => query.removeEventListener("change", onChange);
|
|
27
|
+
};
|
|
28
|
+
const noSubscribe = () => () => { };
|
|
29
|
+
/**
|
|
30
|
+
* The device's shortcut keys, for hints: the modifier (`mod`, "⌘" or "Ctrl"), and whether it
|
|
31
|
+
* has a keyboard at all (`hasKeyboard`) — not a touch-only phone or tablet, where nobody
|
|
32
|
+
* presses ⌘V. A tablet with a keyboard and trackpad counts as having keys. On the server, and in the first client render,
|
|
33
|
+
* it answers "Ctrl" with keys, then settles on the device's own answer.
|
|
34
|
+
*/
|
|
35
|
+
export function useShortcutKeys() {
|
|
36
|
+
const mod = React.useSyncExternalStore(noSubscribe, modKey, () => "Ctrl");
|
|
37
|
+
const hasKeyboard = React.useSyncExternalStore(subscribeTouch, () => !window.matchMedia(touchOnly).matches, () => true);
|
|
38
|
+
return { mod, hasKeyboard };
|
|
39
|
+
}
|
|
40
|
+
/** Keys that are written differently on Apple keyboards and on others. */
|
|
41
|
+
const appleKeys = { mod: "⌘", shift: "⇧", alt: "⌥", ctrl: "⌃", enter: "↵" };
|
|
42
|
+
const otherKeys = {
|
|
43
|
+
mod: "Ctrl",
|
|
44
|
+
shift: "Shift",
|
|
45
|
+
alt: "Alt",
|
|
46
|
+
ctrl: "Ctrl",
|
|
47
|
+
enter: "Enter",
|
|
48
|
+
};
|
|
49
|
+
/** Each key of a shortcut as the device's keyboard prints it: `mod` is ⌘ or Ctrl, and so on. */
|
|
50
|
+
export function keyNames(keys, mod) {
|
|
51
|
+
const names = mod === "⌘" ? appleKeys : otherKeys;
|
|
52
|
+
return keys.map((key) => names[key.toLowerCase()] ?? key);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A shortcut as text, the way each platform writes it in menus: run together on Apple ("⇧⌘Z",
|
|
56
|
+
* modifiers in Apple's order), joined with "+" elsewhere ("Ctrl+Shift+Z").
|
|
57
|
+
*/
|
|
58
|
+
export function formatShortcut(keys, mod) {
|
|
59
|
+
if (mod !== "⌘")
|
|
60
|
+
return keyNames(keys, mod).join("+");
|
|
61
|
+
const order = ["ctrl", "alt", "shift", "mod"];
|
|
62
|
+
const sorted = [...keys].sort((a, b) => {
|
|
63
|
+
const ia = order.indexOf(a.toLowerCase());
|
|
64
|
+
const ib = order.indexOf(b.toLowerCase());
|
|
65
|
+
return (ia === -1 ? order.length : ia) - (ib === -1 ? order.length : ib);
|
|
66
|
+
});
|
|
67
|
+
return keyNames(sorted, mod).join("");
|
|
68
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/** The nearest ancestor that scrolls sideways (auto/scroll), or null for the window. */
|
|
3
|
+
export declare function roomOf(el: Element | null): HTMLElement | null;
|
|
4
|
+
/**
|
|
5
|
+
* A collision boundary for a popup opened from `trigger`: its room's left and right edges, the
|
|
6
|
+
* window's top and bottom. Undefined when the trigger has no room of its own (the window).
|
|
7
|
+
*
|
|
8
|
+
* The edges are read each time the popup is positioned, not once: the room moves when the window
|
|
9
|
+
* resizes or the layout around it changes, and a popup kept to where the room used to be would
|
|
10
|
+
* open shrunk or away from its trigger.
|
|
11
|
+
*/
|
|
12
|
+
export declare function roomBounds(trigger: Element | null): {
|
|
13
|
+
readonly x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
readonly width: number;
|
|
16
|
+
readonly height: number;
|
|
17
|
+
} | undefined;
|
|
18
|
+
/** Lets a popup find the trigger that opened it: the trigger registers, the content reads. */
|
|
19
|
+
export interface TriggerRoom {
|
|
20
|
+
trigger: HTMLElement | null;
|
|
21
|
+
setTrigger: (el: HTMLElement | null) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare const TriggerRoomContext: React.Context<TriggerRoom | null>;
|
|
24
|
+
/** State for a popup root: the trigger it opens from. Provide it with `TriggerRoomContext`. */
|
|
25
|
+
export declare function useTriggerRoom(): TriggerRoom;
|
package/dist/lib/room.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
/*
|
|
3
|
+
* A popup is portalled out of the panel its trigger sits in, so by default it only keeps inside
|
|
4
|
+
* the window. Across, it should keep inside the room its trigger has — the nearest scrolling
|
|
5
|
+
* container: a side panel, a dialog body, the docs' narrowed stage. Up and down it may still use
|
|
6
|
+
* the window, or a short panel would crop it.
|
|
7
|
+
*/
|
|
8
|
+
/** The nearest ancestor that scrolls sideways (auto/scroll), or null for the window. */
|
|
9
|
+
export function roomOf(el) {
|
|
10
|
+
let room = el?.parentElement ?? null;
|
|
11
|
+
while (room && room !== document.body && !/auto|scroll/.test(getComputedStyle(room).overflowX)) {
|
|
12
|
+
room = room.parentElement;
|
|
13
|
+
}
|
|
14
|
+
return room && room !== document.body ? room : null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A collision boundary for a popup opened from `trigger`: its room's left and right edges, the
|
|
18
|
+
* window's top and bottom. Undefined when the trigger has no room of its own (the window).
|
|
19
|
+
*
|
|
20
|
+
* The edges are read each time the popup is positioned, not once: the room moves when the window
|
|
21
|
+
* resizes or the layout around it changes, and a popup kept to where the room used to be would
|
|
22
|
+
* open shrunk or away from its trigger.
|
|
23
|
+
*/
|
|
24
|
+
export function roomBounds(trigger) {
|
|
25
|
+
const room = roomOf(trigger);
|
|
26
|
+
if (!room)
|
|
27
|
+
return undefined;
|
|
28
|
+
return {
|
|
29
|
+
get x() {
|
|
30
|
+
return room.getBoundingClientRect().left;
|
|
31
|
+
},
|
|
32
|
+
y: 0,
|
|
33
|
+
get width() {
|
|
34
|
+
return room.getBoundingClientRect().width;
|
|
35
|
+
},
|
|
36
|
+
get height() {
|
|
37
|
+
return window.innerHeight;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export const TriggerRoomContext = React.createContext(null);
|
|
42
|
+
/** State for a popup root: the trigger it opens from. Provide it with `TriggerRoomContext`. */
|
|
43
|
+
export function useTriggerRoom() {
|
|
44
|
+
const [trigger, setTrigger] = React.useState(null);
|
|
45
|
+
return React.useMemo(() => ({ trigger, setTrigger }), [trigger]);
|
|
46
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/** Where a column's cell is drawn at the current width. */
|
|
2
|
+
export type FitMode = "column" | "inline" | "hidden";
|
|
3
|
+
export interface FitColumn {
|
|
4
|
+
/** Stable id, unique among the columns (the column's index in the table). */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Lower steps out first. A column with no `priority`, `inline` or `minWidth` never steps out. */
|
|
7
|
+
priority?: number;
|
|
8
|
+
/** When the column steps out, show its cell right after the title instead of hiding it. */
|
|
9
|
+
inline?: boolean;
|
|
10
|
+
/** Optional floor, in rem of container width: below it the column steps out regardless. */
|
|
11
|
+
minWidth?: number;
|
|
12
|
+
/** The grid track while the column has its own column. Defaults to `auto`. */
|
|
13
|
+
width?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface FitLayout {
|
|
16
|
+
/** How many columns have stepped out, in removal order. */
|
|
17
|
+
step: number;
|
|
18
|
+
/** Every removable column is out or inline: the only layout in which titles may wrap. */
|
|
19
|
+
final: boolean;
|
|
20
|
+
modes: Record<string, FitMode>;
|
|
21
|
+
/** True while at least one column is drawn inside the title cell. */
|
|
22
|
+
inlined: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** The columns that can step out, in the order they do. The title never does. */
|
|
25
|
+
export declare function removalOrder(columns: FitColumn[], title: string): FitColumn[];
|
|
26
|
+
/**
|
|
27
|
+
* The order columns are drawn in: those before the title as given, the title, then its inline
|
|
28
|
+
* columns in the order they step out, then the others as given. Rows keep this DOM order at
|
|
29
|
+
* every width, so what is read matches what is seen.
|
|
30
|
+
*/
|
|
31
|
+
export declare function drawOrder(columns: FitColumn[], title: string): FitColumn[];
|
|
32
|
+
export declare function layoutFor(step: number, order: FitColumn[], columns: FitColumn[]): FitLayout;
|
|
33
|
+
/** Natural, single-line widths, measured once per data or font change. */
|
|
34
|
+
export interface FitMetrics {
|
|
35
|
+
/** Each row: its title on one line and each cell's width. Header rows carry no inline cells. */
|
|
36
|
+
rows: {
|
|
37
|
+
title: number;
|
|
38
|
+
cells: Record<string, number>;
|
|
39
|
+
head: boolean;
|
|
40
|
+
}[];
|
|
41
|
+
/** Each column's track while it has its own column, header included. */
|
|
42
|
+
tracks: Record<string, number>;
|
|
43
|
+
/** The space between the title and an inline cell. */
|
|
44
|
+
space: number;
|
|
45
|
+
}
|
|
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 declare function measuredRows(body: HTMLElement): HTMLElement[];
|
|
52
|
+
/**
|
|
53
|
+
* Clones every measured title and cell (`measuredRows`) into a hidden probe with
|
|
54
|
+
* `white-space: nowrap`, reads all widths in one pass and removes the probe — before anything
|
|
55
|
+
* paints.
|
|
56
|
+
*/
|
|
57
|
+
export declare function measureMetrics(root: HTMLElement, body: HTMLElement, columns: FitColumn[]): FitMetrics;
|
|
58
|
+
/**
|
|
59
|
+
* The final layout's room for the title's track: the width less the columns that keep their own,
|
|
60
|
+
* the gaps, and the padding of a last track that sizes to its content. Null before the final
|
|
61
|
+
* layout, or when the title is the only column left.
|
|
62
|
+
*/
|
|
63
|
+
export declare function titleRoom(layout: FitLayout, drawn: FitColumn[], title: string, m: FitMetrics, available: number, edge: number, gap: number): number | null;
|
|
64
|
+
/**
|
|
65
|
+
* The fewest columns to step out so the widest title stays on one line. Stepping out happens
|
|
66
|
+
* the moment it no longer fits; stepping back needs `HYSTERESIS_PX` to spare.
|
|
67
|
+
*/
|
|
68
|
+
export declare function fitStep(options: {
|
|
69
|
+
available: number;
|
|
70
|
+
current: number;
|
|
71
|
+
order: FitColumn[];
|
|
72
|
+
columns: FitColumn[];
|
|
73
|
+
drawn: FitColumn[];
|
|
74
|
+
title: string;
|
|
75
|
+
metrics: FitMetrics;
|
|
76
|
+
edge: number;
|
|
77
|
+
gap: number;
|
|
78
|
+
widthRem: number;
|
|
79
|
+
}): number;
|
|
80
|
+
/**
|
|
81
|
+
* The glide. Tracked pieces carry `data-flip`. Each is measured relative to its nearest tracked
|
|
82
|
+
* parent (bands and rows relative to the scroll content), so a cell glides inside its row while
|
|
83
|
+
* the row glides inside the table, and a stuck band stays stuck.
|
|
84
|
+
*
|
|
85
|
+
* - `tier()` wraps a layout change: measure where everything is drawn, commit the new layout,
|
|
86
|
+
* measure again, animate the difference. The bands and rows in view go top to bottom, up to
|
|
87
|
+
* 30ms apart; every piece of a row starts with its row, its leaving cells included. Entering
|
|
88
|
+
* cells fade and grow in; leaving cells are cloned where they stood and fade out as their
|
|
89
|
+
* neighbours glide over. Interrupted, it starts again from what is drawn: positions
|
|
90
|
+
* mid-glide, cells mid-fade, ghosts still fading out.
|
|
91
|
+
* - `reflow()` runs on every other resize. In the final layout, where titles wrap, a piece that
|
|
92
|
+
* changed line glides there instead of jumping; pieces that only follow the width keep
|
|
93
|
+
* following the pointer.
|
|
94
|
+
*
|
|
95
|
+
* Each pass reads every rect first and writes after, so there is one forced layout per change.
|
|
96
|
+
*/
|
|
97
|
+
export declare class Flip {
|
|
98
|
+
private root;
|
|
99
|
+
private body;
|
|
100
|
+
private layer;
|
|
101
|
+
private anims;
|
|
102
|
+
private ghosts;
|
|
103
|
+
private cache;
|
|
104
|
+
private active;
|
|
105
|
+
/** Right to left: a column's end is on the left. Read at the start of every glide. */
|
|
106
|
+
private rtl;
|
|
107
|
+
constructor(root: HTMLElement, body: HTMLElement, layer: HTMLElement);
|
|
108
|
+
/** The side a piece is anchored to: its column's end (the right, or the left right to left) or start. */
|
|
109
|
+
private sideOf;
|
|
110
|
+
private direction;
|
|
111
|
+
private easing;
|
|
112
|
+
private track;
|
|
113
|
+
private run;
|
|
114
|
+
private dropGhost;
|
|
115
|
+
/**
|
|
116
|
+
* Where a piece's box starts without the scale it is drawn at. A piece fading in is scaled from
|
|
117
|
+
* its side's vertical middle, which moves its drawn top; read as is, that looked like a change
|
|
118
|
+
* of line, and the next resize replaced the fade-in with a glide, so the cell popped in.
|
|
119
|
+
*/
|
|
120
|
+
private unscaled;
|
|
121
|
+
/** Every drawn piece, its rect, and its position in its parent — less `offsets`, a glide in progress. */
|
|
122
|
+
private measure;
|
|
123
|
+
/**
|
|
124
|
+
* The cascade: bands and rows in view count 0, 1, 2… from the top; those above the view start
|
|
125
|
+
* at once, those below with the last one in view.
|
|
126
|
+
*/
|
|
127
|
+
private cascade;
|
|
128
|
+
/** Forget the last positions: something other than the width moved things (scroll, data, a group). */
|
|
129
|
+
invalidate(): void;
|
|
130
|
+
cancel(): void;
|
|
131
|
+
/** Glides from what is drawn now to the layout that `commit` applies (synchronously) for `next`. */
|
|
132
|
+
tier(next: FitLayout, commit: () => void): void;
|
|
133
|
+
/** A resize within a layout: glide what changed line, from where it is drawn now. */
|
|
134
|
+
reflow(): void;
|
|
135
|
+
}
|
|
136
|
+
export declare const reducedMotion: () => boolean;
|
|
137
|
+
/**
|
|
138
|
+
* The rows that size a virtual table's columns: for each value of a row (`valuesOf`, one per
|
|
139
|
+
* column), the `per` rows where it is longest, and the `per` rows longest in all (a title with
|
|
140
|
+
* its inline cells). Rendered out of view, they stand in for every row, so a column keeps its
|
|
141
|
+
* width while rows scroll in and out. Returns indices into `rows`, in order.
|
|
142
|
+
*/
|
|
143
|
+
export declare function widestRows<TRow>(rows: readonly TRow[], valuesOf: (row: TRow) => readonly unknown[], per?: number): number[];
|