@sorb/leaf 0.1.1 → 0.2.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/README.md +26 -0
- package/dist/index.js +198 -8
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +198 -8
- package/dist/index.mjs.map +3 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -41,6 +41,32 @@ properties on `:root`, and polls for live updates. If the server isn't
|
|
|
41
41
|
running it falls back silently to the committed tokens — preview never
|
|
42
42
|
breaks production.
|
|
43
43
|
|
|
44
|
+
## Security
|
|
45
|
+
|
|
46
|
+
Sorb injects externally-authored token values into your running app, so the
|
|
47
|
+
SDK treats every value and preview origin as untrusted input.
|
|
48
|
+
|
|
49
|
+
- **Value sanitization.** Every token value is validated before it is written
|
|
50
|
+
to `:root`. Values containing `url(...)`, `image-set(...)`, `expression(...)`,
|
|
51
|
+
`@import`, `javascript:`, raw `;`/`{`/`}`, or any non-allowlisted CSS function
|
|
52
|
+
are **skipped** (the rest still apply). This neutralizes CSS-exfil and
|
|
53
|
+
defacement via a hostile token. The check is exported as `sanitizeCssValue`.
|
|
54
|
+
- **Preview is off by default and origin-allowlisted.** `?preview=` is honored
|
|
55
|
+
only when `preview.enabled === true` **and** the resolved `preview.origin` is
|
|
56
|
+
localhost / `127.0.0.1` / `[::1]` (any port) or is listed in
|
|
57
|
+
`preview.allowedOrigins`. A stray `?preview=` on a production deploy against an
|
|
58
|
+
untrusted bridge is ignored. **Never enable preview in production against an
|
|
59
|
+
untrusted bridge origin.**
|
|
60
|
+
|
|
61
|
+
```jsx
|
|
62
|
+
preview: {
|
|
63
|
+
enabled: import.meta.env.MODE !== 'production',
|
|
64
|
+
origin: 'http://localhost:7777',
|
|
65
|
+
// optional: trust an additional exact origin (e.g. a staging bridge)
|
|
66
|
+
allowedOrigins: ['https://staging-bridge.example.com'],
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
44
70
|
## Hooks
|
|
45
71
|
|
|
46
72
|
```jsx
|
package/dist/index.js
CHANGED
|
@@ -31,10 +31,12 @@ var src_exports = {};
|
|
|
31
31
|
__export(src_exports, {
|
|
32
32
|
PreviewBanner: () => PreviewBanner,
|
|
33
33
|
SorbProvider: () => SorbProvider,
|
|
34
|
+
sanitizeCssValue: () => sanitizeCssValue,
|
|
34
35
|
useIsPreview: () => useIsPreview,
|
|
35
36
|
usePreviewState: () => usePreviewState,
|
|
36
37
|
useToken: () => useToken,
|
|
37
|
-
useTokens: () => useTokens
|
|
38
|
+
useTokens: () => useTokens,
|
|
39
|
+
verifyResolved: () => verifyResolved
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(src_exports);
|
|
40
42
|
|
|
@@ -52,16 +54,147 @@ var useTokenContext = () => {
|
|
|
52
54
|
return ctx;
|
|
53
55
|
};
|
|
54
56
|
|
|
57
|
+
// src/sanitize.js
|
|
58
|
+
var ALLOWED_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
59
|
+
"rgb",
|
|
60
|
+
"rgba",
|
|
61
|
+
"hsl",
|
|
62
|
+
"hsla",
|
|
63
|
+
"hwb",
|
|
64
|
+
"lab",
|
|
65
|
+
"lch",
|
|
66
|
+
"oklab",
|
|
67
|
+
"oklch",
|
|
68
|
+
"color",
|
|
69
|
+
"calc",
|
|
70
|
+
"min",
|
|
71
|
+
"max",
|
|
72
|
+
"clamp",
|
|
73
|
+
"var",
|
|
74
|
+
"env"
|
|
75
|
+
]);
|
|
76
|
+
var FUNCTION_CALL = /([a-zA-Z_-][\w-]*)\s*\(/g;
|
|
77
|
+
var CONTROL_CHARS = /[\x00-\x1f]/;
|
|
78
|
+
var CONTEXT_BREAK = /[{};]/;
|
|
79
|
+
var sanitizeCssValue = (value) => {
|
|
80
|
+
if (typeof value !== "string") {
|
|
81
|
+
return { ok: false, value: "", reason: "not-a-string" };
|
|
82
|
+
}
|
|
83
|
+
const raw = value;
|
|
84
|
+
if (raw.length === 0) {
|
|
85
|
+
return { ok: false, value: "", reason: "empty" };
|
|
86
|
+
}
|
|
87
|
+
if (CONTROL_CHARS.test(raw)) {
|
|
88
|
+
return { ok: false, value: raw, reason: "control-char" };
|
|
89
|
+
}
|
|
90
|
+
if (CONTEXT_BREAK.test(raw)) {
|
|
91
|
+
return { ok: false, value: raw, reason: "context-break-char" };
|
|
92
|
+
}
|
|
93
|
+
const lower = raw.toLowerCase();
|
|
94
|
+
const collapsed = lower.replace(/\s+/g, "");
|
|
95
|
+
if (collapsed.includes("@import")) {
|
|
96
|
+
return { ok: false, value: raw, reason: "at-import" };
|
|
97
|
+
}
|
|
98
|
+
if (collapsed.includes("javascript:")) {
|
|
99
|
+
return { ok: false, value: raw, reason: "javascript-scheme" };
|
|
100
|
+
}
|
|
101
|
+
if (collapsed.includes("</")) {
|
|
102
|
+
return { ok: false, value: raw, reason: "markup-break" };
|
|
103
|
+
}
|
|
104
|
+
FUNCTION_CALL.lastIndex = 0;
|
|
105
|
+
let match;
|
|
106
|
+
while ((match = FUNCTION_CALL.exec(raw)) !== null) {
|
|
107
|
+
const name = match[1].toLowerCase();
|
|
108
|
+
if (!ALLOWED_FUNCTIONS.has(name)) {
|
|
109
|
+
return { ok: false, value: raw, reason: `disallowed-function:${name}` };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, value: raw };
|
|
113
|
+
};
|
|
114
|
+
|
|
55
115
|
// src/apply.js
|
|
116
|
+
var warnRejected = (key, reason) => {
|
|
117
|
+
try {
|
|
118
|
+
if (typeof process !== "undefined" && process.env && true) {
|
|
119
|
+
console.warn(
|
|
120
|
+
`[sorb] skipped token "--${key}": value failed CSS sanitization` + (reason ? ` (${reason})` : "")
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
} catch (e) {
|
|
124
|
+
}
|
|
125
|
+
};
|
|
56
126
|
var applyTokens = (tokens) => {
|
|
57
127
|
const root = document.documentElement;
|
|
58
128
|
Object.entries(tokens).forEach(([key, value]) => {
|
|
59
|
-
|
|
129
|
+
const result = sanitizeCssValue(String(value));
|
|
130
|
+
if (!result.ok) {
|
|
131
|
+
warnRejected(key, result.reason);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
root.style.setProperty(`--${key}`, result.value);
|
|
60
135
|
});
|
|
61
136
|
};
|
|
62
137
|
|
|
138
|
+
// src/previewGuard.js
|
|
139
|
+
var DEFAULT_ORIGIN = "http://localhost:7777";
|
|
140
|
+
var isLocalhostOrigin = (origin) => {
|
|
141
|
+
let url;
|
|
142
|
+
try {
|
|
143
|
+
url = new URL(origin);
|
|
144
|
+
} catch (e) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
148
|
+
const host = url.hostname.toLowerCase();
|
|
149
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
150
|
+
};
|
|
151
|
+
var toOrigin = (value) => {
|
|
152
|
+
try {
|
|
153
|
+
return new URL(value).origin;
|
|
154
|
+
} catch (e) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
var shouldLoadPreview = (config) => {
|
|
159
|
+
const preview = config && config.preview;
|
|
160
|
+
if (!preview || preview.enabled !== true) {
|
|
161
|
+
return { allowed: false, origin: null, reason: "preview-disabled" };
|
|
162
|
+
}
|
|
163
|
+
const origin = preview.origin ?? DEFAULT_ORIGIN;
|
|
164
|
+
const normalized = toOrigin(origin);
|
|
165
|
+
if (!normalized) {
|
|
166
|
+
return { allowed: false, origin: null, reason: "malformed-origin" };
|
|
167
|
+
}
|
|
168
|
+
if (isLocalhostOrigin(origin)) {
|
|
169
|
+
return { allowed: true, origin };
|
|
170
|
+
}
|
|
171
|
+
const extra = Array.isArray(preview.allowedOrigins) ? preview.allowedOrigins : [];
|
|
172
|
+
const allowed = extra.some((entry) => toOrigin(entry) === normalized);
|
|
173
|
+
if (allowed) {
|
|
174
|
+
return { allowed: true, origin };
|
|
175
|
+
}
|
|
176
|
+
return { allowed: false, origin, reason: "origin-not-allowlisted" };
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// src/bridgeAuth.js
|
|
180
|
+
var bridgeHeaders = (key, base) => {
|
|
181
|
+
const headers = base ? { ...base } : {};
|
|
182
|
+
if (typeof key === "string" && key.trim() !== "") {
|
|
183
|
+
headers.Authorization = `Bearer ${key.trim()}`;
|
|
184
|
+
}
|
|
185
|
+
return headers;
|
|
186
|
+
};
|
|
187
|
+
|
|
63
188
|
// src/TokenProvider.jsx
|
|
64
189
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
190
|
+
var devWarn = (msg) => {
|
|
191
|
+
try {
|
|
192
|
+
if (typeof process !== "undefined" && process.env && true) {
|
|
193
|
+
console.warn(`[sorb] ${msg}`);
|
|
194
|
+
}
|
|
195
|
+
} catch (e) {
|
|
196
|
+
}
|
|
197
|
+
};
|
|
65
198
|
var SorbProvider = ({ config, children }) => {
|
|
66
199
|
const [activeTokens, setActiveTokens] = (0, import_react2.useState)(config.tokens);
|
|
67
200
|
const [isPreview, setIsPreview] = (0, import_react2.useState)(false);
|
|
@@ -75,9 +208,16 @@ var SorbProvider = ({ config, children }) => {
|
|
|
75
208
|
}, [config.tokens]);
|
|
76
209
|
const loadPreview = (0, import_react2.useCallback)(
|
|
77
210
|
async (id) => {
|
|
78
|
-
const
|
|
211
|
+
const guard = shouldLoadPreview(config);
|
|
212
|
+
if (!guard.allowed) {
|
|
213
|
+
loadCommitted();
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
const origin = guard.origin;
|
|
79
217
|
try {
|
|
80
|
-
const res = await fetch(`${origin}/preview/${id}
|
|
218
|
+
const res = await fetch(`${origin}/preview/${id}`, {
|
|
219
|
+
headers: bridgeHeaders(config.preview?.key)
|
|
220
|
+
});
|
|
81
221
|
if (!res.ok) throw new Error("preview not found");
|
|
82
222
|
const tokens = await res.json();
|
|
83
223
|
applyTokens(tokens);
|
|
@@ -85,12 +225,12 @@ var SorbProvider = ({ config, children }) => {
|
|
|
85
225
|
setIsPreview(true);
|
|
86
226
|
setPreviewId(id);
|
|
87
227
|
return true;
|
|
88
|
-
} catch {
|
|
228
|
+
} catch (e) {
|
|
89
229
|
loadCommitted();
|
|
90
230
|
return false;
|
|
91
231
|
}
|
|
92
232
|
},
|
|
93
|
-
[config
|
|
233
|
+
[config, loadCommitted]
|
|
94
234
|
);
|
|
95
235
|
const clearPreview = (0, import_react2.useCallback)(() => {
|
|
96
236
|
if (pollRef.current) clearInterval(pollRef.current);
|
|
@@ -101,9 +241,14 @@ var SorbProvider = ({ config, children }) => {
|
|
|
101
241
|
loadCommitted();
|
|
102
242
|
}, [loadCommitted]);
|
|
103
243
|
(0, import_react2.useEffect)(() => {
|
|
104
|
-
const
|
|
244
|
+
const guard = shouldLoadPreview(config);
|
|
105
245
|
const id = new URLSearchParams(location.search).get("preview");
|
|
106
|
-
if (!
|
|
246
|
+
if (!guard.allowed || !id) {
|
|
247
|
+
if (id && !guard.allowed) {
|
|
248
|
+
devWarn(
|
|
249
|
+
`ignoring ?preview= \u2014 preview not permitted (${guard.reason ?? "blocked"}); loading committed tokens`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
107
252
|
loadCommitted();
|
|
108
253
|
return;
|
|
109
254
|
}
|
|
@@ -214,4 +359,49 @@ var PreviewBanner = () => {
|
|
|
214
359
|
}
|
|
215
360
|
);
|
|
216
361
|
};
|
|
362
|
+
|
|
363
|
+
// src/verify.js
|
|
364
|
+
var toCssVar = (name) => {
|
|
365
|
+
const s = String(name).trim();
|
|
366
|
+
return s.startsWith("--") ? s : `--${s}`;
|
|
367
|
+
};
|
|
368
|
+
var verifyResolved = async (tokens, { origin = "http://localhost:7777", key, fetch: fetchImpl } = {}) => {
|
|
369
|
+
if (typeof document === "undefined" || !document.documentElement) {
|
|
370
|
+
return { ok: false, reason: "no-dom" };
|
|
371
|
+
}
|
|
372
|
+
if (!Array.isArray(tokens) || tokens.length === 0) {
|
|
373
|
+
return { ok: false, reason: "no-tokens" };
|
|
374
|
+
}
|
|
375
|
+
const cs = getComputedStyle(document.documentElement);
|
|
376
|
+
const values = {};
|
|
377
|
+
for (const t of tokens) {
|
|
378
|
+
const cssVar = toCssVar(t);
|
|
379
|
+
values[cssVar] = cs.getPropertyValue(cssVar).trim();
|
|
380
|
+
}
|
|
381
|
+
const unapplied = Object.entries(values).filter(([, v]) => v.startsWith("var(")).map(([k]) => k);
|
|
382
|
+
if (unapplied.length) return { ok: false, reason: "provider-not-applied", unapplied };
|
|
383
|
+
const f = fetchImpl || (typeof fetch !== "undefined" ? fetch : globalThis.fetch);
|
|
384
|
+
if (typeof f !== "function") return { ok: false, reason: "no-fetch" };
|
|
385
|
+
const base = String(origin).replace(/\/+$/, "");
|
|
386
|
+
try {
|
|
387
|
+
const res = await f(`${base}/verify/app`, {
|
|
388
|
+
method: "POST",
|
|
389
|
+
// Hosted bridge needs the bearer key; localhost (no key) sends no header.
|
|
390
|
+
headers: bridgeHeaders(key, { "Content-Type": "application/json" }),
|
|
391
|
+
body: JSON.stringify({ values })
|
|
392
|
+
});
|
|
393
|
+
if (!res.ok) {
|
|
394
|
+
let detail = "";
|
|
395
|
+
try {
|
|
396
|
+
const b = await res.json();
|
|
397
|
+
detail = b && b.error ? b.error : "";
|
|
398
|
+
} catch (e) {
|
|
399
|
+
}
|
|
400
|
+
return { ok: false, reason: "bridge-error", error: `${res.status}${detail ? ` \u2014 ${detail}` : ""}` };
|
|
401
|
+
}
|
|
402
|
+
return await res.json();
|
|
403
|
+
} catch (e) {
|
|
404
|
+
return { ok: false, reason: "bridge-unreachable", error: e && e.message };
|
|
405
|
+
}
|
|
406
|
+
};
|
|
217
407
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.js", "../src/TokenProvider.jsx", "../src/context.js", "../src/apply.js", "../src/PreviewBanner.jsx", "../src/hooks.js"],
|
|
4
|
-
"sourcesContent": ["export { SorbProvider } from './TokenProvider'\nexport { PreviewBanner } from './PreviewBanner'\nexport { useTokens, useToken, useIsPreview, usePreviewState } from './hooks'\n", "import React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { TokenContext } from './context'\nimport { applyTokens } from './apply'\n\n/**\n * @param {{ config: import('./types').SorbConfig, children: React.ReactNode }} props\n */\nexport const SorbProvider = ({ config, children }) => {\n const [activeTokens, setActiveTokens] = useState(config.tokens)\n const [isPreview, setIsPreview] = useState(false)\n const [previewId, setPreviewId] = useState(null)\n const pollRef = useRef(null)\n\n // \u2500\u2500\u2500 committed token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadCommitted = useCallback(() => {\n applyTokens(config.tokens)\n setActiveTokens(config.tokens)\n setIsPreview(false)\n setPreviewId(null)\n }, [config.tokens])\n\n // \u2500\u2500\u2500 preview token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadPreview = useCallback(\n async (id) => {\n const origin = config.preview?.origin ?? 'http://localhost:7777'\n try {\n const res = await fetch(`${origin}/preview/${id}`)\n if (!res.ok) throw new Error('preview not found')\n const tokens = await res.json()\n applyTokens(tokens)\n setActiveTokens(tokens)\n setIsPreview(true)\n setPreviewId(id)\n return true\n } catch {\n // local server not running, preview expired, or network error\n // fall back silently \u2014 never break the app\n loadCommitted()\n return false\n }\n },\n [config.preview?.origin, loadCommitted],\n )\n\n // \u2500\u2500\u2500 clear preview + remove query param \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const clearPreview = useCallback(() => {\n if (pollRef.current) clearInterval(pollRef.current)\n const params = new URLSearchParams(location.search)\n params.delete('preview')\n const qs = params.toString()\n history.replaceState(null, '', qs ? `?${qs}` : location.pathname)\n loadCommitted()\n }, [loadCommitted])\n\n // \u2500\u2500\u2500 initialise on mount \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n useEffect(() => {\n const previewEnabled = config.preview?.enabled ?? false\n const id = new URLSearchParams(location.search).get('preview')\n\n // bail out immediately if preview is disabled or no param present\n if (!previewEnabled || !id) {\n loadCommitted()\n return\n }\n\n // load the preview, then start polling so Figma changes reflect live\n loadPreview(id).then((ok) => {\n if (!ok) return\n const interval = config.preview?.pollInterval ?? 1500\n pollRef.current = setInterval(() => loadPreview(id), interval)\n })\n\n return () => {\n if (pollRef.current) clearInterval(pollRef.current)\n }\n }, []) // intentionally empty \u2014 only runs on mount\n\n return (\n <TokenContext.Provider value={{ tokens: activeTokens, isPreview, previewId, clearPreview }}>\n {children}\n </TokenContext.Provider>\n )\n}\n", "import { createContext, useContext } from 'react'\n\n/** @type {import('react').Context<import('./types').TokenContextValue | null>} */\nexport const TokenContext = createContext(null)\n\n/** @returns {import('./types').TokenContextValue} */\nexport const useTokenContext = () => {\n const ctx = useContext(TokenContext)\n if (!ctx) {\n throw new Error('Sorb hooks must be used inside <SorbProvider>')\n }\n return ctx\n}\n", "/**\n * Writes all token values as CSS custom properties on :root.\n * Applies globally \u2014 affects the entire app.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const applyTokens = (tokens) => {\n const root = document.documentElement\n Object.entries(tokens).forEach(([key, value]) => {\n root.style.setProperty(`--${key}`, String(value))\n })\n}\n\n/**\n * Removes token CSS custom properties from :root.\n * Called when clearing a preview to restore the committed set.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const clearTokenOverrides = (tokens) => {\n const root = document.documentElement\n Object.keys(tokens).forEach((key) => {\n root.style.removeProperty(`--${key}`)\n })\n}\n", "import React from 'react'\nimport { usePreviewState } from './hooks'\n\n/**\n * Drop-in banner that appears at the bottom of the screen when a\n * Sorb preview is active. Includes an \"Exit preview\" button.\n *\n * Only renders when preview.enabled is true AND a preview is loaded.\n * Safe to include unconditionally \u2014 renders nothing in production.\n *\n * @example\n * // In your app root, after <SorbProvider>\n * <PreviewBanner />\n */\nexport const PreviewBanner = () => {\n const { isPreview, previewId, clearPreview } = usePreviewState()\n if (!isPreview) return null\n\n return (\n <div\n role=\"status\"\n aria-live=\"polite\"\n style={{\n position: 'fixed',\n bottom: 0,\n left: 0,\n right: 0,\n background: '#3B5BDB',\n color: '#fff',\n padding: '10px 20px',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '12px',\n fontSize: '13px',\n lineHeight: '1.4',\n zIndex: 99999,\n fontFamily:\n 'system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif',\n boxShadow: '0 -2px 12px rgba(0,0,0,0.15)',\n }}\n >\n <span>\n <strong style={{ fontWeight: 600 }}>Sorb preview active</strong>\n {previewId && (\n <code\n style={{\n marginLeft: '8px',\n opacity: 0.75,\n fontSize: '11px',\n background: 'rgba(255,255,255,0.15)',\n padding: '2px 6px',\n borderRadius: '4px',\n }}\n >\n {previewId}\n </code>\n )}\n <span style={{ marginLeft: '8px', opacity: 0.75, fontSize: '12px' }}>\n Token changes from Figma are live\n </span>\n </span>\n <button\n onClick={clearPreview}\n style={{\n flexShrink: 0,\n background: 'rgba(255,255,255,0.2)',\n border: '1px solid rgba(255,255,255,0.3)',\n color: '#fff',\n padding: '5px 14px',\n borderRadius: '6px',\n cursor: 'pointer',\n fontSize: '12px',\n fontWeight: 500,\n transition: 'background 0.15s',\n }}\n onMouseEnter={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.3)')\n }\n onMouseLeave={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.2)')\n }\n >\n Exit preview\n </button>\n </div>\n )\n}\n", "import { useTokenContext } from './context'\n\n/**\n * Returns the full active token set (committed or preview).\n * @returns {import('./types').TokenSet}\n */\nexport const useTokens = () => {\n return useTokenContext().tokens\n}\n\n/**\n * Returns a single token value by key.\n *\n * @param {string} key\n * @returns {string}\n * @example\n * const primary = useToken('color-primary') // \u2192 '#3B5BDB'\n */\nexport const useToken = (key) => {\n const tokens = useTokenContext().tokens\n const value = tokens[key]\n if (value === undefined && process.env.NODE_ENV === 'development') {\n console.warn(`[Sorb] Token not found: \"${key}\"`)\n }\n return String(value ?? '')\n}\n\n/**\n * Returns whether a preview token set is currently active.\n * Useful for showing a preview indicator in your app.\n * @returns {boolean}\n */\nexport const useIsPreview = () => {\n return useTokenContext().isPreview\n}\n\n/**\n * Returns full preview state \u2014 useful for building a preview banner.\n *\n * @example\n * const { isPreview, previewId, clearPreview } = usePreviewState()\n */\nexport const usePreviewState = () => {\n const { isPreview, previewId, clearPreview } = useTokenContext()\n return { isPreview, previewId, clearPreview }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAgE;;;ACAhE,mBAA0C;AAGnC,IAAM,mBAAe,4BAAc,IAAI;AAGvC,IAAM,kBAAkB,MAAM;AACnC,QAAM,UAAM,yBAAW,YAAY;AACnC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,SAAO;AACT;;;
|
|
3
|
+
"sources": ["../src/index.js", "../src/TokenProvider.jsx", "../src/context.js", "../src/sanitize.js", "../src/apply.js", "../src/previewGuard.js", "../src/bridgeAuth.js", "../src/PreviewBanner.jsx", "../src/hooks.js", "../src/verify.js"],
|
|
4
|
+
"sourcesContent": ["export { SorbProvider } from './TokenProvider'\nexport { PreviewBanner } from './PreviewBanner'\nexport { useTokens, useToken, useIsPreview, usePreviewState } from './hooks'\nexport { sanitizeCssValue } from './sanitize'\nexport { verifyResolved } from './verify'\n", "import React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { TokenContext } from './context'\nimport { applyTokens } from './apply'\nimport { shouldLoadPreview } from './previewGuard'\nimport { bridgeHeaders } from './bridgeAuth'\n\n/**\n * Dev-only warning that never throws in a browser (no `process` global there).\n * @param {string} msg\n * @returns {void}\n */\nconst devWarn = (msg) => {\n try {\n if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(`[sorb] ${msg}`)\n }\n } catch (e) {\n void e\n }\n}\n\n/**\n * @param {{ config: import('./types').SorbConfig, children: React.ReactNode }} props\n */\nexport const SorbProvider = ({ config, children }) => {\n const [activeTokens, setActiveTokens] = useState(config.tokens)\n const [isPreview, setIsPreview] = useState(false)\n const [previewId, setPreviewId] = useState(null)\n const pollRef = useRef(null)\n\n // \u2500\u2500\u2500 committed token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadCommitted = useCallback(() => {\n applyTokens(config.tokens)\n setActiveTokens(config.tokens)\n setIsPreview(false)\n setPreviewId(null)\n }, [config.tokens])\n\n // \u2500\u2500\u2500 preview token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadPreview = useCallback(\n async (id) => {\n // Re-check the guard here too: loadPreview must never fetch an\n // untrusted origin even if called directly. Use the guard-resolved\n // origin, not the raw config, so the trust decision is single-sourced.\n const guard = shouldLoadPreview(config)\n if (!guard.allowed) {\n loadCommitted()\n return false\n }\n const origin = guard.origin\n try {\n // Hosted bridge needs `Authorization: Bearer <config.preview.key>`;\n // when no key is configured (localhost `sorb dev`) NO header is sent\n // and this call is unchanged.\n const res = await fetch(`${origin}/preview/${id}`, {\n headers: bridgeHeaders(config.preview?.key),\n })\n if (!res.ok) throw new Error('preview not found')\n const tokens = await res.json()\n applyTokens(tokens)\n setActiveTokens(tokens)\n setIsPreview(true)\n setPreviewId(id)\n return true\n } catch (e) {\n // local server not running, preview expired, or network error\n // fall back silently \u2014 never break the app\n void e\n loadCommitted()\n return false\n }\n },\n [config, loadCommitted],\n )\n\n // \u2500\u2500\u2500 clear preview + remove query param \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const clearPreview = useCallback(() => {\n if (pollRef.current) clearInterval(pollRef.current)\n const params = new URLSearchParams(location.search)\n params.delete('preview')\n const qs = params.toString()\n history.replaceState(null, '', qs ? `?${qs}` : location.pathname)\n loadCommitted()\n }, [loadCommitted])\n\n // \u2500\u2500\u2500 initialise on mount \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n useEffect(() => {\n const guard = shouldLoadPreview(config)\n const id = new URLSearchParams(location.search).get('preview')\n\n // Preview only runs when the origin-allowlist guard says so (C3). A stray\n // `?preview=` on a production deploy against an untrusted origin is ignored\n // \u2014 we load committed tokens and dev-warn instead.\n if (!guard.allowed || !id) {\n if (id && !guard.allowed) {\n devWarn(\n `ignoring ?preview= \u2014 preview not permitted (${guard.reason ?? 'blocked'}); ` +\n 'loading committed tokens',\n )\n }\n loadCommitted()\n return\n }\n\n // load the preview, then start polling so Figma changes reflect live\n loadPreview(id).then((ok) => {\n if (!ok) return\n const interval = config.preview?.pollInterval ?? 1500\n pollRef.current = setInterval(() => loadPreview(id), interval)\n })\n\n return () => {\n if (pollRef.current) clearInterval(pollRef.current)\n }\n }, []) // intentionally empty \u2014 only runs on mount\n\n return (\n <TokenContext.Provider value={{ tokens: activeTokens, isPreview, previewId, clearPreview }}>\n {children}\n </TokenContext.Provider>\n )\n}\n", "import { createContext, useContext } from 'react'\n\n/** @type {import('react').Context<import('./types').TokenContextValue | null>} */\nexport const TokenContext = createContext(null)\n\n/** @returns {import('./types').TokenContextValue} */\nexport const useTokenContext = () => {\n const ctx = useContext(TokenContext)\n if (!ctx) {\n throw new Error('Sorb hooks must be used inside <SorbProvider>')\n }\n return ctx\n}\n", "/**\n * CSS token-value sanitizer \u2014 the C1 injection-boundary guard.\n *\n * Token values flow Figma \u2192 bridge \u2192 `applyTokens` \u2192 `setProperty`. Those values\n * are UNTRUSTED INPUT crossing a trust boundary. This is a pure string function\n * (no DOM) so it is fully node:test-able and reusable. Phase 2 will hoist it to\n * `@sorb/core`; do NOT add a DOM dependency here.\n *\n * Strategy: deny-by-default on the dangerous classes, then allowlist CSS\n * functions. A *valid* hostile value (a real `url(...)`) passes `setProperty`\n * unharmed, so we cannot rely on the browser \u2014 we reject it here.\n */\n\n/**\n * The only CSS functions we permit inside a token value. Anything else \u2014\n * `url(`, `image(`, `image-set(`, `-webkit-image-set(`, `cross-fade(`,\n * `expression(`, `paint(`, `element(`, `attr(`, \u2026 \u2014 is rejected.\n * @type {Set<string>}\n */\nconst ALLOWED_FUNCTIONS = new Set([\n 'rgb',\n 'rgba',\n 'hsl',\n 'hsla',\n 'hwb',\n 'lab',\n 'lch',\n 'oklab',\n 'oklch',\n 'color',\n 'calc',\n 'min',\n 'max',\n 'clamp',\n 'var',\n 'env',\n])\n\n// Matches an identifier immediately followed by '(' \u2014 i.e. a CSS function call.\n// Identifiers may start with one or two leading hyphens (vendor prefixes like\n// `-webkit-image-set`). The lookahead keeps the '(' out of the captured name.\nconst FUNCTION_CALL = /([a-zA-Z_-][\\w-]*)\\s*\\(/g\n\n// ASCII control chars (incl. NUL, newlines, tabs) \u2014 never legitimate in a\n// token value and a classic way to smuggle past naive filters.\n// eslint-disable-next-line no-control-regex\nconst CONTROL_CHARS = /[\\x00-\\x1f]/\n\n// CSS-context-break characters that let a value escape the custom-property\n// declaration: `;` ends the declaration, `{` / `}` open/close a block.\nconst CONTEXT_BREAK = /[{};]/\n\n/**\n * Validate an untrusted CSS token value before it is injected via\n * `setProperty`. Pure \u2014 does not touch the DOM.\n *\n * Rules (deny-by-default):\n * - non-string / empty input is rejected.\n * - reject ASCII control chars `\\x00-\\x1f`.\n * - reject the context-break chars `{` `}` `;`.\n * - reject (case-insensitive, whitespace-tolerant) `@import`, `javascript:`,\n * and the markup-break `</`.\n * - extract every `identifier(` and reject if ANY is not in the allowlist\n * (this is what stops `url(`, `image-set(`, `expression(`, `paint(`, \u2026).\n *\n * @param {unknown} value\n * @returns {{ ok: boolean, value: string, reason?: string }}\n */\nexport const sanitizeCssValue = (value) => {\n if (typeof value !== 'string') {\n return { ok: false, value: '', reason: 'not-a-string' }\n }\n\n const raw = value\n if (raw.length === 0) {\n return { ok: false, value: '', reason: 'empty' }\n }\n\n if (CONTROL_CHARS.test(raw)) {\n return { ok: false, value: raw, reason: 'control-char' }\n }\n\n if (CONTEXT_BREAK.test(raw)) {\n return { ok: false, value: raw, reason: 'context-break-char' }\n }\n\n // Case-insensitive, whitespace-tolerant dangerous tokens. We strip ASCII\n // whitespace before substring-matching so `@ import`, `java script:`,\n // `< /script` style evasions are still caught.\n const lower = raw.toLowerCase()\n const collapsed = lower.replace(/\\s+/g, '')\n if (collapsed.includes('@import')) {\n return { ok: false, value: raw, reason: 'at-import' }\n }\n if (collapsed.includes('javascript:')) {\n return { ok: false, value: raw, reason: 'javascript-scheme' }\n }\n if (collapsed.includes('</')) {\n return { ok: false, value: raw, reason: 'markup-break' }\n }\n\n // Allowlist every function call in the value.\n FUNCTION_CALL.lastIndex = 0\n let match\n while ((match = FUNCTION_CALL.exec(raw)) !== null) {\n const name = match[1].toLowerCase()\n if (!ALLOWED_FUNCTIONS.has(name)) {\n return { ok: false, value: raw, reason: `disallowed-function:${name}` }\n }\n }\n\n return { ok: true, value: raw }\n}\n", "import { sanitizeCssValue } from './sanitize.js'\n\n/**\n * Dev-only warning that never throws in a browser (no `process` global there).\n * Silent in production so a hostile token can't spam a shipped app's console.\n *\n * @param {string} key\n * @param {string} [reason]\n * @returns {void}\n */\nconst warnRejected = (key, reason) => {\n try {\n if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(\n `[sorb] skipped token \"--${key}\": value failed CSS sanitization` +\n (reason ? ` (${reason})` : ''),\n )\n }\n } catch (e) {\n // never let logging break token application\n void e\n }\n}\n\n/**\n * Writes all token values as CSS custom properties on :root.\n * Applies globally \u2014 affects the entire app.\n *\n * Each value is validated by {@link sanitizeCssValue} at this injection\n * boundary (concern C1). A value that fails sanitization is SKIPPED (fail\n * safe) \u2014 it is never written \u2014 and the remaining tokens still apply.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const applyTokens = (tokens) => {\n const root = document.documentElement\n Object.entries(tokens).forEach(([key, value]) => {\n const result = sanitizeCssValue(String(value))\n if (!result.ok) {\n warnRejected(key, result.reason)\n return\n }\n root.style.setProperty(`--${key}`, result.value)\n })\n}\n\n/**\n * Removes token CSS custom properties from :root.\n * Called when clearing a preview to restore the committed set.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const clearTokenOverrides = (tokens) => {\n const root = document.documentElement\n Object.keys(tokens).forEach((key) => {\n root.style.removeProperty(`--${key}`)\n })\n}\n", "/**\n * Preview-origin guard \u2014 the C3 production foot-gun guard.\n *\n * Preview defaults OFF. Even when a team opts in, the SDK must only talk to a\n * TRUSTED bridge origin: a stray `?preview=` on a production link must not be\n * able to point the running app at an untrusted bridge. This pure helper makes\n * that decision; the provider wires it in. No DOM, fully node:test-able.\n */\n\nconst DEFAULT_ORIGIN = 'http://localhost:7777'\n\n/**\n * Is `origin` a localhost / loopback origin (any port)? `http`/`https`,\n * `localhost`, `127.0.0.1`, and IPv6 `[::1]` all count.\n *\n * @param {string} origin\n * @returns {boolean}\n */\nconst isLocalhostOrigin = (origin) => {\n let url\n try {\n url = new URL(origin)\n } catch (e) {\n void e\n return false\n }\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return false\n const host = url.hostname.toLowerCase()\n return host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]'\n}\n\n/**\n * Normalise to a bare `protocol//host:port` origin for exact comparison\n * against a consumer-supplied allowlist (trailing slashes / paths ignored).\n *\n * @param {string} value\n * @returns {string|null}\n */\nconst toOrigin = (value) => {\n try {\n return new URL(value).origin\n } catch (e) {\n void e\n return null\n }\n}\n\n/**\n * Decide whether the preview path may run, and against which origin.\n *\n * Allowed only when BOTH:\n * 1. `config.preview?.enabled === true` (strict \u2014 not just truthy), and\n * 2. the resolved origin is on the allowlist: localhost/127.0.0.1/[::1]\n * (any port) by default, plus any exact origins the consumer lists in\n * `config.preview.allowedOrigins`.\n *\n * Anything else (disabled, missing config, non-allowlisted origin, malformed\n * origin) \u2192 not allowed; the caller falls back to committed tokens.\n *\n * @param {import('./types').SorbConfig} [config]\n * @returns {{ allowed: boolean, origin: string|null, reason?: string }}\n */\nexport const shouldLoadPreview = (config) => {\n const preview = config && config.preview\n if (!preview || preview.enabled !== true) {\n return { allowed: false, origin: null, reason: 'preview-disabled' }\n }\n\n const origin = preview.origin ?? DEFAULT_ORIGIN\n const normalized = toOrigin(origin)\n if (!normalized) {\n return { allowed: false, origin: null, reason: 'malformed-origin' }\n }\n\n if (isLocalhostOrigin(origin)) {\n return { allowed: true, origin }\n }\n\n const extra = Array.isArray(preview.allowedOrigins) ? preview.allowedOrigins : []\n const allowed = extra.some((entry) => toOrigin(entry) === normalized)\n if (allowed) {\n return { allowed: true, origin }\n }\n\n return { allowed: false, origin, reason: 'origin-not-allowlisted' }\n}\n", "// bridgeAuth.js \u2014 hosted-bridge Authorization header (Plugin-UX U4).\n//\n// Sorb's hosted bridge (https://bridge.sorbcloud.com) requires\n// `Authorization: Bearer <key>` on every route except /health. The key is a\n// read-only publishable `sorb_pk_\u2026` (safe to ship in a distributable; 403s on\n// writes). Local `sorb dev` runs with NO auth, so when no key is configured we\n// send NO header and the localhost path is byte-for-byte unchanged.\n//\n// One place builds the header so both fetch sites (TokenProvider preview poll +\n// verify.js) stay consistent. Pure + node:test-able; no DOM, no fetch.\n\n/**\n * Build the request headers for a hosted-bridge call, merging in the bearer\n * `Authorization` header only when a non-empty key is configured.\n *\n * @param {string} [key] The configured bearer key (`config.preview.key`), if any.\n * @param {Record<string,string>} [base] Base headers to extend (e.g. Content-Type).\n * @returns {Record<string,string>}\n */\nexport const bridgeHeaders = (key, base) => {\n const headers = base ? { ...base } : {}\n if (typeof key === 'string' && key.trim() !== '') {\n headers.Authorization = `Bearer ${key.trim()}`\n }\n return headers\n}\n", "import React from 'react'\nimport { usePreviewState } from './hooks'\n\n/**\n * Drop-in banner that appears at the bottom of the screen when a\n * Sorb preview is active. Includes an \"Exit preview\" button.\n *\n * Only renders when preview.enabled is true AND a preview is loaded.\n * Safe to include unconditionally \u2014 renders nothing in production.\n *\n * @example\n * // In your app root, after <SorbProvider>\n * <PreviewBanner />\n */\nexport const PreviewBanner = () => {\n const { isPreview, previewId, clearPreview } = usePreviewState()\n if (!isPreview) return null\n\n return (\n <div\n role=\"status\"\n aria-live=\"polite\"\n style={{\n position: 'fixed',\n bottom: 0,\n left: 0,\n right: 0,\n background: '#3B5BDB',\n color: '#fff',\n padding: '10px 20px',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '12px',\n fontSize: '13px',\n lineHeight: '1.4',\n zIndex: 99999,\n fontFamily:\n 'system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif',\n boxShadow: '0 -2px 12px rgba(0,0,0,0.15)',\n }}\n >\n <span>\n <strong style={{ fontWeight: 600 }}>Sorb preview active</strong>\n {previewId && (\n <code\n style={{\n marginLeft: '8px',\n opacity: 0.75,\n fontSize: '11px',\n background: 'rgba(255,255,255,0.15)',\n padding: '2px 6px',\n borderRadius: '4px',\n }}\n >\n {previewId}\n </code>\n )}\n <span style={{ marginLeft: '8px', opacity: 0.75, fontSize: '12px' }}>\n Token changes from Figma are live\n </span>\n </span>\n <button\n onClick={clearPreview}\n style={{\n flexShrink: 0,\n background: 'rgba(255,255,255,0.2)',\n border: '1px solid rgba(255,255,255,0.3)',\n color: '#fff',\n padding: '5px 14px',\n borderRadius: '6px',\n cursor: 'pointer',\n fontSize: '12px',\n fontWeight: 500,\n transition: 'background 0.15s',\n }}\n onMouseEnter={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.3)')\n }\n onMouseLeave={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.2)')\n }\n >\n Exit preview\n </button>\n </div>\n )\n}\n", "import { useTokenContext } from './context'\n\n/**\n * Returns the full active token set (committed or preview).\n * @returns {import('./types').TokenSet}\n */\nexport const useTokens = () => {\n return useTokenContext().tokens\n}\n\n/**\n * Returns a single token value by key.\n *\n * @param {string} key\n * @returns {string}\n * @example\n * const primary = useToken('color-primary') // \u2192 '#3B5BDB'\n */\nexport const useToken = (key) => {\n const tokens = useTokenContext().tokens\n const value = tokens[key]\n if (value === undefined && process.env.NODE_ENV === 'development') {\n console.warn(`[Sorb] Token not found: \"${key}\"`)\n }\n return String(value ?? '')\n}\n\n/**\n * Returns whether a preview token set is currently active.\n * Useful for showing a preview indicator in your app.\n * @returns {boolean}\n */\nexport const useIsPreview = () => {\n return useTokenContext().isPreview\n}\n\n/**\n * Returns full preview state \u2014 useful for building a preview banner.\n *\n * @example\n * const { isPreview, previewId, clearPreview } = usePreviewState()\n */\nexport const usePreviewState = () => {\n const { isPreview, previewId, clearPreview } = useTokenContext()\n return { isPreview, previewId, clearPreview }\n}\n", "// verify.js \u2014 RUNNING-APP token verification (e2e-fix W2).\n//\n// Reports the values the running app ACTUALLY resolved for a set of tokens (read\n// off `:root` \u2014 where SorbProvider's applyTokens wrote the committed/preview\n// values) to the bridge's `POST /verify/app`, which diffs them against the\n// committed resolved map. This is what makes \"verify-before-merge in your running\n// app\" true in code: it asserts the live DOM resolves to the bound token values,\n// not Figma-side geometry.\n//\n// SSR-safe: no DOM \u2192 returns a clear `{ ok:false, reason:'no-dom' }` rather than\n// throwing (safe to call from a server-rendered component's effect). `fetch` is\n// injectable for tests.\n\nimport { bridgeHeaders } from './bridgeAuth.js'\n\n/** Normalize a token name to a `--cssVar`. */\nconst toCssVar = (name) => {\n const s = String(name).trim()\n return s.startsWith('--') ? s : `--${s}`\n}\n\n/**\n * Read each token's resolved value off `:root` and ask the bridge whether the\n * running app matches the committed resolved map.\n *\n * Precondition: call from inside a mounted `<SorbProvider>` \u2014 it applies the\n * resolved token literals onto `:root`. Without it, custom props read back as\n * `var(...)` refs (outputReferences css) and the result is `{ ok:false,\n * reason:'provider-not-applied' }` rather than a misleading mismatch.\n *\n * @param {string[]} tokens Token names or `--cssVar`s to check (e.g. `'button-primary-bg-default'`).\n * @param {{ origin?: string, key?: string, fetch?: typeof globalThis.fetch }} [opts]\n * `key` is the hosted-bridge bearer key (`config.preview.key`). Omit for the\n * no-auth localhost bridge \u2014 no `Authorization` header is then sent.\n * @returns {Promise<{ok:boolean, reason?:string, checked?:number, matched?:number, mismatches?:Array<{cssVar:string,expected:any,got:any}>, unknown?:string[], error?:string}>}\n */\nexport const verifyResolved = async (tokens, { origin = 'http://localhost:7777', key, fetch: fetchImpl } = {}) => {\n if (typeof document === 'undefined' || !document.documentElement) {\n return { ok: false, reason: 'no-dom' }\n }\n if (!Array.isArray(tokens) || tokens.length === 0) {\n return { ok: false, reason: 'no-tokens' }\n }\n const cs = getComputedStyle(document.documentElement)\n /** @type {Record<string,string>} */\n const values = {}\n for (const t of tokens) {\n const cssVar = toCssVar(t)\n values[cssVar] = cs.getPropertyValue(cssVar).trim()\n }\n // Precondition: SorbProvider must have applied the resolved literals onto :root.\n // `variables.css` is built with outputReferences, so an un-applied custom prop\n // reads back as a `var(--\u2026)` reference, not a value \u2014 verifying that is\n // meaningless. Detect it and say so plainly instead of reporting false mismatches.\n const unapplied = Object.entries(values)\n .filter(([, v]) => v.startsWith('var('))\n .map(([k]) => k)\n if (unapplied.length) return { ok: false, reason: 'provider-not-applied', unapplied }\n const f = fetchImpl || (typeof fetch !== 'undefined' ? fetch : globalThis.fetch)\n if (typeof f !== 'function') return { ok: false, reason: 'no-fetch' }\n const base = String(origin).replace(/\\/+$/, '')\n try {\n const res = await f(`${base}/verify/app`, {\n method: 'POST',\n // Hosted bridge needs the bearer key; localhost (no key) sends no header.\n headers: bridgeHeaders(key, { 'Content-Type': 'application/json' }),\n body: JSON.stringify({ values }),\n })\n if (!res.ok) {\n let detail = ''\n try {\n const b = await res.json()\n detail = b && b.error ? b.error : ''\n } catch (e) {\n void e\n }\n return { ok: false, reason: 'bridge-error', error: `${res.status}${detail ? ` \u2014 ${detail}` : ''}` }\n }\n return await res.json()\n } catch (e) {\n // Bridge not running / network error \u2014 never throw into the app.\n return { ok: false, reason: 'bridge-unreachable', error: e && e.message }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAgE;;;ACAhE,mBAA0C;AAGnC,IAAM,mBAAe,4BAAc,IAAI;AAGvC,IAAM,kBAAkB,MAAM;AACnC,QAAM,UAAM,yBAAW,YAAY;AACnC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,SAAO;AACT;;;ACOA,IAAM,oBAAoB,oBAAI,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKD,IAAM,gBAAgB;AAKtB,IAAM,gBAAgB;AAItB,IAAM,gBAAgB;AAkBf,IAAM,mBAAmB,CAAC,UAAU;AACzC,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,EAAE,IAAI,OAAO,OAAO,IAAI,QAAQ,eAAe;AAAA,EACxD;AAEA,QAAM,MAAM;AACZ,MAAI,IAAI,WAAW,GAAG;AACpB,WAAO,EAAE,IAAI,OAAO,OAAO,IAAI,QAAQ,QAAQ;AAAA,EACjD;AAEA,MAAI,cAAc,KAAK,GAAG,GAAG;AAC3B,WAAO,EAAE,IAAI,OAAO,OAAO,KAAK,QAAQ,eAAe;AAAA,EACzD;AAEA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CAAC,EACtC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AACjB,MAAI,UAAU,OAAQ,QAAO,EAAE,IAAI,OAAO,QAAQ,wBAAwB,UAAU;AACpF,QAAM,IAAI,cAAc,OAAO,UAAU,cAAc,QAAQ,WAAW;AAC1E,MAAI,OAAO,MAAM,WAAY,QAAO,EAAE,IAAI,OAAO,QAAQ,WAAW;AACpE,QAAM,OAAO,OAAO,MAAM,EAAE,QAAQ,QAAQ,EAAE;AAC9C,MAAI;AACF,UAAM,MAAM,MAAM,EAAE,GAAG,IAAI,eAAe;AAAA,MACxC,QAAQ;AAAA;AAAA,MAER,SAAS,cAAc,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;AAAA,MAClE,MAAM,KAAK,UAAU,EAAE,OAAO,CAAC;AAAA,IACjC,CAAC;AACD,QAAI,CAAC,IAAI,IAAI;AACX,UAAI,SAAS;AACb,UAAI;AACF,cAAM,IAAI,MAAM,IAAI,KAAK;AACzB,iBAAS,KAAK,EAAE,QAAQ,EAAE,QAAQ;AAAA,MACpC,SAAS,GAAG;AAAA,MAEZ;AACA,aAAO,EAAE,IAAI,OAAO,QAAQ,gBAAgB,OAAO,GAAG,IAAI,MAAM,GAAG,SAAS,WAAM,MAAM,KAAK,EAAE,GAAG;AAAA,IACpG;AACA,WAAO,MAAM,IAAI,KAAK;AAAA,EACxB,SAAS,GAAG;AAEV,WAAO,EAAE,IAAI,OAAO,QAAQ,sBAAsB,OAAO,KAAK,EAAE,QAAQ;AAAA,EAC1E;AACF;",
|
|
6
6
|
"names": ["import_react", "import_react", "import_jsx_runtime"]
|
|
7
7
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -12,16 +12,147 @@ var useTokenContext = () => {
|
|
|
12
12
|
return ctx;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
// src/sanitize.js
|
|
16
|
+
var ALLOWED_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
17
|
+
"rgb",
|
|
18
|
+
"rgba",
|
|
19
|
+
"hsl",
|
|
20
|
+
"hsla",
|
|
21
|
+
"hwb",
|
|
22
|
+
"lab",
|
|
23
|
+
"lch",
|
|
24
|
+
"oklab",
|
|
25
|
+
"oklch",
|
|
26
|
+
"color",
|
|
27
|
+
"calc",
|
|
28
|
+
"min",
|
|
29
|
+
"max",
|
|
30
|
+
"clamp",
|
|
31
|
+
"var",
|
|
32
|
+
"env"
|
|
33
|
+
]);
|
|
34
|
+
var FUNCTION_CALL = /([a-zA-Z_-][\w-]*)\s*\(/g;
|
|
35
|
+
var CONTROL_CHARS = /[\x00-\x1f]/;
|
|
36
|
+
var CONTEXT_BREAK = /[{};]/;
|
|
37
|
+
var sanitizeCssValue = (value) => {
|
|
38
|
+
if (typeof value !== "string") {
|
|
39
|
+
return { ok: false, value: "", reason: "not-a-string" };
|
|
40
|
+
}
|
|
41
|
+
const raw = value;
|
|
42
|
+
if (raw.length === 0) {
|
|
43
|
+
return { ok: false, value: "", reason: "empty" };
|
|
44
|
+
}
|
|
45
|
+
if (CONTROL_CHARS.test(raw)) {
|
|
46
|
+
return { ok: false, value: raw, reason: "control-char" };
|
|
47
|
+
}
|
|
48
|
+
if (CONTEXT_BREAK.test(raw)) {
|
|
49
|
+
return { ok: false, value: raw, reason: "context-break-char" };
|
|
50
|
+
}
|
|
51
|
+
const lower = raw.toLowerCase();
|
|
52
|
+
const collapsed = lower.replace(/\s+/g, "");
|
|
53
|
+
if (collapsed.includes("@import")) {
|
|
54
|
+
return { ok: false, value: raw, reason: "at-import" };
|
|
55
|
+
}
|
|
56
|
+
if (collapsed.includes("javascript:")) {
|
|
57
|
+
return { ok: false, value: raw, reason: "javascript-scheme" };
|
|
58
|
+
}
|
|
59
|
+
if (collapsed.includes("</")) {
|
|
60
|
+
return { ok: false, value: raw, reason: "markup-break" };
|
|
61
|
+
}
|
|
62
|
+
FUNCTION_CALL.lastIndex = 0;
|
|
63
|
+
let match;
|
|
64
|
+
while ((match = FUNCTION_CALL.exec(raw)) !== null) {
|
|
65
|
+
const name = match[1].toLowerCase();
|
|
66
|
+
if (!ALLOWED_FUNCTIONS.has(name)) {
|
|
67
|
+
return { ok: false, value: raw, reason: `disallowed-function:${name}` };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { ok: true, value: raw };
|
|
71
|
+
};
|
|
72
|
+
|
|
15
73
|
// src/apply.js
|
|
74
|
+
var warnRejected = (key, reason) => {
|
|
75
|
+
try {
|
|
76
|
+
if (typeof process !== "undefined" && process.env && true) {
|
|
77
|
+
console.warn(
|
|
78
|
+
`[sorb] skipped token "--${key}": value failed CSS sanitization` + (reason ? ` (${reason})` : "")
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
} catch (e) {
|
|
82
|
+
}
|
|
83
|
+
};
|
|
16
84
|
var applyTokens = (tokens) => {
|
|
17
85
|
const root = document.documentElement;
|
|
18
86
|
Object.entries(tokens).forEach(([key, value]) => {
|
|
19
|
-
|
|
87
|
+
const result = sanitizeCssValue(String(value));
|
|
88
|
+
if (!result.ok) {
|
|
89
|
+
warnRejected(key, result.reason);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
root.style.setProperty(`--${key}`, result.value);
|
|
20
93
|
});
|
|
21
94
|
};
|
|
22
95
|
|
|
96
|
+
// src/previewGuard.js
|
|
97
|
+
var DEFAULT_ORIGIN = "http://localhost:7777";
|
|
98
|
+
var isLocalhostOrigin = (origin) => {
|
|
99
|
+
let url;
|
|
100
|
+
try {
|
|
101
|
+
url = new URL(origin);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
106
|
+
const host = url.hostname.toLowerCase();
|
|
107
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "[::1]";
|
|
108
|
+
};
|
|
109
|
+
var toOrigin = (value) => {
|
|
110
|
+
try {
|
|
111
|
+
return new URL(value).origin;
|
|
112
|
+
} catch (e) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
var shouldLoadPreview = (config) => {
|
|
117
|
+
const preview = config && config.preview;
|
|
118
|
+
if (!preview || preview.enabled !== true) {
|
|
119
|
+
return { allowed: false, origin: null, reason: "preview-disabled" };
|
|
120
|
+
}
|
|
121
|
+
const origin = preview.origin ?? DEFAULT_ORIGIN;
|
|
122
|
+
const normalized = toOrigin(origin);
|
|
123
|
+
if (!normalized) {
|
|
124
|
+
return { allowed: false, origin: null, reason: "malformed-origin" };
|
|
125
|
+
}
|
|
126
|
+
if (isLocalhostOrigin(origin)) {
|
|
127
|
+
return { allowed: true, origin };
|
|
128
|
+
}
|
|
129
|
+
const extra = Array.isArray(preview.allowedOrigins) ? preview.allowedOrigins : [];
|
|
130
|
+
const allowed = extra.some((entry) => toOrigin(entry) === normalized);
|
|
131
|
+
if (allowed) {
|
|
132
|
+
return { allowed: true, origin };
|
|
133
|
+
}
|
|
134
|
+
return { allowed: false, origin, reason: "origin-not-allowlisted" };
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// src/bridgeAuth.js
|
|
138
|
+
var bridgeHeaders = (key, base) => {
|
|
139
|
+
const headers = base ? { ...base } : {};
|
|
140
|
+
if (typeof key === "string" && key.trim() !== "") {
|
|
141
|
+
headers.Authorization = `Bearer ${key.trim()}`;
|
|
142
|
+
}
|
|
143
|
+
return headers;
|
|
144
|
+
};
|
|
145
|
+
|
|
23
146
|
// src/TokenProvider.jsx
|
|
24
147
|
import { jsx } from "react/jsx-runtime";
|
|
148
|
+
var devWarn = (msg) => {
|
|
149
|
+
try {
|
|
150
|
+
if (typeof process !== "undefined" && process.env && true) {
|
|
151
|
+
console.warn(`[sorb] ${msg}`);
|
|
152
|
+
}
|
|
153
|
+
} catch (e) {
|
|
154
|
+
}
|
|
155
|
+
};
|
|
25
156
|
var SorbProvider = ({ config, children }) => {
|
|
26
157
|
const [activeTokens, setActiveTokens] = useState(config.tokens);
|
|
27
158
|
const [isPreview, setIsPreview] = useState(false);
|
|
@@ -35,9 +166,16 @@ var SorbProvider = ({ config, children }) => {
|
|
|
35
166
|
}, [config.tokens]);
|
|
36
167
|
const loadPreview = useCallback(
|
|
37
168
|
async (id) => {
|
|
38
|
-
const
|
|
169
|
+
const guard = shouldLoadPreview(config);
|
|
170
|
+
if (!guard.allowed) {
|
|
171
|
+
loadCommitted();
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
const origin = guard.origin;
|
|
39
175
|
try {
|
|
40
|
-
const res = await fetch(`${origin}/preview/${id}
|
|
176
|
+
const res = await fetch(`${origin}/preview/${id}`, {
|
|
177
|
+
headers: bridgeHeaders(config.preview?.key)
|
|
178
|
+
});
|
|
41
179
|
if (!res.ok) throw new Error("preview not found");
|
|
42
180
|
const tokens = await res.json();
|
|
43
181
|
applyTokens(tokens);
|
|
@@ -45,12 +183,12 @@ var SorbProvider = ({ config, children }) => {
|
|
|
45
183
|
setIsPreview(true);
|
|
46
184
|
setPreviewId(id);
|
|
47
185
|
return true;
|
|
48
|
-
} catch {
|
|
186
|
+
} catch (e) {
|
|
49
187
|
loadCommitted();
|
|
50
188
|
return false;
|
|
51
189
|
}
|
|
52
190
|
},
|
|
53
|
-
[config
|
|
191
|
+
[config, loadCommitted]
|
|
54
192
|
);
|
|
55
193
|
const clearPreview = useCallback(() => {
|
|
56
194
|
if (pollRef.current) clearInterval(pollRef.current);
|
|
@@ -61,9 +199,14 @@ var SorbProvider = ({ config, children }) => {
|
|
|
61
199
|
loadCommitted();
|
|
62
200
|
}, [loadCommitted]);
|
|
63
201
|
useEffect(() => {
|
|
64
|
-
const
|
|
202
|
+
const guard = shouldLoadPreview(config);
|
|
65
203
|
const id = new URLSearchParams(location.search).get("preview");
|
|
66
|
-
if (!
|
|
204
|
+
if (!guard.allowed || !id) {
|
|
205
|
+
if (id && !guard.allowed) {
|
|
206
|
+
devWarn(
|
|
207
|
+
`ignoring ?preview= \u2014 preview not permitted (${guard.reason ?? "blocked"}); loading committed tokens`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
67
210
|
loadCommitted();
|
|
68
211
|
return;
|
|
69
212
|
}
|
|
@@ -174,12 +317,59 @@ var PreviewBanner = () => {
|
|
|
174
317
|
}
|
|
175
318
|
);
|
|
176
319
|
};
|
|
320
|
+
|
|
321
|
+
// src/verify.js
|
|
322
|
+
var toCssVar = (name) => {
|
|
323
|
+
const s = String(name).trim();
|
|
324
|
+
return s.startsWith("--") ? s : `--${s}`;
|
|
325
|
+
};
|
|
326
|
+
var verifyResolved = async (tokens, { origin = "http://localhost:7777", key, fetch: fetchImpl } = {}) => {
|
|
327
|
+
if (typeof document === "undefined" || !document.documentElement) {
|
|
328
|
+
return { ok: false, reason: "no-dom" };
|
|
329
|
+
}
|
|
330
|
+
if (!Array.isArray(tokens) || tokens.length === 0) {
|
|
331
|
+
return { ok: false, reason: "no-tokens" };
|
|
332
|
+
}
|
|
333
|
+
const cs = getComputedStyle(document.documentElement);
|
|
334
|
+
const values = {};
|
|
335
|
+
for (const t of tokens) {
|
|
336
|
+
const cssVar = toCssVar(t);
|
|
337
|
+
values[cssVar] = cs.getPropertyValue(cssVar).trim();
|
|
338
|
+
}
|
|
339
|
+
const unapplied = Object.entries(values).filter(([, v]) => v.startsWith("var(")).map(([k]) => k);
|
|
340
|
+
if (unapplied.length) return { ok: false, reason: "provider-not-applied", unapplied };
|
|
341
|
+
const f = fetchImpl || (typeof fetch !== "undefined" ? fetch : globalThis.fetch);
|
|
342
|
+
if (typeof f !== "function") return { ok: false, reason: "no-fetch" };
|
|
343
|
+
const base = String(origin).replace(/\/+$/, "");
|
|
344
|
+
try {
|
|
345
|
+
const res = await f(`${base}/verify/app`, {
|
|
346
|
+
method: "POST",
|
|
347
|
+
// Hosted bridge needs the bearer key; localhost (no key) sends no header.
|
|
348
|
+
headers: bridgeHeaders(key, { "Content-Type": "application/json" }),
|
|
349
|
+
body: JSON.stringify({ values })
|
|
350
|
+
});
|
|
351
|
+
if (!res.ok) {
|
|
352
|
+
let detail = "";
|
|
353
|
+
try {
|
|
354
|
+
const b = await res.json();
|
|
355
|
+
detail = b && b.error ? b.error : "";
|
|
356
|
+
} catch (e) {
|
|
357
|
+
}
|
|
358
|
+
return { ok: false, reason: "bridge-error", error: `${res.status}${detail ? ` \u2014 ${detail}` : ""}` };
|
|
359
|
+
}
|
|
360
|
+
return await res.json();
|
|
361
|
+
} catch (e) {
|
|
362
|
+
return { ok: false, reason: "bridge-unreachable", error: e && e.message };
|
|
363
|
+
}
|
|
364
|
+
};
|
|
177
365
|
export {
|
|
178
366
|
PreviewBanner,
|
|
179
367
|
SorbProvider,
|
|
368
|
+
sanitizeCssValue,
|
|
180
369
|
useIsPreview,
|
|
181
370
|
usePreviewState,
|
|
182
371
|
useToken,
|
|
183
|
-
useTokens
|
|
372
|
+
useTokens,
|
|
373
|
+
verifyResolved
|
|
184
374
|
};
|
|
185
375
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/TokenProvider.jsx", "../src/context.js", "../src/apply.js", "../src/PreviewBanner.jsx", "../src/hooks.js"],
|
|
4
|
-
"sourcesContent": ["import React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { TokenContext } from './context'\nimport { applyTokens } from './apply'\n\n/**\n * @param {{ config: import('./types').SorbConfig, children: React.ReactNode }} props\n */\nexport const SorbProvider = ({ config, children }) => {\n const [activeTokens, setActiveTokens] = useState(config.tokens)\n const [isPreview, setIsPreview] = useState(false)\n const [previewId, setPreviewId] = useState(null)\n const pollRef = useRef(null)\n\n // \u2500\u2500\u2500 committed token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadCommitted = useCallback(() => {\n applyTokens(config.tokens)\n setActiveTokens(config.tokens)\n setIsPreview(false)\n setPreviewId(null)\n }, [config.tokens])\n\n // \u2500\u2500\u2500 preview token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadPreview = useCallback(\n async (id) => {\n const origin = config.preview?.origin ?? 'http://localhost:7777'\n try {\n const res = await fetch(`${origin}/preview/${id}`)\n if (!res.ok) throw new Error('preview not found')\n const tokens = await res.json()\n applyTokens(tokens)\n setActiveTokens(tokens)\n setIsPreview(true)\n setPreviewId(id)\n return true\n } catch {\n // local server not running, preview expired, or network error\n // fall back silently \u2014 never break the app\n loadCommitted()\n return false\n }\n },\n [config.preview?.origin, loadCommitted],\n )\n\n // \u2500\u2500\u2500 clear preview + remove query param \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const clearPreview = useCallback(() => {\n if (pollRef.current) clearInterval(pollRef.current)\n const params = new URLSearchParams(location.search)\n params.delete('preview')\n const qs = params.toString()\n history.replaceState(null, '', qs ? `?${qs}` : location.pathname)\n loadCommitted()\n }, [loadCommitted])\n\n // \u2500\u2500\u2500 initialise on mount \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n useEffect(() => {\n const previewEnabled = config.preview?.enabled ?? false\n const id = new URLSearchParams(location.search).get('preview')\n\n // bail out immediately if preview is disabled or no param present\n if (!previewEnabled || !id) {\n loadCommitted()\n return\n }\n\n // load the preview, then start polling so Figma changes reflect live\n loadPreview(id).then((ok) => {\n if (!ok) return\n const interval = config.preview?.pollInterval ?? 1500\n pollRef.current = setInterval(() => loadPreview(id), interval)\n })\n\n return () => {\n if (pollRef.current) clearInterval(pollRef.current)\n }\n }, []) // intentionally empty \u2014 only runs on mount\n\n return (\n <TokenContext.Provider value={{ tokens: activeTokens, isPreview, previewId, clearPreview }}>\n {children}\n </TokenContext.Provider>\n )\n}\n", "import { createContext, useContext } from 'react'\n\n/** @type {import('react').Context<import('./types').TokenContextValue | null>} */\nexport const TokenContext = createContext(null)\n\n/** @returns {import('./types').TokenContextValue} */\nexport const useTokenContext = () => {\n const ctx = useContext(TokenContext)\n if (!ctx) {\n throw new Error('Sorb hooks must be used inside <SorbProvider>')\n }\n return ctx\n}\n", "/**\n * Writes all token values as CSS custom properties on :root.\n * Applies globally \u2014 affects the entire app.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const applyTokens = (tokens) => {\n const root = document.documentElement\n Object.entries(tokens).forEach(([key, value]) => {\n root.style.setProperty(`--${key}`, String(value))\n })\n}\n\n/**\n * Removes token CSS custom properties from :root.\n * Called when clearing a preview to restore the committed set.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const clearTokenOverrides = (tokens) => {\n const root = document.documentElement\n Object.keys(tokens).forEach((key) => {\n root.style.removeProperty(`--${key}`)\n })\n}\n", "import React from 'react'\nimport { usePreviewState } from './hooks'\n\n/**\n * Drop-in banner that appears at the bottom of the screen when a\n * Sorb preview is active. Includes an \"Exit preview\" button.\n *\n * Only renders when preview.enabled is true AND a preview is loaded.\n * Safe to include unconditionally \u2014 renders nothing in production.\n *\n * @example\n * // In your app root, after <SorbProvider>\n * <PreviewBanner />\n */\nexport const PreviewBanner = () => {\n const { isPreview, previewId, clearPreview } = usePreviewState()\n if (!isPreview) return null\n\n return (\n <div\n role=\"status\"\n aria-live=\"polite\"\n style={{\n position: 'fixed',\n bottom: 0,\n left: 0,\n right: 0,\n background: '#3B5BDB',\n color: '#fff',\n padding: '10px 20px',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '12px',\n fontSize: '13px',\n lineHeight: '1.4',\n zIndex: 99999,\n fontFamily:\n 'system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif',\n boxShadow: '0 -2px 12px rgba(0,0,0,0.15)',\n }}\n >\n <span>\n <strong style={{ fontWeight: 600 }}>Sorb preview active</strong>\n {previewId && (\n <code\n style={{\n marginLeft: '8px',\n opacity: 0.75,\n fontSize: '11px',\n background: 'rgba(255,255,255,0.15)',\n padding: '2px 6px',\n borderRadius: '4px',\n }}\n >\n {previewId}\n </code>\n )}\n <span style={{ marginLeft: '8px', opacity: 0.75, fontSize: '12px' }}>\n Token changes from Figma are live\n </span>\n </span>\n <button\n onClick={clearPreview}\n style={{\n flexShrink: 0,\n background: 'rgba(255,255,255,0.2)',\n border: '1px solid rgba(255,255,255,0.3)',\n color: '#fff',\n padding: '5px 14px',\n borderRadius: '6px',\n cursor: 'pointer',\n fontSize: '12px',\n fontWeight: 500,\n transition: 'background 0.15s',\n }}\n onMouseEnter={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.3)')\n }\n onMouseLeave={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.2)')\n }\n >\n Exit preview\n </button>\n </div>\n )\n}\n", "import { useTokenContext } from './context'\n\n/**\n * Returns the full active token set (committed or preview).\n * @returns {import('./types').TokenSet}\n */\nexport const useTokens = () => {\n return useTokenContext().tokens\n}\n\n/**\n * Returns a single token value by key.\n *\n * @param {string} key\n * @returns {string}\n * @example\n * const primary = useToken('color-primary') // \u2192 '#3B5BDB'\n */\nexport const useToken = (key) => {\n const tokens = useTokenContext().tokens\n const value = tokens[key]\n if (value === undefined && process.env.NODE_ENV === 'development') {\n console.warn(`[Sorb] Token not found: \"${key}\"`)\n }\n return String(value ?? '')\n}\n\n/**\n * Returns whether a preview token set is currently active.\n * Useful for showing a preview indicator in your app.\n * @returns {boolean}\n */\nexport const useIsPreview = () => {\n return useTokenContext().isPreview\n}\n\n/**\n * Returns full preview state \u2014 useful for building a preview banner.\n *\n * @example\n * const { isPreview, previewId, clearPreview } = usePreviewState()\n */\nexport const usePreviewState = () => {\n const { isPreview, previewId, clearPreview } = useTokenContext()\n return { isPreview, previewId, clearPreview }\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,SAAS,aAAa,WAAW,QAAQ,gBAAgB;;;ACAhE,SAAS,eAAe,kBAAkB;AAGnC,IAAM,eAAe,cAAc,IAAI;AAGvC,IAAM,kBAAkB,MAAM;AACnC,QAAM,MAAM,WAAW,YAAY;AACnC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,SAAO;AACT;;;
|
|
3
|
+
"sources": ["../src/TokenProvider.jsx", "../src/context.js", "../src/sanitize.js", "../src/apply.js", "../src/previewGuard.js", "../src/bridgeAuth.js", "../src/PreviewBanner.jsx", "../src/hooks.js", "../src/verify.js"],
|
|
4
|
+
"sourcesContent": ["import React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { TokenContext } from './context'\nimport { applyTokens } from './apply'\nimport { shouldLoadPreview } from './previewGuard'\nimport { bridgeHeaders } from './bridgeAuth'\n\n/**\n * Dev-only warning that never throws in a browser (no `process` global there).\n * @param {string} msg\n * @returns {void}\n */\nconst devWarn = (msg) => {\n try {\n if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(`[sorb] ${msg}`)\n }\n } catch (e) {\n void e\n }\n}\n\n/**\n * @param {{ config: import('./types').SorbConfig, children: React.ReactNode }} props\n */\nexport const SorbProvider = ({ config, children }) => {\n const [activeTokens, setActiveTokens] = useState(config.tokens)\n const [isPreview, setIsPreview] = useState(false)\n const [previewId, setPreviewId] = useState(null)\n const pollRef = useRef(null)\n\n // \u2500\u2500\u2500 committed token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadCommitted = useCallback(() => {\n applyTokens(config.tokens)\n setActiveTokens(config.tokens)\n setIsPreview(false)\n setPreviewId(null)\n }, [config.tokens])\n\n // \u2500\u2500\u2500 preview token loader \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const loadPreview = useCallback(\n async (id) => {\n // Re-check the guard here too: loadPreview must never fetch an\n // untrusted origin even if called directly. Use the guard-resolved\n // origin, not the raw config, so the trust decision is single-sourced.\n const guard = shouldLoadPreview(config)\n if (!guard.allowed) {\n loadCommitted()\n return false\n }\n const origin = guard.origin\n try {\n // Hosted bridge needs `Authorization: Bearer <config.preview.key>`;\n // when no key is configured (localhost `sorb dev`) NO header is sent\n // and this call is unchanged.\n const res = await fetch(`${origin}/preview/${id}`, {\n headers: bridgeHeaders(config.preview?.key),\n })\n if (!res.ok) throw new Error('preview not found')\n const tokens = await res.json()\n applyTokens(tokens)\n setActiveTokens(tokens)\n setIsPreview(true)\n setPreviewId(id)\n return true\n } catch (e) {\n // local server not running, preview expired, or network error\n // fall back silently \u2014 never break the app\n void e\n loadCommitted()\n return false\n }\n },\n [config, loadCommitted],\n )\n\n // \u2500\u2500\u2500 clear preview + remove query param \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n const clearPreview = useCallback(() => {\n if (pollRef.current) clearInterval(pollRef.current)\n const params = new URLSearchParams(location.search)\n params.delete('preview')\n const qs = params.toString()\n history.replaceState(null, '', qs ? `?${qs}` : location.pathname)\n loadCommitted()\n }, [loadCommitted])\n\n // \u2500\u2500\u2500 initialise on mount \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n useEffect(() => {\n const guard = shouldLoadPreview(config)\n const id = new URLSearchParams(location.search).get('preview')\n\n // Preview only runs when the origin-allowlist guard says so (C3). A stray\n // `?preview=` on a production deploy against an untrusted origin is ignored\n // \u2014 we load committed tokens and dev-warn instead.\n if (!guard.allowed || !id) {\n if (id && !guard.allowed) {\n devWarn(\n `ignoring ?preview= \u2014 preview not permitted (${guard.reason ?? 'blocked'}); ` +\n 'loading committed tokens',\n )\n }\n loadCommitted()\n return\n }\n\n // load the preview, then start polling so Figma changes reflect live\n loadPreview(id).then((ok) => {\n if (!ok) return\n const interval = config.preview?.pollInterval ?? 1500\n pollRef.current = setInterval(() => loadPreview(id), interval)\n })\n\n return () => {\n if (pollRef.current) clearInterval(pollRef.current)\n }\n }, []) // intentionally empty \u2014 only runs on mount\n\n return (\n <TokenContext.Provider value={{ tokens: activeTokens, isPreview, previewId, clearPreview }}>\n {children}\n </TokenContext.Provider>\n )\n}\n", "import { createContext, useContext } from 'react'\n\n/** @type {import('react').Context<import('./types').TokenContextValue | null>} */\nexport const TokenContext = createContext(null)\n\n/** @returns {import('./types').TokenContextValue} */\nexport const useTokenContext = () => {\n const ctx = useContext(TokenContext)\n if (!ctx) {\n throw new Error('Sorb hooks must be used inside <SorbProvider>')\n }\n return ctx\n}\n", "/**\n * CSS token-value sanitizer \u2014 the C1 injection-boundary guard.\n *\n * Token values flow Figma \u2192 bridge \u2192 `applyTokens` \u2192 `setProperty`. Those values\n * are UNTRUSTED INPUT crossing a trust boundary. This is a pure string function\n * (no DOM) so it is fully node:test-able and reusable. Phase 2 will hoist it to\n * `@sorb/core`; do NOT add a DOM dependency here.\n *\n * Strategy: deny-by-default on the dangerous classes, then allowlist CSS\n * functions. A *valid* hostile value (a real `url(...)`) passes `setProperty`\n * unharmed, so we cannot rely on the browser \u2014 we reject it here.\n */\n\n/**\n * The only CSS functions we permit inside a token value. Anything else \u2014\n * `url(`, `image(`, `image-set(`, `-webkit-image-set(`, `cross-fade(`,\n * `expression(`, `paint(`, `element(`, `attr(`, \u2026 \u2014 is rejected.\n * @type {Set<string>}\n */\nconst ALLOWED_FUNCTIONS = new Set([\n 'rgb',\n 'rgba',\n 'hsl',\n 'hsla',\n 'hwb',\n 'lab',\n 'lch',\n 'oklab',\n 'oklch',\n 'color',\n 'calc',\n 'min',\n 'max',\n 'clamp',\n 'var',\n 'env',\n])\n\n// Matches an identifier immediately followed by '(' \u2014 i.e. a CSS function call.\n// Identifiers may start with one or two leading hyphens (vendor prefixes like\n// `-webkit-image-set`). The lookahead keeps the '(' out of the captured name.\nconst FUNCTION_CALL = /([a-zA-Z_-][\\w-]*)\\s*\\(/g\n\n// ASCII control chars (incl. NUL, newlines, tabs) \u2014 never legitimate in a\n// token value and a classic way to smuggle past naive filters.\n// eslint-disable-next-line no-control-regex\nconst CONTROL_CHARS = /[\\x00-\\x1f]/\n\n// CSS-context-break characters that let a value escape the custom-property\n// declaration: `;` ends the declaration, `{` / `}` open/close a block.\nconst CONTEXT_BREAK = /[{};]/\n\n/**\n * Validate an untrusted CSS token value before it is injected via\n * `setProperty`. Pure \u2014 does not touch the DOM.\n *\n * Rules (deny-by-default):\n * - non-string / empty input is rejected.\n * - reject ASCII control chars `\\x00-\\x1f`.\n * - reject the context-break chars `{` `}` `;`.\n * - reject (case-insensitive, whitespace-tolerant) `@import`, `javascript:`,\n * and the markup-break `</`.\n * - extract every `identifier(` and reject if ANY is not in the allowlist\n * (this is what stops `url(`, `image-set(`, `expression(`, `paint(`, \u2026).\n *\n * @param {unknown} value\n * @returns {{ ok: boolean, value: string, reason?: string }}\n */\nexport const sanitizeCssValue = (value) => {\n if (typeof value !== 'string') {\n return { ok: false, value: '', reason: 'not-a-string' }\n }\n\n const raw = value\n if (raw.length === 0) {\n return { ok: false, value: '', reason: 'empty' }\n }\n\n if (CONTROL_CHARS.test(raw)) {\n return { ok: false, value: raw, reason: 'control-char' }\n }\n\n if (CONTEXT_BREAK.test(raw)) {\n return { ok: false, value: raw, reason: 'context-break-char' }\n }\n\n // Case-insensitive, whitespace-tolerant dangerous tokens. We strip ASCII\n // whitespace before substring-matching so `@ import`, `java script:`,\n // `< /script` style evasions are still caught.\n const lower = raw.toLowerCase()\n const collapsed = lower.replace(/\\s+/g, '')\n if (collapsed.includes('@import')) {\n return { ok: false, value: raw, reason: 'at-import' }\n }\n if (collapsed.includes('javascript:')) {\n return { ok: false, value: raw, reason: 'javascript-scheme' }\n }\n if (collapsed.includes('</')) {\n return { ok: false, value: raw, reason: 'markup-break' }\n }\n\n // Allowlist every function call in the value.\n FUNCTION_CALL.lastIndex = 0\n let match\n while ((match = FUNCTION_CALL.exec(raw)) !== null) {\n const name = match[1].toLowerCase()\n if (!ALLOWED_FUNCTIONS.has(name)) {\n return { ok: false, value: raw, reason: `disallowed-function:${name}` }\n }\n }\n\n return { ok: true, value: raw }\n}\n", "import { sanitizeCssValue } from './sanitize.js'\n\n/**\n * Dev-only warning that never throws in a browser (no `process` global there).\n * Silent in production so a hostile token can't spam a shipped app's console.\n *\n * @param {string} key\n * @param {string} [reason]\n * @returns {void}\n */\nconst warnRejected = (key, reason) => {\n try {\n if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn(\n `[sorb] skipped token \"--${key}\": value failed CSS sanitization` +\n (reason ? ` (${reason})` : ''),\n )\n }\n } catch (e) {\n // never let logging break token application\n void e\n }\n}\n\n/**\n * Writes all token values as CSS custom properties on :root.\n * Applies globally \u2014 affects the entire app.\n *\n * Each value is validated by {@link sanitizeCssValue} at this injection\n * boundary (concern C1). A value that fails sanitization is SKIPPED (fail\n * safe) \u2014 it is never written \u2014 and the remaining tokens still apply.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const applyTokens = (tokens) => {\n const root = document.documentElement\n Object.entries(tokens).forEach(([key, value]) => {\n const result = sanitizeCssValue(String(value))\n if (!result.ok) {\n warnRejected(key, result.reason)\n return\n }\n root.style.setProperty(`--${key}`, result.value)\n })\n}\n\n/**\n * Removes token CSS custom properties from :root.\n * Called when clearing a preview to restore the committed set.\n *\n * @param {import('./types').TokenSet} tokens\n * @returns {void}\n */\nexport const clearTokenOverrides = (tokens) => {\n const root = document.documentElement\n Object.keys(tokens).forEach((key) => {\n root.style.removeProperty(`--${key}`)\n })\n}\n", "/**\n * Preview-origin guard \u2014 the C3 production foot-gun guard.\n *\n * Preview defaults OFF. Even when a team opts in, the SDK must only talk to a\n * TRUSTED bridge origin: a stray `?preview=` on a production link must not be\n * able to point the running app at an untrusted bridge. This pure helper makes\n * that decision; the provider wires it in. No DOM, fully node:test-able.\n */\n\nconst DEFAULT_ORIGIN = 'http://localhost:7777'\n\n/**\n * Is `origin` a localhost / loopback origin (any port)? `http`/`https`,\n * `localhost`, `127.0.0.1`, and IPv6 `[::1]` all count.\n *\n * @param {string} origin\n * @returns {boolean}\n */\nconst isLocalhostOrigin = (origin) => {\n let url\n try {\n url = new URL(origin)\n } catch (e) {\n void e\n return false\n }\n if (url.protocol !== 'http:' && url.protocol !== 'https:') return false\n const host = url.hostname.toLowerCase()\n return host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]'\n}\n\n/**\n * Normalise to a bare `protocol//host:port` origin for exact comparison\n * against a consumer-supplied allowlist (trailing slashes / paths ignored).\n *\n * @param {string} value\n * @returns {string|null}\n */\nconst toOrigin = (value) => {\n try {\n return new URL(value).origin\n } catch (e) {\n void e\n return null\n }\n}\n\n/**\n * Decide whether the preview path may run, and against which origin.\n *\n * Allowed only when BOTH:\n * 1. `config.preview?.enabled === true` (strict \u2014 not just truthy), and\n * 2. the resolved origin is on the allowlist: localhost/127.0.0.1/[::1]\n * (any port) by default, plus any exact origins the consumer lists in\n * `config.preview.allowedOrigins`.\n *\n * Anything else (disabled, missing config, non-allowlisted origin, malformed\n * origin) \u2192 not allowed; the caller falls back to committed tokens.\n *\n * @param {import('./types').SorbConfig} [config]\n * @returns {{ allowed: boolean, origin: string|null, reason?: string }}\n */\nexport const shouldLoadPreview = (config) => {\n const preview = config && config.preview\n if (!preview || preview.enabled !== true) {\n return { allowed: false, origin: null, reason: 'preview-disabled' }\n }\n\n const origin = preview.origin ?? DEFAULT_ORIGIN\n const normalized = toOrigin(origin)\n if (!normalized) {\n return { allowed: false, origin: null, reason: 'malformed-origin' }\n }\n\n if (isLocalhostOrigin(origin)) {\n return { allowed: true, origin }\n }\n\n const extra = Array.isArray(preview.allowedOrigins) ? preview.allowedOrigins : []\n const allowed = extra.some((entry) => toOrigin(entry) === normalized)\n if (allowed) {\n return { allowed: true, origin }\n }\n\n return { allowed: false, origin, reason: 'origin-not-allowlisted' }\n}\n", "// bridgeAuth.js \u2014 hosted-bridge Authorization header (Plugin-UX U4).\n//\n// Sorb's hosted bridge (https://bridge.sorbcloud.com) requires\n// `Authorization: Bearer <key>` on every route except /health. The key is a\n// read-only publishable `sorb_pk_\u2026` (safe to ship in a distributable; 403s on\n// writes). Local `sorb dev` runs with NO auth, so when no key is configured we\n// send NO header and the localhost path is byte-for-byte unchanged.\n//\n// One place builds the header so both fetch sites (TokenProvider preview poll +\n// verify.js) stay consistent. Pure + node:test-able; no DOM, no fetch.\n\n/**\n * Build the request headers for a hosted-bridge call, merging in the bearer\n * `Authorization` header only when a non-empty key is configured.\n *\n * @param {string} [key] The configured bearer key (`config.preview.key`), if any.\n * @param {Record<string,string>} [base] Base headers to extend (e.g. Content-Type).\n * @returns {Record<string,string>}\n */\nexport const bridgeHeaders = (key, base) => {\n const headers = base ? { ...base } : {}\n if (typeof key === 'string' && key.trim() !== '') {\n headers.Authorization = `Bearer ${key.trim()}`\n }\n return headers\n}\n", "import React from 'react'\nimport { usePreviewState } from './hooks'\n\n/**\n * Drop-in banner that appears at the bottom of the screen when a\n * Sorb preview is active. Includes an \"Exit preview\" button.\n *\n * Only renders when preview.enabled is true AND a preview is loaded.\n * Safe to include unconditionally \u2014 renders nothing in production.\n *\n * @example\n * // In your app root, after <SorbProvider>\n * <PreviewBanner />\n */\nexport const PreviewBanner = () => {\n const { isPreview, previewId, clearPreview } = usePreviewState()\n if (!isPreview) return null\n\n return (\n <div\n role=\"status\"\n aria-live=\"polite\"\n style={{\n position: 'fixed',\n bottom: 0,\n left: 0,\n right: 0,\n background: '#3B5BDB',\n color: '#fff',\n padding: '10px 20px',\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: '12px',\n fontSize: '13px',\n lineHeight: '1.4',\n zIndex: 99999,\n fontFamily:\n 'system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif',\n boxShadow: '0 -2px 12px rgba(0,0,0,0.15)',\n }}\n >\n <span>\n <strong style={{ fontWeight: 600 }}>Sorb preview active</strong>\n {previewId && (\n <code\n style={{\n marginLeft: '8px',\n opacity: 0.75,\n fontSize: '11px',\n background: 'rgba(255,255,255,0.15)',\n padding: '2px 6px',\n borderRadius: '4px',\n }}\n >\n {previewId}\n </code>\n )}\n <span style={{ marginLeft: '8px', opacity: 0.75, fontSize: '12px' }}>\n Token changes from Figma are live\n </span>\n </span>\n <button\n onClick={clearPreview}\n style={{\n flexShrink: 0,\n background: 'rgba(255,255,255,0.2)',\n border: '1px solid rgba(255,255,255,0.3)',\n color: '#fff',\n padding: '5px 14px',\n borderRadius: '6px',\n cursor: 'pointer',\n fontSize: '12px',\n fontWeight: 500,\n transition: 'background 0.15s',\n }}\n onMouseEnter={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.3)')\n }\n onMouseLeave={(e) =>\n (e.target.style.background = 'rgba(255,255,255,0.2)')\n }\n >\n Exit preview\n </button>\n </div>\n )\n}\n", "import { useTokenContext } from './context'\n\n/**\n * Returns the full active token set (committed or preview).\n * @returns {import('./types').TokenSet}\n */\nexport const useTokens = () => {\n return useTokenContext().tokens\n}\n\n/**\n * Returns a single token value by key.\n *\n * @param {string} key\n * @returns {string}\n * @example\n * const primary = useToken('color-primary') // \u2192 '#3B5BDB'\n */\nexport const useToken = (key) => {\n const tokens = useTokenContext().tokens\n const value = tokens[key]\n if (value === undefined && process.env.NODE_ENV === 'development') {\n console.warn(`[Sorb] Token not found: \"${key}\"`)\n }\n return String(value ?? '')\n}\n\n/**\n * Returns whether a preview token set is currently active.\n * Useful for showing a preview indicator in your app.\n * @returns {boolean}\n */\nexport const useIsPreview = () => {\n return useTokenContext().isPreview\n}\n\n/**\n * Returns full preview state \u2014 useful for building a preview banner.\n *\n * @example\n * const { isPreview, previewId, clearPreview } = usePreviewState()\n */\nexport const usePreviewState = () => {\n const { isPreview, previewId, clearPreview } = useTokenContext()\n return { isPreview, previewId, clearPreview }\n}\n", "// verify.js \u2014 RUNNING-APP token verification (e2e-fix W2).\n//\n// Reports the values the running app ACTUALLY resolved for a set of tokens (read\n// off `:root` \u2014 where SorbProvider's applyTokens wrote the committed/preview\n// values) to the bridge's `POST /verify/app`, which diffs them against the\n// committed resolved map. This is what makes \"verify-before-merge in your running\n// app\" true in code: it asserts the live DOM resolves to the bound token values,\n// not Figma-side geometry.\n//\n// SSR-safe: no DOM \u2192 returns a clear `{ ok:false, reason:'no-dom' }` rather than\n// throwing (safe to call from a server-rendered component's effect). `fetch` is\n// injectable for tests.\n\nimport { bridgeHeaders } from './bridgeAuth.js'\n\n/** Normalize a token name to a `--cssVar`. */\nconst toCssVar = (name) => {\n const s = String(name).trim()\n return s.startsWith('--') ? s : `--${s}`\n}\n\n/**\n * Read each token's resolved value off `:root` and ask the bridge whether the\n * running app matches the committed resolved map.\n *\n * Precondition: call from inside a mounted `<SorbProvider>` \u2014 it applies the\n * resolved token literals onto `:root`. Without it, custom props read back as\n * `var(...)` refs (outputReferences css) and the result is `{ ok:false,\n * reason:'provider-not-applied' }` rather than a misleading mismatch.\n *\n * @param {string[]} tokens Token names or `--cssVar`s to check (e.g. `'button-primary-bg-default'`).\n * @param {{ origin?: string, key?: string, fetch?: typeof globalThis.fetch }} [opts]\n * `key` is the hosted-bridge bearer key (`config.preview.key`). Omit for the\n * no-auth localhost bridge \u2014 no `Authorization` header is then sent.\n * @returns {Promise<{ok:boolean, reason?:string, checked?:number, matched?:number, mismatches?:Array<{cssVar:string,expected:any,got:any}>, unknown?:string[], error?:string}>}\n */\nexport const verifyResolved = async (tokens, { origin = 'http://localhost:7777', key, fetch: fetchImpl } = {}) => {\n if (typeof document === 'undefined' || !document.documentElement) {\n return { ok: false, reason: 'no-dom' }\n }\n if (!Array.isArray(tokens) || tokens.length === 0) {\n return { ok: false, reason: 'no-tokens' }\n }\n const cs = getComputedStyle(document.documentElement)\n /** @type {Record<string,string>} */\n const values = {}\n for (const t of tokens) {\n const cssVar = toCssVar(t)\n values[cssVar] = cs.getPropertyValue(cssVar).trim()\n }\n // Precondition: SorbProvider must have applied the resolved literals onto :root.\n // `variables.css` is built with outputReferences, so an un-applied custom prop\n // reads back as a `var(--\u2026)` reference, not a value \u2014 verifying that is\n // meaningless. Detect it and say so plainly instead of reporting false mismatches.\n const unapplied = Object.entries(values)\n .filter(([, v]) => v.startsWith('var('))\n .map(([k]) => k)\n if (unapplied.length) return { ok: false, reason: 'provider-not-applied', unapplied }\n const f = fetchImpl || (typeof fetch !== 'undefined' ? fetch : globalThis.fetch)\n if (typeof f !== 'function') return { ok: false, reason: 'no-fetch' }\n const base = String(origin).replace(/\\/+$/, '')\n try {\n const res = await f(`${base}/verify/app`, {\n method: 'POST',\n // Hosted bridge needs the bearer key; localhost (no key) sends no header.\n headers: bridgeHeaders(key, { 'Content-Type': 'application/json' }),\n body: JSON.stringify({ values }),\n })\n if (!res.ok) {\n let detail = ''\n try {\n const b = await res.json()\n detail = b && b.error ? b.error : ''\n } catch (e) {\n void e\n }\n return { ok: false, reason: 'bridge-error', error: `${res.status}${detail ? ` \u2014 ${detail}` : ''}` }\n }\n return await res.json()\n } catch (e) {\n // Bridge not running / network error \u2014 never throw into the app.\n return { ok: false, reason: 'bridge-unreachable', error: e && e.message }\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,SAAS,aAAa,WAAW,QAAQ,gBAAgB;;;ACAhE,SAAS,eAAe,kBAAkB;AAGnC,IAAM,eAAe,cAAc,IAAI;AAGvC,IAAM,kBAAkB,MAAM;AACnC,QAAM,MAAM,WAAW,YAAY;AACnC,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,+CAA+C;AAAA,EACjE;AACA,SAAO;AACT;;;ACOA,IAAM,oBAAoB,oBAAI,IAAI;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKD,IAAM,gBAAgB;AAKtB,IAAM,gBAAgB;AAItB,IAAM,gBAAgB;AAkBf,IAAM,mBA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,EAAE,IAAI,OAAO,QAAQ,sBAAsB,OAAO,KAAK,EAAE,QAAQ;AAAA,EAC1E;AACF;",
|
|
6
6
|
"names": ["React", "jsx"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sorb/leaf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "React provider for Sorb design tokens — the foliage rendered in your running app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"sideEffects": false,
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "node build.mjs",
|
|
36
|
+
"test": "node --test",
|
|
36
37
|
"dev": "node build.mjs --watch",
|
|
37
38
|
"prepublishOnly": "node build.mjs"
|
|
38
39
|
},
|