@master/css-runtime 2.0.0-rc.7 → 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 +90 -8
- package/dist/class-tracker.d.ts +12 -0
- package/dist/core.d.ts +61 -14
- package/dist/css-runtime.d.ts +17 -0
- package/dist/debuggers/class-count.d.ts +1 -0
- package/dist/debuggers/index.d.ts +1 -0
- package/dist/debuggers/lifecycle.d.ts +1 -0
- package/dist/debuggers/log.d.ts +17 -0
- package/dist/default-manifest.json +1 -0
- package/dist/generated-rule.d.ts +26 -0
- package/dist/global.min.js +1 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.development.d.ts +1 -0
- package/dist/index.development.mjs +1316 -0
- package/dist/index.mjs +1183 -0
- package/dist/layer.d.ts +16 -0
- package/dist/native-declaration.d.ts +2 -0
- package/dist/register-global.d.ts +6 -0
- package/dist/theme-layer.d.ts +27 -0
- package/dist/types/hydrate-result.d.ts +5 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/utility-layer.d.ts +13 -0
- package/dist/utils/find-native-css-rule-index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/iife.bundle.js +0 -1
- package/dist/index.bundle.js +0 -1
- package/dist/index.bundle.mjs +0 -1
- package/dist/init-css-runtime.d.ts +0 -9
- package/dist/types/global.d.ts +0 -8
- /package/dist/{iife.d.ts → global.min.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</picture>
|
|
11
11
|
</a>
|
|
12
12
|
</p>
|
|
13
|
-
<p align="center">Run
|
|
13
|
+
<p align="center">Run Master CSS right in the browser</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,99 @@
|
|
|
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/
|
|
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
|
-
##
|
|
63
|
-
|
|
64
|
-
|
|
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="preload" as="fetch" type="application/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 fetches `default-manifest.json` next to the runtime script, starts automatically, and registers the document runtime as `globalThis.masterCSSRuntime`. 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
|
+
| `register()` | `this` | Registers this runtime in `CSSRuntime.instances`. |
|
|
114
|
+
| `unregister()` | `this` | Removes this runtime from `CSSRuntime.instances`. |
|
|
115
|
+
| `needsHydrationManifest()` | `boolean` | Returns `true` when an external hydration manifest should be loaded before observation. |
|
|
116
|
+
| `loadHydrationManifest()` | `Promise<this>` | Reads inline hydration data or fetches the external hydration manifest URL from `style#master-css`. |
|
|
117
|
+
| `setHydrationManifest(manifest?)` | `this` | Sets the hydration manifest used by progressive hydration. |
|
|
118
|
+
| `observe()` | `this` | Observes class attribute changes. |
|
|
119
|
+
| `disconnect()` | `this \| undefined` | Cancels observation. |
|
|
120
|
+
| `refresh(manifest?)` | `this` | Refreshes with a complete `MasterCSSManifest`. |
|
|
121
|
+
| `reset()` | `this` | Clears rules and styles. |
|
|
122
|
+
| `destroy()` | `this` | Removes this runtime from `CSSRuntime.instances`. |
|
|
123
|
+
|
|
124
|
+
### Progressive Hydration
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { CSSRuntime } from '@master/css-runtime'
|
|
128
|
+
import manifest from 'virtual:master-css-manifest'
|
|
129
|
+
import emittedGlobals from 'virtual:master-css-emitted-globals'
|
|
130
|
+
|
|
131
|
+
const cssRuntime = CSSRuntime.create({
|
|
132
|
+
manifest,
|
|
133
|
+
emittedGlobals,
|
|
134
|
+
})
|
|
135
|
+
if (cssRuntime.needsHydrationManifest()) {
|
|
136
|
+
await cssRuntime.loadHydrationManifest()
|
|
137
|
+
}
|
|
138
|
+
cssRuntime.observe()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`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.
|
|
142
|
+
|
|
143
|
+
## Related docs
|
|
144
|
+
|
|
145
|
+
- [General installation](https://rc.css.master.co/guide/installation)
|
|
146
|
+
- [Using CDNs](https://rc.css.master.co/guide/installation/cdn)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type ClassDeltaMap = Map<string, number>;
|
|
2
|
+
type ClassCountMap = Map<string, number>;
|
|
3
|
+
export default class RuntimeClassTracker {
|
|
4
|
+
private snapshots;
|
|
5
|
+
reset(): void;
|
|
6
|
+
collectConnected(root: Document | ShadowRoot, classCounts: ClassCountMap): Set<string>;
|
|
7
|
+
collectMutations(records: MutationRecord[]): ClassDeltaMap;
|
|
8
|
+
private snapshotElement;
|
|
9
|
+
private diffElement;
|
|
10
|
+
private removeElement;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
package/dist/core.d.ts
CHANGED
|
@@ -1,23 +1,70 @@
|
|
|
1
|
-
import { MasterCSS } from '@master/css';
|
|
2
|
-
import type {
|
|
3
|
-
import '
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { MasterCSS } from '@master/css-engine';
|
|
2
|
+
import type { MasterCSSManifest } from '@master/css-schema/manifest';
|
|
3
|
+
import type { MasterCSSEmittedGlobals } from '@master/css-engine';
|
|
4
|
+
import { type MasterCSSHydrationManifest } from '@master/css-schema/hydration-manifest';
|
|
5
|
+
import { HydrateResult } from './types';
|
|
6
|
+
import RuntimeUtilityLayer from './utility-layer';
|
|
7
|
+
import RuntimeThemeLayer from './theme-layer';
|
|
8
|
+
export interface CSSRuntimeCreateOptions {
|
|
9
|
+
manifest: MasterCSSManifest;
|
|
10
|
+
root?: Document | ShadowRoot;
|
|
11
|
+
emittedGlobals?: MasterCSSEmittedGlobals;
|
|
12
|
+
hydrationManifest?: MasterCSSHydrationManifest;
|
|
13
|
+
}
|
|
14
|
+
export default class CSSRuntime extends MasterCSS {
|
|
15
|
+
root: Document | ShadowRoot;
|
|
16
|
+
hydrationManifest?: MasterCSSHydrationManifest | undefined;
|
|
17
|
+
static instances: WeakMap<Document | ShadowRoot, CSSRuntime>;
|
|
7
18
|
readonly host: Element;
|
|
8
|
-
readonly observing = false;
|
|
9
19
|
readonly container: HTMLElement | ShadowRoot;
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
readonly baseLayer: RuntimeUtilityLayer;
|
|
21
|
+
readonly themeLayer: RuntimeThemeLayer;
|
|
22
|
+
readonly defaultsLayer: RuntimeUtilityLayer;
|
|
23
|
+
readonly componentsLayer: RuntimeUtilityLayer;
|
|
24
|
+
readonly utilitiesLayer: RuntimeUtilityLayer;
|
|
25
|
+
readonly classCounts: Map<string, number>;
|
|
26
|
+
private readonly classTracker;
|
|
27
|
+
private hydrationFailureReason?;
|
|
28
|
+
observer?: MutationObserver;
|
|
29
|
+
progressive: boolean;
|
|
30
|
+
observing: boolean;
|
|
31
|
+
static create(options: CSSRuntimeCreateOptions): CSSRuntime;
|
|
32
|
+
constructor(root: (Document | ShadowRoot) | undefined, manifest: MasterCSSManifest, emittedGlobals?: MasterCSSEmittedGlobals, hydrationManifest?: MasterCSSHydrationManifest | undefined);
|
|
33
|
+
register(): this;
|
|
34
|
+
unregister(): this;
|
|
35
|
+
setHydrationManifest(hydrationManifest?: MasterCSSHydrationManifest): this;
|
|
36
|
+
needsHydrationManifest(): boolean;
|
|
37
|
+
loadHydrationManifest(): Promise<this>;
|
|
38
|
+
private createRuntimeStyle;
|
|
39
|
+
private warnHydrationFallback;
|
|
40
|
+
private useRuntimeStyle;
|
|
41
|
+
private detectRuntimeStyle;
|
|
42
|
+
private collectConnectedClasses;
|
|
43
|
+
private hydrateRuntimeStyle;
|
|
44
|
+
private renderRuntimeStyle;
|
|
45
|
+
private handleMutationRecords;
|
|
46
|
+
private startMutationObserver;
|
|
47
|
+
private revealHostIfNeeded;
|
|
12
48
|
/**
|
|
13
49
|
* Observe the DOM for changes and update the running stylesheet. (browser only)
|
|
14
50
|
* @param options mutation observer options
|
|
15
51
|
* @returns this
|
|
16
52
|
*/
|
|
17
|
-
observe(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
53
|
+
observe(): this;
|
|
54
|
+
private failHydration;
|
|
55
|
+
private getHydrationManifestLayerRules;
|
|
56
|
+
private registerHydratedClassRule;
|
|
57
|
+
private getUtilityLayerByName;
|
|
58
|
+
private collectHydrationManifestVariableNames;
|
|
59
|
+
private collectHydrationManifestAnimationNames;
|
|
60
|
+
private nativeThemeLayerHasOnlyEmittedGlobalsVariables;
|
|
61
|
+
private getVariableRuleBuckets;
|
|
62
|
+
private getNativeThemeRuleBucketKey;
|
|
63
|
+
private hydrateHydrationManifestVariables;
|
|
64
|
+
private hydrateHydrationManifestAnimations;
|
|
65
|
+
private hydrateHydrationManifestLayer;
|
|
66
|
+
hydrate(nativeLayerRules: CSSRuleList): HydrateResult | undefined;
|
|
67
|
+
disconnect(): this | undefined;
|
|
68
|
+
refresh(manifest?: MasterCSSManifest): this;
|
|
21
69
|
destroy(): this;
|
|
22
70
|
}
|
|
23
|
-
export declare const cssRuntimes: CSSRuntime[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { MasterCSSManifest } from '@master/css-schema/manifest';
|
|
2
|
+
import type { MasterCSSEmittedGlobals } from '@master/css-engine';
|
|
3
|
+
import type { MasterCSSHydrationManifest } from '@master/css-schema/hydration-manifest';
|
|
4
|
+
type CSSRuntimeHostConstructor = new (...args: any[]) => HTMLElement;
|
|
5
|
+
type CSSRuntimeManifest = MasterCSSManifest | ((host: HTMLElement) => MasterCSSManifest);
|
|
6
|
+
type CSSRuntimeRoot = ShadowRoot | ((host: HTMLElement) => ShadowRoot | null | undefined);
|
|
7
|
+
type CSSRuntimeEmittedGlobals = MasterCSSEmittedGlobals | ((host: HTMLElement) => MasterCSSEmittedGlobals | undefined);
|
|
8
|
+
type CSSHydrationManifest = MasterCSSHydrationManifest | ((host: HTMLElement) => MasterCSSHydrationManifest | undefined);
|
|
9
|
+
export interface CSSRuntimeOptions {
|
|
10
|
+
manifest: CSSRuntimeManifest;
|
|
11
|
+
root?: CSSRuntimeRoot;
|
|
12
|
+
emittedGlobals?: CSSRuntimeEmittedGlobals;
|
|
13
|
+
hydrationManifest?: CSSHydrationManifest;
|
|
14
|
+
}
|
|
15
|
+
export type CSSRuntimeDecoratorOptions = CSSRuntimeOptions;
|
|
16
|
+
export default function cssRuntime(options: CSSRuntimeOptions): <T extends CSSRuntimeHostConstructor>(target: T) => T;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function registerClassCountDebugger(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function startDebuggers(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function registerLifecycleDebugger(): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type ConsoleMethod = 'log' | 'debug' | 'info' | 'warn' | 'error' | 'trace' | 'table' | 'group' | 'groupCollapsed' | 'groupEnd' | 'time' | 'timeEnd';
|
|
2
|
+
declare const createLogger: (type?: Exclude<ConsoleMethod, "table" | "group" | "groupCollapsed" | "groupEnd" | "time" | "timeEnd">) => (message: string, ...args: unknown[]) => void;
|
|
3
|
+
declare const loggers: {
|
|
4
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
5
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
6
|
+
warn: (...data: any[]) => void;
|
|
7
|
+
error: (...data: any[]) => void;
|
|
8
|
+
trace: (...data: any[]) => void;
|
|
9
|
+
table: (tabularData?: any, properties?: string[]) => void;
|
|
10
|
+
group: (...data: any[]) => void;
|
|
11
|
+
groupCollapsed: (...data: any[]) => void;
|
|
12
|
+
groupEnd: () => void;
|
|
13
|
+
time: (label?: string) => void;
|
|
14
|
+
timeEnd: (label?: string) => void;
|
|
15
|
+
};
|
|
16
|
+
declare const log: ReturnType<typeof createLogger> & typeof loggers;
|
|
17
|
+
export default log;
|