@sorb/leaf 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
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,138 @@ 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
- root.style.setProperty(`--${key}`, String(value));
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
+
63
179
  // src/TokenProvider.jsx
64
180
  var import_jsx_runtime = require("react/jsx-runtime");
181
+ var devWarn = (msg) => {
182
+ try {
183
+ if (typeof process !== "undefined" && process.env && true) {
184
+ console.warn(`[sorb] ${msg}`);
185
+ }
186
+ } catch (e) {
187
+ }
188
+ };
65
189
  var SorbProvider = ({ config, children }) => {
66
190
  const [activeTokens, setActiveTokens] = (0, import_react2.useState)(config.tokens);
67
191
  const [isPreview, setIsPreview] = (0, import_react2.useState)(false);
@@ -75,7 +199,12 @@ var SorbProvider = ({ config, children }) => {
75
199
  }, [config.tokens]);
76
200
  const loadPreview = (0, import_react2.useCallback)(
77
201
  async (id) => {
78
- const origin = config.preview?.origin ?? "http://localhost:7777";
202
+ const guard = shouldLoadPreview(config);
203
+ if (!guard.allowed) {
204
+ loadCommitted();
205
+ return false;
206
+ }
207
+ const origin = guard.origin;
79
208
  try {
80
209
  const res = await fetch(`${origin}/preview/${id}`);
81
210
  if (!res.ok) throw new Error("preview not found");
@@ -85,12 +214,12 @@ var SorbProvider = ({ config, children }) => {
85
214
  setIsPreview(true);
86
215
  setPreviewId(id);
87
216
  return true;
88
- } catch {
217
+ } catch (e) {
89
218
  loadCommitted();
90
219
  return false;
91
220
  }
92
221
  },
93
- [config.preview?.origin, loadCommitted]
222
+ [config, loadCommitted]
94
223
  );
95
224
  const clearPreview = (0, import_react2.useCallback)(() => {
96
225
  if (pollRef.current) clearInterval(pollRef.current);
@@ -101,9 +230,14 @@ var SorbProvider = ({ config, children }) => {
101
230
  loadCommitted();
102
231
  }, [loadCommitted]);
103
232
  (0, import_react2.useEffect)(() => {
104
- const previewEnabled = config.preview?.enabled ?? false;
233
+ const guard = shouldLoadPreview(config);
105
234
  const id = new URLSearchParams(location.search).get("preview");
106
- if (!previewEnabled || !id) {
235
+ if (!guard.allowed || !id) {
236
+ if (id && !guard.allowed) {
237
+ devWarn(
238
+ `ignoring ?preview= \u2014 preview not permitted (${guard.reason ?? "blocked"}); loading committed tokens`
239
+ );
240
+ }
107
241
  loadCommitted();
108
242
  return;
109
243
  }
@@ -214,4 +348,48 @@ var PreviewBanner = () => {
214
348
  }
215
349
  );
216
350
  };
351
+
352
+ // src/verify.js
353
+ var toCssVar = (name) => {
354
+ const s = String(name).trim();
355
+ return s.startsWith("--") ? s : `--${s}`;
356
+ };
357
+ var verifyResolved = async (tokens, { origin = "http://localhost:7777", fetch: fetchImpl } = {}) => {
358
+ if (typeof document === "undefined" || !document.documentElement) {
359
+ return { ok: false, reason: "no-dom" };
360
+ }
361
+ if (!Array.isArray(tokens) || tokens.length === 0) {
362
+ return { ok: false, reason: "no-tokens" };
363
+ }
364
+ const cs = getComputedStyle(document.documentElement);
365
+ const values = {};
366
+ for (const t of tokens) {
367
+ const cssVar = toCssVar(t);
368
+ values[cssVar] = cs.getPropertyValue(cssVar).trim();
369
+ }
370
+ const unapplied = Object.entries(values).filter(([, v]) => v.startsWith("var(")).map(([k]) => k);
371
+ if (unapplied.length) return { ok: false, reason: "provider-not-applied", unapplied };
372
+ const f = fetchImpl || (typeof fetch !== "undefined" ? fetch : globalThis.fetch);
373
+ if (typeof f !== "function") return { ok: false, reason: "no-fetch" };
374
+ const base = String(origin).replace(/\/+$/, "");
375
+ try {
376
+ const res = await f(`${base}/verify/app`, {
377
+ method: "POST",
378
+ headers: { "Content-Type": "application/json" },
379
+ body: JSON.stringify({ values })
380
+ });
381
+ if (!res.ok) {
382
+ let detail = "";
383
+ try {
384
+ const b = await res.json();
385
+ detail = b && b.error ? b.error : "";
386
+ } catch (e) {
387
+ }
388
+ return { ok: false, reason: "bridge-error", error: `${res.status}${detail ? ` \u2014 ${detail}` : ""}` };
389
+ }
390
+ return await res.json();
391
+ } catch (e) {
392
+ return { ok: false, reason: "bridge-unreachable", error: e && e.message };
393
+ }
394
+ };
217
395
  //# 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": ";;;;;;;;;;;;;;;;;;;;;;;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Y;AAAA,cACZ,QAAQ;AAAA,cACR,OAAO;AAAA,cACP,SAAS;AAAA,cACT,cAAc;AAAA,cACd,QAAQ;AAAA,cACR,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,YAAY;AAAA,YACd;AAAA,YACA,cAAc,CAAC,MACZ,EAAE,OAAO,MAAM,aAAa;AAAA,YAE/B,cAAc,CAAC,MACZ,EAAE,OAAO,MAAM,aAAa;AAAA,YAEhC;AAAA;AAAA,QAED;AAAA;AAAA;AAAA,EACF;AAEJ;",
3
+ "sources": ["../src/index.js", "../src/TokenProvider.jsx", "../src/context.js", "../src/sanitize.js", "../src/apply.js", "../src/previewGuard.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'\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 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 (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", "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\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, fetch?: typeof globalThis.fetch }} [opts]\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', 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 headers: { '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,gB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AAK;AAAA,EACpD;AAKA,QAAM,YAAY,OAAO,QAAQ,MAAM,EACpC,OAAO,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,MAAM,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,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,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,138 @@ 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
- root.style.setProperty(`--${key}`, String(value));
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
+
23
137
  // src/TokenProvider.jsx
24
138
  import { jsx } from "react/jsx-runtime";
139
+ var devWarn = (msg) => {
140
+ try {
141
+ if (typeof process !== "undefined" && process.env && true) {
142
+ console.warn(`[sorb] ${msg}`);
143
+ }
144
+ } catch (e) {
145
+ }
146
+ };
25
147
  var SorbProvider = ({ config, children }) => {
26
148
  const [activeTokens, setActiveTokens] = useState(config.tokens);
27
149
  const [isPreview, setIsPreview] = useState(false);
@@ -35,7 +157,12 @@ var SorbProvider = ({ config, children }) => {
35
157
  }, [config.tokens]);
36
158
  const loadPreview = useCallback(
37
159
  async (id) => {
38
- const origin = config.preview?.origin ?? "http://localhost:7777";
160
+ const guard = shouldLoadPreview(config);
161
+ if (!guard.allowed) {
162
+ loadCommitted();
163
+ return false;
164
+ }
165
+ const origin = guard.origin;
39
166
  try {
40
167
  const res = await fetch(`${origin}/preview/${id}`);
41
168
  if (!res.ok) throw new Error("preview not found");
@@ -45,12 +172,12 @@ var SorbProvider = ({ config, children }) => {
45
172
  setIsPreview(true);
46
173
  setPreviewId(id);
47
174
  return true;
48
- } catch {
175
+ } catch (e) {
49
176
  loadCommitted();
50
177
  return false;
51
178
  }
52
179
  },
53
- [config.preview?.origin, loadCommitted]
180
+ [config, loadCommitted]
54
181
  );
55
182
  const clearPreview = useCallback(() => {
56
183
  if (pollRef.current) clearInterval(pollRef.current);
@@ -61,9 +188,14 @@ var SorbProvider = ({ config, children }) => {
61
188
  loadCommitted();
62
189
  }, [loadCommitted]);
63
190
  useEffect(() => {
64
- const previewEnabled = config.preview?.enabled ?? false;
191
+ const guard = shouldLoadPreview(config);
65
192
  const id = new URLSearchParams(location.search).get("preview");
66
- if (!previewEnabled || !id) {
193
+ if (!guard.allowed || !id) {
194
+ if (id && !guard.allowed) {
195
+ devWarn(
196
+ `ignoring ?preview= \u2014 preview not permitted (${guard.reason ?? "blocked"}); loading committed tokens`
197
+ );
198
+ }
67
199
  loadCommitted();
68
200
  return;
69
201
  }
@@ -174,12 +306,58 @@ var PreviewBanner = () => {
174
306
  }
175
307
  );
176
308
  };
309
+
310
+ // src/verify.js
311
+ var toCssVar = (name) => {
312
+ const s = String(name).trim();
313
+ return s.startsWith("--") ? s : `--${s}`;
314
+ };
315
+ var verifyResolved = async (tokens, { origin = "http://localhost:7777", fetch: fetchImpl } = {}) => {
316
+ if (typeof document === "undefined" || !document.documentElement) {
317
+ return { ok: false, reason: "no-dom" };
318
+ }
319
+ if (!Array.isArray(tokens) || tokens.length === 0) {
320
+ return { ok: false, reason: "no-tokens" };
321
+ }
322
+ const cs = getComputedStyle(document.documentElement);
323
+ const values = {};
324
+ for (const t of tokens) {
325
+ const cssVar = toCssVar(t);
326
+ values[cssVar] = cs.getPropertyValue(cssVar).trim();
327
+ }
328
+ const unapplied = Object.entries(values).filter(([, v]) => v.startsWith("var(")).map(([k]) => k);
329
+ if (unapplied.length) return { ok: false, reason: "provider-not-applied", unapplied };
330
+ const f = fetchImpl || (typeof fetch !== "undefined" ? fetch : globalThis.fetch);
331
+ if (typeof f !== "function") return { ok: false, reason: "no-fetch" };
332
+ const base = String(origin).replace(/\/+$/, "");
333
+ try {
334
+ const res = await f(`${base}/verify/app`, {
335
+ method: "POST",
336
+ headers: { "Content-Type": "application/json" },
337
+ body: JSON.stringify({ values })
338
+ });
339
+ if (!res.ok) {
340
+ let detail = "";
341
+ try {
342
+ const b = await res.json();
343
+ detail = b && b.error ? b.error : "";
344
+ } catch (e) {
345
+ }
346
+ return { ok: false, reason: "bridge-error", error: `${res.status}${detail ? ` \u2014 ${detail}` : ""}` };
347
+ }
348
+ return await res.json();
349
+ } catch (e) {
350
+ return { ok: false, reason: "bridge-unreachable", error: e && e.message };
351
+ }
352
+ };
177
353
  export {
178
354
  PreviewBanner,
179
355
  SorbProvider,
356
+ sanitizeCssValue,
180
357
  useIsPreview,
181
358
  usePreviewState,
182
359
  useToken,
183
- useTokens
360
+ useTokens,
361
+ verifyResolved
184
362
  };
185
363
  //# sourceMappingURL=index.mjs.map
@@ -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;;;ACLO,IAAM,cAAc,CAAC,WAAW;AACrC,QAAM,OAAO,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AEJ;",
3
+ "sources": ["../src/TokenProvider.jsx", "../src/context.js", "../src/sanitize.js", "../src/apply.js", "../src/previewGuard.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'\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 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 (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", "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\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, fetch?: typeof globalThis.fetch }} [opts]\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', 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 headers: { '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,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,MAAI,cAAc,KAAK,GAAG,GAAG;AAC3B,WAAO,EAAE,IAAI,OAAO,OAAO,KAAK,QAAQ,qBAAqB;AAAA,EAC/D;AAKA,QAAM,QAAQ,IAAI,YAAY;A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B,mBAAmB;AAAA,MAC9C,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": ["React", "jsx"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sorb/leaf",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
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
  },