@homepages/concrete 1.0.3 → 3.0.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/CHANGELOG.md +131 -0
- package/codemods/framework-namespace.mjs +107 -0
- package/codemods/manifest.json +17 -0
- package/codemods/theme-collapse.mjs +394 -0
- package/codemods/unlayer-author-css.mjs +194 -0
- package/dist/artifact/playground/client/assets/index-B3eNADCe.js +1107 -0
- package/dist/artifact/playground/client/index.html +1 -1
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
- package/dist/artifact/playground/host.mjs +21 -21
- package/dist/base.css +61 -31
- package/dist/cli/build/static.js +1 -1
- package/dist/cli/check/render/class-conflicts.js +1 -1
- package/dist/cli/dev/islands.js +2 -2
- package/dist/cli/dev/server.js +6 -2
- package/dist/cli/dev/vite.js +42 -22
- package/dist/css/compile.js +26 -4
- package/dist/css/rules.js +72 -1
- package/dist/eslint/authoring.js +2 -0
- package/dist/eslint/rules/island-ids.js +39 -0
- package/dist/fixtures/media-plugin.js +32 -17
- package/dist/fixtures/media.js +4 -2
- package/dist/fixtures/property.js +12 -2
- package/dist/fixtures/resolve.js +58 -5
- package/dist/fixtures/rows.js +6 -1
- package/dist/fixtures.d.ts +57 -12
- package/dist/fixtures.js +7 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/islands/island-id.js +8 -0
- package/dist/islands/marker.d.ts +14 -4
- package/dist/islands/marker.js +18 -6
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/island-runtime/dist/index.js +4 -2
- package/dist/packages/internal/island-runtime/dist/island-id-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/use-island-id.d.ts +24 -0
- package/dist/packages/internal/island-runtime/dist/use-island-id.js +44 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +44 -2
- package/dist/primitives/FrameShell.d.ts +1 -1
- package/dist/primitives/FrameShell.js +1 -1
- package/dist/primitives/Image.d.ts +1 -1
- package/dist/primitives/Image.js +3 -3
- package/dist/primitives/Section.d.ts +3 -3
- package/dist/primitives/Section.js +4 -4
- package/dist/primitives/Tour.d.ts +1 -1
- package/dist/primitives/Tour.js +3 -3
- package/dist/primitives/Video.d.ts +1 -1
- package/dist/primitives/Video.js +3 -3
- package/dist/rules/registry.js +19 -0
- package/dist/styles.css +4 -3
- package/dist/template/logic-shim.d.ts +2 -1
- package/dist/template/logic-shim.js +2 -1
- package/guide/reference/cli/INDEX.md +2 -2
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +1 -1
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +1 -1
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +4 -1
- package/package.json +1 -1
- package/dist/artifact/playground/client/assets/index-Da8V3M7E.js +0 -1101
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// 2.0.0 — author CSS is no longer layered.
|
|
2
|
+
//
|
|
3
|
+
// `base.css` used to declare `@layer theme, base, components, sections, template,
|
|
4
|
+
// utilities`, and a workspace wrapped its own rules in `sections.<name>` / `template` to
|
|
5
|
+
// sit in that order. Those two layers ranked BELOW `utilities`, so a declaration in one
|
|
6
|
+
// lost to any utility setting the same property on the same element, whatever its
|
|
7
|
+
// selector's specificity. `base.css` no longer declares them, which flips the trap
|
|
8
|
+
// rather than closing it: an undeclared layer is sorted AFTER every declared one, so a
|
|
9
|
+
// leftover wrapper would make the same rule start winning instead. Neither ordering is
|
|
10
|
+
// something an author asked for, so this codemod removes the wrappers and `check`
|
|
11
|
+
// refuses the names from here on.
|
|
12
|
+
//
|
|
13
|
+
// What it does, per `.css` file in the workspace:
|
|
14
|
+
// - unwraps `@layer sections.<name> { … }` and `@layer template { … }`, de-indenting
|
|
15
|
+
// - deletes `@layer sections.a, sections.b;` ordering statements
|
|
16
|
+
// - rewrites `@import "pkg/x.css" layer(sections.<name>)` to `layer(components)`,
|
|
17
|
+
// which still demotes a third-party sheet below your own now-unlayered rules
|
|
18
|
+
//
|
|
19
|
+
// What it does NOT do: judge the cascade. Where a rule of yours and a utility on the
|
|
20
|
+
// same element set the same property, your rule now wins where the utility used to.
|
|
21
|
+
// That is the point of the change, and a handful of those flips are ones you want to
|
|
22
|
+
// look at — a utility applied conditionally (`className={hidden ? "hidden" : ""}`) that
|
|
23
|
+
// was counting on outranking your stylesheet is the shape to check first.
|
|
24
|
+
|
|
25
|
+
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
26
|
+
import { join, relative } from "node:path";
|
|
27
|
+
|
|
28
|
+
/** The layer names the old build owned. A workspace may not declare either any more. */
|
|
29
|
+
const RETIRED = new Set(["sections", "template"]);
|
|
30
|
+
|
|
31
|
+
const SKIP_DIRS = new Set(["node_modules", ".concrete", ".git", "dist", "build"]);
|
|
32
|
+
|
|
33
|
+
/** Every `.css` file under `root`, absolute, skipping build output and dependencies. */
|
|
34
|
+
async function cssFiles(root) {
|
|
35
|
+
const found = [];
|
|
36
|
+
async function walk(dir) {
|
|
37
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
38
|
+
if (entry.isDirectory()) {
|
|
39
|
+
if (!SKIP_DIRS.has(entry.name)) await walk(join(dir, entry.name));
|
|
40
|
+
} else if (entry.name.endsWith(".css")) {
|
|
41
|
+
found.push(join(dir, entry.name));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
await walk(root);
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `css` with every comment and string literal blanked to spaces, newlines kept, so
|
|
51
|
+
* indices still line up with the original. Searching happens here; edits apply to the
|
|
52
|
+
* original — which is how `@layer sections.<name>` written in a comment stays prose.
|
|
53
|
+
*/
|
|
54
|
+
function masked(css) {
|
|
55
|
+
const out = [...css];
|
|
56
|
+
const blank = (from, to) => {
|
|
57
|
+
for (let k = from; k < Math.min(to, css.length); k++) if (out[k] !== "\n") out[k] = " ";
|
|
58
|
+
};
|
|
59
|
+
for (let i = 0; i < css.length; ) {
|
|
60
|
+
if (css[i] === "/" && css[i + 1] === "*") {
|
|
61
|
+
const end = css.indexOf("*/", i + 2);
|
|
62
|
+
const stop = end === -1 ? css.length : end + 2;
|
|
63
|
+
blank(i, stop);
|
|
64
|
+
i = stop;
|
|
65
|
+
} else if (css[i] === '"' || css[i] === "'") {
|
|
66
|
+
const quote = css[i];
|
|
67
|
+
let k = i + 1;
|
|
68
|
+
while (k < css.length && css[k] !== quote) k += css[k] === "\\" ? 2 : 1;
|
|
69
|
+
blank(i, k + 1);
|
|
70
|
+
i = k + 1;
|
|
71
|
+
} else {
|
|
72
|
+
i += 1;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out.join("");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `sections.hero` → `sections`; the root segment is what the order is declared on. */
|
|
79
|
+
const rootOf = (name) => name.trim().split(".")[0].trim();
|
|
80
|
+
|
|
81
|
+
/** Index just past the `}` matching the `{` at `open`, or -1 if the file is unbalanced. */
|
|
82
|
+
function matchBrace(scan, open) {
|
|
83
|
+
let depth = 0;
|
|
84
|
+
for (let i = open; i < scan.length; i++) {
|
|
85
|
+
if (scan[i] === "{") depth += 1;
|
|
86
|
+
else if (scan[i] === "}" && --depth === 0) return i;
|
|
87
|
+
}
|
|
88
|
+
return -1;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Start of the line holding `at`, when only whitespace precedes it on that line. */
|
|
92
|
+
function lineStart(css, at) {
|
|
93
|
+
const bol = css.lastIndexOf("\n", at - 1) + 1;
|
|
94
|
+
return css.slice(bol, at).trim() === "" ? bol : at;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** End of the line holding `at`, when only whitespace follows it on that line. */
|
|
98
|
+
function lineEnd(css, at) {
|
|
99
|
+
const eol = css.indexOf("\n", at);
|
|
100
|
+
if (eol === -1) return css.length;
|
|
101
|
+
return css.slice(at, eol).trim() === "" ? eol + 1 : at;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A layer block's body, stripped of the one indent level the wrapper added. */
|
|
105
|
+
function dedent(body) {
|
|
106
|
+
const lines = body.split("\n");
|
|
107
|
+
while (lines.length > 0 && lines[0].trim() === "") lines.shift();
|
|
108
|
+
while (lines.length > 0 && lines[lines.length - 1].trim() === "") lines.pop();
|
|
109
|
+
const indents = lines.filter((l) => l.trim() !== "").map((l) => /^[ \t]*/.exec(l)[0].length);
|
|
110
|
+
const strip = indents.length === 0 ? 0 : Math.min(...indents);
|
|
111
|
+
return lines.map((l) => (l.trim() === "" ? "" : l.slice(strip))).join("\n");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* One retired-layer edit, or null when the file holds none left.
|
|
116
|
+
*
|
|
117
|
+
* Exactly one per call so the caller can re-scan between edits: every edit moves the
|
|
118
|
+
* offsets after it, and a nested wrapper would be read against a stale index otherwise.
|
|
119
|
+
*/
|
|
120
|
+
function nextEdit(css) {
|
|
121
|
+
const scan = masked(css);
|
|
122
|
+
|
|
123
|
+
// `@import … layer(sections.<name>)` — the third-party demotion, re-pointed.
|
|
124
|
+
for (const m of scan.matchAll(/\blayer\(\s*([^)]*?)\s*\)/gi)) {
|
|
125
|
+
if (!RETIRED.has(rootOf(m[1]))) continue;
|
|
126
|
+
return { start: m.index, end: m.index + m[0].length, text: "layer(components)" };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (const m of scan.matchAll(/@layer\b/gi)) {
|
|
130
|
+
const at = m.index;
|
|
131
|
+
let i = at + m[0].length;
|
|
132
|
+
while (i < scan.length && scan[i] !== "{" && scan[i] !== ";") i += 1;
|
|
133
|
+
if (i >= scan.length) continue;
|
|
134
|
+
const names = css
|
|
135
|
+
.slice(at + m[0].length, i)
|
|
136
|
+
.split(",")
|
|
137
|
+
.map(rootOf)
|
|
138
|
+
.filter((n) => n !== "");
|
|
139
|
+
if (!names.some((n) => RETIRED.has(n))) continue;
|
|
140
|
+
|
|
141
|
+
// A statement: `@layer a, b;`. Whole thing goes, with its line.
|
|
142
|
+
if (scan[i] === ";") {
|
|
143
|
+
if (!names.every((n) => RETIRED.has(n))) {
|
|
144
|
+
return { mixed: names.filter((n) => !RETIRED.has(n)) };
|
|
145
|
+
}
|
|
146
|
+
return { start: lineStart(css, at), end: lineEnd(css, i + 1), text: "" };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// A block: `@layer sections.hero { … }`. Wrapper goes, body stays, de-indented.
|
|
150
|
+
const close = matchBrace(scan, i);
|
|
151
|
+
if (close === -1) return { unbalanced: names[0] };
|
|
152
|
+
return {
|
|
153
|
+
start: lineStart(css, at),
|
|
154
|
+
end: lineEnd(css, close + 1),
|
|
155
|
+
text: `${dedent(css.slice(i + 1, close))}\n`,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Applies every retired-layer edit to one file's text. */
|
|
162
|
+
function unlayer(css) {
|
|
163
|
+
let out = css;
|
|
164
|
+
for (let pass = 0; pass < 500; pass += 1) {
|
|
165
|
+
const edit = nextEdit(out);
|
|
166
|
+
if (edit === null) return { css: out };
|
|
167
|
+
if (edit.mixed !== undefined) {
|
|
168
|
+
return { reason: `an @layer statement names both retired and live layers (${edit.mixed.join(", ")}); split it by hand` };
|
|
169
|
+
}
|
|
170
|
+
if (edit.unbalanced !== undefined) {
|
|
171
|
+
return { reason: `@layer ${edit.unbalanced} is never closed; the file's braces are unbalanced` };
|
|
172
|
+
}
|
|
173
|
+
out = out.slice(0, edit.start) + edit.text + out.slice(edit.end);
|
|
174
|
+
}
|
|
175
|
+
return { reason: "more than 500 retired-layer edits in one file, which is not a shape this codemod expects" };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** @param {string} root @returns {Promise<{rewritten: string[], notRewritten: {file: string, reason: string}[]}>} */
|
|
179
|
+
export default async function unlayerAuthorCss(root) {
|
|
180
|
+
const rewritten = [];
|
|
181
|
+
const notRewritten = [];
|
|
182
|
+
for (const file of await cssFiles(root)) {
|
|
183
|
+
const before = await readFile(file, "utf8");
|
|
184
|
+
const name = relative(root, file).split("\\").join("/");
|
|
185
|
+
const result = unlayer(before);
|
|
186
|
+
if (result.reason !== undefined) {
|
|
187
|
+
notRewritten.push({ file: name, reason: result.reason });
|
|
188
|
+
} else if (result.css !== before) {
|
|
189
|
+
await writeFile(file, result.css);
|
|
190
|
+
rewritten.push(name);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return { rewritten, notRewritten };
|
|
194
|
+
}
|