@alchemy.run/sigil 0.0.0-alpha.4 → 0.0.0-alpha.6

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 (138) hide show
  1. package/README.md +21 -9
  2. package/THIRD_PARTY_NOTICES.md +39 -1
  3. package/dist/Text-BobFKi74.d.ts +452 -0
  4. package/dist/ansi.d.ts +122 -131
  5. package/dist/ansi.js +86 -6
  6. package/dist/capabilities.d.ts +5 -0
  7. package/dist/capabilities.js +3 -0
  8. package/dist/cell-_ZVhbfl0.js +44 -0
  9. package/dist/color-CkbalRqK.js +2 -0
  10. package/dist/color-policy-BMzMwV7Q.d.ts +22 -0
  11. package/dist/color-policy-SVj1pYTA.js +560 -0
  12. package/dist/color-profile-DHhQHY55.js +36 -0
  13. package/dist/color-profile-u0Nhe9Nv.d.ts +97 -0
  14. package/dist/color.d.ts +21 -0
  15. package/dist/color.js +3 -0
  16. package/dist/cursor-position-D2LAkRG0.d.ts +7 -0
  17. package/dist/detect-Bh4yGP6w.d.ts +186 -0
  18. package/dist/detect-BuTXtY6e.js +373 -0
  19. package/dist/env-YVw64yZS.js +9 -0
  20. package/dist/escapes-CB_6CWOE.d.ts +72 -0
  21. package/dist/geometry-BxXOzJgo.d.ts +11 -0
  22. package/dist/index-DZ88EXJv.d.ts +21 -0
  23. package/dist/index.d.ts +143 -498
  24. package/dist/index.js +1026 -2244
  25. package/dist/osc-CCH7xDoS.js +71 -0
  26. package/dist/osc-Cn0fw77g.d.ts +23 -0
  27. package/dist/paint-C19minOS.d.ts +81 -0
  28. package/dist/query-vaIeGOkH.d.ts +152 -0
  29. package/dist/router.d.ts +392 -0
  30. package/dist/router.js +709 -0
  31. package/dist/sample-Cqw1bjUL.js +445 -0
  32. package/dist/screen-BOSLQ8fF.d.ts +49 -0
  33. package/dist/screen-CiPytswf.js +342 -0
  34. package/dist/screen.d.ts +5 -0
  35. package/dist/screen.js +5 -0
  36. package/dist/semantic-text-style-DIMzC7xt.js +91 -0
  37. package/dist/serialize-BTkAZgw1.js +79 -0
  38. package/dist/session-aZr9O8h3.js +665 -0
  39. package/dist/sgr-BhwaWAJB.js +246 -0
  40. package/dist/store-CgrG9K4y.d.ts +72 -0
  41. package/dist/string-width-CijQwpIk.js +69 -0
  42. package/dist/strip-BvU4toXG.js +6 -0
  43. package/dist/terminal.d.ts +118 -0
  44. package/dist/terminal.js +2 -0
  45. package/dist/tokenize-AjqbvtiT.js +1242 -0
  46. package/dist/tokenize-Dx1y_l5H.d.ts +57 -0
  47. package/dist/truncate-D31fhU6i.js +562 -0
  48. package/dist/use-focus-BzqAJi0n.js +1337 -0
  49. package/package.json +41 -9
  50. package/src/ansi/chalk.ts +5 -3
  51. package/src/ansi/escapes.ts +14 -0
  52. package/src/ansi/graphemes.ts +8 -0
  53. package/src/ansi/hyperlink.ts +44 -0
  54. package/src/ansi/index.ts +3 -1
  55. package/src/ansi/osc.ts +77 -0
  56. package/src/ansi/tokenize.ts +3 -4
  57. package/src/capabilities/color-policy.ts +34 -0
  58. package/src/capabilities/detect.ts +594 -0
  59. package/src/capabilities/index.ts +37 -0
  60. package/src/capabilities/query.ts +657 -0
  61. package/src/capabilities/store.ts +379 -0
  62. package/src/color/index.ts +3 -0
  63. package/src/color/paint.ts +169 -0
  64. package/src/color/palette.ts +48 -0
  65. package/src/color/sample.ts +323 -0
  66. package/src/color.ts +1 -0
  67. package/src/components/AnsiText.tsx +42 -0
  68. package/src/components/App.tsx +98 -10
  69. package/src/components/BackgroundContext.ts +2 -3
  70. package/src/components/Box.tsx +0 -8
  71. package/src/components/CursorContext.ts +1 -1
  72. package/src/components/Hyperlink.tsx +56 -0
  73. package/src/components/TerminalOscContext.ts +25 -0
  74. package/src/components/Text.tsx +22 -45
  75. package/src/components/Transform.tsx +1 -1
  76. package/src/dom.ts +11 -2
  77. package/src/global.d.ts +3 -0
  78. package/src/hooks/use-capabilities.ts +73 -0
  79. package/src/hooks/use-cursor.ts +2 -2
  80. package/src/hooks/use-terminal-osc.ts +59 -0
  81. package/src/index.ts +45 -1
  82. package/src/ink.tsx +213 -153
  83. package/src/{render-node-to-output.ts → paint-tree.ts} +75 -48
  84. package/src/reconciler.ts +24 -3
  85. package/src/render-background.ts +36 -15
  86. package/src/render-border.ts +94 -61
  87. package/src/render-frame.ts +83 -0
  88. package/src/render-to-string.ts +21 -6
  89. package/src/render.ts +15 -6
  90. package/src/router/components.tsx +343 -0
  91. package/src/router/context.ts +41 -0
  92. package/src/router/history.ts +194 -0
  93. package/src/router/hooks.tsx +391 -0
  94. package/src/router/index.ts +34 -0
  95. package/src/router/matcher.ts +571 -0
  96. package/src/screen/ansi.ts +184 -0
  97. package/src/screen/canvas.ts +160 -0
  98. package/src/screen/cell.ts +138 -0
  99. package/src/screen/color-profile.ts +47 -0
  100. package/src/screen/geometry.ts +9 -0
  101. package/src/screen/index.ts +6 -0
  102. package/src/screen/screen.ts +305 -0
  103. package/src/screen/serialize.ts +129 -0
  104. package/src/screen.ts +1 -0
  105. package/src/semantic-text-style.ts +118 -0
  106. package/src/squash-text-nodes.ts +2 -5
  107. package/src/structured-text.ts +325 -0
  108. package/src/styles.ts +19 -14
  109. package/src/terminal/index.ts +2 -0
  110. package/src/terminal/inline-presenter.ts +120 -0
  111. package/src/terminal/input.ts +86 -0
  112. package/src/terminal/render-scheduler.ts +37 -0
  113. package/src/terminal/screen-presenter.ts +188 -0
  114. package/src/terminal/session.ts +407 -0
  115. package/src/terminal.ts +1 -0
  116. package/src/testing/browser.ts +588 -0
  117. package/src/testing/emulators.ts +205 -0
  118. package/src/testing/explorer-app/index.html +12 -0
  119. package/src/testing/explorer-app/main.ts +381 -0
  120. package/src/testing/explorer-app/style.css +194 -0
  121. package/src/testing/explorer-app/tsconfig.json +15 -0
  122. package/src/testing/explorer-app/vite-env.d.ts +1 -0
  123. package/src/testing/index.ts +26 -0
  124. package/src/testing/keys.ts +56 -0
  125. package/src/testing/live.ts +85 -0
  126. package/src/testing/matchers.ts +70 -0
  127. package/src/testing/public.ts +94 -0
  128. package/src/testing/terminal.ts +349 -0
  129. package/src/testing/vitest.ts +157 -0
  130. package/src/transform-adapter.ts +14 -0
  131. package/src/wrap-text.ts +4 -0
  132. package/dist/sgr-CMfEpjSk.d.ts +0 -91
  133. package/dist/truncate-Cr6xVFMa.js +0 -2330
  134. package/src/ansi/supports-color.ts +0 -207
  135. package/src/colorize.ts +0 -60
  136. package/src/log-update.ts +0 -370
  137. package/src/output.ts +0 -308
  138. package/src/renderer.ts +0 -73
@@ -0,0 +1,445 @@
1
+ import { r as parseSemanticColor } from "./semantic-text-style-DIMzC7xt.js";
2
+ //#region src/color/paint.ts
3
+ const rgb = (red, green, blue, alpha = 255) => ({
4
+ model: "rgb",
5
+ red: channel(red),
6
+ green: channel(green),
7
+ blue: channel(blue),
8
+ alpha: channel(alpha)
9
+ });
10
+ const ansi = (index) => ({
11
+ model: "indexed",
12
+ index: Math.max(0, Math.min(15, Math.round(index))),
13
+ encoding: "ansi16"
14
+ });
15
+ const ansi256 = (index) => ({
16
+ model: "indexed",
17
+ index: Math.max(0, Math.min(255, Math.round(index))),
18
+ encoding: "ansi256"
19
+ });
20
+ const namedIndexes = {
21
+ black: 0,
22
+ red: 1,
23
+ green: 2,
24
+ yellow: 3,
25
+ blue: 4,
26
+ magenta: 5,
27
+ cyan: 6,
28
+ white: 7,
29
+ blackBright: 8,
30
+ gray: 8,
31
+ grey: 8,
32
+ redBright: 9,
33
+ greenBright: 10,
34
+ yellowBright: 11,
35
+ blueBright: 12,
36
+ magentaBright: 13,
37
+ cyanBright: 14,
38
+ whiteBright: 15
39
+ };
40
+ const named = (color) => ansi(namedIndexes[color]);
41
+ const adaptive = (light, dark) => ({
42
+ type: "adaptive-color",
43
+ light,
44
+ dark
45
+ });
46
+ const perProfile = (colors, fallback) => ({
47
+ type: "profile-color",
48
+ colors,
49
+ fallback
50
+ });
51
+ const linearGradient = (stops, options = {}) => {
52
+ if (stops.length < 2) throw new Error("A linear gradient requires at least two color stops");
53
+ return {
54
+ type: "linear-gradient",
55
+ stops: normalizeStops(stops.map((stop) => isGradientStop(stop) ? stop : { color: stop })),
56
+ angle: options.angle ?? 0,
57
+ space: options.space ?? "oklab"
58
+ };
59
+ };
60
+ const perimeterGradient = (stops, options = {}) => {
61
+ if (stops.length < 2) throw new Error("A perimeter gradient requires at least two color stops");
62
+ return {
63
+ type: "perimeter-gradient",
64
+ stops: normalizeStops(stops.map((color) => ({ color }))),
65
+ offset: Math.round(options.offset ?? 0),
66
+ space: options.space ?? "lab"
67
+ };
68
+ };
69
+ function normalizeStops(stops) {
70
+ const output = stops.map((stop) => ({ ...stop }));
71
+ output[0] = {
72
+ ...output[0],
73
+ offset: output[0].offset ?? 0
74
+ };
75
+ output[output.length - 1] = {
76
+ ...output.at(-1),
77
+ offset: output.at(-1).offset ?? 1
78
+ };
79
+ let anchor = 0;
80
+ while (anchor < output.length - 1) {
81
+ let next = anchor + 1;
82
+ while (next < output.length && output[next].offset === void 0) next++;
83
+ const start = output[anchor].offset;
84
+ const end = output[next].offset;
85
+ for (let index = anchor + 1; index < next; index++) output[index] = {
86
+ ...output[index],
87
+ offset: start + (end - start) * (index - anchor) / (next - anchor)
88
+ };
89
+ anchor = next;
90
+ }
91
+ return output.map((stop) => ({
92
+ ...stop,
93
+ offset: Math.max(0, Math.min(1, stop.offset))
94
+ }));
95
+ }
96
+ function isGradientStop(value) {
97
+ return typeof value === "object" && value !== null && "color" in value;
98
+ }
99
+ function channel(value) {
100
+ return Math.max(0, Math.min(255, Math.round(value)));
101
+ }
102
+ const canonicalAnsiPalette = [
103
+ [
104
+ 0,
105
+ 0,
106
+ 0
107
+ ],
108
+ [
109
+ 205,
110
+ 0,
111
+ 0
112
+ ],
113
+ [
114
+ 0,
115
+ 205,
116
+ 0
117
+ ],
118
+ [
119
+ 205,
120
+ 205,
121
+ 0
122
+ ],
123
+ [
124
+ 0,
125
+ 0,
126
+ 238
127
+ ],
128
+ [
129
+ 205,
130
+ 0,
131
+ 205
132
+ ],
133
+ [
134
+ 0,
135
+ 205,
136
+ 205
137
+ ],
138
+ [
139
+ 229,
140
+ 229,
141
+ 229
142
+ ],
143
+ [
144
+ 127,
145
+ 127,
146
+ 127
147
+ ],
148
+ [
149
+ 255,
150
+ 0,
151
+ 0
152
+ ],
153
+ [
154
+ 0,
155
+ 255,
156
+ 0
157
+ ],
158
+ [
159
+ 255,
160
+ 255,
161
+ 0
162
+ ],
163
+ [
164
+ 92,
165
+ 92,
166
+ 255
167
+ ],
168
+ [
169
+ 255,
170
+ 0,
171
+ 255
172
+ ],
173
+ [
174
+ 0,
175
+ 255,
176
+ 255
177
+ ],
178
+ [
179
+ 255,
180
+ 255,
181
+ 255
182
+ ]
183
+ ].map(([red, green, blue]) => ({
184
+ model: "rgb",
185
+ red,
186
+ green,
187
+ blue,
188
+ alpha: 255
189
+ }));
190
+ function colorToRgb(color, palette) {
191
+ if (color.model === "rgb") return color;
192
+ const custom = color.index < 16 ? palette?.[color.index] : void 0;
193
+ if (custom) return {
194
+ model: "rgb",
195
+ red: custom.r,
196
+ green: custom.g,
197
+ blue: custom.b,
198
+ alpha: 255
199
+ };
200
+ if (color.index < 16) return canonicalAnsiPalette[color.index];
201
+ if (color.index >= 232) {
202
+ const value = 8 + (color.index - 232) * 10;
203
+ return {
204
+ model: "rgb",
205
+ red: value,
206
+ green: value,
207
+ blue: value,
208
+ alpha: 255
209
+ };
210
+ }
211
+ const index = color.index - 16;
212
+ const levels = [
213
+ 0,
214
+ 95,
215
+ 135,
216
+ 175,
217
+ 215,
218
+ 255
219
+ ];
220
+ return {
221
+ model: "rgb",
222
+ red: levels[Math.floor(index / 36)],
223
+ green: levels[Math.floor(index % 36 / 6)],
224
+ blue: levels[index % 6],
225
+ alpha: 255
226
+ };
227
+ }
228
+ //#endregion
229
+ //#region src/color/sample.ts
230
+ function samplePaint(paint, x, y, bounds, context = {}) {
231
+ const resolved = resolveConditional(paint, context);
232
+ if (resolved && typeof resolved === "object" && "type" in resolved) {
233
+ if (resolved.type === "perimeter-gradient") return samplePerimeterGradient(resolved, x, y, bounds, context);
234
+ }
235
+ if (isLinearGradient(resolved)) return sampleGradient(resolved, x, y, bounds, context);
236
+ return resolveColor(resolved);
237
+ }
238
+ function blend(source, destination, palette) {
239
+ const foreground = colorToRgb(source, palette);
240
+ if (foreground.alpha >= 255) return foreground;
241
+ const background = colorToRgb(destination, palette);
242
+ const alpha = foreground.alpha / 255;
243
+ return rgb(foreground.red * alpha + background.red * (1 - alpha), foreground.green * alpha + background.green * (1 - alpha), foreground.blue * alpha + background.blue * (1 - alpha));
244
+ }
245
+ /** Progressively moves a color toward white in perceptual OKLab space. */
246
+ function lighten(color, amount, palette) {
247
+ return interpolateColor(color, rgb(255, 255, 255), amount, "oklab", palette);
248
+ }
249
+ /** Progressively moves a color toward black in perceptual OKLab space. */
250
+ function darken(color, amount, palette) {
251
+ return interpolateColor(color, rgb(0, 0, 0), amount, "oklab", palette);
252
+ }
253
+ function sampleGradient(gradient, x, y, bounds, context) {
254
+ const radians = gradient.angle * Math.PI / 180;
255
+ const dx = Math.cos(radians);
256
+ const dy = Math.sin(radians);
257
+ const width = Math.max(1, bounds.width - 1);
258
+ const height = Math.max(1, bounds.height - 1);
259
+ const projections = [
260
+ 0,
261
+ width * dx,
262
+ height * dy,
263
+ width * dx + height * dy
264
+ ];
265
+ const minimum = Math.min(...projections);
266
+ const maximum = Math.max(...projections);
267
+ const projection = (x - bounds.x) * dx + (y - bounds.y) * dy;
268
+ const position = maximum === minimum ? 0 : (projection - minimum) / (maximum - minimum);
269
+ return sampleStops(gradient.stops, position, gradient.space, x, y, bounds, context);
270
+ }
271
+ function samplePerimeterGradient(gradient, x, y, bounds, context) {
272
+ const width = Math.max(1, bounds.width);
273
+ const height = Math.max(1, bounds.height);
274
+ const steps = width === 1 || height === 1 ? Math.max(width, height) : 2 * width + 2 * height - 4;
275
+ if (steps <= 1) return samplePaint(gradient.stops[0].color, x, y, bounds, context);
276
+ const left = bounds.x;
277
+ const top = bounds.y;
278
+ const right = left + width - 1;
279
+ const bottom = top + height - 1;
280
+ let index;
281
+ if (height === 1) index = x - left;
282
+ else if (width === 1) index = y - top;
283
+ else if (y <= top) index = Math.max(0, Math.min(width - 1, x - left));
284
+ else if (x >= right) index = width + Math.max(0, Math.min(height - 2, y - top - 1));
285
+ else if (y >= bottom) index = width + height - 2 + Math.max(0, Math.min(width - 1, right - x));
286
+ else index = 2 * width + height - 2 + Math.max(0, Math.min(height - 2, bottom - y - 1));
287
+ index = modulo(index - gradient.offset, steps);
288
+ const position = blendPosition(index, steps, gradient.stops.length);
289
+ return sampleStops(gradient.stops, position, gradient.space, x, y, bounds, context);
290
+ }
291
+ /** Matches Lip Gloss Blend1D's even, discrete distribution of stops. */
292
+ function blendPosition(index, steps, stopCount) {
293
+ if (steps <= stopCount) return index / Math.max(1, stopCount - 1);
294
+ const segments = stopCount - 1;
295
+ const baseSize = Math.floor(steps / segments);
296
+ const remainder = steps % segments;
297
+ let start = 0;
298
+ for (let segment = 0; segment < segments; segment++) {
299
+ const size = baseSize + (segment < remainder ? 1 : 0);
300
+ if (index < start + size) {
301
+ const local = size <= 1 ? 0 : (index - start) / (size - 1);
302
+ return (segment + local) / segments;
303
+ }
304
+ start += size;
305
+ }
306
+ return 1;
307
+ }
308
+ function sampleStops(stops, position, space, x, y, bounds, context) {
309
+ let right = 1;
310
+ while (right < stops.length - 1 && position > stops[right].offset) right++;
311
+ const start = stops[right - 1];
312
+ const end = stops[right];
313
+ const span = end.offset - start.offset;
314
+ const amount = span === 0 ? 0 : Math.max(0, Math.min(1, (position - start.offset) / span));
315
+ const startColor = samplePaint(start.color, x, y, bounds, context);
316
+ const endColor = samplePaint(end.color, x, y, bounds, context);
317
+ if (!startColor || !endColor) return startColor ?? endColor;
318
+ return interpolateColor(startColor, endColor, amount, space, context.palette);
319
+ }
320
+ function interpolateColor(from, to, amount, space = "oklab", palette) {
321
+ const a = colorToRgb(from, palette);
322
+ const b = colorToRgb(to, palette);
323
+ const t = Math.max(0, Math.min(1, amount));
324
+ if (space === "rgb") return rgb(mix(a.red, b.red, t), mix(a.green, b.green, t), mix(a.blue, b.blue, t), mix(a.alpha, b.alpha, t));
325
+ if (space === "hsv") {
326
+ const ah = toHsv(a), bh = toHsv(b);
327
+ let delta = bh[0] - ah[0];
328
+ if (delta > 180) delta -= 360;
329
+ if (delta < -180) delta += 360;
330
+ return fromHsv(ah[0] + delta * t, mix(ah[1], bh[1], t), mix(ah[2], bh[2], t), mix(a.alpha, b.alpha, t));
331
+ }
332
+ if (space === "lab") {
333
+ const al = toLab(a), bl = toLab(b);
334
+ return fromLab(mix(al[0], bl[0], t), mix(al[1], bl[1], t), mix(al[2], bl[2], t), mix(a.alpha, b.alpha, t));
335
+ }
336
+ const al = toOklab(a), bl = toOklab(b);
337
+ return fromOklab(mix(al[0], bl[0], t), mix(al[1], bl[1], t), mix(al[2], bl[2], t), mix(a.alpha, b.alpha, t));
338
+ }
339
+ const D65 = [
340
+ .95047,
341
+ 1,
342
+ 1.08883
343
+ ];
344
+ function labCurve(value) {
345
+ return value > (6 / 29) ** 3 ? Math.cbrt(value) : value / 3 * (29 / 6) ** 2 + 4 / 29;
346
+ }
347
+ function inverseLabCurve(value) {
348
+ return value > 6 / 29 ? value ** 3 : 3 * (6 / 29) ** 2 * (value - 4 / 29);
349
+ }
350
+ function toLab(color) {
351
+ const r = linear(color.red), g = linear(color.green), b = linear(color.blue);
352
+ const x = .4123907992659595 * r + .357584339383878 * g + .1804807884018343 * b;
353
+ const y = .2126390058715104 * r + .7151686787677559 * g + .0721923153607337 * b;
354
+ const z = .0193308187155919 * r + .119194779794626 * g + .9505321522496606 * b;
355
+ const fy = labCurve(y / D65[1]);
356
+ return [
357
+ 1.16 * fy - .16,
358
+ 5 * (labCurve(x / D65[0]) - fy),
359
+ 2 * (fy - labCurve(z / D65[2]))
360
+ ];
361
+ }
362
+ function fromLab(l, a, b, alpha) {
363
+ const center = (l + .16) / 1.16;
364
+ const x = D65[0] * inverseLabCurve(center + a / 5);
365
+ const y = D65[1] * inverseLabCurve(center);
366
+ const z = D65[2] * inverseLabCurve(center - b / 2);
367
+ return rgb(colorfulChannel(3.240969941904521 * x - 1.5373831775700935 * y - .4986107602930033 * z), colorfulChannel(-.9692436362808798 * x + 1.8759675015077206 * y + .0415550574071756 * z), colorfulChannel(.0556300796969936 * x - .2039769588889766 * y + 1.0569715142428786 * z), alpha);
368
+ }
369
+ const mix = (a, b, t) => a + (b - a) * t;
370
+ const linear = (value) => {
371
+ const x = value / 255;
372
+ return x <= .04045 ? x / 12.92 : ((x + .055) / 1.055) ** 2.4;
373
+ };
374
+ const gamma = (value) => 255 * (value <= .0031308 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - .055);
375
+ const colorfulChannel = (value) => {
376
+ const encoded = value <= .0031308 ? 12.92 * value : 1.055 * value ** (1 / 2.4) - .055;
377
+ return Math.floor(Math.round(Math.max(0, Math.min(1, encoded)) * 65535) / 256);
378
+ };
379
+ function toOklab(c) {
380
+ const r = linear(c.red), g = linear(c.green), b = linear(c.blue);
381
+ const l = Math.cbrt(.4122214708 * r + .5363325363 * g + .0514459929 * b), m = Math.cbrt(.2119034982 * r + .6806995451 * g + .1073969566 * b), s = Math.cbrt(.0883024619 * r + .2817188376 * g + .6299787005 * b);
382
+ return [
383
+ .2104542553 * l + .793617785 * m - .0040720468 * s,
384
+ 1.9779984951 * l - 2.428592205 * m + .4505937099 * s,
385
+ .0259040371 * l + .7827717662 * m - .808675766 * s
386
+ ];
387
+ }
388
+ function fromOklab(L, a, b, alpha) {
389
+ const l = (L + .3963377774 * a + .2158037573 * b) ** 3, m = (L - .1055613458 * a - .0638541728 * b) ** 3, s = (L - .0894841775 * a - 1.291485548 * b) ** 3;
390
+ return rgb(gamma(4.0767416621 * l - 3.3077115913 * m + .2309699292 * s), gamma(-1.2684380046 * l + 2.6097574011 * m - .3413193965 * s), gamma(-.0041960863 * l - .7034186147 * m + 1.707614701 * s), alpha);
391
+ }
392
+ function toHsv(c) {
393
+ const r = c.red / 255, g = c.green / 255, b = c.blue / 255, max = Math.max(r, g, b), d = max - Math.min(r, g, b);
394
+ let h = 0;
395
+ if (d) h = max === r ? 60 * ((g - b) / d % 6) : max === g ? 60 * ((b - r) / d + 2) : 60 * ((r - g) / d + 4);
396
+ return [
397
+ (h + 360) % 360,
398
+ max === 0 ? 0 : d / max,
399
+ max
400
+ ];
401
+ }
402
+ function fromHsv(h, s, v, alpha) {
403
+ const c = v * s, x = c * (1 - Math.abs(h / 60 % 2 - 1)), m = v - c;
404
+ const [r, g, b] = h < 60 ? [
405
+ c,
406
+ x,
407
+ 0
408
+ ] : h < 120 ? [
409
+ x,
410
+ c,
411
+ 0
412
+ ] : h < 180 ? [
413
+ 0,
414
+ c,
415
+ x
416
+ ] : h < 240 ? [
417
+ 0,
418
+ x,
419
+ c
420
+ ] : h < 300 ? [
421
+ x,
422
+ 0,
423
+ c
424
+ ] : [
425
+ c,
426
+ 0,
427
+ x
428
+ ];
429
+ return rgb((r + m) * 255, (g + m) * 255, (b + m) * 255, alpha);
430
+ }
431
+ function resolveConditional(paint, context) {
432
+ if (typeof paint !== "object" || paint === null || "model" in paint) return paint;
433
+ if (paint.type === "adaptive-color") return resolveConditional(context.appearance === "light" ? paint.light : paint.dark, context);
434
+ if (paint.type === "profile-color") return resolveConditional((context.profile && paint.colors[context.profile]) ?? paint.fallback, context);
435
+ return paint;
436
+ }
437
+ function resolveColor(value) {
438
+ return typeof value === "string" ? parseSemanticColor(value) : typeof value === "object" && value !== null && "model" in value ? value : void 0;
439
+ }
440
+ function isLinearGradient(value) {
441
+ return typeof value === "object" && value !== null && "type" in value && value.type === "linear-gradient";
442
+ }
443
+ const modulo = (value, divisor) => (value % divisor + divisor) % divisor;
444
+ //#endregion
445
+ export { samplePaint as a, adaptive as c, linearGradient as d, named as f, rgb as h, lighten as i, ansi as l, perimeterGradient as m, darken as n, canonicalAnsiPalette as o, perProfile as p, interpolateColor as r, colorToRgb as s, blend as t, ansi256 as u };
@@ -0,0 +1,49 @@
1
+ import { i as Cell, o as CellPatch } from "./color-profile-u0Nhe9Nv.js";
2
+ import { n as Rect } from "./geometry-BxXOzJgo.js";
3
+ //#region src/screen/screen.d.ts
4
+ type Line = readonly Cell[];
5
+ /** A half-open range of changed columns in one row. */
6
+ type DirtySpan = {
7
+ readonly y: number;
8
+ readonly start: number;
9
+ readonly end: number;
10
+ };
11
+ /**
12
+ A mutable two-dimensional terminal cell buffer. Cells themselves are immutable,
13
+ so current and next screens can compare them by value or safely share constants.
14
+ */
15
+ declare class Screen {
16
+ #private;
17
+ constructor(width: number, height: number);
18
+ get width(): number;
19
+ /**
20
+ The populated length of one row: the nominal width, or more when overflow
21
+ writes (`textWrap: "none"` content) extended it past the screen's width.
22
+ */
23
+ rowLength(y: number): number;
24
+ get height(): number;
25
+ bounds(): Rect;
26
+ cellAt(x: number, y: number): Cell | undefined;
27
+ /** Whether a drawable explicitly touched this position. */
28
+ isPainted(x: number, y: number): boolean;
29
+ setCell(x: number, y: number, cell: Cell, options?: {
30
+ overflow?: boolean;
31
+ }): void;
32
+ /**
33
+ Composes independent cell channels over the existing cell. An undefined
34
+ patch is transparent; an explicit space in `content` paints a blank.
35
+ */
36
+ composeCell(x: number, y: number, patch: CellPatch | undefined, options?: {
37
+ overflow?: boolean;
38
+ }): void;
39
+ /** Composes a patch throughout a rectangle, clipped to this screen. */
40
+ fill(bounds: Rect, patch: CellPatch | undefined): void;
41
+ /** Resizes while preserving complete graphemes in the shared top-left area. */
42
+ resize(width: number, height: number): void;
43
+ clear(): void;
44
+ toRows(): readonly Line[];
45
+ dirtySpans(): readonly DirtySpan[];
46
+ takeDirtySpans(): readonly DirtySpan[];
47
+ }
48
+ //#endregion
49
+ export { Screen as n, Line as t };