@promptctl/rich-js 0.1.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 +418 -0
- package/dist/core/box.d.ts +91 -0
- package/dist/core/box.d.ts.map +1 -0
- package/dist/core/box.js +534 -0
- package/dist/core/box.js.map +1 -0
- package/dist/core/cells.d.ts +24 -0
- package/dist/core/cells.d.ts.map +1 -0
- package/dist/core/cells.js +114 -0
- package/dist/core/cells.js.map +1 -0
- package/dist/core/color.d.ts +158 -0
- package/dist/core/color.d.ts.map +1 -0
- package/dist/core/color.js +825 -0
- package/dist/core/color.js.map +1 -0
- package/dist/core/console.d.ts +100 -0
- package/dist/core/console.d.ts.map +1 -0
- package/dist/core/console.js +353 -0
- package/dist/core/console.js.map +1 -0
- package/dist/core/emoji.d.ts +25 -0
- package/dist/core/emoji.d.ts.map +1 -0
- package/dist/core/emoji.js +392 -0
- package/dist/core/emoji.js.map +1 -0
- package/dist/core/highlighter.d.ts +33 -0
- package/dist/core/highlighter.d.ts.map +1 -0
- package/dist/core/highlighter.js +103 -0
- package/dist/core/highlighter.js.map +1 -0
- package/dist/core/markup.d.ts +69 -0
- package/dist/core/markup.d.ts.map +1 -0
- package/dist/core/markup.js +401 -0
- package/dist/core/markup.js.map +1 -0
- package/dist/core/measure.d.ts +17 -0
- package/dist/core/measure.d.ts.map +1 -0
- package/dist/core/measure.js +50 -0
- package/dist/core/measure.js.map +1 -0
- package/dist/core/protocol.d.ts +32 -0
- package/dist/core/protocol.d.ts.map +1 -0
- package/dist/core/protocol.js +17 -0
- package/dist/core/protocol.js.map +1 -0
- package/dist/core/render.d.ts +51 -0
- package/dist/core/render.d.ts.map +1 -0
- package/dist/core/render.js +69 -0
- package/dist/core/render.js.map +1 -0
- package/dist/core/segment.d.ts +104 -0
- package/dist/core/segment.d.ts.map +1 -0
- package/dist/core/segment.js +364 -0
- package/dist/core/segment.js.map +1 -0
- package/dist/core/spinnerData.d.ts +11 -0
- package/dist/core/spinnerData.d.ts.map +1 -0
- package/dist/core/spinnerData.js +116 -0
- package/dist/core/spinnerData.js.map +1 -0
- package/dist/core/strip.d.ts +159 -0
- package/dist/core/strip.d.ts.map +1 -0
- package/dist/core/strip.js +237 -0
- package/dist/core/strip.js.map +1 -0
- package/dist/core/style.d.ts +115 -0
- package/dist/core/style.d.ts.map +1 -0
- package/dist/core/style.js +662 -0
- package/dist/core/style.js.map +1 -0
- package/dist/core/text.d.ts +91 -0
- package/dist/core/text.d.ts.map +1 -0
- package/dist/core/text.js +610 -0
- package/dist/core/text.js.map +1 -0
- package/dist/index.d.ts +99 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +72 -0
- package/dist/index.js.map +1 -0
- package/dist/renderables/align.d.ts +17 -0
- package/dist/renderables/align.d.ts.map +1 -0
- package/dist/renderables/align.js +47 -0
- package/dist/renderables/align.js.map +1 -0
- package/dist/renderables/columns.d.ts +28 -0
- package/dist/renderables/columns.d.ts.map +1 -0
- package/dist/renderables/columns.js +92 -0
- package/dist/renderables/columns.js.map +1 -0
- package/dist/renderables/constrain.d.ts +16 -0
- package/dist/renderables/constrain.d.ts.map +1 -0
- package/dist/renderables/constrain.js +38 -0
- package/dist/renderables/constrain.js.map +1 -0
- package/dist/renderables/flexStrip.d.ts +42 -0
- package/dist/renderables/flexStrip.d.ts.map +1 -0
- package/dist/renderables/flexStrip.js +201 -0
- package/dist/renderables/flexStrip.js.map +1 -0
- package/dist/renderables/group.d.ts +12 -0
- package/dist/renderables/group.d.ts.map +1 -0
- package/dist/renderables/group.js +16 -0
- package/dist/renderables/group.js.map +1 -0
- package/dist/renderables/json.d.ts +23 -0
- package/dist/renderables/json.d.ts.map +1 -0
- package/dist/renderables/json.js +49 -0
- package/dist/renderables/json.js.map +1 -0
- package/dist/renderables/layout.d.ts +37 -0
- package/dist/renderables/layout.d.ts.map +1 -0
- package/dist/renderables/layout.js +151 -0
- package/dist/renderables/layout.js.map +1 -0
- package/dist/renderables/live.d.ts +48 -0
- package/dist/renderables/live.d.ts.map +1 -0
- package/dist/renderables/live.js +131 -0
- package/dist/renderables/live.js.map +1 -0
- package/dist/renderables/markdown.d.ts +25 -0
- package/dist/renderables/markdown.d.ts.map +1 -0
- package/dist/renderables/markdown.js +190 -0
- package/dist/renderables/markdown.js.map +1 -0
- package/dist/renderables/padding.d.ts +26 -0
- package/dist/renderables/padding.d.ts.map +1 -0
- package/dist/renderables/padding.js +92 -0
- package/dist/renderables/padding.js.map +1 -0
- package/dist/renderables/panel.d.ts +42 -0
- package/dist/renderables/panel.d.ts.map +1 -0
- package/dist/renderables/panel.js +202 -0
- package/dist/renderables/panel.js.map +1 -0
- package/dist/renderables/pretty.d.ts +29 -0
- package/dist/renderables/pretty.d.ts.map +1 -0
- package/dist/renderables/pretty.js +141 -0
- package/dist/renderables/pretty.js.map +1 -0
- package/dist/renderables/progress.d.ts +91 -0
- package/dist/renderables/progress.d.ts.map +1 -0
- package/dist/renderables/progress.js +234 -0
- package/dist/renderables/progress.js.map +1 -0
- package/dist/renderables/progressBar.d.ts +32 -0
- package/dist/renderables/progressBar.d.ts.map +1 -0
- package/dist/renderables/progressBar.js +59 -0
- package/dist/renderables/progressBar.js.map +1 -0
- package/dist/renderables/prompt.d.ts +25 -0
- package/dist/renderables/prompt.d.ts.map +1 -0
- package/dist/renderables/prompt.js +109 -0
- package/dist/renderables/prompt.js.map +1 -0
- package/dist/renderables/rule.d.ts +25 -0
- package/dist/renderables/rule.d.ts.map +1 -0
- package/dist/renderables/rule.js +96 -0
- package/dist/renderables/rule.js.map +1 -0
- package/dist/renderables/spinner.d.ts +30 -0
- package/dist/renderables/spinner.d.ts.map +1 -0
- package/dist/renderables/spinner.js +70 -0
- package/dist/renderables/spinner.js.map +1 -0
- package/dist/renderables/status.d.ts +24 -0
- package/dist/renderables/status.d.ts.map +1 -0
- package/dist/renderables/status.js +67 -0
- package/dist/renderables/status.js.map +1 -0
- package/dist/renderables/syntax.d.ts +36 -0
- package/dist/renderables/syntax.d.ts.map +1 -0
- package/dist/renderables/syntax.js +115 -0
- package/dist/renderables/syntax.js.map +1 -0
- package/dist/renderables/table.d.ts +109 -0
- package/dist/renderables/table.d.ts.map +1 -0
- package/dist/renderables/table.js +434 -0
- package/dist/renderables/table.js.map +1 -0
- package/dist/renderables/traceback.d.ts +26 -0
- package/dist/renderables/traceback.d.ts.map +1 -0
- package/dist/renderables/traceback.js +108 -0
- package/dist/renderables/traceback.js.map +1 -0
- package/dist/renderables/tree.d.ts +30 -0
- package/dist/renderables/tree.d.ts.map +1 -0
- package/dist/renderables/tree.js +107 -0
- package/dist/renderables/tree.js.map +1 -0
- package/dist/template-bindings/index.d.ts +61 -0
- package/dist/template-bindings/index.d.ts.map +1 -0
- package/dist/template-bindings/index.js +70 -0
- package/dist/template-bindings/index.js.map +1 -0
- package/dist/template-bindings/style-funcs.d.ts +30 -0
- package/dist/template-bindings/style-funcs.d.ts.map +1 -0
- package/dist/template-bindings/style-funcs.js +172 -0
- package/dist/template-bindings/style-funcs.js.map +1 -0
- package/dist/themes/buildPalette.d.ts +31 -0
- package/dist/themes/buildPalette.d.ts.map +1 -0
- package/dist/themes/buildPalette.js +43 -0
- package/dist/themes/buildPalette.js.map +1 -0
- package/dist/themes/colorMath.d.ts +23 -0
- package/dist/themes/colorMath.d.ts.map +1 -0
- package/dist/themes/colorMath.js +99 -0
- package/dist/themes/colorMath.js.map +1 -0
- package/dist/themes/data/atom-one-dark.d.ts +4 -0
- package/dist/themes/data/atom-one-dark.d.ts.map +1 -0
- package/dist/themes/data/atom-one-dark.js +159 -0
- package/dist/themes/data/atom-one-dark.js.map +1 -0
- package/dist/themes/data/atom-one-light.d.ts +4 -0
- package/dist/themes/data/atom-one-light.d.ts.map +1 -0
- package/dist/themes/data/atom-one-light.js +159 -0
- package/dist/themes/data/atom-one-light.js.map +1 -0
- package/dist/themes/data/catppuccin-latte.d.ts +4 -0
- package/dist/themes/data/catppuccin-latte.d.ts.map +1 -0
- package/dist/themes/data/catppuccin-latte.js +159 -0
- package/dist/themes/data/catppuccin-latte.js.map +1 -0
- package/dist/themes/data/catppuccin-mocha.d.ts +4 -0
- package/dist/themes/data/catppuccin-mocha.d.ts.map +1 -0
- package/dist/themes/data/catppuccin-mocha.js +159 -0
- package/dist/themes/data/catppuccin-mocha.js.map +1 -0
- package/dist/themes/data/dracula.d.ts +4 -0
- package/dist/themes/data/dracula.d.ts.map +1 -0
- package/dist/themes/data/dracula.js +159 -0
- package/dist/themes/data/dracula.js.map +1 -0
- package/dist/themes/data/flexoki.d.ts +4 -0
- package/dist/themes/data/flexoki.d.ts.map +1 -0
- package/dist/themes/data/flexoki.js +159 -0
- package/dist/themes/data/flexoki.js.map +1 -0
- package/dist/themes/data/gruvbox.d.ts +4 -0
- package/dist/themes/data/gruvbox.d.ts.map +1 -0
- package/dist/themes/data/gruvbox.js +159 -0
- package/dist/themes/data/gruvbox.js.map +1 -0
- package/dist/themes/data/index.d.ts +29 -0
- package/dist/themes/data/index.d.ts.map +1 -0
- package/dist/themes/data/index.js +48 -0
- package/dist/themes/data/index.js.map +1 -0
- package/dist/themes/data/monokai.d.ts +4 -0
- package/dist/themes/data/monokai.d.ts.map +1 -0
- package/dist/themes/data/monokai.js +159 -0
- package/dist/themes/data/monokai.js.map +1 -0
- package/dist/themes/data/nord.d.ts +4 -0
- package/dist/themes/data/nord.d.ts.map +1 -0
- package/dist/themes/data/nord.js +159 -0
- package/dist/themes/data/nord.js.map +1 -0
- package/dist/themes/data/rose-pine-dawn.d.ts +4 -0
- package/dist/themes/data/rose-pine-dawn.d.ts.map +1 -0
- package/dist/themes/data/rose-pine-dawn.js +159 -0
- package/dist/themes/data/rose-pine-dawn.js.map +1 -0
- package/dist/themes/data/rose-pine-moon.d.ts +4 -0
- package/dist/themes/data/rose-pine-moon.d.ts.map +1 -0
- package/dist/themes/data/rose-pine-moon.js +159 -0
- package/dist/themes/data/rose-pine-moon.js.map +1 -0
- package/dist/themes/data/rose-pine.d.ts +4 -0
- package/dist/themes/data/rose-pine.d.ts.map +1 -0
- package/dist/themes/data/rose-pine.js +159 -0
- package/dist/themes/data/rose-pine.js.map +1 -0
- package/dist/themes/data/solarized-dark.d.ts +4 -0
- package/dist/themes/data/solarized-dark.d.ts.map +1 -0
- package/dist/themes/data/solarized-dark.js +159 -0
- package/dist/themes/data/solarized-dark.js.map +1 -0
- package/dist/themes/data/solarized-light.d.ts +4 -0
- package/dist/themes/data/solarized-light.d.ts.map +1 -0
- package/dist/themes/data/solarized-light.js +159 -0
- package/dist/themes/data/solarized-light.js.map +1 -0
- package/dist/themes/data/textual-ansi.d.ts +4 -0
- package/dist/themes/data/textual-ansi.d.ts.map +1 -0
- package/dist/themes/data/textual-ansi.js +159 -0
- package/dist/themes/data/textual-ansi.js.map +1 -0
- package/dist/themes/data/textual-dark.d.ts +4 -0
- package/dist/themes/data/textual-dark.d.ts.map +1 -0
- package/dist/themes/data/textual-dark.js +159 -0
- package/dist/themes/data/textual-dark.js.map +1 -0
- package/dist/themes/data/textual-light.d.ts +4 -0
- package/dist/themes/data/textual-light.d.ts.map +1 -0
- package/dist/themes/data/textual-light.js +159 -0
- package/dist/themes/data/textual-light.js.map +1 -0
- package/dist/themes/data/tokyo-night.d.ts +4 -0
- package/dist/themes/data/tokyo-night.d.ts.map +1 -0
- package/dist/themes/data/tokyo-night.js +159 -0
- package/dist/themes/data/tokyo-night.js.map +1 -0
- package/dist/themes/data/types.d.ts +15 -0
- package/dist/themes/data/types.d.ts.map +1 -0
- package/dist/themes/data/types.js +2 -0
- package/dist/themes/data/types.js.map +1 -0
- package/dist/themes/palette.d.ts +20 -0
- package/dist/themes/palette.d.ts.map +1 -0
- package/dist/themes/palette.js +27 -0
- package/dist/themes/palette.js.map +1 -0
- package/dist/themes/paletteResolver.d.ts +35 -0
- package/dist/themes/paletteResolver.d.ts.map +1 -0
- package/dist/themes/paletteResolver.js +88 -0
- package/dist/themes/paletteResolver.js.map +1 -0
- package/dist/themes/registry.d.ts +17 -0
- package/dist/themes/registry.d.ts.map +1 -0
- package/dist/themes/registry.js +33 -0
- package/dist/themes/registry.js.map +1 -0
- package/dist/themes/terminalThemes.d.ts +46 -0
- package/dist/themes/terminalThemes.d.ts.map +1 -0
- package/dist/themes/terminalThemes.js +268 -0
- package/dist/themes/terminalThemes.js.map +1 -0
- package/dist/widgets/button.d.ts +47 -0
- package/dist/widgets/button.d.ts.map +1 -0
- package/dist/widgets/button.js +183 -0
- package/dist/widgets/button.js.map +1 -0
- package/dist/widgets/checkbox.d.ts +43 -0
- package/dist/widgets/checkbox.d.ts.map +1 -0
- package/dist/widgets/checkbox.js +144 -0
- package/dist/widgets/checkbox.js.map +1 -0
- package/dist/widgets/dropdown.d.ts +67 -0
- package/dist/widgets/dropdown.d.ts.map +1 -0
- package/dist/widgets/dropdown.js +373 -0
- package/dist/widgets/dropdown.js.map +1 -0
- package/dist/widgets/event-router.d.ts +73 -0
- package/dist/widgets/event-router.d.ts.map +1 -0
- package/dist/widgets/event-router.js +479 -0
- package/dist/widgets/event-router.js.map +1 -0
- package/dist/widgets/focus-manager.d.ts +26 -0
- package/dist/widgets/focus-manager.d.ts.map +1 -0
- package/dist/widgets/focus-manager.js +179 -0
- package/dist/widgets/focus-manager.js.map +1 -0
- package/dist/widgets/index.d.ts +23 -0
- package/dist/widgets/index.d.ts.map +1 -0
- package/dist/widgets/index.js +13 -0
- package/dist/widgets/index.js.map +1 -0
- package/dist/widgets/screen.d.ts +90 -0
- package/dist/widgets/screen.d.ts.map +1 -0
- package/dist/widgets/screen.js +440 -0
- package/dist/widgets/screen.js.map +1 -0
- package/dist/widgets/slider.d.ts +55 -0
- package/dist/widgets/slider.d.ts.map +1 -0
- package/dist/widgets/slider.js +248 -0
- package/dist/widgets/slider.js.map +1 -0
- package/dist/widgets/static-item.d.ts +41 -0
- package/dist/widgets/static-item.d.ts.map +1 -0
- package/dist/widgets/static-item.js +62 -0
- package/dist/widgets/static-item.js.map +1 -0
- package/dist/widgets/text-input.d.ts +50 -0
- package/dist/widgets/text-input.d.ts.map +1 -0
- package/dist/widgets/text-input.js +242 -0
- package/dist/widgets/text-input.js.map +1 -0
- package/dist/widgets/toggle.d.ts +46 -0
- package/dist/widgets/toggle.d.ts.map +1 -0
- package/dist/widgets/toggle.js +169 -0
- package/dist/widgets/toggle.js.map +1 -0
- package/dist/widgets/types.d.ts +92 -0
- package/dist/widgets/types.d.ts.map +1 -0
- package/dist/widgets/types.js +13 -0
- package/dist/widgets/types.js.map +1 -0
- package/dist/widgets/widget-base.d.ts +41 -0
- package/dist/widgets/widget-base.d.ts.map +1 -0
- package/dist/widgets/widget-base.js +159 -0
- package/dist/widgets/widget-base.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree — hierarchical view with guide lines.
|
|
3
|
+
*/
|
|
4
|
+
import { Segment } from "../core/segment.js";
|
|
5
|
+
import { Style, NULL_STYLE } from "../core/style.js";
|
|
6
|
+
import { RichText } from "../core/text.js";
|
|
7
|
+
// Guide characters
|
|
8
|
+
const GUIDE_BRANCH = "├── ";
|
|
9
|
+
const GUIDE_LAST = "└── ";
|
|
10
|
+
const GUIDE_VERT = "│ ";
|
|
11
|
+
const GUIDE_SPACE = " ";
|
|
12
|
+
// ASCII fallback
|
|
13
|
+
const GUIDE_BRANCH_ASCII = "+-- ";
|
|
14
|
+
const GUIDE_LAST_ASCII = "+-- ";
|
|
15
|
+
const GUIDE_VERT_ASCII = "| ";
|
|
16
|
+
function resolveStyle(style) {
|
|
17
|
+
if (style === undefined)
|
|
18
|
+
return NULL_STYLE;
|
|
19
|
+
if (typeof style === "string")
|
|
20
|
+
return Style.parse(style);
|
|
21
|
+
return style;
|
|
22
|
+
}
|
|
23
|
+
function toRenderable(label) {
|
|
24
|
+
if (typeof label === "string")
|
|
25
|
+
return new RichText(label, { end: "" });
|
|
26
|
+
if (label instanceof RichText) {
|
|
27
|
+
// Ensure no trailing newline in tree labels
|
|
28
|
+
const copy = label.copy();
|
|
29
|
+
copy.end = "";
|
|
30
|
+
return copy;
|
|
31
|
+
}
|
|
32
|
+
return label;
|
|
33
|
+
}
|
|
34
|
+
export class Tree {
|
|
35
|
+
label;
|
|
36
|
+
children;
|
|
37
|
+
expanded;
|
|
38
|
+
hideRoot;
|
|
39
|
+
guideStyle;
|
|
40
|
+
style;
|
|
41
|
+
constructor(label, options) {
|
|
42
|
+
this.label = toRenderable(label);
|
|
43
|
+
this.children = [];
|
|
44
|
+
this.expanded = options?.expanded !== false;
|
|
45
|
+
this.hideRoot = options?.hideRoot ?? false;
|
|
46
|
+
this.guideStyle = resolveStyle(options?.guide_style);
|
|
47
|
+
this.style = resolveStyle(options?.style);
|
|
48
|
+
}
|
|
49
|
+
add(label, options) {
|
|
50
|
+
const child = new Tree(label, {
|
|
51
|
+
guide_style: options?.guide_style,
|
|
52
|
+
style: options?.style,
|
|
53
|
+
expanded: options?.expanded,
|
|
54
|
+
});
|
|
55
|
+
this.children.push(child);
|
|
56
|
+
return child;
|
|
57
|
+
}
|
|
58
|
+
*render(options) {
|
|
59
|
+
yield* this._renderNode(options, [], !this.hideRoot);
|
|
60
|
+
}
|
|
61
|
+
*_renderNode(options, prefixes, showLabel) {
|
|
62
|
+
const ascii = options.asciiOnly ?? false;
|
|
63
|
+
const guideStyle = this.guideStyle.isNull ? undefined : this.guideStyle;
|
|
64
|
+
if (showLabel) {
|
|
65
|
+
// Render prefix
|
|
66
|
+
for (const prefix of prefixes) {
|
|
67
|
+
yield new Segment(prefix, guideStyle);
|
|
68
|
+
}
|
|
69
|
+
// [LAW:single-enforcer] Tree owns its row boundaries explicitly instead
|
|
70
|
+
// of depending on label renderables to invent trailing newlines.
|
|
71
|
+
yield* this.label.render(options);
|
|
72
|
+
yield Segment.line();
|
|
73
|
+
}
|
|
74
|
+
if (!this.expanded)
|
|
75
|
+
return;
|
|
76
|
+
for (let i = 0; i < this.children.length; i++) {
|
|
77
|
+
const child = this.children[i];
|
|
78
|
+
const isLast = i === this.children.length - 1;
|
|
79
|
+
const branch = ascii
|
|
80
|
+
? (isLast ? GUIDE_LAST_ASCII : GUIDE_BRANCH_ASCII)
|
|
81
|
+
: (isLast ? GUIDE_LAST : GUIDE_BRANCH);
|
|
82
|
+
const continuation = ascii
|
|
83
|
+
? (isLast ? GUIDE_SPACE : GUIDE_VERT_ASCII)
|
|
84
|
+
: (isLast ? GUIDE_SPACE : GUIDE_VERT);
|
|
85
|
+
// Child label with branch guide
|
|
86
|
+
const childGuideStyle = child.guideStyle.isNull ? guideStyle : (child.guideStyle.isNull ? undefined : child.guideStyle);
|
|
87
|
+
// Render child label
|
|
88
|
+
for (const prefix of prefixes) {
|
|
89
|
+
yield new Segment(prefix, childGuideStyle);
|
|
90
|
+
}
|
|
91
|
+
yield new Segment(branch, childGuideStyle);
|
|
92
|
+
yield* child.label.render(options);
|
|
93
|
+
yield Segment.line();
|
|
94
|
+
// Render grandchildren with continuation prefix
|
|
95
|
+
if (child.expanded && child.children.length > 0) {
|
|
96
|
+
const grandPrefixes = [...prefixes, continuation];
|
|
97
|
+
for (let j = 0; j < child.children.length; j++) {
|
|
98
|
+
yield* child.children[j]._renderNode(options, grandPrefixes, true);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
measure(options) {
|
|
104
|
+
return { minimum: 4, maximum: options.maxWidth };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../src/renderables/tree.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAO3C,mBAAmB;AACnB,MAAM,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C,CAAC;YACnC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;YAErB,gDAAgD;YAChD,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAChD,MAAM,aAAa,GAAG,CAAC,GAAG,QAAQ,EAAE,YAAY,CAAC,CAAC;gBAClD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC/C,KAAK,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAE,CAAC,WAAW,CACnC,OAAO,EACP,aAAa,EACb,IAAI,CACL,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,OAAsB;QAC5B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;IACnD,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rich-js template bindings — public entry point.
|
|
3
|
+
*
|
|
4
|
+
* [LAW:one-source-of-truth] This module is the single place where rich-js's
|
|
5
|
+
* styling vocabulary is exposed as `@promptctl/go-template-js` template
|
|
6
|
+
* functions. The current registration set covers foreground colour
|
|
7
|
+
* (named, palette index, hex, RGB), background (`on`), and text
|
|
8
|
+
* attributes (canonical names, short aliases, `not_*` negations) — all
|
|
9
|
+
* registered via `richTextStyleFuncs`. `link`, palette / theme /
|
|
10
|
+
* auto-contrast helpers, and per-position hue rotation ship in follow-up
|
|
11
|
+
* epics on the same `template-bindings` topic and merge into this same
|
|
12
|
+
* map. Consumers compose templates against the Engine returned here;
|
|
13
|
+
* nesting is plain function composition (`{{ red (bold "x") }}`), not a
|
|
14
|
+
* second markup grammar.
|
|
15
|
+
*
|
|
16
|
+
* Fragment type: `RichText`. Chosen because it is the library's primary
|
|
17
|
+
* text type (implements `Renderable` + `Measurable`), composes via
|
|
18
|
+
* `append`, and flows directly into the existing render pipeline with no
|
|
19
|
+
* adapter. Top-level template expressions emit as `RichText[]` — natural
|
|
20
|
+
* for cases where a single template produces multiple independently
|
|
21
|
+
* addressable fragments (e.g. multiple top-level `link` calls, each
|
|
22
|
+
* carrying its own URL).
|
|
23
|
+
*/
|
|
24
|
+
import { type Engine, type FuncMap } from "@promptctl/go-template-js";
|
|
25
|
+
import { RichText } from "../core/text.js";
|
|
26
|
+
/**
|
|
27
|
+
* Funcs registered by the rich-js binding. Style functions
|
|
28
|
+
* (foreground / attribute / background) are populated by
|
|
29
|
+
* `richTextStyleFuncs`; subsequent epics on the `template-bindings`
|
|
30
|
+
* topic merge `link`, palette/theme/auto-contrast, and per-position
|
|
31
|
+
* hue rotation into the same map. Exposed as a factory (not a const)
|
|
32
|
+
* so future registrations that need configuration (e.g. a palette
|
|
33
|
+
* resolver bound at construction time) have a place to receive
|
|
34
|
+
* arguments without breaking the public shape.
|
|
35
|
+
*
|
|
36
|
+
* `FuncMap` is not parameterised over `T` in `@promptctl/go-template-js` — the engine's
|
|
37
|
+
* `T` lives on the `Engine`/`EngineConfig`, and per-function input/output
|
|
38
|
+
* types are carried as runtime `argTypes` on each `TemplateFunc`. The map
|
|
39
|
+
* therefore *type-checks* against any `EngineConfig<T>.funcs`, but the
|
|
40
|
+
* functions returned here are only *runtime-compatible* with
|
|
41
|
+
* `Engine<RichText>`: each style function returns a `RichText` and
|
|
42
|
+
* requires its lifted child to be a `RichText` (enforced by an
|
|
43
|
+
* `instanceof` check that throws on misuse). Consumers merging this map
|
|
44
|
+
* into a wider engine must keep `T = RichText`; merging into an engine
|
|
45
|
+
* whose `T` is something else will compile but fail at evaluation time.
|
|
46
|
+
*/
|
|
47
|
+
export declare function richTextFuncs(): FuncMap;
|
|
48
|
+
/**
|
|
49
|
+
* Construct an `Engine<RichText>` with the rich-js style-function set
|
|
50
|
+
* registered. Consumers that already manage their own engine should call
|
|
51
|
+
* `richTextFuncs()` and merge the result into their own `createEngine`
|
|
52
|
+
* configuration; consumers that just want rich-js styling can use this
|
|
53
|
+
* factory directly.
|
|
54
|
+
*
|
|
55
|
+
* `fromString` lifts text literals into `RichText`. `toString` flattens a
|
|
56
|
+
* `RichText` to its plain text — the engine's no-silent-flatten guard uses
|
|
57
|
+
* this only for `printf "%s"` / `"%q"` and `print*` slots, where ANSI is
|
|
58
|
+
* not desired anyway.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createRichTextEngine(): Engine<RichText>;
|
|
61
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/template-bindings/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAAC,QAAQ,CAAC,CAMvD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rich-js template bindings — public entry point.
|
|
3
|
+
*
|
|
4
|
+
* [LAW:one-source-of-truth] This module is the single place where rich-js's
|
|
5
|
+
* styling vocabulary is exposed as `@promptctl/go-template-js` template
|
|
6
|
+
* functions. The current registration set covers foreground colour
|
|
7
|
+
* (named, palette index, hex, RGB), background (`on`), and text
|
|
8
|
+
* attributes (canonical names, short aliases, `not_*` negations) — all
|
|
9
|
+
* registered via `richTextStyleFuncs`. `link`, palette / theme /
|
|
10
|
+
* auto-contrast helpers, and per-position hue rotation ship in follow-up
|
|
11
|
+
* epics on the same `template-bindings` topic and merge into this same
|
|
12
|
+
* map. Consumers compose templates against the Engine returned here;
|
|
13
|
+
* nesting is plain function composition (`{{ red (bold "x") }}`), not a
|
|
14
|
+
* second markup grammar.
|
|
15
|
+
*
|
|
16
|
+
* Fragment type: `RichText`. Chosen because it is the library's primary
|
|
17
|
+
* text type (implements `Renderable` + `Measurable`), composes via
|
|
18
|
+
* `append`, and flows directly into the existing render pipeline with no
|
|
19
|
+
* adapter. Top-level template expressions emit as `RichText[]` — natural
|
|
20
|
+
* for cases where a single template produces multiple independently
|
|
21
|
+
* addressable fragments (e.g. multiple top-level `link` calls, each
|
|
22
|
+
* carrying its own URL).
|
|
23
|
+
*/
|
|
24
|
+
import { createEngine } from "@promptctl/go-template-js";
|
|
25
|
+
import { RichText } from "../core/text.js";
|
|
26
|
+
import { richTextStyleFuncs } from "./style-funcs.js";
|
|
27
|
+
/**
|
|
28
|
+
* Funcs registered by the rich-js binding. Style functions
|
|
29
|
+
* (foreground / attribute / background) are populated by
|
|
30
|
+
* `richTextStyleFuncs`; subsequent epics on the `template-bindings`
|
|
31
|
+
* topic merge `link`, palette/theme/auto-contrast, and per-position
|
|
32
|
+
* hue rotation into the same map. Exposed as a factory (not a const)
|
|
33
|
+
* so future registrations that need configuration (e.g. a palette
|
|
34
|
+
* resolver bound at construction time) have a place to receive
|
|
35
|
+
* arguments without breaking the public shape.
|
|
36
|
+
*
|
|
37
|
+
* `FuncMap` is not parameterised over `T` in `@promptctl/go-template-js` — the engine's
|
|
38
|
+
* `T` lives on the `Engine`/`EngineConfig`, and per-function input/output
|
|
39
|
+
* types are carried as runtime `argTypes` on each `TemplateFunc`. The map
|
|
40
|
+
* therefore *type-checks* against any `EngineConfig<T>.funcs`, but the
|
|
41
|
+
* functions returned here are only *runtime-compatible* with
|
|
42
|
+
* `Engine<RichText>`: each style function returns a `RichText` and
|
|
43
|
+
* requires its lifted child to be a `RichText` (enforced by an
|
|
44
|
+
* `instanceof` check that throws on misuse). Consumers merging this map
|
|
45
|
+
* into a wider engine must keep `T = RichText`; merging into an engine
|
|
46
|
+
* whose `T` is something else will compile but fail at evaluation time.
|
|
47
|
+
*/
|
|
48
|
+
export function richTextFuncs() {
|
|
49
|
+
return richTextStyleFuncs();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Construct an `Engine<RichText>` with the rich-js style-function set
|
|
53
|
+
* registered. Consumers that already manage their own engine should call
|
|
54
|
+
* `richTextFuncs()` and merge the result into their own `createEngine`
|
|
55
|
+
* configuration; consumers that just want rich-js styling can use this
|
|
56
|
+
* factory directly.
|
|
57
|
+
*
|
|
58
|
+
* `fromString` lifts text literals into `RichText`. `toString` flattens a
|
|
59
|
+
* `RichText` to its plain text — the engine's no-silent-flatten guard uses
|
|
60
|
+
* this only for `printf "%s"` / `"%q"` and `print*` slots, where ANSI is
|
|
61
|
+
* not desired anyway.
|
|
62
|
+
*/
|
|
63
|
+
export function createRichTextEngine() {
|
|
64
|
+
return createEngine({
|
|
65
|
+
fromString: (s) => new RichText(s),
|
|
66
|
+
toString: (rt) => rt.plain,
|
|
67
|
+
funcs: richTextFuncs(),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/template-bindings/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,YAAY,EAA6B,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,kBAAkB,EAAE,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,YAAY,CAAW;QAC5B,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC;QAClC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK;QAC1B,KAAK,EAAE,aAAa,EAAE;KACvB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style-function registrations for the rich-js template binding.
|
|
3
|
+
*
|
|
4
|
+
* [LAW:one-source-of-truth] The function inventory below mirrors the
|
|
5
|
+
* string-syntax style vocabulary documented in `spec/style.md` —
|
|
6
|
+
* foreground colours (named, palette index, hex, RGB), background
|
|
7
|
+
* (`on`), text attributes (positive + negated), and short aliases.
|
|
8
|
+
* Each registration is a templating-time analogue of a piece of
|
|
9
|
+
* `Style.parse`, so a template fragment composed by these functions
|
|
10
|
+
* round-trips through `Style` without semantic drift.
|
|
11
|
+
*
|
|
12
|
+
* [LAW:dataflow-not-control-flow] Every function follows the same
|
|
13
|
+
* shape: child `RichText` in, `RichText` out. The styling difference
|
|
14
|
+
* lives in a captured `Style` value (or constructor closure), not in
|
|
15
|
+
* branches inside a single dispatch. That is why this file is mostly
|
|
16
|
+
* factories — the data (the colour, the attribute name) is the
|
|
17
|
+
* variability; the operation is fixed.
|
|
18
|
+
*/
|
|
19
|
+
import type { FuncMap } from "@promptctl/go-template-js";
|
|
20
|
+
/**
|
|
21
|
+
* The full binding registration set populated by the template-bindings
|
|
22
|
+
* style epics — foreground colours (named + generic forms), background
|
|
23
|
+
* (`on`), text attributes (canonical names, short aliases, and `not_*`
|
|
24
|
+
* negations), and the hyperlink cell-splitter (`link`).
|
|
25
|
+
*
|
|
26
|
+
* Palette/theme/auto-contrast and per-position hue rotation are
|
|
27
|
+
* deliberately absent — they ship in `rich-template-bindings-83q`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function richTextStyleFuncs(): FuncMap;
|
|
30
|
+
//# sourceMappingURL=style-funcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-funcs.d.ts","sourceRoot":"","sources":["../../src/template-bindings/style-funcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,2BAA2B,CAAC;AAkKvE;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAU5C"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Style-function registrations for the rich-js template binding.
|
|
3
|
+
*
|
|
4
|
+
* [LAW:one-source-of-truth] The function inventory below mirrors the
|
|
5
|
+
* string-syntax style vocabulary documented in `spec/style.md` —
|
|
6
|
+
* foreground colours (named, palette index, hex, RGB), background
|
|
7
|
+
* (`on`), text attributes (positive + negated), and short aliases.
|
|
8
|
+
* Each registration is a templating-time analogue of a piece of
|
|
9
|
+
* `Style.parse`, so a template fragment composed by these functions
|
|
10
|
+
* round-trips through `Style` without semantic drift.
|
|
11
|
+
*
|
|
12
|
+
* [LAW:dataflow-not-control-flow] Every function follows the same
|
|
13
|
+
* shape: child `RichText` in, `RichText` out. The styling difference
|
|
14
|
+
* lives in a captured `Style` value (or constructor closure), not in
|
|
15
|
+
* branches inside a single dispatch. That is why this file is mostly
|
|
16
|
+
* factories — the data (the colour, the attribute name) is the
|
|
17
|
+
* variability; the operation is fixed.
|
|
18
|
+
*/
|
|
19
|
+
import { Style, ATTRIBUTE_NAMES, ATTRIBUTE_SHORT_ALIASES, } from "../core/style.js";
|
|
20
|
+
import { ColorSpec, ANSI_COLOR_NAMES } from "../core/color.js";
|
|
21
|
+
import { RichText } from "../core/text.js";
|
|
22
|
+
// --- Helpers ---
|
|
23
|
+
/**
|
|
24
|
+
* Apply a style on top of an already-styled RichText fragment.
|
|
25
|
+
*
|
|
26
|
+
* The engine's `"liftable"` arg type lifts string literals to
|
|
27
|
+
* `RichText` via the binding's `fromString` *before* the body runs,
|
|
28
|
+
* so by the time we get here, `child` is always a `RichText`. The
|
|
29
|
+
* defensive instanceof check exists because `"liftable"` admits any
|
|
30
|
+
* non-primitive value — the engine cannot prove the object is the
|
|
31
|
+
* binding's own `T`. A misuse (`{{ red someMap }}`) lands here and
|
|
32
|
+
* fails loudly rather than producing a malformed fragment.
|
|
33
|
+
*
|
|
34
|
+
* Conflict resolution follows `Style.add`: the outer (newly applied)
|
|
35
|
+
* style wins. `red (bold "x")` → bold + red; `red (red "x")` → red.
|
|
36
|
+
* Spans inside the inner fragment are preserved as-is — their styles
|
|
37
|
+
* compose with the new wrapper at render time via the segment
|
|
38
|
+
* pipeline's existing additive semantics.
|
|
39
|
+
*/
|
|
40
|
+
function applyStyleToFragment(child, style) {
|
|
41
|
+
if (!(child instanceof RichText)) {
|
|
42
|
+
throw new TypeError(`style function expected a RichText fragment, got ${typeof child === "object" ? Object.prototype.toString.call(child) : typeof child}`);
|
|
43
|
+
}
|
|
44
|
+
const result = child.copy();
|
|
45
|
+
result.style = child.style.add(style);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function fgFunc(style) {
|
|
49
|
+
return {
|
|
50
|
+
fn: ((child) => applyStyleToFragment(child, style)),
|
|
51
|
+
argTypes: ["liftable"],
|
|
52
|
+
returnType: "T",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// --- Foreground colours: named ---
|
|
56
|
+
function namedColorFuncs() {
|
|
57
|
+
const out = {};
|
|
58
|
+
for (const name of Object.keys(ANSI_COLOR_NAMES)) {
|
|
59
|
+
const colorSpec = ColorSpec.parse(name);
|
|
60
|
+
out[name] = fgFunc(new Style({ color: colorSpec }));
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
// --- Foreground colours: generic forms ---
|
|
65
|
+
const colorPaletteFunc = {
|
|
66
|
+
fn: ((index, child) => {
|
|
67
|
+
if (!Number.isInteger(index) || index < 0 || index > 255) {
|
|
68
|
+
throw new RangeError(`color index ${index} is out of range (0-255)`);
|
|
69
|
+
}
|
|
70
|
+
return applyStyleToFragment(child, new Style({ color: ColorSpec.fromAnsi(index) }));
|
|
71
|
+
}),
|
|
72
|
+
argTypes: ["number", "liftable"],
|
|
73
|
+
returnType: "T",
|
|
74
|
+
};
|
|
75
|
+
// [LAW:types-are-the-program] `hex` advertises a narrower domain than the
|
|
76
|
+
// general colour-spec parser — only `#RRGGBB` / `#RRGGBBAA` is admitted.
|
|
77
|
+
// Without this gate, `ColorSpec.parse` would silently accept any colour-spec
|
|
78
|
+
// string (named colours, `rgb(...)`, `color(N)`), letting `hex "red"` succeed
|
|
79
|
+
// and masking author mistakes.
|
|
80
|
+
const HEX_INPUT_RE = /^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/;
|
|
81
|
+
const colorHexFunc = {
|
|
82
|
+
fn: ((hex, child) => {
|
|
83
|
+
if (!HEX_INPUT_RE.test(hex)) {
|
|
84
|
+
throw new RangeError(`hex expected #RRGGBB or #RRGGBBAA, got ${JSON.stringify(hex)}`);
|
|
85
|
+
}
|
|
86
|
+
return applyStyleToFragment(child, new Style({ color: ColorSpec.parse(hex) }));
|
|
87
|
+
}),
|
|
88
|
+
argTypes: ["string", "liftable"],
|
|
89
|
+
returnType: "T",
|
|
90
|
+
};
|
|
91
|
+
const colorRgbFunc = {
|
|
92
|
+
fn: ((r, g, b, child) => {
|
|
93
|
+
return applyStyleToFragment(child, new Style({ color: ColorSpec.fromRgb(r, g, b) }));
|
|
94
|
+
}),
|
|
95
|
+
argTypes: ["number", "number", "number", "liftable"],
|
|
96
|
+
returnType: "T",
|
|
97
|
+
};
|
|
98
|
+
// --- Background ---
|
|
99
|
+
const onFunc = {
|
|
100
|
+
fn: ((spec, child) => {
|
|
101
|
+
return applyStyleToFragment(child, new Style({ bgcolor: ColorSpec.parse(spec) }));
|
|
102
|
+
}),
|
|
103
|
+
argTypes: ["string", "liftable"],
|
|
104
|
+
returnType: "T",
|
|
105
|
+
};
|
|
106
|
+
// --- Text attributes ---
|
|
107
|
+
//
|
|
108
|
+
// [LAW:one-source-of-truth] The attribute and short-alias inventories
|
|
109
|
+
// come from `core/style.ts`. This file derives the template registration
|
|
110
|
+
// set from the same data `Style.parse` consults — adding an attribute or
|
|
111
|
+
// alias in one place propagates here automatically.
|
|
112
|
+
function attrStyle(name, value) {
|
|
113
|
+
return new Style({ [name]: value });
|
|
114
|
+
}
|
|
115
|
+
function attributeFuncs() {
|
|
116
|
+
const out = {};
|
|
117
|
+
for (const name of ATTRIBUTE_NAMES) {
|
|
118
|
+
out[name] = fgFunc(attrStyle(name, true));
|
|
119
|
+
out[`not_${name}`] = fgFunc(attrStyle(name, false));
|
|
120
|
+
}
|
|
121
|
+
for (const [alias, canonical] of Object.entries(ATTRIBUTE_SHORT_ALIASES)) {
|
|
122
|
+
out[alias] = fgFunc(attrStyle(canonical, true));
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
// --- Hyperlink ---
|
|
127
|
+
//
|
|
128
|
+
// `link` is the cell-splitter for the multi-cell consumer contract.
|
|
129
|
+
// Implementation-wise it is the same shape as any other style function:
|
|
130
|
+
// it sets the `link` slot of `Style` exactly as the existing string-form
|
|
131
|
+
// `link URL` does, so a template-built fragment is byte-equivalent to
|
|
132
|
+
// `RichText("x", { style: Style.parse("link u") })`.
|
|
133
|
+
//
|
|
134
|
+
// The cell-boundary signal that consumers (cc-candybar et al.) walk is
|
|
135
|
+
// `fragment.style.link` being truthy. `Style.add` propagates `link`
|
|
136
|
+
// through any outer wrapping call, so `{{ red (link "u" "x") }}` and
|
|
137
|
+
// `{{ link "u" "x" }}` produce shapes that both qualify as cells from
|
|
138
|
+
// the consumer's perspective. Outer-wins on nested links comes for free
|
|
139
|
+
// from `Style.add`'s right-wins-on-conflict rule.
|
|
140
|
+
//
|
|
141
|
+
// [LAW:dataflow-not-control-flow] No special-case AST node, no
|
|
142
|
+
// `LinkFragment` subclass, no second emitter path — the variability is
|
|
143
|
+
// the value of `style.link`, not whether some control-flow branch ran.
|
|
144
|
+
const linkFunc = {
|
|
145
|
+
fn: ((url, child) => {
|
|
146
|
+
return applyStyleToFragment(child, new Style({ link: url }));
|
|
147
|
+
}),
|
|
148
|
+
argTypes: ["string", "liftable"],
|
|
149
|
+
returnType: "T",
|
|
150
|
+
};
|
|
151
|
+
// --- Public assembly ---
|
|
152
|
+
/**
|
|
153
|
+
* The full binding registration set populated by the template-bindings
|
|
154
|
+
* style epics — foreground colours (named + generic forms), background
|
|
155
|
+
* (`on`), text attributes (canonical names, short aliases, and `not_*`
|
|
156
|
+
* negations), and the hyperlink cell-splitter (`link`).
|
|
157
|
+
*
|
|
158
|
+
* Palette/theme/auto-contrast and per-position hue rotation are
|
|
159
|
+
* deliberately absent — they ship in `rich-template-bindings-83q`.
|
|
160
|
+
*/
|
|
161
|
+
export function richTextStyleFuncs() {
|
|
162
|
+
return {
|
|
163
|
+
...namedColorFuncs(),
|
|
164
|
+
color: colorPaletteFunc,
|
|
165
|
+
hex: colorHexFunc,
|
|
166
|
+
rgb: colorRgbFunc,
|
|
167
|
+
on: onFunc,
|
|
168
|
+
...attributeFuncs(),
|
|
169
|
+
link: linkFunc,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=style-funcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-funcs.js","sourceRoot":"","sources":["../../src/template-bindings/style-funcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EACL,KAAK,EACL,eAAe,EACf,uBAAuB,GAExB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,kBAAkB;AAElB;;;;;;;;;;;;;;;;GAgBG;AACH,SAAS,oBAAoB,CAAC,KAAc,EAAE,K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AO,GAAG,CAAC;AACb,CAAC;AAED,oBAAoB;AACpB,EAAE;AACF,oEAAoE;AACpE,wEAAwE;AACxE,yEAAyE;AACzE,sEAAsE;AACtE,qDAAqD;AACrD,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,qEAAqE;AACrE,sEAAsE;AACtE,wEAAwE;AACxE,kDAAkD;AAClD,EAAE;AACF,+DAA+D;AAC/D,uEAAuE;AACvE,uEAAuE;AAEvE,MAAM,QAAQ,GAAiB;IAC7B,EAAE,EAAE,CAAC,CAAC,GAAW,EAAE,KAAc,EAAE,EAAE;QACnC,OAAO,oBAAoB,CAAC,KAAK,EAAE,IAAI,KAAK,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;IAC/D,CAAC,CAAuB;IACxB,QAAQ,EAAE,CAAC,QAAQ,EAAE,UAAU,CAAC;IAChC,UAAU,EAAE,GAAG;CAChB,CAAC;AAEF,0BAA0B;AAE1B;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO;QACL,GAAG,eAAe,EAAE;QACpB,KAAK,EAAE,gBAAgB;QACvB,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,YAAY;QACjB,EAAE,EAAE,MAAM;QACV,GAAG,cAAc,EAAE;QACnB,IAAI,EAAE,QAAQ;KACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ColorRgba } from "../core/color.js";
|
|
2
|
+
import { Palette } from "./palette.js";
|
|
3
|
+
/**
|
|
4
|
+
* Base colors required to build a full semantic palette.
|
|
5
|
+
* All are ColorRgba — callers construct from whatever source (hex, HSL, etc.).
|
|
6
|
+
*/
|
|
7
|
+
export interface BaseColors {
|
|
8
|
+
primary: ColorRgba;
|
|
9
|
+
secondary: ColorRgba;
|
|
10
|
+
accent: ColorRgba;
|
|
11
|
+
success: ColorRgba;
|
|
12
|
+
warning: ColorRgba;
|
|
13
|
+
error: ColorRgba;
|
|
14
|
+
background: ColorRgba;
|
|
15
|
+
foreground: ColorRgba;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Build a full semantic palette from base colors.
|
|
19
|
+
*
|
|
20
|
+
* Derived entries follow Textual's formulas:
|
|
21
|
+
* - `*-muted` = color blended 70% toward background
|
|
22
|
+
* - `text-*` = contrast text tinted 66% with the accent color (use as
|
|
23
|
+
* foreground in muted/background-tinted contexts)
|
|
24
|
+
* - `on-*` = WCAG-correct contrast colour (black or white) for use as
|
|
25
|
+
* foreground when the FULL accent is the background. Picked
|
|
26
|
+
* by relative luminance — single source of truth so widgets
|
|
27
|
+
* never need to invert / reverse fg/bg to get readable text.
|
|
28
|
+
* - `surface` = background blended 5% toward foreground
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildPalette(name: string, dark: boolean, base: BaseColors): Palette;
|
|
31
|
+
//# sourceMappingURL=buildPalette.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPalette.d.ts","sourceRoot":"","sources":["../../src/themes/buildPalette.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,SAAS,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,SAAS,CAAC;IACnB,OAAO,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,SAAS,CAAC;IACtB,UAAU,EAAE,SAAS,CAAC;CACvB;AAUD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAyBnF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { blendRgb } from "../core/color.js";
|
|
2
|
+
import { alphaBlend, contrastFor } from "./colorMath.js";
|
|
3
|
+
import { Palette } from "./palette.js";
|
|
4
|
+
const MUTED_BLEND = 0.7;
|
|
5
|
+
const TEXT_ALPHA = 0.66;
|
|
6
|
+
const SURFACE_LIFT = 0.05;
|
|
7
|
+
const ACCENT_KEYS = ["primary", "secondary", "accent", "success", "warning", "error"];
|
|
8
|
+
/**
|
|
9
|
+
* Build a full semantic palette from base colors.
|
|
10
|
+
*
|
|
11
|
+
* Derived entries follow Textual's formulas:
|
|
12
|
+
* - `*-muted` = color blended 70% toward background
|
|
13
|
+
* - `text-*` = contrast text tinted 66% with the accent color (use as
|
|
14
|
+
* foreground in muted/background-tinted contexts)
|
|
15
|
+
* - `on-*` = WCAG-correct contrast colour (black or white) for use as
|
|
16
|
+
* foreground when the FULL accent is the background. Picked
|
|
17
|
+
* by relative luminance — single source of truth so widgets
|
|
18
|
+
* never need to invert / reverse fg/bg to get readable text.
|
|
19
|
+
* - `surface` = background blended 5% toward foreground
|
|
20
|
+
*/
|
|
21
|
+
export function buildPalette(name, dark, base) {
|
|
22
|
+
const vars = new Map();
|
|
23
|
+
// Base entries
|
|
24
|
+
vars.set("background", base.background);
|
|
25
|
+
vars.set("foreground", base.foreground);
|
|
26
|
+
for (const key of ACCENT_KEYS) {
|
|
27
|
+
vars.set(key, base[key]);
|
|
28
|
+
}
|
|
29
|
+
// Surface — subtle lift from background
|
|
30
|
+
vars.set("surface", blendRgb(base.background, base.foreground, SURFACE_LIFT));
|
|
31
|
+
// Derived: muted, text-, and on- for each accent.
|
|
32
|
+
// [LAW:single-enforcer] contrastFor is the only place that decides
|
|
33
|
+
// black-vs-white for "text on this accent" — widgets read on-${accent}.
|
|
34
|
+
const contrastText = contrastFor(base.background);
|
|
35
|
+
for (const key of ACCENT_KEYS) {
|
|
36
|
+
const color = base[key];
|
|
37
|
+
vars.set(`${key}-muted`, blendRgb(color, base.background, MUTED_BLEND));
|
|
38
|
+
vars.set(`text-${key}`, alphaBlend(color, contrastText, TEXT_ALPHA));
|
|
39
|
+
vars.set(`on-${key}`, contrastFor(color));
|
|
40
|
+
}
|
|
41
|
+
return new Palette(name, dark, vars);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=buildPalette.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPalette.js","sourceRoot":"","sources":["../../src/themes/buildPalette.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAiBvC,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,YAAY,GAAG,IAAI,CAAC;AAI1B,MAAM,WAAW,GAAgB,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAEnG;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAa,EAAE,IAAgB;IACxE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC;IAE1C,eAAe;IACf,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACxC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACxC,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3B,CAAC;IAED,wCAAwC;IACxC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAE9E,kDAAkD;IAClD,mEAAmE;IACnE,wEAAwE;IACxE,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAClD,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;QACxE,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,EAAE,EAAE,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;QACrE,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ColorRgba } from "../core/color.js";
|
|
2
|
+
/**
|
|
3
|
+
* Darken a color by N levels, where each level reduces HSL lightness by 10%.
|
|
4
|
+
* Negative levels lighten. Level 0 returns an equivalent triplet (after the
|
|
5
|
+
* RGB↔HSL roundtrip; values may differ by ±1 due to rounding).
|
|
6
|
+
*/
|
|
7
|
+
export declare function darken(color: ColorRgba, levels: number): ColorRgba;
|
|
8
|
+
/**
|
|
9
|
+
* Lighten a color by N levels. Equivalent to `darken(color, -levels)`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function lighten(color: ColorRgba, levels: number): ColorRgba;
|
|
12
|
+
/**
|
|
13
|
+
* Composite `fg` over `bg` with the given alpha (0..1). At alpha=0 returns bg;
|
|
14
|
+
* at alpha=1 returns fg.
|
|
15
|
+
*/
|
|
16
|
+
export declare function alphaBlend(fg: ColorRgba, bg: ColorRgba, alpha: number): ColorRgba;
|
|
17
|
+
/**
|
|
18
|
+
* Pick a contrasting foreground (black or white) for a background, using the
|
|
19
|
+
* WCAG relative-luminance threshold of 0.179 (the perceptually correct cutoff
|
|
20
|
+
* where black and white are equally readable).
|
|
21
|
+
*/
|
|
22
|
+
export declare function contrastFor(bg: ColorRgba): ColorRgba;
|
|
23
|
+
//# sourceMappingURL=colorMath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorMath.d.ts","sourceRoot":"","sources":["../../src/themes/colorMath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAY,MAAM,kBAAkB,CAAC;AAmEvD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAIlE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAEnE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,EAAE,EAAE,SAAS,EACb,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,MAAM,GACZ,SAAS,CAEX;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,GAAG,SAAS,CAKpD"}
|