@zonsh/ui 0.2.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.
Files changed (180) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +19 -13
  3. package/dist/components/alert-dialog.js +1 -1
  4. package/dist/components/ascii-field.d.ts +1 -1
  5. package/dist/components/bottom-nav.d.ts +86 -0
  6. package/dist/components/bottom-nav.js +175 -0
  7. package/dist/components/breadcrumb.d.ts +9 -0
  8. package/dist/components/breadcrumb.js +6 -1
  9. package/dist/components/button-group.d.ts +1 -1
  10. package/dist/components/button-group.js +2 -2
  11. package/dist/components/calendar.d.ts +1 -1
  12. package/dist/components/calendar.js +18 -3
  13. package/dist/components/carousel.d.ts +22 -3
  14. package/dist/components/carousel.js +25 -7
  15. package/dist/components/chart.d.ts +9 -0
  16. package/dist/components/chart.js +40 -3
  17. package/dist/components/code-block.d.ts +20 -10
  18. package/dist/components/code-block.js +54 -12
  19. package/dist/components/collapsible.js +2 -2
  20. package/dist/components/color-picker.d.ts +30 -8
  21. package/dist/components/color-picker.js +48 -27
  22. package/dist/components/combobox.d.ts +21 -3
  23. package/dist/components/combobox.js +79 -7
  24. package/dist/components/command.d.ts +23 -3
  25. package/dist/components/command.js +61 -16
  26. package/dist/components/conversation.d.ts +10 -1
  27. package/dist/components/conversation.js +14 -4
  28. package/dist/components/copy-button.d.ts +15 -6
  29. package/dist/components/copy-button.js +20 -5
  30. package/dist/components/data-table.d.ts +66 -6
  31. package/dist/components/data-table.js +376 -23
  32. package/dist/components/date-picker.d.ts +73 -4
  33. package/dist/components/date-picker.js +138 -7
  34. package/dist/components/dialog.d.ts +10 -1
  35. package/dist/components/dialog.js +6 -3
  36. package/dist/components/drawer.d.ts +10 -1
  37. package/dist/components/drawer.js +6 -3
  38. package/dist/components/feature-list.js +2 -2
  39. package/dist/components/field.d.ts +27 -8
  40. package/dist/components/field.js +49 -4
  41. package/dist/components/file-drop.d.ts +26 -4
  42. package/dist/components/file-drop.js +125 -64
  43. package/dist/components/filter-bar.d.ts +50 -3
  44. package/dist/components/filter-bar.js +71 -33
  45. package/dist/components/form.d.ts +4 -2
  46. package/dist/components/form.js +24 -2
  47. package/dist/components/graph.d.ts +41 -0
  48. package/dist/components/graph.js +84 -45
  49. package/dist/components/illustration.js +1 -1
  50. package/dist/components/input-group.d.ts +16 -5
  51. package/dist/components/input-group.js +35 -15
  52. package/dist/components/input.d.ts +2 -2
  53. package/dist/components/input.js +3 -3
  54. package/dist/components/kbd.d.ts +17 -0
  55. package/dist/components/kbd.js +8 -1
  56. package/dist/components/lightbox.d.ts +100 -0
  57. package/dist/components/lightbox.js +439 -0
  58. package/dist/components/locale.d.ts +44 -0
  59. package/dist/components/locale.js +37 -0
  60. package/dist/components/logo.js +1 -1
  61. package/dist/components/menu.js +3 -1
  62. package/dist/components/message.d.ts +3 -3
  63. package/dist/components/message.js +10 -7
  64. package/dist/components/meter.js +3 -1
  65. package/dist/components/money-input.d.ts +80 -0
  66. package/dist/components/money-input.js +253 -0
  67. package/dist/components/number-field.d.ts +21 -2
  68. package/dist/components/number-field.js +27 -16
  69. package/dist/components/otp-field.d.ts +14 -1
  70. package/dist/components/otp-field.js +10 -2
  71. package/dist/components/pagination.d.ts +13 -7
  72. package/dist/components/pagination.js +18 -7
  73. package/dist/components/pdf-viewer.d.ts +67 -2
  74. package/dist/components/pdf-viewer.js +88 -21
  75. package/dist/components/phone-input.d.ts +79 -0
  76. package/dist/components/phone-input.js +282 -0
  77. package/dist/components/popover.js +1 -1
  78. package/dist/components/progress.js +3 -1
  79. package/dist/components/prompt-input.d.ts +34 -9
  80. package/dist/components/prompt-input.js +28 -16
  81. package/dist/components/rating.d.ts +73 -0
  82. package/dist/components/rating.js +124 -0
  83. package/dist/components/reasoning.d.ts +16 -1
  84. package/dist/components/reasoning.js +10 -7
  85. package/dist/components/resizable.d.ts +10 -1
  86. package/dist/components/resizable.js +4 -1
  87. package/dist/components/response.d.ts +14 -3
  88. package/dist/components/response.js +36 -8
  89. package/dist/components/scroll-area.d.ts +1 -1
  90. package/dist/components/select.js +14 -3
  91. package/dist/components/separator.js +1 -1
  92. package/dist/components/sidebar.d.ts +20 -4
  93. package/dist/components/sidebar.js +34 -18
  94. package/dist/components/site-header.d.ts +46 -12
  95. package/dist/components/site-header.js +73 -19
  96. package/dist/components/slider.js +3 -1
  97. package/dist/components/sortable.d.ts +178 -0
  98. package/dist/components/sortable.js +1258 -0
  99. package/dist/components/sources.d.ts +17 -2
  100. package/dist/components/sources.js +11 -4
  101. package/dist/components/spinner.d.ts +13 -1
  102. package/dist/components/spinner.js +5 -2
  103. package/dist/components/stat.d.ts +91 -0
  104. package/dist/components/stat.js +141 -0
  105. package/dist/components/stepper.d.ts +71 -0
  106. package/dist/components/stepper.js +101 -0
  107. package/dist/components/switch.d.ts +2 -2
  108. package/dist/components/switch.js +2 -2
  109. package/dist/components/table.d.ts +12 -2
  110. package/dist/components/table.js +176 -39
  111. package/dist/components/tags-input.d.ts +18 -2
  112. package/dist/components/tags-input.js +65 -33
  113. package/dist/components/theme.d.ts +16 -2
  114. package/dist/components/theme.js +15 -7
  115. package/dist/components/time-field.d.ts +22 -3
  116. package/dist/components/time-field.js +19 -6
  117. package/dist/components/timeline.d.ts +18 -2
  118. package/dist/components/timeline.js +13 -4
  119. package/dist/components/tippy.d.ts +48 -0
  120. package/dist/components/tippy.js +648 -0
  121. package/dist/components/toast.d.ts +18 -2
  122. package/dist/components/toast.js +12 -3
  123. package/dist/components/tool-call.d.ts +19 -8
  124. package/dist/components/tool-call.js +18 -7
  125. package/dist/components/toolbar.js +6 -1
  126. package/dist/components/tour.d.ts +127 -0
  127. package/dist/components/tour.js +648 -0
  128. package/dist/components/tree.js +17 -4
  129. package/dist/components/video-player.d.ts +10 -2
  130. package/dist/components/video-player.js +73 -33
  131. package/dist/illustration.d.ts +2 -0
  132. package/dist/illustration.js +7 -0
  133. package/dist/index.d.ts +11 -3
  134. package/dist/index.js +11 -3
  135. package/dist/lib/code-highlight.d.ts +3 -16
  136. package/dist/lib/code-highlight.js +160 -10
  137. package/dist/lib/code-theme.js +3 -3
  138. package/dist/lib/digit-roll.js +8 -8
  139. package/dist/lib/field-errors.d.ts +28 -0
  140. package/dist/lib/field-errors.js +24 -0
  141. package/dist/lib/field-value.d.ts +13 -0
  142. package/dist/lib/field-value.js +44 -0
  143. package/dist/lib/graph-layout.js +11 -2
  144. package/dist/lib/money.d.ts +73 -0
  145. package/dist/lib/money.js +343 -0
  146. package/dist/lib/phone-countries.d.ts +1 -0
  147. package/dist/lib/phone-countries.js +281 -0
  148. package/dist/lib/phone.d.ts +90 -0
  149. package/dist/lib/phone.js +286 -0
  150. package/dist/lib/platform.d.ts +8 -3
  151. package/dist/lib/platform.js +13 -6
  152. package/dist/lib/row-index.d.ts +15 -0
  153. package/dist/lib/row-index.js +136 -0
  154. package/dist/lib/table-fit.js +23 -4
  155. package/dist/lib/theme-script.d.ts +15 -2
  156. package/dist/lib/theme-script.js +23 -3
  157. package/dist/lib/tippy/pixels.d.ts +47 -0
  158. package/dist/lib/tippy/pixels.js +187 -0
  159. package/dist/lib/tippy/sprite.d.ts +86 -0
  160. package/dist/lib/tippy/sprite.js +753 -0
  161. package/dist/messages/de.d.ts +12 -0
  162. package/dist/messages/de.js +326 -0
  163. package/dist/styles/expressive.css +20 -5
  164. package/dist/styles/index.css +3 -2
  165. package/dist/styles/material.css +7 -3
  166. package/dist/styles/parts/ai.css +2 -1
  167. package/dist/styles/parts/controls.css +62 -13
  168. package/dist/styles/parts/feedback.css +68 -1
  169. package/dist/styles/parts/foundations.css +1 -1
  170. package/dist/styles/parts/navigation.css +194 -2
  171. package/dist/styles/parts/overlays.css +7 -7
  172. package/dist/styles/tokens.css +12 -3
  173. package/dist/vite.d.ts +0 -50
  174. package/dist/vite.js +0 -100
  175. package/package.json +28 -33
  176. package/dist/components/code-highlight.d.ts +0 -13
  177. package/dist/components/code-highlight.js +0 -107
  178. package/dist/components/whiteboard.d.ts +0 -80
  179. package/dist/components/whiteboard.js +0 -389
  180. package/dist/styles/parts/whiteboard.css +0 -855
@@ -0,0 +1,90 @@
1
+ export interface PhoneCountry {
2
+ /** ISO 3166-1 alpha-2, upper case ("DE"); "AC" and "TA" for Ascension and Tristan da Cunha. */
3
+ iso: string;
4
+ /** The country calling code, without "+": "49". */
5
+ dial: string;
6
+ /** Every possible length of the national number. */
7
+ lengths: number[];
8
+ /** National prefixes people may type first ("0"), left out of E.164. */
9
+ trunks: string[];
10
+ /** International prefixes dialled instead of "+", besides the 00 read everywhere: "011" in
11
+ North America, "0011" and others in Australia. */
12
+ exits: string[];
13
+ /** National numbers that start with the trunk prefix's 0 (with 00, where there is no trunk
14
+ prefix), by their first digits and lengths: Rwanda's 06 and six digits, freephone 00800 …
15
+ in Bulgaria. A number starting with one has no trunk prefix and isn't international. */
16
+ zeros: {
17
+ prefix: string;
18
+ lengths: number[];
19
+ }[];
20
+ /** Whether the trunk prefix is written apart from the number ("8 912 345 67 89"), not joined to
21
+ its first group ("0163 7568602"). */
22
+ trunkApart: boolean;
23
+ /** Digit groups for reading, tried in order: the first whose `lead` matches the start of the
24
+ national number (`null`: any number) and whose groups fit its length. Each group is its
25
+ fewest and most digits. */
26
+ formats: {
27
+ lead: RegExp | null;
28
+ groups: [number, number][];
29
+ }[];
30
+ /** Leading digits that pick this country from the others sharing its calling code. */
31
+ leading: string[];
32
+ }
33
+ export declare const PHONE_COUNTRIES: readonly PhoneCountry[];
34
+ /** The country with this ISO code (any case), or undefined. */
35
+ export declare function phoneCountry(iso: string | null | undefined): PhoneCountry | undefined;
36
+ /** The countries with this calling code, the main one first. */
37
+ export declare function countriesWithCode(dial: string): readonly PhoneCountry[];
38
+ /** E.164 allows 15 digits after the "+", the country code included. */
39
+ export declare const E164_MAX_DIGITS = 15;
40
+ /** The digits 0–9 in a text, from any script ("٠١٢" and full-width digits count). */
41
+ export declare function phoneDigits(text: string): string;
42
+ /**
43
+ * The country and national number of the digits after a "+": "442079460018" → GB, "2079460018".
44
+ * Calling codes are prefix-free, so the first one that matches is the one. Null while the digits
45
+ * don't start with a known code yet ("4", or "9" of "+9…").
46
+ */
47
+ export declare function splitInternational(digits: string, current?: string): {
48
+ country: PhoneCountry;
49
+ national: string;
50
+ } | null;
51
+ /** An E.164 number as its country and national number; null for anything else. */
52
+ export declare function parsePhoneNumber(value: string | null | undefined, current?: string): {
53
+ country: PhoneCountry;
54
+ national: string;
55
+ } | null;
56
+ /** The E.164 form of a national number in a country, or null when there are no digits yet. */
57
+ export declare function toE164(country: PhoneCountry, national: string): string | null;
58
+ /**
59
+ * The national prefixes people dial at home, at the front of what they typed: "020 7946 0018" in
60
+ * the UK starts with the trunk "0". A "0" (or "06") is one, as national numbers there don't start
61
+ * with 0 — except a few ranges (Rwanda's 06 fixed lines, India's freephone 000800), read whole once
62
+ * the digits start with one — and so is North America's "1". Others ("8" in Russia, where 812 is
63
+ * an area code) count only when the digits are a possible length without them and not with them,
64
+ * or too long.
65
+ */
66
+ export declare function trunkPrefix(digits: string, country: PhoneCountry): string;
67
+ /** The national (significant) number of what someone typed, without the trunk prefix. */
68
+ export declare function nationalNumber(digits: string, country: PhoneCountry): string;
69
+ /**
70
+ * A national number grouped for reading, with any trunk prefix kept in front of the first group
71
+ * (or apart, where the country writes it so: "8 912 345 67 89"): "2079460018" → "20 7946 0018",
72
+ * "02079460018" → "020 7946 0018". Digits past the pattern stay on the last group.
73
+ */
74
+ export declare function formatNational(digits: string, country: PhoneCountry): string;
75
+ export type PhoneLength = "ok" | "short" | "long";
76
+ /**
77
+ * Whether a national number has one of its country's lengths, or is too short or too long; one of
78
+ * the ranges starting with 0 (`PhoneCountry.zeros`), one of that range's lengths.
79
+ */
80
+ export declare function checkPhoneLength(national: string, country: PhoneCountry): PhoneLength;
81
+ /**
82
+ * What a person typed or pasted as an international number: "+44 20 7946 0018", "0044 20…",
83
+ * "+44 (0)20 7946 0018", "tel:+4420…", or after the current country's own international prefix
84
+ * ("011 44 20…" in the US). Returns the digits after the "+", or null when the text isn't written
85
+ * internationally — as for a national number that starts like an international prefix, so far
86
+ * (Korea's freephone 00798 …, Bulgaria's 00800 …).
87
+ */
88
+ export declare function internationalDigits(text: string, current?: PhoneCountry): string | null;
89
+ /** The region of a locale ("de-AT" → "AT", "de" → "DE", "en" → "US"), if the table has it. */
90
+ export declare function regionOfLocale(locale: string | undefined): string | undefined;
@@ -0,0 +1,286 @@
1
+ /*
2
+ * Phone numbers for PhoneInput: E.164 ("+4915112345678"), split into a country and its national
3
+ * number, checked by length and grouped for reading. The countries come from libphonenumber's
4
+ * metadata, in phone-countries.ts (generated by `pnpm phone:data`, with what it holds); this is
5
+ * the table read and used.
6
+ */
7
+ import { latinDigits } from "./money.js";
8
+ import { PHONE_TABLE } from "./phone-countries.js";
9
+ function lengths(spec) {
10
+ const out = [];
11
+ for (const part of spec.split(",")) {
12
+ const [a, b] = part.split("-").map(Number);
13
+ for (let n = a; n <= (b ?? a); n++)
14
+ out.push(n);
15
+ }
16
+ return out;
17
+ }
18
+ function group(spec) {
19
+ if (spec.endsWith("+"))
20
+ return [Number(spec.slice(0, -1)), Infinity];
21
+ const [a, b] = spec.split("-").map(Number);
22
+ return [a, b ?? a];
23
+ }
24
+ const MAIN = new Set();
25
+ export const PHONE_COUNTRIES = PHONE_TABLE.trim()
26
+ .split("\n")
27
+ .map((line) => {
28
+ const [iso, code, len, trunk, ...rest] = line.trim().split(" ");
29
+ const dial = code.replace("*", "");
30
+ if (code.endsWith("*"))
31
+ MAIN.add(iso);
32
+ const exits = rest[0]?.startsWith("+") ? rest.shift().slice(1).split(",") : [];
33
+ const zeros = [];
34
+ while (rest[0]?.startsWith("!")) {
35
+ const [prefixes, len] = rest.shift().slice(1).split("/");
36
+ for (const prefix of prefixes.split(","))
37
+ zeros.push({ prefix, lengths: lengths(len) });
38
+ }
39
+ const leading = rest[0]?.startsWith("^") ? rest.shift().slice(1).split(",") : [];
40
+ return {
41
+ iso,
42
+ dial,
43
+ lengths: lengths(len),
44
+ trunks: trunk === "-" ? [] : trunk.replace("_", "").split("|"),
45
+ trunkApart: trunk.endsWith("_"),
46
+ exits,
47
+ zeros,
48
+ formats: rest.map((f) => {
49
+ const at = f.indexOf("=");
50
+ return {
51
+ lead: at < 0 ? null : new RegExp(`^(?:${f.slice(0, at)})`),
52
+ groups: f
53
+ .slice(at + 1)
54
+ .split(".")
55
+ .map(group),
56
+ };
57
+ }),
58
+ leading,
59
+ };
60
+ });
61
+ const BY_ISO = new Map(PHONE_COUNTRIES.map((c) => [c.iso, c]));
62
+ const BY_DIAL = new Map();
63
+ for (const c of PHONE_COUNTRIES) {
64
+ const list = BY_DIAL.get(c.dial) ?? [];
65
+ // The main country of a shared code first.
66
+ if (MAIN.has(c.iso))
67
+ list.unshift(c);
68
+ else
69
+ list.push(c);
70
+ BY_DIAL.set(c.dial, list);
71
+ }
72
+ // A territory without formats of its own (Canada, Jersey) writes numbers as its code's main
73
+ // country does, as in libphonenumber.
74
+ for (const list of BY_DIAL.values())
75
+ for (const c of list)
76
+ if (!c.formats.length && list[0] !== c) {
77
+ c.formats = list[0].formats;
78
+ c.trunkApart = list[0].trunkApart;
79
+ }
80
+ /** The country with this ISO code (any case), or undefined. */
81
+ export function phoneCountry(iso) {
82
+ return iso ? BY_ISO.get(iso.toUpperCase()) : undefined;
83
+ }
84
+ /** The countries with this calling code, the main one first. */
85
+ export function countriesWithCode(dial) {
86
+ return BY_DIAL.get(dial) ?? [];
87
+ }
88
+ /** E.164 allows 15 digits after the "+", the country code included. */
89
+ export const E164_MAX_DIGITS = 15;
90
+ /** The digits 0–9 in a text, from any script ("٠١٢" and full-width digits count). */
91
+ export function phoneDigits(text) {
92
+ return latinDigits(text.normalize("NFKC")).replace(/[^0-9]/g, "");
93
+ }
94
+ /**
95
+ * Of the countries sharing a calling code, the one a national number belongs to: the one whose
96
+ * leading digits it starts with (an area code: 416 is Canada), else the `current` country while
97
+ * the number can't tell them apart yet, else the code's main country.
98
+ */
99
+ function pickCountry(list, national, current) {
100
+ if (list.length === 1)
101
+ return list[0];
102
+ const byLeading = list.find((c) => c.leading.some((p) => national.startsWith(p)));
103
+ if (byLeading)
104
+ return byLeading;
105
+ const mine = list.find((c) => c.iso === current);
106
+ if (mine) {
107
+ // A country with no leading digits of its own can't be told from the main one.
108
+ if (mine.leading.length === 0)
109
+ return mine;
110
+ // Still one of its prefixes, as far as it goes: "41" may yet be 416, Toronto.
111
+ const undecided = mine.leading.some((p) => p.length > national.length && p.startsWith(national));
112
+ if (undecided)
113
+ return mine;
114
+ }
115
+ return list[0];
116
+ }
117
+ /**
118
+ * The country and national number of the digits after a "+": "442079460018" → GB, "2079460018".
119
+ * Calling codes are prefix-free, so the first one that matches is the one. Null while the digits
120
+ * don't start with a known code yet ("4", or "9" of "+9…").
121
+ */
122
+ export function splitInternational(digits, current) {
123
+ for (let len = 1; len <= 3 && len <= digits.length; len++) {
124
+ const list = countriesWithCode(digits.slice(0, len));
125
+ if (list.length) {
126
+ const national = digits.slice(len);
127
+ return { country: pickCountry(list, national, current), national };
128
+ }
129
+ }
130
+ return null;
131
+ }
132
+ /** An E.164 number as its country and national number; null for anything else. */
133
+ export function parsePhoneNumber(value, current) {
134
+ if (!value)
135
+ return null;
136
+ const m = /^\s*\+\s*([\d\s().-]+)$/.exec(value);
137
+ if (!m)
138
+ return null;
139
+ return splitInternational(phoneDigits(m[1]), current);
140
+ }
141
+ /** The E.164 form of a national number in a country, or null when there are no digits yet. */
142
+ export function toE164(country, national) {
143
+ return national ? `+${country.dial}${national}` : null;
144
+ }
145
+ /** The range of national numbers starting with 0 (see `PhoneCountry.zeros`) that digits are in. */
146
+ function zeroRange(digits, country) {
147
+ return country.zeros.find((z) => digits.startsWith(z.prefix));
148
+ }
149
+ /**
150
+ * The national prefixes people dial at home, at the front of what they typed: "020 7946 0018" in
151
+ * the UK starts with the trunk "0". A "0" (or "06") is one, as national numbers there don't start
152
+ * with 0 — except a few ranges (Rwanda's 06 fixed lines, India's freephone 000800), read whole once
153
+ * the digits start with one — and so is North America's "1". Others ("8" in Russia, where 812 is
154
+ * an area code) count only when the digits are a possible length without them and not with them,
155
+ * or too long.
156
+ */
157
+ export function trunkPrefix(digits, country) {
158
+ if (zeroRange(digits, country))
159
+ return "";
160
+ const { lengths } = country;
161
+ const n = digits.length;
162
+ for (const trunk of [...country.trunks].sort((a, b) => b.length - a.length)) {
163
+ if (!digits.startsWith(trunk))
164
+ continue;
165
+ if (trunk.startsWith("0") || (trunk === "1" && country.dial === "1"))
166
+ return trunk;
167
+ if (n > Math.max(...lengths))
168
+ return trunk;
169
+ if (!lengths.includes(n) && lengths.includes(n - trunk.length))
170
+ return trunk;
171
+ }
172
+ return "";
173
+ }
174
+ /** The national (significant) number of what someone typed, without the trunk prefix. */
175
+ export function nationalNumber(digits, country) {
176
+ return digits.slice(trunkPrefix(digits, country).length);
177
+ }
178
+ /** Groups of threes and fours for a number of `n` digits: 7 → 3 4, 10 → 3 3 4, 11 → 3 4 4. */
179
+ function defaultGroups(n) {
180
+ if (n <= 4)
181
+ return [n];
182
+ const r = n % 3;
183
+ if (r === 0)
184
+ return Array(n / 3).fill(3);
185
+ if (r === 1)
186
+ return [...Array((n - 4) / 3).fill(3), 4];
187
+ if (n === 5)
188
+ return [2, 3];
189
+ return [...Array((n - 8) / 3).fill(3), 4, 4];
190
+ }
191
+ /** The sizes of a format's groups for a number of `n` digits, the way its pattern would match. */
192
+ function sizesFor(groups, n) {
193
+ const fewest = groups.reduce((sum, g) => sum + g[0], 0);
194
+ // While it is being typed, each group at its shortest; past the longest, the rest joins the last.
195
+ if (n <= fewest)
196
+ return groups.map((g) => g[0]);
197
+ let rest = n - fewest;
198
+ return groups.map(([lo, hi]) => {
199
+ const size = Math.min(hi, lo + rest);
200
+ rest -= size - lo;
201
+ return size;
202
+ });
203
+ }
204
+ function groupsFor(national, country) {
205
+ const n = national.length;
206
+ const range = (f) => f.groups.reduce(([a, b], [lo, hi]) => [a + lo, b + hi], [0, 0]);
207
+ const matching = country.formats.filter((f) => !f.lead || f.lead.test(national));
208
+ if (matching.length) {
209
+ // libphonenumber's choice: the first that matches the leading digits and fits the length; while
210
+ // the number is short, the first it could still grow into; when too long, the longest.
211
+ const format = matching.find((f) => range(f)[0] <= n && n <= range(f)[1]) ??
212
+ matching.find((f) => n <= range(f)[1]) ??
213
+ matching.reduce((a, b) => (range(b)[1] > range(a)[1] ? b : a));
214
+ return sizesFor(format.groups, n);
215
+ }
216
+ // Without a pattern: grouped for the country's one length while it is being typed, else for n.
217
+ return defaultGroups(country.lengths.length === 1 ? Math.max(n, country.lengths[0]) : n);
218
+ }
219
+ /**
220
+ * A national number grouped for reading, with any trunk prefix kept in front of the first group
221
+ * (or apart, where the country writes it so: "8 912 345 67 89"): "2079460018" → "20 7946 0018",
222
+ * "02079460018" → "020 7946 0018". Digits past the pattern stay on the last group.
223
+ */
224
+ export function formatNational(digits, country) {
225
+ const trunk = trunkPrefix(digits, country);
226
+ const national = digits.slice(trunk.length);
227
+ if (!national)
228
+ return trunk;
229
+ const out = [];
230
+ let i = 0;
231
+ for (const size of groupsFor(national, country)) {
232
+ if (i >= national.length)
233
+ break;
234
+ out.push(national.slice(i, i + size));
235
+ i += size;
236
+ }
237
+ if (i < national.length)
238
+ out[out.length - 1] += national.slice(i);
239
+ out[0] = trunk + (trunk && country.trunkApart ? " " : "") + out[0];
240
+ return out.join(" ");
241
+ }
242
+ /**
243
+ * Whether a national number has one of its country's lengths, or is too short or too long; one of
244
+ * the ranges starting with 0 (`PhoneCountry.zeros`), one of that range's lengths.
245
+ */
246
+ export function checkPhoneLength(national, country) {
247
+ const n = national.length;
248
+ const lengths = zeroRange(national, country)?.lengths ?? country.lengths;
249
+ if (lengths.includes(n))
250
+ return "ok";
251
+ return n > Math.max(...lengths) ? "long" : "short";
252
+ }
253
+ /**
254
+ * What a person typed or pasted as an international number: "+44 20 7946 0018", "0044 20…",
255
+ * "+44 (0)20 7946 0018", "tel:+4420…", or after the current country's own international prefix
256
+ * ("011 44 20…" in the US). Returns the digits after the "+", or null when the text isn't written
257
+ * internationally — as for a national number that starts like an international prefix, so far
258
+ * (Korea's freephone 00798 …, Bulgaria's 00800 …).
259
+ */
260
+ export function internationalDigits(text, current) {
261
+ const t = text.normalize("NFKC").replace(/\(0\)/g, "").trim().replace(/^tel:/i, "");
262
+ if (/^[^\d+]*\+/.test(t))
263
+ return phoneDigits(t.slice(t.indexOf("+") + 1));
264
+ const digits = phoneDigits(t);
265
+ if (current?.zeros.some((z) => digits.startsWith(z.prefix) || z.prefix.startsWith(digits)))
266
+ return null;
267
+ const first = t.replace(/^[\s(]+/, "")[0];
268
+ const exits = [...(current?.exits ?? []), "00"].sort((a, b) => b.length - a.length);
269
+ for (const exit of exits)
270
+ // Not when a 0 follows: no calling code starts with one (as libphonenumber reads it).
271
+ if (digits.startsWith(exit) && digits[exit.length] !== "0" && first === exit[0])
272
+ return digits.slice(exit.length);
273
+ return null;
274
+ }
275
+ /** The region of a locale ("de-AT" → "AT", "de" → "DE", "en" → "US"), if the table has it. */
276
+ export function regionOfLocale(locale) {
277
+ if (!locale)
278
+ return undefined;
279
+ try {
280
+ const region = new Intl.Locale(locale).maximize().region;
281
+ return phoneCountry(region) ? region : undefined;
282
+ }
283
+ catch {
284
+ return undefined;
285
+ }
286
+ }
@@ -24,10 +24,15 @@ export declare function useShortcutKeys(): {
24
24
  mod: string;
25
25
  hasKeyboard: boolean;
26
26
  };
27
- /** Each key of a shortcut as the device's keyboard prints it: `mod` is ⌘ or Ctrl, and so on. */
28
- export declare function keyNames(keys: string[], mod: string): string[];
27
+ /** The names of the keys off Apple keyboards, as a language prints them: German "Strg", "Umschalt". */
28
+ export type KeyNames = Partial<Record<"ctrl" | "shift" | "alt" | "enter", string>>;
29
+ /**
30
+ * Each key of a shortcut as the device's keyboard prints it: `mod` is ⌘ or Ctrl, and so on.
31
+ * `names` renames the keys off Apple keyboards (Apple's are symbols in every language).
32
+ */
33
+ export declare function keyNames(keys: string[], mod: string, names?: KeyNames): string[];
29
34
  /**
30
35
  * A shortcut as text, the way each platform writes it in menus: run together on Apple ("⇧⌘Z",
31
36
  * modifiers in Apple's order), joined with "+" elsewhere ("Ctrl+Shift+Z").
32
37
  */
33
- export declare function formatShortcut(keys: string[], mod: string): string;
38
+ export declare function formatShortcut(keys: string[], mod: string, names?: KeyNames): string;
@@ -46,18 +46,25 @@ const otherKeys = {
46
46
  ctrl: "Ctrl",
47
47
  enter: "Enter",
48
48
  };
49
- /** Each key of a shortcut as the device's keyboard prints it: `mod` is ⌘ or Ctrl, and so on. */
50
- export function keyNames(keys, mod) {
51
- const names = mod === "⌘" ? appleKeys : otherKeys;
52
- return keys.map((key) => names[key.toLowerCase()] ?? key);
49
+ /**
50
+ * Each key of a shortcut as the device's keyboard prints it: `mod` is ⌘ or Ctrl, and so on.
51
+ * `names` renames the keys off Apple keyboards (Apple's are symbols in every language).
52
+ */
53
+ export function keyNames(keys, mod, names) {
54
+ const own = mod === "⌘"
55
+ ? appleKeys
56
+ : names
57
+ ? { ...otherKeys, ...names, mod: names.ctrl ?? otherKeys.mod }
58
+ : otherKeys;
59
+ return keys.map((key) => own[key.toLowerCase()] ?? key);
53
60
  }
54
61
  /**
55
62
  * A shortcut as text, the way each platform writes it in menus: run together on Apple ("⇧⌘Z",
56
63
  * modifiers in Apple's order), joined with "+" elsewhere ("Ctrl+Shift+Z").
57
64
  */
58
- export function formatShortcut(keys, mod) {
65
+ export function formatShortcut(keys, mod, names) {
59
66
  if (mod !== "⌘")
60
- return keyNames(keys, mod).join("+");
67
+ return keyNames(keys, mod, names).join("+");
61
68
  const order = ["ctrl", "alt", "shift", "mod"];
62
69
  const sorted = [...keys].sort((a, b) => {
63
70
  const ia = order.indexOf(a.toLowerCase());
@@ -0,0 +1,15 @@
1
+ /**
2
+ * One number per row that sorts as its value does: numbers and dates as themselves, text by its
3
+ * place among the column's texts in `collator`'s order, an empty cell below everything (first going
4
+ * up, last going down, as DataTable sorts it).
5
+ */
6
+ export declare function columnRanks(count: number, read: (index: number) => unknown, collator: Intl.Collator): Float64Array<ArrayBuffer>;
7
+ /** Every row index, ordered by the keys in turn (each ascending unless `desc`), then by index. */
8
+ export declare function sortedOrder(count: number, keys: readonly {
9
+ ranks: Float64Array;
10
+ desc: boolean;
11
+ }[]): Uint32Array<ArrayBuffer>;
12
+ /** Each row's searchable values as one line of lower-case text, as TanStack's `includesString` reads them. */
13
+ export declare function searchLines(count: number, readers: readonly ((index: number) => unknown)[]): string[];
14
+ /** The indices in `order` whose line holds `query` (ignoring case), in that order. */
15
+ export declare function matching(order: Uint32Array, lines: readonly string[], query: string): Uint32Array<ArrayBuffer>;
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Sorting and searching many rows without an object per row, for DataTable's large mode: each
3
+ * sorted column becomes one number per row (its rank), each row one line of lower-case text to
4
+ * search, and an order is an array of row indices.
5
+ */
6
+ /** null, undefined, NaN and "": a cell with nothing in it. */
7
+ const isBlank = (value) => value == null || value === "" || (typeof value === "number" && Number.isNaN(value));
8
+ /** Past this many different texts in a column, they are ordered by `naturalCompare`, not the collator. */
9
+ const COLLATE_UP_TO = 50_000;
10
+ /**
11
+ * One number per row that sorts as its value does: numbers and dates as themselves, text by its
12
+ * place among the column's texts in `collator`'s order, an empty cell below everything (first going
13
+ * up, last going down, as DataTable sorts it).
14
+ */
15
+ export function columnRanks(count, read, collator) {
16
+ const ranks = new Float64Array(count);
17
+ const values = new Array(count);
18
+ let text = false;
19
+ for (let i = 0; i < count; i++) {
20
+ const value = read(i);
21
+ values[i] = value;
22
+ if (typeof value === "string" && value !== "")
23
+ text = true;
24
+ }
25
+ if (!text) {
26
+ for (let i = 0; i < count; i++) {
27
+ const value = values[i];
28
+ ranks[i] = isBlank(value)
29
+ ? -Infinity
30
+ : value instanceof Date
31
+ ? value.getTime()
32
+ : typeof value === "boolean"
33
+ ? Number(value)
34
+ : Number(value);
35
+ if (Number.isNaN(ranks[i]))
36
+ ranks[i] = -Infinity;
37
+ }
38
+ return ranks;
39
+ }
40
+ // Text (and anything mixed in with it, as its text): each different one sorted once.
41
+ const distinct = new Map();
42
+ for (let i = 0; i < count; i++)
43
+ if (!isBlank(values[i]))
44
+ distinct.set(String(values[i]), 0);
45
+ const texts = [...distinct.keys()];
46
+ if (texts.length <= COLLATE_UP_TO)
47
+ texts.sort(collator.compare);
48
+ else {
49
+ const keys = new Map(texts.map((t) => [t, foldText(t)]));
50
+ texts.sort((a, b) => naturalCompare(keys.get(a), keys.get(b)) || collator.compare(a, b));
51
+ }
52
+ texts.forEach((t, rank) => distinct.set(t, rank));
53
+ for (let i = 0; i < count; i++)
54
+ ranks[i] = isBlank(values[i]) ? -Infinity : distinct.get(String(values[i]));
55
+ return ranks;
56
+ }
57
+ /** Lower case without accents: close to the collator's first level, and fast to compare. */
58
+ const foldText = (text) => text
59
+ .normalize("NFD")
60
+ .replace(/\p{Diacritic}/gu, "")
61
+ .toLowerCase();
62
+ /** Compares runs of digits by value ("item2" before "item10") and the rest by code unit. */
63
+ function naturalCompare(a, b) {
64
+ let i = 0;
65
+ let j = 0;
66
+ while (i < a.length && j < b.length) {
67
+ const ca = a.charCodeAt(i);
68
+ const cb = b.charCodeAt(j);
69
+ if (isDigit(ca) && isDigit(cb)) {
70
+ let ei = i;
71
+ let ej = j;
72
+ while (ei < a.length && isDigit(a.charCodeAt(ei)))
73
+ ei++;
74
+ while (ej < b.length && isDigit(b.charCodeAt(ej)))
75
+ ej++;
76
+ const na = a.slice(i, ei).replace(/^0+(?=\d)/, "");
77
+ const nb = b.slice(j, ej).replace(/^0+(?=\d)/, "");
78
+ if (na.length !== nb.length)
79
+ return na.length - nb.length;
80
+ if (na !== nb)
81
+ return na < nb ? -1 : 1;
82
+ i = ei;
83
+ j = ej;
84
+ continue;
85
+ }
86
+ if (ca !== cb)
87
+ return ca - cb;
88
+ i++;
89
+ j++;
90
+ }
91
+ return a.length - i - (b.length - j);
92
+ }
93
+ const isDigit = (code) => code >= 48 && code <= 57;
94
+ /** Every row index, ordered by the keys in turn (each ascending unless `desc`), then by index. */
95
+ export function sortedOrder(count, keys) {
96
+ const order = new Uint32Array(count);
97
+ for (let i = 0; i < count; i++)
98
+ order[i] = i;
99
+ if (keys.length === 0)
100
+ return order;
101
+ return order.sort((a, b) => {
102
+ for (const { ranks, desc } of keys) {
103
+ const ra = ranks[a];
104
+ const rb = ranks[b];
105
+ if (ra !== rb)
106
+ return (ra < rb ? -1 : 1) * (desc ? -1 : 1);
107
+ }
108
+ return a - b;
109
+ });
110
+ }
111
+ /** Each row's searchable values as one line of lower-case text, as TanStack's `includesString` reads them. */
112
+ export function searchLines(count, readers) {
113
+ const lines = new Array(count);
114
+ for (let i = 0; i < count; i++) {
115
+ let line = "";
116
+ for (const read of readers) {
117
+ const value = read(i);
118
+ if (value != null)
119
+ line += `${String(value).toLowerCase()}\u0000`;
120
+ }
121
+ lines[i] = line;
122
+ }
123
+ return lines;
124
+ }
125
+ /** The indices in `order` whose line holds `query` (ignoring case), in that order. */
126
+ export function matching(order, lines, query) {
127
+ const q = query.toLowerCase();
128
+ const out = new Uint32Array(order.length);
129
+ let n = 0;
130
+ for (let k = 0; k < order.length; k++) {
131
+ const i = order[k];
132
+ if (lines[i].includes(q))
133
+ out[n++] = i;
134
+ }
135
+ return out.subarray(0, n);
136
+ }
@@ -531,12 +531,14 @@ export const reducedMotion = () => typeof window !== "undefined" && window.match
531
531
  /* ── Virtual rows ──────────────────────────────────────────────────────────── */
532
532
  /** East Asian wide characters (CJK, Hangul, full-width forms): drawn about twice as wide. */
533
533
  const WIDE = /[ᄀ-ᅟ⺀-꓏가-힣豈-﫿︰-﹏＀-⦆¢-₩]/g;
534
+ /** No character a wide one could be: most values, checked faster than counting. */
535
+ const ASCII = /^[\x00-\u10ff]*$/;
534
536
  /** How long a value reads, in characters (wide ones twice): a stand-in for how wide its cell is drawn. */
535
537
  function textLength(value) {
536
538
  if (value == null)
537
539
  return 0;
538
540
  if (typeof value === "string")
539
- return value.length + (value.match(WIDE)?.length ?? 0);
541
+ return value.length + (ASCII.test(value) ? 0 : (value.match(WIDE)?.length ?? 0));
540
542
  if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean")
541
543
  return String(value).length;
542
544
  if (value instanceof Date)
@@ -563,15 +565,32 @@ export function widestRows(rows, valuesOf, per = 2) {
563
565
  if (list.length > per)
564
566
  list.pop();
565
567
  };
566
- rows.forEach((row, at) => {
568
+ const visit = (at) => {
567
569
  let total = 0;
568
- valuesOf(row).forEach((value, j) => {
570
+ valuesOf(rows[at]).forEach((value, j) => {
569
571
  const len = textLength(value);
570
572
  total += len;
571
573
  if (len > 0)
572
574
  keep(j + 1, len, at);
573
575
  });
574
576
  keep(0, total, at);
575
- });
577
+ };
578
+ // Every row, up to SAMPLE_FROM; past it, the first and last rows and an even spread between —
579
+ // reading a million values would hold up the table's first paint for the width of a column.
580
+ if (rows.length <= SAMPLE_FROM)
581
+ for (let at = 0; at < rows.length; at++)
582
+ visit(at);
583
+ else {
584
+ const ends = 1000;
585
+ const step = (rows.length - 2 * ends) / (SAMPLE_FROM - 2 * ends);
586
+ for (let at = 0; at < ends; at++)
587
+ visit(at);
588
+ for (let x = ends; x < rows.length - ends; x += step)
589
+ visit(Math.floor(x));
590
+ for (let at = rows.length - ends; at < rows.length; at++)
591
+ visit(at);
592
+ }
576
593
  return [...new Set(best.flat().map((entry) => entry.at))].sort((a, b) => a - b);
577
594
  }
595
+ /** Past this many rows, `widestRows` reads a sample of them. */
596
+ const SAMPLE_FROM = 50_000;
@@ -3,13 +3,26 @@ export type ThemeMode = "light" | "dark" | "system";
3
3
  export declare const THEME_STORAGE_KEY = "zon-theme";
4
4
  /** The media query `system` follows. Not part of the public API. */
5
5
  export declare const DARK_QUERY = "(prefers-color-scheme: dark)";
6
+ /**
7
+ * The page ground as one flat colour in each theme, --page-tone in tokens.css: what the grain
8
+ * over the background averages to. The browser's own bars (the status bar and toolbar on a
9
+ * phone) take it through `<meta name="theme-color">`, so they match the page.
10
+ */
11
+ export declare const PAGE_TONE: {
12
+ readonly light: "#f9f9f9";
13
+ readonly dark: "#141414";
14
+ };
15
+ /** The `theme-color` meta that names no media, made if the page has none. Not part of the public API. */
16
+ export declare function setThemeColor(dark: boolean): void;
6
17
  /**
7
18
  * Build the no-flash script for `<head>`. It applies `.dark` before first paint, using the
8
- * same storage key and default as `ThemeProvider`. Pass the same options to both.
19
+ * same storage key and default as `ThemeProvider`, and sets `<meta name="theme-color">` to the
20
+ * theme's page tone (making the tag if there is none). Pass the same options to both.
9
21
  */
10
- export declare function createThemeScript({ storageKey, defaultTheme, }?: {
22
+ export declare function createThemeScript({ storageKey, defaultTheme, themeColor, }?: {
11
23
  storageKey?: string;
12
24
  defaultTheme?: ThemeMode;
25
+ themeColor?: boolean;
13
26
  }): string;
14
27
  /**
15
28
  * Inline this in `<head>`, before any stylesheet paints, to avoid a flash of the wrong theme: