@elastics-ai/host-kit 0.0.0-stage → 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 ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2026 Elastics. All rights reserved.
2
+
3
+ This package is proprietary software. It is not open source.
4
+
5
+ You may use this package only to display data from the Elastics service in a
6
+ page that uses the Elastics service. Any other use, and any copy,
7
+ modification or distribution of this package outside that purpose, needs
8
+ written permission from Elastics.
9
+
10
+ THE PACKAGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11
+ IMPLIED. IN NO EVENT SHALL ELASTICS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
12
+ LIABILITY ARISING FROM THE PACKAGE OR ITS USE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # @elastics-ai/host-kit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Elastics design tokens and eight custom elements for a page that a host builds and publishes, such as a Claude artifact or a ChatGPT Site. The Elastics MCP tool `get_style_kit` tells the model to load these files.
4
+
5
+ ```html
6
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@elastics-ai/host-kit@0.1.0/host-kit.css" integrity="sha384-…" crossorigin="anonymous">
7
+ <script src="https://cdn.jsdelivr.net/npm/@elastics-ai/host-kit@0.1.0/host-kit.js" integrity="sha384-…" crossorigin="anonymous"></script>
8
+
9
+ <ex-card heading="Will BTC close above $100k?" state="live">
10
+ <ex-stat label="Yes price" value="62¢" change="+3¢" trend="up"></ex-stat>
11
+ <ex-book></ex-book>
12
+ </ex-card>
13
+ <script>
14
+ document.querySelector('ex-book').bids = [['62', '150'], ['61', '90']];
15
+ </script>
16
+ ```
17
+
18
+ Take the full tags, with their `integrity` values, from `get_style_kit` or from `HOST_KIT_TAGS` in `src/index.ts`. The browser then refuses a file whose bytes differ from the ones this repository built.
19
+
20
+ | Element | Input |
21
+ |---|---|
22
+ | `ex-card` | `heading`, `state`, `label`; children go in the card |
23
+ | `ex-stat` | `label`, `value`, `change`, `trend` (`up` or `down`) |
24
+ | `ex-badge` | `state` (`live`, `stale`, `failed`, `off`), `label` |
25
+ | `ex-table` | `.columns = [{key, label, numeric}]`, `.rows = [{...}]` |
26
+ | `ex-book` | `.asks`, `.bids` as `[[price, size]]` or `[{price, size}]` |
27
+ | `ex-news-row` | `headline`, `url` (linked only when https), `source`, `time` |
28
+ | `ex-notification-row` | `headline`, `body`, `time`, `read` |
29
+ | `ex-run-row` | `status` (`running`, `failed`, other), `action`, `time` |
30
+
31
+ Every element writes values with `textContent`, so markup in a feed value shows as text. The colours follow `prefers-color-scheme`, and a `.light` or `.dark` class on any ancestor pins one scheme.
32
+
33
+ A Claude artifact loads stylesheets only from Google Fonts. There, put the `css` from `get_style_kit` (the same rules as `host-kit.css`) in a `<style>` tag and load only the script.
34
+
35
+ `host-kit.js` has no import or export, so it loads as a classic script or as a module, and from a `file://` page. Open `demo.html` to see every element in both schemes.
36
+
37
+ ## Change the kit
38
+
39
+ `host-kit.css` and `src/tokens.generated.ts` are generated from `packages/ui/src/styles/globals.css` and `src/styles.ts`. `src/sri.generated.json` holds the sha384 of `host-kit.css` and `host-kit.js`. After a change to any of them, run `pnpm --filter @elastics-ai/host-kit gen`. A test fails while a generated file is out of date. A published version never changes, so a change to a published file also needs a version bump.
40
+
41
+ ## License
42
+
43
+ Proprietary. Copyright Elastics, all rights reserved. See `LICENSE`.
package/host-kit.css ADDED
@@ -0,0 +1,4 @@
1
+ /* @elastics-ai/host-kit. Generated by scripts/gen.ts. Do not edit. */
2
+ :root{color-scheme:light dark;--background:light-dark(#fafafa,#0c0c0e);--surface:light-dark(#efeff0,#161618);--foreground:light-dark(#161618,#efeff0);--muted-foreground:light-dark(#58585d,#9a9a9e);--card:light-dark(#e7e7e9,#1f1f23);--card-foreground:light-dark(#161618,#efeff0);--border:light-dark(#e7e7e9,#1f1f23);--accent:light-dark(#ebebed,#1b1b1d);--accent-foreground:light-dark(#161618,#efeff0);--primary:light-dark(#0c0c0e,#fafafa);--primary-foreground:light-dark(#fafafa,#0c0c0e);--ring:#6e6e73;--positive:light-dark(#cdf1df,#002b20);--positive-foreground:light-dark(#09684b,#1ebf88);--negative:light-dark(#ffdcdf,#3a161e);--negative-foreground:light-dark(#b81f43,#fe6b80);--caution:light-dark(#fff0cc,#3b290d);--caution-foreground:light-dark(#8a5300,#fdae31);--info:light-dark(#f1e4ff,#3b126f);--info-foreground:light-dark(#7d2be6,#ae6cf5);--chart-cat-1:light-dark(#0a66fb,#4f84fe);--chart-cat-2:light-dark(#b37903,#b47d06);--chart-cat-3:light-dark(#f416aa,#ed16ce);--chart-cat-4:light-dark(#008ab3,#0b7699);--chart-cat-5:#697005;--chart-positive:#0b9d6f;--chart-negative:#fe546d;--radius-sm:4px;--radius-md:6px;--radius-lg:8px;--radius-3xl:16px;--text-xs:0.75rem;--text-sm:0.8125rem;--text-base:0.875rem;--text-2xl:1.5rem;--font-sans:Geist, ui-sans-serif, system-ui, sans-serif;--font-mono:'Geist Mono', ui-monospace, 'SF Mono', monospace}.light{color-scheme:light}.dark{color-scheme:dark}
3
+ body{margin:0;background:var(--background);color:var(--foreground);font:400 var(--text-base)/1.5 var(--font-sans)}.ex-num{font-variant-numeric:tabular-nums}.ex-muted{color:var(--muted-foreground);font-size:var(--text-xs)}.ex-card{background:var(--card);color:var(--card-foreground);border-radius:var(--radius-3xl);padding:16px;display:flex;flex-direction:column;gap:12px;overflow:hidden}.ex-card>h2{margin:0;font-size:var(--text-sm);font-weight:500;display:flex;justify-content:space-between;align-items:center;gap:8px}.ex-stat{display:flex;flex-direction:column;gap:4px}.ex-stat b{font-size:var(--text-2xl);font-weight:500;font-variant-numeric:tabular-nums}.ex-up{color:var(--positive-foreground)}.ex-down{color:var(--negative-foreground)}.ex-table{width:100%;border-collapse:collapse;font-size:var(--text-sm)}.ex-table th{text-align:left;font-weight:500;color:var(--muted-foreground)}.ex-table th,.ex-table td{padding:6px 8px;border-bottom:1px solid var(--border)}.ex-table td.n,.ex-table th.n{text-align:right;font-variant-numeric:tabular-nums}.ex-lvl{position:relative;display:flex;justify-content:space-between;padding:2px 8px;font:var(--text-xs)/1.6 var(--font-mono)}.ex-lvl>i{position:absolute;inset:0 auto 0 0;border-radius:var(--radius-md);background:var(--positive)}.ex-lvl.ask>i{background:var(--negative)}.ex-lvl>span{position:relative}.ex-lvl.bid>i+span{color:var(--positive-foreground)}.ex-lvl.ask>i+span{color:var(--negative-foreground)}.ex-badge{display:inline-flex;align-items:center;gap:4px;font-size:var(--text-xs);font-weight:500;color:var(--muted-foreground)}.ex-badge::before{content:"";width:6px;height:6px;border-radius:9999px;background:currentColor}.ex-badge[data-state=live]{color:var(--positive-foreground)}.ex-badge[data-state=stale]{color:var(--caution-foreground)}.ex-badge[data-state=failed]{color:var(--negative-foreground)}.ex-row{display:flex;gap:12px;align-items:flex-start;padding:8px 0;border-bottom:1px solid var(--border)}.ex-row>div{flex:1;min-width:0}.ex-row p{margin:0;overflow:hidden;text-overflow:ellipsis}.ex-row a{color:inherit;text-decoration:none}.ex-row a:hover{text-decoration:underline}.ex-dot{width:8px;height:8px;margin-top:6px;border-radius:9999px;background:var(--info-foreground);flex:none}.ex-dot[data-read]{background:transparent}.ex-btn{background:var(--primary);color:var(--primary-foreground);border:0;border-radius:var(--radius-lg);padding:8px 14px;font:500 var(--text-sm) var(--font-sans);cursor:pointer}:focus-visible{outline:2px solid var(--ring);outline-offset:2px}
4
+ ex-stat,ex-table,ex-book,ex-news-row,ex-notification-row,ex-run-row{display:block}
package/host-kit.js ADDED
@@ -0,0 +1,315 @@
1
+ // @elastics-ai/host-kit: eight custom elements for a page that Claude or
2
+ // ChatGPT publishes, styled by host-kit.css. Values go in through attributes
3
+ // or properties and come out through textContent only: no element parses
4
+ // HTML, so a market title or news headline from a feed renders as text.
5
+ //
6
+ // The file has no import or export, so it loads as <script src> as well as
7
+ // type="module". Chrome refuses module scripts from a file:// page.
8
+ (() => {
9
+ /** @typedef {{ key: string, label: string, numeric?: boolean }} Column */
10
+ /** @typedef {{ price: number | string, size: number | string }} Level */
11
+ /** @typedef {Level | [number | string, number | string]} LevelIn */
12
+
13
+ const STATES = {
14
+ live: 'Live',
15
+ stale: 'Stale',
16
+ failed: 'Failed',
17
+ off: 'Off',
18
+ };
19
+
20
+ /**
21
+ * @param {string} tag
22
+ * @param {string} [className]
23
+ * @param {unknown} [text]
24
+ */
25
+ function node(tag, className, text) {
26
+ const el = document.createElement(tag);
27
+ if (className) el.className = className;
28
+ if (text !== undefined && text !== null) el.textContent = String(text);
29
+ return el;
30
+ }
31
+
32
+ /** @param {string | null} state @param {string | null} [label] */
33
+ function badge(state, label) {
34
+ const known = state !== null && Object.hasOwn(STATES, state);
35
+ const key = known ? /** @type {keyof typeof STATES} */ (state) : 'off';
36
+ const el = node('span', 'ex-badge', label || STATES[key]);
37
+ el.dataset.state = key;
38
+ return el;
39
+ }
40
+
41
+ /** @param {string | null} value */
42
+ function httpsUrl(value) {
43
+ if (!value) return null;
44
+ try {
45
+ const url = new URL(value);
46
+ return url.protocol === 'https:' ? url.href : null;
47
+ } catch {
48
+ return null;
49
+ }
50
+ }
51
+
52
+ /** @param {unknown} value */
53
+ function list(value) {
54
+ return Array.isArray(value) ? value : [];
55
+ }
56
+
57
+ // Only the row's own keys: a column keyed "constructor" must not print
58
+ // Object's source.
59
+ /** @param {unknown} row @param {string} key */
60
+ function cell(row, key) {
61
+ return row && typeof row === 'object' && Object.hasOwn(row, key)
62
+ ? (Reflect.get(row, key) ?? '')
63
+ : '';
64
+ }
65
+
66
+ // Levels come as {price, size} or as the feeds' [price, size] pairs.
67
+ /** @param {unknown} value @returns {Level[]} */
68
+ function levels(value) {
69
+ return list(value).map((l) =>
70
+ Array.isArray(l) ? { price: l[0], size: l[1] } : l
71
+ );
72
+ }
73
+
74
+ class KitElement extends HTMLElement {
75
+ /** Properties that a page can set before this script defines the tag. */
76
+ static props = /** @type {string[]} */ ([]);
77
+
78
+ connectedCallback() {
79
+ for (const p of /** @type {typeof KitElement} */ (this.constructor).props)
80
+ if (Object.hasOwn(this, p)) {
81
+ const value = Reflect.get(this, p);
82
+ Reflect.deleteProperty(this, p);
83
+ Reflect.set(this, p, value);
84
+ }
85
+ this.render();
86
+ }
87
+
88
+ attributeChangedCallback() {
89
+ if (this.isConnected) this.render();
90
+ }
91
+
92
+ /** @param {string} name */
93
+ text(name) {
94
+ return this.getAttribute(name) ?? '';
95
+ }
96
+
97
+ render() {}
98
+ }
99
+
100
+ // The card is the container itself: it keeps its children and owns one
101
+ // header as its first child. A clone of a rendered card brings its header
102
+ // along, so the card takes that one instead of adding a second.
103
+ class ExCard extends KitElement {
104
+ static observedAttributes = ['heading', 'state', 'label'];
105
+ /** @type {Element | null} */
106
+ head = null;
107
+
108
+ render() {
109
+ this.classList.add('ex-card');
110
+ const first = this.firstElementChild;
111
+ this.head ??= first?.tagName === 'H2' ? first : node('h2');
112
+ const parts = [node('span', '', this.text('heading'))];
113
+ if (this.hasAttribute('state'))
114
+ parts.push(
115
+ badge(this.getAttribute('state'), this.getAttribute('label'))
116
+ );
117
+ this.head.replaceChildren(...parts);
118
+ if (this.firstChild !== this.head) this.prepend(this.head);
119
+ }
120
+ }
121
+
122
+ class ExBadge extends KitElement {
123
+ static observedAttributes = ['state', 'label'];
124
+
125
+ render() {
126
+ this.replaceChildren(
127
+ badge(this.getAttribute('state'), this.getAttribute('label'))
128
+ );
129
+ }
130
+ }
131
+
132
+ class ExStat extends KitElement {
133
+ static observedAttributes = ['label', 'value', 'change', 'trend'];
134
+
135
+ render() {
136
+ const box = node('div', 'ex-stat');
137
+ box.append(
138
+ node('span', 'ex-muted', this.text('label')),
139
+ node('b', '', this.text('value'))
140
+ );
141
+ if (this.hasAttribute('change')) {
142
+ const trend = this.getAttribute('trend');
143
+ const tone =
144
+ trend === 'up' ? ' ex-up' : trend === 'down' ? ' ex-down' : '';
145
+ box.append(node('span', `ex-num${tone}`, this.text('change')));
146
+ }
147
+ this.replaceChildren(box);
148
+ }
149
+ }
150
+
151
+ class ExTable extends KitElement {
152
+ static props = ['columns', 'rows'];
153
+ /** @type {Column[]} */
154
+ #columns = [];
155
+ /** @type {Record<string, unknown>[]} */
156
+ #rows = [];
157
+
158
+ get columns() {
159
+ return this.#columns;
160
+ }
161
+ set columns(value) {
162
+ this.#columns = list(value).filter((c) => c && typeof c === 'object');
163
+ this.attributeChangedCallback();
164
+ }
165
+ get rows() {
166
+ return this.#rows;
167
+ }
168
+ set rows(value) {
169
+ this.#rows = list(value);
170
+ this.attributeChangedCallback();
171
+ }
172
+
173
+ render() {
174
+ const head = node('tr');
175
+ for (const c of this.#columns)
176
+ head.append(node('th', c.numeric ? 'n' : '', c.label));
177
+ const body = node('tbody');
178
+ for (const row of this.#rows) {
179
+ const tr = node('tr');
180
+ for (const c of this.#columns)
181
+ tr.append(node('td', c.numeric ? 'n' : '', cell(row, c.key)));
182
+ body.append(tr);
183
+ }
184
+ const thead = node('thead');
185
+ thead.append(head);
186
+ const table = node('table', 'ex-table');
187
+ table.append(thead, body);
188
+ this.replaceChildren(table);
189
+ }
190
+ }
191
+
192
+ // Asks above with the best ask last, bids below with the best bid first,
193
+ // as in the product's book. Bar width is size over the largest size shown.
194
+ class ExBook extends KitElement {
195
+ static props = ['asks', 'bids'];
196
+ /** @type {Level[]} */
197
+ #asks = [];
198
+ /** @type {Level[]} */
199
+ #bids = [];
200
+
201
+ get asks() {
202
+ return this.#asks;
203
+ }
204
+ set asks(value) {
205
+ this.#asks = levels(value);
206
+ this.attributeChangedCallback();
207
+ }
208
+ get bids() {
209
+ return this.#bids;
210
+ }
211
+ set bids(value) {
212
+ this.#bids = levels(value);
213
+ this.attributeChangedCallback();
214
+ }
215
+
216
+ render() {
217
+ /** @param {Level} l */
218
+ const size = (l) => {
219
+ const n = Number(l?.size);
220
+ return Number.isFinite(n) && n > 0 ? n : 0;
221
+ };
222
+ /** @param {Level} a @param {Level} b */
223
+ const byPriceDesc = (a, b) => Number(b?.price) - Number(a?.price);
224
+ const asks = [...this.#asks].sort(byPriceDesc);
225
+ const bids = [...this.#bids].sort(byPriceDesc);
226
+ const largest = Math.max(0, ...asks.map(size), ...bids.map(size));
227
+ /** @param {Level} l @param {'ask' | 'bid'} side */
228
+ const row = (l, side) => {
229
+ const bar = node('i');
230
+ bar.style.width = `${largest ? (size(l) / largest) * 100 : 0}%`;
231
+ const el = node('div', `ex-lvl ${side}`);
232
+ el.append(bar, node('span', '', l?.price), node('span', '', l?.size));
233
+ return el;
234
+ };
235
+ this.replaceChildren(
236
+ ...asks.map((l) => row(l, 'ask')),
237
+ ...bids.map((l) => row(l, 'bid'))
238
+ );
239
+ }
240
+ }
241
+
242
+ // A headline links out only when its URL is https. The attribute is
243
+ // headline, not title: title would also show as the row's tooltip.
244
+ class ExNewsRow extends KitElement {
245
+ static observedAttributes = ['headline', 'url', 'source', 'time'];
246
+
247
+ render() {
248
+ const href = httpsUrl(this.getAttribute('url'));
249
+ const title = node(href ? 'a' : 'span', '', this.text('headline'));
250
+ if (title instanceof HTMLAnchorElement && href) {
251
+ title.href = href;
252
+ title.target = '_blank';
253
+ title.rel = 'noopener noreferrer';
254
+ }
255
+ const p = node('p');
256
+ p.append(title);
257
+ const meta = [this.text('source'), this.text('time')].filter(Boolean);
258
+ const box = node('div');
259
+ box.append(p, node('span', 'ex-muted', meta.join(' · ')));
260
+ const rowEl = node('div', 'ex-row');
261
+ rowEl.append(box);
262
+ this.replaceChildren(rowEl);
263
+ }
264
+ }
265
+
266
+ class ExNotificationRow extends KitElement {
267
+ static observedAttributes = ['headline', 'body', 'time', 'read'];
268
+
269
+ render() {
270
+ const dot = node('span', 'ex-dot');
271
+ if (this.hasAttribute('read')) dot.dataset.read = '';
272
+ const box = node('div');
273
+ box.append(
274
+ node('p', '', this.text('headline')),
275
+ node('p', 'ex-muted', this.text('body'))
276
+ );
277
+ const rowEl = node('div', 'ex-row');
278
+ rowEl.append(dot, box, node('span', 'ex-muted', this.text('time')));
279
+ this.replaceChildren(rowEl);
280
+ }
281
+ }
282
+
283
+ // Run status: running shows as live, failed as failed, any other as off.
284
+ class ExRunRow extends KitElement {
285
+ static observedAttributes = ['status', 'action', 'time'];
286
+
287
+ render() {
288
+ const status = this.text('status');
289
+ const state =
290
+ status === 'running' ? 'live' : status === 'failed' ? 'failed' : 'off';
291
+ const box = node('div');
292
+ box.append(
293
+ node('p', '', this.text('action')),
294
+ node('span', 'ex-muted', this.text('time'))
295
+ );
296
+ const rowEl = node('div', 'ex-row');
297
+ rowEl.append(badge(state, status), box);
298
+ this.replaceChildren(rowEl);
299
+ }
300
+ }
301
+
302
+ /** @type {[string, CustomElementConstructor][]} */
303
+ const elements = [
304
+ ['ex-card', ExCard],
305
+ ['ex-badge', ExBadge],
306
+ ['ex-stat', ExStat],
307
+ ['ex-table', ExTable],
308
+ ['ex-book', ExBook],
309
+ ['ex-news-row', ExNewsRow],
310
+ ['ex-notification-row', ExNotificationRow],
311
+ ['ex-run-row', ExRunRow],
312
+ ];
313
+ for (const [name, element] of elements)
314
+ if (!customElements.get(name)) customElements.define(name, element);
315
+ })();
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@elastics-ai/host-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Elastics design tokens and custom elements for pages that Claude or ChatGPT publish.",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "sideEffects": true,
8
+ "main": "./host-kit.js",
9
+ "types": null,
10
+ "exports": {
11
+ ".": "./host-kit.js",
12
+ "./host-kit.js": "./host-kit.js",
13
+ "./host-kit.css": "./host-kit.css"
14
+ },
15
+ "files": [
16
+ "host-kit.js",
17
+ "host-kit.css",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "devDependencies": {
25
+ "@biomejs/biome": "2.5.9",
26
+ "@types/jsdom": "20.0.1",
27
+ "@types/node": "26.2.0",
28
+ "jsdom": "20.0.3",
29
+ "typescript": "6.0.3"
30
+ },
31
+ "scripts": {
32
+ "gen": "node scripts/gen.ts",
33
+ "typecheck": "tsc --noEmit",
34
+ "lint": "biome check .",
35
+ "lint:fix": "biome check . --write --unsafe",
36
+ "test": "node --test"
37
+ }
6
38
  }