cssints 0.0.0-stage → 0.2.0
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 +21 -0
- package/README.md +188 -2
- package/dist/author-types-C1AhsnrT.d.mts +80 -0
- package/dist/check.d.mts +22 -0
- package/dist/check.mjs +37 -0
- package/dist/color-BYIxVLlS.mjs +29 -0
- package/dist/color-C8OzjAeg.mjs +2 -0
- package/dist/contrast-DhK69Xak.mjs +83 -0
- package/dist/derived.d.mts +14 -0
- package/dist/derived.mjs +391 -0
- package/dist/errors-D4ZbcwRo.d.mts +32 -0
- package/dist/frame-BoBKjgBB.mjs +92 -0
- package/dist/frame.d.mts +72 -0
- package/dist/frame.mjs +2 -0
- package/dist/group-common-9zpBxfUF.d.mts +1 -0
- package/dist/group-types-9ttphdku.d.mts +55 -0
- package/dist/groups/compositing-2.d.mts +20 -0
- package/dist/groups/css-align-3.d.mts +29 -0
- package/dist/groups/css-anchor-position-1.d.mts +49 -0
- package/dist/groups/css-anchor-position-2.d.mts +50 -0
- package/dist/groups/css-animations-1.d.mts +28 -0
- package/dist/groups/css-animations-2.d.mts +29 -0
- package/dist/groups/css-backgrounds-3.d.mts +27 -0
- package/dist/groups/css-backgrounds-4.d.mts +29 -0
- package/dist/groups/css-borders-4.d.mts +95 -0
- package/dist/groups/css-box-4.d.mts +38 -0
- package/dist/groups/css-break-4.d.mts +23 -0
- package/dist/groups/css-cascade-5.d.mts +18 -0
- package/dist/groups/css-cascade-6.d.mts +18 -0
- package/dist/groups/css-color-4.d.mts +29 -0
- package/dist/groups/css-color-5.d.mts +32 -0
- package/dist/groups/css-color-6.d.mts +32 -0
- package/dist/groups/css-color-adjust-1.d.mts +20 -0
- package/dist/groups/css-color-hdr-1.d.mts +19 -0
- package/dist/groups/css-conditional-3.d.mts +17 -0
- package/dist/groups/css-conditional-4.d.mts +17 -0
- package/dist/groups/css-conditional-5.d.mts +22 -0
- package/dist/groups/css-contain-2.d.mts +19 -0
- package/dist/groups/css-content-3.d.mts +23 -0
- package/dist/groups/css-counter-styles-3.d.mts +16 -0
- package/dist/groups/css-display-4.d.mts +22 -0
- package/dist/groups/css-easing-2.d.mts +18 -0
- package/dist/groups/css-env-1.d.mts +16 -0
- package/dist/groups/css-flexbox-1.d.mts +24 -0
- package/dist/groups/css-fonts-4.d.mts +46 -0
- package/dist/groups/css-fonts-5.d.mts +44 -0
- package/dist/groups/css-forms-1.d.mts +19 -0
- package/dist/groups/css-gaps-1.d.mts +21 -0
- package/dist/groups/css-gcpm-3.d.mts +20 -0
- package/dist/groups/css-gcpm-4.d.mts +20 -0
- package/dist/groups/css-grid-2.d.mts +34 -0
- package/dist/groups/css-grid-3.d.mts +34 -0
- package/dist/groups/css-images-3.d.mts +25 -0
- package/dist/groups/css-images-4.d.mts +32 -0
- package/dist/groups/css-images-5.d.mts +33 -0
- package/dist/groups/css-inline-3.d.mts +28 -0
- package/dist/groups/css-lists-3.d.mts +26 -0
- package/dist/groups/css-logical-1.d.mts +35 -0
- package/dist/groups/css-masking-1.d.mts +37 -0
- package/dist/groups/css-multicol-2.d.mts +24 -0
- package/dist/groups/css-overflow-3.d.mts +28 -0
- package/dist/groups/css-overflow-4.d.mts +29 -0
- package/dist/groups/css-overflow-5.d.mts +31 -0
- package/dist/groups/css-overscroll-1.d.mts +22 -0
- package/dist/groups/css-page-3.d.mts +18 -0
- package/dist/groups/css-page-floats-3.d.mts +19 -0
- package/dist/groups/css-position-3.d.mts +29 -0
- package/dist/groups/css-position-4.d.mts +30 -0
- package/dist/groups/css-rhythm-1.d.mts +18 -0
- package/dist/groups/css-round-display-1.d.mts +16 -0
- package/dist/groups/css-ruby-1.d.mts +21 -0
- package/dist/groups/css-scroll-anchoring-1.d.mts +18 -0
- package/dist/groups/css-scroll-snap-1.d.mts +42 -0
- package/dist/groups/css-scroll-snap-2.d.mts +43 -0
- package/dist/groups/css-scrollbars-1.d.mts +19 -0
- package/dist/groups/css-shapes-1.d.mts +27 -0
- package/dist/groups/css-shapes-2.d.mts +27 -0
- package/dist/groups/css-size-adjust-1.d.mts +18 -0
- package/dist/groups/css-sizing-3.d.mts +34 -0
- package/dist/groups/css-sizing-4.d.mts +33 -0
- package/dist/groups/css-speech-1.d.mts +18 -0
- package/dist/groups/css-tables-3.d.mts +22 -0
- package/dist/groups/css-text-3.d.mts +36 -0
- package/dist/groups/css-text-4.d.mts +40 -0
- package/dist/groups/css-text-decor-3.d.mts +30 -0
- package/dist/groups/css-text-decor-4.d.mts +31 -0
- package/dist/groups/css-transforms-1.d.mts +31 -0
- package/dist/groups/css-transforms-2.d.mts +48 -0
- package/dist/groups/css-transitions-1.d.mts +22 -0
- package/dist/groups/css-transitions-2.d.mts +23 -0
- package/dist/groups/css-ui-4.d.mts +35 -0
- package/dist/groups/css-values-4.d.mts +38 -0
- package/dist/groups/css-values-5.d.mts +43 -0
- package/dist/groups/css-variables-2.d.mts +6 -0
- package/dist/groups/css-view-transitions-2.d.mts +20 -0
- package/dist/groups/css-viewport.d.mts +18 -0
- package/dist/groups/css-will-change-1.d.mts +18 -0
- package/dist/groups/css-writing-modes-4.d.mts +22 -0
- package/dist/groups/css2.d.mts +19 -0
- package/dist/groups/fill-stroke-3.d.mts +27 -0
- package/dist/groups/filter-effects-1.d.mts +32 -0
- package/dist/groups/filter-effects-2.d.mts +33 -0
- package/dist/groups/limited-availability.d.mts +2 -0
- package/dist/groups/mediaqueries-4.d.mts +16 -0
- package/dist/groups/mediaqueries-5.d.mts +16 -0
- package/dist/groups/motion-1.d.mts +24 -0
- package/dist/groups/newly-available.d.mts +631 -0
- package/dist/groups/not-discouraged.d.mts +727 -0
- package/dist/groups/scroll-animations-1.d.mts +30 -0
- package/dist/groups/selectors-4.d.mts +54 -0
- package/dist/groups/selectors-5.d.mts +54 -0
- package/dist/groups/widely-available.d.mts +616 -0
- package/dist/index.d.mts +48 -0
- package/dist/index.mjs +1269 -0
- package/dist/instrument-gCazujmb.mjs +1624 -0
- package/dist/lowered-D2KusPLp.mjs +28 -0
- package/dist/node-OJ_w_Usj.d.mts +233 -0
- package/dist/parent-vars.d.mts +13 -0
- package/dist/parent-vars.mjs +65 -0
- package/dist/plugin-types.d.mts +377 -0
- package/dist/plugin.d.mts +3 -0
- package/dist/plugin.mjs +30 -0
- package/dist/registry-CTumHB8p.mjs +73 -0
- package/dist/runtime-Dt4Tm0Q7.d.mts +19 -0
- package/dist/runtime.d.mts +18 -0
- package/dist/runtime.mjs +25 -0
- package/dist/scope-ZVhUxQH1.d.mts +2101 -0
- package/dist/sheet-BKsMTa0c.mjs +757 -0
- package/dist/surface.d.mts +228 -0
- package/dist/surface.mjs +101 -0
- package/dist/theme-BsP2E4LB.mjs +929 -0
- package/dist/theme-types-Bqv0Ggz_.d.mts +1808 -0
- package/dist/trace-otlp-CbKFDsn9.mjs +14 -0
- package/dist/tui-types.d.mts +181 -0
- package/dist/tui.d.mts +23 -0
- package/dist/tui.mjs +427 -0
- package/dist/types.d.mts +2 -0
- package/dist/vite.d.mts +134 -0
- package/dist/vite.mjs +977 -0
- package/docs/API.md +1193 -0
- package/package.json +85 -4
- package/skills/cssints/SKILL.md +203 -0
- package/skills/cssints/references/errors.md +86 -0
- package/skills/cssints/references/plugins.md +91 -0
- package/skills/cssints/references/tokens.md +91 -0
- package/skills/cssints-plugin/SKILL.md +177 -0
- package/skills/cssints-plugin/references/table.md +124 -0
- package/skills/cssints-plugin/references/testing.md +122 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { a as registry } from "./registry-CTumHB8p.mjs";
|
|
2
|
+
import { Result } from "effect";
|
|
3
|
+
import { browserslistToTargets, transform } from "lightningcss";
|
|
4
|
+
//#region src/lowered.ts
|
|
5
|
+
const first = (css) => /^[^{]*\{([^;}]*)/.exec(css)?.[1];
|
|
6
|
+
const lower = (prop, value, lacking, feature) => {
|
|
7
|
+
const code = Buffer.from(prop.startsWith("--") ? `:root{${prop}:${value}}` : `x{${prop}:${value}}`);
|
|
8
|
+
const out = first(transform({
|
|
9
|
+
filename: "x.css",
|
|
10
|
+
code,
|
|
11
|
+
minify: true,
|
|
12
|
+
targets: browserslistToTargets(lacking)
|
|
13
|
+
}).code.toString());
|
|
14
|
+
const holds = new RegExp(`(?<![\\w-])${feature.replace(/\(\)$/, "")}(?![\\w-])`);
|
|
15
|
+
return out !== void 0 && holds.test(`${prop}:${value}`) && !holds.test(out) ? out.slice(out.indexOf(":") + 1) : void 0;
|
|
16
|
+
};
|
|
17
|
+
const fallbackOf = (prop, value, w) => {
|
|
18
|
+
const key = `${prop}\0${value}\0${w.feature}\0${w.lacking.join()}`;
|
|
19
|
+
let hit = registry.lowered.get(key);
|
|
20
|
+
if (hit === void 0) {
|
|
21
|
+
hit = Result.getOrElse(Result.try(() => lower(prop, value, w.lacking, w.feature)), () => void 0) ?? false;
|
|
22
|
+
registry.lowered.set(key, hit);
|
|
23
|
+
}
|
|
24
|
+
return hit || void 0;
|
|
25
|
+
};
|
|
26
|
+
const loweredOf = (prop, value, w) => fallbackOf(prop, value, w) !== void 0;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { loweredOf as n, fallbackOf as t };
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { a as Kernel, i as GlobalRule, n as Conflict, o as Runtime, s as ThemeRule } from "./author-types-C1AhsnrT.mjs";
|
|
2
|
+
import { Warning } from "@cssints/css-grammar/support";
|
|
3
|
+
import { Context } from "effect";
|
|
4
|
+
import { TokenType } from "@cssints/css-grammar/token";
|
|
5
|
+
//#region src/registry.d.ts
|
|
6
|
+
interface Rule {
|
|
7
|
+
layer: string;
|
|
8
|
+
/** Sort key within the layer: the min-width of its conditions, then the places of its pseudo-classes. */
|
|
9
|
+
cond: number[];
|
|
10
|
+
/** The at-rule preludes around `css`, outermost first (`@media (width >= 40rem)`). */
|
|
11
|
+
wrap: string[];
|
|
12
|
+
prop: string;
|
|
13
|
+
/** The style rule: `.cls:hover{color:red}`. */
|
|
14
|
+
css: string;
|
|
15
|
+
/** The tokens (`--name`) its value reads. */
|
|
16
|
+
tokens?: string[];
|
|
17
|
+
}
|
|
18
|
+
/** What a plugin member leaves on a style node besides declarations: its name, and the runtime and conflicts it has. */
|
|
19
|
+
interface Plug {
|
|
20
|
+
name: string;
|
|
21
|
+
/** What errors call it (the scope that owns `name`), when that is not `name`. */
|
|
22
|
+
label?: string;
|
|
23
|
+
marker: string;
|
|
24
|
+
conflicts?: Conflict;
|
|
25
|
+
runtime?: Runtime;
|
|
26
|
+
}
|
|
27
|
+
/** A registered runtime, by plugin name: the files whose styles use it. */
|
|
28
|
+
interface RuntimeEntry {
|
|
29
|
+
runtime: Runtime;
|
|
30
|
+
users: Set<string>;
|
|
31
|
+
}
|
|
32
|
+
/** A registered kernel: the custom properties it declares, the markers printed for it, the files that use it. */
|
|
33
|
+
interface KernelEntry {
|
|
34
|
+
kernel: Kernel;
|
|
35
|
+
vars: string[];
|
|
36
|
+
markers: Set<string>;
|
|
37
|
+
users: Set<string>;
|
|
38
|
+
}
|
|
39
|
+
/** A support warning of a declaration in a kernel written as styles, weighed against the runtimes of a style (kernel.ts `addKernel`). */
|
|
40
|
+
interface KernelWarning {
|
|
41
|
+
prop: string;
|
|
42
|
+
/** the value as the sheet prints it: `--_x` is `--<scope>-x` */
|
|
43
|
+
value: string;
|
|
44
|
+
warning: Warning;
|
|
45
|
+
}
|
|
46
|
+
/** The call site being evaluated, set by `__at` before its expression runs. */
|
|
47
|
+
interface At {
|
|
48
|
+
file: string;
|
|
49
|
+
site: number;
|
|
50
|
+
offset: number;
|
|
51
|
+
}
|
|
52
|
+
/** A token's `@property` rule, by variable name (`--color-primary`). One entry per name across all modules. */
|
|
53
|
+
interface Property {
|
|
54
|
+
css: string;
|
|
55
|
+
/** Literals of its type, put in place of `var(--name)` when a value that uses it is checked (TOKEN_TYPES). */
|
|
56
|
+
probes: readonly string[];
|
|
57
|
+
/** Where it was declared: `file#site.n`, `file`, and the evaluation (`gen`) that declared it. */
|
|
58
|
+
by: string;
|
|
59
|
+
file: string;
|
|
60
|
+
gen: number;
|
|
61
|
+
}
|
|
62
|
+
/** What a token is worth, by variable name: its literal (an alias or a derived token: the flattened one), and what it stays live as. */
|
|
63
|
+
interface TokenDef {
|
|
64
|
+
kind: TokenType;
|
|
65
|
+
/** Whether the custom property inherits: only a token that does can be written on <html> by the runtime of derived tokens. */
|
|
66
|
+
inherit: boolean;
|
|
67
|
+
/** `color.bg` for a token of createTokens, else the variable. */
|
|
68
|
+
path: string;
|
|
69
|
+
value: string;
|
|
70
|
+
/** An alias or a derived token: its value with `var(--target)` for each reference, and the variables it refers to. */
|
|
71
|
+
template?: string;
|
|
72
|
+
refs?: string[];
|
|
73
|
+
/** `value` as LightningCSS lowers it for the targets that lack it: the initial value, and the default of a derived token. */
|
|
74
|
+
fallback?: string;
|
|
75
|
+
/** A derived token the runtime computes (derived-data.ts): its flattened literal, which a browser that parses it needs no runtime for. */
|
|
76
|
+
poly?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A rule of a token set or a theme, in layer _.k after the globals (sheet.ts). `key` orders them: the kind (0 the
|
|
80
|
+
* `:root` declarations of aliases, 1 themes under a condition, 2 themes under a selector), then the place in the source.
|
|
81
|
+
* `names` are the variables it sets or reads: a module that uses one of them has the rule in its sheet too (plugin.ts).
|
|
82
|
+
* `layer`, when set, sends the rule to a **top-level** declared layer of that name instead of `_.k`: a look must rank
|
|
83
|
+
* above the engine's `:root` fallbacks, and a nested layer ranks below the rules of its parent.
|
|
84
|
+
* `theme` is what a contrast check reads: the values the theme sets, by variable name, for the selector `label` (inside
|
|
85
|
+
* `@scope (scope)`, if it has one); `poly` those of them that the runtime of derived tokens computes, with their flattened literals.
|
|
86
|
+
*/
|
|
87
|
+
interface Themed {
|
|
88
|
+
file: string;
|
|
89
|
+
key: string;
|
|
90
|
+
css: string;
|
|
91
|
+
names: string[];
|
|
92
|
+
layer?: string;
|
|
93
|
+
theme?: {
|
|
94
|
+
label: string;
|
|
95
|
+
scope?: string;
|
|
96
|
+
values: Map<string, string>;
|
|
97
|
+
poly?: Map<string, string>;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** A global rule of a plugin member (`addGlobal`), by its content, with the files whose styles carry it. */
|
|
101
|
+
interface GlobalEntry {
|
|
102
|
+
global: GlobalRule;
|
|
103
|
+
users: Set<string>;
|
|
104
|
+
}
|
|
105
|
+
/** A statement `@layer a, b;` to declare: `before` prints it before the engine's `@layer _.k, …;`, so its layers rank below. */
|
|
106
|
+
interface LayersDecl {
|
|
107
|
+
names: readonly string[];
|
|
108
|
+
before?: boolean;
|
|
109
|
+
}
|
|
110
|
+
/** A declared statement `@layer a, b;` (`layers()`), by its names joined with `,`, with the files that declared it. */
|
|
111
|
+
interface LayerEntry {
|
|
112
|
+
names: string[];
|
|
113
|
+
before: boolean;
|
|
114
|
+
users: Set<string>;
|
|
115
|
+
}
|
|
116
|
+
/** A `css.check.contrast` call, checked once the module that made it has run, and again at the end of a build. */
|
|
117
|
+
interface Check {
|
|
118
|
+
at: At;
|
|
119
|
+
fg: string;
|
|
120
|
+
bg: string;
|
|
121
|
+
min: number;
|
|
122
|
+
gen: number;
|
|
123
|
+
}
|
|
124
|
+
interface RegistryState {
|
|
125
|
+
/** file -> site index -> replacement expression */
|
|
126
|
+
sites: Map<string, Map<number, string>>;
|
|
127
|
+
/** file -> site index -> the declarations of the style it produced: what a cn() with runtime arguments settles (macro.ts `groupOf`) */
|
|
128
|
+
nodes: Map<string, Map<number, Decl[]>>;
|
|
129
|
+
/** class -> rule; one entry per class across all modules */
|
|
130
|
+
rules: Map<string, Rule>;
|
|
131
|
+
/** `layer<TAB>css` -> a global rule: in the sheet of the modules that carry it, in layer _.k unless it names a layer (sheet.ts `addGlobal`) */
|
|
132
|
+
globals: Map<string, GlobalEntry>;
|
|
133
|
+
/** the declared top-level layers (sheet.ts `addLayers`) */
|
|
134
|
+
layers: Map<string, LayerEntry>;
|
|
135
|
+
/** key -> the kernels of the styles evaluated so far (sheet.ts `addKernel`): for collisions; the sheet reads the entries of a module */
|
|
136
|
+
kernels: Map<string, KernelEntry>;
|
|
137
|
+
/** plugin name -> its runtime and the files that use it (delivery.ts) */
|
|
138
|
+
runtimes: Map<string, RuntimeEntry>;
|
|
139
|
+
/** scope name -> the hash of its content (scope.ts `register`): a name is unique per process */
|
|
140
|
+
scopes: Map<string, string>;
|
|
141
|
+
/** what scope.ts needs of the eval-time library, set by macro.ts: `css` for a kernel written as styles (with `nest` and `vars`), `kernelOf` to check and print it under its class */
|
|
142
|
+
lib?: {
|
|
143
|
+
css: object;
|
|
144
|
+
kernelOf: (what: string, style: CssNode, cls: string) => {
|
|
145
|
+
css: string;
|
|
146
|
+
props: string[];
|
|
147
|
+
kernels?: Kernel[];
|
|
148
|
+
warnings: KernelWarning[];
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
/** the replacement of a site that holds a node of cssints/tui (tui.ts), set when that module loads */
|
|
152
|
+
tui?: (value: {
|
|
153
|
+
readonly __tui: unknown;
|
|
154
|
+
}) => string | undefined;
|
|
155
|
+
/** the tokens and themes of cssints/tui (tui.ts): a namespace of their own, never in a sheet (cssints-0s1z) */
|
|
156
|
+
terminal?: Pick<RegistryState, "properties" | "defs" | "themed">;
|
|
157
|
+
/** what the front of "cssints/plugin" calls (scope-engine.ts `engine`), set by macro.ts */
|
|
158
|
+
engine?: object;
|
|
159
|
+
/** the typed properties of scopes: checked by their own grammar when called, not by the engine */
|
|
160
|
+
userProps: Set<string>;
|
|
161
|
+
/** file -> the evaluation (`gen`) in which its first site ran: its kernels of older ones are forgotten (`__at`) */
|
|
162
|
+
seen: Map<string, number>;
|
|
163
|
+
/** name -> the `@property` rule of every token declared so far (token.ts) */
|
|
164
|
+
properties: Map<string, Property>;
|
|
165
|
+
/** name -> what each token is worth (token.ts, theme.ts): the contrast check and the theme rules read it */
|
|
166
|
+
defs: Map<string, TokenDef>;
|
|
167
|
+
/** `file#site.n` -> the rules of createTokens and createGlobalTheme calls */
|
|
168
|
+
themed: Map<string, Themed>;
|
|
169
|
+
/** `file#site` -> the contrast checks */
|
|
170
|
+
checks: Map<string, Check>;
|
|
171
|
+
/** the evaluation in progress; tokens of an older one that its file no longer declares are stale */
|
|
172
|
+
gen: number;
|
|
173
|
+
/** tokens created at the site being evaluated: two in one site get different private names */
|
|
174
|
+
tokens: number;
|
|
175
|
+
/** warnings not yet handed to Vite, each at the site that made it (`warn`) */
|
|
176
|
+
warnings: Warned[];
|
|
177
|
+
/** `file of the site \0 key` of the warnings said in this build; in dev, until that file is edited (`forgetWarnings`) */
|
|
178
|
+
warned: Set<string>;
|
|
179
|
+
/** `property value feature targets` -> what LightningCSS lowers it to, or false (lowered.ts) */
|
|
180
|
+
lowered: Map<string, string | false>;
|
|
181
|
+
/** the files the evaluation in progress read (`dependsOn`): dependencies of the module being evaluated (plugin.ts `depsOf`) */
|
|
182
|
+
files: Set<string>;
|
|
183
|
+
at?: At;
|
|
184
|
+
/** the site `tokens` is counting for: a call in a loop is one site that registers several tokens */
|
|
185
|
+
site?: string;
|
|
186
|
+
}
|
|
187
|
+
declare global {
|
|
188
|
+
var __cssints: RegistryState | undefined;
|
|
189
|
+
}
|
|
190
|
+
/** A warning and the site that made it, when there is one. */
|
|
191
|
+
interface Warned {
|
|
192
|
+
message: string;
|
|
193
|
+
at?: At | undefined;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/node.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* One condition of a style: an at-rule prelude (`@media (width >= 40rem)`), a pseudo-class (`:hover`), an attribute
|
|
199
|
+
* (`[aria-current="page"]`) or, with `ancestor`, a selector of a marked ancestor (`:where(._g:hover)`), or, with
|
|
200
|
+
* `nest` (kernels only), a selector around the class (`& > *`, `:root:has(&)`: `&` is the class); with `own`, its subject
|
|
201
|
+
* is still the element (`.x &`).
|
|
202
|
+
* `rank` orders the rules of a layer: the min-width of a media or container query in px, the place of a pseudo-class.
|
|
203
|
+
*/
|
|
204
|
+
interface Cond {
|
|
205
|
+
text: string;
|
|
206
|
+
rank: number;
|
|
207
|
+
ancestor?: true;
|
|
208
|
+
nest?: true;
|
|
209
|
+
own?: true;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* One declaration: property and value, under the conditions that wrap it (outermost first). `fallbacks` are the other
|
|
213
|
+
* values of a `firstThatWorks(...)`, best first: the rule prints them before `value`, which is the one wanted.
|
|
214
|
+
*/
|
|
215
|
+
type Decl = [prop: string, value: string, conds?: Cond[], fallbacks?: string[]];
|
|
216
|
+
/**
|
|
217
|
+
* What a css.* builder returns: its declarations, and next to them the fixed classes it prints (`markers`, each with
|
|
218
|
+
* the key of the kernel it belongs to), the kernels it needs, and the plugin members whose runtime and conflicts apply
|
|
219
|
+
* (`plugs`). `cn()` merges all three. `bare` are the markers of a merged style that came with no declaration of their
|
|
220
|
+
* own (`pretty()`, `frame()`): a condition around it would wrap nothing of theirs, so it is an error.
|
|
221
|
+
*/
|
|
222
|
+
interface CssNode {
|
|
223
|
+
__cssints: Decl[];
|
|
224
|
+
markers?: [marker: string, kernel: string][];
|
|
225
|
+
kernels?: Kernel[];
|
|
226
|
+
globals?: GlobalRule[];
|
|
227
|
+
themes?: ThemeRule[];
|
|
228
|
+
layers?: LayersDecl[];
|
|
229
|
+
plugs?: Plug[];
|
|
230
|
+
bare?: [marker: string, kernel: string][];
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
export { RegistryState as i, At as n, LayersDecl as r, CssNode as t };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/parent-vars.d.ts
|
|
2
|
+
interface Family {
|
|
3
|
+
/** The class every element of the family carries (`_f`). */
|
|
4
|
+
marker: string;
|
|
5
|
+
/** The custom property read from the nearest marked ancestor, and written on the element. */
|
|
6
|
+
read: string;
|
|
7
|
+
write: string;
|
|
8
|
+
/** A property that changes when a CSS condition (`:hover`, a media query) changes `read`: its transition re-runs us. */
|
|
9
|
+
watch?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: (add: Family[]) => void;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { _default as default };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region src/parent-vars.ts
|
|
2
|
+
const families = [];
|
|
3
|
+
let started = false;
|
|
4
|
+
let observer;
|
|
5
|
+
const update = (roots) => {
|
|
6
|
+
for (const f of families) {
|
|
7
|
+
const s = `.${f.marker}`;
|
|
8
|
+
const level = /* @__PURE__ */ new Map();
|
|
9
|
+
const rows = [];
|
|
10
|
+
for (const r of roots) for (const el of r.matches(s) ? [r, ...r.querySelectorAll(s)] : r.querySelectorAll(s)) {
|
|
11
|
+
const p = el.parentElement?.closest(s);
|
|
12
|
+
const l = level.has(p) ? level.get(p) + 1 : 0;
|
|
13
|
+
level.set(el, l);
|
|
14
|
+
(rows[l] ??= []).push([el, p]);
|
|
15
|
+
}
|
|
16
|
+
for (const row of rows) {
|
|
17
|
+
const v = new Map(row.map(([, p]) => [p, p && getComputedStyle(p).getPropertyValue(f.read)]));
|
|
18
|
+
for (const [el, p] of row) if (p) el.style.setProperty(f.write, v.get(p));
|
|
19
|
+
else el.style.removeProperty(f.write);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
observer?.takeRecords();
|
|
23
|
+
};
|
|
24
|
+
const top = (nodes) => {
|
|
25
|
+
const s = new Set(nodes);
|
|
26
|
+
return [...s].filter((n) => {
|
|
27
|
+
for (let a = n.parentNode; n.isConnected && a; a = a.parentNode) if (s.has(a)) return false;
|
|
28
|
+
return n.isConnected;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const start = () => {
|
|
32
|
+
const root = document.documentElement;
|
|
33
|
+
const p = document.createElement("div");
|
|
34
|
+
const c = document.createElement("i");
|
|
35
|
+
const s = document.createElement("style");
|
|
36
|
+
s.textContent = "@container style(--_q:1){i{--_h:1}}";
|
|
37
|
+
p.style.setProperty("--_q", "1");
|
|
38
|
+
p.append(c);
|
|
39
|
+
document.head.append(s);
|
|
40
|
+
root.append(p);
|
|
41
|
+
const supported = getComputedStyle(c).getPropertyValue("--_h");
|
|
42
|
+
p.remove();
|
|
43
|
+
s.remove();
|
|
44
|
+
if (supported) return;
|
|
45
|
+
root.setAttribute("data-cssints-poly", "");
|
|
46
|
+
observer = new MutationObserver((rs) => update(top(rs.flatMap((r) => r.type === "childList" ? [...r.addedNodes].filter((n) => n.nodeType === 1) : [r.target]))));
|
|
47
|
+
observer.observe(root, {
|
|
48
|
+
subtree: true,
|
|
49
|
+
childList: true,
|
|
50
|
+
attributes: true,
|
|
51
|
+
attributeFilter: ["class", "style"]
|
|
52
|
+
});
|
|
53
|
+
for (const type of ["transitionrun", "transitionend"]) document.addEventListener(type, (e) => families.some((f) => f.watch === e.propertyName) && update([e.target]));
|
|
54
|
+
};
|
|
55
|
+
var parent_vars_default = (add) => {
|
|
56
|
+
if (typeof document === "undefined") return;
|
|
57
|
+
families.push(...add);
|
|
58
|
+
if (!started) {
|
|
59
|
+
started = true;
|
|
60
|
+
start();
|
|
61
|
+
}
|
|
62
|
+
if (observer) update([document.documentElement]);
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { parent_vars_default as default };
|