@zzclub/pipeline 0.2.0 → 0.4.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 +366 -170
- package/package.json +4 -7
- package/src/adapter-loader.ts +138 -0
- package/src/adapter-types.ts +172 -0
- package/src/adapters/builtin-image-renderer.ts +353 -0
- package/src/adapters/builtin-markdown-renderer.ts +63 -0
- package/src/adapters/index.ts +2 -0
- package/src/args.test.ts +118 -0
- package/src/args.ts +90 -0
- package/src/cli.ts +51 -0
- package/src/commands/abandon.test.ts +104 -0
- package/src/commands/abandon.ts +202 -0
- package/src/commands/attach-body-images.ts +88 -0
- package/src/commands/attach-body.ts +86 -0
- package/src/commands/attach-newspic-spec.ts +41 -0
- package/src/commands/checkpoint.test.ts +91 -0
- package/src/commands/checkpoint.ts +66 -0
- package/src/commands/config.ts +106 -0
- package/src/commands/cos-upload.ts +62 -0
- package/src/commands/doctor.ts +66 -0
- package/src/commands/find-run.ts +55 -0
- package/src/commands/hermes-metrics.ts +226 -0
- package/src/commands/imgx.ts +60 -0
- package/src/commands/ingest-handoff.ts +509 -0
- package/src/commands/init.ts +126 -0
- package/src/commands/prepare-finalize.ts +348 -0
- package/src/commands/prepare.ts +310 -0
- package/src/commands/publish.ts +147 -0
- package/src/commands/reconcile.ts +36 -0
- package/src/commands/render.ts +244 -0
- package/src/commands/reset.test.ts +151 -0
- package/src/commands/reset.ts +159 -0
- package/src/commands/review.ts +77 -0
- package/src/commands/status.ts +68 -0
- package/src/commands/sync-blog.ts +39 -0
- package/src/commands/tasks.ts +50 -0
- package/src/commands/wechat-export.ts +68 -0
- package/src/config.ts +0 -0
- package/src/imgx/ascii-portrait.ts +77 -0
- package/src/imgx/assets/fonts/AlimamaShuHeiTi-Bold.ttf +0 -0
- package/src/imgx/assets/fonts/LXGWNeoZhiSongPlus.ttf +0 -0
- package/src/imgx/assets/fonts/LXGWWenKai-Regular.ttf +0 -0
- package/src/imgx/assets/icons/logo.png +0 -0
- package/src/imgx/assets/icons/logo.svg +8 -0
- package/{dist/assets → src}/imgx/assets/templates/longform-3-4.html +1 -1
- package/{dist/assets → src}/imgx/assets/templates/poster-3-4.html +69 -30
- package/{dist/assets → src}/imgx/assets/templates/wechat-cover-split.html +58 -27
- package/src/imgx/cli.ts +57 -0
- package/src/imgx/geometry.ts +68 -0
- package/src/imgx/index.ts +5 -0
- package/src/imgx/longform-theme.ts +243 -0
- package/src/imgx/poster-recipe.ts +81 -0
- package/src/imgx/pretext-adapter.ts +14 -0
- package/src/imgx/pretext-runtime.ts +61 -0
- package/src/imgx/references/ascii-portrait-3-4.md +59 -0
- package/src/imgx/references/longform-3-4.md +173 -0
- package/src/imgx/references/poster-3-4.md +87 -0
- package/src/imgx/references/tips-3-4.md +69 -0
- package/src/imgx/references/wechat-cover-split.md +89 -0
- package/src/imgx/references/x-like-posts.md +139 -0
- package/src/imgx/render-article.test.ts +53 -0
- package/src/imgx/render-article.ts +1364 -0
- package/src/imgx/render-ascii-portrait.ts +53 -0
- package/src/imgx/render-card.ts +232 -0
- package/src/imgx/render-x-like-posts.ts +235 -0
- package/src/imgx/runtime.ts +403 -0
- package/src/imgx/typographic-scale.test.ts +56 -0
- package/src/imgx/typographic-scale.ts +44 -0
- package/src/output.ts +632 -0
- package/src/plugins.ts +101 -0
- package/src/profiles.ts +149 -0
- package/src/providers/blog.test.ts +58 -0
- package/src/providers/blog.ts +154 -0
- package/src/providers/cos.ts +183 -0
- package/src/providers/index.test.ts +26 -0
- package/src/providers/index.ts +185 -0
- package/src/providers/wechat.test.ts +215 -0
- package/src/providers/wechat.ts +548 -0
- package/src/routes.ts +287 -0
- package/src/runtime-paths.ts +179 -0
- package/src/schema/config.ts +133 -0
- package/src/schema/state.ts +376 -0
- package/src/spawn.ts +103 -0
- package/src/state.ts +265 -0
- package/src/task-manager.ts +657 -0
- package/src/task-views.ts +222 -0
- package/src/text.test.ts +689 -0
- package/src/text.ts +683 -0
- package/src/wechat-preview/assets/fonts/SweiCurveLegCJKsc-Regular.woff +0 -0
- package/src/wechat-preview/browser/editor-export.css +241 -0
- package/src/wechat-preview/browser/editor-export.ts +103 -0
- package/src/wechat-preview/frontmatter-handler.ts +73 -0
- package/src/wechat-preview/index.test.ts +154 -0
- package/src/wechat-preview/index.ts +294 -0
- package/src/wechat-preview/themes.ts +141 -0
- package/src/wechat-preview/wechat-formatter.test.ts +288 -0
- package/src/wechat-preview/wechat-formatter.ts +1506 -0
- package/src/wechat-preview.test.ts +73 -0
- package/src/workflow-materials.test.ts +225 -0
- package/src/workflow-materials.ts +217 -0
- package/src/workflow.test.ts +2087 -0
- package/dist/assets/imgx/assets/icons/avatar_jinx_cartoon.jpg +0 -0
- package/dist/assets/imgx/assets/icons/fishbone-logo-square.png +0 -0
- package/dist/assets/imgx/assets/icons/fishbone-logo.jpg +0 -0
- package/dist/assets/imgx/assets/icons/fishbone-logo.png +0 -0
- package/dist/assets/imgx/assets/icons/openclaw-logo.svg +0 -22
- package/dist/assets/imgx/assets/icons/zzclub-logo-black.jpg +0 -0
- package/dist/assets/imgx/assets/icons/zzclub-logo-gray.svg +0 -25
- package/dist/cli.js +0 -432
- package/dist/node_modules/@chenglou/pretext/dist/analysis.d.ts +0 -33
- package/dist/node_modules/@chenglou/pretext/dist/analysis.js +0 -1063
- package/dist/node_modules/@chenglou/pretext/dist/bidi.d.ts +0 -1
- package/dist/node_modules/@chenglou/pretext/dist/bidi.js +0 -175
- package/dist/node_modules/@chenglou/pretext/dist/generated/bidi-data.d.ts +0 -4
- package/dist/node_modules/@chenglou/pretext/dist/generated/bidi-data.js +0 -979
- package/dist/node_modules/@chenglou/pretext/dist/layout.d.ts +0 -70
- package/dist/node_modules/@chenglou/pretext/dist/layout.js +0 -496
- package/dist/node_modules/@chenglou/pretext/dist/line-break.d.ts +0 -36
- package/dist/node_modules/@chenglou/pretext/dist/line-break.js +0 -820
- package/dist/node_modules/@chenglou/pretext/dist/measurement.d.ts +0 -28
- package/dist/node_modules/@chenglou/pretext/dist/measurement.js +0 -219
- package/dist/node_modules/@chenglou/pretext/dist/rich-inline.d.ts +0 -51
- package/dist/node_modules/@chenglou/pretext/dist/rich-inline.js +0 -401
- /package/{dist/assets → src}/imgx/assets/browser/obstacle-flow.d.ts +0 -0
- /package/{dist/assets → src}/imgx/assets/browser/obstacle-flow.js +0 -0
- /package/{dist/assets → src}/imgx/assets/icons/clover.svg +0 -0
- /package/{dist/assets → src}/imgx/assets/templates/ascii-portrait-3-4.html +0 -0
- /package/{dist/assets → src}/imgx/assets/templates/ascii-portrait-tile.html +0 -0
- /package/{dist/assets → src}/imgx/assets/templates/tips-3-4.html +0 -0
- /package/{dist/assets → src}/imgx/assets/templates/x-like-posts.html +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/.vite/manifest.json +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/SweiCurveLegCJKsc-Regular-B3Ut5bwH.woff +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/assets/style-BYNXnUvc.css +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/browser-dist/editor-export.js +0 -0
- /package/{dist/assets → src}/wechat-preview/assets/templates/export-shell.html +0 -0
|
@@ -1,820 +0,0 @@
|
|
|
1
|
-
import { getEngineProfile } from './measurement.js';
|
|
2
|
-
function normalizeSimpleLineStartSegmentIndex(prepared, segmentIndex) {
|
|
3
|
-
while (segmentIndex < prepared.widths.length) {
|
|
4
|
-
const kind = prepared.kinds[segmentIndex];
|
|
5
|
-
if (kind !== 'space' && kind !== 'zero-width-break' && kind !== 'soft-hyphen')
|
|
6
|
-
break;
|
|
7
|
-
segmentIndex++;
|
|
8
|
-
}
|
|
9
|
-
return segmentIndex;
|
|
10
|
-
}
|
|
11
|
-
function getTabAdvance(lineWidth, tabStopAdvance) {
|
|
12
|
-
if (tabStopAdvance <= 0)
|
|
13
|
-
return 0;
|
|
14
|
-
const remainder = lineWidth % tabStopAdvance;
|
|
15
|
-
if (Math.abs(remainder) <= 1e-6)
|
|
16
|
-
return tabStopAdvance;
|
|
17
|
-
return tabStopAdvance - remainder;
|
|
18
|
-
}
|
|
19
|
-
function fitSoftHyphenBreak(graphemeFitAdvances, initialWidth, maxWidth, lineFitEpsilon, discretionaryHyphenWidth) {
|
|
20
|
-
let fitCount = 0;
|
|
21
|
-
let fittedWidth = initialWidth;
|
|
22
|
-
while (fitCount < graphemeFitAdvances.length) {
|
|
23
|
-
const nextWidth = fittedWidth + graphemeFitAdvances[fitCount];
|
|
24
|
-
const nextLineWidth = fitCount + 1 < graphemeFitAdvances.length
|
|
25
|
-
? nextWidth + discretionaryHyphenWidth
|
|
26
|
-
: nextWidth;
|
|
27
|
-
if (nextLineWidth > maxWidth + lineFitEpsilon)
|
|
28
|
-
break;
|
|
29
|
-
fittedWidth = nextWidth;
|
|
30
|
-
fitCount++;
|
|
31
|
-
}
|
|
32
|
-
return { fitCount, fittedWidth };
|
|
33
|
-
}
|
|
34
|
-
function findChunkIndexForStart(prepared, segmentIndex) {
|
|
35
|
-
let lo = 0;
|
|
36
|
-
let hi = prepared.chunks.length;
|
|
37
|
-
while (lo < hi) {
|
|
38
|
-
const mid = Math.floor((lo + hi) / 2);
|
|
39
|
-
if (segmentIndex < prepared.chunks[mid].consumedEndSegmentIndex) {
|
|
40
|
-
hi = mid;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
lo = mid + 1;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return lo < prepared.chunks.length ? lo : -1;
|
|
47
|
-
}
|
|
48
|
-
function normalizeLineStartInChunk(prepared, chunkIndex, cursor) {
|
|
49
|
-
let segmentIndex = cursor.segmentIndex;
|
|
50
|
-
if (cursor.graphemeIndex > 0)
|
|
51
|
-
return chunkIndex;
|
|
52
|
-
const chunk = prepared.chunks[chunkIndex];
|
|
53
|
-
if (chunk.startSegmentIndex === chunk.endSegmentIndex && segmentIndex === chunk.startSegmentIndex) {
|
|
54
|
-
cursor.segmentIndex = segmentIndex;
|
|
55
|
-
cursor.graphemeIndex = 0;
|
|
56
|
-
return chunkIndex;
|
|
57
|
-
}
|
|
58
|
-
if (segmentIndex < chunk.startSegmentIndex)
|
|
59
|
-
segmentIndex = chunk.startSegmentIndex;
|
|
60
|
-
while (segmentIndex < chunk.endSegmentIndex) {
|
|
61
|
-
const kind = prepared.kinds[segmentIndex];
|
|
62
|
-
if (kind !== 'space' && kind !== 'zero-width-break' && kind !== 'soft-hyphen') {
|
|
63
|
-
cursor.segmentIndex = segmentIndex;
|
|
64
|
-
cursor.graphemeIndex = 0;
|
|
65
|
-
return chunkIndex;
|
|
66
|
-
}
|
|
67
|
-
segmentIndex++;
|
|
68
|
-
}
|
|
69
|
-
if (chunk.consumedEndSegmentIndex >= prepared.widths.length)
|
|
70
|
-
return -1;
|
|
71
|
-
cursor.segmentIndex = chunk.consumedEndSegmentIndex;
|
|
72
|
-
cursor.graphemeIndex = 0;
|
|
73
|
-
return chunkIndex + 1;
|
|
74
|
-
}
|
|
75
|
-
function normalizeLineStartChunkIndex(prepared, cursor) {
|
|
76
|
-
if (cursor.segmentIndex >= prepared.widths.length)
|
|
77
|
-
return -1;
|
|
78
|
-
const chunkIndex = findChunkIndexForStart(prepared, cursor.segmentIndex);
|
|
79
|
-
if (chunkIndex < 0)
|
|
80
|
-
return -1;
|
|
81
|
-
return normalizeLineStartInChunk(prepared, chunkIndex, cursor);
|
|
82
|
-
}
|
|
83
|
-
function normalizeLineStartChunkIndexFromHint(prepared, chunkIndex, cursor) {
|
|
84
|
-
if (cursor.segmentIndex >= prepared.widths.length)
|
|
85
|
-
return -1;
|
|
86
|
-
let nextChunkIndex = chunkIndex;
|
|
87
|
-
while (nextChunkIndex < prepared.chunks.length &&
|
|
88
|
-
cursor.segmentIndex >= prepared.chunks[nextChunkIndex].consumedEndSegmentIndex) {
|
|
89
|
-
nextChunkIndex++;
|
|
90
|
-
}
|
|
91
|
-
if (nextChunkIndex >= prepared.chunks.length)
|
|
92
|
-
return -1;
|
|
93
|
-
return normalizeLineStartInChunk(prepared, nextChunkIndex, cursor);
|
|
94
|
-
}
|
|
95
|
-
export function normalizeLineStart(prepared, start) {
|
|
96
|
-
const cursor = {
|
|
97
|
-
segmentIndex: start.segmentIndex,
|
|
98
|
-
graphemeIndex: start.graphemeIndex,
|
|
99
|
-
};
|
|
100
|
-
const chunkIndex = normalizeLineStartChunkIndex(prepared, cursor);
|
|
101
|
-
return chunkIndex < 0 ? null : cursor;
|
|
102
|
-
}
|
|
103
|
-
export function countPreparedLines(prepared, maxWidth) {
|
|
104
|
-
if (prepared.simpleLineWalkFastPath) {
|
|
105
|
-
return walkPreparedLinesSimple(prepared, maxWidth);
|
|
106
|
-
}
|
|
107
|
-
return walkPreparedLines(prepared, maxWidth);
|
|
108
|
-
}
|
|
109
|
-
function walkPreparedLinesSimple(prepared, maxWidth, onLine) {
|
|
110
|
-
const { widths, kinds, breakableFitAdvances } = prepared;
|
|
111
|
-
if (widths.length === 0)
|
|
112
|
-
return 0;
|
|
113
|
-
const engineProfile = getEngineProfile();
|
|
114
|
-
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
115
|
-
const fitLimit = maxWidth + lineFitEpsilon;
|
|
116
|
-
let lineCount = 0;
|
|
117
|
-
let lineW = 0;
|
|
118
|
-
let hasContent = false;
|
|
119
|
-
let lineStartSegmentIndex = 0;
|
|
120
|
-
let lineStartGraphemeIndex = 0;
|
|
121
|
-
let lineEndSegmentIndex = 0;
|
|
122
|
-
let lineEndGraphemeIndex = 0;
|
|
123
|
-
let pendingBreakSegmentIndex = -1;
|
|
124
|
-
let pendingBreakPaintWidth = 0;
|
|
125
|
-
function clearPendingBreak() {
|
|
126
|
-
pendingBreakSegmentIndex = -1;
|
|
127
|
-
pendingBreakPaintWidth = 0;
|
|
128
|
-
}
|
|
129
|
-
function emitCurrentLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width = lineW) {
|
|
130
|
-
lineCount++;
|
|
131
|
-
onLine?.({
|
|
132
|
-
startSegmentIndex: lineStartSegmentIndex,
|
|
133
|
-
startGraphemeIndex: lineStartGraphemeIndex,
|
|
134
|
-
endSegmentIndex,
|
|
135
|
-
endGraphemeIndex,
|
|
136
|
-
width,
|
|
137
|
-
});
|
|
138
|
-
lineW = 0;
|
|
139
|
-
hasContent = false;
|
|
140
|
-
clearPendingBreak();
|
|
141
|
-
}
|
|
142
|
-
function startLineAtSegment(segmentIndex, width) {
|
|
143
|
-
hasContent = true;
|
|
144
|
-
lineStartSegmentIndex = segmentIndex;
|
|
145
|
-
lineStartGraphemeIndex = 0;
|
|
146
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
147
|
-
lineEndGraphemeIndex = 0;
|
|
148
|
-
lineW = width;
|
|
149
|
-
}
|
|
150
|
-
function startLineAtGrapheme(segmentIndex, graphemeIndex, width) {
|
|
151
|
-
hasContent = true;
|
|
152
|
-
lineStartSegmentIndex = segmentIndex;
|
|
153
|
-
lineStartGraphemeIndex = graphemeIndex;
|
|
154
|
-
lineEndSegmentIndex = segmentIndex;
|
|
155
|
-
lineEndGraphemeIndex = graphemeIndex + 1;
|
|
156
|
-
lineW = width;
|
|
157
|
-
}
|
|
158
|
-
function appendWholeSegment(segmentIndex, width) {
|
|
159
|
-
if (!hasContent) {
|
|
160
|
-
startLineAtSegment(segmentIndex, width);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
lineW += width;
|
|
164
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
165
|
-
lineEndGraphemeIndex = 0;
|
|
166
|
-
}
|
|
167
|
-
function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
|
|
168
|
-
const fitAdvances = breakableFitAdvances[segmentIndex];
|
|
169
|
-
for (let g = startGraphemeIndex; g < fitAdvances.length; g++) {
|
|
170
|
-
const gw = fitAdvances[g];
|
|
171
|
-
if (!hasContent) {
|
|
172
|
-
startLineAtGrapheme(segmentIndex, g, gw);
|
|
173
|
-
}
|
|
174
|
-
else if (lineW + gw > fitLimit) {
|
|
175
|
-
emitCurrentLine();
|
|
176
|
-
startLineAtGrapheme(segmentIndex, g, gw);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
lineW += gw;
|
|
180
|
-
lineEndSegmentIndex = segmentIndex;
|
|
181
|
-
lineEndGraphemeIndex = g + 1;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
|
|
185
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
186
|
-
lineEndGraphemeIndex = 0;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
let i = 0;
|
|
190
|
-
while (i < widths.length) {
|
|
191
|
-
if (!hasContent) {
|
|
192
|
-
i = normalizeSimpleLineStartSegmentIndex(prepared, i);
|
|
193
|
-
if (i >= widths.length)
|
|
194
|
-
break;
|
|
195
|
-
}
|
|
196
|
-
const w = widths[i];
|
|
197
|
-
const kind = kinds[i];
|
|
198
|
-
const breakAfter = kind === 'space' || kind === 'preserved-space' || kind === 'tab' || kind === 'zero-width-break' || kind === 'soft-hyphen';
|
|
199
|
-
if (!hasContent) {
|
|
200
|
-
if (w > maxWidth && breakableFitAdvances[i] !== null) {
|
|
201
|
-
appendBreakableSegmentFrom(i, 0);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
startLineAtSegment(i, w);
|
|
205
|
-
}
|
|
206
|
-
if (breakAfter) {
|
|
207
|
-
pendingBreakSegmentIndex = i + 1;
|
|
208
|
-
pendingBreakPaintWidth = lineW - w;
|
|
209
|
-
}
|
|
210
|
-
i++;
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
const newW = lineW + w;
|
|
214
|
-
if (newW > fitLimit) {
|
|
215
|
-
if (breakAfter) {
|
|
216
|
-
appendWholeSegment(i, w);
|
|
217
|
-
emitCurrentLine(i + 1, 0, lineW - w);
|
|
218
|
-
i++;
|
|
219
|
-
continue;
|
|
220
|
-
}
|
|
221
|
-
if (pendingBreakSegmentIndex >= 0) {
|
|
222
|
-
if (lineEndSegmentIndex > pendingBreakSegmentIndex ||
|
|
223
|
-
(lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0)) {
|
|
224
|
-
emitCurrentLine();
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
emitCurrentLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
if (w > maxWidth && breakableFitAdvances[i] !== null) {
|
|
231
|
-
emitCurrentLine();
|
|
232
|
-
appendBreakableSegmentFrom(i, 0);
|
|
233
|
-
i++;
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
emitCurrentLine();
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
appendWholeSegment(i, w);
|
|
240
|
-
if (breakAfter) {
|
|
241
|
-
pendingBreakSegmentIndex = i + 1;
|
|
242
|
-
pendingBreakPaintWidth = lineW - w;
|
|
243
|
-
}
|
|
244
|
-
i++;
|
|
245
|
-
}
|
|
246
|
-
if (hasContent)
|
|
247
|
-
emitCurrentLine();
|
|
248
|
-
return lineCount;
|
|
249
|
-
}
|
|
250
|
-
export function walkPreparedLines(prepared, maxWidth, onLine) {
|
|
251
|
-
if (prepared.simpleLineWalkFastPath) {
|
|
252
|
-
return walkPreparedLinesSimple(prepared, maxWidth, onLine);
|
|
253
|
-
}
|
|
254
|
-
const { widths, lineEndFitAdvances, lineEndPaintAdvances, kinds, breakableFitAdvances, discretionaryHyphenWidth, tabStopAdvance, chunks, } = prepared;
|
|
255
|
-
if (widths.length === 0 || chunks.length === 0)
|
|
256
|
-
return 0;
|
|
257
|
-
const engineProfile = getEngineProfile();
|
|
258
|
-
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
259
|
-
const fitLimit = maxWidth + lineFitEpsilon;
|
|
260
|
-
let lineCount = 0;
|
|
261
|
-
let lineW = 0;
|
|
262
|
-
let hasContent = false;
|
|
263
|
-
let lineStartSegmentIndex = 0;
|
|
264
|
-
let lineStartGraphemeIndex = 0;
|
|
265
|
-
let lineEndSegmentIndex = 0;
|
|
266
|
-
let lineEndGraphemeIndex = 0;
|
|
267
|
-
let pendingBreakSegmentIndex = -1;
|
|
268
|
-
let pendingBreakFitWidth = 0;
|
|
269
|
-
let pendingBreakPaintWidth = 0;
|
|
270
|
-
let pendingBreakKind = null;
|
|
271
|
-
function clearPendingBreak() {
|
|
272
|
-
pendingBreakSegmentIndex = -1;
|
|
273
|
-
pendingBreakFitWidth = 0;
|
|
274
|
-
pendingBreakPaintWidth = 0;
|
|
275
|
-
pendingBreakKind = null;
|
|
276
|
-
}
|
|
277
|
-
function emitCurrentLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width = lineW) {
|
|
278
|
-
lineCount++;
|
|
279
|
-
onLine?.({
|
|
280
|
-
startSegmentIndex: lineStartSegmentIndex,
|
|
281
|
-
startGraphemeIndex: lineStartGraphemeIndex,
|
|
282
|
-
endSegmentIndex,
|
|
283
|
-
endGraphemeIndex,
|
|
284
|
-
width,
|
|
285
|
-
});
|
|
286
|
-
lineW = 0;
|
|
287
|
-
hasContent = false;
|
|
288
|
-
clearPendingBreak();
|
|
289
|
-
}
|
|
290
|
-
function startLineAtSegment(segmentIndex, width) {
|
|
291
|
-
hasContent = true;
|
|
292
|
-
lineStartSegmentIndex = segmentIndex;
|
|
293
|
-
lineStartGraphemeIndex = 0;
|
|
294
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
295
|
-
lineEndGraphemeIndex = 0;
|
|
296
|
-
lineW = width;
|
|
297
|
-
}
|
|
298
|
-
function startLineAtGrapheme(segmentIndex, graphemeIndex, width) {
|
|
299
|
-
hasContent = true;
|
|
300
|
-
lineStartSegmentIndex = segmentIndex;
|
|
301
|
-
lineStartGraphemeIndex = graphemeIndex;
|
|
302
|
-
lineEndSegmentIndex = segmentIndex;
|
|
303
|
-
lineEndGraphemeIndex = graphemeIndex + 1;
|
|
304
|
-
lineW = width;
|
|
305
|
-
}
|
|
306
|
-
function appendWholeSegment(segmentIndex, width) {
|
|
307
|
-
if (!hasContent) {
|
|
308
|
-
startLineAtSegment(segmentIndex, width);
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
lineW += width;
|
|
312
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
313
|
-
lineEndGraphemeIndex = 0;
|
|
314
|
-
}
|
|
315
|
-
function updatePendingBreakForWholeSegment(kind, breakAfter, segmentIndex, segmentWidth) {
|
|
316
|
-
if (!breakAfter)
|
|
317
|
-
return;
|
|
318
|
-
const fitAdvance = kind === 'tab' ? 0 : lineEndFitAdvances[segmentIndex];
|
|
319
|
-
const paintAdvance = kind === 'tab' ? segmentWidth : lineEndPaintAdvances[segmentIndex];
|
|
320
|
-
pendingBreakSegmentIndex = segmentIndex + 1;
|
|
321
|
-
pendingBreakFitWidth = lineW - segmentWidth + fitAdvance;
|
|
322
|
-
pendingBreakPaintWidth = lineW - segmentWidth + paintAdvance;
|
|
323
|
-
pendingBreakKind = kind;
|
|
324
|
-
}
|
|
325
|
-
function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
|
|
326
|
-
const fitAdvances = breakableFitAdvances[segmentIndex];
|
|
327
|
-
for (let g = startGraphemeIndex; g < fitAdvances.length; g++) {
|
|
328
|
-
const gw = fitAdvances[g];
|
|
329
|
-
if (!hasContent) {
|
|
330
|
-
startLineAtGrapheme(segmentIndex, g, gw);
|
|
331
|
-
}
|
|
332
|
-
else if (lineW + gw > fitLimit) {
|
|
333
|
-
emitCurrentLine();
|
|
334
|
-
startLineAtGrapheme(segmentIndex, g, gw);
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
lineW += gw;
|
|
338
|
-
lineEndSegmentIndex = segmentIndex;
|
|
339
|
-
lineEndGraphemeIndex = g + 1;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
|
|
343
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
344
|
-
lineEndGraphemeIndex = 0;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
function continueSoftHyphenBreakableSegment(segmentIndex) {
|
|
348
|
-
if (pendingBreakKind !== 'soft-hyphen')
|
|
349
|
-
return false;
|
|
350
|
-
const fitWidths = breakableFitAdvances[segmentIndex];
|
|
351
|
-
if (fitWidths == null)
|
|
352
|
-
return false;
|
|
353
|
-
const { fitCount, fittedWidth } = fitSoftHyphenBreak(fitWidths, lineW, maxWidth, lineFitEpsilon, discretionaryHyphenWidth);
|
|
354
|
-
if (fitCount === 0)
|
|
355
|
-
return false;
|
|
356
|
-
lineW = fittedWidth;
|
|
357
|
-
lineEndSegmentIndex = segmentIndex;
|
|
358
|
-
lineEndGraphemeIndex = fitCount;
|
|
359
|
-
clearPendingBreak();
|
|
360
|
-
if (fitCount === fitWidths.length) {
|
|
361
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
362
|
-
lineEndGraphemeIndex = 0;
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
emitCurrentLine(segmentIndex, fitCount, fittedWidth + discretionaryHyphenWidth);
|
|
366
|
-
appendBreakableSegmentFrom(segmentIndex, fitCount);
|
|
367
|
-
return true;
|
|
368
|
-
}
|
|
369
|
-
function emitEmptyChunk(chunk) {
|
|
370
|
-
lineCount++;
|
|
371
|
-
onLine?.({
|
|
372
|
-
startSegmentIndex: chunk.startSegmentIndex,
|
|
373
|
-
startGraphemeIndex: 0,
|
|
374
|
-
endSegmentIndex: chunk.consumedEndSegmentIndex,
|
|
375
|
-
endGraphemeIndex: 0,
|
|
376
|
-
width: 0,
|
|
377
|
-
});
|
|
378
|
-
clearPendingBreak();
|
|
379
|
-
}
|
|
380
|
-
for (let chunkIndex = 0; chunkIndex < chunks.length; chunkIndex++) {
|
|
381
|
-
const chunk = chunks[chunkIndex];
|
|
382
|
-
if (chunk.startSegmentIndex === chunk.endSegmentIndex) {
|
|
383
|
-
emitEmptyChunk(chunk);
|
|
384
|
-
continue;
|
|
385
|
-
}
|
|
386
|
-
hasContent = false;
|
|
387
|
-
lineW = 0;
|
|
388
|
-
lineStartSegmentIndex = chunk.startSegmentIndex;
|
|
389
|
-
lineStartGraphemeIndex = 0;
|
|
390
|
-
lineEndSegmentIndex = chunk.startSegmentIndex;
|
|
391
|
-
lineEndGraphemeIndex = 0;
|
|
392
|
-
clearPendingBreak();
|
|
393
|
-
let i = chunk.startSegmentIndex;
|
|
394
|
-
while (i < chunk.endSegmentIndex) {
|
|
395
|
-
const kind = kinds[i];
|
|
396
|
-
const breakAfter = kind === 'space' || kind === 'preserved-space' || kind === 'tab' || kind === 'zero-width-break' || kind === 'soft-hyphen';
|
|
397
|
-
const w = kind === 'tab' ? getTabAdvance(lineW, tabStopAdvance) : widths[i];
|
|
398
|
-
if (kind === 'soft-hyphen') {
|
|
399
|
-
if (hasContent) {
|
|
400
|
-
lineEndSegmentIndex = i + 1;
|
|
401
|
-
lineEndGraphemeIndex = 0;
|
|
402
|
-
pendingBreakSegmentIndex = i + 1;
|
|
403
|
-
pendingBreakFitWidth = lineW + discretionaryHyphenWidth;
|
|
404
|
-
pendingBreakPaintWidth = lineW + discretionaryHyphenWidth;
|
|
405
|
-
pendingBreakKind = kind;
|
|
406
|
-
}
|
|
407
|
-
i++;
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
if (!hasContent) {
|
|
411
|
-
if (w > maxWidth && breakableFitAdvances[i] !== null) {
|
|
412
|
-
appendBreakableSegmentFrom(i, 0);
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
startLineAtSegment(i, w);
|
|
416
|
-
}
|
|
417
|
-
updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
|
|
418
|
-
i++;
|
|
419
|
-
continue;
|
|
420
|
-
}
|
|
421
|
-
const newW = lineW + w;
|
|
422
|
-
if (newW > fitLimit) {
|
|
423
|
-
const currentBreakFitWidth = lineW + (kind === 'tab' ? 0 : lineEndFitAdvances[i]);
|
|
424
|
-
const currentBreakPaintWidth = lineW + (kind === 'tab' ? w : lineEndPaintAdvances[i]);
|
|
425
|
-
if (pendingBreakKind === 'soft-hyphen' &&
|
|
426
|
-
engineProfile.preferEarlySoftHyphenBreak &&
|
|
427
|
-
pendingBreakFitWidth <= fitLimit) {
|
|
428
|
-
emitCurrentLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
if (pendingBreakKind === 'soft-hyphen' && continueSoftHyphenBreakableSegment(i)) {
|
|
432
|
-
i++;
|
|
433
|
-
continue;
|
|
434
|
-
}
|
|
435
|
-
if (breakAfter && currentBreakFitWidth <= fitLimit) {
|
|
436
|
-
appendWholeSegment(i, w);
|
|
437
|
-
emitCurrentLine(i + 1, 0, currentBreakPaintWidth);
|
|
438
|
-
i++;
|
|
439
|
-
continue;
|
|
440
|
-
}
|
|
441
|
-
if (pendingBreakSegmentIndex >= 0 && pendingBreakFitWidth <= fitLimit) {
|
|
442
|
-
if (lineEndSegmentIndex > pendingBreakSegmentIndex ||
|
|
443
|
-
(lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0)) {
|
|
444
|
-
emitCurrentLine();
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
const nextSegmentIndex = pendingBreakSegmentIndex;
|
|
448
|
-
emitCurrentLine(nextSegmentIndex, 0, pendingBreakPaintWidth);
|
|
449
|
-
i = nextSegmentIndex;
|
|
450
|
-
continue;
|
|
451
|
-
}
|
|
452
|
-
if (w > maxWidth && breakableFitAdvances[i] !== null) {
|
|
453
|
-
emitCurrentLine();
|
|
454
|
-
appendBreakableSegmentFrom(i, 0);
|
|
455
|
-
i++;
|
|
456
|
-
continue;
|
|
457
|
-
}
|
|
458
|
-
emitCurrentLine();
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
appendWholeSegment(i, w);
|
|
462
|
-
updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
|
|
463
|
-
i++;
|
|
464
|
-
}
|
|
465
|
-
if (hasContent) {
|
|
466
|
-
const finalPaintWidth = pendingBreakSegmentIndex === chunk.consumedEndSegmentIndex
|
|
467
|
-
? pendingBreakPaintWidth
|
|
468
|
-
: lineW;
|
|
469
|
-
emitCurrentLine(chunk.consumedEndSegmentIndex, 0, finalPaintWidth);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
return lineCount;
|
|
473
|
-
}
|
|
474
|
-
function stepPreparedChunkLineGeometry(prepared, cursor, chunkIndex, maxWidth) {
|
|
475
|
-
const chunk = prepared.chunks[chunkIndex];
|
|
476
|
-
if (chunk.startSegmentIndex === chunk.endSegmentIndex) {
|
|
477
|
-
cursor.segmentIndex = chunk.consumedEndSegmentIndex;
|
|
478
|
-
cursor.graphemeIndex = 0;
|
|
479
|
-
return 0;
|
|
480
|
-
}
|
|
481
|
-
const { widths, lineEndFitAdvances, lineEndPaintAdvances, kinds, breakableFitAdvances, discretionaryHyphenWidth, tabStopAdvance, } = prepared;
|
|
482
|
-
const engineProfile = getEngineProfile();
|
|
483
|
-
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
484
|
-
const fitLimit = maxWidth + lineFitEpsilon;
|
|
485
|
-
let lineW = 0;
|
|
486
|
-
let hasContent = false;
|
|
487
|
-
let lineEndSegmentIndex = cursor.segmentIndex;
|
|
488
|
-
let lineEndGraphemeIndex = cursor.graphemeIndex;
|
|
489
|
-
let pendingBreakSegmentIndex = -1;
|
|
490
|
-
let pendingBreakFitWidth = 0;
|
|
491
|
-
let pendingBreakPaintWidth = 0;
|
|
492
|
-
let pendingBreakKind = null;
|
|
493
|
-
function clearPendingBreak() {
|
|
494
|
-
pendingBreakSegmentIndex = -1;
|
|
495
|
-
pendingBreakFitWidth = 0;
|
|
496
|
-
pendingBreakPaintWidth = 0;
|
|
497
|
-
pendingBreakKind = null;
|
|
498
|
-
}
|
|
499
|
-
function finishLine(endSegmentIndex = lineEndSegmentIndex, endGraphemeIndex = lineEndGraphemeIndex, width = lineW) {
|
|
500
|
-
if (!hasContent)
|
|
501
|
-
return null;
|
|
502
|
-
cursor.segmentIndex = endSegmentIndex;
|
|
503
|
-
cursor.graphemeIndex = endGraphemeIndex;
|
|
504
|
-
return width;
|
|
505
|
-
}
|
|
506
|
-
function startLineAtSegment(segmentIndex, width) {
|
|
507
|
-
hasContent = true;
|
|
508
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
509
|
-
lineEndGraphemeIndex = 0;
|
|
510
|
-
lineW = width;
|
|
511
|
-
}
|
|
512
|
-
function startLineAtGrapheme(segmentIndex, graphemeIndex, width) {
|
|
513
|
-
hasContent = true;
|
|
514
|
-
lineEndSegmentIndex = segmentIndex;
|
|
515
|
-
lineEndGraphemeIndex = graphemeIndex + 1;
|
|
516
|
-
lineW = width;
|
|
517
|
-
}
|
|
518
|
-
function appendWholeSegment(segmentIndex, width) {
|
|
519
|
-
if (!hasContent) {
|
|
520
|
-
startLineAtSegment(segmentIndex, width);
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
lineW += width;
|
|
524
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
525
|
-
lineEndGraphemeIndex = 0;
|
|
526
|
-
}
|
|
527
|
-
function updatePendingBreakForWholeSegment(kind, breakAfter, segmentIndex, segmentWidth) {
|
|
528
|
-
if (!breakAfter)
|
|
529
|
-
return;
|
|
530
|
-
const fitAdvance = kind === 'tab' ? 0 : lineEndFitAdvances[segmentIndex];
|
|
531
|
-
const paintAdvance = kind === 'tab' ? segmentWidth : lineEndPaintAdvances[segmentIndex];
|
|
532
|
-
pendingBreakSegmentIndex = segmentIndex + 1;
|
|
533
|
-
pendingBreakFitWidth = lineW - segmentWidth + fitAdvance;
|
|
534
|
-
pendingBreakPaintWidth = lineW - segmentWidth + paintAdvance;
|
|
535
|
-
pendingBreakKind = kind;
|
|
536
|
-
}
|
|
537
|
-
function appendBreakableSegmentFrom(segmentIndex, startGraphemeIndex) {
|
|
538
|
-
const fitAdvances = breakableFitAdvances[segmentIndex];
|
|
539
|
-
for (let g = startGraphemeIndex; g < fitAdvances.length; g++) {
|
|
540
|
-
const gw = fitAdvances[g];
|
|
541
|
-
if (!hasContent) {
|
|
542
|
-
startLineAtGrapheme(segmentIndex, g, gw);
|
|
543
|
-
}
|
|
544
|
-
else {
|
|
545
|
-
if (lineW + gw > fitLimit) {
|
|
546
|
-
return finishLine();
|
|
547
|
-
}
|
|
548
|
-
lineW += gw;
|
|
549
|
-
lineEndSegmentIndex = segmentIndex;
|
|
550
|
-
lineEndGraphemeIndex = g + 1;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
if (hasContent && lineEndSegmentIndex === segmentIndex && lineEndGraphemeIndex === fitAdvances.length) {
|
|
554
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
555
|
-
lineEndGraphemeIndex = 0;
|
|
556
|
-
}
|
|
557
|
-
return null;
|
|
558
|
-
}
|
|
559
|
-
function maybeFinishAtSoftHyphen(segmentIndex) {
|
|
560
|
-
if (pendingBreakKind !== 'soft-hyphen' || pendingBreakSegmentIndex < 0)
|
|
561
|
-
return null;
|
|
562
|
-
const fitWidths = breakableFitAdvances[segmentIndex] ?? null;
|
|
563
|
-
if (fitWidths !== null) {
|
|
564
|
-
const { fitCount, fittedWidth } = fitSoftHyphenBreak(fitWidths, lineW, maxWidth, lineFitEpsilon, discretionaryHyphenWidth);
|
|
565
|
-
if (fitCount === fitWidths.length) {
|
|
566
|
-
lineW = fittedWidth;
|
|
567
|
-
lineEndSegmentIndex = segmentIndex + 1;
|
|
568
|
-
lineEndGraphemeIndex = 0;
|
|
569
|
-
clearPendingBreak();
|
|
570
|
-
return null;
|
|
571
|
-
}
|
|
572
|
-
if (fitCount > 0) {
|
|
573
|
-
return finishLine(segmentIndex, fitCount, fittedWidth + discretionaryHyphenWidth);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
if (pendingBreakFitWidth <= fitLimit) {
|
|
577
|
-
return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
578
|
-
}
|
|
579
|
-
return null;
|
|
580
|
-
}
|
|
581
|
-
for (let i = cursor.segmentIndex; i < chunk.endSegmentIndex; i++) {
|
|
582
|
-
const kind = kinds[i];
|
|
583
|
-
const breakAfter = kind === 'space' || kind === 'preserved-space' || kind === 'tab' || kind === 'zero-width-break' || kind === 'soft-hyphen';
|
|
584
|
-
const startGraphemeIndex = i === cursor.segmentIndex ? cursor.graphemeIndex : 0;
|
|
585
|
-
const w = kind === 'tab' ? getTabAdvance(lineW, tabStopAdvance) : widths[i];
|
|
586
|
-
if (kind === 'soft-hyphen' && startGraphemeIndex === 0) {
|
|
587
|
-
if (hasContent) {
|
|
588
|
-
lineEndSegmentIndex = i + 1;
|
|
589
|
-
lineEndGraphemeIndex = 0;
|
|
590
|
-
pendingBreakSegmentIndex = i + 1;
|
|
591
|
-
pendingBreakFitWidth = lineW + discretionaryHyphenWidth;
|
|
592
|
-
pendingBreakPaintWidth = lineW + discretionaryHyphenWidth;
|
|
593
|
-
pendingBreakKind = kind;
|
|
594
|
-
}
|
|
595
|
-
continue;
|
|
596
|
-
}
|
|
597
|
-
if (!hasContent) {
|
|
598
|
-
if (startGraphemeIndex > 0) {
|
|
599
|
-
const line = appendBreakableSegmentFrom(i, startGraphemeIndex);
|
|
600
|
-
if (line !== null)
|
|
601
|
-
return line;
|
|
602
|
-
}
|
|
603
|
-
else if (w > maxWidth && breakableFitAdvances[i] !== null) {
|
|
604
|
-
const line = appendBreakableSegmentFrom(i, 0);
|
|
605
|
-
if (line !== null)
|
|
606
|
-
return line;
|
|
607
|
-
}
|
|
608
|
-
else {
|
|
609
|
-
startLineAtSegment(i, w);
|
|
610
|
-
}
|
|
611
|
-
updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
|
|
612
|
-
continue;
|
|
613
|
-
}
|
|
614
|
-
const newW = lineW + w;
|
|
615
|
-
if (newW > fitLimit) {
|
|
616
|
-
const currentBreakFitWidth = lineW + (kind === 'tab' ? 0 : lineEndFitAdvances[i]);
|
|
617
|
-
const currentBreakPaintWidth = lineW + (kind === 'tab' ? w : lineEndPaintAdvances[i]);
|
|
618
|
-
if (pendingBreakKind === 'soft-hyphen' &&
|
|
619
|
-
engineProfile.preferEarlySoftHyphenBreak &&
|
|
620
|
-
pendingBreakFitWidth <= fitLimit) {
|
|
621
|
-
return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
622
|
-
}
|
|
623
|
-
const softBreakLine = maybeFinishAtSoftHyphen(i);
|
|
624
|
-
if (softBreakLine !== null)
|
|
625
|
-
return softBreakLine;
|
|
626
|
-
if (breakAfter && currentBreakFitWidth <= fitLimit) {
|
|
627
|
-
appendWholeSegment(i, w);
|
|
628
|
-
return finishLine(i + 1, 0, currentBreakPaintWidth);
|
|
629
|
-
}
|
|
630
|
-
if (pendingBreakSegmentIndex >= 0 && pendingBreakFitWidth <= fitLimit) {
|
|
631
|
-
if (lineEndSegmentIndex > pendingBreakSegmentIndex ||
|
|
632
|
-
(lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0)) {
|
|
633
|
-
return finishLine();
|
|
634
|
-
}
|
|
635
|
-
return finishLine(pendingBreakSegmentIndex, 0, pendingBreakPaintWidth);
|
|
636
|
-
}
|
|
637
|
-
if (w > maxWidth && breakableFitAdvances[i] !== null) {
|
|
638
|
-
const currentLine = finishLine();
|
|
639
|
-
if (currentLine !== null)
|
|
640
|
-
return currentLine;
|
|
641
|
-
const line = appendBreakableSegmentFrom(i, 0);
|
|
642
|
-
if (line !== null)
|
|
643
|
-
return line;
|
|
644
|
-
}
|
|
645
|
-
return finishLine();
|
|
646
|
-
}
|
|
647
|
-
appendWholeSegment(i, w);
|
|
648
|
-
updatePendingBreakForWholeSegment(kind, breakAfter, i, w);
|
|
649
|
-
}
|
|
650
|
-
if (pendingBreakSegmentIndex === chunk.consumedEndSegmentIndex && lineEndGraphemeIndex === 0) {
|
|
651
|
-
return finishLine(chunk.consumedEndSegmentIndex, 0, pendingBreakPaintWidth);
|
|
652
|
-
}
|
|
653
|
-
return finishLine(chunk.consumedEndSegmentIndex, 0, lineW);
|
|
654
|
-
}
|
|
655
|
-
function stepPreparedSimpleLineGeometry(prepared, cursor, maxWidth) {
|
|
656
|
-
const { widths, kinds, breakableFitAdvances } = prepared;
|
|
657
|
-
const engineProfile = getEngineProfile();
|
|
658
|
-
const lineFitEpsilon = engineProfile.lineFitEpsilon;
|
|
659
|
-
const fitLimit = maxWidth + lineFitEpsilon;
|
|
660
|
-
let lineW = 0;
|
|
661
|
-
let hasContent = false;
|
|
662
|
-
let lineEndSegmentIndex = cursor.segmentIndex;
|
|
663
|
-
let lineEndGraphemeIndex = cursor.graphemeIndex;
|
|
664
|
-
let pendingBreakSegmentIndex = -1;
|
|
665
|
-
let pendingBreakPaintWidth = 0;
|
|
666
|
-
for (let i = cursor.segmentIndex; i < widths.length; i++) {
|
|
667
|
-
const w = widths[i];
|
|
668
|
-
const kind = kinds[i];
|
|
669
|
-
const breakAfter = kind === 'space' || kind === 'preserved-space' || kind === 'tab' || kind === 'zero-width-break' || kind === 'soft-hyphen';
|
|
670
|
-
const startGraphemeIndex = i === cursor.segmentIndex ? cursor.graphemeIndex : 0;
|
|
671
|
-
const breakableFitAdvance = breakableFitAdvances[i];
|
|
672
|
-
if (!hasContent) {
|
|
673
|
-
if (startGraphemeIndex > 0 || (w > maxWidth && breakableFitAdvance !== null)) {
|
|
674
|
-
const fitAdvances = breakableFitAdvance;
|
|
675
|
-
const firstGraphemeWidth = fitAdvances[startGraphemeIndex];
|
|
676
|
-
hasContent = true;
|
|
677
|
-
lineW = firstGraphemeWidth;
|
|
678
|
-
lineEndSegmentIndex = i;
|
|
679
|
-
lineEndGraphemeIndex = startGraphemeIndex + 1;
|
|
680
|
-
for (let g = startGraphemeIndex + 1; g < fitAdvances.length; g++) {
|
|
681
|
-
const gw = fitAdvances[g];
|
|
682
|
-
if (lineW + gw > fitLimit) {
|
|
683
|
-
cursor.segmentIndex = lineEndSegmentIndex;
|
|
684
|
-
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
685
|
-
return lineW;
|
|
686
|
-
}
|
|
687
|
-
lineW += gw;
|
|
688
|
-
lineEndSegmentIndex = i;
|
|
689
|
-
lineEndGraphemeIndex = g + 1;
|
|
690
|
-
}
|
|
691
|
-
if (lineEndSegmentIndex === i && lineEndGraphemeIndex === fitAdvances.length) {
|
|
692
|
-
lineEndSegmentIndex = i + 1;
|
|
693
|
-
lineEndGraphemeIndex = 0;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
else {
|
|
697
|
-
hasContent = true;
|
|
698
|
-
lineW = w;
|
|
699
|
-
lineEndSegmentIndex = i + 1;
|
|
700
|
-
lineEndGraphemeIndex = 0;
|
|
701
|
-
}
|
|
702
|
-
if (breakAfter) {
|
|
703
|
-
pendingBreakSegmentIndex = i + 1;
|
|
704
|
-
pendingBreakPaintWidth = lineW - w;
|
|
705
|
-
}
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
if (lineW + w > fitLimit) {
|
|
709
|
-
if (breakAfter) {
|
|
710
|
-
cursor.segmentIndex = i + 1;
|
|
711
|
-
cursor.graphemeIndex = 0;
|
|
712
|
-
return lineW;
|
|
713
|
-
}
|
|
714
|
-
if (pendingBreakSegmentIndex >= 0) {
|
|
715
|
-
if (lineEndSegmentIndex > pendingBreakSegmentIndex ||
|
|
716
|
-
(lineEndSegmentIndex === pendingBreakSegmentIndex && lineEndGraphemeIndex > 0)) {
|
|
717
|
-
cursor.segmentIndex = lineEndSegmentIndex;
|
|
718
|
-
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
719
|
-
return lineW;
|
|
720
|
-
}
|
|
721
|
-
cursor.segmentIndex = pendingBreakSegmentIndex;
|
|
722
|
-
cursor.graphemeIndex = 0;
|
|
723
|
-
return pendingBreakPaintWidth;
|
|
724
|
-
}
|
|
725
|
-
cursor.segmentIndex = lineEndSegmentIndex;
|
|
726
|
-
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
727
|
-
return lineW;
|
|
728
|
-
}
|
|
729
|
-
lineW += w;
|
|
730
|
-
lineEndSegmentIndex = i + 1;
|
|
731
|
-
lineEndGraphemeIndex = 0;
|
|
732
|
-
if (breakAfter) {
|
|
733
|
-
pendingBreakSegmentIndex = i + 1;
|
|
734
|
-
pendingBreakPaintWidth = lineW - w;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if (!hasContent)
|
|
738
|
-
return null;
|
|
739
|
-
cursor.segmentIndex = lineEndSegmentIndex;
|
|
740
|
-
cursor.graphemeIndex = lineEndGraphemeIndex;
|
|
741
|
-
return lineW;
|
|
742
|
-
}
|
|
743
|
-
export function layoutNextLineRange(prepared, start, maxWidth) {
|
|
744
|
-
const end = {
|
|
745
|
-
segmentIndex: start.segmentIndex,
|
|
746
|
-
graphemeIndex: start.graphemeIndex,
|
|
747
|
-
};
|
|
748
|
-
const chunkIndex = normalizeLineStartChunkIndex(prepared, end);
|
|
749
|
-
if (chunkIndex < 0)
|
|
750
|
-
return null;
|
|
751
|
-
const lineStartSegmentIndex = end.segmentIndex;
|
|
752
|
-
const lineStartGraphemeIndex = end.graphemeIndex;
|
|
753
|
-
const width = prepared.simpleLineWalkFastPath
|
|
754
|
-
? stepPreparedSimpleLineGeometry(prepared, end, maxWidth)
|
|
755
|
-
: stepPreparedChunkLineGeometry(prepared, end, chunkIndex, maxWidth);
|
|
756
|
-
if (width === null)
|
|
757
|
-
return null;
|
|
758
|
-
return {
|
|
759
|
-
startSegmentIndex: lineStartSegmentIndex,
|
|
760
|
-
startGraphemeIndex: lineStartGraphemeIndex,
|
|
761
|
-
endSegmentIndex: end.segmentIndex,
|
|
762
|
-
endGraphemeIndex: end.graphemeIndex,
|
|
763
|
-
width,
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
export function stepPreparedLineGeometry(prepared, cursor, maxWidth) {
|
|
767
|
-
const chunkIndex = normalizeLineStartChunkIndex(prepared, cursor);
|
|
768
|
-
if (chunkIndex < 0)
|
|
769
|
-
return null;
|
|
770
|
-
if (prepared.simpleLineWalkFastPath) {
|
|
771
|
-
return stepPreparedSimpleLineGeometry(prepared, cursor, maxWidth);
|
|
772
|
-
}
|
|
773
|
-
return stepPreparedChunkLineGeometry(prepared, cursor, chunkIndex, maxWidth);
|
|
774
|
-
}
|
|
775
|
-
export function measurePreparedLineGeometry(prepared, maxWidth) {
|
|
776
|
-
if (prepared.widths.length === 0) {
|
|
777
|
-
return {
|
|
778
|
-
lineCount: 0,
|
|
779
|
-
maxLineWidth: 0,
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
const cursor = {
|
|
783
|
-
segmentIndex: 0,
|
|
784
|
-
graphemeIndex: 0,
|
|
785
|
-
};
|
|
786
|
-
let lineCount = 0;
|
|
787
|
-
let maxLineWidth = 0;
|
|
788
|
-
if (!prepared.simpleLineWalkFastPath) {
|
|
789
|
-
let chunkIndex = normalizeLineStartChunkIndex(prepared, cursor);
|
|
790
|
-
while (chunkIndex >= 0) {
|
|
791
|
-
const lineWidth = stepPreparedChunkLineGeometry(prepared, cursor, chunkIndex, maxWidth);
|
|
792
|
-
if (lineWidth === null) {
|
|
793
|
-
return {
|
|
794
|
-
lineCount,
|
|
795
|
-
maxLineWidth,
|
|
796
|
-
};
|
|
797
|
-
}
|
|
798
|
-
lineCount++;
|
|
799
|
-
if (lineWidth > maxLineWidth)
|
|
800
|
-
maxLineWidth = lineWidth;
|
|
801
|
-
chunkIndex = normalizeLineStartChunkIndexFromHint(prepared, chunkIndex, cursor);
|
|
802
|
-
}
|
|
803
|
-
return {
|
|
804
|
-
lineCount,
|
|
805
|
-
maxLineWidth,
|
|
806
|
-
};
|
|
807
|
-
}
|
|
808
|
-
while (true) {
|
|
809
|
-
const lineWidth = stepPreparedLineGeometry(prepared, cursor, maxWidth);
|
|
810
|
-
if (lineWidth === null) {
|
|
811
|
-
return {
|
|
812
|
-
lineCount,
|
|
813
|
-
maxLineWidth,
|
|
814
|
-
};
|
|
815
|
-
}
|
|
816
|
-
lineCount++;
|
|
817
|
-
if (lineWidth > maxLineWidth)
|
|
818
|
-
maxLineWidth = lineWidth;
|
|
819
|
-
}
|
|
820
|
-
}
|