@promptctl/rich-js 0.6.0 → 0.7.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/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/template-bindings/color-funcs.d.ts +78 -0
- package/dist/template-bindings/color-funcs.d.ts.map +1 -0
- package/dist/template-bindings/color-funcs.js +212 -0
- package/dist/template-bindings/color-funcs.js.map +1 -0
- package/dist/template-bindings/index.d.ts +25 -18
- package/dist/template-bindings/index.d.ts.map +1 -1
- package/dist/template-bindings/index.js +27 -19
- package/dist/template-bindings/index.js.map +1 -1
- package/dist/template-bindings/palette-funcs.d.ts +60 -53
- package/dist/template-bindings/palette-funcs.d.ts.map +1 -1
- package/dist/template-bindings/palette-funcs.js +64 -132
- package/dist/template-bindings/palette-funcs.js.map +1 -1
- package/dist/template-bindings/style-funcs.d.ts +11 -12
- package/dist/template-bindings/style-funcs.d.ts.map +1 -1
- package/dist/template-bindings/style-funcs.js +48 -74
- package/dist/template-bindings/style-funcs.js.map +1 -1
- package/dist/themes/buildPalette.d.ts +7 -1
- package/dist/themes/buildPalette.d.ts.map +1 -1
- package/dist/themes/buildPalette.js +15 -1
- package/dist/themes/buildPalette.js.map +1 -1
- package/dist/themes/colorRef.d.ts +52 -0
- package/dist/themes/colorRef.d.ts.map +1 -0
- package/dist/themes/colorRef.js +97 -0
- package/dist/themes/colorRef.js.map +1 -0
- package/dist/themes/palette.d.ts +4 -2
- package/dist/themes/palette.d.ts.map +1 -1
- package/dist/themes/palette.js +4 -2
- package/dist/themes/palette.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,7 @@ export type { DetectColorOptions } from "./core/color.js";
|
|
|
5
5
|
export { Oklch, IDENTITY, INVERT_LIGHTNESS, isIdentityKey, } from "./core/oklch.js";
|
|
6
6
|
export type { ThemeKey } from "./core/oklch.js";
|
|
7
7
|
export { Palette } from "./themes/palette.js";
|
|
8
|
-
export {
|
|
9
|
-
export type { ResolveContext } from "./themes/paletteResolver.js";
|
|
8
|
+
export { resolveColorRef, parseHexColor, ColorRefError, HEX_COLOR_RE, } from "./themes/colorRef.js";
|
|
10
9
|
export { buildPalette } from "./themes/buildPalette.js";
|
|
11
10
|
export type { BaseColors } from "./themes/buildPalette.js";
|
|
12
11
|
export { DEFAULT_TERMINAL_THEME, MONOKAI, SVG_EXPORT_THEME, NORD, GRUVBOX, DRACULA, TOKYO_NIGHT, FLEXOKI, CYBERPUNK, CATPPUCCIN_MOCHA, CATPPUCCIN_LATTE, CATPPUCCIN_FRAPPE, CATPPUCCIN_MACCHIATO, SOLARIZED_DARK, SOLARIZED_LIGHT, ROSE_PINE, ROSE_PINE_MOON, ROSE_PINE_DAWN, ATOM_ONE_DARK, ATOM_ONE_LIGHT, TEXTUAL_DARK, TEXTUAL_LIGHT, TEXTUAL_ANSI, } from "./themes/terminalThemes.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACT,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,SAAS,EACT,UAAU,EACV,WAAW,EACX,aAAa,EACb,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,kBAAk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7C,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,YAAY,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACnF,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,aAAa,EACb,uBAAuB,EACvB,0BAA0B,EAC1B,aAAa,EACb,eAAe,EACf,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAGtD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,9 @@ export { ColorRgba, ColorTable, ColorDepth, ColorSpec, ColorParseError, Terminal
|
|
|
5
5
|
export { Oklch, IDENTITY, INVERT_LIGHTNESS, isIdentityKey, } from "./core/oklch.js";
|
|
6
6
|
// Themes — semantic palettes (distinct from ColorTable quantization LUTs)
|
|
7
7
|
export { Palette } from "./themes/palette.js";
|
|
8
|
-
|
|
8
|
+
// The one checkpoint turning an author-written colour string — a palette
|
|
9
|
+
// variable name or a `#RRGGBB` literal — into a colour. [LAW:parse-dont-validate]
|
|
10
|
+
export { resolveColorRef, parseHexColor, ColorRefError, HEX_COLOR_RE, } from "./themes/colorRef.js";
|
|
9
11
|
export { buildPalette } from "./themes/buildPalette.js";
|
|
10
12
|
export { DEFAULT_TERMINAL_THEME, MONOKAI, SVG_EXPORT_THEME, NORD, GRUVBOX, DRACULA, TOKYO_NIGHT, FLEXOKI, CYBERPUNK, CATPPUCCIN_MOCHA, CATPPUCCIN_LATTE, CATPPUCCIN_FRAPPE, CATPPUCCIN_MACCHIATO, SOLARIZED_DARK, SOLARIZED_LIGHT, ROSE_PINE, ROSE_PINE_MOON, ROSE_PINE_DAWN, ATOM_ONE_DARK, ATOM_ONE_LIGHT, TEXTUAL_DARK, TEXTUAL_LIGHT, TEXTUAL_ANSI, } from "./themes/terminalThemes.js";
|
|
11
13
|
export { getThemePalette, listThemePalettes } from "./themes/registry.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACT,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,SAAS,EACT,UAAU,EACV,WAAW,EACX,aAAa,EACb,aAAa,GACd,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,aAAa,EACb,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AAGzB,kEAAkE;AAClE,OAAO,EACL,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,aAAa,GACd,MAAM,iBAAiB,CAAC;AAGzB,0EAA0E;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACT,OAAO,EACP,WAAW,EACX,uBAAuB,EACvB,SAAS,EACT,UAAU,EACV,WAAW,EACX,aAAa,EACb,aAAa,GACd,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,SAAS,EACT,eAAe,EACf,aAAa,EACb,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,E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,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAmBjD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAYnF,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,sFAAsF;AACtF,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color *values* for the rich-js template binding.
|
|
3
|
+
*
|
|
4
|
+
* ### Why colors are values
|
|
5
|
+
*
|
|
6
|
+
* Every other function in this binding layer takes a child fragment and
|
|
7
|
+
* returns a styled fragment. These do not: they take colors and return a
|
|
8
|
+
* color. That is the whole point. Before this module existed, a color could
|
|
9
|
+
* not survive between two operations — every color function resolved and
|
|
10
|
+
* applied in one breath — so composing two color operations had to be spelled
|
|
11
|
+
* as a *string grammar* (`"primary-darken-3 50%"`), a second language
|
|
12
|
+
* reimplementing function application inside a string literal. Every new color
|
|
13
|
+
* operation meant a new grammar production. [LAW:no-mode-explosion]
|
|
14
|
+
*
|
|
15
|
+
* With colors as values the surface is one shape that grows by nesting:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* {{ fg (color "primary") .branch }}
|
|
19
|
+
* {{ fg (darken (color "primary") 2) .branch }}
|
|
20
|
+
* {{ fg (mix (color "foreground") (color "surface") 65) .label }}
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The simple case is a literal prefix of the composed case — an author adding
|
|
24
|
+
* a `darken` to working code wraps it, rather than rewriting it into an
|
|
25
|
+
* unfamiliar form. [LAW:composability]
|
|
26
|
+
*
|
|
27
|
+
* ### The carrier is a hex string, deliberately
|
|
28
|
+
*
|
|
29
|
+
* A color crosses the template seam as `#RRGGBB`, not as an opaque object,
|
|
30
|
+
* for three reasons:
|
|
31
|
+
*
|
|
32
|
+
* 1. **The type separates.** `"string"` is the strictest arg slot the template
|
|
33
|
+
* engine has — it *refuses* typed `T`. So a color slot cannot silently
|
|
34
|
+
* accept a text fragment. An opaque object would land in `"T"`/`"liftable"`,
|
|
35
|
+
* both of which admit any non-primitive, and `{{ bold (color "primary") }}`
|
|
36
|
+
* would type-check its way into nonsense. [LAW:types-are-the-program]
|
|
37
|
+
* 2. **It flows through the language.** `{{ $muted := mix … }}` holds it,
|
|
38
|
+
* `printf` prints it, `eq` compares it — no engine changes required. Naming
|
|
39
|
+
* a color once and using it ten times is the ergonomic payoff.
|
|
40
|
+
* 3. **Misuse is visible.** A color that lands in text position renders as
|
|
41
|
+
* `#7aa2f7` — wrong in a way an author immediately sees, never a silently
|
|
42
|
+
* dropped style. [LAW:no-silent-failure]
|
|
43
|
+
*
|
|
44
|
+
* No precision is given up: `darken`, `blendRgb`, and `contrastFor` already
|
|
45
|
+
* take and return 8-bit `ColorRgba`. The one caveat is OKLCH: each of the
|
|
46
|
+
* axis functions below round-trips sRGB→OKLCH→sRGB, so chaining three or more
|
|
47
|
+
* of them quantizes visibly. Compose two, or reach for `transposePalette` when
|
|
48
|
+
* a whole palette needs adapting — the same caveat that already applies to
|
|
49
|
+
* chained transpositions.
|
|
50
|
+
*
|
|
51
|
+
* ### Palette-free on purpose
|
|
52
|
+
*
|
|
53
|
+
* Nothing here knows what a palette is. `color` (the one palette-dependent
|
|
54
|
+
* function, in `palette-funcs.ts`) turns a name into a hex string; from that
|
|
55
|
+
* point on the math is pure. A consumer with no theme system at all still gets
|
|
56
|
+
* the full color vocabulary by feeding it hex literals. [LAW:one-way-deps]
|
|
57
|
+
*/
|
|
58
|
+
import type { FuncMap } from "@promptctl/go-template-js";
|
|
59
|
+
/**
|
|
60
|
+
* The palette-free color vocabulary: every function takes colors and returns a
|
|
61
|
+
* color, so they compose by nesting.
|
|
62
|
+
*
|
|
63
|
+
* | function | meaning |
|
|
64
|
+
* |---|---|
|
|
65
|
+
* | `darken c n` / `lighten c n` | slide HSL lightness by N 10% levels |
|
|
66
|
+
* | `mix a b pct` | blend `a` toward `b` by `pct`% (0 → `a`, 100 → `b`) |
|
|
67
|
+
* | `contrastOn bg` | black or white, whichever is readable on `bg` |
|
|
68
|
+
* | `readableOn fg bg ratio` | `fg` nudged in OKLCH lightness until it clears `ratio` on `bg`, hue preserved |
|
|
69
|
+
* | `shiftHue c deg` | rotate hue in OKLCH |
|
|
70
|
+
* | `scaleChroma c f` | multiply chroma (0 → gray, 1 → identity) |
|
|
71
|
+
* | `scaleLightness c f` | multiply lightness (1 → identity, -1 → invert) |
|
|
72
|
+
* | `shiftLightness c d` | add to lightness, after any scale |
|
|
73
|
+
*
|
|
74
|
+
* Pair with `paletteFuncs()` to name colors from a theme, and with
|
|
75
|
+
* `richTextStyleFuncs()`'s `fg`/`bg` to paint them onto text.
|
|
76
|
+
*/
|
|
77
|
+
export declare function colorFuncs(): FuncMap;
|
|
78
|
+
//# sourceMappingURL=color-funcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-funcs.d.ts","sourceRoot":"","sources":["../../src/template-bindings/color-funcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,2BAA2B,CAAC;AAgLvE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,IAAI,OAAO,CASpC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color *values* for the rich-js template binding.
|
|
3
|
+
*
|
|
4
|
+
* ### Why colors are values
|
|
5
|
+
*
|
|
6
|
+
* Every other function in this binding layer takes a child fragment and
|
|
7
|
+
* returns a styled fragment. These do not: they take colors and return a
|
|
8
|
+
* color. That is the whole point. Before this module existed, a color could
|
|
9
|
+
* not survive between two operations — every color function resolved and
|
|
10
|
+
* applied in one breath — so composing two color operations had to be spelled
|
|
11
|
+
* as a *string grammar* (`"primary-darken-3 50%"`), a second language
|
|
12
|
+
* reimplementing function application inside a string literal. Every new color
|
|
13
|
+
* operation meant a new grammar production. [LAW:no-mode-explosion]
|
|
14
|
+
*
|
|
15
|
+
* With colors as values the surface is one shape that grows by nesting:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* {{ fg (color "primary") .branch }}
|
|
19
|
+
* {{ fg (darken (color "primary") 2) .branch }}
|
|
20
|
+
* {{ fg (mix (color "foreground") (color "surface") 65) .label }}
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* The simple case is a literal prefix of the composed case — an author adding
|
|
24
|
+
* a `darken` to working code wraps it, rather than rewriting it into an
|
|
25
|
+
* unfamiliar form. [LAW:composability]
|
|
26
|
+
*
|
|
27
|
+
* ### The carrier is a hex string, deliberately
|
|
28
|
+
*
|
|
29
|
+
* A color crosses the template seam as `#RRGGBB`, not as an opaque object,
|
|
30
|
+
* for three reasons:
|
|
31
|
+
*
|
|
32
|
+
* 1. **The type separates.** `"string"` is the strictest arg slot the template
|
|
33
|
+
* engine has — it *refuses* typed `T`. So a color slot cannot silently
|
|
34
|
+
* accept a text fragment. An opaque object would land in `"T"`/`"liftable"`,
|
|
35
|
+
* both of which admit any non-primitive, and `{{ bold (color "primary") }}`
|
|
36
|
+
* would type-check its way into nonsense. [LAW:types-are-the-program]
|
|
37
|
+
* 2. **It flows through the language.** `{{ $muted := mix … }}` holds it,
|
|
38
|
+
* `printf` prints it, `eq` compares it — no engine changes required. Naming
|
|
39
|
+
* a color once and using it ten times is the ergonomic payoff.
|
|
40
|
+
* 3. **Misuse is visible.** A color that lands in text position renders as
|
|
41
|
+
* `#7aa2f7` — wrong in a way an author immediately sees, never a silently
|
|
42
|
+
* dropped style. [LAW:no-silent-failure]
|
|
43
|
+
*
|
|
44
|
+
* No precision is given up: `darken`, `blendRgb`, and `contrastFor` already
|
|
45
|
+
* take and return 8-bit `ColorRgba`. The one caveat is OKLCH: each of the
|
|
46
|
+
* axis functions below round-trips sRGB→OKLCH→sRGB, so chaining three or more
|
|
47
|
+
* of them quantizes visibly. Compose two, or reach for `transposePalette` when
|
|
48
|
+
* a whole palette needs adapting — the same caveat that already applies to
|
|
49
|
+
* chained transpositions.
|
|
50
|
+
*
|
|
51
|
+
* ### Palette-free on purpose
|
|
52
|
+
*
|
|
53
|
+
* Nothing here knows what a palette is. `color` (the one palette-dependent
|
|
54
|
+
* function, in `palette-funcs.ts`) turns a name into a hex string; from that
|
|
55
|
+
* point on the math is pure. A consumer with no theme system at all still gets
|
|
56
|
+
* the full color vocabulary by feeding it hex literals. [LAW:one-way-deps]
|
|
57
|
+
*/
|
|
58
|
+
import { blendRgb } from "../core/color.js";
|
|
59
|
+
import { Oklch, IDENTITY } from "../core/oklch.js";
|
|
60
|
+
import { HEX_COLOR_RE, parseHexColor } from "../themes/colorRef.js";
|
|
61
|
+
import { darken, contrastFor, ensureContrast } from "../themes/colorMath.js";
|
|
62
|
+
/**
|
|
63
|
+
* The gate every color argument crosses. [LAW:parse-dont-validate] — the
|
|
64
|
+
* function bodies below receive `ColorRgba` and never re-check.
|
|
65
|
+
*
|
|
66
|
+
* Parsing itself is `parseHexColor`'s job; this wrapper exists only to replace
|
|
67
|
+
* its error *wording*, because the mistake it catches is almost always the
|
|
68
|
+
* same one — a palette name passed where a color belongs (`darken "primary" 2`)
|
|
69
|
+
* — and an author who reads "wrap it: darken (color "primary")" is corrected in
|
|
70
|
+
* one step, where "expected #RRGGBB" leaves them guessing.
|
|
71
|
+
* [LAW:no-silent-failure]
|
|
72
|
+
*/
|
|
73
|
+
function asColor(value, func) {
|
|
74
|
+
if (!HEX_COLOR_RE.test(value.trim())) {
|
|
75
|
+
throw new TypeError(`${func} expected a color (#RRGGBB or #RRGGBBAA), got ${JSON.stringify(value)}` +
|
|
76
|
+
` — to use a palette name here, wrap it: ${func} (color ${JSON.stringify(value)}) …`);
|
|
77
|
+
}
|
|
78
|
+
return parseHexColor(value);
|
|
79
|
+
}
|
|
80
|
+
function colorFunc(argTypes, fn) {
|
|
81
|
+
return { fn, argTypes, returnType: "string" };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The gate every *numeric* argument crosses, with an optional inclusive range.
|
|
85
|
+
*
|
|
86
|
+
* [LAW:single-enforcer] One check for the whole family. The template engine
|
|
87
|
+
* treats a trailing slot as variadic, so an under-supplied call
|
|
88
|
+
* (`{{ darken "#102030" }}`) reaches the body with `undefined` rather than
|
|
89
|
+
* failing at the gate. Without this, that `undefined` propagated into the color
|
|
90
|
+
* math and surfaced as `ColorRgba.red must be an integer in [0, 255]; got NaN`
|
|
91
|
+
* — loud, but pointing at a channel the author never wrote, three layers from
|
|
92
|
+
* the missing argument. An error that does not locate its cause is barely
|
|
93
|
+
* better than a silent one. [LAW:no-silent-failure]
|
|
94
|
+
*/
|
|
95
|
+
function asAmount(value, func, param, range) {
|
|
96
|
+
const inRange = range === undefined || (value >= range.min && value <= range.max);
|
|
97
|
+
if (!Number.isFinite(value) || !inRange) {
|
|
98
|
+
const bound = range === undefined
|
|
99
|
+
? "a finite number"
|
|
100
|
+
: `within ${range.min}..${range.max} (${range.note})`;
|
|
101
|
+
throw new RangeError(`${func}'s ${param} must be ${bound}, got ${value}` +
|
|
102
|
+
(value === undefined ? ` — ${func} takes it as its last argument` : ""));
|
|
103
|
+
}
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
// --- HSL lightness ---
|
|
107
|
+
//
|
|
108
|
+
// `lighten` is `darken` with the sign flipped — the same operation, not a
|
|
109
|
+
// second one (colorMath's `lighten` is literally `darken(c, -levels)`). Both
|
|
110
|
+
// names ship because "lighten by 2" and "darken by -2" are not equally
|
|
111
|
+
// readable at a call site, and the operation is genuinely bidirectional.
|
|
112
|
+
const darkenFunc = colorFunc(["string", "int"], ((hex, levels) => darken(asColor(hex, "darken"), asAmount(levels, "darken", "levels")).hex));
|
|
113
|
+
const lightenFunc = colorFunc(["string", "int"], ((hex, levels) => darken(asColor(hex, "lighten"), -asAmount(levels, "lighten", "levels")).hex));
|
|
114
|
+
// --- Blending ---
|
|
115
|
+
//
|
|
116
|
+
// [LAW:one-type-per-behavior] There is no separate `alphaBlend` binding.
|
|
117
|
+
// `alphaBlend(fg, bg, a)` in colorMath is *defined* as `blendRgb(bg, fg, a)` —
|
|
118
|
+
// one operation wearing two names. Compositing a translucent color over a
|
|
119
|
+
// background and mixing two colors by a percentage are the same arithmetic,
|
|
120
|
+
// so they get one function. Terminals have no alpha channel, which is also why
|
|
121
|
+
// no function here *produces* a translucent color: it could not be rendered,
|
|
122
|
+
// and a color that silently does nothing in the sink is worse than no
|
|
123
|
+
// function at all.
|
|
124
|
+
const MIX_PCT_MAX = 100;
|
|
125
|
+
const MIX_RANGE = { min: 0, max: MIX_PCT_MAX, note: "0 = from, 100 = toward" };
|
|
126
|
+
const mixFunc = colorFunc(["string", "string", "float"], ((fromHex, towardHex, pct) => blendRgb(asColor(fromHex, "mix"), asColor(towardHex, "mix"), asAmount(pct, "mix", "percentage", MIX_RANGE) / MIX_PCT_MAX).hex));
|
|
127
|
+
// --- Readability ---
|
|
128
|
+
//
|
|
129
|
+
// Two different questions, so two functions rather than one with a flag:
|
|
130
|
+
// `contrastOn` asks "what is maximally readable here" (black or white, WCAG
|
|
131
|
+
// relative-luminance cutoff); `readableOn` asks "keep this color recognizably
|
|
132
|
+
// itself, but guarantee it clears `ratio`" — it slides OKLCH lightness and
|
|
133
|
+
// preserves hue, so a blue on dark blue becomes a lighter blue rather than
|
|
134
|
+
// white.
|
|
135
|
+
//
|
|
136
|
+
// [LAW:no-silent-failure] `ratio` is required, not defaulted to WCAG AA's 4.5.
|
|
137
|
+
// The threshold is the whole decision this function makes, and the right value
|
|
138
|
+
// genuinely differs by intent — 4.5 for body text, 3.0 for large or
|
|
139
|
+
// deliberately recessive text. A hidden default would silently govern an
|
|
140
|
+
// accessibility outcome the author never saw, and would quietly over-correct a
|
|
141
|
+
// caller whose *point* was to be quiet: de-emphasized text floored at 4.5 is no
|
|
142
|
+
// longer de-emphasized.
|
|
143
|
+
// WCAG 2.x contrast ratios live in [1, 21] — 1 is a color on itself.
|
|
144
|
+
const RATIO_RANGE = {
|
|
145
|
+
min: 1,
|
|
146
|
+
max: 21,
|
|
147
|
+
note: "4.5 = AA body text, 3 = AA large text",
|
|
148
|
+
};
|
|
149
|
+
const contrastOnFunc = colorFunc(["string"], ((bgHex) => contrastFor(asColor(bgHex, "contrastOn")).hex));
|
|
150
|
+
const readableOnFunc = colorFunc(["string", "string", "float"], ((fgHex, bgHex, ratio) => ensureContrast(asColor(fgHex, "readableOn"), asColor(bgHex, "readableOn"), asAmount(ratio, "readableOn", "ratio", RATIO_RANGE)).hex));
|
|
151
|
+
// --- OKLCH axes ---
|
|
152
|
+
//
|
|
153
|
+
// [LAW:one-source-of-truth] One function per `ThemeKey` axis, and the table is
|
|
154
|
+
// keyed BY the axis so the compiler proves it total: add a field to `ThemeKey`
|
|
155
|
+
// and this object stops satisfying `Record<keyof ThemeKey, string>` until a
|
|
156
|
+
// binding name is chosen for it. The same derive-registrations-from-the-real-
|
|
157
|
+
// inventory trick `attributeFuncs()` uses over `ATTRIBUTE_NAMES`.
|
|
158
|
+
//
|
|
159
|
+
// Naming follows the axis semantics rather than the field spelling: `shift`
|
|
160
|
+
// for the additive axes, `scale` for the multiplicative ones, so a reader can
|
|
161
|
+
// tell from the call site whether `1` means "no change" or "one unit".
|
|
162
|
+
const OKLCH_AXIS_FUNCS = {
|
|
163
|
+
hueShift: "shiftHue",
|
|
164
|
+
chromaScale: "scaleChroma",
|
|
165
|
+
lightnessScale: "scaleLightness",
|
|
166
|
+
lightnessShift: "shiftLightness",
|
|
167
|
+
};
|
|
168
|
+
function oklchAxisFuncs() {
|
|
169
|
+
const out = {};
|
|
170
|
+
for (const [axis, funcName] of Object.entries(OKLCH_AXIS_FUNCS)) {
|
|
171
|
+
// [LAW:dataflow-not-control-flow] Every axis takes the identical path —
|
|
172
|
+
// splice one value into the identity key and apply it. The axis is data.
|
|
173
|
+
const key = axis;
|
|
174
|
+
out[funcName] = colorFunc(["string", "float"], ((hex, amount) => {
|
|
175
|
+
const themeKey = {
|
|
176
|
+
...IDENTITY,
|
|
177
|
+
[key]: asAmount(amount, funcName, "amount"),
|
|
178
|
+
};
|
|
179
|
+
return Oklch.fromRgba(asColor(hex, funcName)).applyKey(themeKey).toRgba().hex;
|
|
180
|
+
}));
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The palette-free color vocabulary: every function takes colors and returns a
|
|
186
|
+
* color, so they compose by nesting.
|
|
187
|
+
*
|
|
188
|
+
* | function | meaning |
|
|
189
|
+
* |---|---|
|
|
190
|
+
* | `darken c n` / `lighten c n` | slide HSL lightness by N 10% levels |
|
|
191
|
+
* | `mix a b pct` | blend `a` toward `b` by `pct`% (0 → `a`, 100 → `b`) |
|
|
192
|
+
* | `contrastOn bg` | black or white, whichever is readable on `bg` |
|
|
193
|
+
* | `readableOn fg bg ratio` | `fg` nudged in OKLCH lightness until it clears `ratio` on `bg`, hue preserved |
|
|
194
|
+
* | `shiftHue c deg` | rotate hue in OKLCH |
|
|
195
|
+
* | `scaleChroma c f` | multiply chroma (0 → gray, 1 → identity) |
|
|
196
|
+
* | `scaleLightness c f` | multiply lightness (1 → identity, -1 → invert) |
|
|
197
|
+
* | `shiftLightness c d` | add to lightness, after any scale |
|
|
198
|
+
*
|
|
199
|
+
* Pair with `paletteFuncs()` to name colors from a theme, and with
|
|
200
|
+
* `richTextStyleFuncs()`'s `fg`/`bg` to paint them onto text.
|
|
201
|
+
*/
|
|
202
|
+
export function colorFuncs() {
|
|
203
|
+
return {
|
|
204
|
+
darken: darkenFunc,
|
|
205
|
+
lighten: lightenFunc,
|
|
206
|
+
mix: mixFunc,
|
|
207
|
+
contrastOn: contrastOnFunc,
|
|
208
|
+
readableOn: readableOnFunc,
|
|
209
|
+
...oklchAxisFuncs(),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=color-funcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-funcs.js","sourceRoot":"","sources":["../../src/template-bindings/color-funcs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAGH,OAAO,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE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B;IAChC,cAAc,EAAE,gBAAgB;CACQ,CAAC;AAE3C,SAAS,cAAc;IACrB,MAAM,GAAG,GAAY,EAAE,CAAC;IACxB,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAChE,wEAAwE;QACxE,yEAAyE;QACzE,MAAM,GAAG,GAAG,IAAsB,CAAC;QACnC,GAAG,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC,GAAW,EAAE,MAAc,EAAE,EAAE;YAC9E,MAAM,QAAQ,GAAa;gBACzB,GAAG,QAAQ;gBACX,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC;aAC5C,CAAC;YACF,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC;QAChF,CAAC,CAAuB,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,WAAW;QACpB,GAAG,EAAE,OAAO;QACZ,UAAU,EAAE,cAAc;QAC1B,UAAU,EAAE,cAAc;QAC1B,GAAG,cAAc,EAAE;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -3,20 +3,27 @@
|
|
|
3
3
|
*
|
|
4
4
|
* [LAW:one-source-of-truth] This module is the public entry point for
|
|
5
5
|
* rich-js's styling vocabulary as `@promptctl/go-template-js` template
|
|
6
|
-
* functions.
|
|
6
|
+
* functions. The split between the two exported registrations is exactly the
|
|
7
|
+
* split between what needs a theme and what does not:
|
|
7
8
|
*
|
|
8
|
-
* - `richTextFuncs()` —
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* - `richTextFuncs()` — the colour sinks (`fg`/`bg`), the palette-free colour
|
|
10
|
+
* math (`darken`, `mix`, `contrastOn`, the OKLCH axes …), text attributes,
|
|
11
|
+
* and `link`. Needs no configuration; safe to register unconditionally. A
|
|
12
|
+
* consumer with no theme system still gets the complete colour vocabulary by
|
|
13
|
+
* feeding it hex literals.
|
|
14
|
+
* - `paletteFuncs(getPalette)` — the single function `color`, which turns a
|
|
15
|
+
* palette variable name into a colour. This is the *only* registration that
|
|
16
|
+
* knows a palette exists, which is why it is the only one that takes an
|
|
17
|
+
* argument. [LAW:one-way-deps]
|
|
13
18
|
*
|
|
14
|
-
* `createRichTextEngine()`
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* `createRichTextEngine()` wires up `richTextFuncs()` only — it cannot supply a
|
|
20
|
+
* palette. Consumers that name theme colours call `paletteFuncs(getPalette)`
|
|
21
|
+
* and merge it into their own engine config.
|
|
22
|
+
*
|
|
23
|
+
* Colours compose by nesting, like every other function:
|
|
24
|
+
* `{{ fg (darken (color "primary") 2) (bold "x") }}`. There is no second
|
|
25
|
+
* markup grammar and no colour-spec mini-language — the template *is* the
|
|
26
|
+
* composition mechanism.
|
|
20
27
|
*
|
|
21
28
|
* Fragment type: `RichText`. Chosen because it is the library's primary
|
|
22
29
|
* text type (implements `Renderable` + `Measurable`), composes via
|
|
@@ -30,13 +37,13 @@ import { type Engine, type FuncMap } from "@promptctl/go-template-js";
|
|
|
30
37
|
import { RichText } from "../core/text.js";
|
|
31
38
|
import { Segment } from "../core/segment.js";
|
|
32
39
|
export { paletteFuncs } from "./palette-funcs.js";
|
|
40
|
+
export { colorFuncs } from "./color-funcs.js";
|
|
33
41
|
/**
|
|
34
|
-
* Funcs registered by the rich-js binding —
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* `PaletteResolver` argument and so cannot be included in this generic call.
|
|
42
|
+
* Funcs registered by the rich-js binding — the colour sinks, the palette-free
|
|
43
|
+
* colour math, text attributes, and the `link` cell-splitter. Everything here
|
|
44
|
+
* is configuration-free by construction; the one function that needs a theme
|
|
45
|
+
* (`color`) ships separately via `paletteFuncs(getPalette)` and is merged
|
|
46
|
+
* consumer-side.
|
|
40
47
|
*
|
|
41
48
|
* `FuncMap` is not parameterised over `T` in `@promptctl/go-template-js` — the engine's
|
|
42
49
|
* `T` lives on the `Engine`/`EngineConfig`, and per-function input/output
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/template-bindings/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/template-bindings/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAI7C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAAC,QAAQ,CAAC,CAMvD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,EACxB,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,OAAY,EACnB,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD,OAAO,EAAE,CAYX"}
|
|
@@ -3,20 +3,27 @@
|
|
|
3
3
|
*
|
|
4
4
|
* [LAW:one-source-of-truth] This module is the public entry point for
|
|
5
5
|
* rich-js's styling vocabulary as `@promptctl/go-template-js` template
|
|
6
|
-
* functions.
|
|
6
|
+
* functions. The split between the two exported registrations is exactly the
|
|
7
|
+
* split between what needs a theme and what does not:
|
|
7
8
|
*
|
|
8
|
-
* - `richTextFuncs()` —
|
|
9
|
-
* `
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* - `richTextFuncs()` — the colour sinks (`fg`/`bg`), the palette-free colour
|
|
10
|
+
* math (`darken`, `mix`, `contrastOn`, the OKLCH axes …), text attributes,
|
|
11
|
+
* and `link`. Needs no configuration; safe to register unconditionally. A
|
|
12
|
+
* consumer with no theme system still gets the complete colour vocabulary by
|
|
13
|
+
* feeding it hex literals.
|
|
14
|
+
* - `paletteFuncs(getPalette)` — the single function `color`, which turns a
|
|
15
|
+
* palette variable name into a colour. This is the *only* registration that
|
|
16
|
+
* knows a palette exists, which is why it is the only one that takes an
|
|
17
|
+
* argument. [LAW:one-way-deps]
|
|
13
18
|
*
|
|
14
|
-
* `createRichTextEngine()`
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* `createRichTextEngine()` wires up `richTextFuncs()` only — it cannot supply a
|
|
20
|
+
* palette. Consumers that name theme colours call `paletteFuncs(getPalette)`
|
|
21
|
+
* and merge it into their own engine config.
|
|
22
|
+
*
|
|
23
|
+
* Colours compose by nesting, like every other function:
|
|
24
|
+
* `{{ fg (darken (color "primary") 2) (bold "x") }}`. There is no second
|
|
25
|
+
* markup grammar and no colour-spec mini-language — the template *is* the
|
|
26
|
+
* composition mechanism.
|
|
20
27
|
*
|
|
21
28
|
* Fragment type: `RichText`. Chosen because it is the library's primary
|
|
22
29
|
* text type (implements `Renderable` + `Measurable`), composes via
|
|
@@ -31,14 +38,15 @@ import { RichText } from "../core/text.js";
|
|
|
31
38
|
import { Style } from "../core/style.js";
|
|
32
39
|
import { Segment } from "../core/segment.js";
|
|
33
40
|
import { richTextStyleFuncs } from "./style-funcs.js";
|
|
41
|
+
import { colorFuncs } from "./color-funcs.js";
|
|
34
42
|
export { paletteFuncs } from "./palette-funcs.js";
|
|
43
|
+
export { colorFuncs } from "./color-funcs.js";
|
|
35
44
|
/**
|
|
36
|
-
* Funcs registered by the rich-js binding —
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* `PaletteResolver` argument and so cannot be included in this generic call.
|
|
45
|
+
* Funcs registered by the rich-js binding — the colour sinks, the palette-free
|
|
46
|
+
* colour math, text attributes, and the `link` cell-splitter. Everything here
|
|
47
|
+
* is configuration-free by construction; the one function that needs a theme
|
|
48
|
+
* (`color`) ships separately via `paletteFuncs(getPalette)` and is merged
|
|
49
|
+
* consumer-side.
|
|
42
50
|
*
|
|
43
51
|
* `FuncMap` is not parameterised over `T` in `@promptctl/go-template-js` — the engine's
|
|
44
52
|
* `T` lives on the `Engine`/`EngineConfig`, and per-function input/output
|
|
@@ -52,7 +60,7 @@ export { paletteFuncs } from "./palette-funcs.js";
|
|
|
52
60
|
* whose `T` is something else will compile but fail at evaluation time.
|
|
53
61
|
*/
|
|
54
62
|
export function richTextFuncs() {
|
|
55
|
-
return richTextStyleFuncs();
|
|
63
|
+
return { ...richTextStyleFuncs(), ...colorFuncs() };
|
|
56
64
|
}
|
|
57
65
|
/**
|
|
58
66
|
* Construct an `Engine<RichText>` with the rich-js style-function set
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/template-bindings/index.ts"],"names":[],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