@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,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,73 @@
|
|
|
1
|
+
export type AmountParse = {
|
|
2
|
+
kind: "empty";
|
|
3
|
+
}
|
|
4
|
+
/** Not an amount: letters inside it, two decimal separators, groups in the wrong places. */
|
|
5
|
+
| {
|
|
6
|
+
kind: "invalid";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* More fraction digits than the currency has. `definite` is false while the last separator
|
|
10
|
+
* could still turn out to be a thousands separator once more digits are typed ("1,5" → "1,500").
|
|
11
|
+
*/
|
|
12
|
+
| {
|
|
13
|
+
kind: "precision";
|
|
14
|
+
definite: boolean;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
/** `value` is canonical: an optional "-", the integer, and exactly the currency's fraction digits. */
|
|
18
|
+
| {
|
|
19
|
+
kind: "ok";
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
/** Any decimal digit, of any script, as 0–9; other characters unchanged. */
|
|
23
|
+
export declare function latinDigits(text: string): string;
|
|
24
|
+
/** The locale's decimal and grouping separators, as Intl writes them. */
|
|
25
|
+
export declare function localeSeparators(locale?: string): {
|
|
26
|
+
decimal: string;
|
|
27
|
+
group: string;
|
|
28
|
+
};
|
|
29
|
+
/** The number of fraction digits a currency has in ISO 4217, as Intl knows it: JPY 0, EUR 2, KWD 3. */
|
|
30
|
+
export declare function currencyFractionDigits(currency: string): number;
|
|
31
|
+
/**
|
|
32
|
+
* Reads an amount written by a person, for a currency with `fractionDigits` fraction digits.
|
|
33
|
+
* `locale` decides what a lone "." or "," means; both conventions are read either way.
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseAmount(text: string, { locale, fractionDigits }: {
|
|
36
|
+
locale?: string;
|
|
37
|
+
fractionDigits: number;
|
|
38
|
+
}): AmountParse;
|
|
39
|
+
/**
|
|
40
|
+
* A canonical amount for a currency from any exact decimal string or a number: "12.5" → "12.50".
|
|
41
|
+
* Returns null for anything that isn't a plain decimal, or that has more fraction digits than the
|
|
42
|
+
* currency (a number like 0.1 + 0.2 is refused, not rounded).
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeAmount(value: string | number | null | undefined, fractionDigits: number): string | null;
|
|
45
|
+
/** Compares two canonical amounts with the same fraction digits: −1, 0 or 1. */
|
|
46
|
+
export declare function compareAmounts(a: string, b: string): number;
|
|
47
|
+
/** A canonical amount as an integer of minor units (cents): "12.34" → 1234n. */
|
|
48
|
+
export declare function amountToMinor(value: string, fractionDigits: number): bigint;
|
|
49
|
+
/** An integer of minor units as a canonical amount: 1234n → "12.34". */
|
|
50
|
+
export declare function amountFromMinor(minor: bigint | number | string, fractionDigits: number): string;
|
|
51
|
+
/**
|
|
52
|
+
* A canonical amount as the locale writes it: "1234.5" → "1,234.50" (en-US), "1.234,50" (de-DE),
|
|
53
|
+
* "1 234,50" (fr-FR), "١٬٢٣٤٫٥٠" (ar-EG). `grouping: false` leaves out the thousands separators,
|
|
54
|
+
* for editing. `currency` adds the symbol or code where the locale puts it.
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatAmount(value: string, { locale, fractionDigits, grouping, currency, currencyDisplay, }: {
|
|
57
|
+
locale?: string;
|
|
58
|
+
fractionDigits: number;
|
|
59
|
+
grouping?: boolean;
|
|
60
|
+
currency?: string;
|
|
61
|
+
currencyDisplay?: "symbol" | "narrowSymbol" | "code";
|
|
62
|
+
}): string;
|
|
63
|
+
/** The currency's symbol (or code) in the locale, and whether the locale writes it before the number. */
|
|
64
|
+
export declare function currencyAffix(currency: string, locale?: string, currencyDisplay?: "symbol" | "narrowSymbol" | "code"): {
|
|
65
|
+
symbol: string;
|
|
66
|
+
before: boolean;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Text pasted into an amount field, cleaned of the currency around the number: a symbol or code
|
|
70
|
+
* before or after it ("€", "EUR", "CHF", "kr.", "R$"). Returns null when letters or a currency
|
|
71
|
+
* sign sit inside the number itself ("12abc34").
|
|
72
|
+
*/
|
|
73
|
+
export declare function stripCurrency(text: string): string | null;
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Amounts of money as exact decimal strings — "1234.50", "-0.05", "1200" — never as floats.
|
|
3
|
+
*
|
|
4
|
+
* Everything here works on the digits as text, so no amount is ever rounded by binary floating
|
|
5
|
+
* point: 0.1 + 0.2 never shows up, and an amount of any size keeps every digit. Intl formats the
|
|
6
|
+
* string itself (ECMA-402's exact decimal strings), and the fallback for engines without that
|
|
7
|
+
* formats it by hand.
|
|
8
|
+
*/
|
|
9
|
+
/** The zeros of the decimal digits people type besides 0–9, by script. */
|
|
10
|
+
const DIGIT_ZEROS = [
|
|
11
|
+
0x0660, 0x06f0, 0x07c0, 0x0966, 0x09e6, 0x0a66, 0x0ae6, 0x0b66, 0x0be6, 0x0c66, 0x0ce6, 0x0d66, 0x0de6,
|
|
12
|
+
0x0e50, 0x0ed0, 0x0f20, 0x1040, 0x17e0, 0x1810, 0xff10,
|
|
13
|
+
];
|
|
14
|
+
/** Any decimal digit, of any script, as 0–9; other characters unchanged. */
|
|
15
|
+
export function latinDigits(text) {
|
|
16
|
+
return text.replace(/\p{Nd}/gu, (ch) => {
|
|
17
|
+
const code = ch.codePointAt(0);
|
|
18
|
+
if (code >= 0x30 && code <= 0x39)
|
|
19
|
+
return ch;
|
|
20
|
+
const zero = DIGIT_ZEROS.find((z) => code >= z && code <= z + 9);
|
|
21
|
+
return zero === undefined ? ch : String(code - zero);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const MINUS = /[-−‒–—﹣-]/;
|
|
25
|
+
/** Bidi and format controls that Intl puts around numbers in right-to-left locales. */
|
|
26
|
+
const FORMAT_CONTROLS = /\p{Cf}/gu;
|
|
27
|
+
const separatorCache = new Map();
|
|
28
|
+
/** The locale's decimal and grouping separators, as Intl writes them. */
|
|
29
|
+
export function localeSeparators(locale) {
|
|
30
|
+
const key = locale ?? "";
|
|
31
|
+
let hit = separatorCache.get(key);
|
|
32
|
+
if (!hit) {
|
|
33
|
+
let decimal = ".";
|
|
34
|
+
let group = ",";
|
|
35
|
+
try {
|
|
36
|
+
for (const part of new Intl.NumberFormat(locale || undefined).formatToParts(1234567.5)) {
|
|
37
|
+
if (part.type === "decimal")
|
|
38
|
+
decimal = part.value;
|
|
39
|
+
if (part.type === "group")
|
|
40
|
+
group = part.value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
/* an invalid locale: the defaults */
|
|
45
|
+
}
|
|
46
|
+
hit = { decimal, group };
|
|
47
|
+
separatorCache.set(key, hit);
|
|
48
|
+
}
|
|
49
|
+
return hit;
|
|
50
|
+
}
|
|
51
|
+
/** The number of fraction digits a currency has in ISO 4217, as Intl knows it: JPY 0, EUR 2, KWD 3. */
|
|
52
|
+
export function currencyFractionDigits(currency) {
|
|
53
|
+
try {
|
|
54
|
+
return new Intl.NumberFormat("en", { style: "currency", currency }).resolvedOptions()
|
|
55
|
+
.maximumFractionDigits;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Arabic decimal and thousands separators, which mean only one thing wherever they appear. */
|
|
62
|
+
const ARABIC_DECIMAL = "٫";
|
|
63
|
+
const ARABIC_GROUP = "٬";
|
|
64
|
+
/**
|
|
65
|
+
* What a separator means, on its own: the locale's decimal ("decimal"), its grouping separator
|
|
66
|
+
* ("group"), or the other of "." and "," ("other") — which in this locale can only be a decimal
|
|
67
|
+
* typed the way another country writes it, or a thousands separator from a pasted amount.
|
|
68
|
+
*/
|
|
69
|
+
function separatorRole(ch, locale) {
|
|
70
|
+
if (ch === ARABIC_DECIMAL)
|
|
71
|
+
return "decimal";
|
|
72
|
+
if (ch === ARABIC_GROUP)
|
|
73
|
+
return "group";
|
|
74
|
+
if (ch === locale.decimal)
|
|
75
|
+
return "decimal";
|
|
76
|
+
if (ch === locale.group)
|
|
77
|
+
return "group";
|
|
78
|
+
return "other";
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The digits of an amount written by a person — typed, pasted or read back from the field — in
|
|
82
|
+
* any common convention: "1234.56", "1,234.56", "1.234,56", "1 234,56", "1'234.56", "12,5".
|
|
83
|
+
*
|
|
84
|
+
* Spaces and apostrophes are always thousands separators. When both "." and "," appear, the last
|
|
85
|
+
* one is the decimal. When only one kind appears more than once, it groups thousands. A single
|
|
86
|
+
* one is the decimal when it is the locale's decimal; when it is the locale's thousands separator
|
|
87
|
+
* it groups only if exactly three digits follow it ("1,234" in en-US is 1234, "12,5" is 12.5).
|
|
88
|
+
*/
|
|
89
|
+
function readDigits(raw, locale) {
|
|
90
|
+
let text = latinDigits(raw.normalize("NFKC")).replace(FORMAT_CONTROLS, "").trim();
|
|
91
|
+
if (text === "")
|
|
92
|
+
return "empty";
|
|
93
|
+
let negative = false;
|
|
94
|
+
// Accounting negatives: (12.00).
|
|
95
|
+
const paren = /^\((.*)\)$/.exec(text);
|
|
96
|
+
if (paren) {
|
|
97
|
+
negative = true;
|
|
98
|
+
text = paren[1].trim();
|
|
99
|
+
}
|
|
100
|
+
// A sign in front, or behind ("12.00-").
|
|
101
|
+
const lead = /^([+]|[-−‒–—﹣-])\s*/.exec(text);
|
|
102
|
+
if (lead) {
|
|
103
|
+
if (MINUS.test(lead[1]))
|
|
104
|
+
negative = true;
|
|
105
|
+
text = text.slice(lead[0].length);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const trail = /\s*([-−‒–—﹣-])$/.exec(text);
|
|
109
|
+
if (trail) {
|
|
110
|
+
negative = true;
|
|
111
|
+
text = text.slice(0, -trail[0].length);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (MINUS.test(text) || /[+()]/.test(text))
|
|
115
|
+
return "invalid";
|
|
116
|
+
// Spaces of any width and apostrophes group thousands.
|
|
117
|
+
text = text.replace(/[\p{Zs}'’]/gu, "");
|
|
118
|
+
if (text === "")
|
|
119
|
+
return negative ? { negative, int: "", frac: "" } : "empty";
|
|
120
|
+
if (!/^[0-9.,٫٬]*$/.test(text))
|
|
121
|
+
return "invalid";
|
|
122
|
+
const separators = [...text.matchAll(/[.,٫٬]/g)].map((m) => ({
|
|
123
|
+
ch: m[0],
|
|
124
|
+
at: m.index,
|
|
125
|
+
role: separatorRole(m[0], locale),
|
|
126
|
+
}));
|
|
127
|
+
let decimalAt = -1;
|
|
128
|
+
const last = separators[separators.length - 1];
|
|
129
|
+
if (last && separators.some((s) => s.ch === ARABIC_DECIMAL || s.ch === ARABIC_GROUP)) {
|
|
130
|
+
// Arabic separators mean one thing each; mixed with "." or "," the amount is unreadable.
|
|
131
|
+
if (separators.some((s) => s.ch === "." || s.ch === ","))
|
|
132
|
+
return "invalid";
|
|
133
|
+
const decimals = separators.filter((s) => s.ch === ARABIC_DECIMAL);
|
|
134
|
+
if (decimals.length > 1 || (decimals.length === 1 && decimals[0] !== last))
|
|
135
|
+
return "invalid";
|
|
136
|
+
if (decimals.length === 1)
|
|
137
|
+
decimalAt = last.at;
|
|
138
|
+
}
|
|
139
|
+
else if (last && separators.some((s) => s.ch !== last.ch)) {
|
|
140
|
+
// Both "." and ",": the last is the decimal, and it appears once.
|
|
141
|
+
if (separators.filter((s) => s.ch === last.ch).length > 1)
|
|
142
|
+
return "invalid";
|
|
143
|
+
decimalAt = last.at;
|
|
144
|
+
}
|
|
145
|
+
else if (last && separators.length === 1) {
|
|
146
|
+
if (last.role === "decimal")
|
|
147
|
+
decimalAt = last.at;
|
|
148
|
+
else {
|
|
149
|
+
// A lone separator that isn't the locale's decimal. The locale's thousands separator groups
|
|
150
|
+
// when exactly three digits follow and 1–3 digits (not starting with 0) come before it;
|
|
151
|
+
// anything else ("12,5" in en-US, "12.5" in de-DE or fr-FR) can only be a decimal.
|
|
152
|
+
const after = text.length - last.at - 1;
|
|
153
|
+
const before = text.slice(0, last.at);
|
|
154
|
+
const groups = last.role === "group" && after === 3 && before.length >= 1 && before.length <= 3 && before[0] !== "0";
|
|
155
|
+
decimalAt = groups ? -1 : last.at;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// One kind of separator several times ("1.234.567"): thousands, decimalAt stays -1.
|
|
159
|
+
const intPart = decimalAt === -1 ? text : text.slice(0, decimalAt);
|
|
160
|
+
const frac = decimalAt === -1 ? "" : text.slice(decimalAt + 1);
|
|
161
|
+
if (/[^0-9]/.test(frac))
|
|
162
|
+
return "invalid";
|
|
163
|
+
// The thousands groups: 1–3 digits, then groups of 3 (or the 2s of Indian lakhs and crores).
|
|
164
|
+
const chunks = intPart.split(/[.,٬]/);
|
|
165
|
+
if (chunks.length > 1) {
|
|
166
|
+
const [first, ...rest] = chunks;
|
|
167
|
+
if (!first || first.length > 3)
|
|
168
|
+
return "invalid";
|
|
169
|
+
if (rest[rest.length - 1].length !== 3)
|
|
170
|
+
return "invalid";
|
|
171
|
+
if (rest.some((c) => c.length !== 3 && c.length !== 2))
|
|
172
|
+
return "invalid";
|
|
173
|
+
}
|
|
174
|
+
const int = chunks.join("").replace(/^0+/, "");
|
|
175
|
+
return { negative, int, frac };
|
|
176
|
+
}
|
|
177
|
+
/** Whether the decimal in `text` is certainly one: no more digits could make it a thousands separator. */
|
|
178
|
+
function decimalIsDefinite(raw, locale, fracLength) {
|
|
179
|
+
const text = latinDigits(raw.normalize("NFKC")).replace(/[\p{Zs}'’]/gu, "");
|
|
180
|
+
const separators = [...text.matchAll(/[.,٫٬]/g)];
|
|
181
|
+
if (separators.length !== 1)
|
|
182
|
+
return true;
|
|
183
|
+
const role = separatorRole(separators[0][0], locale);
|
|
184
|
+
return role !== "group" || fracLength > 3;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Reads an amount written by a person, for a currency with `fractionDigits` fraction digits.
|
|
188
|
+
* `locale` decides what a lone "." or "," means; both conventions are read either way.
|
|
189
|
+
*/
|
|
190
|
+
export function parseAmount(text, { locale, fractionDigits }) {
|
|
191
|
+
const seps = localeSeparators(locale);
|
|
192
|
+
const digits = readDigits(text, seps);
|
|
193
|
+
if (digits === "empty")
|
|
194
|
+
return { kind: "empty" };
|
|
195
|
+
if (digits === "invalid")
|
|
196
|
+
return { kind: "invalid" };
|
|
197
|
+
if (digits.int === "" && digits.frac === "") {
|
|
198
|
+
// "-" or "." alone: started, not an amount yet.
|
|
199
|
+
return /[0-9]/.test(latinDigits(text))
|
|
200
|
+
? { kind: "ok", value: canonical(digits, fractionDigits) }
|
|
201
|
+
: { kind: "empty" };
|
|
202
|
+
}
|
|
203
|
+
// Fraction digits past the currency's are fine while they are zeros: 12.500 is 12.50.
|
|
204
|
+
const significant = digits.frac.replace(/0+$/, "");
|
|
205
|
+
if (significant.length > fractionDigits) {
|
|
206
|
+
const value = (digits.negative ? "-" : "") + (digits.int || "0") + "." + digits.frac;
|
|
207
|
+
return { kind: "precision", definite: decimalIsDefinite(text, seps, digits.frac.length), value };
|
|
208
|
+
}
|
|
209
|
+
return { kind: "ok", value: canonical(digits, fractionDigits) };
|
|
210
|
+
}
|
|
211
|
+
function canonical({ negative, int, frac }, fractionDigits) {
|
|
212
|
+
const f = frac.slice(0, fractionDigits).padEnd(fractionDigits, "0");
|
|
213
|
+
const zero = /^0*$/.test(int + f);
|
|
214
|
+
return (negative && !zero ? "-" : "") + (int || "0") + (fractionDigits ? "." + f : "");
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* A canonical amount for a currency from any exact decimal string or a number: "12.5" → "12.50".
|
|
218
|
+
* Returns null for anything that isn't a plain decimal, or that has more fraction digits than the
|
|
219
|
+
* currency (a number like 0.1 + 0.2 is refused, not rounded).
|
|
220
|
+
*/
|
|
221
|
+
export function normalizeAmount(value, fractionDigits) {
|
|
222
|
+
if (value == null || value === "")
|
|
223
|
+
return null;
|
|
224
|
+
let text;
|
|
225
|
+
if (typeof value === "number") {
|
|
226
|
+
if (!Number.isFinite(value))
|
|
227
|
+
return null;
|
|
228
|
+
// The shortest text that reads back as this number: 0.1 is "0.1", not its binary expansion.
|
|
229
|
+
text = String(value);
|
|
230
|
+
if (/e/i.test(text))
|
|
231
|
+
text = value.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 20 });
|
|
232
|
+
}
|
|
233
|
+
else
|
|
234
|
+
text = value.trim();
|
|
235
|
+
const m = /^([-+]?)(\d*)(?:\.(\d*))?$/.exec(text);
|
|
236
|
+
if (!m || (m[2] === "" && !m[3]))
|
|
237
|
+
return null;
|
|
238
|
+
const frac = m[3] ?? "";
|
|
239
|
+
if (frac.replace(/0+$/, "").length > fractionDigits)
|
|
240
|
+
return null;
|
|
241
|
+
return canonical({ negative: m[1] === "-", int: m[2].replace(/^0+/, ""), frac }, fractionDigits);
|
|
242
|
+
}
|
|
243
|
+
/** Compares two canonical amounts with the same fraction digits: −1, 0 or 1. */
|
|
244
|
+
export function compareAmounts(a, b) {
|
|
245
|
+
const x = BigInt(a.replace(".", ""));
|
|
246
|
+
const y = BigInt(b.replace(".", ""));
|
|
247
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
248
|
+
}
|
|
249
|
+
/** A canonical amount as an integer of minor units (cents): "12.34" → 1234n. */
|
|
250
|
+
export function amountToMinor(value, fractionDigits) {
|
|
251
|
+
const normal = normalizeAmount(value, fractionDigits);
|
|
252
|
+
if (normal === null)
|
|
253
|
+
throw new RangeError(`Not an amount with ${fractionDigits} fraction digits: ${value}`);
|
|
254
|
+
return BigInt(normal.replace(".", ""));
|
|
255
|
+
}
|
|
256
|
+
/** An integer of minor units as a canonical amount: 1234n → "12.34". */
|
|
257
|
+
export function amountFromMinor(minor, fractionDigits) {
|
|
258
|
+
if (typeof minor === "number" && !Number.isSafeInteger(minor))
|
|
259
|
+
throw new RangeError(`Minor units must be a safe integer: ${minor}`);
|
|
260
|
+
const n = BigInt(minor);
|
|
261
|
+
const negative = n < 0n;
|
|
262
|
+
const digits = (negative ? -n : n).toString().padStart(fractionDigits + 1, "0");
|
|
263
|
+
const int = digits.slice(0, digits.length - fractionDigits);
|
|
264
|
+
const frac = digits.slice(digits.length - fractionDigits);
|
|
265
|
+
return (negative ? "-" : "") + int + (fractionDigits ? "." + frac : "");
|
|
266
|
+
}
|
|
267
|
+
let exactStrings;
|
|
268
|
+
/** Whether this engine formats a decimal string exactly (Intl.NumberFormat v3), not as a float. */
|
|
269
|
+
function formatsExactStrings() {
|
|
270
|
+
if (exactStrings === undefined) {
|
|
271
|
+
try {
|
|
272
|
+
const f = new Intl.NumberFormat("en-US", { useGrouping: false, maximumFractionDigits: 2 });
|
|
273
|
+
exactStrings = f.format("12345678901234567.89") === "12345678901234567.89";
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
exactStrings = false;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return exactStrings;
|
|
280
|
+
}
|
|
281
|
+
const formatterCache = new Map();
|
|
282
|
+
function formatter(locale, options) {
|
|
283
|
+
const key = `${locale ?? ""}|${JSON.stringify(options)}`;
|
|
284
|
+
let f = formatterCache.get(key);
|
|
285
|
+
if (!f) {
|
|
286
|
+
try {
|
|
287
|
+
f = new Intl.NumberFormat(locale || undefined, options);
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
f = new Intl.NumberFormat("en-US", options);
|
|
291
|
+
}
|
|
292
|
+
formatterCache.set(key, f);
|
|
293
|
+
}
|
|
294
|
+
return f;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* A canonical amount as the locale writes it: "1234.5" → "1,234.50" (en-US), "1.234,50" (de-DE),
|
|
298
|
+
* "1 234,50" (fr-FR), "١٬٢٣٤٫٥٠" (ar-EG). `grouping: false` leaves out the thousands separators,
|
|
299
|
+
* for editing. `currency` adds the symbol or code where the locale puts it.
|
|
300
|
+
*/
|
|
301
|
+
export function formatAmount(value, { locale, fractionDigits, grouping = true, currency, currencyDisplay = "symbol", }) {
|
|
302
|
+
const options = {
|
|
303
|
+
minimumFractionDigits: fractionDigits,
|
|
304
|
+
maximumFractionDigits: fractionDigits,
|
|
305
|
+
useGrouping: grouping,
|
|
306
|
+
...(currency ? { style: "currency", currency, currencyDisplay } : {}),
|
|
307
|
+
};
|
|
308
|
+
const f = formatter(locale, options);
|
|
309
|
+
// Engines without exact decimal strings (before Chrome 106, Safari 15.4, Firefox 116) read the
|
|
310
|
+
// string as a number: exact for amounts under 2^53 minor units, about 90 trillion in cents.
|
|
311
|
+
return f.format((formatsExactStrings() ? value : Number(value)));
|
|
312
|
+
}
|
|
313
|
+
/** The currency's symbol (or code) in the locale, and whether the locale writes it before the number. */
|
|
314
|
+
export function currencyAffix(currency, locale, currencyDisplay = "symbol") {
|
|
315
|
+
try {
|
|
316
|
+
const parts = formatter(locale, { style: "currency", currency, currencyDisplay }).formatToParts(1);
|
|
317
|
+
const at = parts.findIndex((p) => p.type === "currency");
|
|
318
|
+
const integer = parts.findIndex((p) => p.type === "integer");
|
|
319
|
+
return { symbol: parts[at]?.value ?? currency, before: at !== -1 && at < integer };
|
|
320
|
+
}
|
|
321
|
+
catch {
|
|
322
|
+
return { symbol: currency, before: true };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Text pasted into an amount field, cleaned of the currency around the number: a symbol or code
|
|
327
|
+
* before or after it ("€", "EUR", "CHF", "kr.", "R$"). Returns null when letters or a currency
|
|
328
|
+
* sign sit inside the number itself ("12abc34").
|
|
329
|
+
*/
|
|
330
|
+
export function stripCurrency(text) {
|
|
331
|
+
const t = text.normalize("NFKC").replace(FORMAT_CONTROLS, "").trim();
|
|
332
|
+
const digits = [...t.matchAll(/\p{Nd}/gu)];
|
|
333
|
+
if (digits.length === 0)
|
|
334
|
+
return t.replace(/[\p{L}\p{Sc}]+\.?/gu, "").trim();
|
|
335
|
+
const first = digits[0].index;
|
|
336
|
+
const last = digits[digits.length - 1].index + digits[digits.length - 1][0].length;
|
|
337
|
+
const core = t.slice(first, last);
|
|
338
|
+
if (/[\p{L}\p{Sc}]/u.test(core))
|
|
339
|
+
return null;
|
|
340
|
+
// A symbol or code, with the point of an abbreviation ("kr.", "Fr."); a ".5" keeps its point.
|
|
341
|
+
const affix = /[\p{L}\p{Sc}]+\.?/gu;
|
|
342
|
+
return (t.slice(0, first).replace(affix, "") + core + t.slice(last).replace(affix, "")).trim();
|
|
343
|
+
}
|
|
@@ -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;
|