@glasshome/widget-sdk 1.1.0 → 1.1.1

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/dist/index.js CHANGED
@@ -1340,7 +1340,7 @@ function mn(e) {
1340
1340
  function vn() {
1341
1341
  return document.documentElement.classList.contains("dark");
1342
1342
  }
1343
- const Lt = "1.1.0", Ut = {
1343
+ const Lt = "1.1.1", Ut = {
1344
1344
  version: Lt
1345
1345
  }, wn = Ut.version;
1346
1346
  export {
@@ -1,26 +1,26 @@
1
- import { createHash as _ } from "node:crypto";
2
- import { existsSync as l, rmSync as R, mkdirSync as D, readdirSync as I, statSync as k, readFileSync as w, writeFileSync as p } from "node:fs";
1
+ import { createHash as R } from "node:crypto";
2
+ import { existsSync as l, rmSync as T, mkdirSync as D, readdirSync as I, statSync as P, readFileSync as g, writeFileSync as w } from "node:fs";
3
3
  import { createRequire as F } from "node:module";
4
- import { resolve as a, join as d, dirname as y, sep as x } from "node:path";
5
- import { fileURLToPath as T } from "node:url";
6
- import { widgetManifestSchema as U, formatSchemaError as C } from "@glasshome/widget-contract";
7
- import H from "@tailwindcss/vite";
4
+ import { resolve as c, join as u, dirname as y, sep as x } from "node:path";
5
+ import { fileURLToPath as H } from "node:url";
6
+ import { widgetManifestSchema as U, formatSchemaError as A } from "@glasshome/widget-contract";
7
+ import C from "@tailwindcss/vite";
8
8
  function L(e) {
9
9
  const t = JSON.stringify(e, Object.keys(e).sort());
10
- return _("sha256").update(t).digest("hex").slice(0, 16);
10
+ return R("sha256").update(t).digest("hex").slice(0, 16);
11
11
  }
12
- const J = "virtual:glasshome-widget", P = "\0virtual:glasshome-widget", A = "/@glasshome/preview";
13
- function h(e) {
12
+ const V = "virtual:glasshome-widget", E = "\0virtual:glasshome-widget", B = "/@glasshome/preview";
13
+ function p(e) {
14
14
  return x === "\\" ? e.split(x).join("/") : e;
15
15
  }
16
16
  function S() {
17
- const e = T(import.meta.url);
18
- return a(y(e), "../../preview");
17
+ const e = H(import.meta.url);
18
+ return c(y(e), "../../preview");
19
19
  }
20
- function $(e) {
20
+ function k(e) {
21
21
  return e === "solid-js" || e.startsWith("solid-js/") || e === "@glasshome/widget-sdk" || e.startsWith("@glasshome/widget-sdk/") || e === "@glasshome/ui" || e.startsWith("@glasshome/ui/");
22
22
  }
23
- function j() {
23
+ function O() {
24
24
  return {
25
25
  name: "glasshome-widget:sync-layer-guard",
26
26
  apply: "build",
@@ -33,35 +33,57 @@ function j() {
33
33
  }
34
34
  };
35
35
  }
36
- const B = "node_modules/.cache/glasshome-widgets";
37
- function E(e) {
36
+ const J = "node_modules/.cache/glasshome-widgets";
37
+ function $(e) {
38
38
  try {
39
- return F(d(process.cwd(), "package.json")).resolve(e);
39
+ return F(u(process.cwd(), "package.json")).resolve(e);
40
40
  } catch {
41
41
  return null;
42
42
  }
43
43
  }
44
- function O(e, t, n) {
45
- const o = a(e, B);
46
- D(o, { recursive: !0 });
47
- const i = E("@glasshome/ui/styles");
48
- if (!i)
44
+ const G = [
45
+ "--radius",
46
+ "--background",
47
+ "--foreground",
48
+ "--card",
49
+ "--primary",
50
+ "--border",
51
+ "--muted",
52
+ "--accent"
53
+ ];
54
+ function j(e, t) {
55
+ const i = u(e, `${t}.css`);
56
+ if (!l(i)) return;
57
+ const n = g(i, "utf-8");
58
+ for (const o of n.matchAll(/:host[^{]*\{([^}]*)\}/g)) {
59
+ const s = o[1] ?? "", r = G.find((a) => s.includes(`${a}:`));
60
+ if (r)
61
+ throw new Error(
62
+ `[glasshome-widget] "${t}.css" defines theme variable "${r}" on :host. Theme variables must inherit from the document so widgets follow the household theme — never re-scope them into the widget's shadow root.`
63
+ );
64
+ }
65
+ }
66
+ function N(e, t, i) {
67
+ const n = c(e, J);
68
+ D(n, { recursive: !0 });
69
+ const o = $("@glasshome/ui/styles");
70
+ if (!o)
49
71
  throw new Error(
50
72
  "[widget-sdk] @glasshome/ui is required to build widgets (it provides the theme every GlassHome widget ships with). Add it to your widget's dependencies."
51
73
  );
52
- const s = a(y(i), "../.."), r = E("@glasshome/widget-sdk/tailwind-sources"), c = r ? y(r) : null, g = [
53
- d(s, "src"),
54
- d(s, "dist"),
55
- ...c ? [d(c, "src"), d(c, "dist")] : [],
56
- y(n)
57
- ].filter((u) => l(u)), m = a(o, `${t}.tailwind.css`);
58
- p(
74
+ const s = c(y(o), "../.."), r = $("@glasshome/widget-sdk/tailwind-sources"), a = r ? y(r) : null, h = [
75
+ u(s, "src"),
76
+ u(s, "dist"),
77
+ ...a ? [u(a, "src"), u(a, "dist")] : [],
78
+ y(i)
79
+ ].filter((d) => l(d)), m = c(n, `${t}.tailwind.css`);
80
+ w(
59
81
  m,
60
82
  [
61
83
  '@import "tailwindcss" source(none);',
62
84
  '@import "tw-animate-css";',
63
85
  '@import "@glasshome/ui/styles/theme";',
64
- ...g.map((u) => `@source "${h(u)}";`),
86
+ ...h.map((d) => `@source "${p(d)}";`),
65
87
  "@custom-variant dark {",
66
88
  " &:is(.dark *) { @slot }",
67
89
  " :host(.dark) & { @slot }",
@@ -70,84 +92,84 @@ function O(e, t, n) {
70
92
  ].join(`
71
93
  `)
72
94
  );
73
- const f = a(o, `${t}.entry.ts`);
74
- return p(
95
+ const f = c(n, `${t}.entry.ts`);
96
+ return w(
75
97
  f,
76
98
  [
77
- `import "${h(m)}";`,
78
- `export { default } from "${h(n)}";`,
99
+ `import "${p(m)}";`,
100
+ `export { default } from "${p(i)}";`,
79
101
  ""
80
102
  ].join(`
81
103
  `)
82
104
  ), f;
83
105
  }
84
- function W() {
85
- const e = H();
106
+ function _() {
107
+ const e = C();
86
108
  for (const t of e)
87
109
  t.apply ??= "build";
88
110
  return e;
89
111
  }
90
- function G(e) {
112
+ function q(e) {
91
113
  const t = [];
92
114
  if (!l(e)) return t;
93
- for (const n of I(e)) {
94
- const o = a(e, n);
95
- if (!k(o).isDirectory()) continue;
96
- const i = a(o, "index.tsx"), s = a(o, "manifest.json");
97
- l(i) && l(s) && t.push({ name: n, entry: i });
115
+ for (const i of I(e)) {
116
+ const n = c(e, i);
117
+ if (!P(n).isDirectory()) continue;
118
+ const o = c(n, "index.tsx"), s = c(n, "manifest.json");
119
+ l(o) && l(s) && t.push({ name: i, entry: o });
98
120
  }
99
121
  return t;
100
122
  }
101
- function V(e, t) {
102
- const n = [];
123
+ function z(e, t) {
124
+ const i = [];
103
125
  if (l(e))
104
- for (const i of I(e)) {
105
- if (!k(d(e, i)).isDirectory()) continue;
106
- const s = d(e, i, "manifest.json");
126
+ for (const o of I(e)) {
127
+ if (!P(u(e, o)).isDirectory()) continue;
128
+ const s = u(e, o, "manifest.json");
107
129
  if (!l(s)) continue;
108
130
  const r = U.safeParse(
109
- JSON.parse(w(s, "utf-8"))
131
+ JSON.parse(g(s, "utf-8"))
110
132
  );
111
133
  if (!r.success)
112
134
  throw new Error(
113
- `[registry] Invalid manifest for "${i}": ${C(r.error)}`
135
+ `[registry] Invalid manifest for "${o}": ${A(r.error)}`
114
136
  );
115
- const c = l(d(t, `${i}.css`));
116
- n.push({
137
+ const a = l(u(t, `${o}.css`));
138
+ i.push({
117
139
  ...r.data,
118
- bundleUrl: `./${i}.js`,
119
- ...c ? { cssUrl: `./${i}.css` } : {}
140
+ bundleUrl: `./${o}.js`,
141
+ ...a ? { cssUrl: `./${o}.css` } : {}
120
142
  });
121
143
  }
122
- const o = {
144
+ const n = {
123
145
  version: 1,
124
146
  generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
125
147
  baseUrl: "./",
126
- widgets: n
148
+ widgets: i
127
149
  };
128
- l(t) || D(t, { recursive: !0 }), p(d(t, "registry.json"), JSON.stringify(o, null, 2)), console.log(`[registry] Generated registry.json with ${n.length} widget(s)`);
150
+ l(t) || D(t, { recursive: !0 }), w(u(t, "registry.json"), JSON.stringify(n, null, 2)), console.log(`[registry] Generated registry.json with ${i.length} widget(s)`);
129
151
  }
130
- async function q(e) {
131
- const { build: t } = await import("vite"), n = process.cwd(), o = a(n, e?.srcDir ?? "src"), i = a(n, e?.outDir ?? "dist");
132
- let s = G(o);
152
+ async function M(e) {
153
+ const { build: t } = await import("vite"), i = process.cwd(), n = c(i, e?.srcDir ?? "src"), o = c(i, e?.outDir ?? "dist");
154
+ let s = q(n);
133
155
  if (s.length === 0) {
134
- console.warn("[glasshome-widgets] No widgets found in", o);
156
+ console.warn("[glasshome-widgets] No widgets found in", n);
135
157
  return;
136
158
  }
137
159
  if (e?.only) {
138
160
  const r = new Set(e.only);
139
- s = s.filter((c) => r.has(c.name));
161
+ s = s.filter((a) => r.has(a.name));
140
162
  }
141
- e?.only || l(i) && R(i, { recursive: !0 }), l(i) || D(i, { recursive: !0 });
163
+ e?.only || l(o) && T(o, { recursive: !0 }), l(o) || D(o, { recursive: !0 });
142
164
  for (const r of s)
143
165
  await t({
144
166
  configFile: !1,
145
- root: n,
146
- plugins: [...W(), ...e?.plugins ?? [], j()],
167
+ root: i,
168
+ plugins: [..._(), ...e?.plugins ?? [], O()],
147
169
  ...e?.viteConfig,
148
170
  build: {
149
171
  lib: {
150
- entry: O(n, r.name, r.entry),
172
+ entry: N(i, r.name, r.entry),
151
173
  formats: ["es"],
152
174
  fileName: r.name,
153
175
  // Widget CSS ships as a separate asset (adopted by the host's
@@ -155,19 +177,19 @@ async function q(e) {
155
177
  cssFileName: r.name
156
178
  },
157
179
  rollupOptions: {
158
- external: $
180
+ external: k
159
181
  },
160
- outDir: i,
182
+ outDir: o,
161
183
  emptyOutDir: !1,
162
184
  copyPublicDir: !1,
163
185
  ...e?.viteConfig?.build
164
186
  },
165
187
  logLevel: "warn"
166
- });
167
- V(o, i);
188
+ }), j(o, r.name);
189
+ z(n, o);
168
190
  }
169
- function ee(e) {
170
- const t = e?.entry ?? "src/index.tsx", n = {
191
+ function te(e) {
192
+ const t = e?.entry ?? "src/index.tsx", i = {
171
193
  name: "glasshome-widget:build",
172
194
  apply: "build",
173
195
  config() {
@@ -175,100 +197,101 @@ function ee(e) {
175
197
  return {
176
198
  build: {
177
199
  lib: {
178
- entry: O(s, "index", a(s, t)),
200
+ entry: N(s, "index", c(s, t)),
179
201
  formats: ["es"],
180
202
  fileName: "index",
181
203
  cssFileName: "index"
182
204
  },
183
205
  rollupOptions: {
184
- external: $
206
+ external: k
185
207
  }
186
208
  }
187
209
  };
188
210
  }
189
- }, o = {
211
+ }, n = {
190
212
  name: "glasshome-widget:dev",
191
213
  apply: "serve",
192
214
  enforce: "pre",
193
215
  config() {
194
- const s = S(), r = process.cwd(), c = a(r, "..", "..");
216
+ const s = S(), r = process.cwd(), a = c(r, "..", "..");
195
217
  return {
196
218
  server: {
197
219
  fs: {
198
- allow: [s, r, c]
220
+ allow: [s, r, a]
199
221
  }
200
222
  }
201
223
  };
202
224
  },
203
225
  configureServer(s) {
204
- const r = S(), c = d(r, "preview.html");
205
- s.middlewares.use(async (g, m, f) => {
206
- if (g.url === "/" || g.url === "/index.html")
226
+ const r = S(), a = u(r, "preview.html");
227
+ s.middlewares.use(async (h, m, f) => {
228
+ if (h.url === "/" || h.url === "/index.html")
207
229
  try {
208
- let u = w(c, "utf-8");
209
- u = await s.transformIndexHtml(g.url, u), m.setHeader("Content-Type", "text/html"), m.statusCode = 200, m.end(u);
210
- } catch (u) {
211
- f(u);
230
+ let d = g(a, "utf-8");
231
+ d = await s.transformIndexHtml(h.url, d), m.setHeader("Content-Type", "text/html"), m.statusCode = 200, m.end(d);
232
+ } catch (d) {
233
+ f(d);
212
234
  }
213
235
  else
214
236
  f();
215
237
  });
216
238
  },
217
239
  resolveId(s) {
218
- if (s === A) {
240
+ if (s === B) {
219
241
  const r = S();
220
- return h(d(r, "host.tsx"));
242
+ return p(u(r, "host.tsx"));
221
243
  }
222
- if (s === J)
223
- return P;
244
+ if (s === V)
245
+ return E;
224
246
  },
225
247
  load(s) {
226
- if (s === P)
227
- return `export { default } from "${h(a(process.cwd(), t))}";`;
248
+ if (s === E)
249
+ return `export { default } from "${p(c(process.cwd(), t))}";`;
228
250
  }
229
- }, i = {
251
+ }, o = {
230
252
  name: "glasshome-widget:schema",
231
253
  apply: "build",
232
254
  async closeBundle() {
233
- const s = a(process.cwd(), "dist", "index.js");
255
+ j(c(process.cwd(), "dist"), "index");
256
+ const s = c(process.cwd(), "dist", "index.js");
234
257
  if (l(s))
235
258
  try {
236
- const c = (await import(`${s}?t=${Date.now()}`)).default;
237
- if (!c?.configSchema) return;
238
- const { z: g } = await import("zod"), m = g.toJSONSchema(c.configSchema, { unrepresentable: "any" }), f = a(process.cwd(), "manifest.json");
259
+ const a = (await import(`${s}?t=${Date.now()}`)).default;
260
+ if (!a?.configSchema) return;
261
+ const { z: h } = await import("zod"), m = h.toJSONSchema(a.configSchema, { unrepresentable: "any" }), f = c(process.cwd(), "manifest.json");
239
262
  if (l(f)) {
240
- const b = JSON.parse(w(f, "utf-8"));
241
- b.schema = m, p(f, JSON.stringify(b, null, 2));
263
+ const b = JSON.parse(g(f, "utf-8"));
264
+ b.schema = m, w(f, JSON.stringify(b, null, 2));
242
265
  }
243
- const u = L(m), v = a(process.cwd(), ".schema-hash");
244
- if (l(v) && w(v, "utf-8").trim() !== u) {
245
- const N = c.manifest?.name ?? "unknown";
266
+ const d = L(m), v = c(process.cwd(), ".schema-hash");
267
+ if (l(v) && g(v, "utf-8").trim() !== d) {
268
+ const W = a.manifest?.name ?? "unknown";
246
269
  console.warn(
247
- `[widget-sdk] Schema shape changed for "${N}" — verify configVersion was bumped`
270
+ `[widget-sdk] Schema shape changed for "${W}" — verify configVersion was bumped`
248
271
  );
249
272
  }
250
- p(v, u);
273
+ w(v, d);
251
274
  } catch {
252
275
  }
253
276
  }
254
277
  };
255
- return [...W(), n, j(), i, o];
278
+ return [..._(), i, O(), o, n];
256
279
  }
257
- function se(e) {
258
- const t = e?.srcDir ?? "src", n = e?.outDir ?? "dist";
259
- let o = [];
280
+ function re(e) {
281
+ const t = e?.srcDir ?? "src", i = e?.outDir ?? "dist";
282
+ let n = [];
260
283
  return [{
261
284
  name: "glasshome-widgets:build",
262
285
  apply: "build",
263
286
  config(s) {
264
- return o = (s.plugins ?? []).flat().filter(Boolean).filter(
287
+ return n = (s.plugins ?? []).flat().filter(Boolean).filter(
265
288
  (r) => !r.name?.startsWith("glasshome-widgets:")
266
289
  ), {
267
290
  build: {
268
291
  rollupOptions: {
269
292
  input: { __glasshome_noop: "\0glasshome-noop" }
270
293
  },
271
- outDir: n,
294
+ outDir: i,
272
295
  copyPublicDir: !1
273
296
  }
274
297
  };
@@ -280,19 +303,19 @@ function se(e) {
280
303
  if (s === "\0glasshome-noop") return "export {}";
281
304
  },
282
305
  async closeBundle() {
283
- await q({
306
+ await M({
284
307
  srcDir: t,
285
- outDir: n,
286
- plugins: o
308
+ outDir: i,
309
+ plugins: n
287
310
  });
288
311
  }
289
312
  }];
290
313
  }
291
314
  export {
292
- q as buildWidgets,
293
- G as discoverWidgets,
294
- V as generateRegistry,
295
- ee as glasshomeWidget,
296
- se as glasshomeWidgets,
297
- $ as isWidgetExternal
315
+ M as buildWidgets,
316
+ q as discoverWidgets,
317
+ z as generateRegistry,
318
+ te as glasshomeWidget,
319
+ re as glasshomeWidgets,
320
+ k as isWidgetExternal
298
321
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/widget-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "SDK for building GlassHome dashboard widgets with SolidJS",
5
5
  "keywords": [
6
6
  "glasshome",