@styleflow.app/flowpress-astro-core 1.0.0-beta.5 → 1.0.0-beta.6
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/CHANGELOG.md +12 -1
- package/README.md +41 -3
- package/dist/astro/BaseLayout.astro +5 -1
- package/dist/astro/CompositionRenderer.astro +126 -0
- package/dist/astro/DefaultTemplate.astro +6 -1
- package/dist/astro/GutenbergRenderer.astro +62 -51
- package/dist/astro/ThemeRuntime.astro +24 -0
- package/dist/astro/blocks/CarouselBlock.astro +4 -6
- package/dist/astro/blocks/CarouselItemBlock.astro +2 -2
- package/dist/astro/blocks/ColumnBlock.astro +2 -3
- package/dist/astro/blocks/FormBlock.astro +5 -5
- package/dist/astro/blocks/GridBlock.astro +2 -2
- package/dist/astro/blocks/HeroBlock.astro +2 -3
- package/dist/astro/blocks/ImageBlock.astro +2 -3
- package/dist/astro/blocks/ListItemFallback.astro +4 -4
- package/dist/astro/blocks/NumberSpinnerBlock.astro +24 -18
- package/dist/astro/blocks/SemanticElement.astro +35 -0
- package/dist/astro/blocks/SiteLogoBlock.astro +53 -0
- package/dist/astro/blocks/TextBlock.astro +27 -23
- package/dist/astro/blocks/ThemeToggleBlock.astro +23 -0
- package/dist/astro/blocks/helpers.d.ts +7 -0
- package/dist/astro/blocks/helpers.d.ts.map +1 -1
- package/dist/astro/blocks/helpers.js +49 -36
- package/dist/astro/blocks/helpers.js.map +1 -1
- package/dist/astro/blocks/helpers.ts +61 -40
- package/dist/block-renderers.d.ts +18 -2
- package/dist/block-renderers.d.ts.map +1 -1
- package/dist/block-renderers.js.map +1 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +31 -0
- package/dist/client.js.map +1 -1
- package/dist/composition.d.ts +14 -0
- package/dist/composition.d.ts.map +1 -0
- package/dist/composition.js +86 -0
- package/dist/composition.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/styleflow.d.ts +2 -0
- package/dist/styleflow.d.ts.map +1 -1
- package/dist/styleflow.js +35 -1
- package/dist/styleflow.js.map +1 -1
- package/dist/theme-runtime.d.ts +16 -0
- package/dist/theme-runtime.d.ts.map +1 -0
- package/dist/theme-runtime.js +77 -0
- package/dist/theme-runtime.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +73 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +7 -3
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { AstroComponentFactory } from "astro/runtime/server/index.js";
|
|
2
|
-
import type { StyleflowContract } from "./styleflow.js";
|
|
3
|
-
import type { FlowpressBlock } from "./types.js";
|
|
2
|
+
import type { DynamicStyleflowProps, StyleflowContract } from "./styleflow.js";
|
|
3
|
+
import type { FlowpressBlock, FlowpressBlockHtmlProps, FlowpressBlockAdapterStatus, FlowpressBlockClass, FlowpressCompositionV1 } from "./types.js";
|
|
4
4
|
export interface FlowpressBlockRendererProps {
|
|
5
5
|
block: FlowpressBlock;
|
|
6
|
+
styleflowProps: DynamicStyleflowProps;
|
|
7
|
+
htmlProps: FlowpressBlockHtmlProps;
|
|
8
|
+
composition: FlowpressCompositionV1;
|
|
9
|
+
context: {
|
|
10
|
+
parentBlockName?: string;
|
|
11
|
+
depth: number;
|
|
12
|
+
production: boolean;
|
|
13
|
+
};
|
|
14
|
+
parentBlockName?: string;
|
|
6
15
|
contract?: StyleflowContract;
|
|
7
16
|
}
|
|
8
17
|
export interface FlowpressIconRendererProps {
|
|
@@ -19,4 +28,11 @@ export interface FlowpressIconRendererProps {
|
|
|
19
28
|
export type FlowpressBlockRenderer = AstroComponentFactory;
|
|
20
29
|
export type FlowpressIconRenderer = AstroComponentFactory;
|
|
21
30
|
export type FlowpressBlockRenderers = Readonly<Record<string, FlowpressBlockRenderer>>;
|
|
31
|
+
export interface FlowpressBlockAdapterDefinition {
|
|
32
|
+
renderer: FlowpressBlockRenderer;
|
|
33
|
+
status: FlowpressBlockAdapterStatus;
|
|
34
|
+
class: FlowpressBlockClass;
|
|
35
|
+
fingerprint: string;
|
|
36
|
+
}
|
|
37
|
+
export type FlowpressBlockAdapters = Readonly<Record<string, FlowpressBlockAdapterDefinition>>;
|
|
22
38
|
//# sourceMappingURL=block-renderers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-renderers.d.ts","sourceRoot":"","sources":["../src/block-renderers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"block-renderers.d.ts","sourceRoot":"","sources":["../src/block-renderers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACvB,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,cAAc,CAAC;IACtB,cAAc,EAAE,qBAAqB,CAAC;IACtC,SAAS,EAAE,uBAAuB,CAAC;IACnC,WAAW,EAAE,sBAAsB,CAAC;IACpC,OAAO,EAAE;QACP,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,OAAO,CAAC;KACrB,CAAC;IACF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC9B;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE1D,MAAM,MAAM,uBAAuB,GAAG,QAAQ,CAC5C,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CACvC,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,EAAE,sBAAsB,CAAC;IACjC,MAAM,EAAE,2BAA2B,CAAC;IACpC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAC3C,MAAM,CAAC,MAAM,EAAE,+BAA+B,CAAC,CAChD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-renderers.js","sourceRoot":"","sources":["../src/block-renderers.ts"],"names":[],"mappings":"","sourcesContent":["import type { AstroComponentFactory } from \"astro/runtime/server/index.js\";\nimport type { StyleflowContract } from \"./styleflow.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"block-renderers.js","sourceRoot":"","sources":["../src/block-renderers.ts"],"names":[],"mappings":"","sourcesContent":["import type { AstroComponentFactory } from \"astro/runtime/server/index.js\";\nimport type { DynamicStyleflowProps, StyleflowContract } from \"./styleflow.js\";\nimport type {\n FlowpressBlock,\n FlowpressBlockHtmlProps,\n FlowpressBlockAdapterStatus,\n FlowpressBlockClass,\n FlowpressCompositionV1\n} from \"./types.js\";\n\nexport interface FlowpressBlockRendererProps {\n block: FlowpressBlock;\n styleflowProps: DynamicStyleflowProps;\n htmlProps: FlowpressBlockHtmlProps;\n composition: FlowpressCompositionV1;\n context: {\n parentBlockName?: string;\n depth: number;\n production: boolean;\n };\n parentBlockName?: string;\n contract?: StyleflowContract;\n}\n\nexport interface FlowpressIconRendererProps {\n name: string;\n display?: \"inline\" | \"block\";\n foreground?: string;\n tone?: string;\n intensity?: string | number;\n size?: number;\n label?: string;\n id?: string;\n class?: string;\n}\n\nexport type FlowpressBlockRenderer = AstroComponentFactory;\n\nexport type FlowpressIconRenderer = AstroComponentFactory;\n\nexport type FlowpressBlockRenderers = Readonly<\n Record<string, FlowpressBlockRenderer>\n>;\n\nexport interface FlowpressBlockAdapterDefinition {\n renderer: FlowpressBlockRenderer;\n status: FlowpressBlockAdapterStatus;\n class: FlowpressBlockClass;\n fingerprint: string;\n}\n\nexport type FlowpressBlockAdapters = Readonly<\n Record<string, FlowpressBlockAdapterDefinition>\n>;\n"]}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FlowpressCapabilities, FlowpressContent, FlowpressRoute } from "./types.js";
|
|
1
|
+
import type { FlowpressCapabilities, FlowpressCompositionV1, FlowpressContent, FlowpressRoute } from "./types.js";
|
|
2
2
|
export interface FlowpressGraphqlIssue {
|
|
3
3
|
message?: string;
|
|
4
4
|
extensions?: {
|
|
@@ -31,5 +31,6 @@ export declare class FlowpressClient {
|
|
|
31
31
|
getRoute(uri: string, locale?: string): Promise<FlowpressRoute | null>;
|
|
32
32
|
getRoutes(locale?: string): Promise<FlowpressRoute[]>;
|
|
33
33
|
getContent(loader: string, variables: Record<string, unknown>): Promise<FlowpressContent | null>;
|
|
34
|
+
getComposition(uri: string, locale?: string): Promise<FlowpressCompositionV1 | null>;
|
|
34
35
|
}
|
|
35
36
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1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"}
|
package/dist/client.js
CHANGED
|
@@ -209,6 +209,29 @@ export class FlowpressClient {
|
|
|
209
209
|
projectFields: parseJson(projectFieldsJson, {})
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
|
+
async getComposition(uri, locale) {
|
|
213
|
+
const data = await this.request(`query FlowpressComposition($uri: String!, $locale: String) {
|
|
214
|
+
sfCompositionByUri(uri: $uri, locale: $locale) {
|
|
215
|
+
version sourceDigest locale templateJson blocksJson stylesheetsJson blockTypesJson
|
|
216
|
+
diagnosticsJson routeJson contentJson
|
|
217
|
+
}
|
|
218
|
+
}`, { uri, locale: locale ?? null });
|
|
219
|
+
const wire = data.sfCompositionByUri;
|
|
220
|
+
if (!wire)
|
|
221
|
+
return null;
|
|
222
|
+
return {
|
|
223
|
+
version: wire.version,
|
|
224
|
+
sourceDigest: wire.sourceDigest,
|
|
225
|
+
locale: wire.locale ?? null,
|
|
226
|
+
template: parseRequiredJson(wire.templateJson, "templateJson"),
|
|
227
|
+
blocks: parseRequiredJson(wire.blocksJson, "blocksJson"),
|
|
228
|
+
stylesheets: parseRequiredJson(wire.stylesheetsJson, "stylesheetsJson"),
|
|
229
|
+
blockTypes: parseRequiredJson(wire.blockTypesJson, "blockTypesJson"),
|
|
230
|
+
diagnostics: parseRequiredJson(wire.diagnosticsJson, "diagnosticsJson"),
|
|
231
|
+
route: parseRequiredJson(wire.routeJson, "routeJson"),
|
|
232
|
+
content: parseJson(wire.contentJson, null)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
212
235
|
}
|
|
213
236
|
function getOperationName(query) {
|
|
214
237
|
return query.match(/\b(?:query|mutation|subscription)\s+([_A-Za-z][_0-9A-Za-z]*)/)?.[1] || "AnonymousOperation";
|
|
@@ -255,4 +278,12 @@ function parseJson(value, fallback) {
|
|
|
255
278
|
return fallback;
|
|
256
279
|
}
|
|
257
280
|
}
|
|
281
|
+
function parseRequiredJson(value, field) {
|
|
282
|
+
try {
|
|
283
|
+
return JSON.parse(value);
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
throw new FlowpressGraphqlError(`FlowPress composition field ${field} is not valid JSON.`, undefined, undefined, "FlowpressComposition", undefined, error);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
258
289
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA2BA,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAGnC;IACA;IACA;IACA;IALX,YACE,OAAe,EACN,MAAe,EACf,MAAgC,EAChC,aAAsB,EACtB,QAAiB,EAC1B,KAAe;QAEf,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QANnD,WAAM,GAAN,MAAM,CAAS;QACf,WAAM,GAAN,MAAM,CAA0B;QAChC,kBAAa,GAAb,aAAa,CAAS;QACtB,aAAQ,GAAR,QAAQ,CAAS;QAI1B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,eAAe;IACjB,QAAQ,CAAS;IACjB,SAAS,CAAS;IAClB,OAAO,CAAyB;IAChC,KAAK,CAAU;IAExB,YAAY,OAA+B;QACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;QAC7C,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,CAAC,OAA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AC,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE;gBAC5D,CAAC,CAAC,IAAI;SACT;QACH,CAAC,CAAC,IAAI,CAAC;IAET,OAAO;QACL,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,IAAI;QACxB,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,IAAI;QACpC,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,IAAI;QACtC,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;QAC1B,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,IAAI;QAC9B,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC;QACxC,QAAQ,EAAE,GAAG,CAAC,QAAQ,IAAI,IAAI;QAC9B,SAAS,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC;KACjC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAI,KAAgC,EAAE,QAAW;IACjE,IAAI,CAAC,KAAK;QAAE,OAAO,QAAQ,CAAC;IAC5B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC","sourcesContent":["import type {\n FlowpressCapabilities,\n FlowpressContent,\n FlowpressRoute\n} from \"./types.js\";\n\nexport interface FlowpressGraphqlIssue {\n message?: string;\n extensions?: {\n debugMessage?: string;\n category?: string;\n [key: string]: unknown;\n };\n}\n\ninterface GraphqlResponse<T> {\n data?: T;\n errors?: FlowpressGraphqlIssue[];\n}\n\nexport interface FlowpressClientOptions {\n endpoint: string;\n timeoutMs?: number;\n headers?: Record<string, string>;\n debug?: boolean;\n}\n\nexport class FlowpressGraphqlError extends Error {\n constructor(\n message: string,\n readonly status?: number,\n readonly errors?: FlowpressGraphqlIssue[],\n readonly operationName?: string,\n readonly endpoint?: string,\n cause?: unknown\n ) {\n super(message, cause === undefined ? undefined : { cause });\n this.name = \"FlowpressGraphqlError\";\n }\n}\n\nexport class FlowpressClient {\n readonly endpoint: string;\n readonly timeoutMs: number;\n readonly headers: Record<string, string>;\n readonly debug: boolean;\n\n constructor(options: FlowpressClientOptions) {\n const endpoint = options.endpoint.trim();\n if (!endpoint) {\n throw new Error(\"FlowPress GraphQL endpoint is required.\");\n }\n\n new URL(endpoint);\n this.endpoint = endpoint;\n this.timeoutMs = options.timeoutMs ?? 15_000;\n this.headers = { ...options.headers };\n this.debug = options.debug ?? false;\n }\n\n async request<T>(\n query: string,\n variables: Record<string, unknown> = {}\n ): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n const operationName = getOperationName(query);\n const safeEndpoint = sanitizeEndpoint(this.endpoint);\n\n try {\n let response: Response;\n try {\n response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...this.headers\n },\n body: JSON.stringify({ query, variables }),\n signal: controller.signal\n });\n } catch (error) {\n const timedOut = controller.signal.aborted;\n const detail = error instanceof Error && error.message\n ? ` ${error.message}`\n : \"\";\n throw new FlowpressGraphqlError(\n timedOut\n ? `FlowPress GraphQL ${operationName} timed out after ${this.timeoutMs}ms at ${safeEndpoint}.`\n : `FlowPress GraphQL ${operationName} could not reach ${safeEndpoint}.${detail}`,\n undefined,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n const body = await response.text();\n let payload: GraphqlResponse<T>;\n try {\n payload = JSON.parse(body) as GraphqlResponse<T>;\n } catch (error) {\n const contentType = response.headers.get(\"content-type\") || \"unknown content type\";\n throw new FlowpressGraphqlError(\n `FlowPress GraphQL ${operationName} returned ${response.status} `\n + `with ${contentType}, not JSON, from ${safeEndpoint}.`,\n response.status,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n if (!response.ok || payload.errors?.length || payload.data === undefined) {\n const errors: FlowpressGraphqlIssue[] | undefined = payload.errors?.map(\n (error) => {\n if (this.debug) {\n return error;\n }\n return error.message ? { message: error.message } : {};\n }\n );\n const messages = errors\n ?.flatMap((error) => [\n error.message,\n this.debug ? error.extensions?.debugMessage : undefined\n ])\n .filter((message): message is string => Boolean(message));\n throw new FlowpressGraphqlError(\n messages?.join(\"; \")\n || `FlowPress GraphQL ${operationName} failed with ${response.status} at ${safeEndpoint}.`,\n response.status,\n errors,\n operationName,\n safeEndpoint\n );\n }\n\n return payload.data;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async getCapabilities(): Promise<FlowpressCapabilities> {\n const data = await this.request<{ styleflowCapabilities: FlowpressCapabilities }>(\n `query FlowpressCapabilities {\n styleflowCapabilities {\n schemaVersion\n wpGraphql\n acfPro\n wpGraphqlAcf\n rankMath\n wpml\n woocommerce\n contactForm7\n defaultLocale\n locales { code slug homeUrl }\n features { id version enabled capabilities configJson }\n }\n }`\n );\n return {\n ...data.styleflowCapabilities,\n features: (data.styleflowCapabilities.features ?? []).map((feature) => {\n const wire = feature as typeof feature & { configJson?: string | null };\n let config: Record<string, unknown> = {};\n if (wire.configJson) {\n try {\n const parsed = JSON.parse(wire.configJson);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n config = parsed as Record<string, unknown>;\n }\n } catch {\n config = {};\n }\n }\n return {\n id: feature.id,\n version: feature.version ?? null,\n enabled: feature.enabled,\n capabilities: feature.capabilities ?? [],\n config\n };\n })\n };\n }\n\n async getRoute(uri: string, locale?: string): Promise<FlowpressRoute | null> {\n const data = await this.request<{\n sfRouteByUri: (Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }) | null;\n }>(\n `query FlowpressRoute($uri: String!, $locale: String) {\n sfRouteByUri(uri: $uri, locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { uri, locale: locale ?? null }\n );\n if (!data.sfRouteByUri) {\n return null;\n }\n return {\n ...data.sfRouteByUri,\n seo: normalizeGraphqlSeo(data.sfRouteByUri.seo)\n };\n }\n\n async getRoutes(locale?: string): Promise<FlowpressRoute[]> {\n const data = await this.request<{\n sfRoutes: Array<Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }>;\n }>(\n `query FlowpressRoutes($locale: String) {\n sfRoutes(locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { locale: locale ?? null }\n );\n return data.sfRoutes.map((route) => ({\n ...route,\n seo: normalizeGraphqlSeo(route.seo)\n }));\n }\n\n async getContent(\n loader: string,\n variables: Record<string, unknown>\n ): Promise<FlowpressContent | null> {\n const data = await this.request<{\n sfContentByLoader: (Omit<FlowpressContent, \"contentBlocks\"> & {\n contentBlocksJson?: string | null;\n projectFieldsJson?: string | null;\n }) | null;\n }>(\n `query FlowpressContent(\n $loader: String!,\n $databaseId: Int,\n $termId: Int,\n $uri: String,\n $locale: String\n ) {\n sfContentByLoader(\n loader: $loader,\n databaseId: $databaseId,\n termId: $termId,\n uri: $uri,\n locale: $locale\n ) {\n title excerpt content contentBlocksJson projectFieldsJson\n }\n }`,\n {\n loader,\n databaseId: variables.databaseId ?? null,\n termId: variables.termId ?? null,\n uri: variables.uri ?? null,\n locale: variables.locale ?? null\n }\n );\n const content = data.sfContentByLoader;\n if (!content) {\n return null;\n }\n const { contentBlocksJson, projectFieldsJson, ...rest } = content;\n return {\n ...rest,\n contentBlocks: parseJson(contentBlocksJson, []),\n projectFields: parseJson(projectFieldsJson, {})\n };\n }\n}\n\nfunction getOperationName(query: string): string {\n return query.match(\n /\\b(?:query|mutation|subscription)\\s+([_A-Za-z][_0-9A-Za-z]*)/\n )?.[1] || \"AnonymousOperation\";\n}\n\nfunction sanitizeEndpoint(endpoint: string): string {\n const url = new URL(endpoint);\n url.username = \"\";\n url.password = \"\";\n url.search = \"\";\n url.hash = \"\";\n return url.toString();\n}\n\ninterface GraphqlSeo {\n title?: string | null;\n description?: string | null;\n canonicalUrl?: string | null;\n robots?: string[] | null;\n headHtml?: string | null;\n jsonLd?: { raw?: string | null } | null;\n openGraph?: GraphqlSocial | null;\n twitterMeta?: GraphqlSocial | null;\n hreflang?: Array<{ locale: string; url: string }> | null;\n}\n\ninterface GraphqlSocial {\n title?: string | null;\n description?: string | null;\n image?: { url: string; altText?: string | null } | null;\n}\n\nfunction normalizeGraphqlSeo(seo?: GraphqlSeo | null) {\n if (!seo) return null;\n const social = (value?: GraphqlSocial | null) => value\n ? {\n title: value.title ?? null,\n description: value.description ?? null,\n image: value.image\n ? { url: value.image.url, alt: value.image.altText ?? null }\n : null\n }\n : null;\n\n return {\n title: seo.title ?? null,\n description: seo.description ?? null,\n canonicalUrl: seo.canonicalUrl ?? null,\n robots: seo.robots ?? null,\n headHtml: seo.headHtml ?? null,\n jsonLd: parseJson(seo.jsonLd?.raw, null),\n hreflang: seo.hreflang ?? null,\n openGraph: social(seo.openGraph),\n twitter: social(seo.twitterMeta)\n };\n}\n\nfunction parseJson<T>(value: string | null | undefined, fallback: T): T {\n if (!value) return fallback;\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA4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AAC,GAAG,CAAC,SAAS,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC;KACjC,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAI,KAAgC,EAAE,QAAW;IACjE,IAAI,CAAC,KAAK;QAAE,OAAO,QAAQ,CAAC;IAC5B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,QAAQ,CAAC;IAClB,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAI,KAAa,EAAE,KAAa;IACxD,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAM,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,qBAAqB,CAC7B,+BAA+B,KAAK,qBAAqB,EACzD,SAAS,EACT,SAAS,EACT,sBAAsB,EACtB,SAAS,EACT,KAAK,CACN,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type {\n FlowpressCapabilities,\n FlowpressCompositionV1,\n FlowpressContent,\n FlowpressRoute\n} from \"./types.js\";\n\nexport interface FlowpressGraphqlIssue {\n message?: string;\n extensions?: {\n debugMessage?: string;\n category?: string;\n [key: string]: unknown;\n };\n}\n\ninterface GraphqlResponse<T> {\n data?: T;\n errors?: FlowpressGraphqlIssue[];\n}\n\nexport interface FlowpressClientOptions {\n endpoint: string;\n timeoutMs?: number;\n headers?: Record<string, string>;\n debug?: boolean;\n}\n\nexport class FlowpressGraphqlError extends Error {\n constructor(\n message: string,\n readonly status?: number,\n readonly errors?: FlowpressGraphqlIssue[],\n readonly operationName?: string,\n readonly endpoint?: string,\n cause?: unknown\n ) {\n super(message, cause === undefined ? undefined : { cause });\n this.name = \"FlowpressGraphqlError\";\n }\n}\n\nexport class FlowpressClient {\n readonly endpoint: string;\n readonly timeoutMs: number;\n readonly headers: Record<string, string>;\n readonly debug: boolean;\n\n constructor(options: FlowpressClientOptions) {\n const endpoint = options.endpoint.trim();\n if (!endpoint) {\n throw new Error(\"FlowPress GraphQL endpoint is required.\");\n }\n\n new URL(endpoint);\n this.endpoint = endpoint;\n this.timeoutMs = options.timeoutMs ?? 15_000;\n this.headers = { ...options.headers };\n this.debug = options.debug ?? false;\n }\n\n async request<T>(\n query: string,\n variables: Record<string, unknown> = {}\n ): Promise<T> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeoutMs);\n const operationName = getOperationName(query);\n const safeEndpoint = sanitizeEndpoint(this.endpoint);\n\n try {\n let response: Response;\n try {\n response = await fetch(this.endpoint, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n ...this.headers\n },\n body: JSON.stringify({ query, variables }),\n signal: controller.signal\n });\n } catch (error) {\n const timedOut = controller.signal.aborted;\n const detail = error instanceof Error && error.message\n ? ` ${error.message}`\n : \"\";\n throw new FlowpressGraphqlError(\n timedOut\n ? `FlowPress GraphQL ${operationName} timed out after ${this.timeoutMs}ms at ${safeEndpoint}.`\n : `FlowPress GraphQL ${operationName} could not reach ${safeEndpoint}.${detail}`,\n undefined,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n const body = await response.text();\n let payload: GraphqlResponse<T>;\n try {\n payload = JSON.parse(body) as GraphqlResponse<T>;\n } catch (error) {\n const contentType = response.headers.get(\"content-type\") || \"unknown content type\";\n throw new FlowpressGraphqlError(\n `FlowPress GraphQL ${operationName} returned ${response.status} `\n + `with ${contentType}, not JSON, from ${safeEndpoint}.`,\n response.status,\n undefined,\n operationName,\n safeEndpoint,\n error\n );\n }\n\n if (!response.ok || payload.errors?.length || payload.data === undefined) {\n const errors: FlowpressGraphqlIssue[] | undefined = payload.errors?.map(\n (error) => {\n if (this.debug) {\n return error;\n }\n return error.message ? { message: error.message } : {};\n }\n );\n const messages = errors\n ?.flatMap((error) => [\n error.message,\n this.debug ? error.extensions?.debugMessage : undefined\n ])\n .filter((message): message is string => Boolean(message));\n throw new FlowpressGraphqlError(\n messages?.join(\"; \")\n || `FlowPress GraphQL ${operationName} failed with ${response.status} at ${safeEndpoint}.`,\n response.status,\n errors,\n operationName,\n safeEndpoint\n );\n }\n\n return payload.data;\n } finally {\n clearTimeout(timer);\n }\n }\n\n async getCapabilities(): Promise<FlowpressCapabilities> {\n const data = await this.request<{ styleflowCapabilities: FlowpressCapabilities }>(\n `query FlowpressCapabilities {\n styleflowCapabilities {\n schemaVersion\n wpGraphql\n acfPro\n wpGraphqlAcf\n rankMath\n wpml\n woocommerce\n contactForm7\n defaultLocale\n locales { code slug homeUrl }\n features { id version enabled capabilities configJson }\n }\n }`\n );\n return {\n ...data.styleflowCapabilities,\n features: (data.styleflowCapabilities.features ?? []).map((feature) => {\n const wire = feature as typeof feature & { configJson?: string | null };\n let config: Record<string, unknown> = {};\n if (wire.configJson) {\n try {\n const parsed = JSON.parse(wire.configJson);\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n config = parsed as Record<string, unknown>;\n }\n } catch {\n config = {};\n }\n }\n return {\n id: feature.id,\n version: feature.version ?? null,\n enabled: feature.enabled,\n capabilities: feature.capabilities ?? [],\n config\n };\n })\n };\n }\n\n async getRoute(uri: string, locale?: string): Promise<FlowpressRoute | null> {\n const data = await this.request<{\n sfRouteByUri: (Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }) | null;\n }>(\n `query FlowpressRoute($uri: String!, $locale: String) {\n sfRouteByUri(uri: $uri, locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { uri, locale: locale ?? null }\n );\n if (!data.sfRouteByUri) {\n return null;\n }\n return {\n ...data.sfRouteByUri,\n seo: normalizeGraphqlSeo(data.sfRouteByUri.seo)\n };\n }\n\n async getRoutes(locale?: string): Promise<FlowpressRoute[]> {\n const data = await this.request<{\n sfRoutes: Array<Omit<FlowpressRoute, \"seo\"> & {\n seo?: GraphqlSeo | null;\n }>;\n }>(\n `query FlowpressRoutes($locale: String) {\n sfRoutes(locale: $locale) {\n uri status queryType locale isFrontPage isPostsPage frontPageMode\n postType taxonomy slug term databaseId termId authorNicename authorId\n pageTemplate mimeType postFormat templateCandidates\n content { loader databaseId termId }\n seo {\n title description canonicalUrl robots headHtml\n hreflang { locale url }\n jsonLd { raw }\n openGraph { title description image { url altText } }\n twitterMeta { title description image { url altText } }\n }\n }\n }`,\n { locale: locale ?? null }\n );\n return data.sfRoutes.map((route) => ({\n ...route,\n seo: normalizeGraphqlSeo(route.seo)\n }));\n }\n\n async getContent(\n loader: string,\n variables: Record<string, unknown>\n ): Promise<FlowpressContent | null> {\n const data = await this.request<{\n sfContentByLoader: (Omit<FlowpressContent, \"contentBlocks\"> & {\n contentBlocksJson?: string | null;\n projectFieldsJson?: string | null;\n }) | null;\n }>(\n `query FlowpressContent(\n $loader: String!,\n $databaseId: Int,\n $termId: Int,\n $uri: String,\n $locale: String\n ) {\n sfContentByLoader(\n loader: $loader,\n databaseId: $databaseId,\n termId: $termId,\n uri: $uri,\n locale: $locale\n ) {\n title excerpt content contentBlocksJson projectFieldsJson\n }\n }`,\n {\n loader,\n databaseId: variables.databaseId ?? null,\n termId: variables.termId ?? null,\n uri: variables.uri ?? null,\n locale: variables.locale ?? null\n }\n );\n const content = data.sfContentByLoader;\n if (!content) {\n return null;\n }\n const { contentBlocksJson, projectFieldsJson, ...rest } = content;\n return {\n ...rest,\n contentBlocks: parseJson(contentBlocksJson, []),\n projectFields: parseJson(projectFieldsJson, {})\n };\n }\n\n async getComposition(uri: string, locale?: string): Promise<FlowpressCompositionV1 | null> {\n const data = await this.request<{\n sfCompositionByUri: null | {\n version: \"1\";\n sourceDigest: string;\n locale?: string | null;\n templateJson: string;\n blocksJson: string;\n stylesheetsJson: string;\n blockTypesJson: string;\n diagnosticsJson: string;\n routeJson: string;\n contentJson?: string | null;\n };\n }>(\n `query FlowpressComposition($uri: String!, $locale: String) {\n sfCompositionByUri(uri: $uri, locale: $locale) {\n version sourceDigest locale templateJson blocksJson stylesheetsJson blockTypesJson\n diagnosticsJson routeJson contentJson\n }\n }`,\n { uri, locale: locale ?? null }\n );\n const wire = data.sfCompositionByUri;\n if (!wire) return null;\n return {\n version: wire.version,\n sourceDigest: wire.sourceDigest,\n locale: wire.locale ?? null,\n template: parseRequiredJson(wire.templateJson, \"templateJson\"),\n blocks: parseRequiredJson(wire.blocksJson, \"blocksJson\"),\n stylesheets: parseRequiredJson(wire.stylesheetsJson, \"stylesheetsJson\"),\n blockTypes: parseRequiredJson(wire.blockTypesJson, \"blockTypesJson\"),\n diagnostics: parseRequiredJson(wire.diagnosticsJson, \"diagnosticsJson\"),\n route: parseRequiredJson(wire.routeJson, \"routeJson\"),\n content: parseJson(wire.contentJson, null)\n };\n }\n}\n\nfunction getOperationName(query: string): string {\n return query.match(\n /\\b(?:query|mutation|subscription)\\s+([_A-Za-z][_0-9A-Za-z]*)/\n )?.[1] || \"AnonymousOperation\";\n}\n\nfunction sanitizeEndpoint(endpoint: string): string {\n const url = new URL(endpoint);\n url.username = \"\";\n url.password = \"\";\n url.search = \"\";\n url.hash = \"\";\n return url.toString();\n}\n\ninterface GraphqlSeo {\n title?: string | null;\n description?: string | null;\n canonicalUrl?: string | null;\n robots?: string[] | null;\n headHtml?: string | null;\n jsonLd?: { raw?: string | null } | null;\n openGraph?: GraphqlSocial | null;\n twitterMeta?: GraphqlSocial | null;\n hreflang?: Array<{ locale: string; url: string }> | null;\n}\n\ninterface GraphqlSocial {\n title?: string | null;\n description?: string | null;\n image?: { url: string; altText?: string | null } | null;\n}\n\nfunction normalizeGraphqlSeo(seo?: GraphqlSeo | null) {\n if (!seo) return null;\n const social = (value?: GraphqlSocial | null) => value\n ? {\n title: value.title ?? null,\n description: value.description ?? null,\n image: value.image\n ? { url: value.image.url, alt: value.image.altText ?? null }\n : null\n }\n : null;\n\n return {\n title: seo.title ?? null,\n description: seo.description ?? null,\n canonicalUrl: seo.canonicalUrl ?? null,\n robots: seo.robots ?? null,\n headHtml: seo.headHtml ?? null,\n jsonLd: parseJson(seo.jsonLd?.raw, null),\n hreflang: seo.hreflang ?? null,\n openGraph: social(seo.openGraph),\n twitter: social(seo.twitterMeta)\n };\n}\n\nfunction parseJson<T>(value: string | null | undefined, fallback: T): T {\n if (!value) return fallback;\n try {\n return JSON.parse(value) as T;\n } catch {\n return fallback;\n }\n}\n\nfunction parseRequiredJson<T>(value: string, field: string): T {\n try {\n return JSON.parse(value) as T;\n } catch (error) {\n throw new FlowpressGraphqlError(\n `FlowPress composition field ${field} is not valid JSON.`,\n undefined,\n undefined,\n \"FlowpressComposition\",\n undefined,\n error\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FlowpressBlockAdapters } from "./block-renderers.js";
|
|
2
|
+
import type { FlowpressBlockAuthoringAttributes, FlowpressBlockHtmlProps, FlowpressBlockTypeDescriptor, FlowpressCompositionV1 } from "./types.js";
|
|
3
|
+
export declare function flowpressBlockHtmlProps(attributes: FlowpressBlockAuthoringAttributes): FlowpressBlockHtmlProps;
|
|
4
|
+
/** Structural logo visibility rules emitted once per composition. */
|
|
5
|
+
export declare function flowpressCompositionLogoStyles(composition: FlowpressCompositionV1): string;
|
|
6
|
+
export type FlowpressAdapterCompatibilityCode = "missing-adapter" | "draft-adapter" | "missing-descriptor" | "stale-adapter";
|
|
7
|
+
export interface FlowpressAdapterCompatibilityIssue {
|
|
8
|
+
code: FlowpressAdapterCompatibilityCode;
|
|
9
|
+
message: string;
|
|
10
|
+
command: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function flowpressBlockTypeDescriptors(composition: FlowpressCompositionV1): ReadonlyMap<string, FlowpressBlockTypeDescriptor>;
|
|
13
|
+
export declare function flowpressAdapterCompatibilityIssue(blockName: string, descriptors: ReadonlyMap<string, FlowpressBlockTypeDescriptor>, adapters: FlowpressBlockAdapters): FlowpressAdapterCompatibilityIssue | null;
|
|
14
|
+
//# sourceMappingURL=composition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composition.d.ts","sourceRoot":"","sources":["../src/composition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,KAAK,EAEV,iCAAiC,EACjC,uBAAuB,EACvB,4BAA4B,EAC5B,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,iCAAiC,GAC5C,uBAAuB,CASzB;AAkBD,qEAAqE;AACrE,wBAAgB,8BAA8B,CAC5C,WAAW,EAAE,sBAAsB,GAClC,MAAM,CAsBR;AAED,MAAM,MAAM,iCAAiC,GACzC,iBAAiB,GACjB,eAAe,GACf,oBAAoB,GACpB,eAAe,CAAC;AAEpB,MAAM,WAAW,kCAAkC;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,sBAAsB,GAClC,WAAW,CAAC,MAAM,EAAE,4BAA4B,CAAC,CAKnD;AAED,wBAAgB,kCAAkC,CAChD,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,4BAA4B,CAAC,EAC9D,QAAQ,EAAE,sBAAsB,GAC/B,kCAAkC,GAAG,IAAI,CAoC3C"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export function flowpressBlockHtmlProps(attributes) {
|
|
2
|
+
const id = typeof attributes.anchor === "string" ? attributes.anchor.trim() : "";
|
|
3
|
+
const className = typeof attributes.className === "string"
|
|
4
|
+
? attributes.className.trim().replace(/\s+/g, " ")
|
|
5
|
+
: "";
|
|
6
|
+
return {
|
|
7
|
+
...(id ? { id } : {}),
|
|
8
|
+
...(className ? { class: className } : {})
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function findLogoData(blocks) {
|
|
12
|
+
for (const block of blocks) {
|
|
13
|
+
if (block.name === "core/site-logo" && block.resolvedData) {
|
|
14
|
+
return block.resolvedData;
|
|
15
|
+
}
|
|
16
|
+
const nested = findLogoData(block.innerBlocks ?? []);
|
|
17
|
+
if (nested)
|
|
18
|
+
return nested;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/** Structural logo visibility rules emitted once per composition. */
|
|
23
|
+
export function flowpressCompositionLogoStyles(composition) {
|
|
24
|
+
const data = findLogoData(composition.blocks);
|
|
25
|
+
if (!data)
|
|
26
|
+
return "";
|
|
27
|
+
const fallback = data.fallback === "negative" ? "negative" : "positive";
|
|
28
|
+
const other = fallback === "positive" ? "negative" : "positive";
|
|
29
|
+
const lines = [
|
|
30
|
+
`.flowpress-site-logo{--flowpress-logo-${fallback}-display:block;--flowpress-logo-${other}-display:none}`,
|
|
31
|
+
".flowpress-site-logo__image--positive{display:var(--flowpress-logo-positive-display,none)}",
|
|
32
|
+
".flowpress-site-logo__image--negative{display:var(--flowpress-logo-negative-display,none)}"
|
|
33
|
+
];
|
|
34
|
+
for (const [theme, variant] of Object.entries(data.themeMap ?? {})) {
|
|
35
|
+
if (!/^[a-z0-9_-]+$/.test(theme))
|
|
36
|
+
continue;
|
|
37
|
+
const hidden = variant === "positive" ? "negative" : "positive";
|
|
38
|
+
lines.push(`[data-styleflow-theme="${theme}"]{--flowpress-logo-${variant}-display:block;--flowpress-logo-${hidden}-display:none}`);
|
|
39
|
+
}
|
|
40
|
+
lines.push('.flowpress-site-logo[data-flowpress-logo-override="positive"]{--flowpress-logo-positive-display:block;--flowpress-logo-negative-display:none}', '.flowpress-site-logo[data-flowpress-logo-override="negative"]{--flowpress-logo-positive-display:none;--flowpress-logo-negative-display:block}');
|
|
41
|
+
return lines.join("\n");
|
|
42
|
+
}
|
|
43
|
+
export function flowpressBlockTypeDescriptors(composition) {
|
|
44
|
+
return new Map(composition.blockTypes.map((descriptor) => [
|
|
45
|
+
descriptor.blockName,
|
|
46
|
+
descriptor
|
|
47
|
+
]));
|
|
48
|
+
}
|
|
49
|
+
export function flowpressAdapterCompatibilityIssue(blockName, descriptors, adapters) {
|
|
50
|
+
const adapter = adapters[blockName];
|
|
51
|
+
if (!adapter) {
|
|
52
|
+
const command = `pnpm cms:block-adapter ${blockName}`;
|
|
53
|
+
return {
|
|
54
|
+
code: "missing-adapter",
|
|
55
|
+
message: `Missing FlowPress block adapter for "${blockName}". Run ${command}.`,
|
|
56
|
+
command
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (adapter.status !== "ready") {
|
|
60
|
+
const command = `pnpm cms:block-adapter:approve ${blockName}`;
|
|
61
|
+
return {
|
|
62
|
+
code: "draft-adapter",
|
|
63
|
+
message: `FlowPress block adapter for "${blockName}" is draft. Run ${command}.`,
|
|
64
|
+
command
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const descriptor = descriptors.get(blockName);
|
|
68
|
+
if (!descriptor) {
|
|
69
|
+
const command = "pnpm cms:block-adapters:check";
|
|
70
|
+
return {
|
|
71
|
+
code: "missing-descriptor",
|
|
72
|
+
message: `WordPress did not provide a block type descriptor for "${blockName}". Run ${command}.`,
|
|
73
|
+
command
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (descriptor.fingerprint !== adapter.fingerprint) {
|
|
77
|
+
const command = `pnpm cms:block-adapter ${blockName} --refresh-schema`;
|
|
78
|
+
return {
|
|
79
|
+
code: "stale-adapter",
|
|
80
|
+
message: `FlowPress block adapter for "${blockName}" has a stale schema fingerprint. Run ${command}.`,
|
|
81
|
+
command
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|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C;IACpC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,0BAA0B,SAAS,EAAE,CAAC;QACtD,OAAO;YACL,IAAI,EAAE,iBAAiB;YACvB,OAAO,EAAE,wCAAwC,SAAS,UAAU,OAAO,GAAG;YAC9E,OAAO;SACR,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,kCAAkC,SAAS,EAAE,CAAC;QAC9D,OAAO;YACL,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,gCAAgC,SAAS,mBAAmB,OAAO,GAAG;YAC/E,OAAO;SACR,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,+BAA+B,CAAC;QAChD,OAAO;YACL,IAAI,EAAE,oBAAoB;YAC1B,OAAO,EAAE,0DAA0D,SAAS,UAAU,OAAO,GAAG;YAChG,OAAO;SACR,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,WAAW,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC;QACnD,MAAM,OAAO,GAAG,0BAA0B,SAAS,mBAAmB,CAAC;QACvE,OAAO;YACL,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,gCAAgC,SAAS,yCAAyC,OAAO,GAAG;YACrG,OAAO;SACR,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { FlowpressBlockAdapters } from \"./block-renderers.js\";\nimport type {\n FlowpressBlock,\n FlowpressBlockAuthoringAttributes,\n FlowpressBlockHtmlProps,\n FlowpressBlockTypeDescriptor,\n FlowpressCompositionV1\n} from \"./types.js\";\n\nexport function flowpressBlockHtmlProps(\n attributes: FlowpressBlockAuthoringAttributes\n): FlowpressBlockHtmlProps {\n const id = typeof attributes.anchor === \"string\" ? attributes.anchor.trim() : \"\";\n const className = typeof attributes.className === \"string\"\n ? attributes.className.trim().replace(/\\s+/g, \" \")\n : \"\";\n return {\n ...(id ? { id } : {}),\n ...(className ? { class: className } : {})\n };\n}\n\ntype LogoResolvedData = {\n themeMap?: Record<string, \"positive\" | \"negative\">;\n fallback?: \"positive\" | \"negative\";\n};\n\nfunction findLogoData(blocks: FlowpressBlock[]): LogoResolvedData | null {\n for (const block of blocks) {\n if (block.name === \"core/site-logo\" && block.resolvedData) {\n return block.resolvedData as LogoResolvedData;\n }\n const nested = findLogoData(block.innerBlocks ?? []);\n if (nested) return nested;\n }\n return null;\n}\n\n/** Structural logo visibility rules emitted once per composition. */\nexport function flowpressCompositionLogoStyles(\n composition: FlowpressCompositionV1\n): string {\n const data = findLogoData(composition.blocks);\n if (!data) return \"\";\n const fallback = data.fallback === \"negative\" ? \"negative\" : \"positive\";\n const other = fallback === \"positive\" ? \"negative\" : \"positive\";\n const lines = [\n `.flowpress-site-logo{--flowpress-logo-${fallback}-display:block;--flowpress-logo-${other}-display:none}`,\n \".flowpress-site-logo__image--positive{display:var(--flowpress-logo-positive-display,none)}\",\n \".flowpress-site-logo__image--negative{display:var(--flowpress-logo-negative-display,none)}\"\n ];\n for (const [theme, variant] of Object.entries(data.themeMap ?? {})) {\n if (!/^[a-z0-9_-]+$/.test(theme)) continue;\n const hidden = variant === \"positive\" ? \"negative\" : \"positive\";\n lines.push(\n `[data-styleflow-theme=\"${theme}\"]{--flowpress-logo-${variant}-display:block;--flowpress-logo-${hidden}-display:none}`\n );\n }\n lines.push(\n '.flowpress-site-logo[data-flowpress-logo-override=\"positive\"]{--flowpress-logo-positive-display:block;--flowpress-logo-negative-display:none}',\n '.flowpress-site-logo[data-flowpress-logo-override=\"negative\"]{--flowpress-logo-positive-display:none;--flowpress-logo-negative-display:block}'\n );\n return lines.join(\"\\n\");\n}\n\nexport type FlowpressAdapterCompatibilityCode =\n | \"missing-adapter\"\n | \"draft-adapter\"\n | \"missing-descriptor\"\n | \"stale-adapter\";\n\nexport interface FlowpressAdapterCompatibilityIssue {\n code: FlowpressAdapterCompatibilityCode;\n message: string;\n command: string;\n}\n\nexport function flowpressBlockTypeDescriptors(\n composition: FlowpressCompositionV1\n): ReadonlyMap<string, FlowpressBlockTypeDescriptor> {\n return new Map(composition.blockTypes.map((descriptor) => [\n descriptor.blockName,\n descriptor\n ]));\n}\n\nexport function flowpressAdapterCompatibilityIssue(\n blockName: string,\n descriptors: ReadonlyMap<string, FlowpressBlockTypeDescriptor>,\n adapters: FlowpressBlockAdapters\n): FlowpressAdapterCompatibilityIssue | null {\n const adapter = adapters[blockName];\n if (!adapter) {\n const command = `pnpm cms:block-adapter ${blockName}`;\n return {\n code: \"missing-adapter\",\n message: `Missing FlowPress block adapter for \"${blockName}\". Run ${command}.`,\n command\n };\n }\n if (adapter.status !== \"ready\") {\n const command = `pnpm cms:block-adapter:approve ${blockName}`;\n return {\n code: \"draft-adapter\",\n message: `FlowPress block adapter for \"${blockName}\" is draft. Run ${command}.`,\n command\n };\n }\n const descriptor = descriptors.get(blockName);\n if (!descriptor) {\n const command = \"pnpm cms:block-adapters:check\";\n return {\n code: \"missing-descriptor\",\n message: `WordPress did not provide a block type descriptor for \"${blockName}\". Run ${command}.`,\n command\n };\n }\n if (descriptor.fingerprint !== adapter.fingerprint) {\n const command = `pnpm cms:block-adapter ${blockName} --refresh-schema`;\n return {\n code: \"stale-adapter\",\n message: `FlowPress block adapter for \"${blockName}\" has a stale schema fingerprint. Run ${command}.`,\n command\n };\n }\n return null;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export * from "./client.js";
|
|
2
2
|
export * from "./carousel.js";
|
|
3
3
|
export * from "./block-renderers.js";
|
|
4
|
+
export * from "./composition.js";
|
|
4
5
|
export * from "./env.js";
|
|
5
6
|
export * from "./links.js";
|
|
6
7
|
export * from "./number-spinner.js";
|
|
7
8
|
export * from "./styleflow.js";
|
|
8
9
|
export * from "./style-classes.js";
|
|
9
10
|
export * from "./template-hierarchy.js";
|
|
11
|
+
export * from "./theme-runtime.js";
|
|
10
12
|
export * from "./types.js";
|
|
11
13
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export * from "./client.js";
|
|
2
2
|
export * from "./carousel.js";
|
|
3
3
|
export * from "./block-renderers.js";
|
|
4
|
+
export * from "./composition.js";
|
|
4
5
|
export * from "./env.js";
|
|
5
6
|
export * from "./links.js";
|
|
6
7
|
export * from "./number-spinner.js";
|
|
7
8
|
export * from "./styleflow.js";
|
|
8
9
|
export * from "./style-classes.js";
|
|
9
10
|
export * from "./template-hierarchy.js";
|
|
11
|
+
export * from "./theme-runtime.js";
|
|
10
12
|
export * from "./types.js";
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./client.js\";\nexport * from \"./carousel.js\";\nexport * from \"./block-renderers.js\";\nexport * from \"./env.js\";\nexport * from \"./links.js\";\nexport * from \"./number-spinner.js\";\nexport * from \"./styleflow.js\";\nexport * from \"./style-classes.js\";\nexport * from \"./template-hierarchy.js\";\nexport * from \"./types.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC","sourcesContent":["export * from \"./client.js\";\nexport * from \"./carousel.js\";\nexport * from \"./block-renderers.js\";\nexport * from \"./composition.js\";\nexport * from \"./env.js\";\nexport * from \"./links.js\";\nexport * from \"./number-spinner.js\";\nexport * from \"./styleflow.js\";\nexport * from \"./style-classes.js\";\nexport * from \"./template-hierarchy.js\";\nexport * from \"./theme-runtime.js\";\nexport * from \"./types.js\";\n"]}
|
package/dist/styleflow.d.ts
CHANGED
|
@@ -54,6 +54,8 @@ export interface ResolveDynamicStyleflowOptions {
|
|
|
54
54
|
strict?: boolean;
|
|
55
55
|
onDiagnostic?: (diagnostic: StyleflowDiagnostic) => void;
|
|
56
56
|
}
|
|
57
|
+
/** Select and validate the semantic attributes authored on a Gutenberg block. */
|
|
58
|
+
export declare function resolveFlowpressBlockStyleflowProps(attributes: Record<string, unknown>, contract?: StyleflowContract, defaults?: DynamicStyleflowProps, options?: ResolveDynamicStyleflowOptions): DynamicStyleflowProps;
|
|
57
59
|
/** Validate CMS-authored props against the grouped vNext project contract. */
|
|
58
60
|
export declare function resolveDynamicStyleflowProps(input: DynamicStyleflowProps, defaults: DynamicStyleflowProps, contract: StyleflowContract, options?: ResolveDynamicStyleflowOptions): DynamicStyleflowProps;
|
|
59
61
|
//# sourceMappingURL=styleflow.d.ts.map
|
package/dist/styleflow.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styleflow.d.ts","sourceRoot":"","sources":["../src/styleflow.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACnH,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,KAAK,CAAC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC;IACvG,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CA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vD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AACD,MAAM,WAAW,8BAA8B;IAC7C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAC1D;AAuBD,iFAAiF;AACjF,wBAAgB,mCAAmC,CACjD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,QAAQ,CAAC,EAAE,iBAAiB,EAC5B,QAAQ,GAAE,qBAA0B,EACpC,OAAO,GAAE,8BAAmC,GAC3C,qBAAqB,CAevB;AAED,8EAA8E;AAC9E,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,qBAAqB,EAC5B,QAAQ,EAAE,qBAAqB,EAC/B,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,GAAE,8BAAmC,GAC3C,qBAAqB,CAyBvB"}
|
package/dist/styleflow.js
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
const INHERITED_PROPS = new Set(["tone", "intensity", "foreground"]);
|
|
1
|
+
const INHERITED_PROPS = new Set(["theme", "tone", "intensity", "foreground"]);
|
|
2
|
+
const BLOCK_STYLEFLOW_PROPS = [
|
|
3
|
+
"theme",
|
|
4
|
+
"tone",
|
|
5
|
+
"intensity",
|
|
6
|
+
"surface",
|
|
7
|
+
"layoutRole",
|
|
8
|
+
"density",
|
|
9
|
+
"ty",
|
|
10
|
+
"v",
|
|
11
|
+
"w",
|
|
12
|
+
"foreground",
|
|
13
|
+
"interactivePriority",
|
|
14
|
+
"noBackground",
|
|
15
|
+
"noBorder",
|
|
16
|
+
"noPadding",
|
|
17
|
+
"noGap",
|
|
18
|
+
"noRadius",
|
|
19
|
+
"noForeground"
|
|
20
|
+
];
|
|
21
|
+
/** Select and validate the semantic attributes authored on a Gutenberg block. */
|
|
22
|
+
export function resolveFlowpressBlockStyleflowProps(attributes, contract, defaults = {}, options = {}) {
|
|
23
|
+
const input = Object.fromEntries(BLOCK_STYLEFLOW_PROPS
|
|
24
|
+
.filter((key) => attributes[key] !== undefined)
|
|
25
|
+
.map((key) => [key, attributes[key]]));
|
|
26
|
+
if (contract) {
|
|
27
|
+
return resolveDynamicStyleflowProps(input, defaults, contract, options);
|
|
28
|
+
}
|
|
29
|
+
const resolved = { ...defaults, ...input };
|
|
30
|
+
for (const key of INHERITED_PROPS) {
|
|
31
|
+
if (input[key] === "inherit")
|
|
32
|
+
delete resolved[key];
|
|
33
|
+
}
|
|
34
|
+
return resolved;
|
|
35
|
+
}
|
|
2
36
|
/** Validate CMS-authored props against the grouped vNext project contract. */
|
|
3
37
|
export function resolveDynamicStyleflowProps(input, defaults, contract, options = {}) {
|
|
4
38
|
const resolved = { ...defaults };
|
package/dist/styleflow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styleflow.js","sourceRoot":"","sources":["../src/styleflow.ts"],"names":[],"mappings":"AA4BA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAErE,8EAA8E;AAC9E,MAAM,UAAU,4BAA4B,CAC1C,KAA4B,EAC5B,QAA+B,EAC/B,QAA2B,EAC3B,UAA0C,EAAE;IAE5C,MAAM,QAAQ,GAA0B,EAAE,GAAG,QAAQ,EAAE,CAAC;IACxD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;YAAE,SAAS;QACpE,IAAI,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,SAAS,EA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,UAAU,CAAC,GAAG,CAAC,CAAC;IAC9G,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,QAAQ,CAAC,YAAY,CAAC;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC;AACD,SAAS,OAAO,CAAC,GAAW,EAAE,KAAc,EAAE,QAAiB,EAAE,OAAuC;IACtG,MAAM,UAAU,GAAwB;QACtC,IAAI,EAAE,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,uBAAuB;QAC/E,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjE,QAAQ,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI;QACjC,OAAO,EAAE,QAAQ,KAAK,SAAS;YAC7B,CAAC,CAAC,kBAAkB,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,0CAA0C;YAC1F,CAAC,CAAC,kBAAkB,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG;KAC/F,CAAC;IACF,CAAC,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACjG,IAAI,OAAO,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["export interface StyleflowContractAxes {\n color: { tones: string[]; intensitiesByTone: Record<string, string[]>; surfaces: string[]; foregrounds: string[] };\n layout: { roles: string[]; densities: string[]; breakpoints: Array<{ id: string; minWidth: number }> };\n typography: { types: string[]; variantsByType: Record<string, string[]>; weights: string[] };\n interaction: { priorities: string[]; states: string[] };\n}\nexport interface StyleflowContract {\n defaultTheme?: string;\n semantic: {\n themes: string[];\n axes: StyleflowContractAxes;\n agentPolicy: { defaults: { layoutRole: string; density: string; typography: { ty: string; v: string; w: string } } };\n };\n}\nexport type DynamicStyleflowProps = Record<string, unknown>;\nexport interface StyleflowDiagnostic {\n code: \"FP_STYLEFLOW_INVALID\" | \"FP_STYLEFLOW_FALLBACK\";\n prop: string;\n value: unknown;\n fallback?: unknown;\n blocking: boolean;\n message: string;\n}\nexport interface ResolveDynamicStyleflowOptions {\n strict?: boolean;\n onDiagnostic?: (diagnostic: StyleflowDiagnostic) => void;\n}\n\nconst INHERITED_PROPS = new Set([\"tone\", \"intensity\", \"foreground\"]);\n\n/** Validate CMS-authored props against the grouped vNext project contract. */\nexport function resolveDynamicStyleflowProps(\n input: DynamicStyleflowProps,\n defaults: DynamicStyleflowProps,\n contract: StyleflowContract,\n options: ResolveDynamicStyleflowOptions = {}\n): DynamicStyleflowProps {\n const resolved: DynamicStyleflowProps = { ...defaults };\n for (const [key, value] of Object.entries(input)) {\n if (value === undefined || value === null || value === \"\") continue;\n if (INHERITED_PROPS.has(key) && value === \"inherit\") { delete resolved[key]; continue; }\n if (key === \"interactionState\") {\n invalid(key, value, undefined, options); delete resolved[key]; continue;\n }\n const allowed = allowedValues(key, input, defaults, contract);\n if (!allowed) { resolved[key] = value; continue; }\n if (typeof value === \"string\" && allowed.includes(value)) { resolved[key] = value; continue; }\n const fallback = explicitFallback(key, defaults, contract);\n invalid(key, value, fallback, options);\n if (fallback === undefined) delete resolved[key]; else resolved[key] = fallback;\n }\n // Validate dependent defaults too: a default is not permission to emit a\n // coordinate absent from the current project contract.\n for (const key of [\"theme\", \"tone\", \"intensity\", \"surface\", \"foreground\", \"layoutRole\", \"density\", \"ty\", \"v\", \"w\", \"interactivePriority\"]) {\n if (resolved[key] === undefined) continue;\n const allowed = allowedValues(key, resolved, defaults, contract);\n if (allowed && !allowed.includes(String(resolved[key]))) {\n invalid(key, resolved[key], undefined, options); delete resolved[key];\n }\n }\n return resolved;\n}\n\nfunction allowedValues(\n key: string, input: DynamicStyleflowProps, defaults: DynamicStyleflowProps,\n contract: StyleflowContract\n): string[] | undefined {\n const axes = contract.semantic.axes;\n if (key === \"theme\") return contract.semantic.themes;\n if (key === \"tone\") return axes.color.tones;\n if (key === \"intensity\") {\n const tone = String(input.tone ?? defaults.tone ?? \"\");\n return tone ? axes.color.intensitiesByTone[tone] ?? [] : [...new Set(Object.values(axes.color.intensitiesByTone).flat())];\n }\n if (key === \"surface\") return axes.color.surfaces;\n if (key === \"foreground\") return axes.color.foregrounds;\n if (key === \"layoutRole\") return axes.layout.roles;\n if (key === \"density\") return axes.layout.densities;\n if (key === \"ty\") return axes.typography.types;\n if (key === \"v\") {\n const ty = String(input.ty ?? defaults.ty ?? contract.semantic.agentPolicy.defaults.typography.ty);\n return axes.typography.variantsByType[ty] ?? [];\n }\n if (key === \"w\") return axes.typography.weights;\n if (key === \"interactivePriority\") return axes.interaction.priorities;\n return undefined;\n}\n\nfunction explicitFallback(key: string, defaults: DynamicStyleflowProps, contract: StyleflowContract): unknown {\n if (defaults[key] !== undefined) return defaults[key];\n if (key === \"layoutRole\") return contract.semantic.agentPolicy.defaults.layoutRole;\n if (key === \"density\") return contract.semantic.agentPolicy.defaults.density;\n if (key === \"ty\" || key === \"v\" || key === \"w\") return contract.semantic.agentPolicy.defaults.typography[key];\n if (key === \"theme\") return contract.defaultTheme;\n return undefined;\n}\nfunction invalid(key: string, value: unknown, fallback: unknown, options: ResolveDynamicStyleflowOptions): void {\n const diagnostic: StyleflowDiagnostic = {\n code: fallback === undefined ? \"FP_STYLEFLOW_INVALID\" : \"FP_STYLEFLOW_FALLBACK\",\n prop: key, value, ...(fallback !== undefined ? { fallback } : {}),\n blocking: options.strict === true,\n message: fallback === undefined\n ? `Styleflow prop ${key}=${JSON.stringify(value)} is not in the grouped project contract.`\n : `Styleflow prop ${key}=${JSON.stringify(value)} fell back to ${JSON.stringify(fallback)}.`\n };\n (options.onDiagnostic ?? ((item) => console.warn(`[${item.code}] ${item.message}`)))(diagnostic);\n if (options.strict) throw new Error(`${diagnostic.code}: ${diagnostic.message}`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"styleflow.js","sourceRoot":"","sources":["../src/styleflow.ts"],"names":[],"mappings":"AA4BA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAC9E,MAAM,qBAAqB,GAAG;IAC5B,OAAO;IACP,MAAM;IACN,WAAW;IACX,SAAS;IACT,YAAY;IACZ,SAAS;IACT,IAAI;IACJ,GAAG;IACH,GAAG;IACH,YAAY;IACZ,qBAAqB;IACrB,cAAc;IACd,UAAU;IACV,WAAW;IACX,OAAO;IACP,UAAU;IACV,cAAc;CACN,CAAC;AAEX,iFAAiF;AACjF,MAAM,UAAU,mCAAmC,CACjD,UAAmC,EACnC,QAA4B,EAC5B,WAAkC,EAAE,EACpC,UAA0C,EAAE;IAE5C,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,qBAAqB;SAClB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC;SAC9C,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CACxC,CAAC;IACF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,4BAA4B,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;IAED,MAAM,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE,CAA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GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG;KAC/F,CAAC;IACF,CAAC,OAAO,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;IACjG,IAAI,OAAO,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,KAAK,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["export interface StyleflowContractAxes {\n color: { tones: string[]; intensitiesByTone: Record<string, string[]>; surfaces: string[]; foregrounds: string[] };\n layout: { roles: string[]; densities: string[]; breakpoints: Array<{ id: string; minWidth: number }> };\n typography: { types: string[]; variantsByType: Record<string, string[]>; weights: string[] };\n interaction: { priorities: string[]; states: string[] };\n}\nexport interface StyleflowContract {\n defaultTheme?: string;\n semantic: {\n themes: string[];\n axes: StyleflowContractAxes;\n agentPolicy: { defaults: { layoutRole: string; density: string; typography: { ty: string; v: string; w: string } } };\n };\n}\nexport type DynamicStyleflowProps = Record<string, unknown>;\nexport interface StyleflowDiagnostic {\n code: \"FP_STYLEFLOW_INVALID\" | \"FP_STYLEFLOW_FALLBACK\";\n prop: string;\n value: unknown;\n fallback?: unknown;\n blocking: boolean;\n message: string;\n}\nexport interface ResolveDynamicStyleflowOptions {\n strict?: boolean;\n onDiagnostic?: (diagnostic: StyleflowDiagnostic) => void;\n}\n\nconst INHERITED_PROPS = new Set([\"theme\", \"tone\", \"intensity\", \"foreground\"]);\nconst BLOCK_STYLEFLOW_PROPS = [\n \"theme\",\n \"tone\",\n \"intensity\",\n \"surface\",\n \"layoutRole\",\n \"density\",\n \"ty\",\n \"v\",\n \"w\",\n \"foreground\",\n \"interactivePriority\",\n \"noBackground\",\n \"noBorder\",\n \"noPadding\",\n \"noGap\",\n \"noRadius\",\n \"noForeground\"\n] as const;\n\n/** Select and validate the semantic attributes authored on a Gutenberg block. */\nexport function resolveFlowpressBlockStyleflowProps(\n attributes: Record<string, unknown>,\n contract?: StyleflowContract,\n defaults: DynamicStyleflowProps = {},\n options: ResolveDynamicStyleflowOptions = {}\n): DynamicStyleflowProps {\n const input = Object.fromEntries(\n BLOCK_STYLEFLOW_PROPS\n .filter((key) => attributes[key] !== undefined)\n .map((key) => [key, attributes[key]])\n );\n if (contract) {\n return resolveDynamicStyleflowProps(input, defaults, contract, options);\n }\n\n const resolved = { ...defaults, ...input };\n for (const key of INHERITED_PROPS) {\n if (input[key] === \"inherit\") delete resolved[key];\n }\n return resolved;\n}\n\n/** Validate CMS-authored props against the grouped vNext project contract. */\nexport function resolveDynamicStyleflowProps(\n input: DynamicStyleflowProps,\n defaults: DynamicStyleflowProps,\n contract: StyleflowContract,\n options: ResolveDynamicStyleflowOptions = {}\n): DynamicStyleflowProps {\n const resolved: DynamicStyleflowProps = { ...defaults };\n for (const [key, value] of Object.entries(input)) {\n if (value === undefined || value === null || value === \"\") continue;\n if (INHERITED_PROPS.has(key) && value === \"inherit\") { delete resolved[key]; continue; }\n if (key === \"interactionState\") {\n invalid(key, value, undefined, options); delete resolved[key]; continue;\n }\n const allowed = allowedValues(key, input, defaults, contract);\n if (!allowed) { resolved[key] = value; continue; }\n if (typeof value === \"string\" && allowed.includes(value)) { resolved[key] = value; continue; }\n const fallback = explicitFallback(key, defaults, contract);\n invalid(key, value, fallback, options);\n if (fallback === undefined) delete resolved[key]; else resolved[key] = fallback;\n }\n // Validate dependent defaults too: a default is not permission to emit a\n // coordinate absent from the current project contract.\n for (const key of [\"theme\", \"tone\", \"intensity\", \"surface\", \"foreground\", \"layoutRole\", \"density\", \"ty\", \"v\", \"w\", \"interactivePriority\"]) {\n if (resolved[key] === undefined) continue;\n const allowed = allowedValues(key, resolved, defaults, contract);\n if (allowed && !allowed.includes(String(resolved[key]))) {\n invalid(key, resolved[key], undefined, options); delete resolved[key];\n }\n }\n return resolved;\n}\n\nfunction allowedValues(\n key: string, input: DynamicStyleflowProps, defaults: DynamicStyleflowProps,\n contract: StyleflowContract\n): string[] | undefined {\n const axes = contract.semantic.axes;\n if (key === \"theme\") return contract.semantic.themes;\n if (key === \"tone\") return axes.color.tones;\n if (key === \"intensity\") {\n const tone = String(input.tone ?? defaults.tone ?? \"\");\n return tone ? axes.color.intensitiesByTone[tone] ?? [] : [...new Set(Object.values(axes.color.intensitiesByTone).flat())];\n }\n if (key === \"surface\") return axes.color.surfaces;\n if (key === \"foreground\") return axes.color.foregrounds;\n if (key === \"layoutRole\") return axes.layout.roles;\n if (key === \"density\") return axes.layout.densities;\n if (key === \"ty\") return axes.typography.types;\n if (key === \"v\") {\n const ty = String(input.ty ?? defaults.ty ?? contract.semantic.agentPolicy.defaults.typography.ty);\n return axes.typography.variantsByType[ty] ?? [];\n }\n if (key === \"w\") return axes.typography.weights;\n if (key === \"interactivePriority\") return axes.interaction.priorities;\n return undefined;\n}\n\nfunction explicitFallback(key: string, defaults: DynamicStyleflowProps, contract: StyleflowContract): unknown {\n if (defaults[key] !== undefined) return defaults[key];\n if (key === \"layoutRole\") return contract.semantic.agentPolicy.defaults.layoutRole;\n if (key === \"density\") return contract.semantic.agentPolicy.defaults.density;\n if (key === \"ty\" || key === \"v\" || key === \"w\") return contract.semantic.agentPolicy.defaults.typography[key];\n if (key === \"theme\") return contract.defaultTheme;\n return undefined;\n}\nfunction invalid(key: string, value: unknown, fallback: unknown, options: ResolveDynamicStyleflowOptions): void {\n const diagnostic: StyleflowDiagnostic = {\n code: fallback === undefined ? \"FP_STYLEFLOW_INVALID\" : \"FP_STYLEFLOW_FALLBACK\",\n prop: key, value, ...(fallback !== undefined ? { fallback } : {}),\n blocking: options.strict === true,\n message: fallback === undefined\n ? `Styleflow prop ${key}=${JSON.stringify(value)} is not in the grouped project contract.`\n : `Styleflow prop ${key}=${JSON.stringify(value)} fell back to ${JSON.stringify(fallback)}.`\n };\n (options.onDiagnostic ?? ((item) => console.warn(`[${item.code}] ${item.message}`)))(diagnostic);\n if (options.strict) throw new Error(`${diagnostic.code}: ${diagnostic.message}`);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const STYLEFLOW_THEME_STORAGE_KEY = "styleflow:theme";
|
|
2
|
+
export interface StyleflowThemeRuntimeConfig {
|
|
3
|
+
themes: string[];
|
|
4
|
+
defaultTheme: string;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
interface Window {
|
|
8
|
+
__FLOWPRESS_STYLEFLOW_THEME_RUNTIME__?: StyleflowThemeRuntimeConfig;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare function normalizeStyleflowThemes(themes: readonly string[], defaultTheme: string): StyleflowThemeRuntimeConfig;
|
|
12
|
+
export declare function initialStyleflowTheme(themes: readonly string[], defaultTheme: string, storedTheme?: string | null): string;
|
|
13
|
+
export declare function nextStyleflowTheme(themes: readonly string[], currentTheme: string): string;
|
|
14
|
+
export declare function styleflowThemeBootstrapScript(themes: readonly string[], defaultTheme: string): string;
|
|
15
|
+
export declare function initializeStyleflowThemeRuntime(config?: StyleflowThemeRuntimeConfig, documentObject?: Document, storage?: Pick<Storage, "getItem" | "setItem"> | null): () => void;
|
|
16
|
+
//# sourceMappingURL=theme-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-runtime.d.ts","sourceRoot":"","sources":["../src/theme-runtime.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,oBAAoB,CAAC;AAE7D,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,qCAAqC,CAAC,EAAE,2BAA2B,CAAC;KACrE;CACF;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,YAAY,EAAE,MAAM,GACnB,2BAA2B,CAQ7B;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,YAAY,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,GAC1B,MAAM,CAKR;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,YAAY,EAAE,MAAM,GACnB,MAAM,CAIR;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,SAAS,MAAM,EAAE,EACzB,YAAY,EAAE,MAAM,GACnB,MAAM,CAIR;AAED,wBAAgB,+BAA+B,CAC7C,MAAM,GAAE,2BAC6B,EACrC,cAAc,GAAE,QAAmB,EACnC,OAAO,GAAE,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,CAAC,GAAG,IAA8B,GAC7E,MAAM,IAAI,CAiDZ"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export const STYLEFLOW_THEME_STORAGE_KEY = "styleflow:theme";
|
|
2
|
+
export function normalizeStyleflowThemes(themes, defaultTheme) {
|
|
3
|
+
const normalized = [...new Set(themes.filter((theme) => (typeof theme === "string" && /^[a-zA-Z0-9_-]+$/.test(theme))))];
|
|
4
|
+
const fallback = normalized.includes(defaultTheme)
|
|
5
|
+
? defaultTheme
|
|
6
|
+
: normalized[0] ?? "";
|
|
7
|
+
return { themes: normalized, defaultTheme: fallback };
|
|
8
|
+
}
|
|
9
|
+
export function initialStyleflowTheme(themes, defaultTheme, storedTheme) {
|
|
10
|
+
const config = normalizeStyleflowThemes(themes, defaultTheme);
|
|
11
|
+
return storedTheme && config.themes.includes(storedTheme)
|
|
12
|
+
? storedTheme
|
|
13
|
+
: config.defaultTheme;
|
|
14
|
+
}
|
|
15
|
+
export function nextStyleflowTheme(themes, currentTheme) {
|
|
16
|
+
if (themes.length === 0)
|
|
17
|
+
return "";
|
|
18
|
+
const index = themes.indexOf(currentTheme);
|
|
19
|
+
return themes[(index + 1 + themes.length) % themes.length] ?? themes[0] ?? "";
|
|
20
|
+
}
|
|
21
|
+
export function styleflowThemeBootstrapScript(themes, defaultTheme) {
|
|
22
|
+
const config = normalizeStyleflowThemes(themes, defaultTheme);
|
|
23
|
+
const json = JSON.stringify(config).replaceAll("<", "\\u003c");
|
|
24
|
+
return `(()=>{const c=${json};window.__FLOWPRESS_STYLEFLOW_THEME_RUNTIME__=c;if(!c.themes.length)return;let s=null;try{s=localStorage.getItem(${JSON.stringify(STYLEFLOW_THEME_STORAGE_KEY)})}catch{}const t=c.themes.includes(s)?s:c.defaultTheme;document.documentElement.setAttribute("data-styleflow-theme",t)})()`;
|
|
25
|
+
}
|
|
26
|
+
export function initializeStyleflowThemeRuntime(config = window.__FLOWPRESS_STYLEFLOW_THEME_RUNTIME__
|
|
27
|
+
?? { themes: [], defaultTheme: "" }, documentObject = document, storage = globalThis.localStorage) {
|
|
28
|
+
const normalized = normalizeStyleflowThemes(config.themes, config.defaultTheme);
|
|
29
|
+
if (normalized.themes.length === 0)
|
|
30
|
+
return () => undefined;
|
|
31
|
+
const root = documentObject.documentElement;
|
|
32
|
+
let current = initialStyleflowTheme(normalized.themes, normalized.defaultTheme, root.getAttribute("data-styleflow-theme"));
|
|
33
|
+
const buttons = [...documentObject.querySelectorAll("[data-styleflow-theme-toggle]")];
|
|
34
|
+
const updateButtons = () => {
|
|
35
|
+
for (const button of buttons) {
|
|
36
|
+
const baseLabel = button.dataset.styleflowThemeToggleLabel
|
|
37
|
+
|| button.getAttribute("aria-label")
|
|
38
|
+
|| "Change color theme";
|
|
39
|
+
button.dataset.styleflowThemeToggleLabel = baseLabel.replace(/: .+$/, "");
|
|
40
|
+
button.setAttribute("aria-label", `${button.dataset.styleflowThemeToggleLabel}: ${current}`);
|
|
41
|
+
const label = button.querySelector("[data-styleflow-theme-label]");
|
|
42
|
+
if (label)
|
|
43
|
+
label.textContent = current;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const apply = (theme, persist) => {
|
|
47
|
+
current = theme;
|
|
48
|
+
root.setAttribute("data-styleflow-theme", theme);
|
|
49
|
+
if (persist && storage) {
|
|
50
|
+
try {
|
|
51
|
+
storage.setItem(STYLEFLOW_THEME_STORAGE_KEY, theme);
|
|
52
|
+
}
|
|
53
|
+
catch { /* noop */ }
|
|
54
|
+
}
|
|
55
|
+
updateButtons();
|
|
56
|
+
documentObject.dispatchEvent(new CustomEvent("styleflow:theme-change", {
|
|
57
|
+
detail: { theme }
|
|
58
|
+
}));
|
|
59
|
+
};
|
|
60
|
+
const listeners = new Map();
|
|
61
|
+
for (const button of buttons) {
|
|
62
|
+
if (button.dataset.styleflowThemeToggleBound === "true")
|
|
63
|
+
continue;
|
|
64
|
+
const listener = () => apply(nextStyleflowTheme(normalized.themes, current), true);
|
|
65
|
+
button.dataset.styleflowThemeToggleBound = "true";
|
|
66
|
+
button.addEventListener("click", listener);
|
|
67
|
+
listeners.set(button, listener);
|
|
68
|
+
}
|
|
69
|
+
updateButtons();
|
|
70
|
+
return () => {
|
|
71
|
+
for (const [button, listener] of listeners) {
|
|
72
|
+
button.removeEventListener("click", listener);
|
|
73
|
+
delete button.dataset.styleflowThemeToggleBound;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=theme-runtime.js.map
|