@master/css-runtime 2.0.0-rc.8 → 2.0.0-rc.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Aoyue Design LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  </picture>
11
11
  </a>
12
12
  </p>
13
- <p align="center">Run the Master CSS right in the browser</p>
13
+ <p align="center">Browser runtime for Master CSS</p>
14
14
 
15
15
  <p align="center">
16
16
  <a aria-label="GitHub release (latest by date including pre-releases)" href="https://github.com/master-co/css/releases">
@@ -48,17 +48,108 @@
48
48
  <img alt="Follow @mastercorg" src="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
49
49
  </picture>
50
50
  </a>
51
- <a aria-label="Github Actions" href="https://github.com/1aron/repo/actions/workflows/release.yml">
51
+ <a aria-label="Github Actions" href="https://github.com/master-co/css/actions/workflows/ci-release.yml">
52
52
  <picture>
53
- <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=rc&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge">
54
- <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
55
- <img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/master-co/css/release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
53
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge">
54
+ <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
55
+ <img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
56
56
  </picture>
57
57
  </a>
58
58
  </p>
59
59
 
60
60
  </div>
61
61
 
62
- ## Documentation
63
- - [General Installation](https://rc.css.master.co/docs/installation/general)
64
- - [Using CDNs](https://rc.css.master.co/docs/installation/cdn)
62
+ ## Installation
63
+
64
+ ```bash
65
+ npm install @master/css-runtime
66
+ ```
67
+
68
+ Initialize the runtime with the project manifest and emitted global CSS state provided by an official integration:
69
+
70
+ ```js
71
+ import CSSRuntime from '@master/css-runtime'
72
+ import manifest from 'virtual:master-css-manifest'
73
+ import emittedGlobals from 'virtual:master-css-emitted-globals'
74
+
75
+ CSSRuntime.create({ manifest, emittedGlobals }).observe()
76
+ ```
77
+
78
+ ## CDN IIFE
79
+
80
+ Use the CDN runtime when a page only needs the default preset and zero configuration:
81
+
82
+ ```html
83
+ <link rel="preload" as="style" href="https://cdn.master.co/css@rc/base.css">
84
+ <link rel="modulepreload" as="json" crossorigin href="https://cdn.master.co/css-runtime@rc/default-manifest.json">
85
+ <link rel="stylesheet" href="https://cdn.master.co/css@rc/base.css">
86
+ <script src="https://cdn.master.co/css-runtime@rc"></script>
87
+ ```
88
+
89
+ The IIFE imports `default-manifest.json` next to the runtime script as a JSON module, starts automatically, and registers the document runtime as `globalThis.masterCSSRuntime`. The CDN must serve the manifest with `application/json`, and the browser must support JSON modules and import attributes. It does not read global options or custom manifests. Use ESM `CSSRuntime.create({ manifest, emittedGlobals }).observe()` for custom theme tokens, utilities, modes, emitted globals, or hydration inputs.
90
+
91
+ ## API
92
+
93
+ ### `CSSRuntime`
94
+
95
+ ```ts
96
+ import CSSRuntime from '@master/css-runtime'
97
+ import manifest from 'virtual:master-css-manifest'
98
+
99
+ const cssRuntime = CSSRuntime.create({ manifest })
100
+ cssRuntime.observe()
101
+ ```
102
+
103
+ `CSSRuntime` runs in the browser and extends the manifest-driven `MasterCSS` engine. Use `CSSRuntime.create({ manifest })` when the runtime should reuse an existing runtime for the same root.
104
+
105
+ | API | Type | Description |
106
+ | --- | --- | --- |
107
+ | `CSSRuntime.instances` | `WeakMap<Document \| ShadowRoot, CSSRuntime>` | Runtime instances keyed by root. |
108
+ | `CSSRuntime.create(options)` | `CSSRuntime` | Creates or reuses a registered runtime for `options.root`. |
109
+ | `cssRuntime.root` | `Document \| ShadowRoot` | Observed root. |
110
+ | `cssRuntime.host` | `Element` | Root host, usually `root.host` or `document.documentElement`. |
111
+ | `cssRuntime.container` | `HTMLElement \| ShadowRoot` | Container for `style#master-css`. |
112
+ | `cssRuntime.observing` | `boolean` | `true` after `observe()`, `false` after `disconnect()`. |
113
+ | `cssRuntime.classCounts` | `Map<string, number>` | Active DOM class usage counts. This is the source of truth for observed DOM usage. |
114
+ | `cssRuntime.classUtilities` | `Map<string, Utility[]>` | Generated rule cache. It can include retained mutation rules that are no longer active in the DOM. |
115
+ | `cssRuntime.retainedClassNames` | `Set<string>` | Mutation-removed class names whose generated rules are temporarily retained in CSSOM. |
116
+ | `register()` | `this` | Registers this runtime in `CSSRuntime.instances`. |
117
+ | `unregister()` | `this` | Removes this runtime from `CSSRuntime.instances`. |
118
+ | `needsHydrationManifest()` | `boolean` | Returns `true` when an external hydration manifest should be loaded before observation. |
119
+ | `loadHydrationManifest()` | `Promise<this>` | Reads inline hydration data or imports the external hydration manifest URL from `style#master-css`. |
120
+ | `setHydrationManifest(manifest?)` | `this` | Sets the hydration manifest used by progressive hydration. |
121
+ | `observe()` | `this` | Observes class attribute changes. |
122
+ | `ensureClassRules(...classNames)` | `this` | Synchronously ensures generated rules exist for class names. Use this to warm rules before DOM insertion. |
123
+ | `deleteClassRules(...classNames)` | `void` | Synchronously deletes generated rules for class names. |
124
+ | `flushRetainedClassRules()` | `number` | Synchronously removes retained mutation rules that are no longer active and returns the removed class count. |
125
+ | `disconnect()` | `this \| undefined` | Cancels observation. |
126
+ | `refresh(manifest?)` | `this` | Refreshes with a complete `MasterCSSManifest`. |
127
+ | `reset()` | `this` | Clears rules and styles. |
128
+ | `destroy()` | `this` | Removes this runtime from `CSSRuntime.instances`. |
129
+
130
+ MutationObserver additions update `classCounts` immediately. Existing and retained generated rules are reused immediately, while first-time rules discovered by the observer are batched into the next pre-paint flush. MutationObserver removals also update `classCounts` immediately, but generated CSS rules may be retained briefly to avoid CSSOM deletion during interaction-heavy updates. Re-adding a retained class reuses the existing generated rule. Direct `cssRuntime.ensureClassRules(...)`, `cssRuntime.deleteClassRules(...)`, `refresh()`, `disconnect()`, and `destroy()` stay synchronous.
131
+
132
+ ### Progressive Hydration
133
+
134
+ ```ts
135
+ import CSSRuntime from '@master/css-runtime'
136
+ import manifest from 'virtual:master-css-manifest'
137
+ import emittedGlobals from 'virtual:master-css-emitted-globals'
138
+
139
+ const cssRuntime = CSSRuntime.create({
140
+ manifest,
141
+ emittedGlobals,
142
+ })
143
+ if (cssRuntime.needsHydrationManifest()) {
144
+ await cssRuntime.loadHydrationManifest()
145
+ }
146
+ cssRuntime.observe()
147
+ ```
148
+
149
+ `emittedGlobals` tells the runtime which variables and keyframes were already emitted by the project CSS entry, so future dynamic classes can reuse them without inserting duplicate global CSS.
150
+
151
+ ## Related docs
152
+
153
+ - [General installation](https://rc.css.master.co/guide/installation)
154
+ - [Using CDNs](https://rc.css.master.co/guide/installation/cdn)
155
+ - [Runtime rendering](https://rc.css.master.co/guide/rendering-modes#runtime-rendering)
@@ -0,0 +1,14 @@
1
+ //#region src/class-tracker.d.ts
2
+ type ClassDeltaMap = Map<string, number>;
3
+ type ClassCountMap = Map<string, number>;
4
+ declare class RuntimeClassTracker {
5
+ private snapshots;
6
+ reset(): void;
7
+ collectConnected(root: Document | ShadowRoot, classCounts: ClassCountMap): Set<string>;
8
+ collectMutations(records: MutationRecord[]): ClassDeltaMap;
9
+ private snapshotElement;
10
+ private diffElement;
11
+ private removeElement;
12
+ }
13
+ //#endregion
14
+ export { RuntimeClassTracker as default };
package/dist/core.d.ts CHANGED
@@ -1,23 +1,111 @@
1
- import { MasterCSS } from '@master/css';
2
- import type { Config } from '@master/css';
3
- import './types/global';
4
- export declare class CSSRuntime extends MasterCSS {
5
- root: Document | ShadowRoot | undefined | null;
6
- customConfig: Config;
7
- readonly host: Element;
8
- readonly observing = false;
9
- readonly container: HTMLElement | ShadowRoot;
10
- observer?: MutationObserver | null;
11
- constructor(root?: Document | ShadowRoot | undefined | null, customConfig?: Config);
12
- /**
13
- * Observe the DOM for changes and update the running stylesheet. (browser only)
14
- * @param options mutation observer options
15
- * @returns this
16
- */
17
- observe(options?: MutationObserverInit): this;
18
- refresh(customConfig?: Config): this;
19
- reset(): this;
20
- disconnect(): this;
21
- destroy(): this;
1
+ import RuntimeUtilityLayer from "./utility-layer.js";
2
+ import { HydrateResult } from "./types/hydrate-result.js";
3
+ import RuntimeThemeLayer from "./theme-layer.js";
4
+ import { MasterCSS, MasterCSSEmittedGlobals } from "@master/css-engine";
5
+ import { MasterCSSManifest } from "@master/css-schema/manifest";
6
+ import { MasterCSSHydrationManifest } from "@master/css-schema/hydration-manifest";
7
+
8
+ //#region src/core.d.ts
9
+ interface CSSRuntimeCreateOptions {
10
+ manifest: MasterCSSManifest;
11
+ root?: Document | ShadowRoot;
12
+ emittedGlobals?: MasterCSSEmittedGlobals;
13
+ hydrationManifest?: MasterCSSHydrationManifest;
22
14
  }
23
- export declare const cssRuntimes: CSSRuntime[];
15
+ declare class CSSRuntime extends MasterCSS {
16
+ root: Document | ShadowRoot;
17
+ hydrationManifest?: MasterCSSHydrationManifest | undefined;
18
+ static instances: WeakMap<Document | ShadowRoot, CSSRuntime>;
19
+ readonly host: Element;
20
+ readonly container: HTMLElement | ShadowRoot;
21
+ readonly baseLayer: RuntimeUtilityLayer;
22
+ readonly themeLayer: RuntimeThemeLayer;
23
+ readonly defaultsLayer: RuntimeUtilityLayer;
24
+ readonly componentsLayer: RuntimeUtilityLayer;
25
+ readonly utilitiesLayer: RuntimeUtilityLayer;
26
+ readonly classCounts: Map<string, number>;
27
+ readonly retainedClassNames: Set<string>;
28
+ private readonly classTracker;
29
+ private readonly pendingAddedClassNames;
30
+ private readonly pendingRemovedClassNames;
31
+ private readonly retainedClassRules;
32
+ private pendingAdditionFrame;
33
+ private pendingRemovalFrame;
34
+ private pendingRemovalFlushFrame;
35
+ private retainedCleanupIdleHandle;
36
+ private retainedCleanupTimeoutHandle;
37
+ private hydrationFailureReason?;
38
+ observer?: MutationObserver;
39
+ progressive: boolean;
40
+ observing: boolean;
41
+ static create(options: CSSRuntimeCreateOptions): CSSRuntime;
42
+ constructor(root: (Document | ShadowRoot) | undefined, manifest: MasterCSSManifest, emittedGlobals?: MasterCSSEmittedGlobals, hydrationManifest?: MasterCSSHydrationManifest | undefined);
43
+ register(): this;
44
+ unregister(): this;
45
+ setHydrationManifest(hydrationManifest?: MasterCSSHydrationManifest): this;
46
+ needsHydrationManifest(): boolean;
47
+ loadHydrationManifest(): Promise<this>;
48
+ private createRuntimeStyle;
49
+ private warnHydrationFallback;
50
+ private useRuntimeStyle;
51
+ private detectRuntimeStyle;
52
+ private collectConnectedClasses;
53
+ private hydrateRuntimeStyle;
54
+ private renderRuntimeStyle;
55
+ private getAnimationFrameWindow;
56
+ private cancelPendingRemovalFrames;
57
+ private cancelPendingAdditionFrame;
58
+ private clearPendingAddedClassNames;
59
+ private clearPendingRemovedClassNames;
60
+ private getCleanupWindow;
61
+ private cancelRetainedClassRuleCleanup;
62
+ private clearRetainedClassRules;
63
+ private cancelPendingRemovedClassNames;
64
+ private cancelPendingAddedClassNames;
65
+ private cancelRetainedClassNames;
66
+ private schedulePendingRemovalFlush;
67
+ private queueRemovedClassNames;
68
+ private schedulePendingAdditionFlush;
69
+ private queueAddedClassNames;
70
+ private estimateRetainedClassRule;
71
+ private getRetainedClassRuleRawBytes;
72
+ private exceedsRetainedClassRuleHardLimits;
73
+ private scheduleRetainedClassRuleCleanup;
74
+ private retainRemovedClassRules;
75
+ private getRetainedClassRuleCleanupCandidates;
76
+ private removeRetainedClassRules;
77
+ private cleanupRetainedClassRules;
78
+ flushRetainedClassRules(): number;
79
+ private flushPendingRemovedClassNames;
80
+ private flushPendingAddedClassNames;
81
+ private handleMutationRecords;
82
+ ensureClassRules(...classNames: string[]): this;
83
+ deleteClassRules(...classNames: string[]): void;
84
+ private startMutationObserver;
85
+ private revealHostIfNeeded;
86
+ /**
87
+ * Observe the DOM for changes and update the running stylesheet. (browser only)
88
+ * @param options mutation observer options
89
+ * @returns this
90
+ */
91
+ observe(): this;
92
+ private failHydration;
93
+ private getHydrationManifestLayerRules;
94
+ private registerHydratedClassRule;
95
+ private getUtilityLayerByName;
96
+ private collectHydrationManifestVariableNames;
97
+ private collectHydrationManifestAnimationNames;
98
+ private nativeThemeLayerHasOnlyEmittedGlobalsVariables;
99
+ private getVariableRuleBuckets;
100
+ private isSyntheticColorSchemeDeclaration;
101
+ private getNativeThemeRuleBucketKey;
102
+ private hydrateHydrationManifestVariables;
103
+ private hydrateHydrationManifestAnimations;
104
+ private hydrateHydrationManifestLayer;
105
+ hydrate(nativeLayerRules: CSSRuleList): HydrateResult | undefined;
106
+ disconnect(): this | undefined;
107
+ refresh(manifest?: MasterCSSManifest): this;
108
+ destroy(): this;
109
+ }
110
+ //#endregion
111
+ export { CSSRuntimeCreateOptions, CSSRuntime as default };
@@ -0,0 +1,20 @@
1
+ import { MasterCSSEmittedGlobals } from "@master/css-engine";
2
+ import { MasterCSSManifest } from "@master/css-schema/manifest";
3
+ import { MasterCSSHydrationManifest } from "@master/css-schema/hydration-manifest";
4
+
5
+ //#region src/css-runtime.d.ts
6
+ type CSSRuntimeHostConstructor = new (...args: any[]) => HTMLElement;
7
+ type CSSRuntimeManifest = MasterCSSManifest | ((host: HTMLElement) => MasterCSSManifest);
8
+ type CSSRuntimeRoot = ShadowRoot | ((host: HTMLElement) => ShadowRoot | null | undefined);
9
+ type CSSRuntimeEmittedGlobals = MasterCSSEmittedGlobals | ((host: HTMLElement) => MasterCSSEmittedGlobals | undefined);
10
+ type CSSHydrationManifest = MasterCSSHydrationManifest | ((host: HTMLElement) => MasterCSSHydrationManifest | undefined);
11
+ interface CSSRuntimeOptions {
12
+ manifest: CSSRuntimeManifest;
13
+ root?: CSSRuntimeRoot;
14
+ emittedGlobals?: CSSRuntimeEmittedGlobals;
15
+ hydrationManifest?: CSSHydrationManifest;
16
+ }
17
+ type CSSRuntimeDecoratorOptions = CSSRuntimeOptions;
18
+ declare function cssRuntime(options: CSSRuntimeOptions): <T extends CSSRuntimeHostConstructor>(target: T) => T;
19
+ //#endregion
20
+ export { CSSRuntimeDecoratorOptions, CSSRuntimeOptions, cssRuntime as default };
@@ -0,0 +1,6 @@
1
+ import CSSRuntime from "../core.js";
2
+
3
+ //#region src/debuggers/class-count.d.ts
4
+ declare function debugRuntimeMutation(records: MutationRecord[], classCounts: Map<string, number>, cssRuntime: CSSRuntime): void;
5
+ //#endregion
6
+ export { debugRuntimeMutation as default };
@@ -0,0 +1,7 @@
1
+ import debugRuntimeMutation from "./class-count.js";
2
+ import { debugRuntimeCreated, debugRuntimeDestroyed, debugRuntimeDisconnected, debugRuntimeHydrated, debugRuntimeObserved, debugRuntimeRefreshed } from "./lifecycle.js";
3
+
4
+ //#region src/debuggers/index.d.ts
5
+ declare function startDebuggers(): void;
6
+ //#endregion
7
+ export { debugRuntimeCreated, debugRuntimeDestroyed, debugRuntimeDisconnected, debugRuntimeHydrated, debugRuntimeMutation, debugRuntimeObserved, debugRuntimeRefreshed, startDebuggers as default };
@@ -0,0 +1,13 @@
1
+ import { HydrateResult } from "../types/hydrate-result.js";
2
+ import CSSRuntime from "../core.js";
3
+ import { MasterCSSManifest } from "@master/css-schema/manifest";
4
+
5
+ //#region src/debuggers/lifecycle.d.ts
6
+ declare function debugRuntimeCreated(cssRuntime: CSSRuntime): void;
7
+ declare function debugRuntimeHydrated(cssRuntime: CSSRuntime, result: HydrateResult): void;
8
+ declare function debugRuntimeObserved(cssRuntime: CSSRuntime): void;
9
+ declare function debugRuntimeRefreshed(cssRuntime: CSSRuntime, manifest: MasterCSSManifest): void;
10
+ declare function debugRuntimeDisconnected(cssRuntime: CSSRuntime): void;
11
+ declare function debugRuntimeDestroyed(cssRuntime: CSSRuntime): void;
12
+ //#endregion
13
+ export { debugRuntimeCreated, debugRuntimeDestroyed, debugRuntimeDisconnected, debugRuntimeHydrated, debugRuntimeObserved, debugRuntimeRefreshed };
@@ -0,0 +1,19 @@
1
+ //#region src/debuggers/log.d.ts
2
+ type ConsoleMethod = 'log' | 'debug' | 'info' | 'warn' | 'error' | 'trace' | 'table' | 'group' | 'groupCollapsed' | 'groupEnd' | 'time' | 'timeEnd';
3
+ declare const createLogger: (type?: Exclude<ConsoleMethod, "table" | "group" | "groupCollapsed" | "groupEnd" | "time" | "timeEnd">) => (message: string, ...args: unknown[]) => void;
4
+ declare const loggers: {
5
+ info: (message: string, ...args: unknown[]) => void;
6
+ debug: (message: string, ...args: unknown[]) => void;
7
+ warn: (...data: any[]) => void;
8
+ error: (...data: any[]) => void;
9
+ trace: (...data: any[]) => void;
10
+ table: (tabularData?: any, properties?: string[]) => void;
11
+ group: (...data: any[]) => void;
12
+ groupCollapsed: (...data: any[]) => void;
13
+ groupEnd: () => void;
14
+ time: (label?: string) => void;
15
+ timeEnd: (label?: string) => void;
16
+ };
17
+ declare const log: ReturnType<typeof createLogger> & typeof loggers;
18
+ //#endregion
19
+ export { log as default };