@tuidom/core 0.9.0 → 0.9.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.
@@ -1,5 +1,5 @@
1
+ import { segmentGraphemes } from "./segmentGraphemes.js";
1
2
  import { getCharDisplayWidth, getGraphemeDisplayWidth } from "./unicodeWidth.js";
2
- const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
3
3
  const DEFAULT_TAB_SIZE = 4;
4
4
  /**
5
5
  * Maps a raw document string to an array of grapheme slots with correct
@@ -34,7 +34,7 @@ export class DisplayLine {
34
34
  // отброшенной графемы (сегменты непрерывны, поэтому это ровно граница).
35
35
  let scannedLength = raw.length;
36
36
  let truncated = false;
37
- for (const { segment, index } of segmenter.segment(raw)) {
37
+ for (const { segment, index } of segmentGraphemes(raw)) {
38
38
  if (index >= stopAfter) {
39
39
  truncated = true;
40
40
  scannedLength = index;
@@ -1,5 +1,5 @@
1
+ import { segmentGraphemes } from "./segmentGraphemes.js";
1
2
  import { getCharDisplayWidth, getGraphemeDisplayWidth } from "./unicodeWidth.js";
2
- const segmenter = new Intl.Segmenter("en", { granularity: "grapheme" });
3
3
  const DEFAULT_TAB_SIZE = 4;
4
4
  /**
5
5
  * Display width of `raw` in terminal columns.
@@ -23,7 +23,7 @@ const DEFAULT_TAB_SIZE = 4;
23
23
  */
24
24
  export function measureTextWidth(raw, tabSize = DEFAULT_TAB_SIZE, stopAfter = Infinity) {
25
25
  let column = 0;
26
- for (const { segment, index } of segmenter.segment(raw)) {
26
+ for (const { segment, index } of segmentGraphemes(raw)) {
27
27
  if (index >= stopAfter)
28
28
  break;
29
29
  if (segment === "\t") {
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Grapheme segmentation of `raw` (lazy iterator, as `Intl.Segmenter.segment`).
3
+ *
4
+ * The segmenter is created on first call, not at module load: a native `Intl`
5
+ * object held by a module-level binding cannot be serialized into a V8 startup
6
+ * snapshot, and hosts build one from the whole engine graph
7
+ * (`npm run check:snapshot`). The extra cost on the hot path is one null check.
8
+ */
9
+ export declare function segmentGraphemes(raw: string): Intl.Segments;
@@ -0,0 +1,13 @@
1
+ let segmenter = null;
2
+ /**
3
+ * Grapheme segmentation of `raw` (lazy iterator, as `Intl.Segmenter.segment`).
4
+ *
5
+ * The segmenter is created on first call, not at module load: a native `Intl`
6
+ * object held by a module-level binding cannot be serialized into a V8 startup
7
+ * snapshot, and hosts build one from the whole engine graph
8
+ * (`npm run check:snapshot`). The extra cost on the hot path is one null check.
9
+ */
10
+ export function segmentGraphemes(raw) {
11
+ segmenter ??= new Intl.Segmenter("en", { granularity: "grapheme" });
12
+ return segmenter.segment(raw);
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuidom/core",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "type": "module",
5
5
  "description": "Experimental terminal UI DOM — core: element tree, flex layout, grid rendering, input parsing. API is unstable.",
6
6
  "license": "MIT",