@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.
Files changed (318) hide show
  1. package/README.md +418 -0
  2. package/dist/core/box.d.ts +91 -0
  3. package/dist/core/box.d.ts.map +1 -0
  4. package/dist/core/box.js +534 -0
  5. package/dist/core/box.js.map +1 -0
  6. package/dist/core/cells.d.ts +24 -0
  7. package/dist/core/cells.d.ts.map +1 -0
  8. package/dist/core/cells.js +114 -0
  9. package/dist/core/cells.js.map +1 -0
  10. package/dist/core/color.d.ts +158 -0
  11. package/dist/core/color.d.ts.map +1 -0
  12. package/dist/core/color.js +825 -0
  13. package/dist/core/color.js.map +1 -0
  14. package/dist/core/console.d.ts +100 -0
  15. package/dist/core/console.d.ts.map +1 -0
  16. package/dist/core/console.js +353 -0
  17. package/dist/core/console.js.map +1 -0
  18. package/dist/core/emoji.d.ts +25 -0
  19. package/dist/core/emoji.d.ts.map +1 -0
  20. package/dist/core/emoji.js +392 -0
  21. package/dist/core/emoji.js.map +1 -0
  22. package/dist/core/highlighter.d.ts +33 -0
  23. package/dist/core/highlighter.d.ts.map +1 -0
  24. package/dist/core/highlighter.js +103 -0
  25. package/dist/core/highlighter.js.map +1 -0
  26. package/dist/core/markup.d.ts +69 -0
  27. package/dist/core/markup.d.ts.map +1 -0
  28. package/dist/core/markup.js +401 -0
  29. package/dist/core/markup.js.map +1 -0
  30. package/dist/core/measure.d.ts +17 -0
  31. package/dist/core/measure.d.ts.map +1 -0
  32. package/dist/core/measure.js +50 -0
  33. package/dist/core/measure.js.map +1 -0
  34. package/dist/core/protocol.d.ts +32 -0
  35. package/dist/core/protocol.d.ts.map +1 -0
  36. package/dist/core/protocol.js +17 -0
  37. package/dist/core/protocol.js.map +1 -0
  38. package/dist/core/render.d.ts +51 -0
  39. package/dist/core/render.d.ts.map +1 -0
  40. package/dist/core/render.js +69 -0
  41. package/dist/core/render.js.map +1 -0
  42. package/dist/core/segment.d.ts +104 -0
  43. package/dist/core/segment.d.ts.map +1 -0
  44. package/dist/core/segment.js +364 -0
  45. package/dist/core/segment.js.map +1 -0
  46. package/dist/core/spinnerData.d.ts +11 -0
  47. package/dist/core/spinnerData.d.ts.map +1 -0
  48. package/dist/core/spinnerData.js +116 -0
  49. package/dist/core/spinnerData.js.map +1 -0
  50. package/dist/core/strip.d.ts +159 -0
  51. package/dist/core/strip.d.ts.map +1 -0
  52. package/dist/core/strip.js +237 -0
  53. package/dist/core/strip.js.map +1 -0
  54. package/dist/core/style.d.ts +115 -0
  55. package/dist/core/style.d.ts.map +1 -0
  56. package/dist/core/style.js +662 -0
  57. package/dist/core/style.js.map +1 -0
  58. package/dist/core/text.d.ts +91 -0
  59. package/dist/core/text.d.ts.map +1 -0
  60. package/dist/core/text.js +610 -0
  61. package/dist/core/text.js.map +1 -0
  62. package/dist/index.d.ts +99 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +72 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/renderables/align.d.ts +17 -0
  67. package/dist/renderables/align.d.ts.map +1 -0
  68. package/dist/renderables/align.js +47 -0
  69. package/dist/renderables/align.js.map +1 -0
  70. package/dist/renderables/columns.d.ts +28 -0
  71. package/dist/renderables/columns.d.ts.map +1 -0
  72. package/dist/renderables/columns.js +92 -0
  73. package/dist/renderables/columns.js.map +1 -0
  74. package/dist/renderables/constrain.d.ts +16 -0
  75. package/dist/renderables/constrain.d.ts.map +1 -0
  76. package/dist/renderables/constrain.js +38 -0
  77. package/dist/renderables/constrain.js.map +1 -0
  78. package/dist/renderables/flexStrip.d.ts +42 -0
  79. package/dist/renderables/flexStrip.d.ts.map +1 -0
  80. package/dist/renderables/flexStrip.js +201 -0
  81. package/dist/renderables/flexStrip.js.map +1 -0
  82. package/dist/renderables/group.d.ts +12 -0
  83. package/dist/renderables/group.d.ts.map +1 -0
  84. package/dist/renderables/group.js +16 -0
  85. package/dist/renderables/group.js.map +1 -0
  86. package/dist/renderables/json.d.ts +23 -0
  87. package/dist/renderables/json.d.ts.map +1 -0
  88. package/dist/renderables/json.js +49 -0
  89. package/dist/renderables/json.js.map +1 -0
  90. package/dist/renderables/layout.d.ts +37 -0
  91. package/dist/renderables/layout.d.ts.map +1 -0
  92. package/dist/renderables/layout.js +151 -0
  93. package/dist/renderables/layout.js.map +1 -0
  94. package/dist/renderables/live.d.ts +48 -0
  95. package/dist/renderables/live.d.ts.map +1 -0
  96. package/dist/renderables/live.js +131 -0
  97. package/dist/renderables/live.js.map +1 -0
  98. package/dist/renderables/markdown.d.ts +25 -0
  99. package/dist/renderables/markdown.d.ts.map +1 -0
  100. package/dist/renderables/markdown.js +190 -0
  101. package/dist/renderables/markdown.js.map +1 -0
  102. package/dist/renderables/padding.d.ts +26 -0
  103. package/dist/renderables/padding.d.ts.map +1 -0
  104. package/dist/renderables/padding.js +92 -0
  105. package/dist/renderables/padding.js.map +1 -0
  106. package/dist/renderables/panel.d.ts +42 -0
  107. package/dist/renderables/panel.d.ts.map +1 -0
  108. package/dist/renderables/panel.js +202 -0
  109. package/dist/renderables/panel.js.map +1 -0
  110. package/dist/renderables/pretty.d.ts +29 -0
  111. package/dist/renderables/pretty.d.ts.map +1 -0
  112. package/dist/renderables/pretty.js +141 -0
  113. package/dist/renderables/pretty.js.map +1 -0
  114. package/dist/renderables/progress.d.ts +91 -0
  115. package/dist/renderables/progress.d.ts.map +1 -0
  116. package/dist/renderables/progress.js +234 -0
  117. package/dist/renderables/progress.js.map +1 -0
  118. package/dist/renderables/progressBar.d.ts +32 -0
  119. package/dist/renderables/progressBar.d.ts.map +1 -0
  120. package/dist/renderables/progressBar.js +59 -0
  121. package/dist/renderables/progressBar.js.map +1 -0
  122. package/dist/renderables/prompt.d.ts +25 -0
  123. package/dist/renderables/prompt.d.ts.map +1 -0
  124. package/dist/renderables/prompt.js +109 -0
  125. package/dist/renderables/prompt.js.map +1 -0
  126. package/dist/renderables/rule.d.ts +25 -0
  127. package/dist/renderables/rule.d.ts.map +1 -0
  128. package/dist/renderables/rule.js +96 -0
  129. package/dist/renderables/rule.js.map +1 -0
  130. package/dist/renderables/spinner.d.ts +30 -0
  131. package/dist/renderables/spinner.d.ts.map +1 -0
  132. package/dist/renderables/spinner.js +70 -0
  133. package/dist/renderables/spinner.js.map +1 -0
  134. package/dist/renderables/status.d.ts +24 -0
  135. package/dist/renderables/status.d.ts.map +1 -0
  136. package/dist/renderables/status.js +67 -0
  137. package/dist/renderables/status.js.map +1 -0
  138. package/dist/renderables/syntax.d.ts +36 -0
  139. package/dist/renderables/syntax.d.ts.map +1 -0
  140. package/dist/renderables/syntax.js +115 -0
  141. package/dist/renderables/syntax.js.map +1 -0
  142. package/dist/renderables/table.d.ts +109 -0
  143. package/dist/renderables/table.d.ts.map +1 -0
  144. package/dist/renderables/table.js +434 -0
  145. package/dist/renderables/table.js.map +1 -0
  146. package/dist/renderables/traceback.d.ts +26 -0
  147. package/dist/renderables/traceback.d.ts.map +1 -0
  148. package/dist/renderables/traceback.js +108 -0
  149. package/dist/renderables/traceback.js.map +1 -0
  150. package/dist/renderables/tree.d.ts +30 -0
  151. package/dist/renderables/tree.d.ts.map +1 -0
  152. package/dist/renderables/tree.js +107 -0
  153. package/dist/renderables/tree.js.map +1 -0
  154. package/dist/template-bindings/index.d.ts +61 -0
  155. package/dist/template-bindings/index.d.ts.map +1 -0
  156. package/dist/template-bindings/index.js +70 -0
  157. package/dist/template-bindings/index.js.map +1 -0
  158. package/dist/template-bindings/style-funcs.d.ts +30 -0
  159. package/dist/template-bindings/style-funcs.d.ts.map +1 -0
  160. package/dist/template-bindings/style-funcs.js +172 -0
  161. package/dist/template-bindings/style-funcs.js.map +1 -0
  162. package/dist/themes/buildPalette.d.ts +31 -0
  163. package/dist/themes/buildPalette.d.ts.map +1 -0
  164. package/dist/themes/buildPalette.js +43 -0
  165. package/dist/themes/buildPalette.js.map +1 -0
  166. package/dist/themes/colorMath.d.ts +23 -0
  167. package/dist/themes/colorMath.d.ts.map +1 -0
  168. package/dist/themes/colorMath.js +99 -0
  169. package/dist/themes/colorMath.js.map +1 -0
  170. package/dist/themes/data/atom-one-dark.d.ts +4 -0
  171. package/dist/themes/data/atom-one-dark.d.ts.map +1 -0
  172. package/dist/themes/data/atom-one-dark.js +159 -0
  173. package/dist/themes/data/atom-one-dark.js.map +1 -0
  174. package/dist/themes/data/atom-one-light.d.ts +4 -0
  175. package/dist/themes/data/atom-one-light.d.ts.map +1 -0
  176. package/dist/themes/data/atom-one-light.js +159 -0
  177. package/dist/themes/data/atom-one-light.js.map +1 -0
  178. package/dist/themes/data/catppuccin-latte.d.ts +4 -0
  179. package/dist/themes/data/catppuccin-latte.d.ts.map +1 -0
  180. package/dist/themes/data/catppuccin-latte.js +159 -0
  181. package/dist/themes/data/catppuccin-latte.js.map +1 -0
  182. package/dist/themes/data/catppuccin-mocha.d.ts +4 -0
  183. package/dist/themes/data/catppuccin-mocha.d.ts.map +1 -0
  184. package/dist/themes/data/catppuccin-mocha.js +159 -0
  185. package/dist/themes/data/catppuccin-mocha.js.map +1 -0
  186. package/dist/themes/data/dracula.d.ts +4 -0
  187. package/dist/themes/data/dracula.d.ts.map +1 -0
  188. package/dist/themes/data/dracula.js +159 -0
  189. package/dist/themes/data/dracula.js.map +1 -0
  190. package/dist/themes/data/flexoki.d.ts +4 -0
  191. package/dist/themes/data/flexoki.d.ts.map +1 -0
  192. package/dist/themes/data/flexoki.js +159 -0
  193. package/dist/themes/data/flexoki.js.map +1 -0
  194. package/dist/themes/data/gruvbox.d.ts +4 -0
  195. package/dist/themes/data/gruvbox.d.ts.map +1 -0
  196. package/dist/themes/data/gruvbox.js +159 -0
  197. package/dist/themes/data/gruvbox.js.map +1 -0
  198. package/dist/themes/data/index.d.ts +29 -0
  199. package/dist/themes/data/index.d.ts.map +1 -0
  200. package/dist/themes/data/index.js +48 -0
  201. package/dist/themes/data/index.js.map +1 -0
  202. package/dist/themes/data/monokai.d.ts +4 -0
  203. package/dist/themes/data/monokai.d.ts.map +1 -0
  204. package/dist/themes/data/monokai.js +159 -0
  205. package/dist/themes/data/monokai.js.map +1 -0
  206. package/dist/themes/data/nord.d.ts +4 -0
  207. package/dist/themes/data/nord.d.ts.map +1 -0
  208. package/dist/themes/data/nord.js +159 -0
  209. package/dist/themes/data/nord.js.map +1 -0
  210. package/dist/themes/data/rose-pine-dawn.d.ts +4 -0
  211. package/dist/themes/data/rose-pine-dawn.d.ts.map +1 -0
  212. package/dist/themes/data/rose-pine-dawn.js +159 -0
  213. package/dist/themes/data/rose-pine-dawn.js.map +1 -0
  214. package/dist/themes/data/rose-pine-moon.d.ts +4 -0
  215. package/dist/themes/data/rose-pine-moon.d.ts.map +1 -0
  216. package/dist/themes/data/rose-pine-moon.js +159 -0
  217. package/dist/themes/data/rose-pine-moon.js.map +1 -0
  218. package/dist/themes/data/rose-pine.d.ts +4 -0
  219. package/dist/themes/data/rose-pine.d.ts.map +1 -0
  220. package/dist/themes/data/rose-pine.js +159 -0
  221. package/dist/themes/data/rose-pine.js.map +1 -0
  222. package/dist/themes/data/solarized-dark.d.ts +4 -0
  223. package/dist/themes/data/solarized-dark.d.ts.map +1 -0
  224. package/dist/themes/data/solarized-dark.js +159 -0
  225. package/dist/themes/data/solarized-dark.js.map +1 -0
  226. package/dist/themes/data/solarized-light.d.ts +4 -0
  227. package/dist/themes/data/solarized-light.d.ts.map +1 -0
  228. package/dist/themes/data/solarized-light.js +159 -0
  229. package/dist/themes/data/solarized-light.js.map +1 -0
  230. package/dist/themes/data/textual-ansi.d.ts +4 -0
  231. package/dist/themes/data/textual-ansi.d.ts.map +1 -0
  232. package/dist/themes/data/textual-ansi.js +159 -0
  233. package/dist/themes/data/textual-ansi.js.map +1 -0
  234. package/dist/themes/data/textual-dark.d.ts +4 -0
  235. package/dist/themes/data/textual-dark.d.ts.map +1 -0
  236. package/dist/themes/data/textual-dark.js +159 -0
  237. package/dist/themes/data/textual-dark.js.map +1 -0
  238. package/dist/themes/data/textual-light.d.ts +4 -0
  239. package/dist/themes/data/textual-light.d.ts.map +1 -0
  240. package/dist/themes/data/textual-light.js +159 -0
  241. package/dist/themes/data/textual-light.js.map +1 -0
  242. package/dist/themes/data/tokyo-night.d.ts +4 -0
  243. package/dist/themes/data/tokyo-night.d.ts.map +1 -0
  244. package/dist/themes/data/tokyo-night.js +159 -0
  245. package/dist/themes/data/tokyo-night.js.map +1 -0
  246. package/dist/themes/data/types.d.ts +15 -0
  247. package/dist/themes/data/types.d.ts.map +1 -0
  248. package/dist/themes/data/types.js +2 -0
  249. package/dist/themes/data/types.js.map +1 -0
  250. package/dist/themes/palette.d.ts +20 -0
  251. package/dist/themes/palette.d.ts.map +1 -0
  252. package/dist/themes/palette.js +27 -0
  253. package/dist/themes/palette.js.map +1 -0
  254. package/dist/themes/paletteResolver.d.ts +35 -0
  255. package/dist/themes/paletteResolver.d.ts.map +1 -0
  256. package/dist/themes/paletteResolver.js +88 -0
  257. package/dist/themes/paletteResolver.js.map +1 -0
  258. package/dist/themes/registry.d.ts +17 -0
  259. package/dist/themes/registry.d.ts.map +1 -0
  260. package/dist/themes/registry.js +33 -0
  261. package/dist/themes/registry.js.map +1 -0
  262. package/dist/themes/terminalThemes.d.ts +46 -0
  263. package/dist/themes/terminalThemes.d.ts.map +1 -0
  264. package/dist/themes/terminalThemes.js +268 -0
  265. package/dist/themes/terminalThemes.js.map +1 -0
  266. package/dist/widgets/button.d.ts +47 -0
  267. package/dist/widgets/button.d.ts.map +1 -0
  268. package/dist/widgets/button.js +183 -0
  269. package/dist/widgets/button.js.map +1 -0
  270. package/dist/widgets/checkbox.d.ts +43 -0
  271. package/dist/widgets/checkbox.d.ts.map +1 -0
  272. package/dist/widgets/checkbox.js +144 -0
  273. package/dist/widgets/checkbox.js.map +1 -0
  274. package/dist/widgets/dropdown.d.ts +67 -0
  275. package/dist/widgets/dropdown.d.ts.map +1 -0
  276. package/dist/widgets/dropdown.js +373 -0
  277. package/dist/widgets/dropdown.js.map +1 -0
  278. package/dist/widgets/event-router.d.ts +73 -0
  279. package/dist/widgets/event-router.d.ts.map +1 -0
  280. package/dist/widgets/event-router.js +479 -0
  281. package/dist/widgets/event-router.js.map +1 -0
  282. package/dist/widgets/focus-manager.d.ts +26 -0
  283. package/dist/widgets/focus-manager.d.ts.map +1 -0
  284. package/dist/widgets/focus-manager.js +179 -0
  285. package/dist/widgets/focus-manager.js.map +1 -0
  286. package/dist/widgets/index.d.ts +23 -0
  287. package/dist/widgets/index.d.ts.map +1 -0
  288. package/dist/widgets/index.js +13 -0
  289. package/dist/widgets/index.js.map +1 -0
  290. package/dist/widgets/screen.d.ts +90 -0
  291. package/dist/widgets/screen.d.ts.map +1 -0
  292. package/dist/widgets/screen.js +440 -0
  293. package/dist/widgets/screen.js.map +1 -0
  294. package/dist/widgets/slider.d.ts +55 -0
  295. package/dist/widgets/slider.d.ts.map +1 -0
  296. package/dist/widgets/slider.js +248 -0
  297. package/dist/widgets/slider.js.map +1 -0
  298. package/dist/widgets/static-item.d.ts +41 -0
  299. package/dist/widgets/static-item.d.ts.map +1 -0
  300. package/dist/widgets/static-item.js +62 -0
  301. package/dist/widgets/static-item.js.map +1 -0
  302. package/dist/widgets/text-input.d.ts +50 -0
  303. package/dist/widgets/text-input.d.ts.map +1 -0
  304. package/dist/widgets/text-input.js +242 -0
  305. package/dist/widgets/text-input.js.map +1 -0
  306. package/dist/widgets/toggle.d.ts +46 -0
  307. package/dist/widgets/toggle.d.ts.map +1 -0
  308. package/dist/widgets/toggle.js +169 -0
  309. package/dist/widgets/toggle.js.map +1 -0
  310. package/dist/widgets/types.d.ts +92 -0
  311. package/dist/widgets/types.d.ts.map +1 -0
  312. package/dist/widgets/types.js +13 -0
  313. package/dist/widgets/types.js.map +1 -0
  314. package/dist/widgets/widget-base.d.ts +41 -0
  315. package/dist/widgets/widget-base.d.ts.map +1 -0
  316. package/dist/widgets/widget-base.js +159 -0
  317. package/dist/widgets/widget-base.js.map +1 -0
  318. package/package.json +76 -0
@@ -0,0 +1,662 @@
1
+ /**
2
+ * Immutable style descriptors — colors, text attributes, links, metadata.
3
+ */
4
+ import { ColorRgba, ColorSpec, } from "./color.js";
5
+ // [LAW:one-way-deps] `core/style` depends only on `core/color`; the substrate
6
+ // fallback is the canonical canvas color (black), inlined to avoid pulling in
7
+ // any preset theme constants. Preset themes live in `src/themes/` and depend
8
+ // on core, never the reverse.
9
+ const SURFACE_BLACK = new ColorRgba(0, 0, 0);
10
+ // --- Attribute definitions ---
11
+ /**
12
+ * Canonical text-attribute inventory. Single source of truth consumed by
13
+ * `Style.parse` / `Style.toString` and the template bindings — adding an
14
+ * attribute here propagates to every styling surface without a second
15
+ * list to keep in sync. [LAW:one-source-of-truth]
16
+ */
17
+ export const ATTRIBUTE_NAMES = [
18
+ "bold",
19
+ "dim",
20
+ "italic",
21
+ "underline",
22
+ "blink",
23
+ "blink2",
24
+ "reverse",
25
+ "conceal",
26
+ "strike",
27
+ "underline2",
28
+ "frame",
29
+ "encircle",
30
+ "overline",
31
+ ];
32
+ // SGR codes for each attribute (on / off)
33
+ const ATTRIBUTE_SGR = {
34
+ bold: [1, 22],
35
+ dim: [2, 22],
36
+ italic: [3, 23],
37
+ underline: [4, 24],
38
+ blink: [5, 25],
39
+ blink2: [6, 25],
40
+ reverse: [7, 27],
41
+ conceal: [8, 28],
42
+ strike: [9, 29],
43
+ underline2: [21, 24],
44
+ frame: [51, 54],
45
+ encircle: [52, 54],
46
+ overline: [53, 55],
47
+ };
48
+ /**
49
+ * Canonical short-attribute aliases (`b` → `bold`, `i` → `italic`, …).
50
+ * Single source of truth consumed by `Style.parse` and the template
51
+ * bindings — adding an alias here makes it available everywhere.
52
+ * [LAW:one-source-of-truth]
53
+ */
54
+ export const ATTRIBUTE_SHORT_ALIASES = {
55
+ b: "bold",
56
+ d: "dim",
57
+ i: "italic",
58
+ u: "underline",
59
+ s: "strike",
60
+ r: "reverse",
61
+ o: "overline",
62
+ uu: "underline2",
63
+ };
64
+ export class StyleSyntaxError extends Error {
65
+ constructor(message) {
66
+ super(message);
67
+ this.name = "StyleSyntaxError";
68
+ }
69
+ }
70
+ // [LAW:one-source-of-truth] Parse cache is the single source for parsed Style instances
71
+ const styleParseCache = new Map();
72
+ let nextLinkId = 1;
73
+ // --- Style ---
74
+ export class Style {
75
+ color;
76
+ bgcolor;
77
+ bold;
78
+ dim;
79
+ italic;
80
+ underline;
81
+ blink;
82
+ blink2;
83
+ reverse;
84
+ conceal;
85
+ strike;
86
+ underline2;
87
+ frame;
88
+ encircle;
89
+ overline;
90
+ link;
91
+ meta;
92
+ /** @internal */
93
+ _linkId;
94
+ constructor(options) {
95
+ if (!options) {
96
+ this.color = undefined;
97
+ this.bgcolor = undefined;
98
+ this.bold = undefined;
99
+ this.dim = undefined;
100
+ this.italic = undefined;
101
+ this.underline = undefined;
102
+ this.blink = undefined;
103
+ this.blink2 = undefined;
104
+ this.reverse = undefined;
105
+ this.conceal = undefined;
106
+ this.strike = undefined;
107
+ this.underline2 = undefined;
108
+ this.frame = undefined;
109
+ this.encircle = undefined;
110
+ this.overline = undefined;
111
+ this.link = undefined;
112
+ this.meta = undefined;
113
+ this._linkId = 0;
114
+ return;
115
+ }
116
+ this.color = resolveColor(options.color);
117
+ this.bgcolor = resolveColor(options.bgcolor);
118
+ this.bold = options.bold;
119
+ this.dim = options.dim;
120
+ this.italic = options.italic;
121
+ this.underline = options.underline;
122
+ this.blink = options.blink;
123
+ this.blink2 = options.blink2;
124
+ this.reverse = options.reverse;
125
+ this.conceal = options.conceal;
126
+ this.strike = options.strike;
127
+ this.underline2 = options.underline2;
128
+ this.frame = options.frame;
129
+ this.encircle = options.encircle;
130
+ this.overline = options.overline;
131
+ this.link = options.link;
132
+ this.meta = options.meta;
133
+ this._linkId = options.link ? nextLinkId++ : 0;
134
+ }
135
+ get isNull() {
136
+ return (this.color === undefined &&
137
+ this.bgcolor === undefined &&
138
+ this.bold === undefined &&
139
+ this.dim === undefined &&
140
+ this.italic === undefined &&
141
+ this.underline === undefined &&
142
+ this.blink === undefined &&
143
+ this.blink2 === undefined &&
144
+ this.reverse === undefined &&
145
+ this.conceal === undefined &&
146
+ this.strike === undefined &&
147
+ this.underline2 === undefined &&
148
+ this.frame === undefined &&
149
+ this.encircle === undefined &&
150
+ this.overline === undefined &&
151
+ this.link === undefined &&
152
+ this.meta === undefined);
153
+ }
154
+ get transparentBackground() {
155
+ return this.bgcolor === undefined || this.bgcolor.isDefault;
156
+ }
157
+ get backgroundStyle() {
158
+ return new Style({ bgcolor: this.bgcolor });
159
+ }
160
+ get withoutColor() {
161
+ return new Style({
162
+ bold: this.bold,
163
+ dim: this.dim,
164
+ italic: this.italic,
165
+ underline: this.underline,
166
+ blink: this.blink,
167
+ blink2: this.blink2,
168
+ reverse: this.reverse,
169
+ conceal: this.conceal,
170
+ strike: this.strike,
171
+ underline2: this.underline2,
172
+ frame: this.frame,
173
+ encircle: this.encircle,
174
+ overline: this.overline,
175
+ link: this.link,
176
+ meta: this.meta,
177
+ });
178
+ }
179
+ clearMetaAndLinks() {
180
+ return new Style({
181
+ color: this.color,
182
+ bgcolor: this.bgcolor,
183
+ bold: this.bold,
184
+ dim: this.dim,
185
+ italic: this.italic,
186
+ underline: this.underline,
187
+ blink: this.blink,
188
+ blink2: this.blink2,
189
+ reverse: this.reverse,
190
+ conceal: this.conceal,
191
+ strike: this.strike,
192
+ underline2: this.underline2,
193
+ frame: this.frame,
194
+ encircle: this.encircle,
195
+ overline: this.overline,
196
+ });
197
+ }
198
+ /**
199
+ * Merges two styles. `other`'s values take priority.
200
+ */
201
+ add(other) {
202
+ if (!other || other.isNull)
203
+ return this;
204
+ if (this.isNull)
205
+ return other;
206
+ return new Style({
207
+ color: other.color ?? this.color,
208
+ bgcolor: other.bgcolor ?? this.bgcolor,
209
+ bold: other.bold ?? this.bold,
210
+ dim: other.dim ?? this.dim,
211
+ italic: other.italic ?? this.italic,
212
+ underline: other.underline ?? this.underline,
213
+ blink: other.blink ?? this.blink,
214
+ blink2: other.blink2 ?? this.blink2,
215
+ reverse: other.reverse ?? this.reverse,
216
+ conceal: other.conceal ?? this.conceal,
217
+ strike: other.strike ?? this.strike,
218
+ underline2: other.underline2 ?? this.underline2,
219
+ frame: other.frame ?? this.frame,
220
+ encircle: other.encircle ?? this.encircle,
221
+ overline: other.overline ?? this.overline,
222
+ link: other.link ?? this.link,
223
+ meta: other.meta && this.meta
224
+ ? { ...this.meta, ...other.meta }
225
+ : other.meta ?? this.meta,
226
+ });
227
+ }
228
+ equals(other) {
229
+ if (this === other)
230
+ return true;
231
+ return (this.color?.name === other.color?.name &&
232
+ this.bgcolor?.name === other.bgcolor?.name &&
233
+ this.bold === other.bold &&
234
+ this.dim === other.dim &&
235
+ this.italic === other.italic &&
236
+ this.underline === other.underline &&
237
+ this.blink === other.blink &&
238
+ this.blink2 === other.blink2 &&
239
+ this.reverse === other.reverse &&
240
+ this.conceal === other.conceal &&
241
+ this.strike === other.strike &&
242
+ this.underline2 === other.underline2 &&
243
+ this.frame === other.frame &&
244
+ this.encircle === other.encircle &&
245
+ this.overline === other.overline &&
246
+ this.link === other.link);
247
+ }
248
+ /**
249
+ * Render text with this style's ANSI escape codes.
250
+ */
251
+ render(text, colorSystem) {
252
+ if (text.length === 0)
253
+ return "";
254
+ if (this.isNull)
255
+ return text;
256
+ const attrs = [];
257
+ // [LAW:dataflow-not-control-flow] Always resolve a substrate and flatten
258
+ // alpha before downgrade. Opaque colors short-circuit inside compositeOver,
259
+ // so the same code path runs every render — the alpha value is the data,
260
+ // not a branch.
261
+ const surface = SURFACE_BLACK;
262
+ const bgFlat = this.bgcolor?.flattenAlpha(surface);
263
+ const fgSubstrate = bgFlat?.getTruecolor(undefined, false) ?? surface;
264
+ const fgFlat = this.color?.flattenAlpha(fgSubstrate);
265
+ if (fgFlat) {
266
+ const c = colorSystem !== undefined ? fgFlat.downgrade(colorSystem) : fgFlat;
267
+ attrs.push(...c.getAnsiCodes(true));
268
+ }
269
+ if (bgFlat) {
270
+ const c = colorSystem !== undefined ? bgFlat.downgrade(colorSystem) : bgFlat;
271
+ attrs.push(...c.getAnsiCodes(false));
272
+ }
273
+ // Attributes
274
+ for (const name of ATTRIBUTE_NAMES) {
275
+ const val = this[name];
276
+ if (val === true) {
277
+ attrs.push(`${ATTRIBUTE_SGR[name][0]}`);
278
+ }
279
+ else if (val === false) {
280
+ attrs.push(`${ATTRIBUTE_SGR[name][1]}`);
281
+ }
282
+ }
283
+ let result = text;
284
+ if (attrs.length > 0) {
285
+ result = `\x1b[${attrs.join(";")}m${text}\x1b[0m`;
286
+ }
287
+ // Link (OSC 8)
288
+ if (this.link) {
289
+ const id = this._linkId;
290
+ result = `\x1b]8;id=${id};${this.link}\x1b\\${result}\x1b]8;;\x1b\\`;
291
+ }
292
+ return result;
293
+ }
294
+ /**
295
+ * Returns a CSS style string for HTML rendering.
296
+ */
297
+ getHtmlStyle(theme) {
298
+ if (this.isNull)
299
+ return "";
300
+ const parts = [];
301
+ if (this.color) {
302
+ const triplet = this.color.getTruecolor(theme, true);
303
+ parts.push(`color: ${triplet.hex}`);
304
+ }
305
+ if (this.bgcolor) {
306
+ const triplet = this.bgcolor.getTruecolor(theme, false);
307
+ parts.push(`background-color: ${triplet.hex}`);
308
+ }
309
+ if (this.bold)
310
+ parts.push("font-weight: bold");
311
+ if (this.italic)
312
+ parts.push("font-style: italic");
313
+ const decorations = [];
314
+ if (this.underline)
315
+ decorations.push("underline");
316
+ if (this.strike)
317
+ decorations.push("line-through");
318
+ if (this.overline)
319
+ decorations.push("overline");
320
+ if (decorations.length > 0) {
321
+ parts.push(`text-decoration: ${decorations.join(" ")}`);
322
+ }
323
+ if (this.dim)
324
+ parts.push("opacity: 0.5");
325
+ return parts.join("; ");
326
+ }
327
+ /**
328
+ * Serializes to a canonical string that round-trips through `Style.parse()`.
329
+ */
330
+ toString() {
331
+ if (this.isNull)
332
+ return "none";
333
+ const parts = [];
334
+ // Negated attributes first
335
+ for (const name of ATTRIBUTE_NAMES) {
336
+ if (this[name] === false)
337
+ parts.push(`not ${name}`);
338
+ }
339
+ // Positive attributes
340
+ for (const name of ATTRIBUTE_NAMES) {
341
+ if (this[name] === true)
342
+ parts.push(name);
343
+ }
344
+ if (this.color)
345
+ parts.push(this.color.name);
346
+ if (this.bgcolor)
347
+ parts.push(`on ${this.bgcolor.name}`);
348
+ if (this.link)
349
+ parts.push(`link ${this.link}`);
350
+ return parts.join(" ") || "none";
351
+ }
352
+ // --- Static methods ---
353
+ static null() {
354
+ return NULL_STYLE;
355
+ }
356
+ static fromColor(color, bgcolor) {
357
+ return new Style({ color, bgcolor });
358
+ }
359
+ static fromMeta(meta) {
360
+ return new Style({ meta });
361
+ }
362
+ static pickFirst(...args) {
363
+ for (const a of args) {
364
+ if (a !== undefined)
365
+ return a;
366
+ }
367
+ throw new Error("All arguments are undefined");
368
+ }
369
+ static combine(styles) {
370
+ let result = NULL_STYLE;
371
+ for (const s of styles) {
372
+ if (s)
373
+ result = result.add(s);
374
+ }
375
+ return result;
376
+ }
377
+ static chain(...styles) {
378
+ return Style.combine(styles);
379
+ }
380
+ static normalize(definition) {
381
+ return definition.trim().replace(/\s+/g, " ");
382
+ }
383
+ /**
384
+ * Parse a space-separated style definition. Cached.
385
+ */
386
+ static parse(definition) {
387
+ const normalized = Style.normalize(definition);
388
+ if (normalized === "" || normalized === "none")
389
+ return NULL_STYLE;
390
+ const cached = styleParseCache.get(normalized);
391
+ if (cached)
392
+ return cached;
393
+ // Check DEFAULT_STYLES for semantic names (e.g., "table.header", "repr.number")
394
+ // [LAW:one-source-of-truth] Semantic names resolve through DEFAULT_STYLES
395
+ // Only check after initialization is complete (avoid circular reference)
396
+ if (defaultStylesReady && normalized.includes(".")) {
397
+ const semantic = DEFAULT_STYLES[normalized];
398
+ if (semantic !== undefined) {
399
+ styleParseCache.set(normalized, semantic);
400
+ return semantic;
401
+ }
402
+ }
403
+ const result = parseStyleDefinition(normalized);
404
+ styleParseCache.set(normalized, result);
405
+ return result;
406
+ }
407
+ }
408
+ export const NULL_STYLE = new Style();
409
+ // --- StyleStack ---
410
+ export class StyleStack {
411
+ stack;
412
+ constructor(base = NULL_STYLE) {
413
+ this.stack = [base];
414
+ }
415
+ get current() {
416
+ return this.stack[this.stack.length - 1];
417
+ }
418
+ push(style) {
419
+ this.stack.push(this.current.add(style));
420
+ }
421
+ pop() {
422
+ if (this.stack.length <= 1) {
423
+ throw new Error("Cannot pop the base style from StyleStack");
424
+ }
425
+ return this.stack.pop();
426
+ }
427
+ }
428
+ // --- Theme ---
429
+ const STYLE_NAME_RE = /^[a-z][a-z0-9._-]*$/;
430
+ export class Theme {
431
+ styles;
432
+ constructor(definitions = {}, options) {
433
+ this.styles = new Map();
434
+ const inherit = options?.inherit !== false;
435
+ if (inherit) {
436
+ for (const [name, style] of Object.entries(DEFAULT_STYLES)) {
437
+ this.styles.set(name, style);
438
+ }
439
+ }
440
+ for (const [name, def] of Object.entries(definitions)) {
441
+ if (!STYLE_NAME_RE.test(name)) {
442
+ throw new Error(`Invalid style name: "${name}" (must be lowercase, start with letter, contain only letters, digits, ".", "-", "_")`);
443
+ }
444
+ this.styles.set(name, Style.parse(def));
445
+ }
446
+ }
447
+ get(name) {
448
+ return this.styles.get(name);
449
+ }
450
+ has(name) {
451
+ return this.styles.has(name);
452
+ }
453
+ }
454
+ // --- Parse helpers ---
455
+ const ATTRIBUTE_SET = new Set(ATTRIBUTE_NAMES);
456
+ function parseStyleDefinition(definition) {
457
+ const tokens = definition.split(/\s+/);
458
+ const opts = {};
459
+ let i = 0;
460
+ while (i < tokens.length) {
461
+ const token = tokens[i];
462
+ // "not <attr>"
463
+ if (token === "not") {
464
+ i++;
465
+ const next = tokens[i];
466
+ if (!next) {
467
+ throw new StyleSyntaxError(`Expected attribute after "not" in style definition`);
468
+ }
469
+ const attrName = ATTRIBUTE_SHORT_ALIASES[next] ?? next;
470
+ if (!ATTRIBUTE_SET.has(attrName)) {
471
+ throw new StyleSyntaxError(`Invalid attribute: "${next}"`);
472
+ }
473
+ opts[attrName] = false;
474
+ i++;
475
+ continue;
476
+ }
477
+ // "on <color>"
478
+ if (token === "on") {
479
+ i++;
480
+ const next = tokens[i];
481
+ if (!next) {
482
+ throw new StyleSyntaxError(`Expected color after "on" in style definition`);
483
+ }
484
+ try {
485
+ opts.bgcolor = ColorSpec.parse(next);
486
+ }
487
+ catch {
488
+ throw new StyleSyntaxError(`Invalid background color: "${next}"`);
489
+ }
490
+ i++;
491
+ continue;
492
+ }
493
+ // "link <url>"
494
+ if (token === "link") {
495
+ i++;
496
+ const url = tokens[i];
497
+ if (url) {
498
+ opts.link = url;
499
+ }
500
+ i++;
501
+ continue;
502
+ }
503
+ // Attribute (full name)
504
+ const resolvedAttr = ATTRIBUTE_SHORT_ALIASES[token] ?? token;
505
+ if (ATTRIBUTE_SET.has(resolvedAttr)) {
506
+ opts[resolvedAttr] = true;
507
+ i++;
508
+ continue;
509
+ }
510
+ // Must be a color
511
+ try {
512
+ opts.color = ColorSpec.parse(token);
513
+ }
514
+ catch {
515
+ throw new StyleSyntaxError(`Invalid style definition: "${token}"`);
516
+ }
517
+ i++;
518
+ }
519
+ return new Style(opts);
520
+ }
521
+ function resolveColor(c) {
522
+ if (c === undefined)
523
+ return undefined;
524
+ if (c instanceof ColorSpec)
525
+ return c;
526
+ return ColorSpec.parse(c);
527
+ }
528
+ // --- DEFAULT_STYLES ---
529
+ // [LAW:one-source-of-truth] Single canonical mapping of semantic names to styles
530
+ let defaultStylesReady = false;
531
+ export const DEFAULT_STYLES = {
532
+ none: NULL_STYLE,
533
+ reset: new Style({
534
+ color: ColorSpec.default(),
535
+ bgcolor: ColorSpec.default(),
536
+ bold: false,
537
+ dim: false,
538
+ italic: false,
539
+ underline: false,
540
+ blink: false,
541
+ blink2: false,
542
+ reverse: false,
543
+ conceal: false,
544
+ strike: false,
545
+ underline2: false,
546
+ frame: false,
547
+ encircle: false,
548
+ overline: false,
549
+ }),
550
+ bold: new Style({ bold: true }),
551
+ dim: new Style({ dim: true }),
552
+ italic: new Style({ italic: true }),
553
+ underline: new Style({ underline: true }),
554
+ blink: new Style({ blink: true }),
555
+ blink2: new Style({ blink2: true }),
556
+ reverse: new Style({ reverse: true }),
557
+ conceal: new Style({ conceal: true }),
558
+ strike: new Style({ strike: true }),
559
+ underline2: new Style({ underline2: true }),
560
+ frame: new Style({ frame: true }),
561
+ encircle: new Style({ encircle: true }),
562
+ overline: new Style({ overline: true }),
563
+ // Table
564
+ "table.header": new Style({ bold: true }),
565
+ "table.footer": new Style({ bold: true }),
566
+ "table.cell": NULL_STYLE,
567
+ "table.title": new Style({ italic: true }),
568
+ "table.caption": new Style({ italic: true, dim: true }),
569
+ // Repr/highlighting
570
+ "repr.str": Style.parse("green"),
571
+ "repr.number": Style.parse("cyan"),
572
+ "repr.bool": Style.parse("italic bright_magenta"),
573
+ "repr.none": Style.parse("italic magenta"),
574
+ "repr.url": Style.parse("not italic underline bright_blue"),
575
+ "repr.uuid": Style.parse("bright_yellow"),
576
+ "repr.error": Style.parse("bold red"),
577
+ "repr.indent": Style.parse("dim green"),
578
+ "repr.attrib_name": Style.parse("yellow"),
579
+ "repr.attrib_value": Style.parse("magenta"),
580
+ "repr.attrib_equal": Style.parse("bold"),
581
+ "repr.tag_start": Style.parse("bold"),
582
+ "repr.tag_name": Style.parse("bright_magenta"),
583
+ "repr.tag_contents": Style.parse("default"),
584
+ "repr.tag_end": Style.parse("bold"),
585
+ // Log
586
+ "log.time": Style.parse("cyan dim"),
587
+ "log.message": NULL_STYLE,
588
+ "log.path": Style.parse("dim"),
589
+ "log.line_no": Style.parse("cyan"),
590
+ "log.level": NULL_STYLE,
591
+ // Rule
592
+ "rule.line": Style.parse("green"),
593
+ "rule.text": Style.parse("bold"),
594
+ // JSON
595
+ "json.brace": Style.parse("bold"),
596
+ "json.bool": Style.parse("italic bright_magenta"),
597
+ "json.key": Style.parse("bold blue"),
598
+ "json.null": Style.parse("italic magenta"),
599
+ "json.number": Style.parse("cyan"),
600
+ "json.str": Style.parse("green"),
601
+ // Markdown
602
+ "markdown.h1": Style.parse("bold underline"),
603
+ "markdown.h2": Style.parse("bold"),
604
+ "markdown.h3": Style.parse("bold dim"),
605
+ "markdown.h4": Style.parse("bold dim italic"),
606
+ "markdown.code": Style.parse("cyan on grey11"),
607
+ "markdown.hr": Style.parse("yellow"),
608
+ "markdown.link": Style.parse("bright_blue"),
609
+ "markdown.link_url": Style.parse("blue"),
610
+ // Progress
611
+ "progress.description": NULL_STYLE,
612
+ "progress.percentage": Style.parse("cyan"),
613
+ "progress.remaining": Style.parse("cyan"),
614
+ "progress.elapsed": Style.parse("cyan"),
615
+ "progress.spinner": Style.parse("green"),
616
+ "progress.download": Style.parse("green"),
617
+ "progress.filesize": Style.parse("green"),
618
+ "progress.filesize.total": Style.parse("green"),
619
+ "progress.data.speed": Style.parse("red"),
620
+ // Bar
621
+ "bar.back": Style.parse("grey23"),
622
+ "bar.complete": Style.parse("magenta"),
623
+ "bar.finished": Style.parse("green"),
624
+ "bar.pulse": Style.parse("magenta"),
625
+ // Tree
626
+ "tree": NULL_STYLE,
627
+ "tree.guide": NULL_STYLE,
628
+ // Status
629
+ "status.spinner": Style.parse("green"),
630
+ "status.message": NULL_STYLE,
631
+ // Prompt
632
+ "prompt": Style.parse("bold"),
633
+ "prompt.choices": Style.parse("magenta"),
634
+ "prompt.default": Style.parse("cyan"),
635
+ // Inspect
636
+ "inspect.attr": Style.parse("yellow italic"),
637
+ "inspect.attr.dunder": Style.parse("yellow italic dim"),
638
+ "inspect.callable": Style.parse("bold magenta"),
639
+ "inspect.error": Style.parse("bold red"),
640
+ "inspect.help": Style.parse("cyan"),
641
+ "inspect.doc": Style.parse("dim"),
642
+ "inspect.value.border": Style.parse("green"),
643
+ // Traceback
644
+ "traceback.border": Style.parse("red"),
645
+ "traceback.text": Style.parse("red"),
646
+ "traceback.title": Style.parse("bold red"),
647
+ "traceback.exc_type": Style.parse("bold bright_red"),
648
+ "traceback.exc_value": NULL_STYLE,
649
+ "traceback.offset": Style.parse("bold bright_red"),
650
+ // Scope
651
+ "scope.border": Style.parse("blue"),
652
+ "scope.key": Style.parse("italic"),
653
+ "scope.key.special": Style.parse("dim italic"),
654
+ // Pretty
655
+ "pretty": NULL_STYLE,
656
+ // ISO8601
657
+ "iso8601.date": Style.parse("cyan"),
658
+ "iso8601.time": Style.parse("cyan"),
659
+ "iso8601.timezone": Style.parse("bright_blue"),
660
+ };
661
+ defaultStylesReady = true;
662
+ //# sourceMappingURL=style.js.map