@simon_he/vue-tui 0.0.7 → 1.0.0-rc.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 +222 -444
- package/dist/TSelect-BmSkar0D.js +8697 -0
- package/dist/ansi-palette-Bv5Vqr4k.js +1499 -0
- package/dist/ansi-styles.d.ts +200 -0
- package/dist/cli/headless-renderer.d.ts +29 -0
- package/dist/cli/input.d.ts +49 -0
- package/dist/cli/node-file-writers.d.ts +12 -0
- package/dist/cli/node-module.d.ts +2 -0
- package/dist/cli/parse-kitty.d.ts +2 -0
- package/dist/cli/parse-mouse.d.ts +2 -0
- package/dist/cli/parse-utils.d.ts +14 -0
- package/dist/cli/parse-xterm.d.ts +2 -0
- package/dist/cli/path-provider-types.d.ts +1 -0
- package/dist/cli/path-provider.d.ts +4 -0
- package/dist/cli/path-suggest-core.d.ts +1 -0
- package/dist/cli/path-suggest.d.ts +15 -0
- package/dist/cli/recording.d.ts +4 -0
- package/dist/cli/stdin-buffer.d.ts +33 -0
- package/dist/cli.cjs +10664 -0
- package/dist/cli.d.cts +22 -0
- package/dist/cli.d.ts +22 -0
- package/dist/cli.js +9521 -0
- package/dist/core/ansi/capability.d.ts +20 -0
- package/dist/core/ansi/colors.d.ts +41 -0
- package/dist/core/ansi/sgr.d.ts +7 -0
- package/dist/core/ansi/theme.d.ts +6 -0
- package/dist/core/ansi-palette.d.ts +14 -0
- package/dist/core/buffer/buffer.d.ts +54 -0
- package/dist/core/buffer/width.d.ts +4 -0
- package/dist/core/debug-logger.d.ts +18 -0
- package/dist/core/hyperlink.d.ts +9 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/path-provider-types.d.ts +24 -0
- package/dist/core/path-suggest.d.ts +35 -0
- package/dist/core/render-plane.d.ts +3 -0
- package/dist/core/terminal/create-terminal.d.ts +7 -0
- package/dist/core/terminal/emitter.d.ts +7 -0
- package/dist/core/types.d.ts +107 -0
- package/dist/core.cjs +3072 -0
- package/dist/core.d.cts +14 -0
- package/dist/core.d.ts +14 -0
- package/dist/core.js +422 -0
- package/dist/create-terminal-app.d.ts +34 -0
- package/dist/dom-renderer-CDVQIcIL.js +1172 -0
- package/dist/events/index.d.ts +6 -0
- package/dist/events/manager/cli-event-manager.d.ts +22 -0
- package/dist/events/manager/event-manager.d.ts +30 -0
- package/dist/events/manager/selection-suppression.d.ts +3 -0
- package/dist/events/manager/types.d.ts +108 -0
- package/dist/events/recording.d.ts +44 -0
- package/dist/experimental.cjs +9380 -0
- package/dist/experimental.d.cts +39 -0
- package/dist/experimental.d.ts +39 -0
- package/dist/experimental.js +7624 -0
- package/dist/frame-perf-C-w8mjJL.js +98 -0
- package/dist/hyperlink-B5PD7a3Q.js +331 -0
- package/dist/index.cjs +12037 -16507
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -1353
- package/dist/index.js +13 -18738
- package/dist/markdown.cjs +21929 -0
- package/dist/markdown.d.cts +10 -0
- package/dist/markdown.d.ts +10 -0
- package/dist/markdown.js +1649 -0
- package/dist/observability/cli-latency-node.d.ts +3 -0
- package/dist/observability/cli-latency-types.d.ts +41 -0
- package/dist/observability/cli-latency.d.ts +3 -0
- package/dist/observability/frame-perf-store.d.ts +13 -0
- package/dist/observability/frame-perf.d.ts +40 -0
- package/dist/observability/trace.d.ts +40 -0
- package/dist/observability/tui-profiler.d.ts +33 -0
- package/dist/observability.cjs +99 -0
- package/dist/observability.d.cts +6 -0
- package/dist/observability.d.ts +6 -0
- package/dist/observability.js +3 -0
- package/dist/path-DDiSCXrQ.js +99 -0
- package/dist/path-suggest-0Q2BDsuj.js +274 -0
- package/dist/path-suggest-Dk9TRLh5.js +3 -0
- package/dist/{path-suggest-CZQYJIIg.js → path-suggest-bvR9SY6Q.js} +86 -18
- package/dist/renderer/capabilities.d.ts +13 -0
- package/dist/renderer/cli/index.d.ts +2 -0
- package/dist/renderer/cli/stdout-metrics.d.ts +18 -0
- package/dist/renderer/cli/stdout-renderer.d.ts +48 -0
- package/dist/renderer/dom/dom-renderer.d.ts +157 -0
- package/dist/renderer/dom/index.d.ts +2 -0
- package/dist/renderer/index.d.ts +2 -0
- package/dist/renderer-dom.cjs +1511 -0
- package/dist/renderer-dom.d.cts +4 -0
- package/dist/renderer-dom.d.ts +4 -0
- package/dist/renderer-dom.js +6 -0
- package/dist/runtime/index.d.ts +36 -0
- package/dist/runtime/osc52.d.ts +9 -0
- package/dist/runtime-DtrcQidD.js +1197 -0
- package/dist/runtime.cjs +1697 -0
- package/dist/runtime.d.cts +9 -0
- package/dist/runtime.d.ts +9 -0
- package/dist/runtime.js +4 -0
- package/dist/selection/terminal-selection.d.ts +122 -0
- package/dist/sgr-DMK2AvuT.js +304 -0
- package/dist/style-cache-i0ZABZRq.js +178 -0
- package/dist/terminal-selection-BCOh9jsL.js +329 -0
- package/dist/utils/env.d.ts +3 -0
- package/dist/utils/newlines.d.ts +1 -0
- package/dist/utils/path.d.ts +7 -0
- package/dist/utils/url-safety.d.ts +2 -0
- package/dist/vue/components/TAnchor.d.ts +108 -0
- package/dist/vue/components/TBox.d.ts +144 -0
- package/dist/vue/components/TDebugOverlay.d.ts +43 -0
- package/dist/vue/components/TDialog.d.ts +256 -0
- package/dist/vue/components/TFlow.d.ts +85 -0
- package/dist/vue/components/TInput.d.ts +554 -0
- package/dist/vue/components/TInputBox.d.ts +158 -0
- package/dist/vue/components/TJsonEditor.d.ts +165 -0
- package/dist/vue/components/TList.d.ts +119 -0
- package/dist/vue/components/TLogLinksPanel.d.ts +238 -0
- package/dist/vue/components/TLogMinimap.d.ts +263 -0
- package/dist/vue/components/TLogScrollbar.d.ts +236 -0
- package/dist/vue/components/TLogSearchBar.d.ts +267 -0
- package/dist/vue/components/TLogSearchPager.d.ts +162 -0
- package/dist/vue/components/TLogSearchResults.d.ts +200 -0
- package/dist/vue/components/TLogView.d.ts +502 -0
- package/dist/vue/components/TLogVirtualLinksPanel.d.ts +141 -0
- package/dist/vue/components/TLogVirtualSearchResults.d.ts +146 -0
- package/dist/vue/components/TMarkdownText.d.ts +134 -0
- package/dist/vue/components/TMultilineModal.d.ts +62 -0
- package/dist/vue/components/TPathPicker.d.ts +213 -0
- package/dist/vue/components/TRenderLayer.d.ts +16 -0
- package/dist/vue/components/TRenderPlane.d.ts +17 -0
- package/dist/vue/components/TSelect.d.ts +215 -0
- package/dist/vue/components/TText.d.ts +116 -0
- package/dist/vue/components/TTransition.d.ts +83 -0
- package/dist/vue/components/TView.d.ts +127 -0
- package/dist/vue/components/TVirtualList.d.ts +182 -0
- package/dist/vue/components/TVirtualMarkdown.d.ts +168 -0
- package/dist/vue/components/TerminalProvider.d.ts +195 -0
- package/dist/vue/components/input/host.d.ts +17 -0
- package/dist/vue/components/input/plugins/hostPlugin.d.ts +7 -0
- package/dist/vue/components/input/plugins/hostPlugin.node.d.ts +15 -0
- package/dist/vue/components/input/plugins/mentionUtils.d.ts +17 -0
- package/dist/vue/components/input/plugins/nodeMentionPathProvider.d.ts +2 -0
- package/dist/vue/components/input/plugins/promptMentionPlugin.d.ts +8 -0
- package/dist/vue/components/input/plugins/promptMentionState.d.ts +98 -0
- package/dist/vue/components/input/plugins/restrictText.d.ts +27 -0
- package/dist/vue/components/input/plugins/types.d.ts +90 -0
- package/dist/vue/components/input/utils/inlineText.d.ts +57 -0
- package/dist/vue/components/input/utils/inlineTextTokens.d.ts +34 -0
- package/dist/vue/components/input/utils/primitives.d.ts +3 -0
- package/dist/vue/components/input/utils/wordNavigation.d.ts +6 -0
- package/dist/vue/components/list/list-geometry.d.ts +16 -0
- package/dist/vue/components/list/list-paint.d.ts +1 -0
- package/dist/vue/components/list/scroll-state.d.ts +25 -0
- package/dist/vue/components/list/selection-state.d.ts +6 -0
- package/dist/vue/components/terminal-provider/copy-toast.d.ts +6 -0
- package/dist/vue/components/terminal-provider/portals.d.ts +17 -0
- package/dist/vue/components/terminal-provider/scheduler.d.ts +29 -0
- package/dist/vue/components/terminal-provider/selection-config.d.ts +15 -0
- package/dist/vue/components/terminal-provider/utils.d.ts +5 -0
- package/dist/vue/composables/use-layout.d.ts +2 -0
- package/dist/vue/composables/use-render-node.d.ts +19 -0
- package/dist/vue/composables/use-render-stack.d.ts +3 -0
- package/dist/vue/composables/use-runtime.d.ts +5 -0
- package/dist/vue/composables/use-terminal-node.d.ts +14 -0
- package/dist/vue/composables/use-terminal.d.ts +2 -0
- package/dist/vue/composables/use-visibility.d.ts +12 -0
- package/dist/vue/context.d.ts +153 -0
- package/dist/vue/index.d.ts +39 -0
- package/dist/vue/injection-key.d.ts +2 -0
- package/dist/vue/log/append-only-log-store.d.ts +2 -0
- package/dist/vue/log/tlog-keymap.d.ts +28 -0
- package/dist/vue/log/tlog-plugins.d.ts +144 -0
- package/dist/vue/log/tlog-session.d.ts +81 -0
- package/dist/vue/log/tlog-theme.d.ts +68 -0
- package/dist/vue/log/types.d.ts +43 -0
- package/dist/vue/log/use-tlog-link-controller.d.ts +31 -0
- package/dist/vue/log/use-tlog-retained-index.d.ts +26 -0
- package/dist/vue/log/use-tlog-search-controller.d.ts +51 -0
- package/dist/vue/log/use-tlog-search-results-page.d.ts +31 -0
- package/dist/vue/log/use-tlog-virtual-search-results.d.ts +22 -0
- package/dist/vue/markdown/ast.d.ts +3 -0
- package/dist/vue/markdown/block-source.d.ts +22 -0
- package/dist/vue/markdown/document.d.ts +18 -0
- package/dist/vue/markdown/layout.d.ts +16 -0
- package/dist/vue/markdown/parser.d.ts +11 -0
- package/dist/vue/markdown/render.d.ts +10 -0
- package/dist/vue/markdown/theme.d.ts +186 -0
- package/dist/vue/markdown/types.d.ts +47 -0
- package/dist/vue/render/context.d.ts +3 -0
- package/dist/vue/render/render-manager.d.ts +94 -0
- package/dist/vue/router/RouterView.d.ts +25 -0
- package/dist/vue/router/composables.d.ts +4 -0
- package/dist/vue/router/context.d.ts +4 -0
- package/dist/vue/router/router.d.ts +7 -0
- package/dist/vue/router/types.d.ts +29 -0
- package/dist/vue/scheduler/frame-mailbox.d.ts +55 -0
- package/dist/vue/scheduler/frame-scheduler.d.ts +51 -0
- package/dist/vue/utils/frame-task.d.ts +6 -0
- package/dist/vue/utils/rect.d.ts +4 -0
- package/dist/vue/utils/style-cache.d.ts +3 -0
- package/dist/vue/utils/text.d.ts +26 -0
- package/dist/vue/utils/wheel-scroll.d.ts +18 -0
- package/dist/vue.cjs +18882 -0
- package/dist/vue.d.cts +3 -0
- package/dist/vue.d.ts +3 -0
- package/dist/vue.js +3066 -0
- package/dist/wheel-scroll-B-WlFuNB.js +819 -0
- package/package.json +226 -58
- package/dist/path-suggest-DIMby3r0.js +0 -3
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { computed, ref, shallowReactive } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/observability/frame-perf-store.ts
|
|
4
|
+
function createFramePerfStore(limit = 120, opts) {
|
|
5
|
+
const max = Math.max(1, Math.floor(limit));
|
|
6
|
+
const manualEnabled = ref(Boolean(opts?.enabled));
|
|
7
|
+
const leaseCount = ref(0);
|
|
8
|
+
const enabled = computed({
|
|
9
|
+
get: () => manualEnabled.value || leaseCount.value > 0,
|
|
10
|
+
set: (next) => {
|
|
11
|
+
manualEnabled.value = Boolean(next);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const samples = [];
|
|
15
|
+
function acquire(_reason) {
|
|
16
|
+
leaseCount.value++;
|
|
17
|
+
let released = false;
|
|
18
|
+
return () => {
|
|
19
|
+
if (released) return;
|
|
20
|
+
released = true;
|
|
21
|
+
leaseCount.value = Math.max(0, leaseCount.value - 1);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function push(sample) {
|
|
25
|
+
if (!enabled.value) return;
|
|
26
|
+
samples.push(sample);
|
|
27
|
+
if (samples.length > max) samples.splice(0, samples.length - max);
|
|
28
|
+
}
|
|
29
|
+
function latest() {
|
|
30
|
+
return samples.length > 0 ? samples[samples.length - 1] : null;
|
|
31
|
+
}
|
|
32
|
+
function list() {
|
|
33
|
+
return samples.slice();
|
|
34
|
+
}
|
|
35
|
+
function clear() {
|
|
36
|
+
samples.length = 0;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
enabled,
|
|
40
|
+
acquire,
|
|
41
|
+
push,
|
|
42
|
+
latest,
|
|
43
|
+
list,
|
|
44
|
+
clear
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/observability/trace.ts
|
|
50
|
+
function createTraceStore(opts) {
|
|
51
|
+
const enabled = ref(Boolean(opts?.enabled));
|
|
52
|
+
const records = shallowReactive([]);
|
|
53
|
+
const max = Math.max(10, Math.floor(opts?.max ?? 400));
|
|
54
|
+
function push(record) {
|
|
55
|
+
if (!enabled.value) return;
|
|
56
|
+
records.push(record);
|
|
57
|
+
if (records.length > max) records.splice(0, records.length - max);
|
|
58
|
+
}
|
|
59
|
+
function clear() {
|
|
60
|
+
records.splice(0, records.length);
|
|
61
|
+
}
|
|
62
|
+
function snapshot() {
|
|
63
|
+
return records.slice();
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
enabled,
|
|
67
|
+
records,
|
|
68
|
+
push,
|
|
69
|
+
clear,
|
|
70
|
+
snapshot
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/observability/frame-perf.ts
|
|
76
|
+
const FRAME_PERF_REASON_PRIORITY = {
|
|
77
|
+
unknown: 0,
|
|
78
|
+
manual: 1,
|
|
79
|
+
data: 2,
|
|
80
|
+
selection: 3,
|
|
81
|
+
stream: 4,
|
|
82
|
+
resize: 5,
|
|
83
|
+
scroll: 6,
|
|
84
|
+
input: 7
|
|
85
|
+
};
|
|
86
|
+
function framePerfNow() {
|
|
87
|
+
const p = globalThis.performance;
|
|
88
|
+
if (p && typeof p.now === "function") return p.now();
|
|
89
|
+
return Date.now();
|
|
90
|
+
}
|
|
91
|
+
function mergeFramePerfReason(prev, next) {
|
|
92
|
+
const a = prev ?? "unknown";
|
|
93
|
+
const b = next ?? "unknown";
|
|
94
|
+
return FRAME_PERF_REASON_PRIORITY[b] > FRAME_PERF_REASON_PRIORITY[a] ? b : a;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { createFramePerfStore, createTraceStore, framePerfNow, mergeFramePerfReason };
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
//#region src/core/buffer/width.ts
|
|
2
|
+
const fullWidthRanges = [
|
|
3
|
+
[4352, 4447],
|
|
4
|
+
[9001, 9002],
|
|
5
|
+
[11904, 42191],
|
|
6
|
+
[44032, 55203],
|
|
7
|
+
[63744, 64255],
|
|
8
|
+
[65040, 65049],
|
|
9
|
+
[65072, 65135],
|
|
10
|
+
[65280, 65376],
|
|
11
|
+
[65504, 65510]
|
|
12
|
+
];
|
|
13
|
+
const ambiguousWidthRanges = [
|
|
14
|
+
[161, 161],
|
|
15
|
+
[164, 164],
|
|
16
|
+
[167, 168],
|
|
17
|
+
[170, 170],
|
|
18
|
+
[173, 174],
|
|
19
|
+
[176, 180],
|
|
20
|
+
[182, 186],
|
|
21
|
+
[188, 191],
|
|
22
|
+
[198, 198],
|
|
23
|
+
[208, 208],
|
|
24
|
+
[215, 216],
|
|
25
|
+
[222, 225],
|
|
26
|
+
[230, 230],
|
|
27
|
+
[232, 234],
|
|
28
|
+
[236, 237],
|
|
29
|
+
[240, 240],
|
|
30
|
+
[242, 243],
|
|
31
|
+
[247, 250],
|
|
32
|
+
[252, 252],
|
|
33
|
+
[254, 254],
|
|
34
|
+
[257, 257],
|
|
35
|
+
[273, 273],
|
|
36
|
+
[275, 275],
|
|
37
|
+
[283, 283],
|
|
38
|
+
[294, 295],
|
|
39
|
+
[299, 299],
|
|
40
|
+
[305, 307],
|
|
41
|
+
[312, 312],
|
|
42
|
+
[319, 322],
|
|
43
|
+
[324, 324],
|
|
44
|
+
[328, 331],
|
|
45
|
+
[333, 333],
|
|
46
|
+
[338, 339],
|
|
47
|
+
[358, 359],
|
|
48
|
+
[363, 363],
|
|
49
|
+
[462, 462],
|
|
50
|
+
[464, 464],
|
|
51
|
+
[466, 466],
|
|
52
|
+
[468, 468],
|
|
53
|
+
[470, 470],
|
|
54
|
+
[472, 472],
|
|
55
|
+
[474, 474],
|
|
56
|
+
[476, 476],
|
|
57
|
+
[593, 593],
|
|
58
|
+
[609, 609],
|
|
59
|
+
[708, 708],
|
|
60
|
+
[711, 711],
|
|
61
|
+
[713, 715],
|
|
62
|
+
[717, 717],
|
|
63
|
+
[720, 720],
|
|
64
|
+
[728, 731],
|
|
65
|
+
[733, 733],
|
|
66
|
+
[735, 735],
|
|
67
|
+
[913, 929],
|
|
68
|
+
[931, 937],
|
|
69
|
+
[945, 961],
|
|
70
|
+
[963, 969],
|
|
71
|
+
[1025, 1025],
|
|
72
|
+
[1040, 1103],
|
|
73
|
+
[1105, 1105],
|
|
74
|
+
[8208, 8213],
|
|
75
|
+
[8216, 8217],
|
|
76
|
+
[8220, 8221],
|
|
77
|
+
[8224, 8226],
|
|
78
|
+
[8228, 8231],
|
|
79
|
+
[8240, 8240],
|
|
80
|
+
[8242, 8243],
|
|
81
|
+
[8245, 8245],
|
|
82
|
+
[8251, 8251],
|
|
83
|
+
[8254, 8254],
|
|
84
|
+
[8308, 8308],
|
|
85
|
+
[8319, 8319],
|
|
86
|
+
[8321, 8324],
|
|
87
|
+
[8364, 8364],
|
|
88
|
+
[8451, 8451],
|
|
89
|
+
[8453, 8453],
|
|
90
|
+
[8457, 8457],
|
|
91
|
+
[8467, 8467],
|
|
92
|
+
[8470, 8470],
|
|
93
|
+
[8481, 8482],
|
|
94
|
+
[8486, 8486],
|
|
95
|
+
[8491, 8491],
|
|
96
|
+
[8531, 8532],
|
|
97
|
+
[8539, 8542],
|
|
98
|
+
[8544, 8555],
|
|
99
|
+
[8560, 8569],
|
|
100
|
+
[8585, 8585],
|
|
101
|
+
[8592, 8601],
|
|
102
|
+
[8632, 8633],
|
|
103
|
+
[8658, 8658],
|
|
104
|
+
[8660, 8660],
|
|
105
|
+
[8679, 8679],
|
|
106
|
+
[8704, 8704],
|
|
107
|
+
[8706, 8707],
|
|
108
|
+
[8711, 8712],
|
|
109
|
+
[8715, 8715],
|
|
110
|
+
[8719, 8719],
|
|
111
|
+
[8721, 8721],
|
|
112
|
+
[8725, 8725],
|
|
113
|
+
[8730, 8730],
|
|
114
|
+
[8733, 8736],
|
|
115
|
+
[8739, 8739],
|
|
116
|
+
[8741, 8741],
|
|
117
|
+
[8743, 8748],
|
|
118
|
+
[8750, 8750],
|
|
119
|
+
[8756, 8759],
|
|
120
|
+
[8764, 8765],
|
|
121
|
+
[8776, 8776],
|
|
122
|
+
[8780, 8780],
|
|
123
|
+
[8786, 8786],
|
|
124
|
+
[8800, 8801],
|
|
125
|
+
[8804, 8807],
|
|
126
|
+
[8810, 8811],
|
|
127
|
+
[8814, 8815],
|
|
128
|
+
[8834, 8835],
|
|
129
|
+
[8838, 8839],
|
|
130
|
+
[8853, 8853],
|
|
131
|
+
[8857, 8857],
|
|
132
|
+
[8869, 8869],
|
|
133
|
+
[8895, 8895],
|
|
134
|
+
[8978, 8978],
|
|
135
|
+
[9312, 9449],
|
|
136
|
+
[9451, 9471],
|
|
137
|
+
[9600, 9615],
|
|
138
|
+
[9618, 9621],
|
|
139
|
+
[9632, 9633],
|
|
140
|
+
[9635, 9641],
|
|
141
|
+
[9650, 9651],
|
|
142
|
+
[9654, 9655],
|
|
143
|
+
[9660, 9661],
|
|
144
|
+
[9664, 9665],
|
|
145
|
+
[9670, 9672],
|
|
146
|
+
[9675, 9675],
|
|
147
|
+
[9678, 9681],
|
|
148
|
+
[9698, 9701],
|
|
149
|
+
[9711, 9711],
|
|
150
|
+
[9733, 9734],
|
|
151
|
+
[9737, 9737],
|
|
152
|
+
[9742, 9743],
|
|
153
|
+
[9756, 9756],
|
|
154
|
+
[9758, 9758],
|
|
155
|
+
[9792, 9792],
|
|
156
|
+
[9794, 9794],
|
|
157
|
+
[9824, 9825],
|
|
158
|
+
[9827, 9829],
|
|
159
|
+
[9831, 9834],
|
|
160
|
+
[9836, 9837],
|
|
161
|
+
[9839, 9839],
|
|
162
|
+
[10045, 10045],
|
|
163
|
+
[10102, 10111],
|
|
164
|
+
[11094, 11094],
|
|
165
|
+
[57344, 63743],
|
|
166
|
+
[65533, 65533]
|
|
167
|
+
];
|
|
168
|
+
function isFullWidthCodePoint(codePoint) {
|
|
169
|
+
if (codePoint < 4352 || codePoint > 65510) return false;
|
|
170
|
+
for (const [start, end] of fullWidthRanges) {
|
|
171
|
+
if (codePoint < start) return false;
|
|
172
|
+
if (codePoint <= end) return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
function isAmbiguousWidthCodePoint(codePoint) {
|
|
177
|
+
if (codePoint < 161 || codePoint > 65533) return false;
|
|
178
|
+
for (const [start, end] of ambiguousWidthRanges) {
|
|
179
|
+
if (codePoint < start) return false;
|
|
180
|
+
if (codePoint <= end) return true;
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
function isEmojiLike(codePoint) {
|
|
185
|
+
return codePoint >= 127744 && codePoint <= 129791 || codePoint >= 127462 && codePoint <= 127487;
|
|
186
|
+
}
|
|
187
|
+
let extendedPictographicRe = null;
|
|
188
|
+
try {
|
|
189
|
+
extendedPictographicRe = new RegExp("\\p{Extended_Pictographic}", "u");
|
|
190
|
+
} catch {
|
|
191
|
+
extendedPictographicRe = null;
|
|
192
|
+
}
|
|
193
|
+
let emojiPresentationRe = null;
|
|
194
|
+
try {
|
|
195
|
+
emojiPresentationRe = new RegExp("\\p{Emoji_Presentation}", "u");
|
|
196
|
+
} catch {
|
|
197
|
+
emojiPresentationRe = null;
|
|
198
|
+
}
|
|
199
|
+
let emojiRe = null;
|
|
200
|
+
try {
|
|
201
|
+
emojiRe = new RegExp("\\p{Emoji}", "u");
|
|
202
|
+
} catch {
|
|
203
|
+
emojiRe = null;
|
|
204
|
+
}
|
|
205
|
+
function normalizeCustomWidth(width) {
|
|
206
|
+
return width === 2 ? 2 : 1;
|
|
207
|
+
}
|
|
208
|
+
function charCellWidth(text, provider = "default") {
|
|
209
|
+
if (!text) return 1;
|
|
210
|
+
if (typeof provider === "function") return normalizeCustomWidth(provider(text));
|
|
211
|
+
if (provider !== "cjk" && text.length === 1) {
|
|
212
|
+
const code = text.charCodeAt(0);
|
|
213
|
+
if (code < 4352) return 1;
|
|
214
|
+
}
|
|
215
|
+
const codePoint = text.codePointAt(0);
|
|
216
|
+
if (codePoint == null) return 1;
|
|
217
|
+
const hasVs16 = text.includes("️");
|
|
218
|
+
if (isFullWidthCodePoint(codePoint)) return 2;
|
|
219
|
+
if (provider === "cjk" && isAmbiguousWidthCodePoint(codePoint)) return 2;
|
|
220
|
+
if (isEmojiLike(codePoint)) return 2;
|
|
221
|
+
if (emojiPresentationRe?.test(text)) return 2;
|
|
222
|
+
if (text.includes("⃣")) return 2;
|
|
223
|
+
if (hasVs16 && emojiRe?.test(text)) return 2;
|
|
224
|
+
if (extendedPictographicRe?.test(text)) {
|
|
225
|
+
if (codePoint <= 65535) return hasVs16 ? 2 : 1;
|
|
226
|
+
return 2;
|
|
227
|
+
}
|
|
228
|
+
return 1;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/utils/url-safety.ts
|
|
233
|
+
const ENCODED_ASCII_CONTROL_RE = /%(?:0[0-9a-f]|1[0-9a-f]|7f)/i;
|
|
234
|
+
function hasControlCodePoint(value) {
|
|
235
|
+
for (let i = 0; i < value.length; i++) {
|
|
236
|
+
const code = value.charCodeAt(i);
|
|
237
|
+
if (code <= 31 || code >= 127 && code <= 159) return true;
|
|
238
|
+
}
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
function hasEncodedControl(value) {
|
|
242
|
+
let current = String(value ?? "");
|
|
243
|
+
for (let depth = 0; depth < 3; depth++) {
|
|
244
|
+
if (ENCODED_ASCII_CONTROL_RE.test(current)) return true;
|
|
245
|
+
let decoded;
|
|
246
|
+
try {
|
|
247
|
+
decoded = decodeURIComponent(current);
|
|
248
|
+
} catch {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
if (hasControlCodePoint(decoded)) return true;
|
|
252
|
+
if (decoded === current) return false;
|
|
253
|
+
current = decoded;
|
|
254
|
+
}
|
|
255
|
+
return ENCODED_ASCII_CONTROL_RE.test(current) || hasControlCodePoint(current);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/core/hyperlink.ts
|
|
260
|
+
const SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i;
|
|
261
|
+
const BLOCKED_SCHEME_RE = /^(?:javascript|data|vbscript):/i;
|
|
262
|
+
const SAFE_RELATIVE_HREF_RE = /^(?:[A-Za-z0-9._~!$&()*+,;=:@/?#-]|%[0-9A-Fa-f]{2})+$/u;
|
|
263
|
+
function normalizeRawHref(value) {
|
|
264
|
+
if (typeof value !== "string") return null;
|
|
265
|
+
const raw = value.trim();
|
|
266
|
+
if (!raw) return null;
|
|
267
|
+
if (raw !== value) return null;
|
|
268
|
+
for (let i = 0; i < value.length; i++) {
|
|
269
|
+
const code = value.charCodeAt(i);
|
|
270
|
+
if (code <= 31 || code >= 127 && code <= 159) return null;
|
|
271
|
+
}
|
|
272
|
+
if (/\s/u.test(raw)) return null;
|
|
273
|
+
if (raw.startsWith("//")) return null;
|
|
274
|
+
if (BLOCKED_SCHEME_RE.test(raw)) return null;
|
|
275
|
+
if (hasEncodedControl(raw)) return null;
|
|
276
|
+
return raw;
|
|
277
|
+
}
|
|
278
|
+
function hrefScheme(raw) {
|
|
279
|
+
return raw.match(SCHEME_RE)?.[0].toLowerCase() ?? null;
|
|
280
|
+
}
|
|
281
|
+
function parseSafeAbsoluteUrl(raw) {
|
|
282
|
+
if (raw.includes("\\")) return null;
|
|
283
|
+
try {
|
|
284
|
+
return new URL(raw);
|
|
285
|
+
} catch {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function sanitizeAbsoluteHref(raw, options = {}) {
|
|
290
|
+
const url = parseSafeAbsoluteUrl(raw);
|
|
291
|
+
if (!url) return null;
|
|
292
|
+
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
293
|
+
if (!/^https?:\/\//i.test(raw)) return null;
|
|
294
|
+
return options.preserveHttpHref ? raw : url.toString();
|
|
295
|
+
}
|
|
296
|
+
if (url.protocol === "mailto:") return raw;
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
function isSafeNormalizedRelativeHref(raw) {
|
|
300
|
+
if (raw.includes("\\")) return false;
|
|
301
|
+
if (raw.startsWith("//")) return false;
|
|
302
|
+
if (SCHEME_RE.test(raw)) return false;
|
|
303
|
+
if (hasEncodedControl(raw)) return false;
|
|
304
|
+
if (!SAFE_RELATIVE_HREF_RE.test(raw)) return false;
|
|
305
|
+
return raw.startsWith("#") || raw.startsWith("?") || raw.startsWith("/") || raw.startsWith("./") || raw.startsWith("../") || /^[A-Za-z0-9._~-]/u.test(raw);
|
|
306
|
+
}
|
|
307
|
+
function isSafeRelativeHref(value) {
|
|
308
|
+
const raw = normalizeRawHref(value);
|
|
309
|
+
return raw != null && isSafeNormalizedRelativeHref(raw);
|
|
310
|
+
}
|
|
311
|
+
function sanitizeTerminalHref(value, options = {}) {
|
|
312
|
+
const raw = normalizeRawHref(value);
|
|
313
|
+
if (!raw) return null;
|
|
314
|
+
const sanitized = sanitizeAbsoluteHref(raw, { preserveHttpHref: true });
|
|
315
|
+
if (sanitized) return sanitized;
|
|
316
|
+
if (options.allowFileUrls) {
|
|
317
|
+
const url = parseSafeAbsoluteUrl(raw);
|
|
318
|
+
if (url?.protocol === "file:") return url.toString();
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function sanitizeDomHref(value, options = {}) {
|
|
323
|
+
const raw = normalizeRawHref(value);
|
|
324
|
+
if (!raw) return null;
|
|
325
|
+
const scheme = hrefScheme(raw);
|
|
326
|
+
if (!scheme) return options.allowRelative !== false && isSafeNormalizedRelativeHref(raw) ? raw : null;
|
|
327
|
+
return sanitizeAbsoluteHref(raw);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
//#endregion
|
|
331
|
+
export { charCellWidth, hasEncodedControl, isSafeRelativeHref, sanitizeDomHref, sanitizeTerminalHref };
|