@glasshome/widget-sdk 0.5.2 → 1.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/dist/data.d.ts +10 -0
- package/dist/framework/theming/tokens.d.ts +9 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +366 -324
- package/dist/schemas.d.ts +6 -106
- package/dist/schemas.js +13 -77
- package/dist/types.d.ts +3 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +206 -122
- package/package.json +6 -2
package/dist/schemas.d.ts
CHANGED
|
@@ -1,108 +1,8 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
/**
|
|
3
|
-
* Runtime validation schemas
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* instead of letting them surface as cryptic SQLite or JSON errors.
|
|
2
|
+
* Runtime validation schemas, re-exported from the canonical
|
|
3
|
+
* @glasshome/widget-contract package (single source of truth shared by the
|
|
4
|
+
* SDK, the Hub, and Dash). Aliases preserve the SDK's historical export
|
|
5
|
+
* names so consumers don't break.
|
|
8
6
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
h: z.ZodNumber;
|
|
12
|
-
}, z.core.$strip>;
|
|
13
|
-
export declare const WidgetManifestSchema: z.ZodObject<{
|
|
14
|
-
name: z.ZodString;
|
|
15
|
-
description: z.ZodOptional<z.ZodString>;
|
|
16
|
-
minSize: z.ZodObject<{
|
|
17
|
-
w: z.ZodNumber;
|
|
18
|
-
h: z.ZodNumber;
|
|
19
|
-
}, z.core.$strip>;
|
|
20
|
-
maxSize: z.ZodObject<{
|
|
21
|
-
w: z.ZodNumber;
|
|
22
|
-
h: z.ZodNumber;
|
|
23
|
-
}, z.core.$strip>;
|
|
24
|
-
sdkVersion: z.ZodString;
|
|
25
|
-
icon: z.ZodOptional<z.ZodString>;
|
|
26
|
-
schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
27
|
-
defaultConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
28
|
-
version: z.ZodOptional<z.ZodString>;
|
|
29
|
-
displayName: z.ZodOptional<z.ZodString>;
|
|
30
|
-
scope: z.ZodOptional<z.ZodString>;
|
|
31
|
-
author: z.ZodOptional<z.ZodString>;
|
|
32
|
-
license: z.ZodOptional<z.ZodString>;
|
|
33
|
-
homepage: z.ZodOptional<z.ZodString>;
|
|
34
|
-
source: z.ZodOptional<z.ZodString>;
|
|
35
|
-
permissions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
36
|
-
isOfficial: z.ZodOptional<z.ZodBoolean>;
|
|
37
|
-
sha256Hash: z.ZodOptional<z.ZodString>;
|
|
38
|
-
bundleUrl: z.ZodOptional<z.ZodString>;
|
|
39
|
-
_registry: z.ZodOptional<z.ZodEnum<{
|
|
40
|
-
local: "local";
|
|
41
|
-
hub: "hub";
|
|
42
|
-
}>>;
|
|
43
|
-
releaseNotes: z.ZodOptional<z.ZodString>;
|
|
44
|
-
}, z.core.$loose>;
|
|
45
|
-
export declare const PublishRequestSchema: z.ZodObject<{
|
|
46
|
-
action: z.ZodLiteral<"request">;
|
|
47
|
-
scope: z.ZodString;
|
|
48
|
-
name: z.ZodString;
|
|
49
|
-
displayName: z.ZodString;
|
|
50
|
-
description: z.ZodOptional<z.ZodString>;
|
|
51
|
-
icon: z.ZodOptional<z.ZodString>;
|
|
52
|
-
minSize: z.ZodObject<{
|
|
53
|
-
w: z.ZodNumber;
|
|
54
|
-
h: z.ZodNumber;
|
|
55
|
-
}, z.core.$strip>;
|
|
56
|
-
maxSize: z.ZodObject<{
|
|
57
|
-
w: z.ZodNumber;
|
|
58
|
-
h: z.ZodNumber;
|
|
59
|
-
}, z.core.$strip>;
|
|
60
|
-
sdkVersion: z.ZodString;
|
|
61
|
-
version: z.ZodString;
|
|
62
|
-
bundleSize: z.ZodNumber;
|
|
63
|
-
sha256Hash: z.ZodString;
|
|
64
|
-
manifestJson: z.ZodString;
|
|
65
|
-
}, z.core.$strip>;
|
|
66
|
-
export declare const PublishConfirmSchema: z.ZodObject<{
|
|
67
|
-
action: z.ZodLiteral<"confirm">;
|
|
68
|
-
versionId: z.ZodString;
|
|
69
|
-
}, z.core.$strip>;
|
|
70
|
-
export declare const PublishBodySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
71
|
-
action: z.ZodLiteral<"request">;
|
|
72
|
-
scope: z.ZodString;
|
|
73
|
-
name: z.ZodString;
|
|
74
|
-
displayName: z.ZodString;
|
|
75
|
-
description: z.ZodOptional<z.ZodString>;
|
|
76
|
-
icon: z.ZodOptional<z.ZodString>;
|
|
77
|
-
minSize: z.ZodObject<{
|
|
78
|
-
w: z.ZodNumber;
|
|
79
|
-
h: z.ZodNumber;
|
|
80
|
-
}, z.core.$strip>;
|
|
81
|
-
maxSize: z.ZodObject<{
|
|
82
|
-
w: z.ZodNumber;
|
|
83
|
-
h: z.ZodNumber;
|
|
84
|
-
}, z.core.$strip>;
|
|
85
|
-
sdkVersion: z.ZodString;
|
|
86
|
-
version: z.ZodString;
|
|
87
|
-
bundleSize: z.ZodNumber;
|
|
88
|
-
sha256Hash: z.ZodString;
|
|
89
|
-
manifestJson: z.ZodString;
|
|
90
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
91
|
-
action: z.ZodLiteral<"confirm">;
|
|
92
|
-
versionId: z.ZodString;
|
|
93
|
-
}, z.core.$strip>], "action">;
|
|
94
|
-
/**
|
|
95
|
-
* Serialize a GridSize to a JSON string for database storage.
|
|
96
|
-
*/
|
|
97
|
-
export declare function serializeGridSize(size: z.infer<typeof GridSizeSchema>): string;
|
|
98
|
-
/**
|
|
99
|
-
* Parse a GridSize from a database text column or API response.
|
|
100
|
-
* Accepts a JSON string, an already-parsed object, or garbage.
|
|
101
|
-
* Returns the fallback for any value that doesn't validate.
|
|
102
|
-
*/
|
|
103
|
-
export declare function parseGridSize(raw: unknown, fallback?: z.infer<typeof GridSizeSchema>): z.infer<typeof GridSizeSchema>;
|
|
104
|
-
/**
|
|
105
|
-
* Format a zod error into a single user-friendly string.
|
|
106
|
-
* Groups issues by path so the output reads like a bulleted list.
|
|
107
|
-
*/
|
|
108
|
-
export declare function formatSchemaError(error: z.ZodError): string;
|
|
7
|
+
export { capabilitiesSchema, capabilityGrantSchema, formatSchemaError, GridSizeSchema, parseGridSize, PublishBodySchema, PublishConfirmSchema, PublishRequestSchema, publishManifestSchema, serializeGridSize, widgetManifestSchema, widgetManifestSchema as WidgetManifestSchema, } from "@glasshome/widget-contract";
|
|
8
|
+
export type { CapabilityGrant } from "@glasshome/widget-contract";
|
package/dist/schemas.js
CHANGED
|
@@ -1,79 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const t = n.object({
|
|
3
|
-
w: n.number().int().min(1),
|
|
4
|
-
h: n.number().int().min(1)
|
|
5
|
-
}), p = n.object({
|
|
6
|
-
name: n.string().min(1),
|
|
7
|
-
description: n.string().optional(),
|
|
8
|
-
minSize: t,
|
|
9
|
-
maxSize: t,
|
|
10
|
-
sdkVersion: n.string().min(1),
|
|
11
|
-
icon: n.string().optional(),
|
|
12
|
-
schema: n.record(n.string(), n.unknown()).optional(),
|
|
13
|
-
defaultConfig: n.record(n.string(), n.unknown()).optional(),
|
|
14
|
-
// Round-trip fields set by the Hub / widget browser when installing. These
|
|
15
|
-
// must validate so real manifests stringified from WidgetRegistryEntry
|
|
16
|
-
// pass through the canonical schema without being stripped.
|
|
17
|
-
version: n.string().optional(),
|
|
18
|
-
displayName: n.string().optional(),
|
|
19
|
-
scope: n.string().optional(),
|
|
20
|
-
author: n.string().optional(),
|
|
21
|
-
license: n.string().optional(),
|
|
22
|
-
homepage: n.string().url().optional(),
|
|
23
|
-
source: n.string().url().optional(),
|
|
24
|
-
permissions: n.array(n.string()).optional(),
|
|
25
|
-
isOfficial: n.boolean().optional(),
|
|
26
|
-
sha256Hash: n.string().optional(),
|
|
27
|
-
bundleUrl: n.string().optional(),
|
|
28
|
-
_registry: n.enum(["hub", "local"]).optional(),
|
|
29
|
-
releaseNotes: n.string().optional()
|
|
30
|
-
}).passthrough(), r = /^[a-z0-9][a-z0-9-]*$/, a = n.object({
|
|
31
|
-
action: n.literal("request"),
|
|
32
|
-
scope: n.string().regex(r, "Must be lowercase alphanumeric with hyphens"),
|
|
33
|
-
name: n.string().min(1),
|
|
34
|
-
displayName: n.string().min(1),
|
|
35
|
-
description: n.string().optional(),
|
|
36
|
-
icon: n.string().optional(),
|
|
37
|
-
minSize: t,
|
|
38
|
-
maxSize: t,
|
|
39
|
-
sdkVersion: n.string().min(1),
|
|
40
|
-
version: n.string().min(1),
|
|
41
|
-
bundleSize: n.number().int().positive(),
|
|
42
|
-
sha256Hash: n.string().min(1),
|
|
43
|
-
manifestJson: n.string().min(1)
|
|
44
|
-
}), c = n.object({
|
|
45
|
-
action: n.literal("confirm"),
|
|
46
|
-
versionId: n.string().min(1)
|
|
47
|
-
}), m = n.discriminatedUnion("action", [
|
|
48
|
-
a,
|
|
49
|
-
c
|
|
50
|
-
]);
|
|
51
|
-
function g(i) {
|
|
52
|
-
return JSON.stringify(i);
|
|
53
|
-
}
|
|
54
|
-
function u(i, o = { w: 1, h: 1 }) {
|
|
55
|
-
if (i != null && typeof i == "object") {
|
|
56
|
-
const s = t.safeParse(i);
|
|
57
|
-
if (s.success) return s.data;
|
|
58
|
-
}
|
|
59
|
-
if (typeof i == "string")
|
|
60
|
-
try {
|
|
61
|
-
const s = JSON.parse(i), e = t.safeParse(s);
|
|
62
|
-
if (e.success) return e.data;
|
|
63
|
-
} catch {
|
|
64
|
-
}
|
|
65
|
-
return o;
|
|
66
|
-
}
|
|
67
|
-
function h(i) {
|
|
68
|
-
return i.issues.map((o) => `${o.path.length > 0 ? o.path.join(".") : "(root)"}: ${o.message}`).join("; ");
|
|
69
|
-
}
|
|
1
|
+
import { GridSizeSchema as a, PublishBodySchema as h, PublishConfirmSchema as m, PublishRequestSchema as S, widgetManifestSchema as c, capabilitiesSchema as r, capabilityGrantSchema as s, formatSchemaError as t, parseGridSize as d, publishManifestSchema as f, serializeGridSize as l, widgetManifestSchema as b } from "@glasshome/widget-contract";
|
|
70
2
|
export {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
3
|
+
a as GridSizeSchema,
|
|
4
|
+
h as PublishBodySchema,
|
|
5
|
+
m as PublishConfirmSchema,
|
|
6
|
+
S as PublishRequestSchema,
|
|
7
|
+
c as WidgetManifestSchema,
|
|
8
|
+
r as capabilitiesSchema,
|
|
9
|
+
s as capabilityGrantSchema,
|
|
10
|
+
t as formatSchemaError,
|
|
11
|
+
d as parseGridSize,
|
|
12
|
+
f as publishManifestSchema,
|
|
13
|
+
l as serializeGridSize,
|
|
14
|
+
b as widgetManifestSchema
|
|
79
15
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CapabilityGrant } from "@glasshome/widget-contract";
|
|
1
2
|
import type { ZodType } from "zod";
|
|
2
3
|
/**
|
|
3
4
|
* Grid size constraint — number of columns (w) and rows (h).
|
|
@@ -21,6 +22,8 @@ export interface WidgetManifest {
|
|
|
21
22
|
schema?: object;
|
|
22
23
|
defaultConfig?: Record<string, unknown>;
|
|
23
24
|
configVersion?: number;
|
|
25
|
+
capabilities?: CapabilityGrant[];
|
|
26
|
+
cssUrl?: string;
|
|
24
27
|
}
|
|
25
28
|
/**
|
|
26
29
|
* Runtime context provided to widgets by the host.
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ interface DiscoveredWidget {
|
|
|
11
11
|
}
|
|
12
12
|
/** Scan srcDir for subdirectories containing index.tsx + manifest.json. */
|
|
13
13
|
export declare function discoverWidgets(srcDir: string): DiscoveredWidget[];
|
|
14
|
-
/** Generate registry.json from widget manifests. */
|
|
14
|
+
/** Generate registry.json from widget manifests, validated against the contract schema. */
|
|
15
15
|
export declare function generateRegistry(srcDir: string, outDir: string): void;
|
|
16
16
|
export interface BuildWidgetsOptions {
|
|
17
17
|
/** Directory containing widget subdirectories (default: "src") */
|
package/dist/vite/index.js
CHANGED
|
@@ -1,79 +1,161 @@
|
|
|
1
|
-
import { createHash as
|
|
2
|
-
import { existsSync as l, rmSync as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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";
|
|
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";
|
|
8
|
+
function L(e) {
|
|
9
|
+
const t = JSON.stringify(e, Object.keys(e).sort());
|
|
10
|
+
return _("sha256").update(t).digest("hex").slice(0, 16);
|
|
8
11
|
}
|
|
9
|
-
const
|
|
10
|
-
function
|
|
11
|
-
return
|
|
12
|
+
const J = "virtual:glasshome-widget", P = "\0virtual:glasshome-widget", A = "/@glasshome/preview";
|
|
13
|
+
function h(e) {
|
|
14
|
+
return x === "\\" ? e.split(x).join("/") : e;
|
|
12
15
|
}
|
|
13
|
-
function
|
|
14
|
-
const e =
|
|
15
|
-
return a(
|
|
16
|
+
function S() {
|
|
17
|
+
const e = T(import.meta.url);
|
|
18
|
+
return a(y(e), "../../preview");
|
|
16
19
|
}
|
|
17
|
-
function
|
|
18
|
-
return e === "solid-js" || e.startsWith("solid-js/") || e === "@glasshome/widget-sdk" || e.startsWith("@glasshome/widget-sdk/") || e === "@glasshome/ui" || e.startsWith("@glasshome/ui/")
|
|
20
|
+
function $(e) {
|
|
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/");
|
|
19
22
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
function j() {
|
|
24
|
+
return {
|
|
25
|
+
name: "glasshome-widget:sync-layer-guard",
|
|
26
|
+
apply: "build",
|
|
27
|
+
enforce: "pre",
|
|
28
|
+
resolveId(e, t) {
|
|
29
|
+
if (e === "@glasshome/sync-layer" || e.startsWith("@glasshome/sync-layer/"))
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Widgets must not import "${e}" directly` + (t ? ` (imported by ${t})` : "") + '. Import the equivalent hook from "@glasshome/widget-sdk" instead (e.g. useEntity, useEntities, useService).'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const B = "node_modules/.cache/glasshome-widgets";
|
|
37
|
+
function E(e) {
|
|
38
|
+
try {
|
|
39
|
+
return F(d(process.cwd(), "package.json")).resolve(e);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
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)
|
|
49
|
+
throw new Error(
|
|
50
|
+
"[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
|
+
);
|
|
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(
|
|
59
|
+
m,
|
|
60
|
+
[
|
|
61
|
+
'@import "tailwindcss" source(none);',
|
|
62
|
+
'@import "tw-animate-css";',
|
|
63
|
+
'@import "@glasshome/ui/styles/theme";',
|
|
64
|
+
...g.map((u) => `@source "${h(u)}";`),
|
|
65
|
+
"@custom-variant dark {",
|
|
66
|
+
" &:is(.dark *) { @slot }",
|
|
67
|
+
" :host(.dark) & { @slot }",
|
|
68
|
+
"}",
|
|
69
|
+
""
|
|
70
|
+
].join(`
|
|
71
|
+
`)
|
|
72
|
+
);
|
|
73
|
+
const f = a(o, `${t}.entry.ts`);
|
|
74
|
+
return p(
|
|
75
|
+
f,
|
|
76
|
+
[
|
|
77
|
+
`import "${h(m)}";`,
|
|
78
|
+
`export { default } from "${h(n)}";`,
|
|
79
|
+
""
|
|
80
|
+
].join(`
|
|
81
|
+
`)
|
|
82
|
+
), f;
|
|
83
|
+
}
|
|
84
|
+
function W() {
|
|
85
|
+
const e = H();
|
|
86
|
+
for (const t of e)
|
|
87
|
+
t.apply ??= "build";
|
|
88
|
+
return e;
|
|
89
|
+
}
|
|
90
|
+
function G(e) {
|
|
91
|
+
const t = [];
|
|
92
|
+
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 });
|
|
28
98
|
}
|
|
29
|
-
return
|
|
99
|
+
return t;
|
|
30
100
|
}
|
|
31
|
-
function
|
|
32
|
-
const
|
|
101
|
+
function V(e, t) {
|
|
102
|
+
const n = [];
|
|
33
103
|
if (l(e))
|
|
34
|
-
for (const i of
|
|
35
|
-
if (!
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
104
|
+
for (const i of I(e)) {
|
|
105
|
+
if (!k(d(e, i)).isDirectory()) continue;
|
|
106
|
+
const s = d(e, i, "manifest.json");
|
|
107
|
+
if (!l(s)) continue;
|
|
108
|
+
const r = U.safeParse(
|
|
109
|
+
JSON.parse(w(s, "utf-8"))
|
|
110
|
+
);
|
|
111
|
+
if (!r.success)
|
|
112
|
+
throw new Error(
|
|
113
|
+
`[registry] Invalid manifest for "${i}": ${C(r.error)}`
|
|
114
|
+
);
|
|
115
|
+
const c = l(d(t, `${i}.css`));
|
|
116
|
+
n.push({
|
|
117
|
+
...r.data,
|
|
118
|
+
bundleUrl: `./${i}.js`,
|
|
119
|
+
...c ? { cssUrl: `./${i}.css` } : {}
|
|
120
|
+
});
|
|
42
121
|
}
|
|
43
122
|
const o = {
|
|
44
123
|
version: 1,
|
|
45
124
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
46
125
|
baseUrl: "./",
|
|
47
|
-
widgets:
|
|
126
|
+
widgets: n
|
|
48
127
|
};
|
|
49
|
-
l(
|
|
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)`);
|
|
50
129
|
}
|
|
51
|
-
async function
|
|
52
|
-
const { build:
|
|
53
|
-
let
|
|
54
|
-
if (
|
|
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);
|
|
133
|
+
if (s.length === 0) {
|
|
55
134
|
console.warn("[glasshome-widgets] No widgets found in", o);
|
|
56
135
|
return;
|
|
57
136
|
}
|
|
58
137
|
if (e?.only) {
|
|
59
|
-
const
|
|
60
|
-
|
|
138
|
+
const r = new Set(e.only);
|
|
139
|
+
s = s.filter((c) => r.has(c.name));
|
|
61
140
|
}
|
|
62
|
-
e?.only || l(i) &&
|
|
63
|
-
for (const
|
|
64
|
-
await
|
|
141
|
+
e?.only || l(i) && R(i, { recursive: !0 }), l(i) || D(i, { recursive: !0 });
|
|
142
|
+
for (const r of s)
|
|
143
|
+
await t({
|
|
65
144
|
configFile: !1,
|
|
66
|
-
root:
|
|
67
|
-
plugins: e?.plugins ?? [],
|
|
145
|
+
root: n,
|
|
146
|
+
plugins: [...W(), ...e?.plugins ?? [], j()],
|
|
68
147
|
...e?.viteConfig,
|
|
69
148
|
build: {
|
|
70
149
|
lib: {
|
|
71
|
-
entry:
|
|
150
|
+
entry: O(n, r.name, r.entry),
|
|
72
151
|
formats: ["es"],
|
|
73
|
-
fileName:
|
|
152
|
+
fileName: r.name,
|
|
153
|
+
// Widget CSS ships as a separate asset (adopted by the host's
|
|
154
|
+
// shadow root), never inlined into the JS bundle.
|
|
155
|
+
cssFileName: r.name
|
|
74
156
|
},
|
|
75
157
|
rollupOptions: {
|
|
76
|
-
external:
|
|
158
|
+
external: $
|
|
77
159
|
},
|
|
78
160
|
outDir: i,
|
|
79
161
|
emptyOutDir: !1,
|
|
@@ -82,133 +164,135 @@ async function U(e) {
|
|
|
82
164
|
},
|
|
83
165
|
logLevel: "warn"
|
|
84
166
|
});
|
|
85
|
-
|
|
167
|
+
V(o, i);
|
|
86
168
|
}
|
|
87
|
-
function
|
|
88
|
-
const
|
|
89
|
-
return [{
|
|
169
|
+
function ee(e) {
|
|
170
|
+
const t = e?.entry ?? "src/index.tsx", n = {
|
|
90
171
|
name: "glasshome-widget:build",
|
|
91
172
|
apply: "build",
|
|
92
173
|
config() {
|
|
174
|
+
const s = process.cwd();
|
|
93
175
|
return {
|
|
94
176
|
build: {
|
|
95
177
|
lib: {
|
|
96
|
-
entry:
|
|
178
|
+
entry: O(s, "index", a(s, t)),
|
|
97
179
|
formats: ["es"],
|
|
98
|
-
fileName: "index"
|
|
180
|
+
fileName: "index",
|
|
181
|
+
cssFileName: "index"
|
|
99
182
|
},
|
|
100
183
|
rollupOptions: {
|
|
101
|
-
external:
|
|
184
|
+
external: $
|
|
102
185
|
}
|
|
103
186
|
}
|
|
104
187
|
};
|
|
105
188
|
}
|
|
106
|
-
}, {
|
|
107
|
-
name: "glasshome-widget:schema",
|
|
108
|
-
apply: "build",
|
|
109
|
-
async closeBundle() {
|
|
110
|
-
const t = a(process.cwd(), "dist", "index.js");
|
|
111
|
-
if (l(t))
|
|
112
|
-
try {
|
|
113
|
-
const c = (await import(`${t}?t=${Date.now()}`)).default;
|
|
114
|
-
if (!c?.configSchema) return;
|
|
115
|
-
const { z: m } = await import("zod"), f = m.toJSONSchema(c.configSchema, { unrepresentable: "any" }), d = a(process.cwd(), "manifest.json");
|
|
116
|
-
if (l(d)) {
|
|
117
|
-
const w = JSON.parse(h(d, "utf-8"));
|
|
118
|
-
w.schema = f, b(d, JSON.stringify(w, null, 2));
|
|
119
|
-
}
|
|
120
|
-
const u = R(f), p = a(process.cwd(), ".schema-hash");
|
|
121
|
-
if (l(p) && h(p, "utf-8").trim() !== u) {
|
|
122
|
-
const W = c.manifest?.name ?? "unknown";
|
|
123
|
-
console.warn(
|
|
124
|
-
`[widget-sdk] Schema shape changed for "${W}" — verify configVersion was bumped`
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
b(p, u);
|
|
128
|
-
} catch {
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
189
|
+
}, o = {
|
|
132
190
|
name: "glasshome-widget:dev",
|
|
133
191
|
apply: "serve",
|
|
134
192
|
enforce: "pre",
|
|
135
193
|
config() {
|
|
136
|
-
const
|
|
194
|
+
const s = S(), r = process.cwd(), c = a(r, "..", "..");
|
|
137
195
|
return {
|
|
138
196
|
server: {
|
|
139
197
|
fs: {
|
|
140
|
-
allow: [
|
|
198
|
+
allow: [s, r, c]
|
|
141
199
|
}
|
|
142
200
|
}
|
|
143
201
|
};
|
|
144
202
|
},
|
|
145
|
-
configureServer(
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
if (
|
|
203
|
+
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")
|
|
149
207
|
try {
|
|
150
|
-
let u =
|
|
151
|
-
u = await
|
|
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);
|
|
152
210
|
} catch (u) {
|
|
153
|
-
|
|
211
|
+
f(u);
|
|
154
212
|
}
|
|
155
213
|
else
|
|
156
|
-
|
|
214
|
+
f();
|
|
157
215
|
});
|
|
158
216
|
},
|
|
159
|
-
resolveId(
|
|
160
|
-
if (
|
|
161
|
-
const
|
|
162
|
-
return
|
|
217
|
+
resolveId(s) {
|
|
218
|
+
if (s === A) {
|
|
219
|
+
const r = S();
|
|
220
|
+
return h(d(r, "host.tsx"));
|
|
163
221
|
}
|
|
164
|
-
if (
|
|
165
|
-
return
|
|
222
|
+
if (s === J)
|
|
223
|
+
return P;
|
|
166
224
|
},
|
|
167
|
-
load(
|
|
168
|
-
if (
|
|
169
|
-
return `export { default } from "${
|
|
225
|
+
load(s) {
|
|
226
|
+
if (s === P)
|
|
227
|
+
return `export { default } from "${h(a(process.cwd(), t))}";`;
|
|
170
228
|
}
|
|
171
|
-
}
|
|
229
|
+
}, i = {
|
|
230
|
+
name: "glasshome-widget:schema",
|
|
231
|
+
apply: "build",
|
|
232
|
+
async closeBundle() {
|
|
233
|
+
const s = a(process.cwd(), "dist", "index.js");
|
|
234
|
+
if (l(s))
|
|
235
|
+
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");
|
|
239
|
+
if (l(f)) {
|
|
240
|
+
const b = JSON.parse(w(f, "utf-8"));
|
|
241
|
+
b.schema = m, p(f, JSON.stringify(b, null, 2));
|
|
242
|
+
}
|
|
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";
|
|
246
|
+
console.warn(
|
|
247
|
+
`[widget-sdk] Schema shape changed for "${N}" — verify configVersion was bumped`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
p(v, u);
|
|
251
|
+
} catch {
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
return [...W(), n, j(), i, o];
|
|
172
256
|
}
|
|
173
|
-
function
|
|
174
|
-
const
|
|
257
|
+
function se(e) {
|
|
258
|
+
const t = e?.srcDir ?? "src", n = e?.outDir ?? "dist";
|
|
175
259
|
let o = [];
|
|
176
260
|
return [{
|
|
177
261
|
name: "glasshome-widgets:build",
|
|
178
262
|
apply: "build",
|
|
179
|
-
config(
|
|
180
|
-
return o = (
|
|
181
|
-
(
|
|
263
|
+
config(s) {
|
|
264
|
+
return o = (s.plugins ?? []).flat().filter(Boolean).filter(
|
|
265
|
+
(r) => !r.name?.startsWith("glasshome-widgets:")
|
|
182
266
|
), {
|
|
183
267
|
build: {
|
|
184
268
|
rollupOptions: {
|
|
185
269
|
input: { __glasshome_noop: "\0glasshome-noop" }
|
|
186
270
|
},
|
|
187
|
-
outDir:
|
|
271
|
+
outDir: n,
|
|
188
272
|
copyPublicDir: !1
|
|
189
273
|
}
|
|
190
274
|
};
|
|
191
275
|
},
|
|
192
|
-
resolveId(
|
|
193
|
-
if (
|
|
276
|
+
resolveId(s) {
|
|
277
|
+
if (s === "\0glasshome-noop") return s;
|
|
194
278
|
},
|
|
195
|
-
load(
|
|
196
|
-
if (
|
|
279
|
+
load(s) {
|
|
280
|
+
if (s === "\0glasshome-noop") return "export {}";
|
|
197
281
|
},
|
|
198
282
|
async closeBundle() {
|
|
199
|
-
await
|
|
200
|
-
srcDir:
|
|
201
|
-
outDir:
|
|
283
|
+
await q({
|
|
284
|
+
srcDir: t,
|
|
285
|
+
outDir: n,
|
|
202
286
|
plugins: o
|
|
203
287
|
});
|
|
204
288
|
}
|
|
205
289
|
}];
|
|
206
290
|
}
|
|
207
291
|
export {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
292
|
+
q as buildWidgets,
|
|
293
|
+
G as discoverWidgets,
|
|
294
|
+
V as generateRegistry,
|
|
295
|
+
ee as glasshomeWidget,
|
|
296
|
+
se as glasshomeWidgets,
|
|
297
|
+
$ as isWidgetExternal
|
|
214
298
|
};
|