@flyingrobots/bijou 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/adapters/test/index.d.ts.map +1 -1
- package/dist/adapters/test/index.js +4 -0
- package/dist/adapters/test/index.js.map +1 -1
- package/dist/adapters/test/runtime.d.ts +2 -0
- package/dist/adapters/test/runtime.d.ts.map +1 -1
- package/dist/adapters/test/runtime.js +1 -0
- package/dist/adapters/test/runtime.js.map +1 -1
- package/dist/core/components/alert.d.ts +2 -4
- package/dist/core/components/alert.d.ts.map +1 -1
- package/dist/core/components/alert.js.map +1 -1
- package/dist/core/components/badge.d.ts +6 -12
- package/dist/core/components/badge.d.ts.map +1 -1
- package/dist/core/components/badge.js +39 -24
- package/dist/core/components/badge.js.map +1 -1
- package/dist/core/components/bcss-style.d.ts +6 -0
- package/dist/core/components/bcss-style.d.ts.map +1 -0
- package/dist/core/components/bcss-style.js +44 -0
- package/dist/core/components/bcss-style.js.map +1 -0
- package/dist/core/components/box-v3.d.ts +9 -0
- package/dist/core/components/box-v3.d.ts.map +1 -0
- package/dist/core/components/box-v3.js +91 -0
- package/dist/core/components/box-v3.js.map +1 -0
- package/dist/core/components/box.d.ts +4 -4
- package/dist/core/components/box.d.ts.map +1 -1
- package/dist/core/components/box.js +26 -4
- package/dist/core/components/box.js.map +1 -1
- package/dist/core/components/log.d.ts.map +1 -1
- package/dist/core/components/log.js +2 -1
- package/dist/core/components/log.js.map +1 -1
- package/dist/core/components/separator.d.ts +2 -4
- package/dist/core/components/separator.d.ts.map +1 -1
- package/dist/core/components/separator.js.map +1 -1
- package/dist/core/components/types.d.ts +15 -0
- package/dist/core/components/types.d.ts.map +1 -0
- package/dist/core/components/types.js +2 -0
- package/dist/core/components/types.js.map +1 -0
- package/dist/core/layout/flex.d.ts +28 -0
- package/dist/core/layout/flex.d.ts.map +1 -0
- package/dist/core/layout/flex.js +126 -0
- package/dist/core/layout/flex.js.map +1 -0
- package/dist/core/render/differ.d.ts +49 -0
- package/dist/core/render/differ.d.ts.map +1 -0
- package/dist/core/render/differ.js +271 -0
- package/dist/core/render/differ.js.map +1 -0
- package/dist/core/theme/accessors.d.ts.map +1 -1
- package/dist/core/theme/accessors.js +21 -5
- package/dist/core/theme/accessors.js.map +1 -1
- package/dist/core/theme/graph-types.d.ts +58 -0
- package/dist/core/theme/graph-types.d.ts.map +1 -0
- package/dist/core/theme/graph-types.js +2 -0
- package/dist/core/theme/graph-types.js.map +1 -0
- package/dist/core/theme/graph.d.ts +27 -0
- package/dist/core/theme/graph.d.ts.map +1 -0
- package/dist/core/theme/graph.js +155 -0
- package/dist/core/theme/graph.js.map +1 -0
- package/dist/core/theme/index.d.ts +3 -0
- package/dist/core/theme/index.d.ts.map +1 -1
- package/dist/core/theme/index.js +2 -0
- package/dist/core/theme/index.js.map +1 -1
- package/dist/core/theme/resolve.d.ts +3 -0
- package/dist/core/theme/resolve.d.ts.map +1 -1
- package/dist/core/theme/resolve.js +3 -0
- package/dist/core/theme/resolve.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +5 -0
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/ports/context.d.ts +9 -0
- package/dist/ports/context.d.ts.map +1 -1
- package/dist/ports/io.d.ts +6 -0
- package/dist/ports/io.d.ts.map +1 -1
- package/dist/ports/runtime.d.ts +5 -0
- package/dist/ports/runtime.d.ts.map +1 -1
- package/dist/ports/surface.d.ts +152 -0
- package/dist/ports/surface.d.ts.map +1 -0
- package/dist/ports/surface.js +199 -0
- package/dist/ports/surface.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolveSafeCtx as resolveCtx } from '../resolve-ctx.js';
|
|
2
2
|
import { badge } from './badge.js';
|
|
3
3
|
import { renderByMode } from '../mode-render.js';
|
|
4
|
+
import { surfaceToString } from '../render/differ.js';
|
|
4
5
|
/** Abbreviated 3-letter labels for each log level used in pipe/interactive modes. */
|
|
5
6
|
const LABELS = {
|
|
6
7
|
debug: 'DBG',
|
|
@@ -94,7 +95,7 @@ export function log(level, message, options) {
|
|
|
94
95
|
}
|
|
95
96
|
if (showPrefix) {
|
|
96
97
|
const variant = BADGE_VARIANTS[level];
|
|
97
|
-
parts.push(badge(LABELS[level], { variant, ctx }));
|
|
98
|
+
parts.push(surfaceToString(badge(LABELS[level], { variant, ctx }), ctx.style));
|
|
98
99
|
}
|
|
99
100
|
parts.push(message);
|
|
100
101
|
return parts.join(' ');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/core/components/log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../../src/core/components/log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,IAAI,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAetD,qFAAqF;AACrF,MAAM,MAAM,GAA6B;IACvC,KAAK,EAAE,KAAK;IACZ,IAAI,EAAE,KAAK;IACX,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,KAAK;IACZ,KAAK,EAAE,KAAK;CACb,CAAC;AAEF,gFAAgF;AAChF,MAAM,cAAc,GAA6B;IAC/C,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IA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AAE,EAAE,CAAC,CAAC;gBAC7D,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvB,CAAC;YACD,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAQ,CAAC;gBAC7C,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YACjF,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpB,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;KACF,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;AACpB,CAAC"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type { BijouContext } from '../../ports/context.js';
|
|
2
1
|
import type { TokenValue } from '../theme/tokens.js';
|
|
2
|
+
import type { BijouNodeOptions } from './types.js';
|
|
3
3
|
/** Configuration for rendering a horizontal separator line. */
|
|
4
|
-
export interface SeparatorOptions {
|
|
4
|
+
export interface SeparatorOptions extends BijouNodeOptions {
|
|
5
5
|
/** Optional centered label text. */
|
|
6
6
|
label?: string;
|
|
7
7
|
/** Total width in characters (defaults to terminal column count). */
|
|
8
8
|
width?: number;
|
|
9
9
|
/** Theme token applied to the separator line. */
|
|
10
10
|
borderToken?: TokenValue;
|
|
11
|
-
/** Bijou context for I/O, styling, and mode detection. */
|
|
12
|
-
ctx?: BijouContext;
|
|
13
11
|
}
|
|
14
12
|
/**
|
|
15
13
|
* Render a horizontal separator line, optionally centered around a label.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"separator.d.ts","sourceRoot":"","sources":["../../../src/core/components/separator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"separator.d.ts","sourceRoot":"","sources":["../../../src/core/components/separator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,+DAA+D;AAC/D,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,WAAW,CAAC,EAAE,UAAU,CAAC;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,CA4BhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"separator.js","sourceRoot":"","sources":["../../../src/core/components/separator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"separator.js","sourceRoot":"","sources":["../../../src/core/components/separator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAajD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAC,UAA4B,EAAE;IACtD,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;IAEnD,OAAO,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE;QAC5B,IAAI,EAAE,GAAG,EAAE;YACT,IAAI,KAAK;gBAAE,OAAO,OAAO,KAAK,MAAM,CAAC;YACrC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,UAAU,EAAE,GAAG,EAAE;YACf,IAAI,KAAK;gBAAE,OAAO,OAAO,KAAK,MAAM,CAAC;YACrC,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,WAAW,EAAE,GAAG,EAAE;YAChB,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAEzD,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,eAAe,GAAG,IAAI,KAAK,GAAG,CAAC;gBACrC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;gBAC9D,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;gBACvC,MAAM,KAAK,GAAG,SAAS,GAAG,IAAI,CAAC;gBAC/B,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,eAAe,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5H,CAAC;YAED,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACzD,CAAC;KACF,EAAE,OAAO,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BijouContext } from '../../ports/context.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base options shared by all Bijou UI components.
|
|
4
|
+
*
|
|
5
|
+
* Part of the Standardized BijouNode Protocol.
|
|
6
|
+
*/
|
|
7
|
+
export interface BijouNodeOptions {
|
|
8
|
+
/** Unique identifier for the component. Used for CSS styling (#id) and layout tracking. */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** CSS class name(s) for the component. Space-separated. */
|
|
11
|
+
class?: string;
|
|
12
|
+
/** Optional Bijou context. If omitted, the global default context is used. */
|
|
13
|
+
ctx?: BijouContext;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/components/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2FAA2F;IAC3F,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,GAAG,CAAC,EAAE,YAAY,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/components/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { LayoutNode, LayoutRect } from '../../ports/surface.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the flex layout engine.
|
|
4
|
+
*/
|
|
5
|
+
export interface FlexOptions {
|
|
6
|
+
direction?: 'row' | 'column';
|
|
7
|
+
gap?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Metadata for a flex child.
|
|
11
|
+
*/
|
|
12
|
+
export interface FlexChildProps {
|
|
13
|
+
id?: string;
|
|
14
|
+
flex?: number;
|
|
15
|
+
basis?: number;
|
|
16
|
+
minSize?: number;
|
|
17
|
+
maxSize?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Calculate flex layout geometry.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Flex container options.
|
|
23
|
+
* @param children - Properties for each child.
|
|
24
|
+
* @param bounds - Available space.
|
|
25
|
+
* @returns Root LayoutNode containing child rects.
|
|
26
|
+
*/
|
|
27
|
+
export declare function calculateFlex(options: FlexOptions, children: FlexChildProps[], bounds: LayoutRect): LayoutNode;
|
|
28
|
+
//# sourceMappingURL=flex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flex.d.ts","sourceRoot":"","sources":["../../../src/core/layout/flex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,cAAc,EAAE,EAC1B,MAAM,EAAE,UAAU,GACjB,UAAU,CA4HZ"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate flex layout geometry.
|
|
3
|
+
*
|
|
4
|
+
* @param options - Flex container options.
|
|
5
|
+
* @param children - Properties for each child.
|
|
6
|
+
* @param bounds - Available space.
|
|
7
|
+
* @returns Root LayoutNode containing child rects.
|
|
8
|
+
*/
|
|
9
|
+
export function calculateFlex(options, children, bounds) {
|
|
10
|
+
const direction = options.direction ?? 'row';
|
|
11
|
+
const gap = options.gap ?? 0;
|
|
12
|
+
const isRow = direction === 'row';
|
|
13
|
+
const mainAxisTotal = isRow ? bounds.width : bounds.height;
|
|
14
|
+
const crossAxisTotal = isRow ? bounds.height : bounds.width;
|
|
15
|
+
if (children.length === 0) {
|
|
16
|
+
return { rect: bounds, children: [] };
|
|
17
|
+
}
|
|
18
|
+
const totalGaps = gap * (children.length - 1);
|
|
19
|
+
const available = Math.max(0, mainAxisTotal - totalGaps);
|
|
20
|
+
// First pass: fixed sizes
|
|
21
|
+
const sizes = [];
|
|
22
|
+
let usedByFixed = 0;
|
|
23
|
+
let totalFlex = 0;
|
|
24
|
+
for (const child of children) {
|
|
25
|
+
const flexGrow = child.flex ?? 0;
|
|
26
|
+
if (flexGrow > 0) {
|
|
27
|
+
sizes.push(0);
|
|
28
|
+
totalFlex += flexGrow;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const b = child.basis ?? 0;
|
|
32
|
+
const clamped = clamp(b, child.minSize, child.maxSize);
|
|
33
|
+
sizes.push(clamped);
|
|
34
|
+
usedByFixed += clamped;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Second pass: distribute remaining space to flex children iteratively
|
|
38
|
+
// to correctly handle min/max constraints.
|
|
39
|
+
let remaining = Math.max(0, available - usedByFixed);
|
|
40
|
+
let activeFlex = totalFlex;
|
|
41
|
+
const isConstrained = new Array(children.length).fill(false);
|
|
42
|
+
// Iteratively distribute until all flex space is assigned or all flex children are constrained
|
|
43
|
+
while (activeFlex > 0 && remaining > 0) {
|
|
44
|
+
let spaceDistributed = false;
|
|
45
|
+
const perFlexUnit = remaining / activeFlex;
|
|
46
|
+
for (let i = 0; i < children.length; i++) {
|
|
47
|
+
if (isConstrained[i])
|
|
48
|
+
continue;
|
|
49
|
+
const child = children[i];
|
|
50
|
+
const flexGrow = child.flex ?? 0;
|
|
51
|
+
if (flexGrow <= 0)
|
|
52
|
+
continue;
|
|
53
|
+
const currentSize = sizes[i];
|
|
54
|
+
const targetSize = currentSize + (flexGrow * perFlexUnit);
|
|
55
|
+
const clamped = clamp(targetSize, child.minSize, child.maxSize);
|
|
56
|
+
if (clamped !== targetSize) {
|
|
57
|
+
// This child hit a constraint
|
|
58
|
+
sizes[i] = clamped;
|
|
59
|
+
remaining -= (clamped - currentSize);
|
|
60
|
+
activeFlex -= flexGrow;
|
|
61
|
+
isConstrained[i] = true;
|
|
62
|
+
spaceDistributed = true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!spaceDistributed) {
|
|
66
|
+
// Final pass: distribute the last remaining bits without constraints (they are already satisfied)
|
|
67
|
+
const fractionalShares = [];
|
|
68
|
+
let assigned = 0;
|
|
69
|
+
for (let i = 0; i < children.length; i++) {
|
|
70
|
+
if (!isConstrained[i] && (children[i].flex ?? 0) > 0) {
|
|
71
|
+
const flexGrow = children[i].flex;
|
|
72
|
+
const share = (flexGrow / activeFlex) * remaining;
|
|
73
|
+
const whole = Math.floor(share);
|
|
74
|
+
sizes[i] += whole;
|
|
75
|
+
assigned += whole;
|
|
76
|
+
fractionalShares.push({ index: i, remainder: share - whole });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
let leftover = remaining - assigned;
|
|
80
|
+
fractionalShares.sort((a, b) => b.remainder - a.remainder || a.index - b.index);
|
|
81
|
+
for (let i = 0; i < fractionalShares.length && leftover > 0; i++, leftover--) {
|
|
82
|
+
sizes[fractionalShares[i].index] += 1;
|
|
83
|
+
}
|
|
84
|
+
remaining = 0; // All done
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Third pass: position calculation
|
|
88
|
+
const childNodes = [];
|
|
89
|
+
let offset = 0;
|
|
90
|
+
for (let i = 0; i < children.length; i++) {
|
|
91
|
+
const child = children[i];
|
|
92
|
+
const size = sizes[i];
|
|
93
|
+
const childRect = isRow
|
|
94
|
+
? {
|
|
95
|
+
x: bounds.x + offset,
|
|
96
|
+
y: bounds.y,
|
|
97
|
+
width: size,
|
|
98
|
+
height: crossAxisTotal
|
|
99
|
+
}
|
|
100
|
+
: {
|
|
101
|
+
x: bounds.x,
|
|
102
|
+
y: bounds.y + offset,
|
|
103
|
+
width: crossAxisTotal,
|
|
104
|
+
height: size
|
|
105
|
+
};
|
|
106
|
+
childNodes.push({
|
|
107
|
+
id: child.id,
|
|
108
|
+
rect: childRect,
|
|
109
|
+
children: []
|
|
110
|
+
});
|
|
111
|
+
offset += size + gap;
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
rect: bounds,
|
|
115
|
+
children: childNodes
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function clamp(val, min, max) {
|
|
119
|
+
let res = val;
|
|
120
|
+
if (min !== undefined)
|
|
121
|
+
res = Math.max(res, min);
|
|
122
|
+
if (max !== undefined)
|
|
123
|
+
res = Math.min(res, max);
|
|
124
|
+
return Math.max(0, res);
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=flex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flex.js","sourceRoot":"","sources":["../../../src/core/layout/flex.ts"],"names":[],"mappings":"AAqBA;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAC3B,OAAoB,EACpB,QAA0B,EAC1B,MAAkB;IAElB,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,SAAS,KAAK,KAAK,CAAC;IAElC,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;IAC3D,MAAM,cAAc,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;IAE5D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACxC,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,IAAI,C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AAM,CAAC,CAAC,GAAG,MAAM;gBACpB,CAAC,EAAE,MAAM,CAAC,CAAC;gBACX,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,cAAc;aACvB;YACH,CAAC,CAAC;gBACE,CAAC,EAAE,MAAM,CAAC,CAAC;gBACX,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM;gBACpB,KAAK,EAAE,cAAc;gBACrB,MAAM,EAAE,IAAI;aACb,CAAC;QAEN,UAAU,CAAC,IAAI,CAAC;YACd,EAAE,EAAE,KAAK,CAAC,EAAE;YACZ,IAAI,EAAE,SAAS;YACf,QAAQ,EAAE,EAAE;SACb,CAAC,CAAC;QAEH,MAAM,IAAI,IAAI,GAAG,GAAG,CAAC;IACvB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,UAAU;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,KAAK,CAAC,GAAW,EAAE,GAAY,EAAE,GAAY;IACpD,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,IAAI,GAAG,KAAK,SAAS;QAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAChD,IAAI,GAAG,KAAK,SAAS;QAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAChD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Surface, type Cell, type LayoutNode } from '../../ports/surface.js';
|
|
2
|
+
import type { WritePort, StylePort } from '../../ports/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convert a multi-line string into a Surface.
|
|
5
|
+
*
|
|
6
|
+
* Note: This is a legacy migration helper. It currently strips ANSI
|
|
7
|
+
* and treats all characters as the default style.
|
|
8
|
+
*/
|
|
9
|
+
export declare function stringToSurface(text: string, width: number, height: number): Surface;
|
|
10
|
+
/**
|
|
11
|
+
* Robust ANSI-aware string to Surface conversion.
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseAnsiToSurface(text: string, width: number, height: number): Surface;
|
|
14
|
+
/**
|
|
15
|
+
* Convert a Surface into a multi-line string with ANSI escape codes.
|
|
16
|
+
*
|
|
17
|
+
* Note: This is a legacy migration helper.
|
|
18
|
+
*
|
|
19
|
+
* @param surface - The surface to convert.
|
|
20
|
+
* @param style - The style port to use for color resolution.
|
|
21
|
+
* @returns A string representation of the surface.
|
|
22
|
+
*/
|
|
23
|
+
export declare function surfaceToString(surface: Surface, style: StylePort): string;
|
|
24
|
+
/**
|
|
25
|
+
* Paint a LayoutNode tree onto a Surface.
|
|
26
|
+
*
|
|
27
|
+
* @param target - The surface to paint onto.
|
|
28
|
+
* @param node - The root layout node to paint.
|
|
29
|
+
*/
|
|
30
|
+
export declare function paintLayoutNode(target: Surface, node: LayoutNode): void;
|
|
31
|
+
/**
|
|
32
|
+
* Compare two cells for equality (content and style).
|
|
33
|
+
*/
|
|
34
|
+
export declare function isSameCell(a: Cell, b: Cell): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Diff two surfaces and write the minimal set of changes to the WritePort.
|
|
37
|
+
*
|
|
38
|
+
* Optimizations:
|
|
39
|
+
* 1. Skips identical cells.
|
|
40
|
+
* 2. Minimizes CUP (move cursor) commands by detecting contiguous changes.
|
|
41
|
+
* 3. Batches cells with identical styles to minimize SGR codes and keep strings contiguous.
|
|
42
|
+
*
|
|
43
|
+
* @param current - The surface currently on the terminal.
|
|
44
|
+
* @param target - The desired surface state.
|
|
45
|
+
* @param io - The port to write ANSI codes to.
|
|
46
|
+
* @param style - The port to resolve cell styling.
|
|
47
|
+
*/
|
|
48
|
+
export declare function renderDiff(current: Surface, target: Surface, io: WritePort, style: StylePort): void;
|
|
49
|
+
//# sourceMappingURL=differ.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"differ.d.ts","sourceRoot":"","sources":["../../../src/core/render/differ.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjE;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAcpF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAiFvF;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CAgB1E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI,CAQvE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,OAAO,CAcpD;AAUD;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,OAAO,EACf,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,SAAS,GACf,IAAI,CAmEN"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { createSurface } from '../../ports/surface.js';
|
|
2
|
+
import { stripAnsi, segmentGraphemes } from '../text/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convert a multi-line string into a Surface.
|
|
5
|
+
*
|
|
6
|
+
* Note: This is a legacy migration helper. It currently strips ANSI
|
|
7
|
+
* and treats all characters as the default style.
|
|
8
|
+
*/
|
|
9
|
+
export function stringToSurface(text, width, height) {
|
|
10
|
+
const surface = createSurface(width, height);
|
|
11
|
+
const plainText = stripAnsi(text);
|
|
12
|
+
const lines = plainText.split(/\r?\n/);
|
|
13
|
+
for (let y = 0; y < Math.min(height, lines.length); y++) {
|
|
14
|
+
const line = lines[y];
|
|
15
|
+
const gs = segmentGraphemes(line);
|
|
16
|
+
for (let x = 0; x < Math.min(width, gs.length); x++) {
|
|
17
|
+
surface.set(x, y, { char: gs[x], empty: false });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return surface;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Robust ANSI-aware string to Surface conversion.
|
|
24
|
+
*/
|
|
25
|
+
export function parseAnsiToSurface(text, width, height) {
|
|
26
|
+
const surface = createSurface(width, height);
|
|
27
|
+
const lines = text.split(/\r?\n/);
|
|
28
|
+
const ANSI_RE = /\x1b\[([0-9;]*)m/g;
|
|
29
|
+
for (let y = 0; y < Math.min(height, lines.length); y++) {
|
|
30
|
+
const line = lines[y];
|
|
31
|
+
let x = 0;
|
|
32
|
+
let currentFg;
|
|
33
|
+
let currentBg;
|
|
34
|
+
let currentMods = new Set();
|
|
35
|
+
const matches = Array.from(line.matchAll(ANSI_RE));
|
|
36
|
+
let lastIndex = 0;
|
|
37
|
+
for (const match of matches) {
|
|
38
|
+
const matchIndex = match.index;
|
|
39
|
+
const part = line.slice(lastIndex, matchIndex);
|
|
40
|
+
const gs = segmentGraphemes(part);
|
|
41
|
+
for (const char of gs) {
|
|
42
|
+
if (x < width) {
|
|
43
|
+
surface.set(x, y, { char, fg: currentFg, bg: currentBg, modifiers: Array.from(currentMods) });
|
|
44
|
+
x++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const codeStr = match[1];
|
|
48
|
+
if (codeStr === '0' || codeStr === '') {
|
|
49
|
+
currentFg = undefined;
|
|
50
|
+
currentBg = undefined;
|
|
51
|
+
currentMods.clear();
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const parts = codeStr.split(';');
|
|
55
|
+
let i = 0;
|
|
56
|
+
while (i < parts.length) {
|
|
57
|
+
const code = parts[i];
|
|
58
|
+
if (code === '1')
|
|
59
|
+
currentMods.add('bold');
|
|
60
|
+
else if (code === '2')
|
|
61
|
+
currentMods.add('dim');
|
|
62
|
+
else if (code === '3')
|
|
63
|
+
currentMods.add('italic');
|
|
64
|
+
else if (code === '4')
|
|
65
|
+
currentMods.add('underline');
|
|
66
|
+
else if (code === '7')
|
|
67
|
+
currentMods.add('inverse');
|
|
68
|
+
else if (code === '9')
|
|
69
|
+
currentMods.add('strike');
|
|
70
|
+
else if (code === '22') {
|
|
71
|
+
currentMods.delete('bold');
|
|
72
|
+
currentMods.delete('dim');
|
|
73
|
+
}
|
|
74
|
+
else if (code === '23')
|
|
75
|
+
currentMods.delete('italic');
|
|
76
|
+
else if (code === '24')
|
|
77
|
+
currentMods.delete('underline');
|
|
78
|
+
else if (code === '27')
|
|
79
|
+
currentMods.delete('inverse');
|
|
80
|
+
else if (code === '29')
|
|
81
|
+
currentMods.delete('strike');
|
|
82
|
+
else if (code === '38' && parts[i + 1] === '2') {
|
|
83
|
+
// Truecolor FG: 38;2;R;G;B
|
|
84
|
+
const r = parseInt(parts[i + 2], 10).toString(16).padStart(2, '0');
|
|
85
|
+
const g = parseInt(parts[i + 3], 10).toString(16).padStart(2, '0');
|
|
86
|
+
const b = parseInt(parts[i + 4], 10).toString(16).padStart(2, '0');
|
|
87
|
+
currentFg = '#' + r + g + b;
|
|
88
|
+
i += 4;
|
|
89
|
+
}
|
|
90
|
+
else if (code === '48' && parts[i + 1] === '2') {
|
|
91
|
+
// Truecolor BG: 48;2;R;G;B
|
|
92
|
+
const r = parseInt(parts[i + 2], 10).toString(16).padStart(2, '0');
|
|
93
|
+
const g = parseInt(parts[i + 3], 10).toString(16).padStart(2, '0');
|
|
94
|
+
const b = parseInt(parts[i + 4], 10).toString(16).padStart(2, '0');
|
|
95
|
+
currentBg = '#' + r + g + b;
|
|
96
|
+
i += 4;
|
|
97
|
+
}
|
|
98
|
+
i++;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
lastIndex = matchIndex + match[0].length;
|
|
102
|
+
}
|
|
103
|
+
const remaining = line.slice(lastIndex);
|
|
104
|
+
const gs = segmentGraphemes(remaining);
|
|
105
|
+
for (const char of gs) {
|
|
106
|
+
if (x < width) {
|
|
107
|
+
surface.set(x, y, { char, fg: currentFg, bg: currentBg, modifiers: Array.from(currentMods) });
|
|
108
|
+
x++;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return surface;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Convert a Surface into a multi-line string with ANSI escape codes.
|
|
116
|
+
*
|
|
117
|
+
* Note: This is a legacy migration helper.
|
|
118
|
+
*
|
|
119
|
+
* @param surface - The surface to convert.
|
|
120
|
+
* @param style - The style port to use for color resolution.
|
|
121
|
+
* @returns A string representation of the surface.
|
|
122
|
+
*/
|
|
123
|
+
export function surfaceToString(surface, style) {
|
|
124
|
+
const lines = [];
|
|
125
|
+
for (let y = 0; y < surface.height; y++) {
|
|
126
|
+
let line = '';
|
|
127
|
+
for (let x = 0; x < surface.width; x++) {
|
|
128
|
+
const cell = surface.get(x, y);
|
|
129
|
+
const token = {
|
|
130
|
+
hex: cell.fg,
|
|
131
|
+
bg: cell.bg,
|
|
132
|
+
modifiers: cell.modifiers,
|
|
133
|
+
};
|
|
134
|
+
line += style.styled(token, cell.char);
|
|
135
|
+
}
|
|
136
|
+
lines.push(line);
|
|
137
|
+
}
|
|
138
|
+
return lines.join('\n');
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Paint a LayoutNode tree onto a Surface.
|
|
142
|
+
*
|
|
143
|
+
* @param target - The surface to paint onto.
|
|
144
|
+
* @param node - The root layout node to paint.
|
|
145
|
+
*/
|
|
146
|
+
export function paintLayoutNode(target, node) {
|
|
147
|
+
if (node.surface) {
|
|
148
|
+
target.blit(node.surface, node.rect.x, node.rect.y);
|
|
149
|
+
}
|
|
150
|
+
for (const child of node.children) {
|
|
151
|
+
paintLayoutNode(target, child);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Compare two cells for equality (content and style).
|
|
156
|
+
*/
|
|
157
|
+
export function isSameCell(a, b) {
|
|
158
|
+
if (a.char !== b.char)
|
|
159
|
+
return false;
|
|
160
|
+
if (a.fg !== b.fg)
|
|
161
|
+
return false;
|
|
162
|
+
if (a.bg !== b.bg)
|
|
163
|
+
return false;
|
|
164
|
+
if (a.empty !== b.empty)
|
|
165
|
+
return false;
|
|
166
|
+
const aMods = a.modifiers ?? [];
|
|
167
|
+
const bMods = b.modifiers ?? [];
|
|
168
|
+
if (aMods.length !== bMods.length)
|
|
169
|
+
return false;
|
|
170
|
+
for (let i = 0; i < aMods.length; i++) {
|
|
171
|
+
if (aMods[i] !== bMods[i])
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Move the terminal cursor to (x, y) using CUP (Cursor Position) escape code.
|
|
178
|
+
* Coordinates are 0-based in Bijou, but 1-based in ANSI.
|
|
179
|
+
*/
|
|
180
|
+
function moveCursor(x, y) {
|
|
181
|
+
return `\x1b[${y + 1};${x + 1}H`;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Diff two surfaces and write the minimal set of changes to the WritePort.
|
|
185
|
+
*
|
|
186
|
+
* Optimizations:
|
|
187
|
+
* 1. Skips identical cells.
|
|
188
|
+
* 2. Minimizes CUP (move cursor) commands by detecting contiguous changes.
|
|
189
|
+
* 3. Batches cells with identical styles to minimize SGR codes and keep strings contiguous.
|
|
190
|
+
*
|
|
191
|
+
* @param current - The surface currently on the terminal.
|
|
192
|
+
* @param target - The desired surface state.
|
|
193
|
+
* @param io - The port to write ANSI codes to.
|
|
194
|
+
* @param style - The port to resolve cell styling.
|
|
195
|
+
*/
|
|
196
|
+
export function renderDiff(current, target, io, style) {
|
|
197
|
+
const width = target.width;
|
|
198
|
+
const height = target.height;
|
|
199
|
+
let output = '';
|
|
200
|
+
let cursorX = -1;
|
|
201
|
+
let cursorY = -1;
|
|
202
|
+
for (let y = 0; y < height; y++) {
|
|
203
|
+
let x = 0;
|
|
204
|
+
while (x < width) {
|
|
205
|
+
const targetCell = target.get(x, y);
|
|
206
|
+
const currentCell = current.get(x, y);
|
|
207
|
+
if (isSameCell(targetCell, currentCell)) {
|
|
208
|
+
x++;
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
// If we are not at the expected cursor position, move it
|
|
212
|
+
if (x !== cursorX || y !== cursorY) {
|
|
213
|
+
output += moveCursor(x, y);
|
|
214
|
+
}
|
|
215
|
+
// Find how many contiguous cells have the SAME style as this one
|
|
216
|
+
// and also NEED to be updated.
|
|
217
|
+
let batchX = x;
|
|
218
|
+
let batchText = '';
|
|
219
|
+
while (batchX < width) {
|
|
220
|
+
const c = target.get(batchX, y);
|
|
221
|
+
const curr = current.get(batchX, y);
|
|
222
|
+
if (batchX > x && !isSameStyle(c, targetCell))
|
|
223
|
+
break;
|
|
224
|
+
if (isSameCell(c, curr))
|
|
225
|
+
break;
|
|
226
|
+
batchText += c.char;
|
|
227
|
+
batchX++;
|
|
228
|
+
}
|
|
229
|
+
// Render the batch
|
|
230
|
+
const token = {
|
|
231
|
+
hex: targetCell.fg,
|
|
232
|
+
bg: targetCell.bg,
|
|
233
|
+
modifiers: targetCell.modifiers,
|
|
234
|
+
};
|
|
235
|
+
output += style.styled(token, batchText);
|
|
236
|
+
// Advance our internal cursor tracking
|
|
237
|
+
const batchWidth = batchX - x;
|
|
238
|
+
cursorX = x + batchWidth;
|
|
239
|
+
cursorY = y;
|
|
240
|
+
// Advance loop index
|
|
241
|
+
x = batchX;
|
|
242
|
+
// Flush if the buffer is getting large
|
|
243
|
+
if (output.length > 4096) {
|
|
244
|
+
io.write(output);
|
|
245
|
+
output = '';
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (output.length > 0) {
|
|
250
|
+
io.write(output);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Compare two cells for style equality only.
|
|
255
|
+
*/
|
|
256
|
+
function isSameStyle(a, b) {
|
|
257
|
+
if (a.fg !== b.fg)
|
|
258
|
+
return false;
|
|
259
|
+
if (a.bg !== b.bg)
|
|
260
|
+
return false;
|
|
261
|
+
const aMods = a.modifiers ?? [];
|
|
262
|
+
const bMods = b.modifiers ?? [];
|
|
263
|
+
if (aMods.length !== bMods.length)
|
|
264
|
+
return false;
|
|
265
|
+
for (let i = 0; i < aMods.length; i++) {
|
|
266
|
+
if (aMods[i] !== bMods[i])
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=differ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"differ.js","sourceRoot":"","sources":["../../../src/core/render/differ.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4C,MAAM,wBAAwB,CAAC;AAEjG,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,KAAa,EAAE,MAAc;IACzE,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACxD,MAAM,IAAI,GAAG,KAAK,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EAAE,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;IAC1C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessors.d.ts","sourceRoot":"","sources":["../../../src/core/theme/accessors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IACnD,oCAAoC;IACpC,MAAM,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;IAC/C,qCAAqC;IACrC,OAAO,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC;IACjD,+DAA+D;IAC/D,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAChC,4EAA4E;IAC5E,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,EAAE,CAAC;CACvC;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,
|
|
1
|
+
{"version":3,"file":"accessors.d.ts","sourceRoot":"","sources":["../../../src/core/theme/accessors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IACnD,oCAAoC;IACpC,MAAM,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;IAC/C,qCAAqC;IACrC,OAAO,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,SAAS,CAAC,GAAG,UAAU,CAAC;IACjD,+DAA+D;IAC/D,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAChC,4EAA4E;IAC5E,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,EAAE,CAAC;CACvC;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,CAwBzE"}
|
|
@@ -9,12 +9,28 @@
|
|
|
9
9
|
* @returns An object whose properties can be spread into a {@link BijouContext}.
|
|
10
10
|
*/
|
|
11
11
|
export function createThemeAccessors(theme) {
|
|
12
|
+
const { tokenGraph, colorScheme } = theme;
|
|
13
|
+
const mode = colorScheme === 'light' ? 'light' : 'dark';
|
|
12
14
|
return {
|
|
13
|
-
semantic: (key) =>
|
|
14
|
-
border: (key) =>
|
|
15
|
-
surface: (key) =>
|
|
16
|
-
status: (key) =>
|
|
17
|
-
|
|
15
|
+
semantic: (key) => tokenGraph.get(`semantic.${key}`, mode),
|
|
16
|
+
border: (key) => tokenGraph.get(`border.${key}`, mode),
|
|
17
|
+
surface: (key) => tokenGraph.get(`surface.${key}`, mode),
|
|
18
|
+
status: (key) => {
|
|
19
|
+
try {
|
|
20
|
+
return tokenGraph.get(`status.${key}`, mode);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return tokenGraph.get('status.muted', mode);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
ui: (key) => {
|
|
27
|
+
try {
|
|
28
|
+
return tokenGraph.get(`ui.${key}`, mode);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return tokenGraph.get('semantic.primary', mode);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
18
34
|
gradient: (key) => theme.theme.gradient[key] ?? [],
|
|
19
35
|
};
|
|
20
36
|
}
|