@zaly/tui 0.0.5 → 0.0.7
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/assets/schemas/theme.schema.json +272 -270
- package/assets/themes/kanagawa-dragon.json +3 -0
- package/assets/themes/kanagawa-wave.json +3 -0
- package/dist/{actions-CnVzKVID.d.mts → actions-DFboj3g5.d.mts} +4 -4
- package/dist/{actions-CnVzKVID.d.mts.map → actions-DFboj3g5.d.mts.map} +1 -1
- package/dist/ansi.d.mts +10 -11
- package/dist/ansi.d.mts.map +1 -1
- package/dist/{autocomplete-Dfw-yQDa.d.mts → autocomplete-CxzetPOo.d.mts} +4 -4
- package/dist/{autocomplete-Dfw-yQDa.d.mts.map → autocomplete-CxzetPOo.d.mts.map} +1 -1
- package/dist/{box-DepqUtuo.mjs → box-DLEcEvDH.mjs} +18 -11
- package/dist/box-DLEcEvDH.mjs.map +1 -0
- package/dist/{builder-T9oGIWFa.mjs → builder-BgEcjj8Z.mjs} +5 -4
- package/dist/builder-BgEcjj8Z.mjs.map +1 -0
- package/dist/{callbacks-DcMBGQEO.mjs → callbacks-D132G8dy.mjs} +7 -6
- package/dist/callbacks-D132G8dy.mjs.map +1 -0
- package/dist/client-BltmwI6G.mjs +2 -0
- package/dist/{client-BBdtbLp4.mjs → client-xnCHMO2_.mjs} +62 -8
- package/dist/client-xnCHMO2_.mjs.map +1 -0
- package/dist/{clipboard-l_TWxxTf.mjs → clipboard-CNPBTX7j.mjs} +9 -7
- package/dist/{clipboard-l_TWxxTf.mjs.map → clipboard-CNPBTX7j.mjs.map} +1 -1
- package/dist/clipboard.d.mts +6 -7
- package/dist/clipboard.d.mts.map +1 -1
- package/dist/clipboard.mjs +1 -1
- package/dist/{ctx-Ctmvof1N.mjs → ctx-ChO3St_a.mjs} +3 -3
- package/dist/{ctx-Ctmvof1N.mjs.map → ctx-ChO3St_a.mjs.map} +1 -1
- package/dist/ctx-DZHBHjsB.mjs +2 -0
- package/dist/{divider-cclEAdPx.mjs → divider-l0-JPEIm.mjs} +2 -2
- package/dist/{divider-cclEAdPx.mjs.map → divider-l0-JPEIm.mjs.map} +1 -1
- package/dist/{files-Aw3iWpXD.d.mts → files-BUsa-RVl.d.mts} +3 -3
- package/dist/{files-Aw3iWpXD.d.mts.map → files-BUsa-RVl.d.mts.map} +1 -1
- package/dist/{github-DS00VoOj.d.mts → github-D89A3F9U.d.mts} +3 -3
- package/dist/{github-DS00VoOj.d.mts.map → github-D89A3F9U.d.mts.map} +1 -1
- package/dist/{image-BTxDPPiT.d.mts → image-34bU73bW.d.mts} +2 -2
- package/dist/{image-BTxDPPiT.d.mts.map → image-34bU73bW.d.mts.map} +1 -1
- package/dist/image.d.mts +14 -15
- package/dist/image.d.mts.map +1 -1
- package/dist/index.d.mts +13 -13
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/{input-CRBuTrsL.mjs → input-D7fQEUdt.mjs} +3 -3
- package/dist/input-D7fQEUdt.mjs.map +1 -0
- package/dist/{input-B5Vy-iaa.d.mts → input-Dylds_sI.d.mts} +3 -3
- package/dist/input-Dylds_sI.d.mts.map +1 -0
- package/dist/{inspect-D6FW_QUo.d.mts → inspect-DPLRum7L.d.mts} +2 -2
- package/dist/{inspect-D6FW_QUo.d.mts.map → inspect-DPLRum7L.d.mts.map} +1 -1
- package/dist/{inspect-BaKG6cU_.mjs → inspect-xdSq5Hjq.mjs} +3 -3
- package/dist/{inspect-BaKG6cU_.mjs.map → inspect-xdSq5Hjq.mjs.map} +1 -1
- package/dist/kitty-JbCJC0iQ.mjs.map +1 -1
- package/dist/{log-DYHEYX_z.mjs → log-DrYLRdMW.mjs} +4 -4
- package/dist/{log-DYHEYX_z.mjs.map → log-DrYLRdMW.mjs.map} +1 -1
- package/dist/{logger-Ch0LwSG_.mjs → logger-ClSgGf-a.mjs} +3 -3
- package/dist/logger-ClSgGf-a.mjs.map +1 -0
- package/dist/{markdown-CYHHoYu0.mjs → markdown-lRhc_4Cd.mjs} +7 -7
- package/dist/markdown-lRhc_4Cd.mjs.map +1 -0
- package/dist/markdown.d.mts +5 -5
- package/dist/markdown.d.mts.map +1 -1
- package/dist/markdown.mjs +1 -1
- package/dist/md.bun.d.mts +1 -2
- package/dist/md.bun.d.mts.map +1 -1
- package/dist/md.node.d.mts +1 -2
- package/dist/md.node.d.mts.map +1 -1
- package/dist/node-BZ7f6HzU.mjs.map +1 -1
- package/dist/{overlay-9xNgsuuy.mjs → overlay-9WXYiGgW.mjs} +2 -2
- package/dist/{overlay-9xNgsuuy.mjs.map → overlay-9WXYiGgW.mjs.map} +1 -1
- package/dist/{picker-cH-rc7-X.mjs → picker-BqHINl_a.mjs} +4 -4
- package/dist/picker-BqHINl_a.mjs.map +1 -0
- package/dist/{picker-D8OLb6kZ.d.mts → picker-JL8lZfRH.d.mts} +5 -5
- package/dist/{picker-D8OLb6kZ.d.mts.map → picker-JL8lZfRH.d.mts.map} +1 -1
- package/dist/queries-B_lOwEiE.mjs.map +1 -1
- package/dist/{queries-DH3bj74K.d.mts → queries-Cvalgu6P.d.mts} +3 -3
- package/dist/{queries-DH3bj74K.d.mts.map → queries-Cvalgu6P.d.mts.map} +1 -1
- package/dist/reactive-f7NpAi69.mjs.map +1 -1
- package/dist/{registry-CdeLjUo2.mjs → registry-CEpHcTa2.mjs} +2 -2
- package/dist/registry-CEpHcTa2.mjs.map +1 -0
- package/dist/{render-CPUD4yaW.mjs → render-DxIHVH9Y.mjs} +2 -2
- package/dist/{render-CPUD4yaW.mjs.map → render-DxIHVH9Y.mjs.map} +1 -1
- package/dist/{renderer-DJ1pWXSL.mjs → renderer-Bz3tc2IT.mjs} +7 -7
- package/dist/renderer-Bz3tc2IT.mjs.map +1 -0
- package/dist/renderer-CuF4RYBZ.mjs +2 -0
- package/dist/{renderer-qSMVeNSV.mjs → renderer-DesbRwjQ.mjs} +2 -2
- package/dist/renderer-DesbRwjQ.mjs.map +1 -0
- package/dist/select-m7NE6Rwa.mjs.map +1 -1
- package/dist/{select-CbmAZdpt.d.mts → select-zGd5pbiB.d.mts} +3 -3
- package/dist/{select-CbmAZdpt.d.mts.map → select-zGd5pbiB.d.mts.map} +1 -1
- package/dist/services/logger.d.mts +1 -1
- package/dist/services/logger.mjs +1 -1
- package/dist/services/notifier.d.mts +3 -4
- package/dist/services/notifier.d.mts.map +1 -1
- package/dist/services/notifier.mjs +2 -2
- package/dist/services/notifier.mjs.map +1 -1
- package/dist/services/picker.d.mts +8 -9
- package/dist/services/picker.d.mts.map +1 -1
- package/dist/services/picker.mjs +10 -8
- package/dist/services/picker.mjs.map +1 -1
- package/dist/services/prompt.d.mts +8 -9
- package/dist/services/prompt.d.mts.map +1 -1
- package/dist/services/prompt.mjs +9 -7
- package/dist/services/prompt.mjs.map +1 -1
- package/dist/shiki/server.d.mts +1 -1
- package/dist/shiki/server.mjs +6 -2
- package/dist/shiki/server.mjs.map +1 -1
- package/dist/{shiki-BK-v9CtF.mjs → shiki-CcxiFWEF.mjs} +3 -3
- package/dist/{shiki-BK-v9CtF.mjs.map → shiki-CcxiFWEF.mjs.map} +1 -1
- package/dist/{shiki-B5NwIiot.mjs → shiki-D7l5--zz.mjs} +19 -5
- package/dist/shiki-D7l5--zz.mjs.map +1 -0
- package/dist/show-DR2x1YFc.mjs.map +1 -1
- package/dist/style.d.mts +7 -7
- package/dist/style.d.mts.map +1 -1
- package/dist/style.mjs +2 -2
- package/dist/{text-DILrol9j.mjs → text-BLz1tRoC.mjs} +4 -3
- package/dist/{text-DILrol9j.mjs.map → text-BLz1tRoC.mjs.map} +1 -1
- package/dist/{text-9lwQeqYr.d.mts → text-BefiXAFW.d.mts} +3 -3
- package/dist/{text-9lwQeqYr.d.mts.map → text-BefiXAFW.d.mts.map} +1 -1
- package/dist/{text-q26V6_Sc.mjs → text-CRZD9KTN.mjs} +3 -2
- package/dist/{text-q26V6_Sc.mjs.map → text-CRZD9KTN.mjs.map} +1 -1
- package/dist/text.d.mts +1 -1
- package/dist/text.mjs +1 -1
- package/dist/{theme.config-CU3B50HN.mjs → theme.config-DoW6LIcl.mjs} +250 -242
- package/dist/theme.config-DoW6LIcl.mjs.map +1 -0
- package/dist/themes.d.mts +8 -9
- package/dist/themes.d.mts.map +1 -1
- package/dist/themes.mjs +1 -1
- package/dist/tree-Bo1afYhe.mjs.map +1 -1
- package/dist/{tree-C28QOVIK.d.mts → tree-CArtDRec.d.mts} +3 -3
- package/dist/{tree-C28QOVIK.d.mts.map → tree-CArtDRec.d.mts.map} +1 -1
- package/dist/{types-B9Eh7k2v.d.mts → types-C0EOLZDc.d.mts} +7 -2
- package/dist/types-C0EOLZDc.d.mts.map +1 -0
- package/dist/{widget-M7jD8Rgg.d.mts → widget-DtJU2-BJ.d.mts} +2 -2
- package/dist/{widget-M7jD8Rgg.d.mts.map → widget-DtJU2-BJ.d.mts.map} +1 -1
- package/dist/widgets/autocomplete.d.mts +1 -1
- package/dist/widgets/autocomplete.mjs +2 -2
- package/dist/widgets/autocomplete.mjs.map +1 -1
- package/dist/widgets/box.d.mts +1 -1
- package/dist/widgets/box.mjs +1 -1
- package/dist/widgets/code.d.mts +4 -5
- package/dist/widgets/code.d.mts.map +1 -1
- package/dist/widgets/code.mjs +5 -5
- package/dist/widgets/completions/actions.d.mts +1 -1
- package/dist/widgets/completions/files.d.mts +1 -1
- package/dist/widgets/completions/github.d.mts +1 -1
- package/dist/widgets/completions/index.d.mts +3 -3
- package/dist/widgets/diff.d.mts +5 -6
- package/dist/widgets/diff.d.mts.map +1 -1
- package/dist/widgets/diff.mjs +3 -3
- package/dist/widgets/diff.mjs.map +1 -1
- package/dist/widgets/divider.d.mts +4 -5
- package/dist/widgets/divider.d.mts.map +1 -1
- package/dist/widgets/divider.mjs +1 -1
- package/dist/widgets/image.d.mts +1 -1
- package/dist/widgets/image.mjs +1 -1
- package/dist/widgets/image.mjs.map +1 -1
- package/dist/widgets/input.d.mts +1 -1
- package/dist/widgets/input.mjs +1 -1
- package/dist/widgets/log.d.mts +1 -1
- package/dist/widgets/log.mjs +1 -1
- package/dist/widgets/markdown.d.mts +8 -9
- package/dist/widgets/markdown.d.mts.map +1 -1
- package/dist/widgets/markdown.mjs +1 -1
- package/dist/widgets/overlay.d.mts +1 -1
- package/dist/widgets/overlay.mjs +1 -1
- package/dist/widgets/picker.d.mts +1 -1
- package/dist/widgets/picker.mjs +1 -1
- package/dist/widgets/progress.d.mts +5 -6
- package/dist/widgets/progress.d.mts.map +1 -1
- package/dist/widgets/select.d.mts +1 -1
- package/dist/widgets/show.d.mts +7 -7
- package/dist/widgets/show.d.mts.map +1 -1
- package/dist/widgets/spinner.d.mts +7 -8
- package/dist/widgets/spinner.d.mts.map +1 -1
- package/dist/widgets/spinner.mjs.map +1 -1
- package/dist/widgets/text.d.mts +1 -1
- package/dist/widgets/text.mjs +1 -1
- package/dist/widgets/tree.d.mts +1 -1
- package/dist/widgets/widget.d.mts +1 -1
- package/dist/worker-T6SdPzUH.mjs.map +1 -1
- package/package.json +9 -10
- package/dist/box-DepqUtuo.mjs.map +0 -1
- package/dist/builder-T9oGIWFa.mjs.map +0 -1
- package/dist/callbacks-DcMBGQEO.mjs.map +0 -1
- package/dist/client-BBdtbLp4.mjs.map +0 -1
- package/dist/client-cIckDgAj.mjs +0 -2
- package/dist/ctx-DhJIKuOX.mjs +0 -2
- package/dist/input-B5Vy-iaa.d.mts.map +0 -1
- package/dist/input-CRBuTrsL.mjs.map +0 -1
- package/dist/logger-Ch0LwSG_.mjs.map +0 -1
- package/dist/markdown-CYHHoYu0.mjs.map +0 -1
- package/dist/picker-cH-rc7-X.mjs.map +0 -1
- package/dist/registry-CdeLjUo2.mjs.map +0 -1
- package/dist/renderer-DJ1pWXSL.mjs.map +0 -1
- package/dist/renderer-Dgj_qEOA.mjs +0 -2
- package/dist/renderer-qSMVeNSV.mjs.map +0 -1
- package/dist/shiki-B5NwIiot.mjs.map +0 -1
- package/dist/theme.config-CU3B50HN.mjs.map +0 -1
- package/dist/types-B9Eh7k2v.d.mts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Bt as Actions, It as ActionDef } from "./queries-
|
|
2
|
-
import { n as PickerItem } from "./picker-
|
|
3
|
-
import { o as CompletionSource } from "./autocomplete-
|
|
1
|
+
import { Bt as Actions, It as ActionDef } from "./queries-Cvalgu6P.mjs";
|
|
2
|
+
import { n as PickerItem } from "./picker-JL8lZfRH.mjs";
|
|
3
|
+
import { o as CompletionSource } from "./autocomplete-CxzetPOo.mjs";
|
|
4
4
|
//#region src/widgets/completions/actions.d.ts
|
|
5
5
|
/** Completion item produced by `actionsSource`. Carries the full
|
|
6
6
|
* `ActionInfo` plus the action `id` so the source's `accept` can
|
|
@@ -38,4 +38,4 @@ interface ActionsSourceOptions {
|
|
|
38
38
|
declare function actionsSource(opts: ActionsSourceOptions): CompletionSource<ActionCompletionItem>;
|
|
39
39
|
//#endregion
|
|
40
40
|
export { ActionsSourceOptions as n, actionsSource as r, ActionCompletionItem as t };
|
|
41
|
-
//# sourceMappingURL=actions-
|
|
41
|
+
//# sourceMappingURL=actions-DFboj3g5.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions-
|
|
1
|
+
{"version":3,"file":"actions-DFboj3g5.d.mts","names":[],"sources":["../src/widgets/completions/actions.ts"],"mappings":";;;;;;;;KAQY,uBAAuB,YAAY;EAAe;EAAY;;UAEzD;;EAEf,SAAS;;EAET,UAAU;;;EAGV,UAAU,YAAY,MAAM;;;;;;;;;;;;;;;;;;iBAmBd,cAAc,MAAM,uBAAuB,iBAAiB"}
|
package/dist/ansi.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { a as AnsiStyle, r as AnsiColor } from "./types-
|
|
1
|
+
import { a as AnsiStyle, r as AnsiColor } from "./types-C0EOLZDc.mjs";
|
|
2
2
|
//#region src/style/ansi.d.ts
|
|
3
3
|
/** Optional wrap mode: `"word"` (default) breaks at word boundaries;
|
|
4
4
|
* `"char"` hard-wraps mid-word. */
|
|
5
|
-
interface WrapOpts {
|
|
5
|
+
export interface WrapOpts {
|
|
6
6
|
mode?: "word" | "char";
|
|
7
7
|
}
|
|
8
|
-
declare const RESET = "[0m";
|
|
8
|
+
export declare const RESET = "[0m";
|
|
9
9
|
/**
|
|
10
10
|
* Wrap `text` in an OSC 8 hyperlink pointing at `url`. Modern terminals
|
|
11
11
|
* (iTerm2, kitty, WezTerm, VS Code, Ghostty, …) render the text as
|
|
@@ -19,10 +19,10 @@ declare const RESET = "[0m";
|
|
|
19
19
|
*
|
|
20
20
|
* @internal
|
|
21
21
|
*/
|
|
22
|
-
declare function hyperlink(url: string, text: string): string;
|
|
23
|
-
declare function ansiColor(color: AnsiColor, kind: "fg" | "bg"): string | undefined;
|
|
24
|
-
declare function openAnsi(style: AnsiStyle): string;
|
|
25
|
-
declare function styleAnsi(text: string, style?: AnsiStyle): string;
|
|
22
|
+
export declare function hyperlink(url: string, text: string): string;
|
|
23
|
+
export declare function ansiColor(color: AnsiColor, kind: "fg" | "bg"): string | undefined;
|
|
24
|
+
export declare function openAnsi(style: AnsiStyle): string;
|
|
25
|
+
export declare function styleAnsi(text: string, style?: AnsiStyle): string;
|
|
26
26
|
/**
|
|
27
27
|
* Post-process a styled string so an outer style is re-applied after any
|
|
28
28
|
* inner full-reset (`\x1b[0m`). Without this, a child's reset clobbers
|
|
@@ -40,9 +40,8 @@ declare function styleAnsi(text: string, style?: AnsiStyle): string;
|
|
|
40
40
|
*
|
|
41
41
|
* @internal
|
|
42
42
|
*/
|
|
43
|
-
declare function reapplyStyle(s: string, escape: string): string;
|
|
44
|
-
declare function stripAnsiBg(s: string): string;
|
|
45
|
-
declare function ansiBg(str: string, idx: number): AnsiColor | undefined;
|
|
43
|
+
export declare function reapplyStyle(s: string, escape: string): string;
|
|
44
|
+
export declare function stripAnsiBg(s: string): string;
|
|
45
|
+
export declare function ansiBg(str: string, idx: number): AnsiColor | undefined;
|
|
46
46
|
//#endregion
|
|
47
|
-
export { RESET, WrapOpts, ansiBg, ansiColor, hyperlink, openAnsi, reapplyStyle, stripAnsiBg, styleAnsi };
|
|
48
47
|
//# sourceMappingURL=ansi.d.mts.map
|
package/dist/ansi.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ansi.d.mts","names":[],"sources":["../src/style/ansi.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"ansi.d.mts","names":[],"sources":["../src/style/ansi.ts"],"mappings":";;;;iBAQiB;EACf;;qBAQW;;;;;;;;;;;;;;wBA2DG,UAAU,aAAa;wBAKvB,UAAU,OAAO,WAAW;wBA4B5B,SAAS,OAAO;wBAWhB,UAAU,cAAc,QAAQ;;;;;;;;;;;;;;;;;;wBAwBhC,aAAa,WAAW;wBAexB,YAAY;wBAgCZ,OAAO,aAAa,cAAc"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { P as RenderCtx, Z as StyleState, f as BaseEvents, nt as Reactive, p as Node, rt as Ref } from "./queries-
|
|
2
|
-
import { t as Input } from "./input-
|
|
1
|
+
import { P as RenderCtx, Z as StyleState, f as BaseEvents, nt as Reactive, p as Node, rt as Ref } from "./queries-Cvalgu6P.mjs";
|
|
2
|
+
import { t as Input } from "./input-Dylds_sI.mjs";
|
|
3
3
|
import { n as SearchOptions, t as SearchItems } from "./search-FvGnswRl.mjs";
|
|
4
|
-
import { i as Select, n as OptionRender, t as Option } from "./select-
|
|
4
|
+
import { i as Select, n as OptionRender, t as Option } from "./select-zGd5pbiB.mjs";
|
|
5
5
|
//#region src/widgets/autocomplete.d.ts
|
|
6
6
|
/** Called when the user picks `item` from this source. Return a string
|
|
7
7
|
* to insert in place of the trigger + query range, or `undefined`
|
|
@@ -97,4 +97,4 @@ declare class Autocomplete extends Node<AutocompleteState, AutocompleteEvents> {
|
|
|
97
97
|
declare function autocomplete(opts: AutocompleteOptions): Autocomplete;
|
|
98
98
|
//#endregion
|
|
99
99
|
export { AutocompleteState as a, AutocompleteOptions as i, Autocomplete as n, CompletionSource as o, AutocompleteEvents as r, autocomplete as s, AcceptFn as t };
|
|
100
|
-
//# sourceMappingURL=autocomplete-
|
|
100
|
+
//# sourceMappingURL=autocomplete-CxzetPOo.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autocomplete-
|
|
1
|
+
{"version":3,"file":"autocomplete-CxzetPOo.d.mts","names":[],"sources":["../src/widgets/autocomplete.ts"],"mappings":";;;;;;;;;KAgBY,SAAS,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;UAkBnB,iBAAiB,UAAU,SAAS;EACnD,mBAAmB;EACnB,UAAU,SAAS,YAAY;EAC/B,SAAS,SAAS;EAClB,SAAS,aAAa;;UAIP,0BAA0B;UAE1B,4BAA4B;;;;;;;EAO3C,OAAO,QAAQ,IAAI;EAMnB,SAAS,eAAe;;EAExB,YAAY;EACZ,UAAU;EACV;;UAGe,2BAA2B;;;;EAI1C;IAAY;IAAgB,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6CvB,qBAAqB,KAAK,mBAAmB;;kBACxC;WACE;WAET,QAAQ;EAKjB,YAAY,MAAM;MAoDd;YAiFM,QAAQ,KAAK,uBAAuB;;;;;iBAmBhC,aAAa,MAAM,sBAAsB"}
|
|
@@ -2,7 +2,7 @@ import { S as unwrap } from "./reactive-f7NpAi69.mjs";
|
|
|
2
2
|
import { t as Node } from "./node-BZ7f6HzU.mjs";
|
|
3
3
|
import { n as resolveSize, t as clamp } from "./size-D8JogYLy.mjs";
|
|
4
4
|
import { a as zipRow, i as stackColumn, n as isFixedWidth, r as padRow, t as allocateRow } from "./flex-Bguo-fUe.mjs";
|
|
5
|
-
import { r as textContent } from "./text-
|
|
5
|
+
import { r as textContent } from "./text-BLz1tRoC.mjs";
|
|
6
6
|
import { sliceAnsi, stringWidth } from "@zaly/shared/ansi";
|
|
7
7
|
//#region src/layout/border.ts
|
|
8
8
|
/** @internal */
|
|
@@ -120,7 +120,8 @@ var Box = class extends Node {
|
|
|
120
120
|
const upper = Math.max(0, ctx.width - chrome);
|
|
121
121
|
const tentative = await this.#layoutChildren(upper, ctx);
|
|
122
122
|
const natural = tentative.reduce((m, r) => Math.max(m, stringWidth(r)), 0);
|
|
123
|
-
|
|
123
|
+
const fit = Math.min(ctx.width, natural + chrome);
|
|
124
|
+
outer = clamp(fit, {
|
|
124
125
|
available: ctx.width,
|
|
125
126
|
max: style.maxWidth,
|
|
126
127
|
min: style.minWidth
|
|
@@ -128,7 +129,8 @@ var Box = class extends Node {
|
|
|
128
129
|
inner = Math.max(0, outer - chrome);
|
|
129
130
|
contentRows = tentative;
|
|
130
131
|
} else {
|
|
131
|
-
|
|
132
|
+
const requested = resolveSize(style.width ?? "fill", ctx.width) ?? ctx.width;
|
|
133
|
+
outer = clamp(requested, {
|
|
132
134
|
available: ctx.width,
|
|
133
135
|
max: style.maxWidth,
|
|
134
136
|
min: style.minWidth
|
|
@@ -267,7 +269,7 @@ var Box = class extends Node {
|
|
|
267
269
|
if (intr) return intr.width;
|
|
268
270
|
return (measureRows[i] ?? []).reduce((m, r) => Math.max(m, stringWidth(r)), 0);
|
|
269
271
|
});
|
|
270
|
-
const
|
|
272
|
+
const items = children.map((c, i) => {
|
|
271
273
|
const s = c.state;
|
|
272
274
|
return {
|
|
273
275
|
flexGrow: s.flexGrow,
|
|
@@ -278,18 +280,21 @@ var Box = class extends Node {
|
|
|
278
280
|
natural: naturals[i],
|
|
279
281
|
width: s.width
|
|
280
282
|
};
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
+
});
|
|
284
|
+
const allocAvailable = this.state.width === "fit" ? naturals.reduce((a, b) => a + b, 0) + gap * Math.max(0, children.length - 1) : innerWidth;
|
|
285
|
+
const widths = allocateRow(items, {
|
|
286
|
+
contentWidth: allocAvailable,
|
|
283
287
|
gap
|
|
284
288
|
});
|
|
285
|
-
|
|
289
|
+
const padded = (await Promise.all(children.map((c, i) => {
|
|
286
290
|
const cached = measureRows[i];
|
|
287
291
|
if (cached !== void 0 && widths[i] === measureWidths[i]) return Promise.resolve(cached);
|
|
288
292
|
return c.render({
|
|
289
293
|
...ctx,
|
|
290
294
|
width: widths[i]
|
|
291
295
|
});
|
|
292
|
-
}))).map((rows, i) => rows.map((row) => padRow(row, widths[i])))
|
|
296
|
+
}))).map((rows, i) => rows.map((row) => padRow(row, widths[i])));
|
|
297
|
+
return zipRow(padded, {
|
|
293
298
|
gap,
|
|
294
299
|
widths
|
|
295
300
|
});
|
|
@@ -309,7 +314,8 @@ var Box = class extends Node {
|
|
|
309
314
|
async #layoutColumn(children, innerWidth, ctx, gap) {
|
|
310
315
|
const widths = children.map((c) => {
|
|
311
316
|
const s = c.state;
|
|
312
|
-
|
|
317
|
+
const w = (isFixedWidth(s.width) ? resolveSize(s.width, innerWidth) : void 0) ?? innerWidth;
|
|
318
|
+
return clamp(w, {
|
|
313
319
|
available: innerWidth,
|
|
314
320
|
max: s.maxWidth,
|
|
315
321
|
min: s.minWidth
|
|
@@ -320,7 +326,8 @@ var Box = class extends Node {
|
|
|
320
326
|
width: widths[i]
|
|
321
327
|
})));
|
|
322
328
|
const target = this.state.width === "fit" ? childRows.reduce((m, rows) => rows.reduce((mm, r) => Math.max(mm, stringWidth(r)), m), 0) : innerWidth;
|
|
323
|
-
|
|
329
|
+
const padded = childRows.map((rows) => rows.map((row) => padRow(row, target)));
|
|
330
|
+
return stackColumn(padded, {
|
|
324
331
|
gap,
|
|
325
332
|
width: target
|
|
326
333
|
});
|
|
@@ -383,4 +390,4 @@ function resolvePadding(p) {
|
|
|
383
390
|
//#endregion
|
|
384
391
|
export { box as n, Box as t };
|
|
385
392
|
|
|
386
|
-
//# sourceMappingURL=box-
|
|
393
|
+
//# sourceMappingURL=box-DLEcEvDH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"box-DLEcEvDH.mjs","names":[],"sources":["../src/layout/border.ts","../src/widgets/box.ts"],"sourcesContent":["import type { StyleBuilder } from \"../style/builder.ts\"\n\nimport { sliceAnsi, stringWidth } from \"@zaly/shared/ansi\"\n\n/**\n * Border-character glyphs for drawing a box outline. Any single-cell string\n * is allowed (including multi-byte glyphs like rounded corners).\n */\nexport interface BorderChars {\n h: string\n v: string\n tl: string\n tr: string\n bl: string\n br: string\n}\n\nexport type BorderSpec = boolean | \"single\" | \"double\" | \"rounded\" | BorderChars\n\n/** @internal */\nexport const borders = {\n double: { bl: \"╚\", br: \"╝\", h: \"═\", tl: \"╔\", tr: \"╗\", v: \"║\" },\n rounded: { bl: \"╰\", br: \"╯\", h: \"─\", tl: \"╭\", tr: \"╮\", v: \"│\" },\n single: { bl: \"└\", br: \"┘\", h: \"─\", tl: \"┌\", tr: \"┐\", v: \"│\" },\n} as const satisfies Record<string, BorderChars>\n\n/** Resolve the `border` style value to a concrete BorderChars, or undefined.\n *\n * @internal*/\nexport function resolveBorder(spec: BorderSpec | undefined): BorderChars | undefined {\n if (spec === undefined || spec === false) return undefined\n if (spec === true) return borders.single\n if (typeof spec === \"string\") return borders[spec]\n return spec\n}\n\nexport type TitleAlign = \"left\" | \"center\" | \"right\"\n\nexport interface DrawBorderOpts {\n /**\n * Optional title embedded in the top border, with a single-cell space on\n * each side. Ellipsis-truncated when it overflows the budget.\n */\n title?: string\n /** Placement of `title` along the top border. Defaults to `\"left\"`. */\n titleAlign?: TitleAlign\n /**\n * Styled wrapper applied to the border glyphs (corners, horizontal,\n * vertical). Use `ctx.style.add(slotOrStyle)` at the call site so the\n * theme is resolved once per render.\n */\n borderStyle?: StyleBuilder\n /** Styled wrapper applied to the title text (including the padding spaces). */\n titleStyle?: StyleBuilder\n}\n\n/** Pass-through wrapper used when no style is supplied. */\nconst identity = (s: string): string => s\n\n/**\n * Wrap pre-rendered inner rows with a border, adding top/bottom border rows\n * and left/right border chars to each inner row. Inner rows must be padded\n * to a uniform width; the output rows are `innerWidth + 2` wide.\n *\n * Border glyphs and the optional title can be styled independently via\n * `borderStyle` / `titleStyle` — each is a pre-bound `StyleBuilder`, so\n * this helper stays purely about geometry and never touches SGR itself.\n *\n * @internal\n */\nexport function drawBorder(\n rows: readonly string[],\n chars: BorderChars,\n opts: DrawBorderOpts = {}\n): string[] {\n const { title, titleAlign } = opts\n const inner = rows.length > 0 ? stringWidth(rows[0]) : 0\n const wrapB = opts.borderStyle ?? identity\n const wrapT = opts.titleStyle ?? identity\n\n const out: string[] = []\n out.push(topRow({ align: titleAlign ?? \"left\", chars, inner, title, wrapB, wrapT }))\n const v = wrapB(chars.v)\n for (const row of rows) out.push(v + row + v)\n out.push(wrapB(chars.bl + chars.h.repeat(inner) + chars.br))\n return out\n}\n\ninterface TopRowArgs {\n align: TitleAlign\n chars: BorderChars\n inner: number\n title: string | undefined\n wrapB: (s: string) => string\n wrapT: (s: string) => string\n}\n\nfunction topRow({ align, chars, inner, title, wrapB, wrapT }: TopRowArgs): string {\n if (title === undefined || title === \"\") {\n return wrapB(chars.tl + chars.h.repeat(inner) + chars.tr)\n }\n // Chrome: h + space + title + space + h (4 cells of chrome around the title)\n const budget = inner - 4\n if (budget <= 0) return wrapB(chars.tl + chars.h.repeat(inner) + chars.tr)\n const shown = truncate(title, budget)\n const totalH = inner - 2 - stringWidth(shown)\n const { leading, trailing } = distributeH(totalH, align)\n const prefix = wrapB(`${chars.tl}${chars.h.repeat(leading)}`)\n const titleSeg = wrapT(` ${shown} `)\n const suffix = wrapB(`${chars.h.repeat(trailing)}${chars.tr}`)\n return prefix + titleSeg + suffix\n}\n\nfunction distributeH(totalH: number, align: TitleAlign): { leading: number; trailing: number } {\n if (align === \"left\") return { leading: 1, trailing: totalH - 1 }\n if (align === \"right\") return { leading: totalH - 1, trailing: 1 }\n // center: leading rounds down so odd slack biases the title slightly left.\n const leading = Math.floor(totalH / 2)\n return { leading, trailing: totalH - leading }\n}\n\nfunction truncate(s: string, width: number): string {\n if (stringWidth(s) <= width) return s\n if (width <= 1) return \"…\".repeat(width)\n return `${sliceAnsi(s, 0, width - 1)}…`\n}\n","import type { RenderCtx } from \"../core/ctx.ts\"\nimport type { State } from \"../core/state.ts\"\nimport type { BorderSpec, TitleAlign } from \"../layout/border.ts\"\nimport type { RowItem } from \"../layout/flex.ts\"\nimport type { Style } from \"../style/types.ts\"\nimport type { TextContent } from \"./text.ts\"\n\nimport { stringWidth } from \"@zaly/shared/ansi\"\nimport { Node } from \"../core/node.ts\"\nimport { unwrap } from \"../core/reactive.ts\"\nimport { drawBorder, resolveBorder } from \"../layout/border.ts\"\nimport { allocateRow, isFixedWidth, padRow, stackColumn, zipRow } from \"../layout/flex.ts\"\nimport { clamp, resolveSize } from \"../layout/size.ts\"\nimport { textContent } from \"./text.ts\"\n\nexport type Padding =\n | number\n | readonly [v: number, h: number]\n | readonly [t: number, r: number, b: number, l: number]\n\nexport interface BoxStyle extends Style {\n flexDirection?: \"row\" | \"column\"\n gap?: number\n /** Fixed outer height in rows. When unset, the box's height emerges\n * naturally from its content + padding + border. When set, the\n * content area is truncated or padded with blank rows to land at\n * exactly this many rows of *outer* height. Pair with\n * `verticalAlign` to control which edge is anchored. */\n height?: number\n /** Anchor for the content when `height` truncates or extends.\n * `\"top\"` (default) keeps the top edge: extra rows added at the\n * bottom, overflow truncated from the bottom. `\"bottom\"` keeps the\n * bottom edge: extra rows prepended, overflow truncated from the\n * top. Other CSS-like values (`middle`) are not implemented. */\n verticalAlign?: \"top\" | \"bottom\"\n padding?: Padding\n border?: BorderSpec\n borderTitle?: TextContent\n /** Placement of `borderTitle` along the top border. Defaults to `\"left\"`. */\n borderTitleAlign?: TitleAlign\n /**\n * Style applied to the border glyphs. Either a theme slot name (resolved\n * via the active theme) or an inline `Style`. Defaults to the `\"border\"`\n * theme slot when a border is drawn.\n */\n borderStyle?: string | Style\n /**\n * Style applied to the border title. Defaults to the `\"borderTitle\"` theme\n * slot when a title is set.\n */\n borderTitleStyle?: string | Style\n}\n\nexport class Box<T extends object = {}> extends Node<BoxStyle & T> {\n protected async _render(ctx: RenderCtx): Promise<string[]> {\n const style = this.state\n\n const [padT, padR, padB, padL] = resolvePadding(style.padding)\n const bchars = resolveBorder(style.border)\n const hasBorder = bchars !== undefined\n const chrome = padL + padR + (hasBorder ? 2 : 0)\n\n let outer: number\n let contentRows: string[]\n let inner: number\n\n if (style.width === \"fit\") {\n // `fit`: render children at the parent's max inner width, measure\n // the natural max-row width, then clamp the box to that. Two-pass\n // — the first pass uses the upper bound as a measuring window,\n // the second re-pads each row to the chosen inner width.\n const upper = Math.max(0, ctx.width - chrome)\n const tentative = await this.#layoutChildren(upper, ctx)\n const natural = tentative.reduce((m, r) => Math.max(m, stringWidth(r)), 0)\n const fit = Math.min(ctx.width, natural + chrome)\n outer = clamp(fit, {\n available: ctx.width,\n max: style.maxWidth,\n min: style.minWidth,\n })\n inner = Math.max(0, outer - chrome)\n contentRows = tentative\n } else {\n const requested = resolveSize(style.width ?? \"fill\", ctx.width) ?? ctx.width\n outer = clamp(requested, {\n available: ctx.width,\n max: style.maxWidth,\n min: style.minWidth,\n })\n inner = Math.max(0, outer - chrome)\n contentRows = await this.#layoutChildren(inner, ctx)\n }\n\n const paddedWidth = Math.max(0, outer - (hasBorder ? 2 : 0))\n\n // Ensure each content row is exactly `inner` cells wide (absorbs slack).\n contentRows = contentRows.map((row) => padRow(row, inner))\n\n // Horizontal padding.\n if (padL > 0 || padR > 0) {\n const lp = \" \".repeat(padL)\n const rp = \" \".repeat(padR)\n contentRows = contentRows.map((row) => lp + row + rp)\n }\n\n // Vertical padding.\n const blank = \" \".repeat(paddedWidth)\n const top = Array.from({ length: padT }, () => blank)\n const bot = Array.from({ length: padB }, () => blank)\n let rows = [...top, ...contentRows, ...bot]\n\n // Fixed-height fit. The `height` field is the outer dimension —\n // border takes its 2 rows out before we measure against the\n // content area; padding is already baked into `rows`. `verticalAlign`\n // decides which end gets clipped (when too tall) or padded (when\n // too short). Default `\"top\"` matches the natural reading flow.\n if (style.height !== undefined) {\n const innerH = Math.max(0, style.height - (hasBorder ? 2 : 0))\n if (rows.length > innerH) {\n rows = style.verticalAlign === \"bottom\" ? rows.slice(-innerH) : rows.slice(0, innerH)\n } else if (rows.length < innerH) {\n const filler = Array.from({ length: innerH - rows.length }, () => blank)\n rows = style.verticalAlign === \"bottom\" ? [...filler, ...rows] : [...rows, ...filler]\n }\n }\n\n if (bchars) {\n rows = drawBorder(rows, bchars, {\n borderStyle: ctx.style.add(style.borderStyle ?? \"border\"),\n title: await textContent(style.borderTitle, ctx),\n titleAlign: style.borderTitleAlign,\n titleStyle: ctx.style.add(style.borderTitleStyle ?? \"borderTitle\"),\n })\n }\n\n const wrap = ctx.style.add(style)\n return rows.map((row) => wrap(row))\n }\n\n /**\n * Intrinsic content width derived from children (or the explicit\n * `width` when fixed). Lets parent flex containers size this Box\n * without falling back to a measure-render — important for\n * side-effecting children like `Image` whose first render allocates\n * a KGP placement: rendering twice would emit two placements and the\n * second render's `transmitOnce` returns no bytes, so the bytes from\n * the discarded measure pass would be lost.\n *\n * Row direction → bases sum (plus gaps). Column direction → bases\n * max. Both add chrome (padding + border) at the end.\n *\n * Children without `layout()` contribute 0 — the row allocator's\n * render-measure fallback still kicks in for them at allocation\n * time, but their absence here just means this Box reports a\n * smaller intrinsic. That's the safe direction: under-report and\n * let shrink/grow handle slack, never over-report.\n */\n override async layout(ctx: RenderCtx) {\n const s = this.state\n const [, padR, , padL] = resolvePadding(s.padding)\n const chrome = padL + padR + (resolveBorder(s.border) ? 2 : 0)\n\n // Fixed width wins outright.\n if (isFixedWidth(s.width)) {\n const w = resolveSize(s.width, ctx.width) ?? 0\n return { minWidth: w, width: w }\n }\n\n const kids = layoutNodes(this.children)\n if (kids.length === 0) return { minWidth: chrome, width: chrome }\n\n const isRow = (s.flexDirection ?? \"column\") === \"row\"\n const totalGap = isRow ? (s.gap ?? 0) * Math.max(0, kids.length - 1) : 0\n\n let widthAcc = 0\n let minAcc = 0\n for (const k of kids) {\n // oxlint-disable-next-line no-await-in-loop\n const l = (await k.getLayout(ctx)) ?? { minWidth: 0, width: 0 }\n if (isRow) {\n widthAcc += l.width\n minAcc += l.minWidth\n } else {\n widthAcc = Math.max(widthAcc, l.width)\n minAcc = Math.max(minAcc, l.minWidth)\n }\n }\n\n return { minWidth: minAcc + totalGap + chrome, width: widthAcc + totalGap + chrome }\n }\n\n async #layoutChildren(innerWidth: number, ctx: RenderCtx): Promise<string[]> {\n const children = layoutNodes(this.children)\n if (children.length === 0) return []\n const gap = this.state.gap ?? 0\n return (this.state.flexDirection ?? \"column\") === \"row\"\n ? this.#layoutRow(children, innerWidth, ctx, gap)\n : this.#layoutColumn(children, innerWidth, ctx, gap)\n }\n\n /**\n * Row direction — main axis is horizontal. CSS-style flex:\n * each child sizes to its intrinsic content width unless it claims\n * slack via `flexGrow > 0` or `width: \"fill\"`. Slack distributes by\n * grow weights; deficit distributes by `basis * flexShrink` clamped\n * at each child's `min-content` floor.\n *\n * Sizing strategy per child:\n * 1. `node.layout(ctx)` — sync, content-derived. If implemented,\n * use directly; no render needed for measurement.\n * 2. Otherwise fall back to render-at-innerWidth and measure the\n * widest emitted row. Cached; the paint pass reuses the result\n * whenever the allocated width matches the measurement width.\n *\n * In `fit` mode the parent has no slack to give, so the allocator's\n * available is capped at the natural sum.\n */\n async #layoutRow(\n children: readonly Node[],\n innerWidth: number,\n ctx: RenderCtx,\n gap: number\n ): Promise<string[]> {\n // Phase 1: figure out each child's intrinsic size.\n // - `layout()` short-circuits — sync, no render.\n // - Fallback: render at the upper bound (innerWidth or fixed spec)\n // and measure rows.\n const intrinsics = await Promise.all(children.map((c) => c.getLayout(ctx)))\n // For children with intrinsic sizing, skip the measure render\n // entirely. Others fall back to render-at-upper-bound (their fixed\n // width, or innerWidth if fluid).\n const measureWidths = children.map((c, i) => {\n if (intrinsics[i] !== undefined) return -1\n if (isFixedWidth(c.state.width)) {\n return resolveSize(c.state.width, innerWidth) ?? innerWidth\n }\n return innerWidth\n })\n const measureRows = await Promise.all(\n children.map((c, i): Promise<string[] | undefined> => {\n if (measureWidths[i] === -1) return Promise.resolve(undefined)\n return c.render({ ...ctx, width: measureWidths[i] })\n })\n )\n const naturals = children.map((c, i) => {\n // A fixed `state.width` is what the allocator will actually\n // assign this child — use it directly so the fit-mode\n // `allocAvailable` sum below matches what we'll consume. Falling\n // back to intrinsic when there's no override under-reports a\n // child like `text(\"x\", { width: 2 })` and shrinks every sibling\n // by the missing cells.\n if (isFixedWidth(c.state.width)) {\n return resolveSize(c.state.width, innerWidth) ?? 0\n }\n const intr = intrinsics[i]\n if (intr) return intr.width\n return (measureRows[i] ?? []).reduce((m, r) => Math.max(m, stringWidth(r)), 0)\n })\n const items: RowItem[] = children.map((c, i) => {\n const s = c.state\n return {\n flexGrow: s.flexGrow,\n flexShrink: s.flexShrink,\n intrinsicMin: intrinsics[i]?.minWidth,\n maxWidth: s.maxWidth,\n minWidth: s.minWidth,\n natural: naturals[i],\n width: s.width,\n }\n })\n const allocAvailable =\n this.state.width === \"fit\"\n ? naturals.reduce((a, b) => a + b, 0) + gap * Math.max(0, children.length - 1)\n : innerWidth\n const widths = allocateRow(items, { contentWidth: allocAvailable, gap })\n // Phase 2: paint at allocated widths. Reuse the measure-render when\n // the allocation matches; otherwise render fresh (cached).\n const childRows = await Promise.all(\n children.map((c, i): Promise<string[]> => {\n const cached = measureRows[i]\n if (cached !== undefined && widths[i] === measureWidths[i]) {\n return Promise.resolve(cached)\n }\n return c.render({ ...ctx, width: widths[i] })\n })\n )\n // `zipRow` expects rows to be exactly `widths[i]` wide. Children\n // that emit natural-width rows (text default, code default) get\n // padded here so the contract holds; over-wide rows get clipped.\n const padded = childRows.map((rows, i) => rows.map((row) => padRow(row, widths[i])))\n return zipRow(padded, { gap, widths })\n }\n\n /**\n * Column direction — main axis is vertical, cross axis horizontal.\n * Per CSS `align-items: stretch` (default), children with no\n * explicit `width` fill the cross axis. A child with a fixed `width`\n * (number / `Pct`) takes that width as its cross-axis size, with the\n * leftover padded as right slack (default `flex-start`). `min`/`max`\n * clamp the resolved width.\n *\n * In fit-mode (`width: \"fit\"`), the cross-axis target shrinks to the\n * widest child row instead of stretching to `innerWidth` — symmetric\n * to how row-direction caps allocator-available at the natural sum.\n */\n async #layoutColumn(\n children: readonly Node[],\n innerWidth: number,\n ctx: RenderCtx,\n gap: number\n ): Promise<string[]> {\n const widths = children.map((c) => {\n const s = c.state\n const fixed = isFixedWidth(s.width) ? resolveSize(s.width, innerWidth) : undefined\n const w = fixed ?? innerWidth\n return clamp(w, { available: innerWidth, max: s.maxWidth, min: s.minWidth })\n })\n const childRows = await Promise.all(\n children.map((c, i) => c.render({ ...ctx, width: widths[i] }))\n )\n const target =\n this.state.width === \"fit\"\n ? childRows.reduce((m, rows) => rows.reduce((mm, r) => Math.max(mm, stringWidth(r)), m), 0)\n : innerWidth\n // Pad each child's rows to the cross-axis target. For full-stretch\n // children this absorbs natural-row slack; for fixed-width\n // children it adds right-side slack (default `flex-start`\n // alignment). `stackColumn`'s contract requires uniform width.\n const padded = childRows.map((rows) => rows.map((row) => padRow(row, target)))\n return stackColumn(padded, { gap, width: target })\n }\n}\n\ntype Child = Node | false | null | undefined\n\n/**\n * Factory for `Box`. The style object is required (use `{}` if you don't\n * need any styling) — the previous style-less overload caused TS to fail\n * to discriminate between a Node child and an inferred-empty-state node\n * like `WidgetNode`. Pass `box({}, child1, child2)` for un-styled boxes.\n *\n * Falsy children (`false`, `null`, `undefined`) are filtered out, enabling\n * conditional JSX-like composition: `box({}, cond && child)`.\n */\nexport function box(style: State<BoxStyle>, ...children: Child[]): Box {\n const b = new Box(style)\n for (const c of children) if (c) b.add(c)\n return b\n}\n\n/**\n * Flatten fragment nodes (those that implement the `layoutChildren`\n * protocol — `show`, `errorBoundary`, `suspense`) into their currently\n * active leaves. Recursive: a fragment whose `layoutChildren()`\n * itself contains fragments unfolds completely.\n *\n * The fragment Node still lives in the tree (mounted, propagating\n * invalidates) — layout just sees through it so its children share\n * the parent box's flex distribution, gap, and cross-axis sizing\n * instead of collapsing into a single slot.\n */\nfunction layoutNodes(children: readonly Node[]): readonly Node[] {\n return children.flatMap((c) => c.layoutNodes).filter((c) => unwrap(c.state.visible) ?? true)\n}\n\nfunction resolvePadding(p: Padding | undefined): [t: number, r: number, b: number, l: number] {\n if (p === undefined) return [0, 0, 0, 0]\n if (typeof p === \"number\") return [p, p, p, p]\n if (p.length === 2) return [p[0], p[1], p[0], p[1]]\n return [p[0], p[1], p[2], p[3]]\n}\n"],"mappings":";;;;;;;;AAoBA,MAAa,UAAU;CACrB,QAAQ;EAAE,IAAI;EAAK,IAAI;EAAK,GAAG;EAAK,IAAI;EAAK,IAAI;EAAK,GAAG;CAAI;CAC7D,SAAS;EAAE,IAAI;EAAK,IAAI;EAAK,GAAG;EAAK,IAAI;EAAK,IAAI;EAAK,GAAG;CAAI;CAC9D,QAAQ;EAAE,IAAI;EAAK,IAAI;EAAK,GAAG;EAAK,IAAI;EAAK,IAAI;EAAK,GAAG;CAAI;AAC/D;;;;AAKA,SAAgB,cAAc,MAAuD;CACnF,IAAI,SAAS,KAAA,KAAa,SAAS,OAAO,OAAO,KAAA;CACjD,IAAI,SAAS,MAAM,OAAO,QAAQ;CAClC,IAAI,OAAO,SAAS,UAAU,OAAO,QAAQ;CAC7C,OAAO;AACT;;AAuBA,MAAM,YAAY,MAAsB;;;;;;;;;;;;AAaxC,SAAgB,WACd,MACA,OACA,OAAuB,CAAC,GACd;CACV,MAAM,EAAE,OAAO,eAAe;CAC9B,MAAM,QAAQ,KAAK,SAAS,IAAI,YAAY,KAAK,EAAE,IAAI;CACvD,MAAM,QAAQ,KAAK,eAAe;CAClC,MAAM,QAAQ,KAAK,cAAc;CAEjC,MAAM,MAAgB,CAAC;CACvB,IAAI,KAAK,OAAO;EAAE,OAAO,cAAc;EAAQ;EAAO;EAAO;EAAO;EAAO;CAAM,CAAC,CAAC;CACnF,MAAM,IAAI,MAAM,MAAM,CAAC;CACvB,KAAK,MAAM,OAAO,MAAM,IAAI,KAAK,IAAI,MAAM,CAAC;CAC5C,IAAI,KAAK,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A,GAAW,OAAO;EAAC;EAAG;EAAG;EAAG;CAAC;CACvC,IAAI,OAAO,MAAM,UAAU,OAAO;EAAC;EAAG;EAAG;EAAG;CAAC;CAC7C,IAAI,EAAE,WAAW,GAAG,OAAO;EAAC,EAAE;EAAI,EAAE;EAAI,EAAE;EAAI,EAAE;CAAE;CAClD,OAAO;EAAC,EAAE;EAAI,EAAE;EAAI,EAAE;EAAI,EAAE;CAAE;AAChC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as defaultTheme } from "./registry-
|
|
1
|
+
import { t as defaultTheme } from "./registry-CEpHcTa2.mjs";
|
|
2
2
|
import { a as openAnsi, d as toHex, l as isHexColor, o as reapplyStyle, t as RESET, u as parseHex } from "./ansi-Clq0ozyA.mjs";
|
|
3
3
|
import { clamp } from "@zaly/shared";
|
|
4
4
|
//#region src/style/oklch.ts
|
|
@@ -105,11 +105,12 @@ function shiftLightness(hex, delta) {
|
|
|
105
105
|
*/
|
|
106
106
|
function openStyle(style, theme) {
|
|
107
107
|
const resolver = ThemeResolver.from(theme);
|
|
108
|
-
|
|
108
|
+
const ansiStyle = {
|
|
109
109
|
...style,
|
|
110
110
|
bg: style.bg !== void 0 ? resolver.getColor(style.bg, "bg") : void 0,
|
|
111
111
|
fg: style.fg !== void 0 ? resolver.getColor(style.fg, "fg") : void 0
|
|
112
|
-
}
|
|
112
|
+
};
|
|
113
|
+
return openAnsi(ansiStyle);
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* Resolve a style-slot reference into a `Style` object. A ref is either a
|
|
@@ -382,4 +383,4 @@ function build(state) {
|
|
|
382
383
|
//#endregion
|
|
383
384
|
export { styleBuilder as t };
|
|
384
385
|
|
|
385
|
-
//# sourceMappingURL=builder-
|
|
386
|
+
//# sourceMappingURL=builder-BgEcjj8Z.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder-BgEcjj8Z.mjs","names":[],"sources":["../src/style/oklch.ts","../src/style/style.ts","../src/style/builder.ts"],"sourcesContent":["/**\n * OKLCH-based tonal scale generation for theme colors.\n *\n * Given a base hex color, `variant(hex, step)` returns a hex variant at\n * the Tailwind-v4-ish step (50..950). The base color's hue and chroma\n * are preserved; only lightness moves. When the resulting color falls\n * outside sRGB, chroma is reduced via binary search (CSS Color Level 4\n * \"MinDE chroma reduction\") until the color fits — that avoids the\n * saturation blowout you get from naive HSL lightening at the extremes.\n *\n * Matrix constants come from Björn Ottosson's reference OKLab spec:\n * https://bottosson.github.io/posts/oklab/\n */\n\nimport type { HexColor } from \"./types.ts\"\n\nimport { clamp } from \"@zaly/shared\"\nimport { parseHex, toHex } from \"./color.ts\"\n\nexport interface OKLCH {\n L: number\n C: number\n h: number\n}\n\nconst cache = new Map<string, HexColor>()\n\n// ---------- conversions ----------\n\nfunction srgbToLinear(c: number): number {\n return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4\n}\n\nfunction linearToSrgb(c: number): number {\n return c <= 0.0031308 ? c * 12.92 : 1.055 * c ** (1 / 2.4) - 0.055\n}\n\nexport function hexToOklch(hex: string): OKLCH {\n const [r8, g8, b8] = parseHex(hex)\n const r = srgbToLinear(r8 / 255)\n const g = srgbToLinear(g8 / 255)\n const b = srgbToLinear(b8 / 255)\n\n const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b\n const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b\n const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b\n const lp = Math.cbrt(l)\n const mp = Math.cbrt(m)\n const sp = Math.cbrt(s)\n const L = 0.2104542553 * lp + 0.793617785 * mp - 0.0040720468 * sp\n const a = 1.9779984951 * lp - 2.428592205 * mp + 0.4505937099 * sp\n const b2 = 0.0259040371 * lp + 0.7827717662 * mp - 0.808675766 * sp\n const C = Math.hypot(a, b2)\n const h = ((Math.atan2(b2, a) * 180) / Math.PI + 360) % 360\n return { C, L, h }\n}\n\n/** Convert OKLCH → linear sRGB (unclamped — callers can test for gamut). */\nfunction oklchToLinearRgb({ L, C, h }: OKLCH): [number, number, number] {\n const hr = (h * Math.PI) / 180\n const a = C * Math.cos(hr)\n const b2 = C * Math.sin(hr)\n const lp = L + 0.3963377774 * a + 0.2158037573 * b2\n const mp = L - 0.1055613458 * a - 0.0638541728 * b2\n const sp = L - 0.0894841775 * a - 1.291485548 * b2\n const l = lp ** 3\n const m = mp ** 3\n const s = sp ** 3\n const r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s\n const g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s\n const b = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s\n return [r, g, b]\n}\n\nfunction inGamut([r, g, b]: [number, number, number], eps = 0.001): boolean {\n return r >= -eps && r <= 1 + eps && g >= -eps && g <= 1 + eps && b >= -eps && b <= 1 + eps\n}\n\n/**\n * Convert OKLCH → hex, reducing chroma via binary search when the\n * straightforward conversion falls outside sRGB. The search keeps `L`\n * and `h` fixed and shrinks `C` toward the achromatic axis until the\n * color fits, which is the CSS Color Level 4-recommended behavior.\n */\nexport function oklchToHex(oklch: OKLCH): HexColor {\n let rgb = oklchToLinearRgb(oklch)\n if (!inGamut(rgb)) {\n // Binary-search on C.\n let lo = 0\n let hi = oklch.C\n for (let i = 0; i < 24; i++) {\n const mid = (lo + hi) / 2\n if (inGamut(oklchToLinearRgb({ ...oklch, C: mid }))) lo = mid\n else hi = mid\n }\n rgb = oklchToLinearRgb({ ...oklch, C: lo })\n }\n const [r, g, b] = rgb.map((c) => linearToSrgb(Math.max(0, Math.min(1, c)))) as [\n number,\n number,\n number,\n ]\n return toHex(r * 255, g * 255, b * 255)\n}\n\nexport function shiftLightness(hex: HexColor, delta: number): HexColor {\n const key = `${hex}:${delta}`\n let ret = cache.get(key)\n if (ret) return ret\n\n const okl = hexToOklch(hex)\n const L = clamp(okl.L + delta, 0, 1)\n // Pull chroma toward 0 as L approaches an extreme. Keeps near-white\n // and near-black from going out of gamut.\n const margin = Math.min(L, 1 - L)\n const C = okl.C * Math.min(1, margin / 0.1)\n cache.set(key, (ret = oklchToHex({ ...okl, C, L })))\n return ret\n}\n","import type { Theme } from \"../themes/types.ts\"\nimport type { AnsiColor, AnsiStyle, Color, Style } from \"./types.ts\"\n\nimport { openAnsi } from \"./ansi.ts\"\nimport { isHexColor } from \"./color.ts\"\nimport { shiftLightness } from \"./oklch.ts\"\n\n/**\n * Build the opening SGR escape for a style descriptor. Returns '' if nothing\n * would be emitted. Unresolvable colors (invalid or 'inherit') are dropped.\n *\n * When `theme` is provided, `fg`/`bg` values matching a theme color slot\n * (e.g. `\"primary\"`, `\"muted\"`) are resolved against it first. The output\n * ordering is attrs → fg → bg, combined into a single `\\x1b[...m` run.\n *\n * @internal\n */\nexport function openStyle(style: Style, theme?: Theme): string {\n const resolver = ThemeResolver.from(theme)\n const ansiStyle: AnsiStyle = {\n ...style,\n bg: style.bg !== undefined ? resolver.getColor(style.bg, \"bg\") : undefined,\n fg: style.fg !== undefined ? resolver.getColor(style.fg, \"fg\") : undefined,\n }\n return openAnsi(ansiStyle)\n}\n\n/**\n * Resolve a style-slot reference into a `Style` object. A ref is either a\n * theme slot name (string), an inline `Style`, or `undefined`:\n *\n * - Inline `Style` → returned as-is (no slot lookup).\n * - String ref pointing at a **Color** slot → wrapped as `{ fg: <color> }`.\n * - String ref pointing at a **Style** slot → returned directly.\n * - String ref that doesn't match a slot → treated as a fg color\n * (`{ fg: <ref> }`) and resolved downstream by `colorParams`.\n * - `undefined` → `{}` (emits nothing).\n *\n * @internal\n */\nexport function resolveStyle(ref: string | Style | undefined, theme?: Theme): Style {\n return ThemeResolver.from(theme).getStyle(ref)\n}\n\nfunction parseColor(c: string): { base: string; lightness?: number } {\n const m = c.match(/^(.+?)([+-]\\d{1,3})$/)\n if (!m) return { base: c }\n let lightness = Number(m[2])\n if (!Number.isFinite(lightness))\n throw new TypeError(`Invalid color step in color \"${c}\": ${m[2]}`)\n lightness = Math.abs(lightness) < 1 ? lightness : lightness / 100\n return { base: m[1], lightness }\n}\n\nclass ThemeResolver {\n static #cache = new Map<Partial<Theme>, ThemeResolver>()\n static #main = new ThemeResolver()\n #theme: Partial<Theme>\n #styleCache = new Map<string, Style>()\n #colorCache = new Map<string, string>()\n\n private constructor(theme: Partial<Theme> = {}) {\n this.#theme = theme\n }\n\n static from(theme?: Theme): ThemeResolver {\n if (theme === undefined) return this.#main\n let resolver = this.#cache.get(theme)\n if (!resolver) {\n resolver = new ThemeResolver(theme)\n this.#cache.set(theme, resolver)\n }\n return resolver\n }\n\n getStyle(ref?: string | Style, seen?: Set<string>): Style {\n if (ref === undefined) return {}\n if (typeof ref === \"object\")\n return ref.style ? { ...this.getStyle(ref.style, seen), ...ref } : ref\n\n let ret = this.#styleCache.get(ref)\n if (ret) return ret\n\n seen ??= new Set<string>()\n if (seen.has(ref)) throw new TypeError(`Circular dependency for theme slot \"${ref}\".`)\n seen.add(ref)\n\n const value = this.#theme[ref as keyof Theme]\n ret = value === undefined ? { fg: ref as Color } : this.getStyle(value, seen)\n this.#styleCache.set(ref, ret)\n return ret\n }\n\n getColor(ref?: string, kind: \"fg\" | \"bg\" = \"fg\", seen?: Set<string>): AnsiColor {\n if (ref === undefined) return \"inherit\"\n\n const key = `${kind}:${ref}`\n let ret = this.#colorCache.get(key)\n if (ret) return ret as AnsiColor\n\n seen ??= new Set<string>()\n if (seen.has(ref)) throw new TypeError(`Circular dependency for theme slot \"${ref}\".`)\n seen.add(ref)\n\n const { base, lightness } = parseColor(ref)\n\n let value = this.#theme[base as keyof Theme] ?? base\n if (typeof value === \"object\") value = this.getColor(value[kind], kind, seen)\n else if (value !== base) value = this.getColor(value, kind, seen)\n ret = lightness !== undefined && isHexColor(value) ? shiftLightness(value, lightness) : value\n this.#colorCache.set(key, ret)\n return ret as AnsiColor\n }\n}\n","import type { Theme } from \"../themes/types.ts\"\nimport type { AnsiColorName, BrightAnsiColorName, Color, Style } from \"./types.ts\"\n\nimport { defaultTheme } from \"../themes/registry.ts\"\nimport { reapplyStyle, RESET } from \"./ansi.ts\"\nimport { openStyle, resolveStyle } from \"./style.ts\"\n\ntype AttrName = \"bold\" | \"dim\" | \"italic\" | \"underline\" | \"inverse\" | \"strikethrough\"\n\ntype AnyThemeKey = Exclude<keyof Theme, \"shiki\" | \"$schema\"> | (string & {})\n\n// Theme color slots that can chain as fg/bg. `fg`/`bg` become setter methods\n// below, so exclude them here to avoid naming collisions. `dim` is an attr on\n// the chain; users wanting theme-slot-dim for fg use `.fg(\"dim\")`.\ntype ChainSlot = Exclude<keyof Theme, \"fg\" | \"bg\" | AttrName>\n\ntype FgChainKey = AnsiColorName | BrightAnsiColorName | ChainSlot\ntype BgChainKey = `bg${Capitalize<FgChainKey>}`\ntype FgExtractKey = `fg${Capitalize<FgChainKey>}`\n\nexport type StyleBuilder = {\n theme: Theme\n (text: string): string\n fg: (color: Color) => StyleBuilder\n bg: (color: Color) => StyleBuilder\n add: (slot?: AnyThemeKey | Style) => StyleBuilder\n lighten: (n: number) => StyleBuilder\n darken: (n: number) => StyleBuilder\n // oxlint-disable-next-line typescript/consistent-indexed-object-style -- mapped over a key union, not an open string index\n} & {\n readonly [K in AttrName | FgChainKey | BgChainKey | FgExtractKey]: StyleBuilder\n}\n\n/**\n * Build styled strings via chainable property access.\n *\n * ```ts\n * style().red.bold(\"err\") // → \"\\x1b[1;31merr\\x1b[0m\"\n * style().primary.bgAccent(\"x\") // theme slots via the default theme\n * style(myTheme).primary(\"x\") // override the bound theme\n * style().fg(\"#82aaff\")(\"x\") // hex via the escape hatch\n * style().primary[300](\"x\") // tonal variant of the last color\n * style().bgDiffAdd[200].fgDiffAdd(\"x\") // per-channel variants on a Style slot\n * ```\n *\n * Each property access returns a fresh builder, so intermediates can be\n * reused and extended without mutation:\n *\n * ```ts\n * const err = style().red.bold\n * err(\"oops\"); err.underline(\"fatal\")\n * ```\n *\n * Calling an empty builder is a no-op: `styleBuilder()(\"x\")` returns `\"x\"` unchanged.\n */\nexport function styleBuilder(theme: Theme | false = defaultTheme): StyleBuilder {\n return build({\n current: {},\n last: undefined,\n theme: theme === false ? { ...defaultTheme, enabled: false } : theme,\n })\n}\n\nconst ATTRS = new Set<string>([\"bold\", \"dim\", \"italic\", \"underline\", \"inverse\", \"strikethrough\"])\n\n/** Pending \"arg-taking\" op on a chain. Set when the caller accesses\n * `.fg` / `.bg` / `.alpha` / `.add` — the chain is \"parked\" waiting\n * for its argument. Calling the parked chain consumes the arg and\n * produces the real child chain. */\ntype PendingOp = \"fg\" | \"bg\" | \"darken\" | \"add\" | \"lighten\"\n\n/** All the inputs a chain needs to behave correctly, gathered in one\n * object so we can pass it around cheaply instead of closing over\n * four separate vars. `current` is the accumulated Style, `last`\n * tracks which of `fg`/`bg` was most recently touched (for `[step]`\n * and `.alpha()`), `theme` is the resolved theme, `pending` is set\n * on parked arg-taking chains. */\ninterface BuilderState {\n current: Style\n last: \"fg\" | \"bg\" | undefined\n theme: Theme & { enabled?: boolean }\n pending?: PendingOp\n}\n\n/** The function wrapped by every chain's Proxy. Carries its own state\n * so module-level handlers can read it without closure gymnastics. */\ntype BuilderFn = {\n state: BuilderState\n theme: Theme\n} & (((text: string) => string) | ((arg: Color | number | Style | undefined) => StyleBuilder))\n\n// --- module-level handlers (shared across every chain) -----------------\n\nfunction applyStyle(state: BuilderState, text: string): string {\n if (!text || state.theme.enabled === false) return text\n const open = openStyle(state.current, state.theme)\n return open === \"\" ? text : open + reapplyStyle(text, open) + RESET\n}\n\nfunction applyOp(fn: BuilderFn, arg: Color | number | Style | undefined): StyleBuilder {\n // Cache primitive args on the call target itself via `defineProperty`\n // — repeated `.fg(\"#82aaff\")` hits the same child chain after the\n // first call, no rebuild. Object args (e.g. raw Style for `add`)\n // can't be property keys (`\"[object Object]\"` collision), so those\n // always rebuild.\n if (typeof arg === \"string\" || typeof arg === \"number\") {\n const key = String(arg)\n const hit = (fn as unknown as Record<string, unknown>)[key]\n if (hit !== undefined) return hit as StyleBuilder\n const child = fulfill(fn.state, arg)\n Reflect.defineProperty(fn, key, { configurable: false, value: child, writable: false })\n return child\n }\n return fulfill(fn.state, arg)\n}\n\n/** Turn a parked chain + its arg into the real child chain. */\nfunction fulfill(state: BuilderState, arg: unknown): StyleBuilder {\n const { current, last, theme, pending } = state\n switch (pending) {\n case \"fg\": {\n return build({ current: { ...current, fg: arg as Color }, last: \"fg\", theme })\n }\n case \"bg\": {\n return build({ current: { ...current, bg: arg as Color }, last: \"bg\", theme })\n }\n case \"lighten\":\n case \"darken\": {\n if (last === undefined) return build({ current, last, theme })\n const existing = current[last]\n if (typeof existing !== \"string\" || existing === \"inherit\") {\n return build({ current, last, theme })\n }\n const stripped = existing.replace(/[+-]\\d+$/, \"\")\n const n = Math.abs(arg as number)\n const next = `${stripped}${pending === \"lighten\" ? \"+\" : \"-\"}${n}` as Color\n return build({ current: { ...current, [last]: next }, last, theme })\n }\n default: {\n // \"add\" — no pending pending? defaults to rebuild with undef arg.\n return build({\n current: { ...current, ...resolveStyle(arg as string | Style | undefined, theme) },\n last,\n theme,\n })\n }\n }\n}\n\n/** Resolve a single property access on a chain to its child chain. */\nfunction compileKey(state: BuilderState, key: string): StyleBuilder | undefined {\n const { current, last, theme } = state\n\n // Arg-taking ops come back as chains parked in the `pending` state.\n if (key === \"fg\" || key === \"bg\" || key === \"lighten\" || key === \"darken\" || key === \"add\") {\n return build({ current, last, pending: key, theme })\n }\n\n if (ATTRS.has(key)) return build({ current: { ...current, [key]: true }, last, theme })\n\n // `bgFoo` / `fgFoo` → set the channel to the color at slot `foo`.\n // When the slot is a Style, `colorParams` extracts that channel.\n if (key.startsWith(\"bg\") && key.length > 2 && key[2] === key[2].toUpperCase()) {\n const color = (key[2].toLowerCase() + key.slice(3)) as Color\n return build({ current: { ...current, bg: color }, last: \"bg\", theme })\n }\n if (key.startsWith(\"fg\") && key.length > 2 && key[2] === key[2].toUpperCase()) {\n const color = (key[2].toLowerCase() + key.slice(3)) as Color\n return build({ current: { ...current, fg: color }, last: \"fg\", theme })\n }\n\n // Style-valued theme slot → merge its fields into the chain.\n // Anything else (ANSI color names, hex, unresolved slot refs) is\n // treated as a fg color by `colorParams` downstream.\n return build({ current: { ...current, ...resolveStyle(key, theme) }, last: \"fg\", theme })\n}\n\n/** Shared Proxy handler — one instance, used by every chain. Reads\n * state off the target (the `BuilderFn`), so chain construction\n * doesn't allocate a fresh handler object per `build()` call. */\nconst proxyHandler: ProxyHandler<BuilderFn> = {\n get(target, key) {\n if (typeof key !== \"string\") return undefined\n const cached = (target as unknown as Record<string, unknown>)[key]\n if (cached !== undefined) return cached\n // Parked chains can't be chained further — they're waiting for a call.\n if (target.state.pending !== undefined) return undefined\n const child = compileKey(target.state, key)\n if (child === undefined) return undefined\n Reflect.defineProperty(target, key, { configurable: false, value: child, writable: false })\n return child\n },\n}\n\nfunction build(state: BuilderState): StyleBuilder {\n // Two dedicated function shapes so V8 sees a stable signature on\n // each hot path — styling text vs. consuming an op arg are both\n // monomorphic after the build-time ternary.\n const fn = (\n state.pending === undefined\n ? function apply(text: string): string {\n return applyStyle(state, text)\n }\n : function applyOpCall(arg: Color | number | Style | undefined): StyleBuilder {\n return applyOp(fn, arg)\n }\n ) as BuilderFn\n fn.state = state\n fn.theme = state.theme\n return new Proxy(fn, proxyHandler) as unknown as StyleBuilder\n}\n"],"mappings":";;;;AAyBA,MAAM,wBAAQ,IAAI,IAAsB;AAIxC,SAAS,aAAa,GAAmB;CACvC,OAAO,KAAK,SAAU,IAAI,UAAU,IAAI,QAAS,UAAU;AAC7D;AAEA,SAAS,aAAa,GAAmB;CACvC,OAAO,KAAK,WAAY,IAAI,QAAQ,QAAQ,MAAM,IAAI,OAAO;AAC/D;AAEA,SAAgB,WAAW,KAAoB;CAC7C,MAAM,CAAC,IAAI,IAAI,MAAM,SAAS,GAAG;CACjC,MAAM,IAAI,aAAa,KAAK,GAAG;CAC/B,MAAM,IAAI,aAAa,KAAK,GAAG;CAC/B,MAAM,IAAI,aAAa,KAAK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EjC,IAAI,OAAO,MAAM,YAAY,KAAA,GAAW,OAAO,KAAA;CAC/C,MAAM,QAAQ,WAAW,OAAO,OAAO,GAAG;CAC1C,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,QAAQ,eAAe,QAAQ,KAAK;EAAE,cAAc;EAAO,OAAO;EAAO,UAAU;CAAM,CAAC;CAC1F,OAAO;AACT,EACF;AAEA,SAAS,MAAM,OAAmC;CAIhD,MAAM,KACJ,MAAM,YAAY,KAAA,IACd,SAAS,MAAM,MAAsB;EACnC,OAAO,WAAW,OAAO,IAAI;CAC/B,IACA,SAAS,YAAY,KAAuD;EAC1E,OAAO,QAAQ,IAAI,GAAG;CACxB;CAEN,GAAG,QAAQ;CACX,GAAG,QAAQ,MAAM;CACjB,OAAO,IAAI,MAAM,IAAI,YAAY;AACnC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as hyperlink } from "./ansi-Clq0ozyA.mjs";
|
|
2
2
|
import { t as allocateRow } from "./flex-Bguo-fUe.mjs";
|
|
3
|
-
import { n as capitalize, o as formatText, t as calcLayout } from "./text-
|
|
3
|
+
import { n as capitalize, o as formatText, t as calcLayout } from "./text-CRZD9KTN.mjs";
|
|
4
4
|
import { splitAnsi, stringWidth } from "@zaly/shared/ansi";
|
|
5
5
|
//#region src/markdown/code.ts
|
|
6
6
|
/**
|
|
@@ -18,10 +18,10 @@ function createCodeCallback(ctx) {
|
|
|
18
18
|
const hpad = 2;
|
|
19
19
|
const maxWidth = ctx.width;
|
|
20
20
|
const lines = formatText(`\n${highlighted}\n`, {
|
|
21
|
-
width: maxWidth -
|
|
21
|
+
width: maxWidth - 4,
|
|
22
22
|
wrap: "word"
|
|
23
23
|
});
|
|
24
|
-
let width = Math.max(...lines.map(stringWidth)) +
|
|
24
|
+
let width = Math.max(...lines.map(stringWidth)) + 4;
|
|
25
25
|
width = Math.min(width, maxWidth);
|
|
26
26
|
const padded = lines.map((line) => {
|
|
27
27
|
const w = stringWidth(line);
|
|
@@ -155,11 +155,12 @@ function formatTable(state, ctx) {
|
|
|
155
155
|
cols[c].minWidth = Math.max(cols[c].minWidth, l.minWidth);
|
|
156
156
|
}
|
|
157
157
|
const chromeWidth = 3 * colCount + 1;
|
|
158
|
-
const
|
|
158
|
+
const items = cols.map((c) => ({
|
|
159
159
|
flex: 1,
|
|
160
160
|
intrinsicMin: c.minWidth,
|
|
161
161
|
natural: c.width
|
|
162
|
-
}))
|
|
162
|
+
}));
|
|
163
|
+
const widths = allocateRow(items, {
|
|
163
164
|
contentWidth: ctx.width - chromeWidth,
|
|
164
165
|
gap: 0
|
|
165
166
|
});
|
|
@@ -276,4 +277,4 @@ function createCallbacks(ctx) {
|
|
|
276
277
|
//#endregion
|
|
277
278
|
export { createCallbacks };
|
|
278
279
|
|
|
279
|
-
//# sourceMappingURL=callbacks-
|
|
280
|
+
//# sourceMappingURL=callbacks-D132G8dy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callbacks-D132G8dy.mjs","names":[],"sources":["../src/markdown/code.ts","../src/markdown/list.ts","../src/markdown/table.ts","../src/markdown/callbacks.ts"],"sourcesContent":["import type { MarkdownCtx } from \"./renderer.ts\"\nimport type { MdCallbacks } from \"./types.ts\"\n\nimport { stringWidth } from \"@zaly/shared/ansi\"\nimport { formatText } from \"../layout/text.ts\"\n\n/**\n * Build the `code` callback. The returned closure captures ctx/style/highlighter\n * and renders each fenced block: syntax-highlight (if available), pad lines to\n * widest-content + 1, apply `mdCodeBlock` as a bg-only backdrop, and prefix an\n * optional title line from `title=\"...\"`.\n */\nexport function createCodeCallback(ctx: MarkdownCtx): NonNullable<MdCallbacks[\"code\"]> {\n const s = ctx.style\n return (text, meta) => {\n text = text.replace(/\\n+$/, \"\") // trim to avoid extra blank lines after the block\n const highlighted = ctx.highlight?.(text, meta?.language) ?? text\n\n // For highlighted output the per-token fgs would clash with the slot's\n // fg; override fg with `\"inherit\"` so only bg + attrs wrap each row\n // and shiki's per-token colors show through on top of the backdrop.\n const wrap = highlighted === text ? s.mdCodeBlock : s.mdCodeBlock.fg(\"inherit\")\n const hpad = 2\n const maxWidth = ctx.width\n const lines = formatText(`\\n${highlighted}\\n`, {\n width: maxWidth - hpad * 2,\n wrap: \"word\",\n })\n let width = Math.max(...lines.map(stringWidth)) + hpad * 2\n width = Math.min(width, maxWidth) // leave room for the border\n // Left-align with a fixed `hpad` of leading whitespace; pad the\n // right to fill the bg out to `width`. Centering would push short\n // lines toward the middle, which reads as visually misaligned code.\n // Lines wider than the available room (width − hpad) drop the\n // leading pad so the bg ends at the cap rather than overshooting.\n const padded = lines.map((line) => {\n const w = stringWidth(line)\n if (w >= width - hpad) return wrap(line)\n return wrap(`${\" \".repeat(hpad)}${line}${\" \".repeat(width - w - hpad)}`)\n })\n const titleLine = meta?.title === undefined ? \"\" : `${s.mdCodeBlockTitle(meta.title)}\\n`\n // Leading `\\n` guards against raw-text siblings that don't emit a\n // paragraph-wrap (e.g. some inline-only list items where the parser\n // drops the paragraph). Containers (`listItem`, document) collapse\n // `\\n{3,}` → `\\n\\n` so paragraph + code doesn't double up.\n return `\\n${titleLine}${padded.join(\"\\n\")}\\n\\n`\n }\n}\n","// oxlint-disable no-multi-assign\nimport type { RenderCtx } from \"../core/ctx.ts\"\nimport type { MdCallbacks } from \"./types.ts\"\n\nimport { splitAnsi, stringWidth } from \"@zaly/shared/ansi\"\n\ninterface ListState {\n block: boolean\n items: string[]\n /** Formatted output, set when the list closes. The parent `listItem`\n * pulls it via `stack[depth+1]` and splices it onto its own body. */\n rendered?: string\n}\n\nconst BULLETS = [\"●\", \"○\", \"◆\", \"◇\"] as const\n\ntype ListCallbacks = Pick<MdCallbacks, \"list\" | \"listItem\">\n\n/**\n * Stack-based list renderer. Each depth has its own `ListState`. Inner\n * lists return `\"\"` and stash their formatted output on `state.rendered`;\n * the parent `listItem` pulls + splices, so inner output never reaches\n * the parent's `children` string. That keeps each level's loose-vs-tight\n * verdict independent — `children.endsWith(\"\\n\\n\")` is then the per-item\n * loose signal (parser only emits `<p>` for items in loose lists).\n *\n * Nested list lands at the end of its parent's body — `text, list, more`\n * is rare in real markdown and not worth the extra plumbing.\n */\nexport function createListCallbacks(ctx: RenderCtx): ListCallbacks {\n const s = ctx.style\n // Lazy-pushed on the first `listItem` at a given depth; consumed\n // either by the parent `listItem` (nested) or by `list(0)` (top).\n const stack: (ListState | undefined)[] = []\n\n return {\n list: (_children, meta) => {\n const state = stack[meta.depth]\n if (state === undefined || state.items.length === 0) return \"\"\n state.rendered = state.items.join(state.block ? \"\\n\\n\" : \"\\n\")\n if (meta.depth > 0) return \"\"\n // Top-level: defensive stack reset + block-contract `\\n\\n` trailer.\n stack.length = 0\n return `${state.rendered}\\n\\n`\n },\n\n listItem: (children, meta) => {\n let marker = s.mdListBullet(\n meta.ordered ? `${(meta.start ?? 1) + meta.index}.` : BULLETS[meta.depth % BULLETS.length]\n )\n if (meta.checked !== undefined) {\n const ref = meta.checked ? \"mdListChecked\" : \"mdListUnchecked\"\n marker += ` ${s.add(ref)(meta.checked ? \"[x]\" : \"[ ]\")}`\n }\n const indent = \" \".repeat(stringWidth(marker))\n // Pull nested list output (if any) off the stack.\n const nested = stack[meta.depth + 1]\n stack[meta.depth + 1] = undefined\n // Trailing `\\n\\n` = loose signal. Nested output is in `rendered`,\n // not `children`, so it can't pollute this check.\n const block = children.endsWith(\"\\n\\n\")\n const trimmed = children.replace(/\\s*\\n+$/, \"\").replace(/\\n{3,}/g, \"\\n\\n\")\n // Splice nested after the prose; loose item adds a blank-row gap.\n let body = trimmed\n if (nested?.rendered !== undefined) {\n const sep = block ? \"\\n\\n\" : \"\\n\"\n body = trimmed === \"\" ? nested.rendered : `${trimmed}${sep}${nested.rendered}`\n }\n const lines = splitAnsi(body)\n const content = lines\n .map((line, l) => {\n if (l === 0) return `${marker} ${line}`\n // Bare empty lines so loose `\\n\\n` separators stay clean.\n return line === \"\" ? \"\" : `${indent}${line}`\n })\n .join(\"\\n\")\n\n const state = (stack[meta.depth] ??= { block: false, items: [] })\n state.block ||= block\n state.items.push(content)\n return \"\"\n },\n }\n}\n","import type { RenderCtx } from \"../core/ctx.ts\"\nimport type { Layout } from \"../core/state.ts\"\nimport type { RowItem } from \"../layout/flex.ts\"\nimport type { MdCallbacks } from \"./types.ts\"\n\nimport { stringWidth } from \"@zaly/shared/ansi\"\nimport { allocateRow } from \"../layout/flex.ts\"\nimport { calcLayout, formatText } from \"../layout/text.ts\"\n\ntype CellAlign = \"left\" | \"center\" | \"right\"\n\ninterface TableCell {\n text: string\n align: CellAlign | undefined\n}\n\ninterface TableState {\n header: TableCell[][]\n body: TableCell[][]\n pending: TableCell[]\n pendingIsHeader: boolean\n}\n\ntype TableCallbacks = Pick<MdCallbacks, \"table\" | \"tbody\" | \"td\" | \"th\" | \"thead\" | \"tr\">\n\n/**\n * Build the table-related callbacks. They share a closure-local\n * `TableState` accumulator: `th`/`td` push cells, `tr` commits rows into\n * header or body, and `table` runs the final layout + reset. Tables can't\n * nest in markdown, so a single top-level slot is enough.\n */\nexport function createTableCallbacks(ctx: RenderCtx): TableCallbacks {\n const { style } = ctx\n let state: TableState | undefined\n const begin = (): TableState =>\n (state ??= { body: [], header: [], pending: [], pendingIsHeader: false })\n\n return {\n table: () => {\n // Children of th/td/tr/thead/tbody are empty strings; all content is\n // in `state`. Format, reset, emit.\n if (state === undefined) return \"\"\n const out = formatTable(state, ctx)\n state = undefined\n return `${out}\\n\\n`\n },\n\n tbody: () => \"\",\n\n td: (children, meta) => {\n const t = begin()\n t.pending.push({ align: meta?.align, text: children })\n t.pendingIsHeader = false\n return \"\"\n },\n\n th: (children, meta) => {\n const t = begin()\n t.pending.push({ align: meta?.align, text: style.mdTableHeader(children) })\n t.pendingIsHeader = true\n return \"\"\n },\n\n thead: () => \"\",\n\n tr: () => {\n if (state === undefined || state.pending.length === 0) return \"\"\n if (state.pendingIsHeader) state.header.push(state.pending)\n else state.body.push(state.pending)\n state.pending = []\n return \"\"\n },\n }\n}\n\nfunction formatTable(state: TableState, ctx: RenderCtx): string {\n const cols: Layout[] = []\n const cells = [...state.header, ...state.body]\n const colCount = Math.max(...cells.map((r) => r.length))\n\n // 1. Calculate min-content and max-content for each column\n for (let c = 0; c < colCount; c++) {\n for (const row of cells) {\n const cell = row[c] as TableCell | undefined\n if (!cell) continue // Safety guard for ragged rows\n const l = calcLayout(cell.text)\n cols[c] ??= { ...l }\n cols[c].width = Math.max(cols[c].width, l.width)\n cols[c].minWidth = Math.max(cols[c].minWidth, l.minWidth)\n }\n }\n const chromeWidth = 3 * colCount + 1\n\n const items: RowItem[] = cols.map((c) => ({\n flex: 1,\n intrinsicMin: c.minWidth,\n natural: c.width,\n }))\n\n const widths = allocateRow(items, { contentWidth: ctx.width - chromeWidth, gap: 0 })\n\n // 4. Render output string using the exact final Column Widths\n // Pre-style each piece of chrome once. Each column span on a rule row is\n // `widths[i] + 2` dashes (one cell of padding on each side of the cell).\n const style = ctx.style\n const v = style.mdTable(\"│\")\n const ruleRow = (left: string, mid: string, right: string): string =>\n style.mdTable(left + widths.map((w) => \"─\".repeat(w + 2)).join(mid) + right)\n const top = ruleRow(\"┌\", \"┬\", \"┐\")\n const sep = ruleRow(\"├\", \"┼\", \"┤\")\n const bot = ruleRow(\"└\", \"┴\", \"┘\")\n\n const renderRow = (row: TableCell[]): string => {\n const formatted = row.map((cell, c) =>\n formatText(cell.text, { indent: false, width: widths[c], wrapBg: false })\n )\n const rows: string[] = []\n const rowCount = Math.max(...formatted.map((r) => r.length))\n for (let r = 0; r < rowCount; r++) {\n const line: string[] = []\n for (let c = 0; c < colCount; c++) {\n const t = formatted[c]?.[r] ?? \"\"\n line.push(padCell(t, widths[c], row[c]?.align))\n }\n rows.push(`${v} ${line.join(` ${v} `)} ${v}`)\n }\n\n return rows.join(\"\\n\")\n }\n\n const lines: string[] = [top]\n for (const row of state.header) lines.push(renderRow(row))\n if (state.header.length > 0 && state.body.length > 0) lines.push(sep)\n for (const row of state.body) lines.push(renderRow(row))\n lines.push(bot)\n return lines.join(\"\\n\")\n}\n\nfunction padCell(text: string, width: number, align: CellAlign | undefined): string {\n const slack = Math.max(0, width - stringWidth(text))\n if (align === \"right\") return \" \".repeat(slack) + text\n if (align === \"center\") {\n const left = Math.floor(slack / 2)\n return \" \".repeat(left) + text + \" \".repeat(slack - left)\n }\n return text + \" \".repeat(slack)\n}\n","import type { AnyStyle } from \"../style/types.ts\"\nimport type { MarkdownCtx } from \"./renderer.ts\"\nimport type { MdCallbacks } from \"./types.ts\"\n\nimport { stringWidth } from \"@zaly/shared/ansi\"\nimport { capitalize } from \"../layout/text.ts\"\nimport { hyperlink } from \"../style/ansi.ts\"\nimport { createCodeCallback } from \"./code.ts\"\nimport { createListCallbacks } from \"./list.ts\"\nimport { createTableCallbacks } from \"./table.ts\"\n\nconst icons = {\n hr: \"─\",\n quote: \"┃\",\n} as const\n\ntype AlertType = \"NOTE\" | \"TIP\" | \"WARNING\" | \"IMPORTANT\" | \"CAUTION\"\nconst alerts: Record<AlertType, { icon: string; style: AnyStyle }> = {\n CAUTION: { icon: \"✖ \", style: \"error\" },\n IMPORTANT: { icon: \"‼\", style: \"syntaxConstant\" },\n NOTE: { icon: \"ℹ \", style: \"info\" },\n TIP: { icon: \"🛈 \", style: \"success\" },\n WARNING: { icon: \"⚠\", style: \"warn\" },\n}\n\nconst alertRe = /^\\s*\\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\\]\\s*$/\n\n/**\n * Build the `MdCallbacks` that drive the theme-aware rendering. Exposed so\n * callers can invoke `renderMarkdown` directly when they need the string\n * output without the wrapping `Markdown` node (e.g. to embed markdown inside\n * a custom `Text` content function).\n * @internal\n */\nexport function createCallbacks(ctx: MarkdownCtx): MdCallbacks {\n const s = ctx.style\n\n return {\n blockquote: (children) => {\n const lines = children.replace(/\\n+$/, \"\").split(\"\\n\")\n let lineStyle: AnyStyle = \"mdQuote\"\n\n const m = lines.length >= 1 ? lines[0].match(alertRe) : undefined\n if (m) {\n const alertType = m[1] as AlertType\n const alert = alerts[alertType]\n lineStyle = alert.style\n const name = capitalize(alertType.toLowerCase())\n lines[0] = s.add(lineStyle)(`${alert.icon} ${name}`)\n }\n\n // Inner blocks (typically a paragraph) end with trailing newlines; if\n // we prefix those empty lines with \"│ \" they render as styled empty\n // rows between the last line of the quote and the block separator.\n // Trim first so the quote stops cleanly.\n const prefixed = lines.map((line) => `${s.add(lineStyle)(icons.quote)} ${line}`).join(\"\\n\")\n return `${prefixed}\\n\\n`\n },\n\n code: createCodeCallback(ctx),\n\n codespan: (text) => s.mdCode(text),\n\n emphasis: (children) => s.mdItalic(children),\n\n heading: (children, { level }) => {\n const width = ctx.width\n const padded = children\n .split(\"\\n\")\n .map((line) => line + \" \".repeat(Math.max(0, width - stringWidth(line))))\n .join(\"\\n\")\n return `${s.add(`mdHeading${level}`)(padded)}\\n\\n`\n },\n\n hr: () => `${s.mdHr(icons.hr.repeat(ctx.width))}\\n\\n`,\n\n html: (children) => children,\n\n link: (children, { href }) => hyperlink(href, s.mdLink(children)),\n\n paragraph: (children) => `${children}\\n\\n`,\n\n strikethrough: (children) => s.mdStrikethrough(children),\n\n strong: (children) => s.mdBold(children),\n\n ...createListCallbacks(ctx),\n ...createTableCallbacks(ctx),\n }\n}\n"],"mappings":";;;;;;;;;;;AAYA,SAAgB,mBAAmB,KAAoD;CACrF,MAAM,IAAI,IAAI;CACd,QAAQ,MAAM,SAAS;EACrB,OAAO,KAAK,QAAQ,QAAQ,EAAE;EAC9B,MAAM,cAAc,IAAI,YAAY,MAAM,MAAM,QAAQ,KAAK;EAK7D,MAAM,OAAO,gBAAgB,OAAO,EAAE,cAAc,EAAE,YAAY,GAAG,SAAS;EAC9E,MAAM,OAAO;EACb,MAAM,WAAW,IAAI;EACrB,MAAM,QAAQ,WAAW,KAAK,YAAY,KAAK;GAC7C,OAAO,WAAW;GAClB,MAAM;EACR,CAAC;EACD,IAAI,QAAQ,KAAK,IAAI,GAAG,MAAM,IAAI,WA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SAAS,SACZ,MAAM,IAAI,CAAC,CACX,KAAK,SAAS,OAAO,IAAI,OAAO,KAAK,IAAI,GAAG,QAAQ,YAAY,IAAI,CAAC,CAAC,CAAC,CAAC,CACxE,KAAK,IAAI;GACZ,OAAO,GAAG,EAAE,IAAI,YAAY,OAAO,CAAC,CAAC,MAAM,EAAE;EAC/C;EAEA,UAAU,GAAG,EAAE,KAAK,MAAM,GAAG,OAAO,IAAI,KAAK,CAAC,EAAE;EAEhD,OAAO,aAAa;EAEpB,OAAO,UAAU,EAAE,WAAW,UAAU,MAAM,EAAE,OAAO,QAAQ,CAAC;EAEhE,YAAY,aAAa,GAAG,SAAS;EAErC,gBAAgB,aAAa,EAAE,gBAAgB,QAAQ;EAEvD,SAAS,aAAa,EAAE,OAAO,QAAQ;EAEvC,GAAG,oBAAoB,GAAG;EAC1B,GAAG,qBAAqB,GAAG;CAC7B;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as isShikiLang } from "./shiki-
|
|
2
|
-
import { hash } from "@zaly/shared";
|
|
1
|
+
import { t as isShikiLang } from "./shiki-D7l5--zz.mjs";
|
|
2
|
+
import { hash, toError } from "@zaly/shared";
|
|
3
3
|
import { hasColors } from "@zaly/shared/env";
|
|
4
4
|
//#region src/shiki/client.ts
|
|
5
5
|
function isJob(s) {
|
|
@@ -7,15 +7,22 @@ function isJob(s) {
|
|
|
7
7
|
}
|
|
8
8
|
const MAX_CACHE_SIZE = 100;
|
|
9
9
|
const MAX_RUNNING = 2;
|
|
10
|
+
const REQUEST_TIMEOUT = 3e4;
|
|
10
11
|
var ShikiWorkerClient = class {
|
|
11
12
|
#id = 0;
|
|
12
13
|
#cache = /* @__PURE__ */ new Map();
|
|
13
14
|
#queue = /* @__PURE__ */ new Map();
|
|
14
15
|
#running = /* @__PURE__ */ new Map();
|
|
15
16
|
#results = [];
|
|
17
|
+
#timeouts = /* @__PURE__ */ new Map();
|
|
16
18
|
#worker;
|
|
17
19
|
#workerPromise;
|
|
20
|
+
#timeout;
|
|
18
21
|
#updateScheduled = void 0;
|
|
22
|
+
#updatePending = false;
|
|
23
|
+
constructor(opts = {}) {
|
|
24
|
+
this.#timeout = opts.timeout ?? REQUEST_TIMEOUT;
|
|
25
|
+
}
|
|
19
26
|
key(req) {
|
|
20
27
|
return req.key ?? hash(`${req.lang}:${req.code}:${req.theme ?? "default"}`);
|
|
21
28
|
}
|
|
@@ -76,6 +83,9 @@ var ShikiWorkerClient = class {
|
|
|
76
83
|
this.#running.set(job.id, job);
|
|
77
84
|
const worker = await this.#createWorker();
|
|
78
85
|
const { signal: _s, promise: _prom, resolve: _res, reject: _rej, ...msg } = job;
|
|
86
|
+
const timeout = setTimeout(() => this.#fail(/* @__PURE__ */ new Error(`Shiki worker timed out after ${this.#timeout}ms (${job.lang}, ${job.key})`)), this.#timeout);
|
|
87
|
+
timeout.unref();
|
|
88
|
+
this.#timeouts.set(job.id, timeout);
|
|
79
89
|
worker.postMessage(msg);
|
|
80
90
|
}
|
|
81
91
|
async #createWorker() {
|
|
@@ -83,21 +93,48 @@ var ShikiWorkerClient = class {
|
|
|
83
93
|
this.#workerPromise ??= (async () => {
|
|
84
94
|
const { createWorker } = await import("./worker-BvRm4OsW.mjs");
|
|
85
95
|
const worker = await createWorker();
|
|
96
|
+
const ready = Promise.withResolvers();
|
|
97
|
+
let started = false;
|
|
98
|
+
const timeout = setTimeout(() => ready.reject(/* @__PURE__ */ new Error(`Shiki worker did not start within ${this.#timeout}ms`)), this.#timeout);
|
|
99
|
+
timeout.unref();
|
|
86
100
|
worker.on("message", (event) => {
|
|
101
|
+
if (event.type === "ready") {
|
|
102
|
+
started = true;
|
|
103
|
+
ready.resolve();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.#clearTimeout(event.id);
|
|
87
107
|
this.#running.delete(event.id);
|
|
88
108
|
this.#results.push(event);
|
|
89
109
|
this.update();
|
|
90
110
|
});
|
|
91
111
|
worker.on("error", (error) => {
|
|
92
|
-
this.#
|
|
112
|
+
if (started) this.#fail(error);
|
|
113
|
+
else ready.reject(error);
|
|
93
114
|
});
|
|
94
|
-
|
|
115
|
+
try {
|
|
116
|
+
await ready.promise;
|
|
117
|
+
return worker;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
worker.terminate();
|
|
120
|
+
throw error;
|
|
121
|
+
} finally {
|
|
122
|
+
clearTimeout(timeout);
|
|
123
|
+
}
|
|
95
124
|
})();
|
|
96
125
|
return this.#worker = await this.#workerPromise;
|
|
97
126
|
}
|
|
98
127
|
update() {
|
|
99
|
-
this.#
|
|
128
|
+
this.#updatePending = true;
|
|
129
|
+
if (this.#updateScheduled) return;
|
|
130
|
+
this.#updateScheduled = (async () => {
|
|
131
|
+
while (this.#updatePending) {
|
|
132
|
+
this.#updatePending = false;
|
|
133
|
+
await this.#update();
|
|
134
|
+
}
|
|
135
|
+
})().catch((error) => this.#fail(error)).finally(() => {
|
|
100
136
|
this.#updateScheduled = void 0;
|
|
137
|
+
if (this.#updatePending) this.update();
|
|
101
138
|
});
|
|
102
139
|
}
|
|
103
140
|
async #update() {
|
|
@@ -105,8 +142,11 @@ var ShikiWorkerClient = class {
|
|
|
105
142
|
const result = this.#results.shift();
|
|
106
143
|
const job = this.#queue.get(result.id);
|
|
107
144
|
if (job) {
|
|
108
|
-
if (result.error)
|
|
109
|
-
|
|
145
|
+
if (result.error) {
|
|
146
|
+
const error = new Error(result.error);
|
|
147
|
+
console.error("Shiki highlighting failed:", error);
|
|
148
|
+
job.reject(error);
|
|
149
|
+
} else job.resolve(result);
|
|
110
150
|
await new Promise((resolve) => setImmediate(resolve));
|
|
111
151
|
this.#queue.delete(job.id);
|
|
112
152
|
}
|
|
@@ -120,18 +160,32 @@ var ShikiWorkerClient = class {
|
|
|
120
160
|
const todo = [...this.#queue.values()].filter((j) => !j.scheduled).slice(-(MAX_RUNNING - this.#running.size));
|
|
121
161
|
await Promise.all(todo.map((j) => this.#request(j)));
|
|
122
162
|
}
|
|
163
|
+
#clearTimeout(id) {
|
|
164
|
+
const timeout = this.#timeouts.get(id);
|
|
165
|
+
if (timeout) clearTimeout(timeout);
|
|
166
|
+
this.#timeouts.delete(id);
|
|
167
|
+
}
|
|
168
|
+
#fail(error) {
|
|
169
|
+
error = toError(error);
|
|
170
|
+
console.error("Shiki worker failed:", error);
|
|
171
|
+
this.#rejectAll(error);
|
|
172
|
+
}
|
|
123
173
|
#rejectAll(error) {
|
|
124
174
|
for (const { reject } of this.#queue.values()) reject(error);
|
|
125
175
|
this.#cache.clear();
|
|
126
176
|
this.#queue.clear();
|
|
127
177
|
this.#running.clear();
|
|
128
178
|
this.#results = [];
|
|
179
|
+
for (const timeout of this.#timeouts.values()) clearTimeout(timeout);
|
|
180
|
+
this.#timeouts.clear();
|
|
181
|
+
this.#updatePending = false;
|
|
129
182
|
this.#worker?.terminate();
|
|
130
183
|
this.#worker = void 0;
|
|
184
|
+
this.#workerPromise = void 0;
|
|
131
185
|
}
|
|
132
186
|
};
|
|
133
187
|
const shikiWorker = new ShikiWorkerClient();
|
|
134
188
|
//#endregion
|
|
135
189
|
export { shikiWorker as n, ShikiWorkerClient as t };
|
|
136
190
|
|
|
137
|
-
//# sourceMappingURL=client-
|
|
191
|
+
//# sourceMappingURL=client-xnCHMO2_.mjs.map
|