@eifi1/ui-kit 0.10.0 → 0.12.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/README.md +66 -37
- package/dist/chart.d.ts +3 -1
- package/dist/chart.js +2 -0
- package/dist/chart.js.map +1 -1
- package/dist/components/account-settings-labels.d.ts +105 -0
- package/dist/components/account-settings-labels.js +81 -0
- package/dist/components/account-settings-labels.js.map +1 -0
- package/dist/components/account-settings.d.ts +36 -52
- package/dist/components/account-settings.js +44 -8
- package/dist/components/account-settings.js.map +1 -1
- package/dist/components/alert-banner.d.ts +26 -1
- package/dist/components/alert-banner.js +10 -7
- package/dist/components/alert-banner.js.map +1 -1
- package/dist/components/amount-input.d.ts +26 -4
- package/dist/components/amount-input.js +5 -2
- package/dist/components/amount-input.js.map +1 -1
- package/dist/components/authed-image.d.ts +68 -0
- package/dist/components/authed-image.js +117 -0
- package/dist/components/authed-image.js.map +1 -0
- package/dist/components/breadcrumbs.d.ts +2 -1
- package/dist/components/breadcrumbs.js +5 -2
- package/dist/components/breadcrumbs.js.map +1 -1
- package/dist/components/bulk-action-bar.d.ts +51 -5
- package/dist/components/bulk-action-bar.js +88 -41
- package/dist/components/bulk-action-bar.js.map +1 -1
- package/dist/components/button-group.d.ts +107 -3
- package/dist/components/button-group.js +60 -5
- package/dist/components/button-group.js.map +1 -1
- package/dist/components/calculator.d.ts +17 -4
- package/dist/components/calendar-heatmap.d.ts +162 -0
- package/dist/components/calendar-heatmap.js +336 -0
- package/dist/components/calendar-heatmap.js.map +1 -0
- package/dist/components/chip.d.ts +2 -1
- package/dist/components/chip.js +6 -3
- package/dist/components/chip.js.map +1 -1
- package/dist/components/choice-card.d.ts +66 -2
- package/dist/components/choice-card.js +108 -1
- package/dist/components/choice-card.js.map +1 -1
- package/dist/components/combobox-core.js +2 -0
- package/dist/components/combobox-core.js.map +1 -1
- package/dist/components/combobox.d.ts +2 -2
- package/dist/components/combobox.js +31 -9
- package/dist/components/combobox.js.map +1 -1
- package/dist/components/copy-button.d.ts +52 -70
- package/dist/components/copy-button.js +1 -1
- package/dist/components/copy-button.js.map +1 -1
- package/dist/components/data-table-cells.d.ts +63 -0
- package/dist/components/data-table-cells.js +64 -0
- package/dist/components/data-table-cells.js.map +1 -0
- package/dist/components/data-table-filter-popover.d.ts +1 -1
- package/dist/components/data-table-filters.d.ts +1 -1
- package/dist/components/data-table-filters.js +31 -1
- package/dist/components/data-table-filters.js.map +1 -1
- package/dist/components/data-table-labels.d.ts +13 -0
- package/dist/components/data-table-labels.js +8 -1
- package/dist/components/data-table-labels.js.map +1 -1
- package/dist/components/data-table.d.ts +1 -1
- package/dist/components/data-table.js +104 -12
- package/dist/components/data-table.js.map +1 -1
- package/dist/components/date-picker.d.ts +3 -1
- package/dist/components/date-picker.js +15 -2
- package/dist/components/date-picker.js.map +1 -1
- package/dist/components/description-list.d.ts +23 -3
- package/dist/components/description-list.js +23 -3
- package/dist/components/description-list.js.map +1 -1
- package/dist/components/dialog-frame.d.ts +1 -0
- package/dist/components/entity-combobox.d.ts +1 -1
- package/dist/components/entity-combobox.js +18 -3
- package/dist/components/entity-combobox.js.map +1 -1
- package/dist/components/error-boundary.d.ts +92 -0
- package/dist/components/error-boundary.js +111 -0
- package/dist/components/error-boundary.js.map +1 -0
- package/dist/components/field.d.ts +69 -0
- package/dist/components/field.js +75 -0
- package/dist/components/field.js.map +1 -0
- package/dist/components/file-button.d.ts +51 -208
- package/dist/components/file-dropzone.d.ts +50 -2
- package/dist/components/floating-panel.d.ts +156 -4
- package/dist/components/floating-panel.js +193 -29
- package/dist/components/floating-panel.js.map +1 -1
- package/dist/components/form-actions.d.ts +53 -0
- package/dist/components/form-actions.js +98 -0
- package/dist/components/form-actions.js.map +1 -0
- package/dist/components/image-grid.d.ts +67 -0
- package/dist/components/image-grid.js +112 -0
- package/dist/components/image-grid.js.map +1 -0
- package/dist/components/lightbox.d.ts +104 -0
- package/dist/components/lightbox.js +229 -0
- package/dist/components/lightbox.js.map +1 -0
- package/dist/components/line-items.d.ts +114 -0
- package/dist/components/line-items.js +238 -0
- package/dist/components/line-items.js.map +1 -0
- package/dist/components/list.d.ts +37 -3
- package/dist/components/list.js +39 -14
- package/dist/components/list.js.map +1 -1
- package/dist/components/loading-state.d.ts +24 -0
- package/dist/components/loading-state.js +32 -0
- package/dist/components/loading-state.js.map +1 -0
- package/dist/components/menu-item.d.ts +13 -2
- package/dist/components/menu-item.js +11 -2
- package/dist/components/menu-item.js.map +1 -1
- package/dist/components/mini-calendar.d.ts +82 -5
- package/dist/components/mini-calendar.js +212 -64
- package/dist/components/mini-calendar.js.map +1 -1
- package/dist/components/modal.d.ts +20 -1
- package/dist/components/modal.js +26 -2
- package/dist/components/modal.js.map +1 -1
- package/dist/components/month-picker.d.ts +21 -1
- package/dist/components/month-picker.js +139 -26
- package/dist/components/month-picker.js.map +1 -1
- package/dist/components/multi-entity-combobox.d.ts +1 -1
- package/dist/components/multi-entity-combobox.js +19 -3
- package/dist/components/multi-entity-combobox.js.map +1 -1
- package/dist/components/nav-pills.d.ts +67 -0
- package/dist/components/nav-pills.js +69 -0
- package/dist/components/nav-pills.js.map +1 -0
- package/dist/components/number-field.d.ts +26 -5
- package/dist/components/number-field.js +5 -7
- package/dist/components/number-field.js.map +1 -1
- package/dist/components/number-input.d.ts +27 -5
- package/dist/components/number-input.js +7 -1
- package/dist/components/number-input.js.map +1 -1
- package/dist/components/numpad-sheet.d.ts +17 -4
- package/dist/components/passkeys-setting.d.ts +67 -0
- package/dist/components/passkeys-setting.js +214 -0
- package/dist/components/passkeys-setting.js.map +1 -0
- package/dist/components/picker-sheet.js +2 -1
- package/dist/components/picker-sheet.js.map +1 -1
- package/dist/components/pie-chart-labels.d.ts +20 -0
- package/dist/components/pie-chart-labels.js +12 -0
- package/dist/components/pie-chart-labels.js.map +1 -0
- package/dist/components/pie-chart.d.ts +101 -0
- package/dist/components/pie-chart.js +283 -0
- package/dist/components/pie-chart.js.map +1 -0
- package/dist/components/progress-bar.d.ts +73 -3
- package/dist/components/progress-bar.js +110 -8
- package/dist/components/progress-bar.js.map +1 -1
- package/dist/components/qr-code.d.ts +34 -0
- package/dist/components/qr-code.js +57 -0
- package/dist/components/qr-code.js.map +1 -0
- package/dist/components/search-field.d.ts +15 -3
- package/dist/components/search-field.js +5 -1
- package/dist/components/search-field.js.map +1 -1
- package/dist/components/series-chart.d.ts +16 -0
- package/dist/components/series-chart.js +4 -1
- package/dist/components/series-chart.js.map +1 -1
- package/dist/components/settings-fields.d.ts +50 -1
- package/dist/components/signed-amount.d.ts +121 -0
- package/dist/components/signed-amount.js +152 -0
- package/dist/components/signed-amount.js.map +1 -0
- package/dist/components/skeleton.d.ts +10 -3
- package/dist/components/skeleton.js +12 -2
- package/dist/components/skeleton.js.map +1 -1
- package/dist/components/stat-tile.d.ts +2 -1
- package/dist/components/stat-tile.js +5 -2
- package/dist/components/stat-tile.js.map +1 -1
- package/dist/components/status-dot.d.ts +6 -2
- package/dist/components/status-dot.js +6 -1
- package/dist/components/status-dot.js.map +1 -1
- package/dist/components/table.d.ts +77 -11
- package/dist/components/table.js +85 -17
- package/dist/components/table.js.map +1 -1
- package/dist/components/text-link.d.ts +176 -0
- package/dist/components/text-link.js +109 -0
- package/dist/components/text-link.js.map +1 -0
- package/dist/components/text.d.ts +8 -1
- package/dist/components/text.js +1 -0
- package/dist/components/text.js.map +1 -1
- package/dist/components/time-input.d.ts +50 -1
- package/dist/components/toggle-group.d.ts +28 -0
- package/dist/components/toggle-group.js +58 -9
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle-legend.d.ts +36 -3
- package/dist/components/toggle-legend.js +49 -0
- package/dist/components/toggle-legend.js.map +1 -1
- package/dist/components/tooltip.d.ts +11 -3
- package/dist/components/tooltip.js +2 -0
- package/dist/components/tooltip.js.map +1 -1
- package/dist/components/ui.d.ts +52 -729
- package/dist/components/ui.js +296 -27
- package/dist/components/ui.js.map +1 -1
- package/dist/components/use-table-state.d.ts +3 -52
- package/dist/components/use-table-state.js +128 -30
- package/dist/components/use-table-state.js.map +1 -1
- package/dist/components/user-avatar.d.ts +25 -3
- package/dist/components/user-avatar.js +32 -3
- package/dist/components/user-avatar.js.map +1 -1
- package/dist/{data-table-filters-Dh9uF_S-.d.ts → data-table-Drun8Fk9.d.ts} +305 -61
- package/dist/data-table.d.ts +2 -1
- package/dist/data-table.js +5 -1
- package/dist/data-table.js.map +1 -1
- package/dist/feedback/feedback-dialog.d.ts +26 -3
- package/dist/feedback/feedback-dialog.js +16 -2
- package/dist/feedback/feedback-dialog.js.map +1 -1
- package/dist/feedback/feedback-thread.d.ts +133 -0
- package/dist/feedback/feedback-thread.js +237 -0
- package/dist/feedback/feedback-thread.js.map +1 -0
- package/dist/feedback.d.ts +2 -1
- package/dist/feedback.js +1 -0
- package/dist/feedback.js.map +1 -1
- package/dist/hooks/use-authed-src.d.ts +71 -0
- package/dist/hooks/use-authed-src.js +63 -0
- package/dist/hooks/use-authed-src.js.map +1 -0
- package/dist/hooks/use-file-drop.d.ts +50 -2
- package/dist/hooks/use-hotkey.d.ts +59 -0
- package/dist/hooks/use-hotkey.js +105 -0
- package/dist/hooks/use-hotkey.js.map +1 -0
- package/dist/hooks/use-search-param-state.d.ts +83 -0
- package/dist/hooks/use-search-param-state.js +94 -0
- package/dist/hooks/use-search-param-state.js.map +1 -0
- package/dist/i18n/defaults.d.ts +17 -4
- package/dist/i18n/defaults.js +33 -1
- package/dist/i18n/defaults.js.map +1 -1
- package/dist/i18n/kit-labels.d.ts +47 -310
- package/dist/i18n/kit-labels.js +20 -5
- package/dist/i18n/kit-labels.js.map +1 -1
- package/dist/i18n/locales/de-CH-informal.d.ts +17 -4
- package/dist/i18n/locales/de-CH.d.ts +17 -4
- package/dist/i18n/locales/de-informal.d.ts +17 -4
- package/dist/i18n/locales/de.d.ts +17 -4
- package/dist/i18n/locales/de.js +165 -4
- package/dist/i18n/locales/de.js.map +1 -1
- package/dist/i18n/locales/es.d.ts +17 -4
- package/dist/i18n/locales/es.js +162 -4
- package/dist/i18n/locales/es.js.map +1 -1
- package/dist/i18n/locales/fr.d.ts +17 -4
- package/dist/i18n/locales/fr.js +162 -4
- package/dist/i18n/locales/fr.js.map +1 -1
- package/dist/i18n/locales/hu.d.ts +17 -4
- package/dist/i18n/locales/hu.js +162 -4
- package/dist/i18n/locales/hu.js.map +1 -1
- package/dist/i18n/locales/it.d.ts +17 -4
- package/dist/i18n/locales/it.js +162 -4
- package/dist/i18n/locales/it.js.map +1 -1
- package/dist/i18n/locales/zh.d.ts +17 -4
- package/dist/i18n/locales/zh.js +162 -4
- package/dist/i18n/locales/zh.js.map +1 -1
- package/dist/index.d.ts +45 -21
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/dist/kit-labels-v3biUF1L.d.ts +1645 -0
- package/dist/lib/clipping.d.ts +21 -5
- package/dist/lib/clipping.js +3 -0
- package/dist/lib/clipping.js.map +1 -1
- package/dist/lib/dates.d.ts +17 -1
- package/dist/lib/dates.js +19 -0
- package/dist/lib/dates.js.map +1 -1
- package/dist/lib/format.d.ts +144 -0
- package/dist/lib/format.js +149 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/qr-encode.d.ts +44 -0
- package/dist/lib/qr-encode.js +338 -0
- package/dist/lib/qr-encode.js.map +1 -0
- package/dist/rhf/fields.d.ts +241 -0
- package/dist/rhf/fields.js +601 -0
- package/dist/rhf/fields.js.map +1 -0
- package/dist/rhf/form.d.ts +50 -1
- package/dist/rhf/line-items.d.ts +31 -0
- package/dist/rhf/line-items.js +59 -0
- package/dist/rhf/line-items.js.map +1 -0
- package/dist/rhf/use-rhf-wizard-step.d.ts +22 -0
- package/dist/rhf/use-rhf-wizard-step.js +38 -0
- package/dist/rhf/use-rhf-wizard-step.js.map +1 -0
- package/dist/rhf.d.ts +63 -1
- package/dist/rhf.js +3 -0
- package/dist/rhf.js.map +1 -1
- package/dist/shell/app-shell.d.ts +99 -2
- package/dist/shell/app-shell.js +58 -3
- package/dist/shell/app-shell.js.map +1 -1
- package/dist/shell/auth-layout.d.ts +74 -0
- package/dist/shell/auth-layout.js +97 -0
- package/dist/shell/auth-layout.js.map +1 -0
- package/dist/shell/top-bar-brand.d.ts +81 -0
- package/dist/shell/top-bar-brand.js +47 -0
- package/dist/shell/top-bar-brand.js.map +1 -0
- package/dist/shell/topbar-action-menu.d.ts +84 -3
- package/dist/shell/topbar-action-menu.js +115 -27
- package/dist/shell/topbar-action-menu.js.map +1 -1
- package/dist/shell.d.ts +58 -2
- package/dist/shell.js +2 -0
- package/dist/shell.js.map +1 -1
- package/dist/wizard/stepper-nav.d.ts +49 -1
- package/dist/wizard/wizard-context.d.ts +30 -1
- package/dist/wizard/wizard-context.js +23 -2
- package/dist/wizard/wizard-context.js.map +1 -1
- package/dist/wizard/wizard-step.d.ts +20 -5
- package/dist/wizard/wizard-step.js +16 -3
- package/dist/wizard/wizard-step.js.map +1 -1
- package/dist/wizard.d.ts +51 -3
- package/package.json +1 -1
- package/src/chart.ts +4 -0
- package/src/components/account-settings-labels.ts +190 -0
- package/src/components/account-settings.tsx +110 -63
- package/src/components/alert-banner.tsx +36 -7
- package/src/components/amount-input.tsx +13 -1
- package/src/components/authed-image.tsx +190 -0
- package/src/components/breadcrumbs.tsx +8 -2
- package/src/components/bulk-action-bar.tsx +163 -57
- package/src/components/button-group.tsx +129 -4
- package/src/components/calendar-heatmap.tsx +599 -0
- package/src/components/chip.tsx +8 -4
- package/src/components/choice-card.tsx +208 -1
- package/src/components/combobox-core.tsx +5 -0
- package/src/components/combobox.tsx +31 -9
- package/src/components/copy-button.tsx +3 -2
- package/src/components/data-table-cells.tsx +119 -0
- package/src/components/data-table-filters.ts +77 -0
- package/src/components/data-table-labels.ts +23 -0
- package/src/components/data-table.tsx +231 -13
- package/src/components/date-picker.tsx +19 -3
- package/src/components/description-list.tsx +52 -3
- package/src/components/entity-combobox.tsx +18 -3
- package/src/components/error-boundary.tsx +216 -0
- package/src/components/field.tsx +188 -0
- package/src/components/floating-panel.tsx +380 -16
- package/src/components/form-actions.tsx +191 -0
- package/src/components/image-grid.tsx +181 -0
- package/src/components/lightbox.tsx +374 -0
- package/src/components/line-items.tsx +385 -0
- package/src/components/list.tsx +93 -18
- package/src/components/loading-state.tsx +47 -0
- package/src/components/menu-item.tsx +29 -3
- package/src/components/mini-calendar.tsx +317 -57
- package/src/components/modal.tsx +61 -3
- package/src/components/month-picker.tsx +181 -26
- package/src/components/multi-entity-combobox.tsx +19 -3
- package/src/components/nav-pills.tsx +152 -0
- package/src/components/number-field.tsx +15 -10
- package/src/components/number-input.tsx +16 -1
- package/src/components/passkeys-setting.tsx +331 -0
- package/src/components/picker-sheet.tsx +7 -1
- package/src/components/pie-chart-labels.ts +32 -0
- package/src/components/pie-chart.tsx +479 -0
- package/src/components/progress-bar.tsx +241 -13
- package/src/components/qr-code.tsx +83 -0
- package/src/components/search-field.tsx +20 -4
- package/src/components/series-chart.tsx +21 -0
- package/src/components/signed-amount.tsx +286 -0
- package/src/components/skeleton.tsx +21 -3
- package/src/components/stat-tile.tsx +8 -2
- package/src/components/status-dot.tsx +10 -2
- package/src/components/table.tsx +186 -23
- package/src/components/text-link.tsx +248 -0
- package/src/components/text.tsx +9 -1
- package/src/components/toggle-group.tsx +106 -13
- package/src/components/toggle-legend.tsx +87 -2
- package/src/components/tooltip.tsx +17 -3
- package/src/components/ui.tsx +572 -44
- package/src/components/use-table-state.ts +265 -33
- package/src/components/user-avatar.tsx +57 -3
- package/src/data-table.ts +10 -0
- package/src/feedback/feedback-dialog.tsx +42 -3
- package/src/feedback/feedback-thread.tsx +434 -0
- package/src/feedback.ts +1 -0
- package/src/hooks/use-authed-src.ts +161 -0
- package/src/hooks/use-hotkey.ts +172 -0
- package/src/hooks/use-search-param-state.ts +187 -0
- package/src/i18n/defaults.ts +32 -0
- package/src/i18n/kit-labels.tsx +104 -8
- package/src/i18n/locales/de.ts +162 -0
- package/src/i18n/locales/es.ts +159 -0
- package/src/i18n/locales/fr.ts +162 -0
- package/src/i18n/locales/hu.ts +160 -0
- package/src/i18n/locales/it.ts +160 -0
- package/src/i18n/locales/zh.ts +159 -0
- package/src/index.ts +64 -0
- package/src/lib/clipping.ts +22 -4
- package/src/lib/dates.ts +37 -0
- package/src/lib/format.ts +325 -0
- package/src/lib/qr-encode.ts +420 -0
- package/src/rhf/fields.tsx +1054 -0
- package/src/rhf/line-items.tsx +130 -0
- package/src/rhf/use-rhf-wizard-step.ts +113 -0
- package/src/rhf.ts +8 -0
- package/src/shell/app-shell.tsx +147 -2
- package/src/shell/auth-layout.tsx +190 -0
- package/src/shell/top-bar-brand.tsx +76 -0
- package/src/shell/topbar-action-menu.tsx +260 -49
- package/src/shell.ts +2 -0
- package/src/wizard/wizard-context.tsx +50 -1
- package/src/wizard/wizard-step.tsx +43 -6
- package/tokens.css +12 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
const LEVELS = ["L", "M", "Q", "H"];
|
|
3
|
+
const FORMAT_BITS = { L: 1, M: 0, Q: 3, H: 2 };
|
|
4
|
+
const ECC_CODEWORDS_PER_BLOCK = [
|
|
5
|
+
[-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
|
6
|
+
[-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
|
|
7
|
+
[-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
|
8
|
+
[-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
|
|
9
|
+
];
|
|
10
|
+
const NUM_ERROR_CORRECTION_BLOCKS = [
|
|
11
|
+
[-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
|
|
12
|
+
[-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
|
|
13
|
+
[-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
|
|
14
|
+
[-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
|
|
15
|
+
];
|
|
16
|
+
function encodeQr(text, options = {}) {
|
|
17
|
+
const bytes = Array.from(new TextEncoder().encode(text));
|
|
18
|
+
let level = LEVELS.indexOf(options.errorCorrection ?? "M");
|
|
19
|
+
let version = 1;
|
|
20
|
+
let usedBits;
|
|
21
|
+
for (; ; version++) {
|
|
22
|
+
const countBits = version <= 9 ? 8 : 16;
|
|
23
|
+
usedBits = bytes.length < 1 << countBits ? 4 + countBits + bytes.length * 8 : Infinity;
|
|
24
|
+
if (usedBits <= dataCodewords(version, level) * 8) break;
|
|
25
|
+
if (version >= 40) throw new RangeError("QR data too long");
|
|
26
|
+
}
|
|
27
|
+
if (options.boostErrorCorrection ?? true) {
|
|
28
|
+
for (let higher = level + 1; higher < LEVELS.length; higher++) {
|
|
29
|
+
if (usedBits <= dataCodewords(version, higher) * 8) level = higher;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const bits = [];
|
|
33
|
+
const append = (value, length) => {
|
|
34
|
+
for (let i = length - 1; i >= 0; i--) bits.push(value >>> i & 1);
|
|
35
|
+
};
|
|
36
|
+
append(4, 4);
|
|
37
|
+
append(bytes.length, version <= 9 ? 8 : 16);
|
|
38
|
+
for (const b of bytes) append(b, 8);
|
|
39
|
+
const capacity = dataCodewords(version, level) * 8;
|
|
40
|
+
append(0, Math.min(4, capacity - bits.length));
|
|
41
|
+
append(0, (8 - bits.length % 8) % 8);
|
|
42
|
+
for (let pad = 236; bits.length < capacity; pad ^= 236 ^ 17) append(pad, 8);
|
|
43
|
+
const data = [];
|
|
44
|
+
for (let i = 0; i < bits.length; i += 8) {
|
|
45
|
+
let byte = 0;
|
|
46
|
+
for (let j = 0; j < 8; j++) byte = byte << 1 | bits[i + j];
|
|
47
|
+
data.push(byte);
|
|
48
|
+
}
|
|
49
|
+
const grid = new Grid(version, LEVELS[level]);
|
|
50
|
+
grid.drawFunctionPatterns();
|
|
51
|
+
grid.drawCodewords(interleaveWithEcc(data, version, level));
|
|
52
|
+
let bestMask = 0;
|
|
53
|
+
let bestPenalty = Infinity;
|
|
54
|
+
for (let mask = 0; mask < 8; mask++) {
|
|
55
|
+
grid.applyMask(mask);
|
|
56
|
+
grid.drawFormatBits(mask);
|
|
57
|
+
const penalty = grid.penalty();
|
|
58
|
+
if (penalty < bestPenalty) {
|
|
59
|
+
bestMask = mask;
|
|
60
|
+
bestPenalty = penalty;
|
|
61
|
+
}
|
|
62
|
+
grid.applyMask(mask);
|
|
63
|
+
}
|
|
64
|
+
grid.applyMask(bestMask);
|
|
65
|
+
grid.drawFormatBits(bestMask);
|
|
66
|
+
return {
|
|
67
|
+
version,
|
|
68
|
+
size: grid.size,
|
|
69
|
+
errorCorrection: LEVELS[level],
|
|
70
|
+
mask: bestMask,
|
|
71
|
+
modules: grid.modules
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function rawDataModules(version) {
|
|
75
|
+
let result = (16 * version + 128) * version + 64;
|
|
76
|
+
if (version >= 2) {
|
|
77
|
+
const numAlign = Math.floor(version / 7) + 2;
|
|
78
|
+
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
79
|
+
if (version >= 7) result -= 36;
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
function dataCodewords(version, level) {
|
|
84
|
+
return Math.floor(rawDataModules(version) / 8) - ECC_CODEWORDS_PER_BLOCK[level][version] * NUM_ERROR_CORRECTION_BLOCKS[level][version];
|
|
85
|
+
}
|
|
86
|
+
function interleaveWithEcc(data, version, level) {
|
|
87
|
+
const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[level][version];
|
|
88
|
+
const eccLen = ECC_CODEWORDS_PER_BLOCK[level][version];
|
|
89
|
+
const rawCodewords = Math.floor(rawDataModules(version) / 8);
|
|
90
|
+
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
|
91
|
+
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
92
|
+
const divisor = reedSolomonDivisor(eccLen);
|
|
93
|
+
const blocks = [];
|
|
94
|
+
for (let i = 0, k = 0; i < numBlocks; i++) {
|
|
95
|
+
const block = data.slice(k, k + shortBlockLen - eccLen + (i < numShortBlocks ? 0 : 1));
|
|
96
|
+
k += block.length;
|
|
97
|
+
const ecc = reedSolomonRemainder(block, divisor);
|
|
98
|
+
if (i < numShortBlocks) block.push(0);
|
|
99
|
+
blocks.push(block.concat(ecc));
|
|
100
|
+
}
|
|
101
|
+
const result = [];
|
|
102
|
+
for (let i = 0; i < blocks[0].length; i++) {
|
|
103
|
+
blocks.forEach((block, j) => {
|
|
104
|
+
if (i !== shortBlockLen - eccLen || j >= numShortBlocks) result.push(block[i]);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
function gfMultiply(x, y) {
|
|
110
|
+
let z = 0;
|
|
111
|
+
for (let i = 7; i >= 0; i--) {
|
|
112
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
113
|
+
z ^= (y >>> i & 1) * x;
|
|
114
|
+
}
|
|
115
|
+
return z;
|
|
116
|
+
}
|
|
117
|
+
function reedSolomonDivisor(degree) {
|
|
118
|
+
const result = new Array(degree).fill(0);
|
|
119
|
+
result[degree - 1] = 1;
|
|
120
|
+
let root = 1;
|
|
121
|
+
for (let i = 0; i < degree; i++) {
|
|
122
|
+
for (let j = 0; j < degree; j++) {
|
|
123
|
+
result[j] = gfMultiply(result[j], root);
|
|
124
|
+
if (j + 1 < degree) result[j] ^= result[j + 1];
|
|
125
|
+
}
|
|
126
|
+
root = gfMultiply(root, 2);
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function reedSolomonRemainder(data, divisor) {
|
|
131
|
+
const result = new Array(divisor.length).fill(0);
|
|
132
|
+
for (const b of data) {
|
|
133
|
+
const factor = b ^ result.shift();
|
|
134
|
+
result.push(0);
|
|
135
|
+
divisor.forEach((coef, i) => {
|
|
136
|
+
result[i] ^= gfMultiply(coef, factor);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
const bit = (value, i) => (value >>> i & 1) !== 0;
|
|
142
|
+
class Grid {
|
|
143
|
+
size;
|
|
144
|
+
modules;
|
|
145
|
+
reserved;
|
|
146
|
+
version;
|
|
147
|
+
level;
|
|
148
|
+
constructor(version, level) {
|
|
149
|
+
this.version = version;
|
|
150
|
+
this.level = level;
|
|
151
|
+
this.size = version * 4 + 17;
|
|
152
|
+
this.modules = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
|
|
153
|
+
this.reserved = Array.from({ length: this.size }, () => new Array(this.size).fill(false));
|
|
154
|
+
}
|
|
155
|
+
set(x, y, dark) {
|
|
156
|
+
this.modules[y][x] = dark;
|
|
157
|
+
this.reserved[y][x] = true;
|
|
158
|
+
}
|
|
159
|
+
drawFunctionPatterns() {
|
|
160
|
+
const { size } = this;
|
|
161
|
+
for (let i = 0; i < size; i++) {
|
|
162
|
+
this.set(6, i, i % 2 === 0);
|
|
163
|
+
this.set(i, 6, i % 2 === 0);
|
|
164
|
+
}
|
|
165
|
+
this.drawFinder(3, 3);
|
|
166
|
+
this.drawFinder(size - 4, 3);
|
|
167
|
+
this.drawFinder(3, size - 4);
|
|
168
|
+
const align = this.alignmentPositions();
|
|
169
|
+
const n = align.length;
|
|
170
|
+
for (let i = 0; i < n; i++) {
|
|
171
|
+
for (let j = 0; j < n; j++) {
|
|
172
|
+
const corner = i === 0 && j === 0 || i === 0 && j === n - 1 || i === n - 1 && j === 0;
|
|
173
|
+
if (!corner) this.drawAlignment(align[i], align[j]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
this.drawFormatBits(0);
|
|
177
|
+
this.drawVersion();
|
|
178
|
+
}
|
|
179
|
+
drawFinder(x, y) {
|
|
180
|
+
for (let dy = -4; dy <= 4; dy++) {
|
|
181
|
+
for (let dx = -4; dx <= 4; dx++) {
|
|
182
|
+
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
183
|
+
const xx = x + dx;
|
|
184
|
+
const yy = y + dy;
|
|
185
|
+
if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size) {
|
|
186
|
+
this.set(xx, yy, dist !== 2 && dist !== 4);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
drawAlignment(x, y) {
|
|
192
|
+
for (let dy = -2; dy <= 2; dy++) {
|
|
193
|
+
for (let dx = -2; dx <= 2; dx++) {
|
|
194
|
+
this.set(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
alignmentPositions() {
|
|
199
|
+
if (this.version === 1) return [];
|
|
200
|
+
const numAlign = Math.floor(this.version / 7) + 2;
|
|
201
|
+
const step = Math.floor((this.version * 8 + numAlign * 3 + 5) / (numAlign * 4 - 4)) * 2;
|
|
202
|
+
const result = [6];
|
|
203
|
+
for (let pos = this.size - 7; result.length < numAlign; pos -= step) result.splice(1, 0, pos);
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
drawFormatBits(mask) {
|
|
207
|
+
const data = FORMAT_BITS[this.level] << 3 | mask;
|
|
208
|
+
let rem = data;
|
|
209
|
+
for (let i = 0; i < 10; i++) rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
210
|
+
const bits = (data << 10 | rem) ^ 21522;
|
|
211
|
+
const { size } = this;
|
|
212
|
+
for (let i = 0; i <= 5; i++) this.set(8, i, bit(bits, i));
|
|
213
|
+
this.set(8, 7, bit(bits, 6));
|
|
214
|
+
this.set(8, 8, bit(bits, 7));
|
|
215
|
+
this.set(7, 8, bit(bits, 8));
|
|
216
|
+
for (let i = 9; i < 15; i++) this.set(14 - i, 8, bit(bits, i));
|
|
217
|
+
for (let i = 0; i < 8; i++) this.set(size - 1 - i, 8, bit(bits, i));
|
|
218
|
+
for (let i = 8; i < 15; i++) this.set(8, size - 15 + i, bit(bits, i));
|
|
219
|
+
this.set(8, size - 8, true);
|
|
220
|
+
}
|
|
221
|
+
drawVersion() {
|
|
222
|
+
if (this.version < 7) return;
|
|
223
|
+
let rem = this.version;
|
|
224
|
+
for (let i = 0; i < 12; i++) rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
225
|
+
const bits = this.version << 12 | rem;
|
|
226
|
+
for (let i = 0; i < 18; i++) {
|
|
227
|
+
const dark = bit(bits, i);
|
|
228
|
+
const a = this.size - 11 + i % 3;
|
|
229
|
+
const b = Math.floor(i / 3);
|
|
230
|
+
this.set(a, b, dark);
|
|
231
|
+
this.set(b, a, dark);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/** The zig-zag placement: two-module columns, right to left, alternating up and down. */
|
|
235
|
+
drawCodewords(data) {
|
|
236
|
+
const { size } = this;
|
|
237
|
+
let i = 0;
|
|
238
|
+
for (let right = size - 1; right >= 1; right -= 2) {
|
|
239
|
+
if (right === 6) right = 5;
|
|
240
|
+
for (let vert = 0; vert < size; vert++) {
|
|
241
|
+
for (let j = 0; j < 2; j++) {
|
|
242
|
+
const x = right - j;
|
|
243
|
+
const upward = (right + 1 & 2) === 0;
|
|
244
|
+
const y = upward ? size - 1 - vert : vert;
|
|
245
|
+
if (!this.reserved[y][x] && i < data.length * 8) {
|
|
246
|
+
this.modules[y][x] = bit(data[i >>> 3], 7 - (i & 7));
|
|
247
|
+
i++;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
applyMask(mask) {
|
|
254
|
+
for (let y = 0; y < this.size; y++) {
|
|
255
|
+
for (let x = 0; x < this.size; x++) {
|
|
256
|
+
if (!this.reserved[y][x] && maskBit(mask, x, y)) this.modules[y][x] = !this.modules[y][x];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
penalty() {
|
|
261
|
+
const { size, modules } = this;
|
|
262
|
+
let result = 0;
|
|
263
|
+
const line = (get) => {
|
|
264
|
+
for (let a = 0; a < size; a++) {
|
|
265
|
+
let runColor = false;
|
|
266
|
+
let run = 0;
|
|
267
|
+
const history = [0, 0, 0, 0, 0, 0, 0];
|
|
268
|
+
for (let b = 0; b < size; b++) {
|
|
269
|
+
if (get(a, b) === runColor) {
|
|
270
|
+
run++;
|
|
271
|
+
if (run === 5) result += 3;
|
|
272
|
+
else if (run > 5) result++;
|
|
273
|
+
} else {
|
|
274
|
+
this.addHistory(run, history);
|
|
275
|
+
if (!runColor) result += this.countFinderLike(history) * 40;
|
|
276
|
+
runColor = get(a, b);
|
|
277
|
+
run = 1;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (runColor) {
|
|
281
|
+
this.addHistory(run, history);
|
|
282
|
+
run = 0;
|
|
283
|
+
}
|
|
284
|
+
this.addHistory(run + size, history);
|
|
285
|
+
result += this.countFinderLike(history) * 40;
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
line((y, x) => modules[y][x]);
|
|
289
|
+
line((x, y) => modules[y][x]);
|
|
290
|
+
for (let y = 0; y < size - 1; y++) {
|
|
291
|
+
for (let x = 0; x < size - 1; x++) {
|
|
292
|
+
const c = modules[y][x];
|
|
293
|
+
if (c === modules[y][x + 1] && c === modules[y + 1][x] && c === modules[y + 1][x + 1]) {
|
|
294
|
+
result += 3;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
let dark = 0;
|
|
299
|
+
for (const row of modules) for (const m of row) if (m) dark++;
|
|
300
|
+
const total = size * size;
|
|
301
|
+
result += (Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1) * 10;
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
addHistory(run, history) {
|
|
305
|
+
if (history[0] === 0) run += this.size;
|
|
306
|
+
history.pop();
|
|
307
|
+
history.unshift(run);
|
|
308
|
+
}
|
|
309
|
+
countFinderLike(h) {
|
|
310
|
+
const n = h[1];
|
|
311
|
+
const core = n > 0 && h[2] === n && h[3] === n * 3 && h[4] === n && h[5] === n;
|
|
312
|
+
return (core && h[0] >= n * 4 && h[6] >= n ? 1 : 0) + (core && h[6] >= n * 4 && h[0] >= n ? 1 : 0);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function maskBit(mask, x, y) {
|
|
316
|
+
switch (mask) {
|
|
317
|
+
case 0:
|
|
318
|
+
return (x + y) % 2 === 0;
|
|
319
|
+
case 1:
|
|
320
|
+
return y % 2 === 0;
|
|
321
|
+
case 2:
|
|
322
|
+
return x % 3 === 0;
|
|
323
|
+
case 3:
|
|
324
|
+
return (x + y) % 3 === 0;
|
|
325
|
+
case 4:
|
|
326
|
+
return (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
|
|
327
|
+
case 5:
|
|
328
|
+
return x * y % 2 + x * y % 3 === 0;
|
|
329
|
+
case 6:
|
|
330
|
+
return (x * y % 2 + x * y % 3) % 2 === 0;
|
|
331
|
+
default:
|
|
332
|
+
return ((x + y) % 2 + x * y % 3) % 2 === 0;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
export {
|
|
336
|
+
encodeQr
|
|
337
|
+
};
|
|
338
|
+
//# sourceMappingURL=qr-encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/qr-encode.ts"],"sourcesContent":["/**\n * A QR code encoder: text in, a square of dark / light modules out (ISO/IEC 18004).\n *\n * WHY IT IS IN THE KIT rather than a dependency. `TwoFactorSetting` needs one QR code —\n * an `otpauth://` URI, around 100–200 bytes — and every app that shows it was pulling\n * in `qrcode.react` plus `react-dom/server` to render that one code to a static SVG\n * string, then base64-encoding it so the kit could draw it back as an `<img>`.\n * A dependency here would land in all three apps whether they show 2FA or not; an\n * optional peer would mean a lazy import and a loading state for something that is\n * a few hundred lines of arithmetic. So it is those lines: pure, no imports, no module\n * state beyond two constant tables, safe under `sideEffects: false`, and\n * tree-shaken out of every app that never renders a {@link QrCode}.\n *\n * Scope, chosen for what the kit renders: BYTE mode only (UTF-8), all 40 versions,\n * all four error-correction levels, automatic version and mask selection. Numeric,\n * alphanumeric and Kanji modes are denser for their alphabets but would not shrink an\n * otpauth URI (lower-case letters are not in the alphanumeric set). The algorithm and\n * its penalty rules follow the reference implementation by Project Nayuki (MIT),\n * which is also what `qrcode.react` wraps — so for the same input, level and boost\n * the modules match that library's output exactly (the test suite pins a matrix).\n */\n\nexport type QrErrorCorrection = \"L\" | \"M\" | \"Q\" | \"H\";\n\nexport interface QrEncodeOptions {\n /** How much of the code may be damaged and still read. Default `\"M\"` (~15 %). */\n errorCorrection?: QrErrorCorrection;\n /** Raise the level as far as the chosen version still fits, for free. Default true. */\n boostErrorCorrection?: boolean;\n}\n\nexport interface QrMatrix {\n /** 1–40. */\n version: number;\n /** Modules per side: `version * 4 + 17`. */\n size: number;\n /** The level actually used — higher than asked when boosted. */\n errorCorrection: QrErrorCorrection;\n /** 0–7. */\n mask: number;\n /** `modules[y][x]`, true = dark. No quiet zone: the renderer adds its own. */\n modules: boolean[][];\n}\n\nconst LEVELS: QrErrorCorrection[] = [\"L\", \"M\", \"Q\", \"H\"];\n/** The two format-information bits per level (not in ordinal order: M is 00). */\nconst FORMAT_BITS: Record<QrErrorCorrection, number> = { L: 1, M: 0, Q: 3, H: 2 };\n\n// Index 0 is padding; rows are L, M, Q, H.\nconst ECC_CODEWORDS_PER_BLOCK: readonly (readonly number[])[] = [\n [-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],\n [-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],\n [-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],\n [-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],\n];\nconst NUM_ERROR_CORRECTION_BLOCKS: readonly (readonly number[])[] = [\n [-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],\n [-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],\n [-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],\n [-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81],\n];\n\n/** Encode `text` (as UTF-8 bytes). Throws a `RangeError` past version 40's capacity. */\nexport function encodeQr(text: string, options: QrEncodeOptions = {}): QrMatrix {\n const bytes = Array.from(new TextEncoder().encode(text));\n let level = LEVELS.indexOf(options.errorCorrection ?? \"M\");\n\n // The smallest version that holds the data at the requested level.\n let version = 1;\n let usedBits: number;\n for (; ; version++) {\n const countBits = version <= 9 ? 8 : 16;\n usedBits = bytes.length < 1 << countBits ? 4 + countBits + bytes.length * 8 : Infinity;\n if (usedBits <= dataCodewords(version, level) * 8) break;\n if (version >= 40) throw new RangeError(\"QR data too long\");\n }\n if (options.boostErrorCorrection ?? true) {\n for (let higher = level + 1; higher < LEVELS.length; higher++) {\n if (usedBits <= dataCodewords(version, higher) * 8) level = higher;\n }\n }\n\n // Mode, count, data; then terminator, byte padding and the 0xEC/0x11 fill.\n const bits: number[] = [];\n const append = (value: number, length: number) => {\n for (let i = length - 1; i >= 0; i--) bits.push((value >>> i) & 1);\n };\n append(0b0100, 4);\n append(bytes.length, version <= 9 ? 8 : 16);\n for (const b of bytes) append(b, 8);\n const capacity = dataCodewords(version, level) * 8;\n append(0, Math.min(4, capacity - bits.length));\n append(0, (8 - (bits.length % 8)) % 8);\n for (let pad = 0xec; bits.length < capacity; pad ^= 0xec ^ 0x11) append(pad, 8);\n\n const data: number[] = [];\n for (let i = 0; i < bits.length; i += 8) {\n let byte = 0;\n for (let j = 0; j < 8; j++) byte = (byte << 1) | bits[i + j];\n data.push(byte);\n }\n\n const grid = new Grid(version, LEVELS[level]);\n grid.drawFunctionPatterns();\n grid.drawCodewords(interleaveWithEcc(data, version, level));\n\n let bestMask = 0;\n let bestPenalty = Infinity;\n for (let mask = 0; mask < 8; mask++) {\n grid.applyMask(mask);\n grid.drawFormatBits(mask);\n const penalty = grid.penalty();\n if (penalty < bestPenalty) {\n bestMask = mask;\n bestPenalty = penalty;\n }\n grid.applyMask(mask); // XOR again undoes it\n }\n grid.applyMask(bestMask);\n grid.drawFormatBits(bestMask);\n\n return {\n version,\n size: grid.size,\n errorCorrection: LEVELS[level],\n mask: bestMask,\n modules: grid.modules,\n };\n}\n\nfunction rawDataModules(version: number): number {\n let result = (16 * version + 128) * version + 64;\n if (version >= 2) {\n const numAlign = Math.floor(version / 7) + 2;\n result -= (25 * numAlign - 10) * numAlign - 55;\n if (version >= 7) result -= 36;\n }\n return result;\n}\n\nfunction dataCodewords(version: number, level: number): number {\n return (\n Math.floor(rawDataModules(version) / 8) -\n ECC_CODEWORDS_PER_BLOCK[level][version] * NUM_ERROR_CORRECTION_BLOCKS[level][version]\n );\n}\n\n/** Split into blocks, append each block's Reed–Solomon codewords, interleave. */\nfunction interleaveWithEcc(data: number[], version: number, level: number): number[] {\n const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[level][version];\n const eccLen = ECC_CODEWORDS_PER_BLOCK[level][version];\n const rawCodewords = Math.floor(rawDataModules(version) / 8);\n const numShortBlocks = numBlocks - (rawCodewords % numBlocks);\n const shortBlockLen = Math.floor(rawCodewords / numBlocks);\n const divisor = reedSolomonDivisor(eccLen);\n\n const blocks: number[][] = [];\n for (let i = 0, k = 0; i < numBlocks; i++) {\n const block = data.slice(k, k + shortBlockLen - eccLen + (i < numShortBlocks ? 0 : 1));\n k += block.length;\n const ecc = reedSolomonRemainder(block, divisor);\n if (i < numShortBlocks) block.push(0); // placeholder, skipped below\n blocks.push(block.concat(ecc));\n }\n\n const result: number[] = [];\n for (let i = 0; i < blocks[0].length; i++) {\n blocks.forEach((block, j) => {\n if (i !== shortBlockLen - eccLen || j >= numShortBlocks) result.push(block[i]);\n });\n }\n return result;\n}\n\nfunction gfMultiply(x: number, y: number): number {\n let z = 0;\n for (let i = 7; i >= 0; i--) {\n z = (z << 1) ^ ((z >>> 7) * 0x11d);\n z ^= ((y >>> i) & 1) * x;\n }\n return z;\n}\n\nfunction reedSolomonDivisor(degree: number): number[] {\n const result = new Array<number>(degree).fill(0);\n result[degree - 1] = 1;\n let root = 1;\n for (let i = 0; i < degree; i++) {\n for (let j = 0; j < degree; j++) {\n result[j] = gfMultiply(result[j], root);\n if (j + 1 < degree) result[j] ^= result[j + 1];\n }\n root = gfMultiply(root, 0x02);\n }\n return result;\n}\n\nfunction reedSolomonRemainder(data: number[], divisor: number[]): number[] {\n const result = new Array<number>(divisor.length).fill(0);\n for (const b of data) {\n const factor = b ^ (result.shift() as number);\n result.push(0);\n divisor.forEach((coef, i) => {\n result[i] ^= gfMultiply(coef, factor);\n });\n }\n return result;\n}\n\nconst bit = (value: number, i: number) => ((value >>> i) & 1) !== 0;\n\nclass Grid {\n readonly size: number;\n readonly modules: boolean[][];\n private readonly reserved: boolean[][];\n private readonly version: number;\n private readonly level: QrErrorCorrection;\n\n constructor(version: number, level: QrErrorCorrection) {\n this.version = version;\n this.level = level;\n this.size = version * 4 + 17;\n this.modules = Array.from({ length: this.size }, () => new Array<boolean>(this.size).fill(false));\n this.reserved = Array.from({ length: this.size }, () => new Array<boolean>(this.size).fill(false));\n }\n\n private set(x: number, y: number, dark: boolean) {\n this.modules[y][x] = dark;\n this.reserved[y][x] = true;\n }\n\n drawFunctionPatterns() {\n const { size } = this;\n for (let i = 0; i < size; i++) {\n this.set(6, i, i % 2 === 0);\n this.set(i, 6, i % 2 === 0);\n }\n this.drawFinder(3, 3);\n this.drawFinder(size - 4, 3);\n this.drawFinder(3, size - 4);\n const align = this.alignmentPositions();\n const n = align.length;\n for (let i = 0; i < n; i++) {\n for (let j = 0; j < n; j++) {\n const corner = (i === 0 && j === 0) || (i === 0 && j === n - 1) || (i === n - 1 && j === 0);\n if (!corner) this.drawAlignment(align[i], align[j]);\n }\n }\n this.drawFormatBits(0); // reserves the area; redrawn once the mask is chosen\n this.drawVersion();\n }\n\n private drawFinder(x: number, y: number) {\n for (let dy = -4; dy <= 4; dy++) {\n for (let dx = -4; dx <= 4; dx++) {\n const dist = Math.max(Math.abs(dx), Math.abs(dy));\n const xx = x + dx;\n const yy = y + dy;\n if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size) {\n this.set(xx, yy, dist !== 2 && dist !== 4);\n }\n }\n }\n }\n\n private drawAlignment(x: number, y: number) {\n for (let dy = -2; dy <= 2; dy++) {\n for (let dx = -2; dx <= 2; dx++) {\n this.set(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1);\n }\n }\n }\n\n private alignmentPositions(): number[] {\n if (this.version === 1) return [];\n const numAlign = Math.floor(this.version / 7) + 2;\n const step = Math.floor((this.version * 8 + numAlign * 3 + 5) / (numAlign * 4 - 4)) * 2;\n const result = [6];\n for (let pos = this.size - 7; result.length < numAlign; pos -= step) result.splice(1, 0, pos);\n return result;\n }\n\n drawFormatBits(mask: number) {\n const data = (FORMAT_BITS[this.level] << 3) | mask;\n let rem = data;\n for (let i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537);\n const bits = ((data << 10) | rem) ^ 0x5412;\n const { size } = this;\n for (let i = 0; i <= 5; i++) this.set(8, i, bit(bits, i));\n this.set(8, 7, bit(bits, 6));\n this.set(8, 8, bit(bits, 7));\n this.set(7, 8, bit(bits, 8));\n for (let i = 9; i < 15; i++) this.set(14 - i, 8, bit(bits, i));\n for (let i = 0; i < 8; i++) this.set(size - 1 - i, 8, bit(bits, i));\n for (let i = 8; i < 15; i++) this.set(8, size - 15 + i, bit(bits, i));\n this.set(8, size - 8, true); // the always-dark module\n }\n\n private drawVersion() {\n if (this.version < 7) return;\n let rem = this.version;\n for (let i = 0; i < 12; i++) rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25);\n const bits = (this.version << 12) | rem;\n for (let i = 0; i < 18; i++) {\n const dark = bit(bits, i);\n const a = this.size - 11 + (i % 3);\n const b = Math.floor(i / 3);\n this.set(a, b, dark);\n this.set(b, a, dark);\n }\n }\n\n /** The zig-zag placement: two-module columns, right to left, alternating up and down. */\n drawCodewords(data: number[]) {\n const { size } = this;\n let i = 0;\n for (let right = size - 1; right >= 1; right -= 2) {\n if (right === 6) right = 5; // skip the vertical timing column\n for (let vert = 0; vert < size; vert++) {\n for (let j = 0; j < 2; j++) {\n const x = right - j;\n const upward = ((right + 1) & 2) === 0;\n const y = upward ? size - 1 - vert : vert;\n if (!this.reserved[y][x] && i < data.length * 8) {\n this.modules[y][x] = bit(data[i >>> 3], 7 - (i & 7));\n i++;\n }\n }\n }\n }\n }\n\n applyMask(mask: number) {\n for (let y = 0; y < this.size; y++) {\n for (let x = 0; x < this.size; x++) {\n if (!this.reserved[y][x] && maskBit(mask, x, y)) this.modules[y][x] = !this.modules[y][x];\n }\n }\n }\n\n penalty(): number {\n const { size, modules } = this;\n let result = 0;\n const line = (get: (a: number, b: number) => boolean) => {\n for (let a = 0; a < size; a++) {\n let runColor = false;\n let run = 0;\n const history = [0, 0, 0, 0, 0, 0, 0];\n for (let b = 0; b < size; b++) {\n if (get(a, b) === runColor) {\n run++;\n if (run === 5) result += 3;\n else if (run > 5) result++;\n } else {\n this.addHistory(run, history);\n if (!runColor) result += this.countFinderLike(history) * 40;\n runColor = get(a, b);\n run = 1;\n }\n }\n if (runColor) {\n this.addHistory(run, history);\n run = 0;\n }\n this.addHistory(run + size, history);\n result += this.countFinderLike(history) * 40;\n }\n };\n line((y, x) => modules[y][x]);\n line((x, y) => modules[y][x]);\n\n for (let y = 0; y < size - 1; y++) {\n for (let x = 0; x < size - 1; x++) {\n const c = modules[y][x];\n if (c === modules[y][x + 1] && c === modules[y + 1][x] && c === modules[y + 1][x + 1]) {\n result += 3;\n }\n }\n }\n\n let dark = 0;\n for (const row of modules) for (const m of row) if (m) dark++;\n const total = size * size;\n result += (Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1) * 10;\n return result;\n }\n\n private addHistory(run: number, history: number[]) {\n if (history[0] === 0) run += this.size; // the light border before the first run\n history.pop();\n history.unshift(run);\n }\n\n private countFinderLike(h: number[]): number {\n const n = h[1];\n const core = n > 0 && h[2] === n && h[3] === n * 3 && h[4] === n && h[5] === n;\n return (core && h[0] >= n * 4 && h[6] >= n ? 1 : 0) + (core && h[6] >= n * 4 && h[0] >= n ? 1 : 0);\n }\n}\n\nfunction maskBit(mask: number, x: number, y: number): boolean {\n switch (mask) {\n case 0:\n return (x + y) % 2 === 0;\n case 1:\n return y % 2 === 0;\n case 2:\n return x % 3 === 0;\n case 3:\n return (x + y) % 3 === 0;\n case 4:\n return (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;\n case 5:\n return ((x * y) % 2) + ((x * y) % 3) === 0;\n case 6:\n return (((x * y) % 2) + ((x * y) % 3)) % 2 === 0;\n default:\n return (((x + y) % 2) + ((x * y) % 3)) % 2 === 0;\n }\n}\n"],"mappings":";AA4CA,MAAM,SAA8B,CAAC,KAAK,KAAK,KAAK,GAAG;AAEvD,MAAM,cAAiD,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAGhF,MAAM,0BAA0D;AAAA,EAC9D,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI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AK,EAAE,CAAC,MAAM;AAC7E,YAAQ,QAAQ,EAAE,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC,KAAK,IAAI,IAAI,MAAM,QAAQ,EAAE,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC,KAAK,IAAI,IAAI;AAAA,EAClG;AACF;AAEA,SAAS,QAAQ,MAAc,GAAW,GAAoB;AAC5D,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,cAAQ,IAAI,KAAK,MAAM;AAAA,IACzB,KAAK;AACH,aAAO,IAAI,MAAM;AAAA,IACnB,KAAK;AACH,aAAO,IAAI,MAAM;AAAA,IACnB,KAAK;AACH,cAAQ,IAAI,KAAK,MAAM;AAAA,IACzB,KAAK;AACH,cAAQ,KAAK,MAAM,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,KAAK,MAAM;AAAA,IACzD,KAAK;AACH,aAAS,IAAI,IAAK,IAAO,IAAI,IAAK,MAAO;AAAA,IAC3C,KAAK;AACH,cAAU,IAAI,IAAK,IAAO,IAAI,IAAK,KAAM,MAAM;AAAA,IACjD;AACE,eAAU,IAAI,KAAK,IAAO,IAAI,IAAK,KAAM,MAAM;AAAA,EACnD;AACF;","names":[]}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ReactElement } from 'react';
|
|
3
|
+
import { FieldValues, FieldPath, ControllerProps, ControllerRenderProps, ControllerFieldState } from 'react-hook-form';
|
|
4
|
+
import { aH as SelectProps, aw as InputProps, aQ as TextareaProps } from '../kit-labels-v3biUF1L.js';
|
|
5
|
+
import { NumberFieldProps } from '../components/number-field.js';
|
|
6
|
+
import { DatePickerProps } from '../components/date-picker.js';
|
|
7
|
+
import { CheckboxProps } from '../components/checkbox.js';
|
|
8
|
+
import { EntityComboboxProps } from '../components/entity-combobox.js';
|
|
9
|
+
import { ComboboxProps } from '../components/combobox.js';
|
|
10
|
+
import { ComboClearValue } from '../components/combobox-core.js';
|
|
11
|
+
import '../components/data-table-labels.js';
|
|
12
|
+
import '../components/mini-calendar.js';
|
|
13
|
+
import '../components/calendar-heatmap.js';
|
|
14
|
+
import '../components/popover.js';
|
|
15
|
+
import '../components/chip.js';
|
|
16
|
+
import 'lucide-react';
|
|
17
|
+
import '../components/field-sync.js';
|
|
18
|
+
import '../components/tooltip.js';
|
|
19
|
+
import '../hooks/use-anchored-rect.js';
|
|
20
|
+
import '../lib/clipping.js';
|
|
21
|
+
import '../wizard/types.js';
|
|
22
|
+
import '../tour/tour.js';
|
|
23
|
+
import '../search/command-palette.js';
|
|
24
|
+
import '../search/global-search.js';
|
|
25
|
+
import '../search/search-index.js';
|
|
26
|
+
import '../components/month-picker.js';
|
|
27
|
+
import '../components/page-contents.js';
|
|
28
|
+
import '../components/series-chart-labels.js';
|
|
29
|
+
import '../components/pie-chart-labels.js';
|
|
30
|
+
import '../components/sparkline.js';
|
|
31
|
+
import '../components/stat-tile.js';
|
|
32
|
+
import '../components/signature-pad.js';
|
|
33
|
+
import '../components/password-strength.js';
|
|
34
|
+
import '../components/danger-confirm.js';
|
|
35
|
+
import '../components/swatch-picker.js';
|
|
36
|
+
import '../components/tile-radio.js';
|
|
37
|
+
import '../components/icon-picker.js';
|
|
38
|
+
import '../components/dialog-frame.js';
|
|
39
|
+
import '../components/modal.js';
|
|
40
|
+
import '../hooks/use-search-param-state.js';
|
|
41
|
+
import '../components/measured-grid.js';
|
|
42
|
+
import '../feedback/feedback-attachment.js';
|
|
43
|
+
import '../feedback/feedback-dialog.js';
|
|
44
|
+
import '../feedback/feedback-thread.js';
|
|
45
|
+
import '../feedback/feedback-inbox.js';
|
|
46
|
+
import '../components/account-settings-labels.js';
|
|
47
|
+
import '../components/confirm-dialog.js';
|
|
48
|
+
import '../components/floating-panel.js';
|
|
49
|
+
import '../components/bulk-action-bar.js';
|
|
50
|
+
import '../components/list.js';
|
|
51
|
+
import '../components/breadcrumbs.js';
|
|
52
|
+
import '../components/toast.js';
|
|
53
|
+
import '../components/description-list.js';
|
|
54
|
+
import '../components/line-items.js';
|
|
55
|
+
import '../components/progress-bar.js';
|
|
56
|
+
import '../components/signed-amount.js';
|
|
57
|
+
import '../components/error-boundary.js';
|
|
58
|
+
import '../components/authed-image.js';
|
|
59
|
+
import '../hooks/use-authed-src.js';
|
|
60
|
+
import '../components/image-grid.js';
|
|
61
|
+
import '../components/lightbox.js';
|
|
62
|
+
import '../components/number-input.js';
|
|
63
|
+
import '../components/calculator.js';
|
|
64
|
+
import '../components/numpad-sheet.js';
|
|
65
|
+
import '../hooks/use-anchored-panel.js';
|
|
66
|
+
|
|
67
|
+
/** What every bound field takes. */
|
|
68
|
+
interface RhfFieldBaseProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> {
|
|
69
|
+
name: TName;
|
|
70
|
+
/** `form.control`. Optional under `<Form {...form}>`; pass it to type-check `name`. */
|
|
71
|
+
control?: ControllerProps<TFieldValues, TName, TTransformed>["control"];
|
|
72
|
+
/** react-hook-form's `rules` (`required`, `min`, `validate` …). */
|
|
73
|
+
rules?: ControllerProps<TFieldValues, TName, TTransformed>["rules"];
|
|
74
|
+
/** A {@link FormLabel} above the field. Omitted: no label — name the control with
|
|
75
|
+
* an `aria-label` instead. */
|
|
76
|
+
label?: ReactNode;
|
|
77
|
+
/** Standing advice under the field ("As printed on the card"), attached to the
|
|
78
|
+
* control with `aria-describedby`. */
|
|
79
|
+
hint?: ReactNode;
|
|
80
|
+
/** Draws the label's required mark and sets `aria-required` where the control
|
|
81
|
+
* takes it. Whether the field IS required is `rules`' or the resolver's to say. */
|
|
82
|
+
required?: boolean;
|
|
83
|
+
/** Disables the field — through react-hook-form, so its value is left out of the
|
|
84
|
+
* submitted values as a disabled input's would be. */
|
|
85
|
+
disabled?: boolean;
|
|
86
|
+
/** Classes for the item's box (a `grid gap-1`). */
|
|
87
|
+
className?: string;
|
|
88
|
+
}
|
|
89
|
+
/** What {@link RhfField}'s `render` receives. */
|
|
90
|
+
interface RhfFieldRenderContext<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
|
91
|
+
field: ControllerRenderProps<TFieldValues, TName>;
|
|
92
|
+
fieldState: ControllerFieldState;
|
|
93
|
+
/** The field has an error: pass it to the control's `invalid` so it paints. */
|
|
94
|
+
invalid: boolean;
|
|
95
|
+
/** The error's message, if any. */
|
|
96
|
+
error: string | undefined;
|
|
97
|
+
/** The control's id, which the label points at. `FormControl` sets it on the
|
|
98
|
+
* rendered element already; this is for a control that routes it elsewhere. */
|
|
99
|
+
id: string;
|
|
100
|
+
/** The label's id, for a control that is named with `aria-labelledby`. */
|
|
101
|
+
labelId: string;
|
|
102
|
+
/** The ids of the rendered hint and message, if any. */
|
|
103
|
+
describedBy: string | undefined;
|
|
104
|
+
}
|
|
105
|
+
interface RhfFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> extends RhfFieldBaseProps<TFieldValues, TName, TTransformed> {
|
|
106
|
+
/** The control. Wrapped in {@link FormControl} (its `id`, `aria-describedby` and
|
|
107
|
+
* `aria-invalid`) unless `asControl` is false. */
|
|
108
|
+
render: (ctx: RhfFieldRenderContext<TFieldValues, TName>) => ReactElement;
|
|
109
|
+
/** `false`: render the control as is, for one that wires its own ids from the
|
|
110
|
+
* context. Default `true`. */
|
|
111
|
+
asControl?: boolean;
|
|
112
|
+
/** `false`: no {@link FormMessage}, for a control that renders its own error (its
|
|
113
|
+
* `error` prop). Default `true`. */
|
|
114
|
+
message?: boolean;
|
|
115
|
+
/** `false`: no {@link FormLabel}, for a control that carries its label itself (a
|
|
116
|
+
* checkbox). Default `true`. */
|
|
117
|
+
showLabel?: boolean;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The shell every bound field is built on: label, control, hint and message around
|
|
121
|
+
* a `render` of your own.
|
|
122
|
+
*
|
|
123
|
+
* ```tsx
|
|
124
|
+
* <RhfField name="address" label="Address" render={({ field, invalid }) => (
|
|
125
|
+
* <AddressAutocomplete value={field.value ?? ""} onChange={field.onChange} invalid={invalid} />
|
|
126
|
+
* )} />
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
declare function RhfField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, render, asControl, message, showLabel, }: RhfFieldProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
130
|
+
type OwnInputProps = Omit<InputProps, "name" | "value" | "defaultValue" | "onChange" | "onBlur" | "ref" | "label" | "error" | "invalid" | "className" | "disabled" | "required">;
|
|
131
|
+
type RhfTextFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & OwnInputProps;
|
|
132
|
+
/** A text {@link Input} — `type` for email, tel, password, url. Stores the string. */
|
|
133
|
+
declare function RhfTextField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, ...inputProps }: RhfTextFieldProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
134
|
+
type OwnTextareaProps = Omit<TextareaProps, "name" | "value" | "defaultValue" | "onChange" | "onBlur" | "ref" | "label" | "error" | "invalid" | "className" | "disabled" | "required"> & {
|
|
135
|
+
/** Classes for the `<textarea>`. */
|
|
136
|
+
inputClassName?: string;
|
|
137
|
+
};
|
|
138
|
+
type RhfTextareaProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & OwnTextareaProps;
|
|
139
|
+
/** A multi-line {@link Textarea}; takes `rows`. Stores the string. */
|
|
140
|
+
declare function RhfTextarea<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, inputClassName, ...areaProps }: RhfTextareaProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
141
|
+
type RhfNumberFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & Pick<NumberFieldProps, "digits" | "min" | "max" | "step" | "calculator" | "unit" | "unitPlacement" | "placeholder" | "inputClassName" | "locale" | "ariaLabel" | "autoFocus"> & {
|
|
142
|
+
/** What an emptied field stores. Default `null`; `""` for a schema written
|
|
143
|
+
* against a native number input (`z.coerce.number()` over `""`). */
|
|
144
|
+
emptyValue?: null | "";
|
|
145
|
+
/** `false`: an emptied field snaps back to its last number instead of storing
|
|
146
|
+
* `emptyValue`. Default `true`. */
|
|
147
|
+
nullable?: boolean;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* The kit's {@link NumberField}: a parsed, rounded (`digits`) and clamped (`min` /
|
|
151
|
+
* `max`) number, committed on blur or Enter in the locale's decimal mark. Stores a
|
|
152
|
+
* number, or `emptyValue` when emptied.
|
|
153
|
+
*/
|
|
154
|
+
declare function RhfNumberField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, emptyValue, nullable, ...numberProps }: RhfNumberFieldProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
155
|
+
type RhfMoneyFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & {
|
|
156
|
+
placeholder?: string;
|
|
157
|
+
/** The currency chip's code ("CHF"). */
|
|
158
|
+
currency?: string;
|
|
159
|
+
/** Makes the chip a currency picker. Bind it to another field with
|
|
160
|
+
* `useController`, or to state. */
|
|
161
|
+
onCurrencyChange?: (code: string) => void;
|
|
162
|
+
/** Colours the figure for the direction of money. */
|
|
163
|
+
tone?: "neutral" | "outflow" | "inflow";
|
|
164
|
+
align?: "start" | "center";
|
|
165
|
+
ariaLabel?: string;
|
|
166
|
+
autoFocus?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* What the form stores: `"number"` (default) — `12.5`, or `emptyValue` while the
|
|
169
|
+
* field is empty — or `"string"`, the field's own text ("12.50") for a schema that
|
|
170
|
+
* parses it itself. A half-typed sum ("12+") leaves the stored number as it was
|
|
171
|
+
* until it resolves.
|
|
172
|
+
*/
|
|
173
|
+
valueAs?: "number" | "string";
|
|
174
|
+
/** What an emptied field stores when `valueAs` is `"number"`. Default `null`. */
|
|
175
|
+
emptyValue?: null | "";
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* The kit's {@link AmountInput}: a money figure with its currency chip and the
|
|
179
|
+
* calculator ("1200+80" resolves on blur or Enter). Stores a number by default — see
|
|
180
|
+
* `valueAs`.
|
|
181
|
+
*/
|
|
182
|
+
declare function RhfMoneyField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, ...amountProps }: RhfMoneyFieldProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
183
|
+
type RhfDateFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & Omit<DatePickerProps, "value" | "onChange" | "label" | "invalid" | "disabled" | "className" | "id"> & {
|
|
184
|
+
/** Classes for the picker. Default `w-full`. */
|
|
185
|
+
inputClassName?: string;
|
|
186
|
+
/** What a cleared date stores. Default `""`, the empty ISO string; `null` for a
|
|
187
|
+
* nullable schema. */
|
|
188
|
+
emptyValue?: "" | null;
|
|
189
|
+
};
|
|
190
|
+
/** The kit's {@link DatePicker}, holding an ISO `"YYYY-MM-DD"` string. */
|
|
191
|
+
declare function RhfDateField<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, inputClassName, emptyValue, ...pickerProps }: RhfDateFieldProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
192
|
+
interface RhfSelectOption {
|
|
193
|
+
value: string | number;
|
|
194
|
+
label: ReactNode;
|
|
195
|
+
disabled?: boolean;
|
|
196
|
+
}
|
|
197
|
+
type RhfSelectProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & Pick<SelectProps, "size" | "autoFocus" | "aria-label"> & {
|
|
198
|
+
/** The options, as data. Or pass `<option>` children. */
|
|
199
|
+
options?: readonly RhfSelectOption[];
|
|
200
|
+
children?: ReactNode;
|
|
201
|
+
/** A first, empty option ("Choose…"), selected while the value is empty. */
|
|
202
|
+
placeholder?: string;
|
|
203
|
+
/** Store `Number(value)` rather than the option's string. An empty choice still
|
|
204
|
+
* stores `""`. */
|
|
205
|
+
valueAsNumber?: boolean;
|
|
206
|
+
/** Classes for the select. Default `w-full`. */
|
|
207
|
+
selectClassName?: string;
|
|
208
|
+
};
|
|
209
|
+
/** A native {@link Select}, from `options` or `<option>` children. */
|
|
210
|
+
declare function RhfSelect<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, options, children, placeholder, valueAsNumber, selectClassName, ...selectProps }: RhfSelectProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
211
|
+
type RhfCheckboxProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & Pick<CheckboxProps, "inputClassName" | "autoFocus" | "aria-label">;
|
|
212
|
+
/**
|
|
213
|
+
* The kit's {@link Checkbox}, label beside the box and `hint` under it (the
|
|
214
|
+
* checkbox's own `description`). Stores a boolean. `required` is the native one here
|
|
215
|
+
* — see Checkbox — so a `<form>` refuses to submit it unticked.
|
|
216
|
+
*/
|
|
217
|
+
declare function RhfCheckbox<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, ...boxProps }: RhfCheckboxProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
218
|
+
type RhfComboboxProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, V extends string | number = string | number, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & Pick<EntityComboboxProps<V>, "options" | "loadOptions" | "loading" | "placeholder" | "searchPlaceholder" | "emptyLabel" | "clearable" | "clearLabel" | "onCreate" | "createLabel" | "filter" | "minChars" | "debounceMs"> & {
|
|
219
|
+
/** What a clear stores — the picker's `clearValue`. Default `null`; `""` for a
|
|
220
|
+
* schema that spells "no choice" as an empty string. */
|
|
221
|
+
clearValue?: ComboClearValue;
|
|
222
|
+
/** Classes for the picker. */
|
|
223
|
+
comboClassName?: string;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* The kit's {@link EntityCombobox}: an id-keyed pick from `options` or `loadOptions`.
|
|
227
|
+
* Stores the option's `value`, or `clearValue` on a clear (only offered with
|
|
228
|
+
* `clearable`).
|
|
229
|
+
*/
|
|
230
|
+
declare function RhfCombobox<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, V extends string | number = string | number, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, clearValue, comboClassName, ...comboProps }: RhfComboboxProps<TFieldValues, TName, V, TTransformed>): react.JSX.Element;
|
|
231
|
+
type RhfTextComboboxProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues> = RhfFieldBaseProps<TFieldValues, TName, TTransformed> & Pick<ComboboxProps, "options" | "placeholder" | "groupBy" | "maxSuggestions" | "searchPlaceholder" | "createLabel" | "optionAdornment" | "autoFocus" | "aria-label"> & {
|
|
232
|
+
/** Classes for the combobox. */
|
|
233
|
+
comboClassName?: string;
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* The kit's free-text {@link Combobox}: type anything, or pick one of `options`.
|
|
237
|
+
* Stores the string.
|
|
238
|
+
*/
|
|
239
|
+
declare function RhfTextCombobox<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>, TTransformed = TFieldValues>({ name, control, rules, label, hint, required, disabled, className, comboClassName, ...comboProps }: RhfTextComboboxProps<TFieldValues, TName, TTransformed>): react.JSX.Element;
|
|
240
|
+
|
|
241
|
+
export { RhfCheckbox, type RhfCheckboxProps, RhfCombobox, type RhfComboboxProps, RhfDateField, type RhfDateFieldProps, RhfField, type RhfFieldBaseProps, type RhfFieldProps, type RhfFieldRenderContext, RhfMoneyField, type RhfMoneyFieldProps, RhfNumberField, type RhfNumberFieldProps, RhfSelect, type RhfSelectOption, type RhfSelectProps, RhfTextCombobox, type RhfTextComboboxProps, RhfTextField, type RhfTextFieldProps, RhfTextarea, type RhfTextareaProps };
|