@tinyactors/scxmljs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +174 -0
- package/THIRD_PARTY_NOTICES +63 -0
- package/dist/bridge.d.ts +44 -0
- package/dist/bridge.js +254 -0
- package/dist/bridge.js.map +1 -0
- package/dist/clock.d.ts +113 -0
- package/dist/clock.js +310 -0
- package/dist/clock.js.map +1 -0
- package/dist/common.d.ts +15 -0
- package/dist/common.js +14 -0
- package/dist/common.js.map +1 -0
- package/dist/datamodel-base.d.ts +122 -0
- package/dist/datamodel-base.js +268 -0
- package/dist/datamodel-base.js.map +1 -0
- package/dist/datamodel-quickjs.d.ts +21 -0
- package/dist/datamodel-quickjs.js +286 -0
- package/dist/datamodel-quickjs.js.map +1 -0
- package/dist/datamodel-trusted.d.ts +1 -0
- package/dist/datamodel-trusted.js +149 -0
- package/dist/datamodel-trusted.js.map +1 -0
- package/dist/diagnostics.d.ts +39 -0
- package/dist/diagnostics.js +154 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/element-events.d.ts +85 -0
- package/dist/element-events.js +129 -0
- package/dist/element-events.js.map +1 -0
- package/dist/events.d.ts +31 -0
- package/dist/events.js +33 -0
- package/dist/events.js.map +1 -0
- package/dist/explorer/element.d.ts +150 -0
- package/dist/explorer/element.js +1791 -0
- package/dist/explorer/element.js.map +1 -0
- package/dist/explorer/layout.d.ts +43 -0
- package/dist/explorer/layout.js +50 -0
- package/dist/explorer/layout.js.map +1 -0
- package/dist/explorer/strings.d.ts +275 -0
- package/dist/explorer/strings.js +135 -0
- package/dist/explorer/strings.js.map +1 -0
- package/dist/explorer/styles.d.ts +10 -0
- package/dist/explorer/styles.js +265 -0
- package/dist/explorer/styles.js.map +1 -0
- package/dist/explorer/viewmodel.d.ts +284 -0
- package/dist/explorer/viewmodel.js +481 -0
- package/dist/explorer/viewmodel.js.map +1 -0
- package/dist/explorer.d.ts +21 -0
- package/dist/explorer.js +22 -0
- package/dist/explorer.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/model.d.ts +157 -0
- package/dist/model.js +485 -0
- package/dist/model.js.map +1 -0
- package/dist/session-events.d.ts +136 -0
- package/dist/session-events.js +114 -0
- package/dist/session-events.js.map +1 -0
- package/dist/session.d.ts +412 -0
- package/dist/session.js +1399 -0
- package/dist/session.js.map +1 -0
- package/dist/themes/tinyactors.css +44 -0
- package/dist/trusted.d.ts +15 -0
- package/dist/trusted.js +30 -0
- package/dist/trusted.js.map +1 -0
- package/dist/ui/announcer.d.ts +22 -0
- package/dist/ui/announcer.js +31 -0
- package/dist/ui/announcer.js.map +1 -0
- package/dist/ui/svg.d.ts +8 -0
- package/dist/ui/svg.js +29 -0
- package/dist/ui/svg.js.map +1 -0
- package/dist/ui/theme.d.ts +34 -0
- package/dist/ui/theme.js +151 -0
- package/dist/ui/theme.js.map +1 -0
- package/dist/view/element.d.ts +172 -0
- package/dist/view/element.js +1045 -0
- package/dist/view/element.js.map +1 -0
- package/dist/view/layout.d.ts +154 -0
- package/dist/view/layout.js +1122 -0
- package/dist/view/layout.js.map +1 -0
- package/dist/view/strings.d.ts +72 -0
- package/dist/view/strings.js +48 -0
- package/dist/view/strings.js.map +1 -0
- package/dist/view/styles.d.ts +1 -0
- package/dist/view/styles.js +115 -0
- package/dist/view/styles.js.map +1 -0
- package/dist/view.d.ts +20 -0
- package/dist/view.js +21 -0
- package/dist/view.js.map +1 -0
- package/package.json +87 -0
package/dist/ui/theme.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared theme for the scxmljs custom elements (`<scxml-explorer>`, and
|
|
3
|
+
* `<scxml-view>` once it moves into the package).
|
|
4
|
+
*
|
|
5
|
+
* Theming contract: every visual decision reads a public `--scxml-*` custom
|
|
6
|
+
* property (set them on `scxml-explorer`, or anywhere above it). Unset ones
|
|
7
|
+
* fall back to the neutral default theme below, which follows the page's
|
|
8
|
+
* light/dark preference via `light-dark()` and `color-scheme`. Internally the
|
|
9
|
+
* shadow DOM uses short private aliases (`--x-*`); they are not part of the API.
|
|
10
|
+
*
|
|
11
|
+
* No fonts are loaded: the defaults are system font stacks.
|
|
12
|
+
*/
|
|
13
|
+
/** One breakpoint for every element: at or below this width (px) the elements switch to their narrow layout. */
|
|
14
|
+
export const NARROW_WIDTH = 760;
|
|
15
|
+
export const THEME_CSS = /* css */ `
|
|
16
|
+
:host {
|
|
17
|
+
/* follow the page: while --scxml-color-scheme is unset this is invalid, so color-scheme
|
|
18
|
+
inherits and light-dark() below matches the page. Set it to "light dark" to follow the OS. */
|
|
19
|
+
color-scheme: var(--scxml-color-scheme);
|
|
20
|
+
/* text */
|
|
21
|
+
--x-fg1: var(--scxml-fg, light-dark(#1c1c21, #ececf1));
|
|
22
|
+
--x-fg2: var(--scxml-fg-muted, light-dark(#484852, #bcbcc6));
|
|
23
|
+
--x-fg3: var(--scxml-fg-subtle, light-dark(#6a6a75, #90909b));
|
|
24
|
+
--x-fg4: var(--scxml-fg-faint, light-dark(#85858f, #777781)); /* graphics only (≥3:1), never text */
|
|
25
|
+
/* surfaces */
|
|
26
|
+
--x-bg: var(--scxml-bg, light-dark(#f6f6f8, #141417));
|
|
27
|
+
--x-s1: var(--scxml-surface, light-dark(#ffffff, #1c1c20));
|
|
28
|
+
--x-s2: var(--scxml-surface-2, light-dark(#f0f0f3, #242429));
|
|
29
|
+
--x-s3: var(--scxml-surface-3, light-dark(#e5e5ea, #2e2e34));
|
|
30
|
+
/* lines */
|
|
31
|
+
--x-b1: var(--scxml-border, light-dark(#e6e6eb, #2a2a30));
|
|
32
|
+
--x-b2: var(--scxml-border-2, light-dark(#d3d3da, #393940));
|
|
33
|
+
--x-strong: var(--scxml-border-strong, light-dark(#8b8b96, #6c6c77));
|
|
34
|
+
/* the one accent */
|
|
35
|
+
--x-accent: var(--scxml-accent, light-dark(#3d5bd9, #8fa3ff));
|
|
36
|
+
--x-accent-fg: var(--scxml-accent-text, light-dark(#2f49b8, #aebcff));
|
|
37
|
+
--x-accent-subtle: var(--scxml-accent-subtle, light-dark(#e9edfc, #252c4c));
|
|
38
|
+
--x-on-accent: var(--scxml-on-accent, light-dark(#ffffff, #10132b));
|
|
39
|
+
/* lifecycle */
|
|
40
|
+
--x-run: var(--scxml-running, light-dark(#26733a, #6fd48a));
|
|
41
|
+
--x-run-bg: var(--scxml-running-bg, light-dark(#e5f3e9, #1a3123));
|
|
42
|
+
--x-wait: var(--scxml-waiting, light-dark(#a8560a, #ffb46b));
|
|
43
|
+
--x-wait-bg: var(--scxml-waiting-bg, light-dark(#fdf0e1, #382815));
|
|
44
|
+
--x-done: var(--scxml-done, light-dark(#48566b, #a7b5c9));
|
|
45
|
+
--x-done-bg: var(--scxml-done-bg, light-dark(#e9edf3, #242b35));
|
|
46
|
+
--x-err: var(--scxml-error, light-dark(#c2332f, #ff8a84));
|
|
47
|
+
/* type */
|
|
48
|
+
--x-sans: var(--scxml-font-sans, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif);
|
|
49
|
+
--x-mono: var(--scxml-font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
|
50
|
+
--x-serif: var(--scxml-font-display, var(--x-sans));
|
|
51
|
+
--x-display-weight: var(--scxml-display-weight, 600);
|
|
52
|
+
/* shape and motion */
|
|
53
|
+
--x-r: var(--scxml-radius, 4px);
|
|
54
|
+
--x-dur: var(--scxml-duration, 140ms);
|
|
55
|
+
--x-row: var(--scxml-row-height, 30px);
|
|
56
|
+
color: var(--x-fg1); font: 400 13px/1.4 var(--x-sans);
|
|
57
|
+
}
|
|
58
|
+
* { box-sizing: border-box; }
|
|
59
|
+
button { font: inherit; color: inherit; }
|
|
60
|
+
:focus-visible { outline: 2px solid var(--x-accent); outline-offset: 1px; }
|
|
61
|
+
|
|
62
|
+
/* ── primitives shared by the elements ─────────────────── */
|
|
63
|
+
.search { display: flex; gap: 6px; padding: 0 12px 8px; flex: none; }
|
|
64
|
+
.search input[type="search"] {
|
|
65
|
+
flex: 1; min-width: 0; height: 28px; padding: 0 8px; font: 12px var(--x-mono); color: var(--x-fg1);
|
|
66
|
+
background: var(--x-s1); border: 1px solid var(--x-b2); border-radius: var(--x-r);
|
|
67
|
+
}
|
|
68
|
+
.search input[type="search"]:focus { border-color: var(--x-accent); }
|
|
69
|
+
.toggle { display: inline-flex; align-items: center; gap: 4px; font: 11px var(--x-sans); color: var(--x-fg3); white-space: nowrap; cursor: pointer; }
|
|
70
|
+
.badge { display: inline-block; font: 500 10px/1 var(--x-mono); letter-spacing: .06em; text-transform: uppercase; padding: 3px 5px; border-radius: var(--x-r); white-space: nowrap; }
|
|
71
|
+
.badge.run { color: var(--x-run); background: var(--x-run-bg); }
|
|
72
|
+
.badge.wait { color: var(--x-wait); background: var(--x-wait-bg); }
|
|
73
|
+
.badge.done { color: var(--x-done); background: var(--x-done-bg); }
|
|
74
|
+
.badge.muted { color: var(--x-fg3); background: var(--x-s2); }
|
|
75
|
+
.count { font: 500 11px var(--x-mono); color: var(--x-fg3); font-variant-numeric: tabular-nums; }
|
|
76
|
+
.chip {
|
|
77
|
+
display: inline-flex; align-items: center; gap: 4px; max-width: 100%; border: 1px solid var(--x-b2); background: var(--x-s1);
|
|
78
|
+
border-radius: 999px; padding: 2px 8px; font: 11.5px/1.4 var(--x-mono); color: var(--x-accent-fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
|
|
79
|
+
}
|
|
80
|
+
.chip:hover { border-color: var(--x-accent); background: var(--x-accent-subtle); }
|
|
81
|
+
.chip.muted { color: var(--x-fg3); cursor: default; }
|
|
82
|
+
.chip.muted:hover { border-color: var(--x-b2); background: var(--x-s1); }
|
|
83
|
+
.more { border: 0; background: none; padding: 2px 4px; font: 500 11px var(--x-mono); color: var(--x-fg3); cursor: pointer; }
|
|
84
|
+
.more:hover { color: var(--x-accent-fg); }
|
|
85
|
+
.kind { display: inline-grid; place-items: center; width: 16px; height: 16px; flex: none; font: 11px/1 var(--x-mono); color: var(--x-fg3); }
|
|
86
|
+
.empty { color: var(--x-fg3); padding: 16px 12px; font-style: italic; }
|
|
87
|
+
h2.title { font: var(--x-display-weight) 24px/1.15 var(--x-serif); letter-spacing: -.01em; margin: 6px 0 2px; }
|
|
88
|
+
.subtitle { color: var(--x-fg3); font: 12px var(--x-sans); margin: 0 0 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
|
|
89
|
+
.section-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; font: 500 10.5px var(--x-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--x-fg3); }
|
|
90
|
+
.section-title::after { content: ""; flex: 1; border-top: 1px solid var(--x-b1); }
|
|
91
|
+
|
|
92
|
+
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
|
|
93
|
+
`;
|
|
94
|
+
/**
|
|
95
|
+
* A constructable stylesheet, created on first use (so modules can be
|
|
96
|
+
* imported where there is no DOM) and shared by every shadow root that
|
|
97
|
+
* adopts it (browsers share the parsed sheet). One per realm: a sheet can
|
|
98
|
+
* only be adopted by documents of the realm whose `CSSStyleSheet` made it.
|
|
99
|
+
*/
|
|
100
|
+
export function lazySheet(css) {
|
|
101
|
+
const made = new WeakMap();
|
|
102
|
+
return () => {
|
|
103
|
+
let sheet = made.get(CSSStyleSheet);
|
|
104
|
+
if (!sheet) {
|
|
105
|
+
sheet = new CSSStyleSheet();
|
|
106
|
+
sheet.replaceSync(css);
|
|
107
|
+
made.set(CSSStyleSheet, sheet);
|
|
108
|
+
}
|
|
109
|
+
return sheet;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** The shared theme as one constructable stylesheet, adopted by every element's shadow root. */
|
|
113
|
+
export const themeSheet = lazySheet(THEME_CSS);
|
|
114
|
+
/**
|
|
115
|
+
* Colour pairs every theme must keep readable, as public token names:
|
|
116
|
+
* [foreground, background, minimum WCAG contrast]. Text needs 4.5:1 (AA);
|
|
117
|
+
* `--scxml-fg-faint` and `--scxml-border-strong` are for graphics only and need 3:1.
|
|
118
|
+
* Checked for the neutral theme by the package tests and for the Tinyactors
|
|
119
|
+
* mapping by the playground tests.
|
|
120
|
+
*/
|
|
121
|
+
export const CONTRAST_PAIRS = [
|
|
122
|
+
["--scxml-fg", "--scxml-bg", 4.5],
|
|
123
|
+
["--scxml-fg", "--scxml-surface", 4.5],
|
|
124
|
+
["--scxml-fg-muted", "--scxml-surface", 4.5],
|
|
125
|
+
["--scxml-fg-muted", "--scxml-surface-2", 4.5],
|
|
126
|
+
["--scxml-fg-subtle", "--scxml-bg", 4.5],
|
|
127
|
+
["--scxml-fg-subtle", "--scxml-surface", 4.5],
|
|
128
|
+
["--scxml-fg-subtle", "--scxml-surface-2", 4.5],
|
|
129
|
+
["--scxml-accent-text", "--scxml-bg", 4.5],
|
|
130
|
+
["--scxml-accent-text", "--scxml-surface", 4.5],
|
|
131
|
+
["--scxml-accent-text", "--scxml-accent-subtle", 4.5],
|
|
132
|
+
["--scxml-on-accent", "--scxml-accent", 4.5],
|
|
133
|
+
["--scxml-running", "--scxml-bg", 4.5],
|
|
134
|
+
["--scxml-running", "--scxml-surface", 4.5],
|
|
135
|
+
["--scxml-running", "--scxml-running-bg", 4.5],
|
|
136
|
+
["--scxml-waiting", "--scxml-surface", 4.5],
|
|
137
|
+
["--scxml-waiting", "--scxml-waiting-bg", 4.5],
|
|
138
|
+
["--scxml-done", "--scxml-done-bg", 4.5],
|
|
139
|
+
["--scxml-error", "--scxml-surface", 4.5],
|
|
140
|
+
["--scxml-fg-faint", "--scxml-surface", 3],
|
|
141
|
+
["--scxml-fg-faint", "--scxml-surface-2", 3],
|
|
142
|
+
["--scxml-border-strong", "--scxml-surface", 3],
|
|
143
|
+
];
|
|
144
|
+
/** The neutral theme's colours for one scheme, keyed by public token name (parsed from THEME_CSS). */
|
|
145
|
+
export function neutralPalette(scheme) {
|
|
146
|
+
const out = {};
|
|
147
|
+
for (const m of THEME_CSS.matchAll(/var\((--scxml-[\w-]+),\s*light-dark\((#[0-9a-f]{3,6}),\s*(#[0-9a-f]{3,6})\)\)/gi))
|
|
148
|
+
out[m[1]] = scheme === "light" ? m[2] : m[3];
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../src/ui/theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,gHAAgH;AAChH,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC;AAEhC,MAAM,CAAC,MAAM,SAAS,GAAG,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8ElC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,MAAM,IAAI,GAAG,IAAI,OAAO,EAAuC,CAAC;IAChE,OAAO,GAAG,EAAE;QACV,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;YAC5B,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QACjC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAwC;IACjE,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,CAAC;IACjC,CAAC,YAAY,EAAE,iBAAiB,EAAE,GAAG,CAAC;IACtC,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,GAAG,CAAC;IAC5C,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,GAAG,CAAC;IAC9C,CAAC,mBAAmB,EAAE,YAAY,EAAE,GAAG,CAAC;IACxC,CAAC,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,CAAC;IAC7C,CAAC,mBAAmB,EAAE,mBAAmB,EAAE,GAAG,CAAC;IAC/C,CAAC,qBAAqB,EAAE,YAAY,EAAE,GAAG,CAAC;IAC1C,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,GAAG,CAAC;IAC/C,CAAC,qBAAqB,EAAE,uBAAuB,EAAE,GAAG,CAAC;IACrD,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,GAAG,CAAC;IAC5C,CAAC,iBAAiB,EAAE,YAAY,EAAE,GAAG,CAAC;IACtC,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,GAAG,CAAC;IAC3C,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,GAAG,CAAC;IAC9C,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,GAAG,CAAC;IAC3C,CAAC,iBAAiB,EAAE,oBAAoB,EAAE,GAAG,CAAC;IAC9C,CAAC,cAAc,EAAE,iBAAiB,EAAE,GAAG,CAAC;IACxC,CAAC,eAAe,EAAE,iBAAiB,EAAE,GAAG,CAAC;IACzC,CAAC,kBAAkB,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAC1C,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAC5C,CAAC,uBAAuB,EAAE,iBAAiB,EAAE,CAAC,CAAC;CAChD,CAAC;AAEF,sGAAsG;AACtG,MAAM,UAAU,cAAc,CAAC,MAAwB;IACrD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,iFAAiF,CAAC;QACnH,GAAG,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC;IAClD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Shared theme for the scxmljs custom elements (`<scxml-explorer>`, and\n * `<scxml-view>` once it moves into the package).\n *\n * Theming contract: every visual decision reads a public `--scxml-*` custom\n * property (set them on `scxml-explorer`, or anywhere above it). Unset ones\n * fall back to the neutral default theme below, which follows the page's\n * light/dark preference via `light-dark()` and `color-scheme`. Internally the\n * shadow DOM uses short private aliases (`--x-*`); they are not part of the API.\n *\n * No fonts are loaded: the defaults are system font stacks.\n */\n/** One breakpoint for every element: at or below this width (px) the elements switch to their narrow layout. */\nexport const NARROW_WIDTH = 760;\n\nexport const THEME_CSS = /* css */ `\n:host {\n /* follow the page: while --scxml-color-scheme is unset this is invalid, so color-scheme\n inherits and light-dark() below matches the page. Set it to \"light dark\" to follow the OS. */\n color-scheme: var(--scxml-color-scheme);\n /* text */\n --x-fg1: var(--scxml-fg, light-dark(#1c1c21, #ececf1));\n --x-fg2: var(--scxml-fg-muted, light-dark(#484852, #bcbcc6));\n --x-fg3: var(--scxml-fg-subtle, light-dark(#6a6a75, #90909b));\n --x-fg4: var(--scxml-fg-faint, light-dark(#85858f, #777781)); /* graphics only (≥3:1), never text */\n /* surfaces */\n --x-bg: var(--scxml-bg, light-dark(#f6f6f8, #141417));\n --x-s1: var(--scxml-surface, light-dark(#ffffff, #1c1c20));\n --x-s2: var(--scxml-surface-2, light-dark(#f0f0f3, #242429));\n --x-s3: var(--scxml-surface-3, light-dark(#e5e5ea, #2e2e34));\n /* lines */\n --x-b1: var(--scxml-border, light-dark(#e6e6eb, #2a2a30));\n --x-b2: var(--scxml-border-2, light-dark(#d3d3da, #393940));\n --x-strong: var(--scxml-border-strong, light-dark(#8b8b96, #6c6c77));\n /* the one accent */\n --x-accent: var(--scxml-accent, light-dark(#3d5bd9, #8fa3ff));\n --x-accent-fg: var(--scxml-accent-text, light-dark(#2f49b8, #aebcff));\n --x-accent-subtle: var(--scxml-accent-subtle, light-dark(#e9edfc, #252c4c));\n --x-on-accent: var(--scxml-on-accent, light-dark(#ffffff, #10132b));\n /* lifecycle */\n --x-run: var(--scxml-running, light-dark(#26733a, #6fd48a));\n --x-run-bg: var(--scxml-running-bg, light-dark(#e5f3e9, #1a3123));\n --x-wait: var(--scxml-waiting, light-dark(#a8560a, #ffb46b));\n --x-wait-bg: var(--scxml-waiting-bg, light-dark(#fdf0e1, #382815));\n --x-done: var(--scxml-done, light-dark(#48566b, #a7b5c9));\n --x-done-bg: var(--scxml-done-bg, light-dark(#e9edf3, #242b35));\n --x-err: var(--scxml-error, light-dark(#c2332f, #ff8a84));\n /* type */\n --x-sans: var(--scxml-font-sans, system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif);\n --x-mono: var(--scxml-font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);\n --x-serif: var(--scxml-font-display, var(--x-sans));\n --x-display-weight: var(--scxml-display-weight, 600);\n /* shape and motion */\n --x-r: var(--scxml-radius, 4px);\n --x-dur: var(--scxml-duration, 140ms);\n --x-row: var(--scxml-row-height, 30px);\n color: var(--x-fg1); font: 400 13px/1.4 var(--x-sans);\n}\n* { box-sizing: border-box; }\nbutton { font: inherit; color: inherit; }\n:focus-visible { outline: 2px solid var(--x-accent); outline-offset: 1px; }\n\n/* ── primitives shared by the elements ─────────────────── */\n.search { display: flex; gap: 6px; padding: 0 12px 8px; flex: none; }\n.search input[type=\"search\"] {\n flex: 1; min-width: 0; height: 28px; padding: 0 8px; font: 12px var(--x-mono); color: var(--x-fg1);\n background: var(--x-s1); border: 1px solid var(--x-b2); border-radius: var(--x-r);\n}\n.search input[type=\"search\"]:focus { border-color: var(--x-accent); }\n.toggle { display: inline-flex; align-items: center; gap: 4px; font: 11px var(--x-sans); color: var(--x-fg3); white-space: nowrap; cursor: pointer; }\n.badge { display: inline-block; font: 500 10px/1 var(--x-mono); letter-spacing: .06em; text-transform: uppercase; padding: 3px 5px; border-radius: var(--x-r); white-space: nowrap; }\n.badge.run { color: var(--x-run); background: var(--x-run-bg); }\n.badge.wait { color: var(--x-wait); background: var(--x-wait-bg); }\n.badge.done { color: var(--x-done); background: var(--x-done-bg); }\n.badge.muted { color: var(--x-fg3); background: var(--x-s2); }\n.count { font: 500 11px var(--x-mono); color: var(--x-fg3); font-variant-numeric: tabular-nums; }\n.chip {\n display: inline-flex; align-items: center; gap: 4px; max-width: 100%; border: 1px solid var(--x-b2); background: var(--x-s1);\n border-radius: 999px; padding: 2px 8px; font: 11.5px/1.4 var(--x-mono); color: var(--x-accent-fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;\n}\n.chip:hover { border-color: var(--x-accent); background: var(--x-accent-subtle); }\n.chip.muted { color: var(--x-fg3); cursor: default; }\n.chip.muted:hover { border-color: var(--x-b2); background: var(--x-s1); }\n.more { border: 0; background: none; padding: 2px 4px; font: 500 11px var(--x-mono); color: var(--x-fg3); cursor: pointer; }\n.more:hover { color: var(--x-accent-fg); }\n.kind { display: inline-grid; place-items: center; width: 16px; height: 16px; flex: none; font: 11px/1 var(--x-mono); color: var(--x-fg3); }\n.empty { color: var(--x-fg3); padding: 16px 12px; font-style: italic; }\nh2.title { font: var(--x-display-weight) 24px/1.15 var(--x-serif); letter-spacing: -.01em; margin: 6px 0 2px; }\n.subtitle { color: var(--x-fg3); font: 12px var(--x-sans); margin: 0 0 14px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }\n.section-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; font: 500 10.5px var(--x-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--x-fg3); }\n.section-title::after { content: \"\"; flex: 1; border-top: 1px solid var(--x-b1); }\n\n@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }\n`;\n\n/**\n * A constructable stylesheet, created on first use (so modules can be\n * imported where there is no DOM) and shared by every shadow root that\n * adopts it (browsers share the parsed sheet). One per realm: a sheet can\n * only be adopted by documents of the realm whose `CSSStyleSheet` made it.\n */\nexport function lazySheet(css: string): () => CSSStyleSheet {\n const made = new WeakMap<typeof CSSStyleSheet, CSSStyleSheet>();\n return () => {\n let sheet = made.get(CSSStyleSheet);\n if (!sheet) {\n sheet = new CSSStyleSheet();\n sheet.replaceSync(css);\n made.set(CSSStyleSheet, sheet);\n }\n return sheet;\n };\n}\n\n/** The shared theme as one constructable stylesheet, adopted by every element's shadow root. */\nexport const themeSheet = lazySheet(THEME_CSS);\n\n/**\n * Colour pairs every theme must keep readable, as public token names:\n * [foreground, background, minimum WCAG contrast]. Text needs 4.5:1 (AA);\n * `--scxml-fg-faint` and `--scxml-border-strong` are for graphics only and need 3:1.\n * Checked for the neutral theme by the package tests and for the Tinyactors\n * mapping by the playground tests.\n */\nexport const CONTRAST_PAIRS: readonly [string, string, number][] = [\n [\"--scxml-fg\", \"--scxml-bg\", 4.5],\n [\"--scxml-fg\", \"--scxml-surface\", 4.5],\n [\"--scxml-fg-muted\", \"--scxml-surface\", 4.5],\n [\"--scxml-fg-muted\", \"--scxml-surface-2\", 4.5],\n [\"--scxml-fg-subtle\", \"--scxml-bg\", 4.5],\n [\"--scxml-fg-subtle\", \"--scxml-surface\", 4.5],\n [\"--scxml-fg-subtle\", \"--scxml-surface-2\", 4.5],\n [\"--scxml-accent-text\", \"--scxml-bg\", 4.5],\n [\"--scxml-accent-text\", \"--scxml-surface\", 4.5],\n [\"--scxml-accent-text\", \"--scxml-accent-subtle\", 4.5],\n [\"--scxml-on-accent\", \"--scxml-accent\", 4.5],\n [\"--scxml-running\", \"--scxml-bg\", 4.5],\n [\"--scxml-running\", \"--scxml-surface\", 4.5],\n [\"--scxml-running\", \"--scxml-running-bg\", 4.5],\n [\"--scxml-waiting\", \"--scxml-surface\", 4.5],\n [\"--scxml-waiting\", \"--scxml-waiting-bg\", 4.5],\n [\"--scxml-done\", \"--scxml-done-bg\", 4.5],\n [\"--scxml-error\", \"--scxml-surface\", 4.5],\n [\"--scxml-fg-faint\", \"--scxml-surface\", 3],\n [\"--scxml-fg-faint\", \"--scxml-surface-2\", 3],\n [\"--scxml-border-strong\", \"--scxml-surface\", 3],\n];\n\n/** The neutral theme's colours for one scheme, keyed by public token name (parsed from THEME_CSS). */\nexport function neutralPalette(scheme: \"light\" | \"dark\"): Record<string, string> {\n const out: Record<string, string> = {};\n for (const m of THEME_CSS.matchAll(/var\\((--scxml-[\\w-]+),\\s*light-dark\\((#[0-9a-f]{3,6}),\\s*(#[0-9a-f]{3,6})\\)\\)/gi))\n out[m[1]!] = scheme === \"light\" ? m[2]! : m[3]!;\n return out;\n}\n"]}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<scxml-view>` — a whole statechart at once, drop-in.
|
|
3
|
+
*
|
|
4
|
+
* <scxml-view src="traffic-light.scxml"></scxml-view>
|
|
5
|
+
*
|
|
6
|
+
* <scxml-view>
|
|
7
|
+
* <script type="application/scxml+xml"> <scxml …> … </scxml> </script>
|
|
8
|
+
* </scxml-view>
|
|
9
|
+
*
|
|
10
|
+
* Without any JavaScript it loads the chart, compiles and validates it, runs
|
|
11
|
+
* it and draws it: nested boxes, orthogonal transitions, the active
|
|
12
|
+
* configuration highlighted, transitions that just fired lit up. Transition
|
|
13
|
+
* labels are buttons that send their event.
|
|
14
|
+
*
|
|
15
|
+
* The data model: SANDBOXED by default (QuickJS, safe for any source), or the
|
|
16
|
+
* host's engine with the `trusted` attribute (no WebAssembly download — only
|
|
17
|
+
* for charts you trust). Both are loaded on demand with `import()`, so a page
|
|
18
|
+
* that hands the element its own `session` downloads neither.
|
|
19
|
+
*
|
|
20
|
+
* Attributes: `src`, `trusted`, `autostart` ("false" = draw without running),
|
|
21
|
+
* `interactive` ("false" = labels aren't buttons), `data` (JSON initial values
|
|
22
|
+
* for `<data>`), `direction` ("auto" | "right" | "down"), `max-states` (fold
|
|
23
|
+
* large charts beyond this many boxes, default 150), `announce`
|
|
24
|
+
* ("all" | "sends" | "off"), `fit` (scale down to the element's width),
|
|
25
|
+
* `warnings` ("off" hides the list of authoring warnings — see `model.warnings`).
|
|
26
|
+
*
|
|
27
|
+
* Properties: `session` (a host-created session; the element then creates,
|
|
28
|
+
* starts and disposes nothing), `options` (extra SessionOptions for sessions
|
|
29
|
+
* the element creates: I/O processors, invokers, loader…), `clock` (e.g. a
|
|
30
|
+
* PlaybackClock: shows play / pause / step controls), `strings`, `source`
|
|
31
|
+
* (SCXML text instead of `src`), `model`, and `reload()`.
|
|
32
|
+
*
|
|
33
|
+
* Events (bubbling, composed): `scxml-load` { session, model },
|
|
34
|
+
* `scxml-error` { message, problems?, error }, `scxml-send` { session, name }
|
|
35
|
+
* (cancelable; fired before a label sends its event).
|
|
36
|
+
*
|
|
37
|
+
* Styling: the shared `--scxml-*` tokens and these parts — `frame`, `canvas`,
|
|
38
|
+
* `state` (+ `atomic` `compound` `parallel` `parallel-region` `final`
|
|
39
|
+
* `history` `collapsed` `active`), `state-name`, `transition` / `edge-label`
|
|
40
|
+
* (+ `live` `fired`), `event`, `cond`, `internal`, `edge` (+ `live` `fired`),
|
|
41
|
+
* `initial`, `expand`, `collapse`, `notice`, `error`, `controls`, `play`,
|
|
42
|
+
* `step`, `speeds`, `clock`, `warnings`, `warning`.
|
|
43
|
+
*/
|
|
44
|
+
import { type Clock } from "../clock.js";
|
|
45
|
+
import { type Model } from "../model.js";
|
|
46
|
+
import { SCXMLSession, type SessionOptions } from "../session.js";
|
|
47
|
+
import { type Direction } from "./layout.js";
|
|
48
|
+
import { type ViewStrings } from "./strings.js";
|
|
49
|
+
/** `scxml-load`: the chart compiled and its session is ready; the element starts it right after (unless `autostart="false"`). */
|
|
50
|
+
export interface ViewLoadDetail {
|
|
51
|
+
/** the session shown (created by the element, or the one you set) */
|
|
52
|
+
session: SCXMLSession;
|
|
53
|
+
/** the compiled chart */
|
|
54
|
+
model: Model;
|
|
55
|
+
}
|
|
56
|
+
/** `scxml-error`: nothing to show, a fetch failed, or the chart is invalid. The element shows the problems too. */
|
|
57
|
+
export interface ViewErrorDetail {
|
|
58
|
+
/** a one-line summary */
|
|
59
|
+
message: string;
|
|
60
|
+
/** Validation problems, one per line of the chart that is wrong. */
|
|
61
|
+
problems?: string[];
|
|
62
|
+
/** the underlying error (an `SCXMLValidationError`, `SCXMLParseError`, `ViewSourceError`, fetch error…) */
|
|
63
|
+
error: unknown;
|
|
64
|
+
}
|
|
65
|
+
/** `scxml-send`: a transition label is about to send its event. Cancelable (`preventDefault()` stops it). */
|
|
66
|
+
export interface ViewSendDetail {
|
|
67
|
+
/** the session the event goes to */
|
|
68
|
+
session: SCXMLSession;
|
|
69
|
+
/** the event name */
|
|
70
|
+
name: string;
|
|
71
|
+
}
|
|
72
|
+
/** SessionOptions for sessions the element creates (its own clock comes from the `clock` property). */
|
|
73
|
+
export type ViewOptions = Omit<SessionOptions, "clock">;
|
|
74
|
+
/** Layout direction: layers left to right, top to bottom, or `auto` (down below the 760px breakpoint). */
|
|
75
|
+
export type ViewDirection = Direction | "auto";
|
|
76
|
+
/** What the live region announces: every step and sent event, only sent events, or nothing. */
|
|
77
|
+
export type ViewAnnounce = "all" | "sends" | "off";
|
|
78
|
+
declare const ElementBase: typeof HTMLElement;
|
|
79
|
+
/**
|
|
80
|
+
* `<scxml-view>`: a whole statechart, drawn and running, with no JavaScript
|
|
81
|
+
* of your own. Registered by importing `@tinyactors/scxmljs/view`.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```html
|
|
85
|
+
* <script type="module">import "@tinyactors/scxmljs/view";</script>
|
|
86
|
+
* <scxml-view src="traffic-light.scxml"></scxml-view>
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare class ScxmlView extends ElementBase {
|
|
90
|
+
#private;
|
|
91
|
+
/** Attributes the element reacts to. */
|
|
92
|
+
static observedAttributes: string[];
|
|
93
|
+
constructor();
|
|
94
|
+
/** The chart's URL (the `src` attribute). Relative `<script src>` / `<data src>` / `<invoke src>` resolve against it. */
|
|
95
|
+
get src(): string;
|
|
96
|
+
/** Sets the `src` attribute (loads the chart). */
|
|
97
|
+
set src(v: string);
|
|
98
|
+
/** Run the chart in the host's JS engine instead of the QuickJS sandbox (no WebAssembly; trusted charts only). */
|
|
99
|
+
get trusted(): boolean;
|
|
100
|
+
/** Toggles the `trusted` attribute (reloads). */
|
|
101
|
+
set trusted(v: boolean);
|
|
102
|
+
/** Start the session the element creates (default true; `autostart="false"` only draws the chart). */
|
|
103
|
+
get autostart(): boolean;
|
|
104
|
+
/** Sets the `autostart` attribute. */
|
|
105
|
+
set autostart(v: boolean);
|
|
106
|
+
/** Transition labels are buttons that send their event (default true). */
|
|
107
|
+
get interactive(): boolean;
|
|
108
|
+
/** Sets the `interactive` attribute. */
|
|
109
|
+
set interactive(v: boolean);
|
|
110
|
+
/** "right" (layers left to right), "down", or "auto" (down when narrower than the shared breakpoint). */
|
|
111
|
+
get direction(): ViewDirection;
|
|
112
|
+
/** Sets the `direction` attribute (re-lays out). */
|
|
113
|
+
set direction(v: ViewDirection);
|
|
114
|
+
/** Fold the largest compound states until at most this many boxes are drawn (default 150). */
|
|
115
|
+
get maxStates(): number;
|
|
116
|
+
/** Sets the `max-states` attribute (folds again). */
|
|
117
|
+
set maxStates(n: number);
|
|
118
|
+
/** What the polite live region announces: "all" (steps and sent events, default), "sends" or "off". */
|
|
119
|
+
get announce(): ViewAnnounce;
|
|
120
|
+
/** Sets the `announce` attribute. */
|
|
121
|
+
set announce(v: ViewAnnounce);
|
|
122
|
+
/** "show" (default) lists the chart's authoring warnings (`model.warnings`) above the diagram; "off" hides them. */
|
|
123
|
+
get warnings(): "show" | "off";
|
|
124
|
+
/** Sets the `warnings` attribute. */
|
|
125
|
+
set warnings(v: "show" | "off");
|
|
126
|
+
/** Scale the diagram down to the element's width. */
|
|
127
|
+
get fit(): boolean;
|
|
128
|
+
/** Toggles the `fit` attribute. */
|
|
129
|
+
set fit(v: boolean);
|
|
130
|
+
/** The session shown. Setting one hands the element a host-owned session (it won't be started or disposed). */
|
|
131
|
+
get session(): SCXMLSession | undefined;
|
|
132
|
+
/** Show your own session (the element never starts or disposes it); `undefined` goes back to `src` / inline source. */
|
|
133
|
+
set session(s: SCXMLSession | undefined);
|
|
134
|
+
/** The compiled chart shown. */
|
|
135
|
+
get model(): Model | undefined;
|
|
136
|
+
/** Extra options for sessions the element creates (I/O processors, invokers, loader, data model…). Setting them reloads. */
|
|
137
|
+
get options(): ViewOptions;
|
|
138
|
+
/** Options for sessions the element creates; reloads unless a host session is shown. */
|
|
139
|
+
set options(o: ViewOptions);
|
|
140
|
+
/** The clock for sessions the element creates; a PlaybackClock adds play / pause / step controls. Setting it reloads. */
|
|
141
|
+
get clock(): Clock | undefined;
|
|
142
|
+
/** The clock for sessions the element creates; reloads unless a host session is shown. */
|
|
143
|
+
set clock(c: Clock | undefined);
|
|
144
|
+
/** SCXML text to show instead of `src` / inline source. */
|
|
145
|
+
get source(): string | undefined;
|
|
146
|
+
/** Show this SCXML text (reloads). */
|
|
147
|
+
set source(text: string | undefined);
|
|
148
|
+
/** Translations: a partial override of the English defaults. */
|
|
149
|
+
get strings(): ViewStrings;
|
|
150
|
+
/** Translate: a partial object; unset keys keep their English default. */
|
|
151
|
+
set strings(s: Partial<ViewStrings>);
|
|
152
|
+
/** Load the chart again (re-reading `src` / inline source) and start a fresh session. */
|
|
153
|
+
reload(): void;
|
|
154
|
+
/** Custom-element lifecycle (called by the browser): loads the chart when first connected. */
|
|
155
|
+
connectedCallback(): void;
|
|
156
|
+
/** Custom-element lifecycle (called by the browser): disposes an element-owned session unless the element was only moved. */
|
|
157
|
+
disconnectedCallback(): void;
|
|
158
|
+
/** Custom-element lifecycle (called by the browser) for the observed attributes. */
|
|
159
|
+
attributeChangedCallback(name: string, old: string | null, value: string | null): void;
|
|
160
|
+
}
|
|
161
|
+
/** Thrown when the element has nothing to show or its attributes are malformed. */
|
|
162
|
+
export declare class ViewSourceError extends Error {
|
|
163
|
+
/** Always `"SCXML_VIEW_SOURCE"`. */
|
|
164
|
+
readonly code = "SCXML_VIEW_SOURCE";
|
|
165
|
+
constructor(message: string);
|
|
166
|
+
}
|
|
167
|
+
declare global {
|
|
168
|
+
interface HTMLElementTagNameMap {
|
|
169
|
+
"scxml-view": ScxmlView;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export {};
|