@govtechsg/sgds-web-component 3.30.1-rc.0 → 3.30.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/custom-elements.json +1 -1
- package/package.json +1 -1
- package/react/_ssr/utils/ssr-nonce.js.map +1 -1
- package/react/utils/ssr-nonce-patch.cjs.js +6 -5
- package/react/utils/ssr-nonce-patch.cjs.js.map +1 -1
- package/react/utils/ssr-nonce-patch.js +6 -6
- package/react/utils/ssr-nonce-patch.js.map +1 -1
- package/utils/ssr-nonce-patch.d.ts +4 -3
- package/react/_virtual/_rolldown/runtime.js +0 -8
package/custom-elements.json
CHANGED
|
@@ -32036,7 +32036,7 @@
|
|
|
32036
32036
|
"package": {
|
|
32037
32037
|
"name": "@govtechsg/sgds-web-component",
|
|
32038
32038
|
"description": "",
|
|
32039
|
-
"version": "3.30.1-rc.
|
|
32039
|
+
"version": "3.30.1-rc.1",
|
|
32040
32040
|
"author": "GovTechSG",
|
|
32041
32041
|
"license": "MIT"
|
|
32042
32042
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-nonce.js","names":[],"sources":["../../../../src/utils/ssr-nonce.ts"],"sourcesContent":["export function getCSPNonce(): string | null {\n return ((globalThis as Record<string, unknown>)[\"litNonce\"] as string) ?? null;\n}\n\n/**\n * Patch LitElementRenderer.renderShadow() to inject CSP nonces into\n * DSD <style> tags. Call this ONCE at server startup from instrumentation.ts.\n *\n * This must run before any SSR request is handled. Next.js's\n * instrumentation.ts `register()` hook guarantees this.\n */\nexport async function registerSSRNonce(): Promise<void> {\n if (typeof window !== \"undefined\") return;\n\n try {\n const { LitElementRenderer } = await import(\"@lit-labs/ssr/lib/lit-element-renderer.js\");\n\n // Guard against double-patching\n if ((LitElementRenderer as Record<string, unknown>)._sgdsNoncePatched) {\n return;\n }\n (LitElementRenderer as Record<string, unknown>)._sgdsNoncePatched = true;\n\n const originalRenderShadow = LitElementRenderer.prototype.renderShadow;\n\n LitElementRenderer.prototype.renderShadow = function (renderInfo: unknown) {\n const result = originalRenderShadow.call(this, renderInfo);\n if (!result) return result;\n\n const litNonce = (globalThis as Record<string, unknown>)[\"litNonce\"];\n if (!litNonce) return result;\n\n return result.map((item: unknown) => {\n if (typeof item === \"string\" && item === \"<style>\") {\n return `<style nonce=\"${litNonce}\">`;\n }\n return item;\n });\n };\n } catch {\n // @lit-labs/ssr not available — nonce injection disabled\n }\n}\n\n/**\n * CSP nonce for Declarative Shadow DOM (DSD) styles.\n *\n * Two functions:\n * - `registerSSRNonce()` — call ONCE at server startup (instrumentation.ts).\n * Patches LitElementRenderer to respect globalThis.litNonce.\n * - `setCSPNonce()` — call per-request in layout.tsx.\n * Sets globalThis.litNonce for the current request.\n *\n * @example\n * ```ts\n * // instrumentation.ts\n * import { registerSSRNonce } from '@govtechsg/sgds-web-component/react/ssr';\n *\n * export async function register() {\n * await registerSSRNonce();\n * }\n * ```\n *\n * ```tsx\n * // app/layout.tsx (server component)\n * import { setCSPNonce } from '@govtechsg/sgds-web-component/react/ssr';\n * import { headers } from 'next/headers';\n *\n * export default async function Layout({ children }) {\n * const nonce = (await headers()).get('x-nonce');\n * if (nonce) setCSPNonce(nonce);\n * return <html><body>{children}</body></html>;\n * }\n * ```\n */\n/**\n * Set the CSP nonce for the current request. Call this in your server\n * component (e.g. layout.tsx) before SGDS components render.\n * This is synchronous — no await needed.\n */\nexport function setCSPNonce(nonce: string | null): void {\n (globalThis as Record<string, unknown>)[\"litNonce\"] = nonce ?? undefined;\n}\n"],"mappings":";AAAA,SAAgB,cAA6B;CAC3C,OAAS,WAAuC,eAA0B;AAC5E;;;;;;;;AASA,eAAsB,mBAAkC;CACtD,IAAI,OAAO,WAAW,aAAa;CAEnC,IAAI;EACF,MAAM,EAAE,uBAAuB,MAAM,OAAO;EAG5C,IAAK,
|
|
1
|
+
{"version":3,"file":"ssr-nonce.js","names":[],"sources":["../../../../src/utils/ssr-nonce.ts"],"sourcesContent":["export function getCSPNonce(): string | null {\n return ((globalThis as Record<string, unknown>)[\"litNonce\"] as string) ?? null;\n}\n\n/**\n * Patch LitElementRenderer.renderShadow() to inject CSP nonces into\n * DSD <style> tags. Call this ONCE at server startup from instrumentation.ts.\n *\n * This must run before any SSR request is handled. Next.js's\n * instrumentation.ts `register()` hook guarantees this.\n */\nexport async function registerSSRNonce(): Promise<void> {\n if (typeof window !== \"undefined\") return;\n\n try {\n const { LitElementRenderer } = await import(\"@lit-labs/ssr/lib/lit-element-renderer.js\");\n\n // Guard against double-patching\n if ((LitElementRenderer as unknown as Record<string, unknown>)._sgdsNoncePatched) {\n return;\n }\n (LitElementRenderer as unknown as Record<string, unknown>)._sgdsNoncePatched = true;\n\n const originalRenderShadow = LitElementRenderer.prototype.renderShadow;\n\n LitElementRenderer.prototype.renderShadow = function (renderInfo: unknown) {\n const result = originalRenderShadow.call(this, renderInfo);\n if (!result) return result;\n\n const litNonce = (globalThis as Record<string, unknown>)[\"litNonce\"];\n if (!litNonce) return result;\n\n return result.map((item: unknown) => {\n if (typeof item === \"string\" && item === \"<style>\") {\n return `<style nonce=\"${litNonce}\">`;\n }\n return item;\n });\n };\n } catch {\n // @lit-labs/ssr not available — nonce injection disabled\n }\n}\n\n/**\n * CSP nonce for Declarative Shadow DOM (DSD) styles.\n *\n * Two functions:\n * - `registerSSRNonce()` — call ONCE at server startup (instrumentation.ts).\n * Patches LitElementRenderer to respect globalThis.litNonce.\n * - `setCSPNonce()` — call per-request in layout.tsx.\n * Sets globalThis.litNonce for the current request.\n *\n * @example\n * ```ts\n * // instrumentation.ts\n * import { registerSSRNonce } from '@govtechsg/sgds-web-component/react/ssr';\n *\n * export async function register() {\n * await registerSSRNonce();\n * }\n * ```\n *\n * ```tsx\n * // app/layout.tsx (server component)\n * import { setCSPNonce } from '@govtechsg/sgds-web-component/react/ssr';\n * import { headers } from 'next/headers';\n *\n * export default async function Layout({ children }) {\n * const nonce = (await headers()).get('x-nonce');\n * if (nonce) setCSPNonce(nonce);\n * return <html><body>{children}</body></html>;\n * }\n * ```\n */\n/**\n * Set the CSP nonce for the current request. Call this in your server\n * component (e.g. layout.tsx) before SGDS components render.\n * This is synchronous — no await needed.\n */\nexport function setCSPNonce(nonce: string | null): void {\n (globalThis as Record<string, unknown>)[\"litNonce\"] = nonce ?? undefined;\n}\n"],"mappings":";AAAA,SAAgB,cAA6B;CAC3C,OAAS,WAAuC,eAA0B;AAC5E;;;;;;;;AASA,eAAsB,mBAAkC;CACtD,IAAI,OAAO,WAAW,aAAa;CAEnC,IAAI;EACF,MAAM,EAAE,uBAAuB,MAAM,OAAO;EAG5C,IAAK,mBAA0D,mBAC7D;EAEF,mBAA2D,oBAAoB;EAE/E,MAAM,uBAAuB,mBAAmB,UAAU;EAE1D,mBAAmB,UAAU,eAAe,SAAU,YAAqB;GACzE,MAAM,SAAS,qBAAqB,KAAK,MAAM,UAAU;GACzD,IAAI,CAAC,QAAQ,OAAO;GAEpB,MAAM,WAAY,WAAuC;GACzD,IAAI,CAAC,UAAU,OAAO;GAEtB,OAAO,OAAO,KAAK,SAAkB;IACnC,IAAI,OAAO,SAAS,YAAY,SAAS,WACvC,OAAO,iBAAiB,SAAS;IAEnC,OAAO;GACT,CAAC;EACH;CACF,QAAQ,CAER;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,YAAY,OAA4B;CACtD,WAAwC,cAAc,SAAS,KAAA;AACjE"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
let node_module = require("node:module");
|
|
2
3
|
//#region src/utils/ssr-nonce-patch.ts
|
|
3
4
|
/**
|
|
4
5
|
* Patches @lit-labs/ssr's LitElementRenderer.renderShadow() to respect
|
|
5
6
|
* globalThis.litNonce for CSP nonce injection.
|
|
6
7
|
*
|
|
7
|
-
* Uses
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Uses module.createRequire for SYNCHRONOUS module resolution in ESM.
|
|
9
|
+
* createRequire is a function call (not the bare `require` keyword),
|
|
10
|
+
* so Rolldown preserves it instead of transforming to __require().
|
|
10
11
|
*/
|
|
11
12
|
if (typeof window === "undefined") try {
|
|
12
|
-
const mod = (
|
|
13
|
+
const mod = (0, node_module.createRequire)({}.url)("@lit-labs/ssr/lib/lit-element-renderer.js");
|
|
13
14
|
const LitElementRenderer = mod.LitElementRenderer || mod.default?.LitElementRenderer;
|
|
14
15
|
if (LitElementRenderer && !LitElementRenderer._sgdsNoncePatched) {
|
|
15
16
|
LitElementRenderer._sgdsNoncePatched = true;
|
|
@@ -17,7 +18,7 @@ if (typeof window === "undefined") try {
|
|
|
17
18
|
LitElementRenderer.prototype.renderShadow = function(renderInfo) {
|
|
18
19
|
const result = originalRenderShadow.call(this, renderInfo);
|
|
19
20
|
if (!result) return result;
|
|
20
|
-
const nonce = globalThis
|
|
21
|
+
const nonce = globalThis.litNonce;
|
|
21
22
|
if (!nonce) return result;
|
|
22
23
|
return result.map((item) => {
|
|
23
24
|
if (typeof item === "string" && item === "<style>") return `<style nonce="${nonce}">`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-nonce-patch.cjs.js","names":[],"sources":["../../../src/utils/ssr-nonce-patch.ts"],"sourcesContent":["/**\n * Patches @lit-labs/ssr's LitElementRenderer.renderShadow() to respect\n * globalThis.litNonce for CSP nonce injection.\n *\n * Uses
|
|
1
|
+
{"version":3,"file":"ssr-nonce-patch.cjs.js","names":["createRequire"],"sources":["../../../src/utils/ssr-nonce-patch.ts"],"sourcesContent":["/**\n * Patches @lit-labs/ssr's LitElementRenderer.renderShadow() to respect\n * globalThis.litNonce for CSP nonce injection.\n *\n * Uses module.createRequire for SYNCHRONOUS module resolution in ESM.\n * createRequire is a function call (not the bare `require` keyword),\n * so Rolldown preserves it instead of transforming to __require().\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n// @ts-expect-error -- node:module types not in tsconfig (server-only, guarded by typeof window check)\nimport { createRequire } from \"node:module\";\n\nif (typeof window === \"undefined\") {\n try {\n const _require = createRequire(import.meta.url);\n const mod = _require(\"@lit-labs/ssr/lib/lit-element-renderer.js\");\n const LitElementRenderer =\n mod.LitElementRenderer || mod.default?.LitElementRenderer;\n\n if (LitElementRenderer && !LitElementRenderer._sgdsNoncePatched) {\n LitElementRenderer._sgdsNoncePatched = true;\n\n const originalRenderShadow =\n LitElementRenderer.prototype.renderShadow;\n\n LitElementRenderer.prototype.renderShadow = function (\n renderInfo: unknown\n ) {\n const result = originalRenderShadow.call(this, renderInfo);\n if (!result) return result;\n\n const nonce = (globalThis as any).litNonce;\n if (!nonce) return result;\n\n return result.map((item: unknown) => {\n if (typeof item === \"string\" && item === \"<style>\") {\n return `<style nonce=\"${nonce}\">`;\n }\n return item;\n });\n };\n }\n } catch {\n // @lit-labs/ssr not available — nonce injection disabled\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAI,OAAO,WAAW,aACpB,IAAI;CAEF,MAAM,OAAA,GADWA,YAAAA,cAAAA,CAAAA,CAAAA,EAA0B,GACxB,CAAC,CAAC,2CAA2C;CAChE,MAAM,qBACJ,IAAI,sBAAsB,IAAI,SAAS;CAEzC,IAAI,sBAAsB,CAAC,mBAAmB,mBAAmB;EAC/D,mBAAmB,oBAAoB;EAEvC,MAAM,uBACJ,mBAAmB,UAAU;EAE/B,mBAAmB,UAAU,eAAe,SAC1C,YACA;GACA,MAAM,SAAS,qBAAqB,KAAK,MAAM,UAAU;GACzD,IAAI,CAAC,QAAQ,OAAO;GAEpB,MAAM,QAAS,WAAmB;GAClC,IAAI,CAAC,OAAO,OAAO;GAEnB,OAAO,OAAO,KAAK,SAAkB;IACnC,IAAI,OAAO,SAAS,YAAY,SAAS,WACvC,OAAO,iBAAiB,MAAM;IAEhC,OAAO;GACT,CAAC;EACH;CACF;AACF,QAAQ,CAER"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
3
|
//#region src/utils/ssr-nonce-patch.ts
|
|
4
4
|
/**
|
|
5
5
|
* Patches @lit-labs/ssr's LitElementRenderer.renderShadow() to respect
|
|
6
6
|
* globalThis.litNonce for CSP nonce injection.
|
|
7
7
|
*
|
|
8
|
-
* Uses
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Uses module.createRequire for SYNCHRONOUS module resolution in ESM.
|
|
9
|
+
* createRequire is a function call (not the bare `require` keyword),
|
|
10
|
+
* so Rolldown preserves it instead of transforming to __require().
|
|
11
11
|
*/
|
|
12
12
|
if (typeof window === "undefined") try {
|
|
13
|
-
const mod = (
|
|
13
|
+
const mod = createRequire(import.meta.url)("@lit-labs/ssr/lib/lit-element-renderer.js");
|
|
14
14
|
const LitElementRenderer = mod.LitElementRenderer || mod.default?.LitElementRenderer;
|
|
15
15
|
if (LitElementRenderer && !LitElementRenderer._sgdsNoncePatched) {
|
|
16
16
|
LitElementRenderer._sgdsNoncePatched = true;
|
|
@@ -18,7 +18,7 @@ if (typeof window === "undefined") try {
|
|
|
18
18
|
LitElementRenderer.prototype.renderShadow = function(renderInfo) {
|
|
19
19
|
const result = originalRenderShadow.call(this, renderInfo);
|
|
20
20
|
if (!result) return result;
|
|
21
|
-
const nonce = globalThis
|
|
21
|
+
const nonce = globalThis.litNonce;
|
|
22
22
|
if (!nonce) return result;
|
|
23
23
|
return result.map((item) => {
|
|
24
24
|
if (typeof item === "string" && item === "<style>") return `<style nonce="${nonce}">`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-nonce-patch.js","names":[],"sources":["../../../src/utils/ssr-nonce-patch.ts"],"sourcesContent":["/**\n * Patches @lit-labs/ssr's LitElementRenderer.renderShadow() to respect\n * globalThis.litNonce for CSP nonce injection.\n *\n * Uses
|
|
1
|
+
{"version":3,"file":"ssr-nonce-patch.js","names":[],"sources":["../../../src/utils/ssr-nonce-patch.ts"],"sourcesContent":["/**\n * Patches @lit-labs/ssr's LitElementRenderer.renderShadow() to respect\n * globalThis.litNonce for CSP nonce injection.\n *\n * Uses module.createRequire for SYNCHRONOUS module resolution in ESM.\n * createRequire is a function call (not the bare `require` keyword),\n * so Rolldown preserves it instead of transforming to __require().\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n// @ts-expect-error -- node:module types not in tsconfig (server-only, guarded by typeof window check)\nimport { createRequire } from \"node:module\";\n\nif (typeof window === \"undefined\") {\n try {\n const _require = createRequire(import.meta.url);\n const mod = _require(\"@lit-labs/ssr/lib/lit-element-renderer.js\");\n const LitElementRenderer =\n mod.LitElementRenderer || mod.default?.LitElementRenderer;\n\n if (LitElementRenderer && !LitElementRenderer._sgdsNoncePatched) {\n LitElementRenderer._sgdsNoncePatched = true;\n\n const originalRenderShadow =\n LitElementRenderer.prototype.renderShadow;\n\n LitElementRenderer.prototype.renderShadow = function (\n renderInfo: unknown\n ) {\n const result = originalRenderShadow.call(this, renderInfo);\n if (!result) return result;\n\n const nonce = (globalThis as any).litNonce;\n if (!nonce) return result;\n\n return result.map((item: unknown) => {\n if (typeof item === \"string\" && item === \"<style>\") {\n return `<style nonce=\"${nonce}\">`;\n }\n return item;\n });\n };\n }\n } catch {\n // @lit-labs/ssr not available — nonce injection disabled\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAI,OAAO,WAAW,aACpB,IAAI;CAEF,MAAM,MADW,cAAc,YAAY,GACxB,CAAC,CAAC,2CAA2C;CAChE,MAAM,qBACJ,IAAI,sBAAsB,IAAI,SAAS;CAEzC,IAAI,sBAAsB,CAAC,mBAAmB,mBAAmB;EAC/D,mBAAmB,oBAAoB;EAEvC,MAAM,uBACJ,mBAAmB,UAAU;EAE/B,mBAAmB,UAAU,eAAe,SAC1C,YACA;GACA,MAAM,SAAS,qBAAqB,KAAK,MAAM,UAAU;GACzD,IAAI,CAAC,QAAQ,OAAO;GAEpB,MAAM,QAAS,WAAmB;GAClC,IAAI,CAAC,OAAO,OAAO;GAEnB,OAAO,OAAO,KAAK,SAAkB;IACnC,IAAI,OAAO,SAAS,YAAY,SAAS,WACvC,OAAO,iBAAiB,MAAM;IAEhC,OAAO;GACT,CAAC;EACH;CACF;AACF,QAAQ,CAER"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Patches @lit-labs/ssr's LitElementRenderer.renderShadow() to respect
|
|
3
3
|
* globalThis.litNonce for CSP nonce injection.
|
|
4
4
|
*
|
|
5
|
-
* Uses
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Uses module.createRequire for SYNCHRONOUS module resolution in ESM.
|
|
6
|
+
* createRequire is a function call (not the bare `require` keyword),
|
|
7
|
+
* so Rolldown preserves it instead of transforming to __require().
|
|
8
8
|
*/
|
|
9
|
+
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
//#region \0rolldown/runtime.js
|
|
3
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
6
|
-
});
|
|
7
|
-
//#endregion
|
|
8
|
-
export { __require };
|