actual-css 0.18.0 → 0.19.1
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 +54 -0
- package/README.md +7 -5
- package/components.json +6 -2
- package/dist/actual.full.css +272 -57
- package/dist/actual.full.js +2 -2
- package/dist/actual.full.min.css +1 -1
- package/docs/design-notes/enhancement-contract.md +20 -11
- package/docs/design-notes/motion-cost.md +62 -0
- package/docs/design-notes/tokens.md +4 -0
- package/docs/navigation.json +3 -0
- package/docs/pages/components/aura.md +3 -0
- package/docs/pages/components/mark-sweep.md +42 -0
- package/docs/pages/components/rating.md +53 -22
- package/docs/pages/components/reveal.md +54 -0
- package/docs/pages/components/shimmer.md +3 -2
- package/docs/pages/enhancements/in-view.md +109 -0
- package/docs/pages/enhancements/overview.md +3 -2
- package/docs/pages/enhancements/scrollspy.md +5 -5
- package/docs/pages/examples/overview.md +5 -2
- package/docs/pages/forms/date-picker.md +3 -2
- package/docs/pages/forms/switch.md +25 -16
- package/docs/pages/foundations/tokens.md +37 -15
- package/docs/pages/foundations/typography.md +8 -2
- package/docs/pages/guides/introduction.md +1 -1
- package/docs/pages/guides/modular-import.md +20 -4
- package/docs/pages/guides/progressive-enhancement.md +2 -1
- package/docs/pages/guides/upgrading.md +1 -1
- package/docs/pages/patterns/code-block.md +1 -1
- package/docs/pages/patterns/empty-state.md +3 -3
- package/docs/pages/patterns/exclusive-accordion.md +3 -2
- package/docs/pages/patterns/hierarchical-nav.md +5 -4
- package/docs/pages/patterns/icon-input.md +1 -1
- package/docs/pages/patterns/icon-slot.md +4 -4
- package/docs/pages/patterns/intent-nesting.md +2 -3
- package/docs/pages/patterns/navigation-list.md +7 -4
- package/docs/pages/patterns/stat.md +3 -3
- package/docs/pages/patterns/structured-lists.md +1 -2
- package/llms.txt +2 -1
- package/package.json +3 -1
- package/reserved-classes.json +4 -0
- package/src/cli/actual-css.js +3 -1
- package/src/css/components/navbar.css +13 -5
- package/src/css/components/rating.css +23 -2
- package/src/css/components/scrollspy.css +4 -2
- package/src/css/core/base.css +16 -0
- package/src/css/core/focus.css +13 -12
- package/src/css/core/reset.css +10 -0
- package/src/css/core/theme.css +15 -0
- package/src/css/core/tokens.css +4 -10
- package/src/css/effects/aura.css +5 -0
- package/src/css/effects/index.css +2 -0
- package/src/css/effects/mark-sweep.css +64 -0
- package/src/css/effects/reveal.css +66 -0
- package/src/css/effects/shimmer.css +28 -10
- package/src/css/forms/choice.css +0 -7
- package/src/css/forms/switch.css +9 -9
- package/src/js/full.js +1 -0
- package/src/js/in-view.js +152 -0
- package/src/js/scrollspy.js +81 -2
- package/src/js/selectors.js +3 -0
- package/src/tooling/css-bundle.js +153 -6
- package/src/tooling/design-tokens.js +2 -0
- package/tokens.json +2 -0
package/src/js/scrollspy.js
CHANGED
|
@@ -11,9 +11,13 @@
|
|
|
11
11
|
* share the viewport — and guesses wrong for sections shorter than the band.
|
|
12
12
|
*
|
|
13
13
|
* activation line = root top + offset (default 20% of the root's height)
|
|
14
|
+
* near scroll end = line advances to the root bottom over the last viewport
|
|
14
15
|
* active section = last section whose top <= activation line
|
|
15
16
|
* scrolled to end = last section, whatever the line says
|
|
16
17
|
* above the first = no active section
|
|
18
|
+
* followed link = its section, until the next scroll input
|
|
19
|
+
* (wheel, touch, key, pointer); the line then starts
|
|
20
|
+
* between that heading and the next and fades back
|
|
17
21
|
*
|
|
18
22
|
* Optional root: data-scrollspy-root="#scroll-container" measures against a
|
|
19
23
|
* scroll container instead of the viewport.
|
|
@@ -106,6 +110,10 @@ function setupNav(nav) {
|
|
|
106
110
|
let sections = [];
|
|
107
111
|
let frame = 0;
|
|
108
112
|
let current;
|
|
113
|
+
// A followed link bends the activation line to sit between its heading and
|
|
114
|
+
// the next: { section, held, scrollTop, remaining, floor, delta }. Held until
|
|
115
|
+
// the next scroll input, then faded; floor is where the upward fade ends.
|
|
116
|
+
let anchor = null;
|
|
109
117
|
|
|
110
118
|
function activate(section) {
|
|
111
119
|
if (section === current) return;
|
|
@@ -126,15 +134,55 @@ function setupNav(nav) {
|
|
|
126
134
|
|
|
127
135
|
const root = rootFor(nav);
|
|
128
136
|
const { top, height, scrollTop, scrollHeight } = measureRoot(nav, root);
|
|
137
|
+
const offset = activationOffset(nav, height);
|
|
138
|
+
// A fixed line followed by an end-of-scroll jump can skip whole sections
|
|
139
|
+
// on a tall viewport. Advance continuously through the final viewport of
|
|
140
|
+
// scroll travel so each intervening heading can become current first.
|
|
141
|
+
const remaining = scrollHeight - height - scrollTop;
|
|
142
|
+
const progress = height > 0 ? Math.max(0, Math.min(1, 1 - remaining / height)) : 0;
|
|
143
|
+
let line = top + offset + Math.max(0, height - offset) * progress;
|
|
144
|
+
|
|
145
|
+
// A followed link names its section outright. Near the end of the page
|
|
146
|
+
// the browser cannot scroll that heading up to the line, so geometry
|
|
147
|
+
// alone would keep a later section. While held (through a smooth scroll
|
|
148
|
+
// on the way there), the bend is recomputed at each position.
|
|
149
|
+
if (anchor?.held) {
|
|
150
|
+
const index = sections.findIndex(({ section }) => section === anchor.section);
|
|
151
|
+
const next = sections[index + 1]?.section;
|
|
152
|
+
const low = anchor.section.getBoundingClientRect().top;
|
|
153
|
+
const high = next ? next.getBoundingClientRect().top - 1 : Infinity;
|
|
154
|
+
Object.assign(anchor, {
|
|
155
|
+
scrollTop,
|
|
156
|
+
remaining,
|
|
157
|
+
floor: Math.max(0, scrollTop - height),
|
|
158
|
+
delta: Math.min(Math.max(line, low), high) - line,
|
|
159
|
+
});
|
|
160
|
+
line += anchor.delta;
|
|
161
|
+
} else if (anchor) {
|
|
162
|
+
// Released, the bend fades over the scroll travel left in each
|
|
163
|
+
// direction: down to the end of the content, up to one viewport above
|
|
164
|
+
// the release. Scrolling on then walks the neighbouring sections in
|
|
165
|
+
// order instead of jumping to whatever the unbent line picks there.
|
|
166
|
+
// Re-based on every measure, so it only ever shrinks: coming back to the
|
|
167
|
+
// release position does not bend the line again.
|
|
168
|
+
const travel = scrollTop - anchor.scrollTop;
|
|
169
|
+
const span = travel > 0 ? anchor.remaining : anchor.scrollTop - anchor.floor;
|
|
170
|
+
const delta = span > 0 ? anchor.delta * Math.max(0, 1 - Math.abs(travel) / span) : 0;
|
|
171
|
+
// Negated so NaN drops too: a pin released before its first measure.
|
|
172
|
+
if (!(Math.abs(delta) >= 0.5)) anchor = null;
|
|
173
|
+
else {
|
|
174
|
+
line += delta;
|
|
175
|
+
anchor = { ...anchor, scrollTop, remaining, delta };
|
|
176
|
+
}
|
|
177
|
+
}
|
|
129
178
|
|
|
130
179
|
// Scrolled to the end: the last section wins even when its top never
|
|
131
180
|
// crosses the line. This is the case IntersectionObserver cannot express.
|
|
132
|
-
if (scrollHeight > height &&
|
|
181
|
+
if (!anchor && scrollHeight > height && remaining <= 1) {
|
|
133
182
|
activate(sections.at(-1).section);
|
|
134
183
|
return;
|
|
135
184
|
}
|
|
136
185
|
|
|
137
|
-
const line = top + activationOffset(nav, height);
|
|
138
186
|
let active = null;
|
|
139
187
|
for (const { section } of sections) {
|
|
140
188
|
if (section.getBoundingClientRect().top <= line) active = section;
|
|
@@ -151,9 +199,17 @@ function setupNav(nav) {
|
|
|
151
199
|
function rebuild() {
|
|
152
200
|
sections = sectionsFor(nav);
|
|
153
201
|
current = undefined;
|
|
202
|
+
anchor = null;
|
|
154
203
|
measure();
|
|
155
204
|
}
|
|
156
205
|
|
|
206
|
+
function pin(link) {
|
|
207
|
+
const entry = sections.find((candidate) => candidate.link === link);
|
|
208
|
+
if (!entry) return;
|
|
209
|
+
anchor = { section: entry.section, held: true };
|
|
210
|
+
schedule();
|
|
211
|
+
}
|
|
212
|
+
|
|
157
213
|
// The scroll root is resolved once when the enhancement connects, and the
|
|
158
214
|
// scroll listener stays on it. Changing data-scrollspy-root or replacing its
|
|
159
215
|
// target is outside the connection contract; recreate the enhancement with
|
|
@@ -168,6 +224,29 @@ function setupNav(nav) {
|
|
|
168
224
|
signal: controller.signal,
|
|
169
225
|
});
|
|
170
226
|
|
|
227
|
+
const doc = nav.ownerDocument;
|
|
228
|
+
nav.addEventListener("click", (event) => pin(event.target.closest?.("a[href^='#']")), {
|
|
229
|
+
signal: controller.signal,
|
|
230
|
+
});
|
|
231
|
+
// Another in-page link, or history navigation, to one of the sections.
|
|
232
|
+
doc.defaultView?.addEventListener(
|
|
233
|
+
"hashchange",
|
|
234
|
+
() => pin(sections.find(({ link }) => link.hash === doc.location.hash)?.link),
|
|
235
|
+
{ signal: controller.signal },
|
|
236
|
+
);
|
|
237
|
+
// Scroll input, not the scroll event: the navigation itself scrolls. Capture
|
|
238
|
+
// runs before the click that may pin again (pointerdown, Enter on a link).
|
|
239
|
+
for (const type of ["wheel", "touchstart", "keydown", "pointerdown"]) {
|
|
240
|
+
doc.addEventListener(
|
|
241
|
+
type,
|
|
242
|
+
() => {
|
|
243
|
+
// No measure here: the scroll this input causes runs it.
|
|
244
|
+
if (anchor) anchor.held = false;
|
|
245
|
+
},
|
|
246
|
+
{ capture: true, passive: true, signal: controller.signal },
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
171
250
|
// Observer is scoped to the nav subtree — link injection is caught;
|
|
172
251
|
// section-only DOM mutations elsewhere need an explicit refreshScrollspy().
|
|
173
252
|
const mo = new MutationObserver(() => schedule(rebuild));
|
package/src/js/selectors.js
CHANGED
|
@@ -35,6 +35,9 @@ export const CLASSES = {
|
|
|
35
35
|
// surface.js — state class on the open flyout/menu/dialog surface.
|
|
36
36
|
// status.js writes the same class on the status bar while a message shows.
|
|
37
37
|
open: "is-open",
|
|
38
|
+
// in-view.js — transient state on an element that waits outside the viewport
|
|
39
|
+
// for its first appearance. Each effect's CSS decides how to hide it.
|
|
40
|
+
pending: "is-pending",
|
|
38
41
|
// dialog.js — transient class for the "can't dismiss" shake animation.
|
|
39
42
|
static: "is-static",
|
|
40
43
|
// dialog.js — written on <html> while any modal dialog is open.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { existsSync } from "node:fs";
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
import { createRequire } from "node:module";
|
|
9
|
-
import { dirname, resolve } from "node:path";
|
|
9
|
+
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
11
|
|
|
12
12
|
const IMPORT_PREFIX_RE = /^\s*@import\b/;
|
|
@@ -16,6 +16,12 @@ const EXTERNAL_SPECIFIER_RE = /^(?:[a-z][a-z0-9+.-]+:|\/\/|\/)/i;
|
|
|
16
16
|
const CHARSET_RE = /^\s*@charset\s+["'][^"']*["']\s*;[^\n]*\n?/;
|
|
17
17
|
const LAYER_TRAILER_RE = /^layer(?:\(\s*([A-Za-z_-][\w-]*(?:\.[A-Za-z_-][\w-]*)*)?\s*\))?$/;
|
|
18
18
|
const RESOLVER_STUB = "__actual_css_resolve__.js";
|
|
19
|
+
// url() values that stay valid wherever the bundle lands: a scheme (data:,
|
|
20
|
+
// https:; two characters or more, as above), a root- or protocol-relative
|
|
21
|
+
// path, a bare query or fragment (same document).
|
|
22
|
+
const LOCATION_FREE_URL_RE = /^(?:[a-z][a-z0-9+.-]+:|\/|[?#])/i;
|
|
23
|
+
const IDENT_CHAR_RE = /[\w-]/;
|
|
24
|
+
const NODE_MODULES_SEGMENT = `${sep}node_modules${sep}`;
|
|
19
25
|
|
|
20
26
|
function skipWhitespace(source, index) {
|
|
21
27
|
let next = index;
|
|
@@ -157,7 +163,142 @@ function wrapInLayer(css, name) {
|
|
|
157
163
|
return `${head}\n${body}\n}\n`;
|
|
158
164
|
}
|
|
159
165
|
|
|
160
|
-
|
|
166
|
+
// Index just past the string opened by the quote at `start` (escapes
|
|
167
|
+
// honoured), or the line end when the string is left open.
|
|
168
|
+
function stringEnd(line, start) {
|
|
169
|
+
const quote = line[start];
|
|
170
|
+
|
|
171
|
+
for (let i = start + 1; i < line.length; i += 1) {
|
|
172
|
+
if (line[i] === "\\") i += 1;
|
|
173
|
+
else if (line[i] === quote) return i + 1;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return line.length;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Reads the url() whose "(" sits at `open`: { value, quote, end } with `end`
|
|
180
|
+
// just past ")", or null when the call does not close on this line.
|
|
181
|
+
function readUrlCall(line, open) {
|
|
182
|
+
let i = skipWhitespace(line, open + 1);
|
|
183
|
+
const quote = line[i] === '"' || line[i] === "'" ? line[i] : "";
|
|
184
|
+
let value;
|
|
185
|
+
|
|
186
|
+
if (quote) {
|
|
187
|
+
// A string left open runs to the line end, so no ")" follows and the
|
|
188
|
+
// check below returns null: the slice is never used then.
|
|
189
|
+
const end = stringEnd(line, i);
|
|
190
|
+
value = line.slice(i + 1, end - 1);
|
|
191
|
+
i = skipWhitespace(line, end);
|
|
192
|
+
} else {
|
|
193
|
+
const start = i;
|
|
194
|
+
while (i < line.length && line[i] !== ")" && !/\s/.test(line[i])) {
|
|
195
|
+
i += line[i] === "\\" ? 2 : 1;
|
|
196
|
+
}
|
|
197
|
+
value = line.slice(start, i);
|
|
198
|
+
i = skipWhitespace(line, i);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return line[i] === ")" ? { value, quote, end: i + 1 } : null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// The url() value pointing at the same file as `value` written from `file`,
|
|
205
|
+
// seen from `base`; null when it does not depend on the stylesheet location.
|
|
206
|
+
function rebasedUrl(value, file, base) {
|
|
207
|
+
if (value === "" || LOCATION_FREE_URL_RE.test(value)) return null;
|
|
208
|
+
|
|
209
|
+
// Escapes would need decoding before the path means anything: refuse
|
|
210
|
+
// rather than rewrite a path that is not the one the browser reads.
|
|
211
|
+
if (value.includes("\\")) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`Escaped characters in a relative url() are not supported in ${file}: ${value}`,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
// A package directory is never served: the rewritten reference would only
|
|
217
|
+
// ever 404. Copy such assets into the served tree and reference them there.
|
|
218
|
+
if (file.includes(NODE_MODULES_SEGMENT)) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
`Relative url() in a node_modules stylesheet cannot be served from the bundle (${file}): ${value}`,
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const cut = value.search(/[?#]/);
|
|
225
|
+
const path = cut === -1 ? value : value.slice(0, cut);
|
|
226
|
+
const suffix = cut === -1 ? "" : value.slice(cut);
|
|
227
|
+
const target = resolve(dirname(file), path);
|
|
228
|
+
const fromBase = relative(base, target);
|
|
229
|
+
// Another Windows drive has no relative path: fail rather than emit a URL
|
|
230
|
+
// the browser can never resolve.
|
|
231
|
+
if (isAbsolute(fromBase)) {
|
|
232
|
+
throw new Error(`Cannot reach ${target} by a relative url() from ${base} (${file})`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const rebased = fromBase.split(sep).join("/");
|
|
236
|
+
return `${rebased.startsWith(".") ? "" : "./"}${rebased}${suffix}`;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Rewrites the relative url() references of one line (see rebasedUrl).
|
|
240
|
+
// Comments and strings are copied verbatim — a url() quoted inside a data URI
|
|
241
|
+
// or a `content` string is text, not a reference; `state.inComment` carries a
|
|
242
|
+
// comment that spans lines. A url() split over several lines is left as is.
|
|
243
|
+
function rebaseUrls(line, file, base, state) {
|
|
244
|
+
let out = "";
|
|
245
|
+
let i = 0;
|
|
246
|
+
|
|
247
|
+
while (i < line.length) {
|
|
248
|
+
if (state.inComment) {
|
|
249
|
+
const close = line.indexOf("*/", i);
|
|
250
|
+
const end = close === -1 ? line.length : close + 2;
|
|
251
|
+
out += line.slice(i, end);
|
|
252
|
+
state.inComment = close === -1;
|
|
253
|
+
i = end;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const char = line[i];
|
|
258
|
+
|
|
259
|
+
if (char === "/" && line[i + 1] === "*") {
|
|
260
|
+
state.inComment = true;
|
|
261
|
+
out += "/*";
|
|
262
|
+
i += 2;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (char === '"' || char === "'") {
|
|
267
|
+
const end = stringEnd(line, i);
|
|
268
|
+
out += line.slice(i, end);
|
|
269
|
+
i = end;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const call =
|
|
274
|
+
line.slice(i, i + 4).toLowerCase() === "url(" && !IDENT_CHAR_RE.test(line[i - 1] ?? "")
|
|
275
|
+
? readUrlCall(line, i + 3)
|
|
276
|
+
: null;
|
|
277
|
+
if (!call) {
|
|
278
|
+
out += char;
|
|
279
|
+
i += 1;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const rebased = rebasedUrl(call.value, file, base);
|
|
284
|
+
|
|
285
|
+
if (rebased === null) {
|
|
286
|
+
out += line.slice(i, call.end);
|
|
287
|
+
i = call.end;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Quote whatever an unquoted url() could not hold; escape the quote kept.
|
|
292
|
+
const quote = call.quote || (/[\s"'()]/.test(rebased) ? '"' : "");
|
|
293
|
+
const body = quote ? rebased.replaceAll(quote, `\\${quote}`) : rebased;
|
|
294
|
+
out += `url(${quote}${body}${quote})`;
|
|
295
|
+
i = call.end;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return out;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async function inlineFile(path, stack, preserved, layered, base) {
|
|
161
302
|
if (stack.includes(path)) {
|
|
162
303
|
const chain = [...stack, path].map((item) => item.replace(/.*[/\\]/, ""));
|
|
163
304
|
throw new Error(`Circular CSS import: ${chain.join(" -> ")}`);
|
|
@@ -166,6 +307,7 @@ async function inlineFile(path, stack, preserved, layered) {
|
|
|
166
307
|
const css = await readFile(path, "utf8");
|
|
167
308
|
const nextStack = [...stack, path];
|
|
168
309
|
const chunks = [];
|
|
310
|
+
const urlState = { inComment: false };
|
|
169
311
|
|
|
170
312
|
for (const line of css.split(/\r?\n/)) {
|
|
171
313
|
const parsed = parseImportLine(line);
|
|
@@ -174,7 +316,7 @@ async function inlineFile(path, stack, preserved, layered) {
|
|
|
174
316
|
if (IMPORT_PREFIX_RE.test(line)) {
|
|
175
317
|
throw new Error(`Unsupported CSS @import syntax in ${path}: ${line.trim()}`);
|
|
176
318
|
}
|
|
177
|
-
chunks.push(line);
|
|
319
|
+
chunks.push(base ? rebaseUrls(line, path, base, urlState) : line);
|
|
178
320
|
continue;
|
|
179
321
|
}
|
|
180
322
|
|
|
@@ -199,16 +341,21 @@ async function inlineFile(path, stack, preserved, layered) {
|
|
|
199
341
|
}
|
|
200
342
|
|
|
201
343
|
const target = resolveImportTarget(path, parsed.specifier);
|
|
202
|
-
const inlined = await inlineFile(target, nextStack, preserved, layered || layer !== null);
|
|
344
|
+
const inlined = await inlineFile(target, nextStack, preserved, layered || layer !== null, base);
|
|
203
345
|
chunks.push(layer ? wrapInLayer(inlined, layer.name) : inlined);
|
|
204
346
|
}
|
|
205
347
|
|
|
206
348
|
return `${chunks.join("\n").trim()}\n`;
|
|
207
349
|
}
|
|
208
350
|
|
|
209
|
-
|
|
351
|
+
// `outDir`: the directory the bundle will be written to. When given, relative
|
|
352
|
+
// url() references are rewritten to keep pointing at their files from there
|
|
353
|
+
// (fonts, images next to an imported stylesheet); without it they are copied
|
|
354
|
+
// as written, which is only right when the bundle sits beside its entry.
|
|
355
|
+
export async function inlineImports(file, { outDir } = {}) {
|
|
210
356
|
const preserved = [];
|
|
211
|
-
const
|
|
357
|
+
const base = outDir ? resolve(outDir) : null;
|
|
358
|
+
const body = await inlineFile(resolve(file), [], preserved, false, base);
|
|
212
359
|
|
|
213
360
|
if (preserved.length === 0) return body;
|
|
214
361
|
|