@master/css-integration 2.0.0-rc.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @master/css-integration
2
+
3
+ Shared Master CSS integration contracts, virtual module protocols, and build helpers.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @master/css-integration
9
+ ```
10
+
11
+ ## Responsibility
12
+
13
+ `@master/css-integration` is adapter-neutral glue for official build and framework integrations. It owns virtual module IDs, `?master-css-manifest` request helpers, generated manifest and emittedGlobals module source helpers, runtime injection source, ambient client declarations, and explicit Node/build helper subpaths.
14
+
15
+ It does not implement project manifest discovery, CSS import graph resolution, extraction, runtime hydration, or framework lifecycle behavior.
16
+
17
+ ## Public subpaths
18
+
19
+ | Subpath | Purpose |
20
+ | --- | --- |
21
+ | `@master/css-integration` | Shared browser-safe contracts. |
22
+ | `@master/css-integration/client` | Ambient TypeScript declarations for virtual modules. |
23
+ | `@master/css-integration/module` | General virtual module helpers. |
24
+ | `@master/css-integration/manifest-module` | Manifest virtual module IDs, query helpers, and JSON helpers. |
25
+ | `@master/css-integration/manifest-facade` | Generated manifest facade source helpers. |
26
+ | `@master/css-integration/style-module` | Generated style module helpers. |
27
+ | `@master/css-integration/emitted-globals-module` | Generated emittedGlobals module helpers. |
28
+ | `@master/css-integration/runtime` | Runtime injection source helpers. |
29
+ | `@master/css-integration/manifest-loader-plugin` | Build-only manifest loader plugin contracts. |
30
+ | `@master/css-integration/node` | Node filesystem/path helpers. |
31
+
32
+ ## Client types
33
+
34
+ Add the client type reference when TypeScript imports Master CSS virtual modules:
35
+
36
+ ```ts
37
+ /// <reference types="@master/css-integration/client" />
38
+ ```
39
+
40
+ This declares modules such as `virtual:master-css-manifest`, `virtual:master-css-emitted-globals`, generated CSS modules, and `?master-css-manifest` imports.
package/client.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ declare module '*?master-css-manifest' {
2
+ import type { MasterCSSManifest } from '@master/css-engine'
3
+
4
+ const manifest: MasterCSSManifest
5
+ export default manifest
6
+ }
7
+
8
+ declare module 'virtual:master-utilities.css' {
9
+ }
10
+
11
+ declare module 'virtual:master-css-manifest' {
12
+ import type { MasterCSSManifest } from '@master/css-engine'
13
+
14
+ const manifest: MasterCSSManifest
15
+ export default manifest
16
+ }
17
+
18
+ declare module 'virtual:master-css-emitted-globals' {
19
+ import type { MasterCSSEmittedGlobals } from '@master/css-engine'
20
+
21
+ const emittedGlobals: MasterCSSEmittedGlobals
22
+ export default emittedGlobals
23
+ }
@@ -0,0 +1,7 @@
1
+ import type { MasterCSSEmittedGlobals } from '@master/css-engine';
2
+ export type { MasterCSSEmittedGlobals };
3
+ export declare const VIRTUAL_EMITTED_GLOBALS_ID = "virtual:master-css-emitted-globals";
4
+ export declare const VIRTUAL_EMITTED_GLOBALS_FILE = "master-css-emitted-globals.js";
5
+ export declare const EMPTY_EMITTED_GLOBALS_MODULE = "export default { variables: {}, animations: {} };";
6
+ export declare function normalizeEmittedGlobals(emittedGlobals?: MasterCSSEmittedGlobals): Required<MasterCSSEmittedGlobals>;
7
+ export declare function toEmittedGlobalsModule(emittedGlobals: MasterCSSEmittedGlobals): string;
@@ -0,0 +1,14 @@
1
+ const VIRTUAL_EMITTED_GLOBALS_ID = 'virtual:master-css-emitted-globals';
2
+ const VIRTUAL_EMITTED_GLOBALS_FILE = 'master-css-emitted-globals.js';
3
+ const EMPTY_EMITTED_GLOBALS_MODULE = 'export default { variables: {}, animations: {} };';
4
+ function normalizeEmittedGlobals(emittedGlobals = {}) {
5
+ return {
6
+ variables: emittedGlobals.variables || {},
7
+ animations: emittedGlobals.animations || {}
8
+ };
9
+ }
10
+ function toEmittedGlobalsModule(emittedGlobals) {
11
+ return `export default ${JSON.stringify(normalizeEmittedGlobals(emittedGlobals))};`;
12
+ }
13
+
14
+ export { EMPTY_EMITTED_GLOBALS_MODULE, VIRTUAL_EMITTED_GLOBALS_FILE, VIRTUAL_EMITTED_GLOBALS_ID, normalizeEmittedGlobals, toEmittedGlobalsModule };
@@ -0,0 +1 @@
1
+ export * from './module';
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ export { CSS_RUNTIME_INJECTION, MASTER_CSS_RUNTIME_INJECTED_MARKER } from './runtime.mjs';
2
+ export { EMPTY_EMITTED_GLOBALS_MODULE, VIRTUAL_EMITTED_GLOBALS_FILE, VIRTUAL_EMITTED_GLOBALS_ID, normalizeEmittedGlobals, toEmittedGlobalsModule } from './emitted-globals-module.mjs';
3
+ export { EMPTY_MANIFEST_JSON, MASTER_CSS_MANIFEST_QUERY, VIRTUAL_MANIFEST_ASSET_FILE, VIRTUAL_MANIFEST_FILE, VIRTUAL_MANIFEST_ID, isMasterCSSManifestRequest, stripMasterCSSManifestQuery, stripResourceQuery, toManifestJSON, toManifestJSONResult } from './manifest-module.mjs';
4
+ export { MANIFEST_ASSET_FILE, MANIFEST_MODULE_FILE, MASTER_CSS_MANIFEST_PRELOAD_AS, MASTER_CSS_MANIFEST_PRELOAD_REL, MASTER_CSS_MANIFEST_PRELOAD_TYPE, toBrowserManifestFacadeModule, toInlineManifestModule, toManifestPreloadLinkAttrs, toManifestPreloadLinkTag, toNodeManifestFacadeModule, toUniversalManifestFacadeModule } from './manifest-facade.mjs';
5
+ export { VIRTUAL_CSS_ID } from './style-module.mjs';
@@ -0,0 +1,18 @@
1
+ export declare const MANIFEST_MODULE_FILE = "master-css-manifest.js";
2
+ export declare const MANIFEST_ASSET_FILE = "master-css-manifest.json";
3
+ export declare const MASTER_CSS_MANIFEST_PRELOAD_REL = "preload";
4
+ export declare const MASTER_CSS_MANIFEST_PRELOAD_AS = "fetch";
5
+ export declare const MASTER_CSS_MANIFEST_PRELOAD_TYPE = "application/json";
6
+ export interface ManifestPreloadLinkAttrs {
7
+ rel: typeof MASTER_CSS_MANIFEST_PRELOAD_REL;
8
+ as: typeof MASTER_CSS_MANIFEST_PRELOAD_AS;
9
+ type: typeof MASTER_CSS_MANIFEST_PRELOAD_TYPE;
10
+ crossorigin: '';
11
+ href: string;
12
+ }
13
+ export declare function toInlineManifestModule(json: string): string;
14
+ export declare function toManifestPreloadLinkAttrs(href: string): ManifestPreloadLinkAttrs;
15
+ export declare function toManifestPreloadLinkTag(href: string): string;
16
+ export declare function toBrowserManifestFacadeModule(urlExpression: string): string;
17
+ export declare function toNodeManifestFacadeModule(urlExpression: string): string;
18
+ export declare function toUniversalManifestFacadeModule(urlExpression: string): string;
@@ -0,0 +1,95 @@
1
+ const MANIFEST_MODULE_FILE = 'master-css-manifest.js';
2
+ const MANIFEST_ASSET_FILE = 'master-css-manifest.json';
3
+ const MASTER_CSS_MANIFEST_PRELOAD_REL = 'preload';
4
+ const MASTER_CSS_MANIFEST_PRELOAD_AS = 'fetch';
5
+ const MASTER_CSS_MANIFEST_PRELOAD_TYPE = 'application/json';
6
+ function escapeAttributeValue(value) {
7
+ return value.replace(/&/g, '&amp;').replace(/"/g, '&quot;');
8
+ }
9
+ function toInlineManifestModule(json) {
10
+ return `export default ${json};`;
11
+ }
12
+ function toManifestPreloadLinkAttrs(href) {
13
+ return {
14
+ rel: MASTER_CSS_MANIFEST_PRELOAD_REL,
15
+ as: MASTER_CSS_MANIFEST_PRELOAD_AS,
16
+ type: MASTER_CSS_MANIFEST_PRELOAD_TYPE,
17
+ crossorigin: '',
18
+ href
19
+ };
20
+ }
21
+ function toManifestPreloadLinkTag(href) {
22
+ const attrs = toManifestPreloadLinkAttrs(href);
23
+ return [
24
+ '<link',
25
+ `rel="${attrs.rel}"`,
26
+ `as="${attrs.as}"`,
27
+ `type="${attrs.type}"`,
28
+ 'crossorigin',
29
+ `href="${escapeAttributeValue(attrs.href)}">`
30
+ ].join(' ');
31
+ }
32
+ function toBrowserManifestFacadeModule(urlExpression) {
33
+ return [
34
+ `const masterCSSManifestURL = ${urlExpression};`,
35
+ `const masterCSSManifestResponse = await fetch(masterCSSManifestURL);`,
36
+ `if (!masterCSSManifestResponse.ok) {`,
37
+ ` throw new Error(\`Failed to load Master CSS manifest JSON: \${masterCSSManifestResponse.status} \${masterCSSManifestResponse.statusText}\`);`,
38
+ `}`,
39
+ `export default await masterCSSManifestResponse.json();`,
40
+ ``
41
+ ].join('\n');
42
+ }
43
+ function toNodeManifestFacadeModule(urlExpression) {
44
+ return [
45
+ `import { readFile } from 'node:fs/promises';`,
46
+ `import { fileURLToPath } from 'node:url';`,
47
+ ``,
48
+ `const masterCSSManifestURL = ${urlExpression};`,
49
+ `export default JSON.parse(await readFile(fileURLToPath(new URL(masterCSSManifestURL, import.meta.url).href), 'utf8'));`,
50
+ ``
51
+ ].join('\n');
52
+ }
53
+ function toUniversalManifestFacadeModule(urlExpression) {
54
+ return [
55
+ `const masterCSSManifestURL = ${urlExpression};`,
56
+ ``,
57
+ `async function loadMasterCSSManifestFromFile(url) {`,
58
+ ` const load = new Function('specifier', 'return import(specifier)');`,
59
+ ` const { readFile } = await load('node:fs/promises');`,
60
+ ` const { fileURLToPath } = await load('node:url');`,
61
+ ` const { join } = await load('node:path');`,
62
+ ` const value = typeof url === 'string' ? url : url.href;`,
63
+ ` const files = value.startsWith('/_next/')`,
64
+ ` ? [`,
65
+ ` join(process.cwd(), '.next', value.slice('/_next/'.length)),`,
66
+ ` join(process.cwd(), '.next', 'dev', value.slice('/_next/'.length))`,
67
+ ` ]`,
68
+ ` : [fileURLToPath(value)];`,
69
+ ` let lastError;`,
70
+ ` for (const file of files) {`,
71
+ ` try {`,
72
+ ` return JSON.parse(await readFile(file, 'utf8'));`,
73
+ ` } catch (error) {`,
74
+ ` lastError = error;`,
75
+ ` }`,
76
+ ` }`,
77
+ ` throw lastError;`,
78
+ `}`,
79
+ ``,
80
+ `async function loadMasterCSSManifestFromFetch(url) {`,
81
+ ` const response = await fetch(url);`,
82
+ ` if (!response.ok) {`,
83
+ ` throw new Error(\`Failed to load Master CSS manifest JSON: \${response.status} \${response.statusText}\`);`,
84
+ ` }`,
85
+ ` return response.json();`,
86
+ `}`,
87
+ ``,
88
+ `export default typeof window === 'undefined'`,
89
+ ` ? await loadMasterCSSManifestFromFile(masterCSSManifestURL)`,
90
+ ` : await loadMasterCSSManifestFromFetch(masterCSSManifestURL);`,
91
+ ``
92
+ ].join('\n');
93
+ }
94
+
95
+ export { MANIFEST_ASSET_FILE, MANIFEST_MODULE_FILE, MASTER_CSS_MANIFEST_PRELOAD_AS, MASTER_CSS_MANIFEST_PRELOAD_REL, MASTER_CSS_MANIFEST_PRELOAD_TYPE, toBrowserManifestFacadeModule, toInlineManifestModule, toManifestPreloadLinkAttrs, toManifestPreloadLinkTag, toNodeManifestFacadeModule, toUniversalManifestFacadeModule };
@@ -0,0 +1,38 @@
1
+ import { type CSSManifestJSONResult } from './manifest-module';
2
+ type MaybePromise<T> = T | Promise<T>;
3
+ export interface MasterCSSManifestLoaderPluginContext {
4
+ addWatchFile?: (id: string) => void;
5
+ emitFile?: (asset: {
6
+ type: 'asset';
7
+ name: string;
8
+ source: string;
9
+ }) => string;
10
+ }
11
+ export interface MasterCSSManifestLoaderPluginOptions {
12
+ cwd?: string;
13
+ resolveUnresolved?: boolean;
14
+ loadManifestJSON: (path: string) => MaybePromise<CSSManifestJSONResult>;
15
+ toManifestModule?: (payload: {
16
+ manifestPath: string;
17
+ result: CSSManifestJSONResult;
18
+ pluginContext: MasterCSSManifestLoaderPluginContext;
19
+ }) => MaybePromise<string>;
20
+ onLoadManifestJSON?: (payload: {
21
+ manifestPath: string;
22
+ result: CSSManifestJSONResult;
23
+ pluginContext: MasterCSSManifestLoaderPluginContext;
24
+ }) => void;
25
+ }
26
+ export declare function createMasterCSSManifestLoaderPlugin(options: MasterCSSManifestLoaderPluginOptions): {
27
+ name: string;
28
+ enforce: "pre";
29
+ resolveId(this: {
30
+ resolve?: (id: string, importer?: string, options?: {
31
+ skipSelf?: boolean;
32
+ }) => Promise<{
33
+ id: string;
34
+ } | null | undefined>;
35
+ }, id: string, importer?: string): Promise<string | undefined>;
36
+ load(this: MasterCSSManifestLoaderPluginContext, id: string): Promise<string | undefined>;
37
+ };
38
+ export {};
@@ -0,0 +1,43 @@
1
+ import { dirname, isAbsolute, resolve } from 'node:path';
2
+ import { isMasterCSSManifestRequest, stripMasterCSSManifestQuery, stripResourceQuery } from './manifest-module.mjs';
3
+ import { toInlineManifestModule } from './manifest-facade.mjs';
4
+ import { fromResolvedMasterCSSManifestId, toResolvedMasterCSSManifestId } from './node.mjs';
5
+
6
+ function createMasterCSSManifestLoaderPlugin(options) {
7
+ return {
8
+ name: 'master-css:manifest-loader',
9
+ enforce: 'pre',
10
+ async resolveId (id, importer) {
11
+ if (!isMasterCSSManifestRequest(id)) return;
12
+ const sourceId = stripMasterCSSManifestQuery(id);
13
+ const resolved = await this.resolve?.(sourceId, importer, {
14
+ skipSelf: true
15
+ });
16
+ if (resolved) return toResolvedMasterCSSManifestId(resolved.id);
17
+ if (options.resolveUnresolved === false) return;
18
+ const baseDir = importer ? dirname(stripResourceQuery(importer)) : options.cwd || process.cwd();
19
+ const file = isAbsolute(sourceId) ? sourceId : resolve(baseDir, sourceId);
20
+ return toResolvedMasterCSSManifestId(file);
21
+ },
22
+ async load (id) {
23
+ const manifestPath = fromResolvedMasterCSSManifestId(id);
24
+ if (!manifestPath) return;
25
+ const result = await options.loadManifestJSON(manifestPath);
26
+ for (const dependency of result.dependencies){
27
+ this.addWatchFile?.(dependency);
28
+ }
29
+ options.onLoadManifestJSON?.({
30
+ manifestPath,
31
+ result,
32
+ pluginContext: this
33
+ });
34
+ return options.toManifestModule ? options.toManifestModule({
35
+ manifestPath,
36
+ result,
37
+ pluginContext: this
38
+ }) : toInlineManifestModule(result.json);
39
+ }
40
+ };
41
+ }
42
+
43
+ export { createMasterCSSManifestLoaderPlugin };
@@ -0,0 +1,27 @@
1
+ import type { MasterCSSManifest } from '@master/css-schema/manifest';
2
+ export type { MasterCSSManifest };
3
+ export declare const VIRTUAL_MANIFEST_ID = "virtual:master-css-manifest";
4
+ export declare const MASTER_CSS_MANIFEST_QUERY = "?master-css-manifest";
5
+ export declare const VIRTUAL_MANIFEST_FILE = "master-css-manifest.js";
6
+ export declare const VIRTUAL_MANIFEST_ASSET_FILE = "master-css-manifest.json";
7
+ export declare const EMPTY_MANIFEST_JSON = "{\"version\":1}";
8
+ export interface CSSManifestLoadResult {
9
+ manifest: MasterCSSManifest;
10
+ dependencies: string[];
11
+ classNames?: string[];
12
+ nativeClassNames?: string[];
13
+ nativeCSS?: string;
14
+ css?: string;
15
+ generatedCSS?: string;
16
+ warnings?: string[];
17
+ }
18
+ export type CSSManifestJSONResult = CSSManifestLoadResult & {
19
+ json: string;
20
+ };
21
+ export declare function isMasterCSSManifestRequest(id: string): boolean;
22
+ export declare function stripMasterCSSManifestQuery(id: string): string;
23
+ export declare function stripResourceQuery(resourcePath: string): string;
24
+ export declare function toManifestJSON(manifest: MasterCSSManifest): string;
25
+ export declare function toManifestJSONResult<T extends CSSManifestLoadResult>(result: T): T & {
26
+ json: string;
27
+ };
@@ -0,0 +1,28 @@
1
+ import { stringifyMasterCSSManifestJSON } from '@master/css-schema/manifest-json';
2
+ import { MANIFEST_ASSET_FILE, MANIFEST_MODULE_FILE } from './manifest-facade.mjs';
3
+
4
+ const VIRTUAL_MANIFEST_ID = 'virtual:master-css-manifest';
5
+ const MASTER_CSS_MANIFEST_QUERY = '?master-css-manifest';
6
+ const VIRTUAL_MANIFEST_FILE = MANIFEST_MODULE_FILE;
7
+ const VIRTUAL_MANIFEST_ASSET_FILE = MANIFEST_ASSET_FILE;
8
+ const EMPTY_MANIFEST_JSON = '{"version":1}';
9
+ function isMasterCSSManifestRequest(id) {
10
+ return id.endsWith(MASTER_CSS_MANIFEST_QUERY);
11
+ }
12
+ function stripMasterCSSManifestQuery(id) {
13
+ return isMasterCSSManifestRequest(id) ? id.slice(0, -MASTER_CSS_MANIFEST_QUERY.length) : id;
14
+ }
15
+ function stripResourceQuery(resourcePath) {
16
+ return resourcePath.replace(/[?#].*$/, '');
17
+ }
18
+ function toManifestJSON(manifest) {
19
+ return stringifyMasterCSSManifestJSON(manifest);
20
+ }
21
+ function toManifestJSONResult(result) {
22
+ return {
23
+ ...result,
24
+ json: toManifestJSON(result.manifest)
25
+ };
26
+ }
27
+
28
+ export { EMPTY_MANIFEST_JSON, MASTER_CSS_MANIFEST_QUERY, VIRTUAL_MANIFEST_ASSET_FILE, VIRTUAL_MANIFEST_FILE, VIRTUAL_MANIFEST_ID, isMasterCSSManifestRequest, stripMasterCSSManifestQuery, stripResourceQuery, toManifestJSON, toManifestJSONResult };
@@ -0,0 +1,5 @@
1
+ export * from './manifest-module';
2
+ export * from './manifest-facade';
3
+ export * from './style-module';
4
+ export * from './emitted-globals-module';
5
+ export * from './runtime';
@@ -0,0 +1,5 @@
1
+ export { EMPTY_MANIFEST_JSON, MASTER_CSS_MANIFEST_QUERY, VIRTUAL_MANIFEST_ASSET_FILE, VIRTUAL_MANIFEST_FILE, VIRTUAL_MANIFEST_ID, isMasterCSSManifestRequest, stripMasterCSSManifestQuery, stripResourceQuery, toManifestJSON, toManifestJSONResult } from './manifest-module.mjs';
2
+ export { MANIFEST_ASSET_FILE, MANIFEST_MODULE_FILE, MASTER_CSS_MANIFEST_PRELOAD_AS, MASTER_CSS_MANIFEST_PRELOAD_REL, MASTER_CSS_MANIFEST_PRELOAD_TYPE, toBrowserManifestFacadeModule, toInlineManifestModule, toManifestPreloadLinkAttrs, toManifestPreloadLinkTag, toNodeManifestFacadeModule, toUniversalManifestFacadeModule } from './manifest-facade.mjs';
3
+ export { VIRTUAL_CSS_ID } from './style-module.mjs';
4
+ export { EMPTY_EMITTED_GLOBALS_MODULE, VIRTUAL_EMITTED_GLOBALS_FILE, VIRTUAL_EMITTED_GLOBALS_ID, normalizeEmittedGlobals, toEmittedGlobalsModule } from './emitted-globals-module.mjs';
5
+ export { CSS_RUNTIME_INJECTION, MASTER_CSS_RUNTIME_INJECTED_MARKER } from './runtime.mjs';
package/dist/node.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export declare const RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX = "\0master-css-manifest:";
2
+ export declare const VIRTUAL_MODULE_DIR = "node_modules/.master-css";
3
+ export declare function toHashedManifestAssetFileName(json: string, basename?: string): string;
4
+ export declare function toHashedHydrationManifestAssetFileName(json: string): string;
5
+ export declare function toResolvedMasterCSSManifestId(file: string): string;
6
+ export declare function fromResolvedMasterCSSManifestId(id: string): string | undefined;
7
+ export declare function toVirtualDefaultManifestModulePath(context: string): string;
8
+ export declare function toVirtualCSSManifestModulePath(context: string, file: string): string;
9
+ export declare function toVirtualCSSManifestAssetPath(context: string, file: string): string;
10
+ export declare function toVirtualCSSModulePath(context: string): string;
11
+ export declare function toVirtualEmittedGlobalsModulePath(context: string): string;
12
+ export declare function createVirtualDefaultManifestModulePathPattern(): RegExp;
13
+ export declare function ensureVirtualModuleFile(file: string, source: string): string;
14
+ export declare function ensureVirtualManifestModulePath(projectDir?: string): string;
15
+ export declare function ensureVirtualEmittedGlobalsModulePath(projectDir?: string): string;
package/dist/node.mjs ADDED
@@ -0,0 +1,75 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { VIRTUAL_MANIFEST_FILE, EMPTY_MANIFEST_JSON } from './manifest-module.mjs';
5
+ import { toInlineManifestModule } from './manifest-facade.mjs';
6
+ import { VIRTUAL_EMITTED_GLOBALS_FILE, EMPTY_EMITTED_GLOBALS_MODULE } from './emitted-globals-module.mjs';
7
+ import { MASTER_CSS_HYDRATION_MANIFEST_FILE_BASENAME } from '@master/css-schema/hydration-manifest';
8
+
9
+ const RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX = '\0master-css-manifest:';
10
+ const VIRTUAL_MODULE_DIR = 'node_modules/.master-css';
11
+ const VIRTUAL_MODULE_DIR_SEGMENTS = [
12
+ 'node_modules',
13
+ '.master-css'
14
+ ];
15
+ function toHashedManifestAssetFileName(json, basename = 'master-css-manifest') {
16
+ const hash = createHash('sha256').update(json).digest('hex').slice(0, 8);
17
+ return `${basename}.${hash}.json`;
18
+ }
19
+ function toHashedHydrationManifestAssetFileName(json) {
20
+ return toHashedManifestAssetFileName(json, MASTER_CSS_HYDRATION_MANIFEST_FILE_BASENAME);
21
+ }
22
+ function toResolvedMasterCSSManifestId(file) {
23
+ return RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX + Buffer.from(file).toString('base64url');
24
+ }
25
+ function fromResolvedMasterCSSManifestId(id) {
26
+ return id.startsWith(RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX) ? Buffer.from(id.slice(RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX.length), 'base64url').toString() : undefined;
27
+ }
28
+ function toVirtualDefaultManifestModulePath(context) {
29
+ return join(context, ...VIRTUAL_MODULE_DIR_SEGMENTS, VIRTUAL_MANIFEST_FILE);
30
+ }
31
+ function encodeVirtualFilename(id) {
32
+ return Buffer.from(id).toString('base64url');
33
+ }
34
+ function toVirtualCSSManifestModulePath(context, file) {
35
+ return join(context, ...VIRTUAL_MODULE_DIR_SEGMENTS, `${encodeVirtualFilename(file)}.manifest.js`);
36
+ }
37
+ function toVirtualCSSManifestAssetPath(context, file) {
38
+ return join(context, ...VIRTUAL_MODULE_DIR_SEGMENTS, `${encodeVirtualFilename(file)}.manifest.json`);
39
+ }
40
+ function toVirtualCSSModulePath(context) {
41
+ return join(context, ...VIRTUAL_MODULE_DIR_SEGMENTS, 'master-utilities.css');
42
+ }
43
+ function toVirtualEmittedGlobalsModulePath(context) {
44
+ return join(context, ...VIRTUAL_MODULE_DIR_SEGMENTS, VIRTUAL_EMITTED_GLOBALS_FILE);
45
+ }
46
+ function escapeRegExp(source) {
47
+ return source.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
48
+ }
49
+ function createVirtualDefaultManifestModulePathPattern() {
50
+ const source = [
51
+ ...VIRTUAL_MODULE_DIR_SEGMENTS,
52
+ VIRTUAL_MANIFEST_FILE
53
+ ].map(escapeRegExp).join(String.raw`[/\\]`);
54
+ return new RegExp(String.raw`(?:^|[/\\])${source}$`);
55
+ }
56
+ function ensureVirtualModuleFile(file, source) {
57
+ mkdirSync(dirname(file), {
58
+ recursive: true
59
+ });
60
+ try {
61
+ if (readFileSync(file, 'utf8') === source) return file;
62
+ } catch {
63
+ // Create the file below when it does not exist or cannot be read.
64
+ }
65
+ writeFileSync(file, source);
66
+ return file;
67
+ }
68
+ function ensureVirtualManifestModulePath(projectDir = process.cwd()) {
69
+ return ensureVirtualModuleFile(toVirtualDefaultManifestModulePath(projectDir), toInlineManifestModule(EMPTY_MANIFEST_JSON));
70
+ }
71
+ function ensureVirtualEmittedGlobalsModulePath(projectDir = process.cwd()) {
72
+ return ensureVirtualModuleFile(toVirtualEmittedGlobalsModulePath(projectDir), EMPTY_EMITTED_GLOBALS_MODULE);
73
+ }
74
+
75
+ export { RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX, VIRTUAL_MODULE_DIR, createVirtualDefaultManifestModulePathPattern, ensureVirtualEmittedGlobalsModulePath, ensureVirtualManifestModulePath, ensureVirtualModuleFile, fromResolvedMasterCSSManifestId, toHashedHydrationManifestAssetFileName, toHashedManifestAssetFileName, toResolvedMasterCSSManifestId, toVirtualCSSManifestAssetPath, toVirtualCSSManifestModulePath, toVirtualCSSModulePath, toVirtualDefaultManifestModulePath, toVirtualEmittedGlobalsModulePath };
@@ -0,0 +1,2 @@
1
+ export declare const MASTER_CSS_RUNTIME_INJECTED_MARKER = "/*__MASTER_CSS_RUNTIME_INJECTED__*/";
2
+ export declare const CSS_RUNTIME_INJECTION: string;
@@ -0,0 +1,19 @@
1
+ import { VIRTUAL_MANIFEST_ID } from './manifest-module.mjs';
2
+ import { VIRTUAL_EMITTED_GLOBALS_ID } from './emitted-globals-module.mjs';
3
+
4
+ const MASTER_CSS_RUNTIME_INJECTED_MARKER = '/*__MASTER_CSS_RUNTIME_INJECTED__*/';
5
+ const CSS_RUNTIME_INJECTION = [
6
+ `import { CSSRuntime } from '@master/css-runtime';`,
7
+ `import masterCSSManifest from '${VIRTUAL_MANIFEST_ID}';`,
8
+ `import masterCSSEmittedGlobals from '${VIRTUAL_EMITTED_GLOBALS_ID}';`,
9
+ `if (typeof document !== 'undefined') {`,
10
+ `const masterCSSRuntime = CSSRuntime.create({ manifest: masterCSSManifest, emittedGlobals: masterCSSEmittedGlobals });`,
11
+ `if (masterCSSRuntime.needsHydrationManifest()) {`,
12
+ `void masterCSSRuntime.loadHydrationManifest().then(() => masterCSSRuntime.observe());`,
13
+ `} else {`,
14
+ `masterCSSRuntime.observe();`,
15
+ `}`,
16
+ `}`
17
+ ].join('\n');
18
+
19
+ export { CSS_RUNTIME_INJECTION, MASTER_CSS_RUNTIME_INJECTED_MARKER };
@@ -0,0 +1 @@
1
+ export declare const VIRTUAL_CSS_ID = "virtual:master-utilities.css";
@@ -0,0 +1,3 @@
1
+ const VIRTUAL_CSS_ID = 'virtual:master-utilities.css';
2
+
3
+ export { VIRTUAL_CSS_ID };
package/package.json ADDED
@@ -0,0 +1 @@
1
+ {"name":"@master/css-integration","type":"module","scripts":{"build":"techor build \"src/**/*.ts\" --formats esm","dev":"pnpm build --watch","type-check":"tsc --noEmit","lint":"eslint","test":"vitest"},"license":"MIT","description":"Shared Master CSS integration contracts, virtual module protocols, and build helpers.","author":"Aoyue Design LLC.","funding":"https://rc.css.master.co/sponsor","homepage":"https://css.master.co","bugs":{"url":"https://github.com/master-co/css/issues"},"repository":{"type":"git","url":"https://github.com/master-co/css.git","directory":"packages/integration"},"keywords":["integration","virtual-module","css","mastercss"],"sideEffects":false,"main":"./dist/index.mjs","module":"./dist/index.mjs","jsnext:main":"./dist/index.mjs","esnext":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","default":"./dist/index.mjs"},"./client":{"types":"./client.d.ts"},"./module":{"types":"./dist/module.d.ts","import":"./dist/module.mjs","default":"./dist/module.mjs"},"./manifest-module":{"types":"./dist/manifest-module.d.ts","import":"./dist/manifest-module.mjs","default":"./dist/manifest-module.mjs"},"./manifest-facade":{"types":"./dist/manifest-facade.d.ts","import":"./dist/manifest-facade.mjs","default":"./dist/manifest-facade.mjs"},"./style-module":{"types":"./dist/style-module.d.ts","import":"./dist/style-module.mjs","default":"./dist/style-module.mjs"},"./emitted-globals-module":{"types":"./dist/emitted-globals-module.d.ts","import":"./dist/emitted-globals-module.mjs","default":"./dist/emitted-globals-module.mjs"},"./manifest-loader-plugin":{"types":"./dist/manifest-loader-plugin.d.ts","import":"./dist/manifest-loader-plugin.mjs","default":"./dist/manifest-loader-plugin.mjs"},"./runtime":{"types":"./dist/runtime.d.ts","import":"./dist/runtime.mjs","default":"./dist/runtime.mjs"},"./node":{"types":"./dist/node.d.ts","import":"./dist/node.mjs","default":"./dist/node.mjs"}},"files":["client.d.ts","dist"],"publishConfig":{"access":"public","provenance":true},"dependencies":{"@master/css-engine":"^2.0.0-rc.70","@master/css-schema":"^2.0.0-rc.70"},"version":"2.0.0-rc.70"}