@hozo/typography 0.3.0 → 0.5.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +1 -1
  3. package/dist/code/meta.d.ts +14 -0
  4. package/dist/code/meta.d.ts.map +1 -0
  5. package/dist/code/meta.js +62 -0
  6. package/dist/code/meta.js.map +1 -0
  7. package/dist/code/model.d.ts +66 -0
  8. package/dist/code/model.d.ts.map +1 -0
  9. package/dist/code/model.js +139 -0
  10. package/dist/code/model.js.map +1 -0
  11. package/dist/code/reuse.d.ts +22 -0
  12. package/dist/code/reuse.d.ts.map +1 -0
  13. package/dist/code/reuse.js +54 -0
  14. package/dist/code/reuse.js.map +1 -0
  15. package/dist/code/shiki.d.ts +12 -0
  16. package/dist/code/shiki.d.ts.map +1 -0
  17. package/dist/code/shiki.js +28 -0
  18. package/dist/code/shiki.js.map +1 -0
  19. package/dist/code-lines.d.ts +34 -0
  20. package/dist/code-lines.d.ts.map +1 -0
  21. package/dist/code-lines.js +192 -0
  22. package/dist/code-lines.js.map +1 -0
  23. package/dist/code-lines.native.d.ts +69 -0
  24. package/dist/code-lines.native.d.ts.map +1 -0
  25. package/dist/code-lines.native.js +138 -0
  26. package/dist/code-lines.native.js.map +1 -0
  27. package/dist/index.d.ts +3 -41
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +3 -69
  30. package/dist/index.js.map +1 -1
  31. package/dist/index.native.d.ts +3 -82
  32. package/dist/index.native.d.ts.map +1 -1
  33. package/dist/index.native.js +3 -140
  34. package/dist/index.native.js.map +1 -1
  35. package/dist/text.d.ts +43 -0
  36. package/dist/text.d.ts.map +1 -0
  37. package/dist/text.js +75 -0
  38. package/dist/text.js.map +1 -0
  39. package/dist/text.native.d.ts +84 -0
  40. package/dist/text.native.d.ts.map +1 -0
  41. package/dist/text.native.js +144 -0
  42. package/dist/text.native.js.map +1 -0
  43. package/package.json +30 -4
  44. package/src/code/meta.ts +69 -0
  45. package/src/code/model.ts +189 -0
  46. package/src/code/reuse.ts +70 -0
  47. package/src/code/shiki.ts +38 -0
  48. package/src/code-lines.native.tsx +236 -0
  49. package/src/code-lines.tsx +310 -0
  50. package/src/index.native.tsx +4 -245
  51. package/src/index.tsx +4 -164
  52. package/src/text.native.tsx +250 -0
  53. package/src/text.tsx +179 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @hozo/typography
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2123](https://github.com/iray-tno/hozo/pull/2123) [`81d27ab`](https://github.com/iray-tno/hozo/commit/81d27ab01c4b732472499d098c847210355bad53) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `data-code-mark*` owner facts and `figure` / `figcaption` Web host support, and route all eight `CodeBlock` slots (`className`, `lineClassName`, `gutterClassName`, `insClassName`, `delClassName`, `markClassName`, `copyClassName`, `captionClassName`) through audited owner contracts on Web and Native by default.
8
+ - Updated dependencies [[`e5c848d`](https://github.com/iray-tno/hozo/commit/e5c848de8f4ff732fc7fc4a2d343e34938df1800), [`cb4b456`](https://github.com/iray-tno/hozo/commit/cb4b4564ddb95d7ecb6f729433bf5c956788b53e), [`ba5beaf`](https://github.com/iray-tno/hozo/commit/ba5beaf2fbaff50a5b6bb1595ee156cae9dd5a1c), [`43d6add`](https://github.com/iray-tno/hozo/commit/43d6add1b83dce0acda189ce9a1b610fb4a9d70d), [`0001fc4`](https://github.com/iray-tno/hozo/commit/0001fc442e38955770974fb5377002e4deb4b95f), [`ed04074`](https://github.com/iray-tno/hozo/commit/ed04074de82890b87590afb537a0bea99b2751a7), [`6cf46e3`](https://github.com/iray-tno/hozo/commit/6cf46e30640459d327305ffce8b38d26e27b3a9b), [`052b447`](https://github.com/iray-tno/hozo/commit/052b447351a669a12c5b8ced61bef5d07dc8a604), [`43680e3`](https://github.com/iray-tno/hozo/commit/43680e3643ba9f3f6e01f5c7aa885feb8e5c7b04), [`35cc5c3`](https://github.com/iray-tno/hozo/commit/35cc5c31ce90497de9a6f345e884af2d20a6bc60), [`b4bc0e3`](https://github.com/iray-tno/hozo/commit/b4bc0e3bec63c02a0d97b55b256714985385372f), [`5c823ee`](https://github.com/iray-tno/hozo/commit/5c823ee87f1996f7011290af68702ef7f19e5388), [`70643e9`](https://github.com/iray-tno/hozo/commit/70643e959d229a75fcdbd1316f9a972efb4a2622), [`9a5c4ac`](https://github.com/iray-tno/hozo/commit/9a5c4ac57fdc996649a323c72b4be55aeb221cd7), [`3a3a8d5`](https://github.com/iray-tno/hozo/commit/3a3a8d52d64d0d580d9afaa298977c5c33f295f2), [`45eda5b`](https://github.com/iray-tno/hozo/commit/45eda5b451bdf1449c7c16172c03b2a9e743aaa6), [`cca1211`](https://github.com/iray-tno/hozo/commit/cca1211b176ec411112275399fc582a92a50efbe), [`4f62450`](https://github.com/iray-tno/hozo/commit/4f624503a4fb9f4af6f699f7d2deb55b69a72c36), [`ddd7c73`](https://github.com/iray-tno/hozo/commit/ddd7c73d09768ad8fbcf55c40859729b7271ea1a), [`2d28017`](https://github.com/iray-tno/hozo/commit/2d2801735d14c61193610e74bc6178f15b79d07e), [`cabc969`](https://github.com/iray-tno/hozo/commit/cabc9695ae805afa2c690aebcad5657f76f95eac), [`3f1754a`](https://github.com/iray-tno/hozo/commit/3f1754a523e62dc44ccc3da7294e9510e5203302), [`b3cf38b`](https://github.com/iray-tno/hozo/commit/b3cf38b30f2fe748c4f73110d01de2566826355a)]:
9
+ - @hozo/primitives@0.5.0
10
+ - @hozo/engine@0.5.0
11
+ - @hozo/behaviors@0.5.0
12
+
13
+ ## 0.4.0
14
+
15
+ ### Minor Changes
16
+
17
+ - [#1597](https://github.com/iray-tno/hozo/pull/1597) [`b3df5b7`](https://github.com/iray-tno/hozo/commit/b3df5b73a8ec104fe407d89472e4339411de311d) Thanks [@iray-tno](https://github.com/iray-tno)! - React Native 0.87 is now the lowest supported version (`react-native: >=0.87`), and `@hozo/media`'s Expo peers move to SDK 58 (`expo-video`, `expo-audio` and `expo-asset` `>=58 <59`). Native gradients go under `backgroundImage` again: the `experimental_backgroundImage` spelling existed only for React Native 0.86, which read nothing else.
18
+
19
+ - [#1245](https://github.com/iray-tno/hozo/pull/1245) [`37a9151`](https://github.com/iray-tno/hozo/commit/37a915152634d8e25dfa9b2958661d4bc8f0a134) Thanks [@iray-tno](https://github.com/iray-tno)! - Add portable CodeLines and CodeBlock with application-supplied tokens, semantic line marks, hidden gutters, line numbers, wrapping, accessible scrolling and copy feedback. Supply Native clipboard access through CodeClipboardProvider. Pure model, Shiki connection and fence metadata helpers have independent subpaths; no highlighter or diff runtime is included.
20
+
21
+ Del now renders a semantic `<del>` on Web instead of `<s>`. Strikethrough retains `<s>`; Ins adds `<ins>` with underline on Native.
22
+
23
+ ### Patch Changes
24
+
25
+ - [#1396](https://github.com/iray-tno/hozo/pull/1396) [`d674538`](https://github.com/iray-tno/hozo/commit/d674538468608c9aa128494f983bf022722c4337) Thanks [@iray-tno](https://github.com/iray-tno)! - A Native `CodeBlock` or `CodeLines` no longer redraws the lines an update left alone: a line passed again as the same object keeps its row. Changing one line of a 1000-line block re-rendered every mounted line before.
26
+
27
+ - [#1489](https://github.com/iray-tno/hozo/pull/1489) [`7ad0aaa`](https://github.com/iray-tno/hozo/commit/7ad0aaa1ea5db43cb04d4cb4f471e738265f4f1e) Thanks [@iray-tno](https://github.com/iray-tno)! - A Native code line now nests one `Text` per run of tokens that draw the same, rather than one per token, and none when the whole line draws one way. Whitespace joins its neighbour whatever its colour. On Shiki's output for real source this is about a quarter fewer nested `Text`s. The text, the accessibility label and what is drawn are unchanged.
28
+
29
+ - [#1384](https://github.com/iray-tno/hozo/pull/1384) [`1b54676`](https://github.com/iray-tno/hozo/commit/1b54676fbc476f848d2e834a9443fde0bf888ce9) Thanks [@iray-tno](https://github.com/iray-tno)! - A windowed `CodeBlock` now windows on the Web too: only the lines near the visible ones are mounted, the rest are held as space, and an unwrapped block keeps its scrolling width with a hidden copy of the widest line. The lines stay one `<pre><code>`.
30
+
31
+ - [#1411](https://github.com/iray-tno/hozo/pull/1411) [`301e475`](https://github.com/iray-tno/hozo/commit/301e475d88e4628517a9b4fb2b2f0a245af62144) Thanks [@iray-tno](https://github.com/iray-tno)! - A windowed Web `CodeBlock` can be read to its last line by a screen reader: the whole text is kept as hidden plain lines with their mark prefixes, and the drawn rows are hidden from reading.
32
+
33
+ - [#1399](https://github.com/iray-tno/hozo/pull/1399) [`3fb505a`](https://github.com/iray-tno/hozo/commit/3fb505a3ce6a7793eef0037ec27d72edea0abf27) Thanks [@iray-tno](https://github.com/iray-tno)! - A Web `CodeBlock` or `CodeLines` no longer redraws the lines an update left alone, as on Native: a line passed again as the same object keeps its row.
34
+ - Updated dependencies [[`d7dd5b9`](https://github.com/iray-tno/hozo/commit/d7dd5b9d91a77c6cf647ba2de6fb321f8e558613), [`27536fc`](https://github.com/iray-tno/hozo/commit/27536fc602947b8928df7fa4d8940363fc0e3a67), [`99892e2`](https://github.com/iray-tno/hozo/commit/99892e25f536991e2966aa60769bd7155d5d8336), [`4270a72`](https://github.com/iray-tno/hozo/commit/4270a727b14605d7ff5c9831238e60cb518e3ed6), [`1c052da`](https://github.com/iray-tno/hozo/commit/1c052dad66426e8a4acd462c776f161249330c35), [`1b54676`](https://github.com/iray-tno/hozo/commit/1b54676fbc476f848d2e834a9443fde0bf888ce9), [`480e00a`](https://github.com/iray-tno/hozo/commit/480e00a0d6e165b92beb8dbf9310710fcceb7fd1), [`fac2f53`](https://github.com/iray-tno/hozo/commit/fac2f53a7636c7373cf22c4d49fcf5a137bb08ec), [`b0c6f22`](https://github.com/iray-tno/hozo/commit/b0c6f220c74d8a5c5a0c13bcf5fc9f8b97a25419), [`add3e7b`](https://github.com/iray-tno/hozo/commit/add3e7b2c5a152c770eabee7d09d723e925958e1), [`ffd5b6b`](https://github.com/iray-tno/hozo/commit/ffd5b6bbb0021d512d416fc5d8ae7441cc18c463), [`e4734c8`](https://github.com/iray-tno/hozo/commit/e4734c832c6469edc4ba88a7e09209b2b2ccd29b), [`b59995e`](https://github.com/iray-tno/hozo/commit/b59995e108e4cc9b6d093c2487cebece0d02a707), [`d5a1a1e`](https://github.com/iray-tno/hozo/commit/d5a1a1ee6a55dd50c6c2f91289a11a8665dd9d74), [`c1ca21a`](https://github.com/iray-tno/hozo/commit/c1ca21afee0e3f4dd92110570f3ff3775b01c4cf), [`5cbbb5d`](https://github.com/iray-tno/hozo/commit/5cbbb5de2ba68dd8e44c1939535a84f5325bb950), [`cf7773e`](https://github.com/iray-tno/hozo/commit/cf7773edcfd5f9d9cb42e35489ce1b15e35312bb), [`c4696a4`](https://github.com/iray-tno/hozo/commit/c4696a4660ceb546fc9e29bc18d1fe73979681e5), [`b3df5b7`](https://github.com/iray-tno/hozo/commit/b3df5b73a8ec104fe407d89472e4339411de311d), [`c9a3b4d`](https://github.com/iray-tno/hozo/commit/c9a3b4d61541024c66165c91a4b7e2a75c9a203c), [`416d627`](https://github.com/iray-tno/hozo/commit/416d627e8afc6a3f321c95dbe1f74b630d173d7b), [`242253d`](https://github.com/iray-tno/hozo/commit/242253da3910698e0838d74cbc9d51e1ca5995d6), [`37a9151`](https://github.com/iray-tno/hozo/commit/37a915152634d8e25dfa9b2958661d4bc8f0a134), [`e7d97e9`](https://github.com/iray-tno/hozo/commit/e7d97e981615355534d0ea20c4a70410556cbda4)]:
35
+ - @hozo/primitives@0.4.0
36
+ - @hozo/behaviors@0.4.0
37
+ - @hozo/engine@0.4.0
38
+
3
39
  ## 0.3.0
4
40
 
5
41
  ### Minor Changes
package/README.md CHANGED
@@ -157,6 +157,6 @@ plan—it never edits Xcode, Gradle, Info.plist, or Android resources—and omit
157
157
 
158
158
  ---
159
159
 
160
- Part of [Hozo](https://iray-tno.github.io/hozo/), a Rust-powered universal UI compiler and accessibility-first layer for React Native. Most applications install [`@hozo/core`](https://www.npmjs.com/package/@hozo/core) and one build integration; see [Getting started](https://github.com/iray-tno/hozo#getting-started). Source and issues: [github.com/iray-tno/hozo](https://github.com/iray-tno/hozo).
160
+ Part of [Hozo](https://iray-tno.github.io/hozo/), a universal UI framework for React Native, compiled by Rust, with native semantics on every platform, first-class accessibility, and diagnostics for humans and AI agents alike. Most applications install [`@hozo/core`](https://www.npmjs.com/package/@hozo/core) and one build integration; see [Getting started](https://iray-tno.github.io/hozo/docs/getting-started/). Source and issues: [github.com/iray-tno/hozo](https://github.com/iray-tno/hozo).
161
161
 
162
162
  <!-- /generated: package-footer -->
@@ -0,0 +1,14 @@
1
+ import type { CodeRange } from './model.ts';
2
+ export interface CodeMeta {
3
+ language: string;
4
+ title?: string;
5
+ wrap?: boolean;
6
+ lineNumbers?: boolean | {
7
+ start: number;
8
+ };
9
+ marks: CodeRange[];
10
+ unknown: string[];
11
+ }
12
+ /** Fence metadata is data: unknown syntax is preserved, never executed. */
13
+ export declare function parseCodeMeta(language: string, meta?: string): CodeMeta;
14
+ //# sourceMappingURL=meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/code/meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,YAAY,CAAA;AAErD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,WAAW,CAAC,EAAE,OAAO,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;IACzC,KAAK,EAAE,SAAS,EAAE,CAAA;IAClB,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,QAAQ,CAwDnE"}
@@ -0,0 +1,62 @@
1
+ /** Fence metadata is data: unknown syntax is preserved, never executed. */
2
+ export function parseCodeMeta(language, meta = '') {
3
+ const result = { language, marks: [], unknown: [] };
4
+ const tokens = meta.match(/(?:[^\s"'{}]+|"(?:\\.|[^"\\])*"|'[^']*'|\{[^}]*\})+|\S+/g) ?? [];
5
+ let start;
6
+ for (const token of tokens) {
7
+ if (token === 'wrap') {
8
+ result.wrap = true;
9
+ continue;
10
+ }
11
+ if (token === 'showLineNumbers') {
12
+ result.lineNumbers = true;
13
+ continue;
14
+ }
15
+ if (token.startsWith('title=')) {
16
+ const value = token.slice(6);
17
+ try {
18
+ result.title = value.startsWith('"') ? JSON.parse(value) : value.replace(/^'|'$/g, '');
19
+ }
20
+ catch {
21
+ result.unknown.push(token);
22
+ }
23
+ continue;
24
+ }
25
+ if (/^startLineNumber=\d+$/.test(token)) {
26
+ const value = Number(token.slice(16));
27
+ if (Number.isSafeInteger(value))
28
+ start = value;
29
+ else
30
+ result.unknown.push(token);
31
+ continue;
32
+ }
33
+ const range = /^(?:(ins|del)=)?\{([\d,\s-]+)\}$/.exec(token);
34
+ if (range) {
35
+ const mark = (range[1] ?? 'mark');
36
+ const parsed = [];
37
+ for (const part of range[2].split(',')) {
38
+ const match = /^(\d+)(?:-(\d+))?$/.exec(part.trim());
39
+ const from = Number(match?.[1]), to = Number(match?.[2] ?? match?.[1]);
40
+ if (!match ||
41
+ !Number.isSafeInteger(from) ||
42
+ !Number.isSafeInteger(to) ||
43
+ from < 1 ||
44
+ to < from) {
45
+ parsed.length = 0;
46
+ break;
47
+ }
48
+ parsed.push({ from, to, mark });
49
+ }
50
+ if (parsed.length)
51
+ result.marks.push(...parsed);
52
+ else
53
+ result.unknown.push(token);
54
+ continue;
55
+ }
56
+ result.unknown.push(token);
57
+ }
58
+ if (start !== undefined)
59
+ result.lineNumbers = { start };
60
+ return result;
61
+ }
62
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","sourceRoot":"","sources":["../../src/code/meta.ts"],"names":[],"mappings":"AAWA,2EAA2E;AAC3E,MAAM,U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AAC,CAAA;IAC5B,CAAC;IACD,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,CAAC,WAAW,GAAG,EAAE,KAAK,EAAE,CAAA;IACvD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,66 @@
1
+ export interface CodeToken {
2
+ text: string;
3
+ color?: string | Readonly<Record<string, string>>;
4
+ italic?: boolean;
5
+ bold?: boolean;
6
+ underline?: boolean;
7
+ }
8
+ export type CodeMark = 'ins' | 'del' | 'mark';
9
+ export interface CodeLine {
10
+ tokens: string | readonly CodeToken[];
11
+ mark?: CodeMark;
12
+ }
13
+ export interface CodeRange {
14
+ from: number;
15
+ to: number;
16
+ mark: CodeMark;
17
+ }
18
+ export declare function codeText(lines: readonly CodeLine[] | string): string;
19
+ type NormalizedLine = Omit<CodeLine, 'tokens'> & {
20
+ tokens: CodeToken[];
21
+ };
22
+ /** Tab stops cross token boundaries, so highlighting cannot change indentation. */
23
+ export declare function normalizeCodeLines(lines: readonly CodeLine[] | string, tabSize?: number): NormalizedLine[];
24
+ /**
25
+ * @internal `normalizeCodeLines`, handing back what a line object came out as
26
+ * in `previous` (the map the last call returned, at the same tab size) when it
27
+ * is passed again. A renderer can then tell the lines an edit left alone from
28
+ * the one it changed by identity (#1289); lines are read as immutable, as
29
+ * React reads props.
30
+ */
31
+ export declare function normalizeCodeLinesFrom(lines: readonly CodeLine[] | string, tabSize: number, previous: ReadonlyMap<CodeLine, NormalizedLine[]>): [NormalizedLine[], Map<CodeLine, NormalizedLine[]>];
32
+ /** A token as one theme draws it. */
33
+ export interface DrawnCodeToken {
34
+ text: string;
35
+ color?: string;
36
+ italic?: boolean;
37
+ bold?: boolean;
38
+ underline?: boolean;
39
+ }
40
+ /**
41
+ * The tokens as `theme` draws them, with each run of neighbours that would be
42
+ * drawn the same joined into one, so a Native line nests one `Text` per run
43
+ * rather than per token (#1431). Highlighters split far finer than they
44
+ * colour: punctuation, whitespace and plain identifiers often share a style.
45
+ *
46
+ * Only an unchanged look is joined. Colour, italic, bold and underline must
47
+ * all match, with one exception: whitespace with no underline draws nothing,
48
+ * so its colour is not compared. Its weight and slant still are, since a
49
+ * font's bold or italic space is not always as wide.
50
+ */
51
+ export declare function drawnCodeTokens(tokens: readonly CodeToken[], theme: string): DrawnCodeToken[];
52
+ /**
53
+ * The line that needs the most columns, for a windowed block to hold its
54
+ * scrolling width open with before the line itself is mounted.
55
+ *
56
+ * The text is monospaced, so columns are the width; a wide character (CJK,
57
+ * full-width forms, most emoji) takes two, which is approximated by code
58
+ * point rather than read from Unicode's East Asian Width table.
59
+ */
60
+ export declare function widestCodeLine<T extends Pick<CodeLine, 'tokens'>>(lines: readonly T[]): {
61
+ line: T;
62
+ index: number;
63
+ } | undefined;
64
+ export declare function markCodeLines(lines: readonly CodeLine[] | string, ranges: readonly CodeRange[]): CodeLine[];
65
+ export {};
66
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/code/model.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACjD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAA;AAE7C,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,GAAG,SAAS,SAAS,EAAE,CAAA;IACrC,IAAI,CAAC,EAAE,QAAQ,CAAA;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,QAAQ,CAAA;CACf;AAED,wBAAg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,EAAE,SAAS,SAAS,EAAE,GAC3B,QAAQ,EAAE,CAYZ"}
@@ -0,0 +1,139 @@
1
+ export function codeText(lines) {
2
+ return typeof lines === 'string'
3
+ ? lines
4
+ : lines
5
+ .map((line) => typeof line.tokens === 'string'
6
+ ? line.tokens
7
+ : line.tokens.map((token) => token.text).join(''))
8
+ .join('\n');
9
+ }
10
+ /** Tab stops cross token boundaries, so highlighting cannot change indentation. */
11
+ export function normalizeCodeLines(lines, tabSize = 2) {
12
+ return normalizeCodeLinesFrom(lines, tabSize, new Map())[0];
13
+ }
14
+ /**
15
+ * @internal `normalizeCodeLines`, handing back what a line object came out as
16
+ * in `previous` (the map the last call returned, at the same tab size) when it
17
+ * is passed again. A renderer can then tell the lines an edit left alone from
18
+ * the one it changed by identity (#1289); lines are read as immutable, as
19
+ * React reads props.
20
+ */
21
+ export function normalizeCodeLinesFrom(lines, tabSize, previous) {
22
+ if (!Number.isSafeInteger(tabSize) || tabSize < 1)
23
+ throw new RangeError('tabSize must be a positive safe integer');
24
+ const next = new Map();
25
+ if (typeof lines === 'string')
26
+ return [
27
+ lines
28
+ .replace(/\r\n?/g, '\n')
29
+ .split('\n')
30
+ .flatMap((tokens) => normalizeLine({ tokens }, tabSize)),
31
+ next,
32
+ ];
33
+ const result = lines.flatMap((line) => {
34
+ const normalized = next.get(line) ?? previous.get(line) ?? normalizeLine(line, tabSize);
35
+ next.set(line, normalized);
36
+ return normalized;
37
+ });
38
+ return [result, next];
39
+ }
40
+ function normalizeLine(line, tabSize) {
41
+ const parts = typeof line.tokens === 'string' ? [{ text: line.tokens }] : line.tokens;
42
+ const result = [];
43
+ let tokens = [];
44
+ let column = 0;
45
+ for (const token of parts) {
46
+ const pieces = token.text.replace(/\r\n?/g, '\n').split('\n');
47
+ pieces.forEach((piece, index) => {
48
+ if (index > 0) {
49
+ result.push({ tokens, mark: line.mark });
50
+ tokens = [];
51
+ column = 0;
52
+ }
53
+ let text = '';
54
+ for (const character of piece) {
55
+ const expanded = character === '\t' ? ' '.repeat(tabSize - (column % tabSize)) : character;
56
+ text += expanded;
57
+ column += expanded.length;
58
+ }
59
+ tokens.push({ ...token, text });
60
+ });
61
+ }
62
+ result.push({ tokens, mark: line.mark });
63
+ return result;
64
+ }
65
+ /**
66
+ * The tokens as `theme` draws them, with each run of neighbours that would be
67
+ * drawn the same joined into one, so a Native line nests one `Text` per run
68
+ * rather than per token (#1431). Highlighters split far finer than they
69
+ * colour: punctuation, whitespace and plain identifiers often share a style.
70
+ *
71
+ * Only an unchanged look is joined. Colour, italic, bold and underline must
72
+ * all match, with one exception: whitespace with no underline draws nothing,
73
+ * so its colour is not compared. Its weight and slant still are, since a
74
+ * font's bold or italic space is not always as wide.
75
+ */
76
+ export function drawnCodeTokens(tokens, theme) {
77
+ const result = [];
78
+ for (const token of tokens) {
79
+ if (!token.text)
80
+ continue;
81
+ const drawn = {
82
+ text: token.text,
83
+ color: typeof token.color === 'string'
84
+ ? token.color
85
+ : (token.color?.[theme] ?? token.color?.light),
86
+ italic: token.italic || undefined,
87
+ bold: token.bold || undefined,
88
+ underline: token.underline || undefined,
89
+ };
90
+ const last = result.at(-1);
91
+ if (last &&
92
+ last.italic === drawn.italic &&
93
+ last.bold === drawn.bold &&
94
+ last.underline === drawn.underline &&
95
+ (last.color === drawn.color || (!drawn.underline && (blank(last.text) || blank(drawn.text))))) {
96
+ if (blank(last.text))
97
+ last.color = drawn.color;
98
+ last.text += drawn.text;
99
+ }
100
+ else
101
+ result.push(drawn);
102
+ }
103
+ return result;
104
+ }
105
+ const blank = (text) => /^\s+$/.test(text);
106
+ /**
107
+ * The line that needs the most columns, for a windowed block to hold its
108
+ * scrolling width open with before the line itself is mounted.
109
+ *
110
+ * The text is monospaced, so columns are the width; a wide character (CJK,
111
+ * full-width forms, most emoji) takes two, which is approximated by code
112
+ * point rather than read from Unicode's East Asian Width table.
113
+ */
114
+ export function widestCodeLine(lines) {
115
+ let widest;
116
+ lines.forEach((line, index) => {
117
+ let columns = 0;
118
+ const tokens = typeof line.tokens === 'string' ? [{ text: line.tokens }] : line.tokens;
119
+ for (const token of tokens)
120
+ for (const char of token.text)
121
+ columns += (char.codePointAt(0) ?? 0) >= 0x2e80 ? 2 : 1;
122
+ if (!widest || columns > widest.columns)
123
+ widest = { line, index, columns };
124
+ });
125
+ return widest;
126
+ }
127
+ export function markCodeLines(lines, ranges) {
128
+ const normalized = typeof lines === 'string'
129
+ ? lines
130
+ .replace(/\r\n?/g, '\n')
131
+ .split('\n')
132
+ .map((tokens) => ({ tokens }))
133
+ : lines;
134
+ return normalized.map((line, index) => {
135
+ const mark = ranges.findLast((range) => range.from <= index + 1 && range.to >= index + 1)?.mark;
136
+ return mark ? { ...line, mark } : { ...line };
137
+ });
138
+ }
139
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/code/model.ts"],"names":[],"mappings":"AAqBA,MAAM,UAAU,QAAQ,CAAC,KAAmC;IAC1D,OAAO,OAAO,KAAK,KAAK,QAAQ;QAC9B,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,KAAK;aACF,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;YAC7B,CAAC,CAAC,IAAI,CAAC,MAAM;YACb,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CACpD;aACA,IAAI,CAAC,IAAI,CAAC,CAAA;AACnB,CAAC;AAID,mFAAmF;AACnF,MAAM,UAAU,kBAAkB,CAChC,KAAmC,EACnC,OAAO,GAAG,CAAC;IAEX,OAAO,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,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,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,IAAI,CAAA;QAC/F,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type CodeLine, normalizeCodeLinesFrom } from './model.ts';
3
+ type NormalizedCodeLine = ReturnType<typeof normalizeCodeLinesFrom>[0][number];
4
+ /**
5
+ * @internal `normalizeCodeLines`, keeping a line's normalized objects from the
6
+ * last render while the same line object is passed.
7
+ */
8
+ export declare function useNormalizedCodeLines(lines: readonly CodeLine[] | string, tabSize?: number): NormalizedCodeLine[];
9
+ /**
10
+ * @internal Rows already drawn, by line object. A line an edit left alone
11
+ * comes back from `useNormalizedCodeLines` as the same object, and is handed
12
+ * back here as the same element, which React skips; without this, changing
13
+ * one line re-rendered every mounted one (#1289). A `FlatList` asks for rows
14
+ * after the render too, so the map outlives it, holding only the current
15
+ * lines. `key` is everything else a row is drawn from; `undefined` reuses
16
+ * nothing.
17
+ */
18
+ export declare function useCodeRows<Line extends object>(lines: readonly Line[], key: string | undefined, draw: (line: Line, index: number) => ReactNode): (line: Line, index: number) => ReactNode;
19
+ /** @internal JSON for a row key, or `undefined` for a value it cannot write out. */
20
+ export declare function codeKey(value: unknown): string | undefined;
21
+ export {};
22
+ //# sourceMappingURL=reuse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reuse.d.ts","sourceRoot":"","sources":["../../src/code/reuse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAA;AAC9C,OAAO,EAAE,KAAK,QAAQ,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAElE,KAAK,kBAAkB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAE9E;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,EACnC,OAAO,SAAI,GACV,kBAAkB,EAAE,CAWtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,MAAM,EAC7C,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,GAC7C,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAsB1C;AAED,oFAAoF;AACpF,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAM1D"}
@@ -0,0 +1,54 @@
1
+ import { useRef } from 'react';
2
+ import { normalizeCodeLinesFrom } from './model.js';
3
+ /**
4
+ * @internal `normalizeCodeLines`, keeping a line's normalized objects from the
5
+ * last render while the same line object is passed.
6
+ */
7
+ export function useNormalizedCodeLines(lines, tabSize = 2) {
8
+ const last = useRef(undefined);
9
+ const [result, byLine] = normalizeCodeLinesFrom(lines, tabSize, last.current?.tabSize === tabSize ? last.current.byLine : new Map());
10
+ last.current = { tabSize, byLine };
11
+ return result;
12
+ }
13
+ /**
14
+ * @internal Rows already drawn, by line object. A line an edit left alone
15
+ * comes back from `useNormalizedCodeLines` as the same object, and is handed
16
+ * back here as the same element, which React skips; without this, changing
17
+ * one line re-rendered every mounted one (#1289). A `FlatList` asks for rows
18
+ * after the render too, so the map outlives it, holding only the current
19
+ * lines. `key` is everything else a row is drawn from; `undefined` reuses
20
+ * nothing.
21
+ */
22
+ export function useCodeRows(lines, key, draw) {
23
+ const drawn = useRef({ rows: new Map() });
24
+ if (drawn.current.lines !== lines) {
25
+ const rows = new Map();
26
+ for (const line of lines) {
27
+ const hit = drawn.current.rows.get(line);
28
+ if (hit)
29
+ rows.set(line, hit);
30
+ }
31
+ drawn.current = { lines, rows };
32
+ }
33
+ const { rows } = drawn.current;
34
+ return (line, index) => {
35
+ if (key === undefined)
36
+ return draw(line, index);
37
+ const hit = rows.get(line);
38
+ if (hit && hit.index === index && hit.key === key)
39
+ return hit.row;
40
+ const row = draw(line, index);
41
+ rows.set(line, { index, key, row });
42
+ return row;
43
+ };
44
+ }
45
+ /** @internal JSON for a row key, or `undefined` for a value it cannot write out. */
46
+ export function codeKey(value) {
47
+ try {
48
+ return JSON.stringify(value);
49
+ }
50
+ catch {
51
+ return undefined;
52
+ }
53
+ }
54
+ //# sourceMappingURL=reuse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reuse.js","sourceRoot":"","sources":["../../src/code/reuse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,EAAiB,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAIlE;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAmC,EACnC,OAAO,GAAG,CAAC;IAEX,MAAM,IAAI,GAAG,MAAM,CACjB,SAAS,CACV,CAAA;IACD,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,sBAAsB,CAC7C,KAAK,EACL,OAAO,EACP,IAAI,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CACpE,CAAA;IACD,IAAI,CAAC,OAAO,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACzB,KAAsB,EACtB,GAAuB,EACvB,IAA8C;IAE9C,MAAM,KAAK,GAAG,MAAM,CAGj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AC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { CodeLine } from './model.ts';
2
+ export interface ShikiTokenLike {
3
+ content: string;
4
+ color?: string;
5
+ fontStyle?: number;
6
+ htmlStyle?: Readonly<Record<string, string>>;
7
+ }
8
+ /** Maps output theme slots to Shiki's htmlStyle suffixes (for example dark -> dark). */
9
+ export declare function fromShiki(lines: readonly (readonly ShikiTokenLike[])[], options?: {
10
+ themes?: Readonly<Record<string, string>>;
11
+ }): CodeLine[];
12
+ //# sourceMappingURL=shiki.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shiki.d.ts","sourceRoot":"","sources":["../../src/code/shiki.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAa,MAAM,YAAY,CAAA;AAErD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAC7C;AAED,wFAAwF;AACxF,wBAAgB,SAAS,CACvB,KAAK,EAAE,SAAS,CAAC,SAAS,cAAc,EAAE,CAAC,EAAE,EAC7C,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,GACtD,QAAQ,EAAE,CAwBZ"}
@@ -0,0 +1,28 @@
1
+ /** Maps output theme slots to Shiki's htmlStyle suffixes (for example dark -> dark). */
2
+ export function fromShiki(lines, options) {
3
+ return lines.map((line) => ({
4
+ tokens: line.map((token) => {
5
+ let color = token.color ?? token.htmlStyle?.color;
6
+ if (options?.themes) {
7
+ const colors = {};
8
+ for (const [slot, key] of Object.entries(options.themes)) {
9
+ const value = token.htmlStyle?.[key.startsWith('--') ? key : `--shiki-${key}`] ??
10
+ (slot === 'light' ? (token.color ?? token.htmlStyle?.color) : undefined);
11
+ if (value)
12
+ colors[slot] = value;
13
+ }
14
+ if (Object.keys(colors).length)
15
+ color = colors;
16
+ }
17
+ const flags = token.fontStyle !== undefined && token.fontStyle > 0 ? token.fontStyle : 0;
18
+ return {
19
+ text: token.content,
20
+ ...(color ? { color } : {}),
21
+ ...(flags & 1 ? { italic: true } : {}),
22
+ ...(flags & 2 ? { bold: true } : {}),
23
+ ...(flags & 4 ? { underline: true } : {}),
24
+ };
25
+ }),
26
+ }));
27
+ }
28
+ //# sourceMappingURL=shiki.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shiki.js","sourceRoot":"","sources":["../../src/code/shiki.ts"],"names":[],"mappings":"AASA,wFAAwF;AACxF,MAAM,UAAU,SAAS,CACvB,KAA6C,EAC7C,OAAuD;IAEvD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAa,EAAE;YACpC,IAAI,KAAK,GAAuB,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,EAAE,KAAK,CAAA;YACrE,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;gBACpB,MAAM,MAAM,GAA2B,EAAE,CAAA;gBACzC,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;oBACzD,MAAM,KAAK,GACT,KAAK,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,GAAG,EAAE,CAAC;wBAChE,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;oBAC1E,IAAI,KAAK;wBAAE,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;gBACjC,CAAC;gBACD,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM;oBAAE,KAAK,GAAG,MAAM,CAAA;YAChD,CAAC;YACD,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,KAAK,SAAS,IAAI,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;YACxF,OAAO;gBACL,IAAI,EAAE,KAAK,CAAC,OAAO;gBACnB,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3B,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC1C,CAAA;QACH,CAAC,CAAC;KACH,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { type CSSProperties, type ReactNode, type RefObject } from 'react';
2
+ import { type CodeLine } from './code/model.ts';
3
+ import { codeKey, useNormalizedCodeLines } from './code/reuse.ts';
4
+ export { codeKey, useNormalizedCodeLines };
5
+ export interface CodeLinesProps {
6
+ lines: readonly CodeLine[] | string;
7
+ tabSize?: number;
8
+ theme?: string;
9
+ wrap?: boolean;
10
+ className?: string;
11
+ lineClassName?: string;
12
+ insClassName?: string;
13
+ delClassName?: string;
14
+ markClassName?: string;
15
+ style?: CSSProperties;
16
+ lineStyle?: CSSProperties;
17
+ insStyle?: CSSProperties;
18
+ delStyle?: CSSProperties;
19
+ markStyle?: CSSProperties;
20
+ /** @internal A separate, non-selectable gutter supplied by CodeBlock. */
21
+ renderGutter?: (line: CodeLine, index: number) => ReactNode;
22
+ /**
23
+ * @internal Everything `renderGutter` draws from besides the line and its
24
+ * index, as `codeKey` gives it. Without it, a gutter's rows are not reused.
25
+ */
26
+ gutterKey?: string;
27
+ /**
28
+ * @internal The element the lines scroll in. Given, only the lines near
29
+ * the visible ones are mounted; CodeBlock decides when (#1380).
30
+ */
31
+ scroller?: RefObject<HTMLElement | null>;
32
+ }
33
+ export declare function CodeLines(props: CodeLinesProps): import("react").JSX.Element;
34
+ //# sourceMappingURL=code-lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-lines.d.ts","sourceRoot":"","sources":["../src/code-lines.tsx"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,SAAS,EAMf,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,KAAK,QAAQ,EAAiD,MAAM,iBAAiB,CAAA;AAC9F,OAAO,EAAE,OAAO,EAAe,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAE9E,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAA;AAE1C,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,QAAQ,EAAE,GAAG,MAAM,CAAA;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,CA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