@simon_he/vue-tui 1.0.1 → 1.1.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.
- package/README.md +99 -46
- package/dist/TMermaidText-CXm_L969.js +885 -0
- package/dist/{TSelect-HzILuti9.js → TSelect-CiyMvwl-.js} +60 -81
- package/dist/{TTree-ChOot2Bh.js → TTree-DKGiuIcM.js} +140 -103
- package/dist/agent/mermaid.cjs +2 -0
- package/dist/agent/mermaid.d.cts +2 -0
- package/dist/agent/mermaid.d.ts +2 -0
- package/dist/agent/mermaid.js +1 -0
- package/dist/agent.cjs +31184 -24907
- package/dist/agent.d.cts +11 -1
- package/dist/agent.d.ts +11 -1
- package/dist/agent.js +1700 -13
- package/dist/block-source-5CQp4tF8.js +3230 -0
- package/dist/cli/stdin-buffer.d.ts +1 -1
- package/dist/cli.cjs +5363 -6178
- package/dist/cli.d.cts +5 -1
- package/dist/cli.d.ts +5 -1
- package/dist/cli.js +3569 -302
- package/dist/core/buffer/buffer.d.ts +2 -2
- package/dist/core/buffer/eaw-ranges-unicode-17.d.ts +14 -0
- package/dist/core/perf/instrumentation-noop.d.ts +48 -0
- package/dist/core/perf/instrumentation.d.ts +136 -0
- package/dist/core/terminal/create-terminal.d.ts +1 -0
- package/dist/core/types.d.ts +0 -4
- package/dist/core.cjs +851 -1462
- package/dist/core.js +6 -6
- package/dist/{create-terminal-C2oiWFJU.js → create-terminal-DXuZ2fci.js} +54 -19
- package/dist/debug-logger-ChY_PXVk.js +74 -0
- package/dist/{dom-renderer-BqGijQID.js → dom-renderer-DNzmg2As.js} +2 -2
- package/dist/experimental.cjs +4115 -5928
- package/dist/experimental.d.cts +2 -0
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.js +1490 -9
- package/dist/frame-perf-BBhE-iuS.js +111 -0
- package/dist/{sgr-BmzxEjAO.js → hyperlink-B35-O-cW.js} +100 -1
- package/dist/index.cjs +5025 -10332
- package/dist/index.js +16 -14
- package/dist/{linkify-D_gzn9Xq.js → linkify-CuuquMQT.js} +32 -3
- package/dist/markdown.cjs +21295 -12691
- package/dist/markdown.d.cts +1 -1
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.js +211 -51
- package/dist/mermaid-CWto52Wk.js +123 -0
- package/dist/mermaid.cjs +1707 -0
- package/dist/mermaid.d.cts +3 -0
- package/dist/mermaid.d.ts +3 -0
- package/dist/mermaid.js +6 -0
- package/dist/observability/frame-perf-store.d.ts +2 -1
- package/dist/observability/frame-perf.d.ts +33 -0
- package/dist/observability.cjs +106 -107
- package/dist/observability.d.cts +2 -2
- package/dist/observability.d.ts +2 -2
- package/dist/observability.js +3 -3
- package/dist/{path-suggest-BNqcuE3-.js → path-suggest-fPzRsgPv.js} +1 -1
- package/dist/{wheel-scroll-vBRaQ7p-.js → rect-Ng-3eKzF.js} +253 -117
- package/dist/renderer/cli/index.d.ts +1 -1
- package/dist/renderer/cli/stdout-metrics.d.ts +10 -0
- package/dist/renderer/cli/stdout-renderer.d.ts +53 -7
- package/dist/renderer/terminal-graphic-render-queue.d.ts +50 -0
- package/dist/renderer/terminal-graphics-trace.d.ts +53 -0
- package/dist/renderer/terminal-graphics.d.ts +146 -0
- package/dist/renderer-dom.cjs +364 -903
- package/dist/renderer-dom.js +4 -4
- package/dist/runtime/index.d.ts +2 -0
- package/dist/{runtime-rfcZCyJq.js → runtime-D77C03RM.js} +28 -15
- package/dist/runtime.cjs +427 -889
- package/dist/runtime.js +2 -2
- package/dist/{terminal-selection-DBinO6p5.js → terminal-selection-CQYr--26.js} +4 -1
- package/dist/{tlog-theme-CvLFNMwk.js → tlog-theme-CopRt9SC.js} +37 -6
- package/dist/{trace-CjzYeIxN.js → trace-CYHDKM1m.js} +5 -0
- package/dist/vue/agent/create-png-terminal-graphic-renderer.d.ts +19 -0
- package/dist/vue/components/TAgentTerminalGraphic.d.ts +481 -0
- package/dist/vue/components/TCharts.d.ts +1121 -0
- package/dist/vue/components/TFeedback.d.ts +1 -1
- package/dist/vue/components/TFlex.d.ts +389 -0
- package/dist/vue/components/TForm.d.ts +4 -4
- package/dist/vue/components/TLogSearchBar.d.ts +3 -3
- package/dist/vue/components/TLogSearchPager.d.ts +2 -2
- package/dist/vue/components/TMarkdownText.d.ts +162 -4
- package/dist/vue/components/TMermaidText.d.ts +900 -0
- package/dist/vue/components/TVirtualList.d.ts +9 -0
- package/dist/vue/components/TVirtualMarkdown.d.ts +170 -9
- package/dist/vue/components/TVirtualRows.d.ts +9 -0
- package/dist/vue/components/TerminalProvider.d.ts +2 -0
- package/dist/vue/context.d.ts +24 -0
- package/dist/vue/index.d.ts +5 -0
- package/dist/vue/layout/flex.d.ts +67 -0
- package/dist/vue/markdown/ast.d.ts +5 -2
- package/dist/vue/markdown/document.d.ts +5 -0
- package/dist/vue/markdown/image-actions.d.ts +14 -0
- package/dist/vue/markdown/image.d.ts +11 -0
- package/dist/vue/markdown/link-actions.d.ts +14 -0
- package/dist/vue/markdown/math-actions.d.ts +14 -0
- package/dist/vue/markdown/math.d.ts +6 -0
- package/dist/vue/markdown/render.d.ts +28 -0
- package/dist/vue/markdown/types.d.ts +78 -0
- package/dist/vue/mermaid/beautiful-mermaid.d.ts +1436 -0
- package/dist/vue/render/render-manager.d.ts +7 -0
- package/dist/vue.cjs +7215 -12430
- package/dist/vue.js +706 -39
- package/dist/wheel-scroll-CQ22Hcyj.js +106 -0
- package/dist/{hyperlink-Bn02UXJb.js → width-GqllnV8C.js} +166 -111
- package/package.json +107 -18
- package/dist/block-source-CKUOnkgT.js +0 -1663
- package/dist/frame-perf-C6Xfg85O.js +0 -24
- /package/dist/{env-Cl8qmNFN.js → env-DNCzvX8b.js} +0 -0
- /package/dist/{path-mnSgEpCm.js → path-BI9W15Zt.js} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//#region src/vue/utils/wheel-scroll.ts
|
|
2
|
+
const LINE_UNIT_THRESHOLD = 3;
|
|
3
|
+
const PIXELS_PER_LINE = 16;
|
|
4
|
+
const ACCEL_WINDOW_MS = 120;
|
|
5
|
+
const MAX_ACCEL = 26;
|
|
6
|
+
const EDGE_BOUNCE_MS = 120;
|
|
7
|
+
function clamp(n, min, max) {
|
|
8
|
+
return Math.max(min, Math.min(max, n));
|
|
9
|
+
}
|
|
10
|
+
function isLineUnitDelta(deltaY, mode = "auto") {
|
|
11
|
+
if (mode === "line") return true;
|
|
12
|
+
if (mode === "pixel") return false;
|
|
13
|
+
const abs = Math.abs(deltaY);
|
|
14
|
+
return abs > 0 && abs <= LINE_UNIT_THRESHOLD && Number.isInteger(deltaY);
|
|
15
|
+
}
|
|
16
|
+
function normalizeDelta(deltaY, mode = "auto") {
|
|
17
|
+
if (mode === "line") return deltaY;
|
|
18
|
+
if (mode === "pixel") return deltaY / PIXELS_PER_LINE;
|
|
19
|
+
const abs = Math.abs(deltaY);
|
|
20
|
+
if (abs <= LINE_UNIT_THRESHOLD && Number.isInteger(deltaY)) return deltaY;
|
|
21
|
+
return deltaY / PIXELS_PER_LINE;
|
|
22
|
+
}
|
|
23
|
+
function accelFactor(now, lastAt, maxAccel = MAX_ACCEL) {
|
|
24
|
+
const dt = now - lastAt;
|
|
25
|
+
if (!Number.isFinite(dt) || dt <= 0 || dt > ACCEL_WINDOW_MS) return 1;
|
|
26
|
+
const t = 1 - dt / ACCEL_WINDOW_MS;
|
|
27
|
+
return 1 + t * (maxAccel - 1);
|
|
28
|
+
}
|
|
29
|
+
function createWheelScrollState() {
|
|
30
|
+
return {
|
|
31
|
+
accumulator: 0,
|
|
32
|
+
lastAt: 0,
|
|
33
|
+
lastEdgeDir: 0,
|
|
34
|
+
lastEdgeAt: 0
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function resetWheelScrollState(state) {
|
|
38
|
+
state.accumulator = 0;
|
|
39
|
+
state.lastAt = 0;
|
|
40
|
+
state.lastEdgeDir = 0;
|
|
41
|
+
state.lastEdgeAt = 0;
|
|
42
|
+
}
|
|
43
|
+
function applyWheelScroll(state, deltaY, scrollTop, maxTop, now = Date.now(), deltaMode = "auto", options = {}) {
|
|
44
|
+
if (!Number.isFinite(deltaY) || deltaY === 0 || maxTop <= 0) {
|
|
45
|
+
if (maxTop <= 0) {
|
|
46
|
+
state.accumulator = 0;
|
|
47
|
+
state.lastEdgeDir = 0;
|
|
48
|
+
state.lastEdgeAt = 0;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
nextTop: scrollTop,
|
|
52
|
+
dir: 0,
|
|
53
|
+
lines: 0
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const lineUnits = isLineUnitDelta(deltaY, deltaMode);
|
|
57
|
+
const normalizedDelta = normalizeDelta(deltaY, deltaMode);
|
|
58
|
+
const accel = options.disableAcceleration ? 1 : lineUnits ? 1 : state.lastAt ? accelFactor(now, state.lastAt) : 1;
|
|
59
|
+
state.lastAt = now;
|
|
60
|
+
state.accumulator += normalizedDelta * accel;
|
|
61
|
+
const lines = Math.trunc(state.accumulator);
|
|
62
|
+
if (lines === 0) return {
|
|
63
|
+
nextTop: scrollTop,
|
|
64
|
+
dir: 0,
|
|
65
|
+
lines: 0
|
|
66
|
+
};
|
|
67
|
+
state.accumulator -= lines;
|
|
68
|
+
const dir = lines > 0 ? 1 : -1;
|
|
69
|
+
const atTop = scrollTop <= 0;
|
|
70
|
+
const atBottom = scrollTop >= maxTop;
|
|
71
|
+
if (dir < 0 && atTop || dir > 0 && atBottom) {
|
|
72
|
+
state.lastEdgeDir = dir;
|
|
73
|
+
state.lastEdgeAt = now;
|
|
74
|
+
state.accumulator = 0;
|
|
75
|
+
return {
|
|
76
|
+
nextTop: scrollTop,
|
|
77
|
+
dir: 0,
|
|
78
|
+
lines: 0
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (state.lastEdgeDir !== 0 && now - state.lastEdgeAt < EDGE_BOUNCE_MS && dir === -state.lastEdgeDir && (atTop || atBottom)) return {
|
|
82
|
+
nextTop: scrollTop,
|
|
83
|
+
dir: 0,
|
|
84
|
+
lines: 0
|
|
85
|
+
};
|
|
86
|
+
const unclamped = scrollTop + lines;
|
|
87
|
+
const nextTop = clamp(unclamped, 0, maxTop);
|
|
88
|
+
if (nextTop === scrollTop) {
|
|
89
|
+
state.accumulator = 0;
|
|
90
|
+
return {
|
|
91
|
+
nextTop: scrollTop,
|
|
92
|
+
dir: 0,
|
|
93
|
+
lines: 0
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (nextTop !== unclamped) state.accumulator = 0;
|
|
97
|
+
state.lastEdgeDir = 0;
|
|
98
|
+
return {
|
|
99
|
+
nextTop,
|
|
100
|
+
dir: nextTop > scrollTop ? 1 : -1,
|
|
101
|
+
lines: nextTop - scrollTop
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
export { applyWheelScroll, createWheelScrollState, resetWheelScrollState };
|
|
@@ -86,17 +86,131 @@ function segmentedGraphemes(text) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
//#endregion
|
|
89
|
-
//#region src/core/buffer/
|
|
89
|
+
//#region src/core/buffer/eaw-ranges-unicode-17.ts
|
|
90
90
|
const fullWidthRanges = [
|
|
91
91
|
[4352, 4447],
|
|
92
|
+
[8986, 8987],
|
|
92
93
|
[9001, 9002],
|
|
93
|
-
[
|
|
94
|
+
[9193, 9196],
|
|
95
|
+
[9200, 9200],
|
|
96
|
+
[9203, 9203],
|
|
97
|
+
[9725, 9726],
|
|
98
|
+
[9748, 9749],
|
|
99
|
+
[9776, 9783],
|
|
100
|
+
[9800, 9811],
|
|
101
|
+
[9855, 9855],
|
|
102
|
+
[9866, 9871],
|
|
103
|
+
[9875, 9875],
|
|
104
|
+
[9889, 9889],
|
|
105
|
+
[9898, 9899],
|
|
106
|
+
[9917, 9918],
|
|
107
|
+
[9924, 9925],
|
|
108
|
+
[9934, 9934],
|
|
109
|
+
[9940, 9940],
|
|
110
|
+
[9962, 9962],
|
|
111
|
+
[9970, 9971],
|
|
112
|
+
[9973, 9973],
|
|
113
|
+
[9978, 9978],
|
|
114
|
+
[9981, 9981],
|
|
115
|
+
[9989, 9989],
|
|
116
|
+
[9994, 9995],
|
|
117
|
+
[10024, 10024],
|
|
118
|
+
[10060, 10060],
|
|
119
|
+
[10062, 10062],
|
|
120
|
+
[10067, 10069],
|
|
121
|
+
[10071, 10071],
|
|
122
|
+
[10133, 10135],
|
|
123
|
+
[10160, 10160],
|
|
124
|
+
[10175, 10175],
|
|
125
|
+
[11035, 11036],
|
|
126
|
+
[11088, 11088],
|
|
127
|
+
[11093, 11093],
|
|
128
|
+
[11904, 11929],
|
|
129
|
+
[11931, 12019],
|
|
130
|
+
[12032, 12245],
|
|
131
|
+
[12272, 12350],
|
|
132
|
+
[12353, 12438],
|
|
133
|
+
[12441, 12543],
|
|
134
|
+
[12549, 12591],
|
|
135
|
+
[12593, 12686],
|
|
136
|
+
[12688, 12773],
|
|
137
|
+
[12783, 12830],
|
|
138
|
+
[12832, 12871],
|
|
139
|
+
[12880, 42124],
|
|
140
|
+
[42128, 42182],
|
|
141
|
+
[43360, 43388],
|
|
94
142
|
[44032, 55203],
|
|
95
143
|
[63744, 64255],
|
|
96
144
|
[65040, 65049],
|
|
97
|
-
[65072,
|
|
98
|
-
[
|
|
99
|
-
[
|
|
145
|
+
[65072, 65106],
|
|
146
|
+
[65108, 65126],
|
|
147
|
+
[65128, 65131],
|
|
148
|
+
[65281, 65376],
|
|
149
|
+
[65504, 65510],
|
|
150
|
+
[94176, 94180],
|
|
151
|
+
[94192, 94198],
|
|
152
|
+
[94208, 101589],
|
|
153
|
+
[101631, 101662],
|
|
154
|
+
[101760, 101874],
|
|
155
|
+
[110576, 110579],
|
|
156
|
+
[110581, 110587],
|
|
157
|
+
[110589, 110590],
|
|
158
|
+
[110592, 110882],
|
|
159
|
+
[110898, 110898],
|
|
160
|
+
[110928, 110930],
|
|
161
|
+
[110933, 110933],
|
|
162
|
+
[110948, 110951],
|
|
163
|
+
[110960, 111355],
|
|
164
|
+
[119552, 119638],
|
|
165
|
+
[119648, 119670],
|
|
166
|
+
[126980, 126980],
|
|
167
|
+
[127183, 127183],
|
|
168
|
+
[127374, 127374],
|
|
169
|
+
[127377, 127386],
|
|
170
|
+
[127488, 127490],
|
|
171
|
+
[127504, 127547],
|
|
172
|
+
[127552, 127560],
|
|
173
|
+
[127568, 127569],
|
|
174
|
+
[127584, 127589],
|
|
175
|
+
[127744, 127776],
|
|
176
|
+
[127789, 127797],
|
|
177
|
+
[127799, 127868],
|
|
178
|
+
[127870, 127891],
|
|
179
|
+
[127904, 127946],
|
|
180
|
+
[127951, 127955],
|
|
181
|
+
[127968, 127984],
|
|
182
|
+
[127988, 127988],
|
|
183
|
+
[127992, 128062],
|
|
184
|
+
[128064, 128064],
|
|
185
|
+
[128066, 128252],
|
|
186
|
+
[128255, 128317],
|
|
187
|
+
[128331, 128334],
|
|
188
|
+
[128336, 128359],
|
|
189
|
+
[128378, 128378],
|
|
190
|
+
[128405, 128406],
|
|
191
|
+
[128420, 128420],
|
|
192
|
+
[128507, 128591],
|
|
193
|
+
[128640, 128709],
|
|
194
|
+
[128716, 128716],
|
|
195
|
+
[128720, 128722],
|
|
196
|
+
[128725, 128728],
|
|
197
|
+
[128732, 128735],
|
|
198
|
+
[128747, 128748],
|
|
199
|
+
[128756, 128764],
|
|
200
|
+
[128992, 129003],
|
|
201
|
+
[129008, 129008],
|
|
202
|
+
[129292, 129338],
|
|
203
|
+
[129340, 129349],
|
|
204
|
+
[129351, 129535],
|
|
205
|
+
[129648, 129660],
|
|
206
|
+
[129664, 129674],
|
|
207
|
+
[129678, 129734],
|
|
208
|
+
[129736, 129736],
|
|
209
|
+
[129741, 129756],
|
|
210
|
+
[129759, 129770],
|
|
211
|
+
[129775, 129784],
|
|
212
|
+
[131072, 196605],
|
|
213
|
+
[196608, 262141]
|
|
100
214
|
];
|
|
101
215
|
const ambiguousWidthRanges = [
|
|
102
216
|
[161, 161],
|
|
@@ -152,6 +266,7 @@ const ambiguousWidthRanges = [
|
|
|
152
266
|
[728, 731],
|
|
153
267
|
[733, 733],
|
|
154
268
|
[735, 735],
|
|
269
|
+
[768, 879],
|
|
155
270
|
[913, 929],
|
|
156
271
|
[931, 937],
|
|
157
272
|
[945, 961],
|
|
@@ -159,7 +274,8 @@ const ambiguousWidthRanges = [
|
|
|
159
274
|
[1025, 1025],
|
|
160
275
|
[1040, 1103],
|
|
161
276
|
[1105, 1105],
|
|
162
|
-
[8208,
|
|
277
|
+
[8208, 8208],
|
|
278
|
+
[8211, 8214],
|
|
163
279
|
[8216, 8217],
|
|
164
280
|
[8220, 8221],
|
|
165
281
|
[8224, 8226],
|
|
@@ -221,7 +337,8 @@ const ambiguousWidthRanges = [
|
|
|
221
337
|
[8895, 8895],
|
|
222
338
|
[8978, 8978],
|
|
223
339
|
[9312, 9449],
|
|
224
|
-
[9451,
|
|
340
|
+
[9451, 9547],
|
|
341
|
+
[9552, 9587],
|
|
225
342
|
[9600, 9615],
|
|
226
343
|
[9618, 9621],
|
|
227
344
|
[9632, 9633],
|
|
@@ -247,14 +364,40 @@ const ambiguousWidthRanges = [
|
|
|
247
364
|
[9831, 9834],
|
|
248
365
|
[9836, 9837],
|
|
249
366
|
[9839, 9839],
|
|
367
|
+
[9886, 9887],
|
|
368
|
+
[9919, 9919],
|
|
369
|
+
[9926, 9933],
|
|
370
|
+
[9935, 9939],
|
|
371
|
+
[9941, 9953],
|
|
372
|
+
[9955, 9955],
|
|
373
|
+
[9960, 9961],
|
|
374
|
+
[9963, 9969],
|
|
375
|
+
[9972, 9972],
|
|
376
|
+
[9974, 9977],
|
|
377
|
+
[9979, 9980],
|
|
378
|
+
[9982, 9983],
|
|
250
379
|
[10045, 10045],
|
|
251
380
|
[10102, 10111],
|
|
252
|
-
[11094,
|
|
381
|
+
[11094, 11097],
|
|
382
|
+
[12872, 12879],
|
|
253
383
|
[57344, 63743],
|
|
254
|
-
[
|
|
384
|
+
[65024, 65039],
|
|
385
|
+
[65533, 65533],
|
|
386
|
+
[127232, 127242],
|
|
387
|
+
[127248, 127277],
|
|
388
|
+
[127280, 127337],
|
|
389
|
+
[127344, 127373],
|
|
390
|
+
[127375, 127376],
|
|
391
|
+
[127387, 127404],
|
|
392
|
+
[917760, 917999],
|
|
393
|
+
[983040, 1048573],
|
|
394
|
+
[1048576, 1114109]
|
|
255
395
|
];
|
|
396
|
+
|
|
397
|
+
//#endregion
|
|
398
|
+
//#region src/core/buffer/width.ts
|
|
256
399
|
function isFullWidthCodePoint(codePoint) {
|
|
257
|
-
if (codePoint < 4352
|
|
400
|
+
if (codePoint < 4352) return false;
|
|
258
401
|
for (const [start, end] of fullWidthRanges) {
|
|
259
402
|
if (codePoint < start) return false;
|
|
260
403
|
if (codePoint <= end) return true;
|
|
@@ -262,13 +405,22 @@ function isFullWidthCodePoint(codePoint) {
|
|
|
262
405
|
return false;
|
|
263
406
|
}
|
|
264
407
|
function isAmbiguousWidthCodePoint(codePoint) {
|
|
265
|
-
|
|
408
|
+
const first = ambiguousWidthRanges[0];
|
|
409
|
+
const last = ambiguousWidthRanges[ambiguousWidthRanges.length - 1];
|
|
410
|
+
if (!first || !last) return false;
|
|
411
|
+
if (codePoint < first[0] || codePoint > last[1]) return false;
|
|
266
412
|
for (const [start, end] of ambiguousWidthRanges) {
|
|
267
413
|
if (codePoint < start) return false;
|
|
268
414
|
if (codePoint <= end) return true;
|
|
269
415
|
}
|
|
270
416
|
return false;
|
|
271
417
|
}
|
|
418
|
+
function isVariationSelectorCodePoint(codePoint) {
|
|
419
|
+
return codePoint >= 65024 && codePoint <= 65039 || codePoint >= 917760 && codePoint <= 917999;
|
|
420
|
+
}
|
|
421
|
+
function isCombiningMarkCodePoint(codePoint) {
|
|
422
|
+
return codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071 || codePoint >= 12330 && codePoint <= 12335 || codePoint >= 12441 && codePoint <= 12442 || codePoint === 94180;
|
|
423
|
+
}
|
|
272
424
|
function isEmojiLike(codePoint) {
|
|
273
425
|
return codePoint >= 127744 && codePoint <= 129791 || codePoint >= 127462 && codePoint <= 127487;
|
|
274
426
|
}
|
|
@@ -303,6 +455,8 @@ function charCellWidth(text, provider = "default") {
|
|
|
303
455
|
const codePoint = text.codePointAt(0);
|
|
304
456
|
if (codePoint == null) return 1;
|
|
305
457
|
const hasVs16 = text.includes("️");
|
|
458
|
+
if (isVariationSelectorCodePoint(codePoint) || isCombiningMarkCodePoint(codePoint)) return 1;
|
|
459
|
+
if (codePoint >= 9472 && codePoint <= 9599) return 1;
|
|
306
460
|
if (isFullWidthCodePoint(codePoint)) return 2;
|
|
307
461
|
if (provider === "cjk" && isAmbiguousWidthCodePoint(codePoint)) return 2;
|
|
308
462
|
if (isEmojiLike(codePoint)) return 2;
|
|
@@ -317,103 +471,4 @@ function charCellWidth(text, provider = "default") {
|
|
|
317
471
|
}
|
|
318
472
|
|
|
319
473
|
//#endregion
|
|
320
|
-
|
|
321
|
-
const ENCODED_ASCII_CONTROL_RE = /%(?:0[0-9a-f]|1[0-9a-f]|7f)/i;
|
|
322
|
-
function hasControlCodePoint(value) {
|
|
323
|
-
for (let i = 0; i < value.length; i++) {
|
|
324
|
-
const code = value.charCodeAt(i);
|
|
325
|
-
if (code <= 31 || code >= 127 && code <= 159) return true;
|
|
326
|
-
}
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
function hasEncodedControl(value) {
|
|
330
|
-
let current = String(value ?? "");
|
|
331
|
-
for (let depth = 0; depth < 3; depth++) {
|
|
332
|
-
if (ENCODED_ASCII_CONTROL_RE.test(current)) return true;
|
|
333
|
-
let decoded;
|
|
334
|
-
try {
|
|
335
|
-
decoded = decodeURIComponent(current);
|
|
336
|
-
} catch {
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
if (hasControlCodePoint(decoded)) return true;
|
|
340
|
-
if (decoded === current) return false;
|
|
341
|
-
current = decoded;
|
|
342
|
-
}
|
|
343
|
-
return ENCODED_ASCII_CONTROL_RE.test(current) || hasControlCodePoint(current);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
//#endregion
|
|
347
|
-
//#region src/core/hyperlink.ts
|
|
348
|
-
const SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
349
|
-
const BLOCKED_SCHEME_RE = /^(?:javascript|data|vbscript):/i;
|
|
350
|
-
const SAFE_RELATIVE_HREF_RE = /^(?:[A-Za-z0-9._~!$&()*+,;=:@/?#-]|%[0-9A-Fa-f]{2})+$/u;
|
|
351
|
-
function normalizeRawHref(value) {
|
|
352
|
-
if (typeof value !== "string") return null;
|
|
353
|
-
const raw = value.trim();
|
|
354
|
-
if (!raw) return null;
|
|
355
|
-
if (raw !== value) return null;
|
|
356
|
-
for (let i = 0; i < value.length; i++) {
|
|
357
|
-
const code = value.charCodeAt(i);
|
|
358
|
-
if (code <= 31 || code >= 127 && code <= 159) return null;
|
|
359
|
-
}
|
|
360
|
-
if (/\s/u.test(raw)) return null;
|
|
361
|
-
if (raw.startsWith("//")) return null;
|
|
362
|
-
if (BLOCKED_SCHEME_RE.test(raw)) return null;
|
|
363
|
-
if (hasEncodedControl(raw)) return null;
|
|
364
|
-
return raw;
|
|
365
|
-
}
|
|
366
|
-
function hrefScheme(raw) {
|
|
367
|
-
return raw.match(SCHEME_RE)?.[0].toLowerCase() ?? null;
|
|
368
|
-
}
|
|
369
|
-
function parseSafeAbsoluteUrl(raw) {
|
|
370
|
-
if (raw.includes("\\")) return null;
|
|
371
|
-
try {
|
|
372
|
-
return new URL(raw);
|
|
373
|
-
} catch {
|
|
374
|
-
return null;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
function sanitizeAbsoluteHref(raw, options = {}) {
|
|
378
|
-
const url = parseSafeAbsoluteUrl(raw);
|
|
379
|
-
if (!url) return null;
|
|
380
|
-
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
381
|
-
if (!/^https?:\/\//i.test(raw)) return null;
|
|
382
|
-
return options.preserveHttpHref ? raw : url.toString();
|
|
383
|
-
}
|
|
384
|
-
if (url.protocol === "mailto:") return raw;
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
function isSafeNormalizedRelativeHref(raw) {
|
|
388
|
-
if (raw.includes("\\")) return false;
|
|
389
|
-
if (raw.startsWith("//")) return false;
|
|
390
|
-
if (SCHEME_RE.test(raw)) return false;
|
|
391
|
-
if (hasEncodedControl(raw)) return false;
|
|
392
|
-
if (!SAFE_RELATIVE_HREF_RE.test(raw)) return false;
|
|
393
|
-
return raw.startsWith("#") || raw.startsWith("?") || raw.startsWith("/") || raw.startsWith("./") || raw.startsWith("../") || /^[A-Za-z0-9._~-]/u.test(raw);
|
|
394
|
-
}
|
|
395
|
-
function isSafeRelativeHref(value) {
|
|
396
|
-
const raw = normalizeRawHref(value);
|
|
397
|
-
return raw != null && isSafeNormalizedRelativeHref(raw);
|
|
398
|
-
}
|
|
399
|
-
function sanitizeTerminalHref(value, options = {}) {
|
|
400
|
-
const raw = normalizeRawHref(value);
|
|
401
|
-
if (!raw) return null;
|
|
402
|
-
const sanitized = sanitizeAbsoluteHref(raw, { preserveHttpHref: true });
|
|
403
|
-
if (sanitized) return sanitized;
|
|
404
|
-
if (options.allowFileUrls) {
|
|
405
|
-
const url = parseSafeAbsoluteUrl(raw);
|
|
406
|
-
if (url?.protocol === "file:") return url.toString();
|
|
407
|
-
}
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
function sanitizeDomHref(value, options = {}) {
|
|
411
|
-
const raw = normalizeRawHref(value);
|
|
412
|
-
if (!raw) return null;
|
|
413
|
-
const scheme = hrefScheme(raw);
|
|
414
|
-
if (!scheme) return options.allowRelative !== false && isSafeNormalizedRelativeHref(raw) ? raw : null;
|
|
415
|
-
return sanitizeAbsoluteHref(raw);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
//#endregion
|
|
419
|
-
export { charCellWidth, hasEncodedControl, isSafeRelativeHref, sanitizeDomHref, sanitizeTerminalHref, segmentedGraphemes };
|
|
474
|
+
export { charCellWidth, segmentedGraphemes };
|