actual-css 0.2.0 → 0.3.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 +38 -1
- package/README.md +24 -9
- package/dist/actual-themes.min.css +1 -0
- package/dist/actual.css +1244 -915
- package/dist/actual.js +1 -3
- package/dist/actual.min.css +1 -1
- package/dist/optional.css +1048 -0
- package/dist/optional.min.css +1 -0
- package/docs/design-notes/browser-support.md +94 -14
- package/docs/design-notes/cascade-layer.md +1 -1
- package/docs/design-notes/enhancement-contract.md +11 -14
- package/docs/design-notes/forced-colors.md +105 -0
- package/docs/design-notes/naming.md +2 -1
- package/docs/design-notes/platform-alignment.md +492 -0
- package/docs/design-notes/references.md +8 -0
- package/docs/design-notes/widget-primitives.md +37 -1
- package/docs/navigation.json +135 -0
- package/docs/pages/components/accordion.md +80 -0
- package/docs/pages/components/alert.md +203 -0
- package/docs/pages/components/aura.md +35 -0
- package/docs/pages/components/avatar.md +95 -0
- package/docs/pages/components/badge.md +102 -0
- package/docs/pages/components/breadcrumb.md +19 -0
- package/docs/pages/components/button.md +205 -0
- package/docs/pages/components/card.md +183 -0
- package/docs/pages/components/chat.md +50 -0
- package/docs/pages/components/dialog.md +367 -0
- package/docs/pages/components/drawer.md +113 -0
- package/docs/pages/components/fab.md +118 -0
- package/docs/pages/components/key.md +33 -0
- package/docs/pages/components/meter.md +23 -0
- package/docs/pages/components/navbar.md +92 -0
- package/docs/pages/components/pagination.md +55 -0
- package/docs/pages/components/progress.md +29 -0
- package/docs/pages/components/skeleton.md +38 -0
- package/docs/pages/components/spinner.md +93 -0
- package/docs/pages/components/table.md +102 -0
- package/docs/pages/enhancements/flyout.md +391 -0
- package/docs/pages/enhancements/overview.md +36 -0
- package/docs/pages/enhancements/scrollspy.md +71 -0
- package/docs/pages/enhancements/status-bar.md +72 -0
- package/docs/pages/enhancements/tabs.md +80 -0
- package/docs/pages/enhancements/tooltip.md +130 -0
- package/docs/pages/examples/overview.md +41 -0
- package/docs/pages/forms/choice-cards.md +102 -0
- package/docs/pages/forms/controls.md +32 -0
- package/docs/pages/forms/detached-actions.md +59 -0
- package/docs/pages/forms/floating-field.md +88 -0
- package/docs/pages/forms/form-actions.md +56 -0
- package/docs/pages/forms/input-policy.md +91 -0
- package/docs/pages/forms/joined-controls.md +37 -0
- package/docs/pages/forms/labels.md +42 -0
- package/docs/pages/forms/otp.md +50 -0
- package/docs/pages/forms/overview.md +188 -0
- package/docs/pages/forms/password.md +40 -0
- package/docs/pages/forms/range.md +17 -0
- package/docs/pages/forms/states-and-sizes.md +321 -0
- package/docs/pages/forms/sticky-actions.md +187 -0
- package/docs/pages/forms/switch.md +31 -0
- package/docs/pages/forms/validation.md +241 -0
- package/docs/{mental-model.md → pages/foundations/philosophy.md} +33 -18
- package/docs/pages/foundations/theming.md +92 -0
- package/docs/pages/foundations/tokens.md +421 -0
- package/docs/{typography.md → pages/foundations/typography.md} +27 -9
- package/docs/pages/guides/bootstrap.md +438 -0
- package/docs/pages/guides/introduction.md +157 -0
- package/docs/pages/guides/optional-components.md +33 -0
- package/docs/pages/guides/progressive-enhancement.md +686 -0
- package/docs/pages/guides/tailwind.md +455 -0
- package/docs/pages/layout/app-shell.md +25 -0
- package/docs/pages/layout/center.md +29 -0
- package/docs/pages/layout/cluster.md +57 -0
- package/docs/pages/layout/frame.md +30 -0
- package/docs/pages/layout/grid.md +142 -0
- package/docs/pages/layout/list.md +41 -0
- package/docs/pages/layout/media.md +21 -0
- package/docs/pages/layout/overview.md +37 -0
- package/docs/pages/layout/scroll-snap.md +54 -0
- package/docs/pages/layout/sidebar-layout.md +27 -0
- package/docs/pages/layout/stack.md +18 -0
- package/docs/pages/layout/switcher.md +36 -0
- package/docs/pages/layout/topbar.md +23 -0
- package/docs/pages/patterns/actions.md +52 -0
- package/docs/pages/patterns/code-block.md +36 -0
- package/docs/pages/patterns/exclusive-accordion.md +16 -0
- package/docs/pages/patterns/hierarchical-nav.md +26 -0
- package/docs/pages/patterns/icon-input.md +25 -0
- package/docs/pages/patterns/intent-nesting.md +3 -0
- package/docs/pages/patterns/navigation-list.md +235 -0
- package/docs/pages/patterns/overview.md +58 -0
- package/docs/pages/patterns/structured-lists.md +47 -0
- package/docs/pages/utilities/accessibility.md +34 -0
- package/docs/pages/utilities/flex.md +105 -0
- package/docs/pages/utilities/links.md +18 -0
- package/docs/pages/utilities/list.md +31 -0
- package/docs/pages/utilities/overflow.md +43 -0
- package/docs/pages/utilities/overview.md +18 -0
- package/docs/pages/utilities/shape.md +25 -0
- package/docs/pages/utilities/sizing-wrapping.md +115 -0
- package/docs/pages/utilities/spacing.md +79 -0
- package/docs/pages/utilities/text.md +43 -0
- package/llms.txt +4 -4
- package/package.json +20 -12
- package/src/css/actual.css +12 -1
- package/src/css/base.css +3 -5
- package/src/css/components/accordion.css +18 -30
- package/src/css/components/actions.css +4 -1
- package/src/css/components/alert.css +126 -99
- package/src/css/components/avatar.css +16 -10
- package/src/css/components/badge.css +55 -35
- package/src/css/components/breadcrumb.css +7 -15
- package/src/css/components/busy.css +6 -0
- package/src/css/components/button.css +78 -32
- package/src/css/components/card.css +17 -37
- package/src/css/components/drawer.css +30 -13
- package/src/css/components/flyout.css +39 -109
- package/src/css/components/index.css +1 -0
- package/src/css/components/join.css +14 -2
- package/src/css/components/key.css +2 -0
- package/src/css/components/menu.css +125 -0
- package/src/css/components/meter.css +0 -23
- package/src/css/components/modal.css +162 -7
- package/src/css/components/navbar.css +17 -18
- package/src/css/components/overline.css +0 -7
- package/src/css/components/pagination.css +1 -1
- package/src/css/components/progress.css +8 -26
- package/src/css/components/skeleton.css +7 -0
- package/src/css/components/spinner.css +6 -7
- package/src/css/components/status-bar.css +15 -24
- package/src/css/components/surface.css +2 -8
- package/src/css/components/tab.css +19 -48
- package/src/css/components/table.css +7 -5
- package/src/css/components/tooltip.css +14 -7
- package/src/css/focus.css +14 -38
- package/src/css/forms/choice-card.css +13 -14
- package/src/css/forms/choice.css +21 -27
- package/src/css/forms/control.css +16 -17
- package/src/css/forms/custom-select.css +9 -11
- package/src/css/forms/form-actions.css +14 -3
- package/src/css/forms/form.css +7 -4
- package/src/css/forms/index.css +4 -4
- package/src/css/forms/input-icon.css +30 -12
- package/src/css/forms/native.css +50 -11
- package/src/css/forms/range.css +17 -9
- package/src/css/forms/select.css +8 -8
- package/src/css/forms/switch.css +14 -12
- package/src/css/forms/validation.css +32 -5
- package/src/css/grid.css +19 -18
- package/src/css/intents.css +2 -2
- package/src/css/layout.css +29 -1
- package/src/css/optional/aura.css +93 -0
- package/src/css/optional/chat.css +105 -0
- package/src/css/optional/fab.css +104 -0
- package/src/css/optional/floating-field.css +87 -0
- package/src/css/optional/index.css +5 -0
- package/src/css/optional/layout-extra.css +7 -4
- package/src/css/optional/otp.css +115 -0
- package/src/css/optional/scroll-snap.css +6 -0
- package/src/css/optional/scroller.css +13 -7
- package/src/css/optional/typography-fluid.css +5 -0
- package/src/css/optional/utilities-extra.css +17 -2
- package/src/css/prose.css +18 -8
- package/src/css/reset.css +0 -10
- package/src/css/theme.css +21 -5
- package/src/css/themes/cyberpunk.css +1 -1
- package/src/css/themes/dim.css +3 -3
- package/src/css/themes/edge.css +8 -10
- package/src/css/themes/index.css +3 -3
- package/src/css/themes/{dark.css → indigo.css} +5 -4
- package/src/css/themes/neon.css +5 -5
- package/src/css/themes/square.css +0 -3
- package/src/css/tokens.css +74 -20
- package/src/css/utilities.css +8 -10
- package/src/css/variants.css +37 -65
- package/src/js/command.js +1 -3
- package/src/js/context-menu.js +67 -35
- package/src/js/dialog.js +68 -79
- package/src/js/dismiss.js +15 -0
- package/src/js/enhance.js +54 -23
- package/src/js/enhancement-loader.js +301 -0
- package/src/js/events.js +3 -0
- package/src/js/filter.js +3 -3
- package/src/js/floating.js +101 -131
- package/src/js/flyout.js +104 -87
- package/src/js/focus-group.js +116 -0
- package/src/js/focus.js +6 -1
- package/src/js/index.js +4 -2
- package/src/js/input.js +1 -1
- package/src/js/keys.js +27 -0
- package/src/js/mask.js +7 -6
- package/src/js/menu.js +87 -34
- package/src/js/parse-config.js +47 -0
- package/src/js/password.js +9 -1
- package/src/js/scrollspy.js +12 -4
- package/src/js/selectors.js +0 -7
- package/src/js/status.js +3 -1
- package/src/js/surface.js +185 -136
- package/src/js/tab.js +36 -53
- package/src/js/tooltip.js +53 -31
- package/src/js/validation.js +34 -8
- package/dist/actual.js.map +0 -31
- package/docs/README.md +0 -28
- package/docs/components.md +0 -860
- package/docs/design-notes/previous-work.md +0 -5
- package/docs/forms.md +0 -1265
- package/docs/javascript.md +0 -496
- package/docs/layout.md +0 -480
- package/docs/patterns.md +0 -504
- package/docs/reserved.md +0 -7
- package/docs/tokens.md +0 -455
- package/docs/ui.md +0 -929
- package/docs/utilities.md +0 -384
- package/src/css/dialog-fallback.css +0 -56
- package/src/js/dialog-fallback.js +0 -163
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* enhancement-loader.js — Server-declared enhancement manifest loader.
|
|
3
|
+
*
|
|
4
|
+
* Reads <script type="application/json" data-enhance-modules"> blocks or
|
|
5
|
+
* the Enhance-Modules HTTP header, dynamically imports the declared ES
|
|
6
|
+
* module entrypoints, and registers them with the Actual lifecycle engine.
|
|
7
|
+
*
|
|
8
|
+
* Manifests declare document-wide modules: dynamically loaded enhancements
|
|
9
|
+
* always register on the default document root. A scope passed to
|
|
10
|
+
* loadEnhancements() only limits where manifest blocks are looked up.
|
|
11
|
+
*
|
|
12
|
+
* One map keyed by name reserves the slot immediately, so concurrent calls
|
|
13
|
+
* for the same name share one promise. The browser's native module cache
|
|
14
|
+
* handles URL dedup. Script/style helpers fill the gap for non-ESM assets.
|
|
15
|
+
*
|
|
16
|
+
* Exports prefixed with `__` are test hooks and are not part of the
|
|
17
|
+
* supported public API or SemVer contract.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import enhance, { registerEnhancement } from "./enhance.js";
|
|
21
|
+
import { parseConfig } from "./parse-config.js";
|
|
22
|
+
|
|
23
|
+
const MANIFEST_SELECTOR = 'script[type="application/json"][data-enhance-modules]';
|
|
24
|
+
|
|
25
|
+
const enhancements = new Map();
|
|
26
|
+
|
|
27
|
+
const scriptLoads = new Map();
|
|
28
|
+
const styleLoads = new Map();
|
|
29
|
+
|
|
30
|
+
let moduleImporter = (url) => import(url);
|
|
31
|
+
|
|
32
|
+
export function loadScript(url) {
|
|
33
|
+
const absoluteUrl = new URL(url, document.baseURI).href;
|
|
34
|
+
|
|
35
|
+
if (!scriptLoads.has(absoluteUrl)) {
|
|
36
|
+
scriptLoads.set(
|
|
37
|
+
absoluteUrl,
|
|
38
|
+
new Promise((resolve, reject) => {
|
|
39
|
+
const script = document.createElement("script");
|
|
40
|
+
script.src = absoluteUrl;
|
|
41
|
+
script.onload = resolve;
|
|
42
|
+
script.onerror = () => {
|
|
43
|
+
scriptLoads.delete(absoluteUrl);
|
|
44
|
+
script.remove();
|
|
45
|
+
reject(new Error(`Unable to load script: ${absoluteUrl}`));
|
|
46
|
+
};
|
|
47
|
+
document.head.append(script);
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return scriptLoads.get(absoluteUrl);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function loadStyle(url) {
|
|
56
|
+
const absoluteUrl = new URL(url, document.baseURI).href;
|
|
57
|
+
|
|
58
|
+
if (!styleLoads.has(absoluteUrl)) {
|
|
59
|
+
styleLoads.set(
|
|
60
|
+
absoluteUrl,
|
|
61
|
+
new Promise((resolve, reject) => {
|
|
62
|
+
const link = document.createElement("link");
|
|
63
|
+
link.rel = "stylesheet";
|
|
64
|
+
link.href = absoluteUrl;
|
|
65
|
+
link.onload = resolve;
|
|
66
|
+
link.onerror = () => {
|
|
67
|
+
styleLoads.delete(absoluteUrl);
|
|
68
|
+
link.remove();
|
|
69
|
+
reject(new Error(`Unable to load style: ${absoluteUrl}`));
|
|
70
|
+
};
|
|
71
|
+
document.head.append(link);
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return styleLoads.get(absoluteUrl);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function makeInit(name, connect) {
|
|
80
|
+
return (element) => {
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
const source = element.getAttribute("data-enhance-config");
|
|
83
|
+
const config = parseConfig(source ?? "");
|
|
84
|
+
|
|
85
|
+
const emit = (type, detail, options = {}) =>
|
|
86
|
+
element.dispatchEvent(
|
|
87
|
+
new CustomEvent(`actual:${name}:${type}`, {
|
|
88
|
+
bubbles: true,
|
|
89
|
+
detail,
|
|
90
|
+
...options,
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
let cleanup;
|
|
95
|
+
try {
|
|
96
|
+
cleanup = connect(element, {
|
|
97
|
+
config,
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
emit,
|
|
100
|
+
});
|
|
101
|
+
} catch (error) {
|
|
102
|
+
// A throwing connect() must not leak the local controller's listeners.
|
|
103
|
+
controller.abort();
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (cleanup?.then) {
|
|
108
|
+
controller.abort();
|
|
109
|
+
throw new TypeError(
|
|
110
|
+
`Enhancement "${name}" returned a Promise. connect() must be synchronous; use prepare() for asynchronous setup.`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (cleanup !== undefined && typeof cleanup !== "function") {
|
|
115
|
+
controller.abort();
|
|
116
|
+
throw new TypeError(`Enhancement "${name}" must return a cleanup function or undefined.`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return () => {
|
|
120
|
+
controller.abort();
|
|
121
|
+
cleanup?.();
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function assertManifestUrl(name, url) {
|
|
127
|
+
if (typeof url !== "string" || url.trim() === "") {
|
|
128
|
+
throw new TypeError(`Enhancement "${name}" must declare a non-empty module URL.`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function loadEnhancement(name, url) {
|
|
133
|
+
assertManifestUrl(name, url);
|
|
134
|
+
const absoluteUrl = new URL(url, document.baseURI).href;
|
|
135
|
+
const existing = enhancements.get(name);
|
|
136
|
+
|
|
137
|
+
if (existing) {
|
|
138
|
+
if (existing.url !== absoluteUrl) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
`Enhancement "${name}" is already declared from ${existing.url} and cannot be replaced by ${absoluteUrl}.`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return existing.promise.then(() => ({ name, status: "skipped" }));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const promise = moduleImporter(absoluteUrl)
|
|
147
|
+
.then(async (mod) => {
|
|
148
|
+
if (typeof mod.default !== "function") {
|
|
149
|
+
throw new TypeError(`Enhancement "${name}" must export a default function.`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (mod.prepare !== undefined) {
|
|
153
|
+
if (typeof mod.prepare !== "function") {
|
|
154
|
+
throw new TypeError(`Enhancement "${name}" exports an invalid prepare().`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
await mod.prepare({
|
|
158
|
+
resolve: (path) => new URL(path, absoluteUrl).href,
|
|
159
|
+
loadScript,
|
|
160
|
+
loadStyle,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
registerEnhancement(name, makeInit(name, mod.default));
|
|
165
|
+
|
|
166
|
+
return { name, status: "loaded" };
|
|
167
|
+
})
|
|
168
|
+
.catch((error) => {
|
|
169
|
+
if (enhancements.get(name)?.promise === promise) {
|
|
170
|
+
enhancements.delete(name);
|
|
171
|
+
}
|
|
172
|
+
throw error;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
enhancements.set(name, { url: absoluteUrl, promise });
|
|
176
|
+
|
|
177
|
+
return promise;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function loadManifest(manifest) {
|
|
181
|
+
const entries = Object.entries(manifest);
|
|
182
|
+
const results = await Promise.allSettled(
|
|
183
|
+
entries.map(([name, url]) => loadEnhancement(name, url)),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const output = { names: [], failed: [], skipped: [] };
|
|
187
|
+
|
|
188
|
+
results.forEach((result, index) => {
|
|
189
|
+
const name = entries[index][0];
|
|
190
|
+
|
|
191
|
+
if (result.status === "rejected") {
|
|
192
|
+
output.failed.push({ name, error: result.reason });
|
|
193
|
+
} else if (result.value.status === "skipped") {
|
|
194
|
+
output.skipped.push(name);
|
|
195
|
+
} else {
|
|
196
|
+
output.names.push(name);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
return output;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function parseManifestEntries(text) {
|
|
204
|
+
const data = JSON.parse(text);
|
|
205
|
+
|
|
206
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
207
|
+
throw new TypeError("Manifest must be a JSON object.");
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return Object.entries(data);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Load every enhancement declared in the manifest blocks under `scope`.
|
|
215
|
+
*
|
|
216
|
+
* @param {Document | Element | DocumentFragment} [scope] Where to look for
|
|
217
|
+
* manifest blocks. It only limits discovery; loaded enhancements register on
|
|
218
|
+
* the default document root.
|
|
219
|
+
* @returns {Promise<{ names: string[], failed: { name: string, error: Error }[], skipped: string[] }>}
|
|
220
|
+
*/
|
|
221
|
+
export async function loadEnhancements(scope = document) {
|
|
222
|
+
const blocks = scope.querySelectorAll(MANIFEST_SELECTOR);
|
|
223
|
+
|
|
224
|
+
const manifest = new Map();
|
|
225
|
+
|
|
226
|
+
for (const block of blocks) {
|
|
227
|
+
const entries = parseManifestEntries(block.textContent);
|
|
228
|
+
|
|
229
|
+
for (const [name, rawUrl] of entries) {
|
|
230
|
+
assertManifestUrl(name, rawUrl);
|
|
231
|
+
const url = new URL(rawUrl, document.baseURI).href;
|
|
232
|
+
const existing = manifest.get(name);
|
|
233
|
+
|
|
234
|
+
if (existing && existing !== url) {
|
|
235
|
+
throw new Error(`Enhancement "${name}" is declared from both ${existing} and ${url}.`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
manifest.set(name, url);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const result = await loadManifest(Object.fromEntries(manifest));
|
|
243
|
+
|
|
244
|
+
if (result.failed.length === 0) {
|
|
245
|
+
for (const block of blocks) block.remove();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function loadManifestBlock(block) {
|
|
252
|
+
const entries = parseManifestEntries(block.textContent);
|
|
253
|
+
const result = await loadManifest(Object.fromEntries(entries));
|
|
254
|
+
|
|
255
|
+
for (const failure of result.failed) {
|
|
256
|
+
console.error(`Enhancement "${failure.name}" failed to load:`, failure.error);
|
|
257
|
+
}
|
|
258
|
+
if (result.failed.length === 0) block.remove();
|
|
259
|
+
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export function watchEnhancementManifests() {
|
|
264
|
+
return enhance({
|
|
265
|
+
[MANIFEST_SELECTOR]: (block) => {
|
|
266
|
+
loadManifestBlock(block).catch((error) => {
|
|
267
|
+
console.error("Failed to parse enhancement manifest:", error);
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export async function loadResponse(response) {
|
|
274
|
+
const header = response.headers.get("Enhance-Modules");
|
|
275
|
+
|
|
276
|
+
if (!header) return { names: [], failed: [], skipped: [] };
|
|
277
|
+
|
|
278
|
+
let manifest;
|
|
279
|
+
try {
|
|
280
|
+
manifest = JSON.parse(header);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
throw new SyntaxError(`Invalid JSON in Enhance-Modules header: ${error.message}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (typeof manifest !== "object" || manifest === null || Array.isArray(manifest)) {
|
|
286
|
+
throw new TypeError("Enhance-Modules header must be a JSON object.");
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return loadManifest(manifest);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function __setModuleImporter(fn) {
|
|
293
|
+
moduleImporter = fn;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function __reset() {
|
|
297
|
+
enhancements.clear();
|
|
298
|
+
scriptLoads.clear();
|
|
299
|
+
styleLoads.clear();
|
|
300
|
+
moduleImporter = (url) => import(url);
|
|
301
|
+
}
|
package/src/js/events.js
CHANGED
|
@@ -19,4 +19,7 @@ export const EVENTS = {
|
|
|
19
19
|
// Cancelable: dispatched by dialog.js before handling native cancel close.
|
|
20
20
|
// detail: { dialog, sourceEvent }
|
|
21
21
|
dialogCancel: `${ACTUAL_EVENT_PREFIX}:dialog-cancel`,
|
|
22
|
+
// Dispatched after a command hides its target.
|
|
23
|
+
// detail: { trigger }
|
|
24
|
+
dismiss: `${ACTUAL_EVENT_PREFIX}:dismiss`,
|
|
22
25
|
};
|
package/src/js/filter.js
CHANGED
|
@@ -60,12 +60,12 @@ function normalizeText(value) {
|
|
|
60
60
|
function filterSlug(value, event) {
|
|
61
61
|
const keepTrailingSeparator = event?.inputType === "insertText" && /[^\p{L}\p{N}]$/u.test(value);
|
|
62
62
|
const slug = normalizeText(value)
|
|
63
|
-
.
|
|
63
|
+
.toLowerCase()
|
|
64
64
|
.replace(/[^\p{L}\p{N}]+/gu, "-")
|
|
65
65
|
.replace(/-{2,}/g, "-")
|
|
66
|
-
.replace(
|
|
66
|
+
.replace(/^-+/, "");
|
|
67
67
|
|
|
68
|
-
return keepTrailingSeparator ? slug : slug.replace(
|
|
68
|
+
return keepTrailingSeparator ? slug : slug.replace(/-+$/, "");
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function filterValue(value, modes, event) {
|
package/src/js/floating.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Compact positioning engine for menus, tooltips, and popovers.
|
|
3
3
|
*
|
|
4
|
-
* Core math ported from Floating UI.
|
|
5
|
-
*
|
|
4
|
+
* Core math ported from Floating UI. autoUpdate() batches scroll, resize,
|
|
5
|
+
* and element-resize callbacks per ownerDocument so each document owns its
|
|
6
|
+
* own listener set — no global import-time side effects.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
import { EVENTS } from "./events.js";
|
|
9
|
-
|
|
10
9
|
/* ── Placement parsing ────────────────────────────────── */
|
|
11
10
|
|
|
12
11
|
function getSide(p) {
|
|
@@ -65,7 +64,7 @@ function computeCoords(reference, floating, placement, rtl) {
|
|
|
65
64
|
return coords;
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
function applyOffset(coords, side, offset
|
|
67
|
+
function applyOffset(coords, side, offset) {
|
|
69
68
|
switch (side) {
|
|
70
69
|
case "top":
|
|
71
70
|
coords.y -= offset;
|
|
@@ -74,10 +73,10 @@ function applyOffset(coords, side, offset, rtl) {
|
|
|
74
73
|
coords.y += offset;
|
|
75
74
|
break;
|
|
76
75
|
case "left":
|
|
77
|
-
coords.x
|
|
76
|
+
coords.x -= offset;
|
|
78
77
|
break;
|
|
79
78
|
case "right":
|
|
80
|
-
coords.x +=
|
|
79
|
+
coords.x += offset;
|
|
81
80
|
break;
|
|
82
81
|
}
|
|
83
82
|
}
|
|
@@ -103,7 +102,8 @@ function isRTL(el) {
|
|
|
103
102
|
if (el.dir === "rtl") return true;
|
|
104
103
|
if (el.dir === "ltr") return false;
|
|
105
104
|
if (supportsDirSelector) return el.matches(":dir(rtl)");
|
|
106
|
-
|
|
105
|
+
const style = el.ownerDocument?.defaultView?.getComputedStyle?.(el);
|
|
106
|
+
return style?.direction === "rtl";
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
function getDocEl(doc) {
|
|
@@ -134,8 +134,6 @@ function getViewportBoundary(doc) {
|
|
|
134
134
|
doc.compatMode === "CSS1Compat"
|
|
135
135
|
? toNumber(bodyStyle?.marginLeft) + toNumber(bodyStyle?.marginRight)
|
|
136
136
|
: 0;
|
|
137
|
-
// Classic stable scrollbars reserve inline space on the body. Subtract only
|
|
138
|
-
// plausible scrollbar widths so unusual body sizing does not shrink the viewport.
|
|
139
137
|
const stableScrollbar = Math.abs(docEl.clientWidth - body.clientWidth - bodyMargin);
|
|
140
138
|
if (stableScrollbar <= STABLE_SCROLLBAR_MAX_WIDTH) {
|
|
141
139
|
width -= stableScrollbar;
|
|
@@ -181,15 +179,6 @@ function isVisible(el) {
|
|
|
181
179
|
return el.getClientRects().length > 0;
|
|
182
180
|
}
|
|
183
181
|
|
|
184
|
-
function topVisibleTracked() {
|
|
185
|
-
const elements = [...tracked];
|
|
186
|
-
for (let i = elements.length - 1; i >= 0; i--) {
|
|
187
|
-
const el = elements[i];
|
|
188
|
-
if (el.isConnected && isVisible(el)) return el;
|
|
189
|
-
}
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
182
|
function getFloatingSize(float) {
|
|
194
183
|
const rect = float.getBoundingClientRect();
|
|
195
184
|
return {
|
|
@@ -198,138 +187,120 @@ function getFloatingSize(float) {
|
|
|
198
187
|
};
|
|
199
188
|
}
|
|
200
189
|
|
|
201
|
-
/* ──
|
|
202
|
-
|
|
203
|
-
const tracked = new Set();
|
|
204
|
-
let resizeObserver = null;
|
|
205
|
-
let tick = false;
|
|
206
|
-
const pendingTypes = new Set();
|
|
207
|
-
|
|
208
|
-
function notify(type) {
|
|
209
|
-
if (type === "escape") {
|
|
210
|
-
const el = topVisibleTracked();
|
|
211
|
-
if (!el) return;
|
|
212
|
-
el.dispatchEvent(
|
|
213
|
-
new CustomEvent(EVENTS.hide, {
|
|
214
|
-
bubbles: false,
|
|
215
|
-
detail: { type: "escape" },
|
|
216
|
-
}),
|
|
217
|
-
);
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
190
|
+
/* ── Per-document batched callbacks ────────────────────── */
|
|
220
191
|
|
|
221
|
-
|
|
222
|
-
el.dispatchEvent(
|
|
223
|
-
new CustomEvent(EVENTS.reposition, {
|
|
224
|
-
bubbles: false,
|
|
225
|
-
detail: { type },
|
|
226
|
-
}),
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
192
|
+
const trackers = new WeakMap();
|
|
230
193
|
|
|
231
|
-
function
|
|
232
|
-
|
|
233
|
-
|
|
194
|
+
function createTracker(doc) {
|
|
195
|
+
const win = doc.defaultView;
|
|
196
|
+
const ResizeObserver = win?.ResizeObserver;
|
|
234
197
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const types = [...pendingTypes];
|
|
240
|
-
pendingTypes.clear();
|
|
241
|
-
for (const type of types) notify(type);
|
|
242
|
-
tick = false;
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
tick = true;
|
|
246
|
-
}
|
|
198
|
+
const entries = new Map();
|
|
199
|
+
let resizeObserver = null;
|
|
200
|
+
let tick = false;
|
|
201
|
+
const pending = new Map();
|
|
247
202
|
|
|
248
|
-
function getResizeObserver() {
|
|
249
|
-
|
|
203
|
+
function getResizeObserver() {
|
|
204
|
+
if (resizeObserver || !ResizeObserver) return resizeObserver;
|
|
205
|
+
|
|
206
|
+
resizeObserver = new ResizeObserver((entries, observer) => {
|
|
207
|
+
for (const entry of entries) {
|
|
208
|
+
observer.unobserve(entry.target);
|
|
209
|
+
rafNotify("element-resize", entry);
|
|
210
|
+
win.requestAnimationFrame(() => {
|
|
211
|
+
if (tracker.entries.has(entry.target)) observer.observe(entry.target);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
});
|
|
250
215
|
return resizeObserver;
|
|
251
216
|
}
|
|
252
217
|
|
|
253
|
-
|
|
254
|
-
for (const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
218
|
+
function rafNotify(type, source) {
|
|
219
|
+
for (const element of entries.keys()) {
|
|
220
|
+
let notifications = pending.get(element);
|
|
221
|
+
if (!notifications) {
|
|
222
|
+
notifications = new Map();
|
|
223
|
+
pending.set(element, notifications);
|
|
224
|
+
}
|
|
225
|
+
let notification = notifications.get(type);
|
|
226
|
+
if (!notification) {
|
|
227
|
+
notification = { targets: new Set(), timeStamp: 0 };
|
|
228
|
+
notifications.set(type, notification);
|
|
229
|
+
}
|
|
230
|
+
if (source?.target) notification.targets.add(source.target);
|
|
231
|
+
notification.timeStamp = Math.max(notification.timeStamp, source?.timeStamp || 0);
|
|
232
|
+
}
|
|
233
|
+
if (!tick) {
|
|
234
|
+
win.requestAnimationFrame(() => {
|
|
235
|
+
const notifications = [...pending];
|
|
236
|
+
pending.clear();
|
|
237
|
+
for (const [element, types] of notifications) {
|
|
238
|
+
const cb = entries.get(element);
|
|
239
|
+
if (!cb || !element.isConnected) continue;
|
|
240
|
+
for (const [pendingType, detail] of types) {
|
|
241
|
+
cb({ type: pendingType, ...detail });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
tick = false;
|
|
259
245
|
});
|
|
260
246
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
247
|
+
tick = true;
|
|
248
|
+
}
|
|
264
249
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
document.addEventListener("keydown", (e) => {
|
|
269
|
-
if (e.key === "Escape" && !e.ctrlKey && !e.altKey && !e.shiftKey) {
|
|
270
|
-
if (!hasOpenSurface()) return;
|
|
271
|
-
e.preventDefault();
|
|
272
|
-
notify("escape");
|
|
273
|
-
}
|
|
250
|
+
doc.addEventListener("scroll", (e) => rafNotify(e.type, e), {
|
|
251
|
+
passive: true,
|
|
252
|
+
capture: true,
|
|
274
253
|
});
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
254
|
+
win.addEventListener("resize", (e) => rafNotify("resize", e), { passive: true });
|
|
255
|
+
|
|
256
|
+
const tracker = {
|
|
257
|
+
entries,
|
|
258
|
+
add(element, callback) {
|
|
259
|
+
entries.set(element, callback);
|
|
260
|
+
getResizeObserver()?.observe(element);
|
|
261
|
+
return () => {
|
|
262
|
+
entries.delete(element);
|
|
263
|
+
pending.delete(element);
|
|
264
|
+
resizeObserver?.unobserve(element);
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
return tracker;
|
|
279
270
|
}
|
|
280
271
|
|
|
281
|
-
|
|
272
|
+
function trackerFor(element) {
|
|
273
|
+
const doc = element.ownerDocument;
|
|
274
|
+
let tracker = trackers.get(doc);
|
|
275
|
+
if (!tracker) {
|
|
276
|
+
tracker = createTracker(doc);
|
|
277
|
+
trackers.set(doc, tracker);
|
|
278
|
+
}
|
|
279
|
+
return tracker;
|
|
280
|
+
}
|
|
282
281
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
* Returns a cleanup function that removes the element from tracking.
|
|
286
|
-
*/
|
|
287
|
-
export function track(el) {
|
|
288
|
-
tracked.add(el);
|
|
289
|
-
getResizeObserver()?.observe(el);
|
|
290
|
-
return () => {
|
|
291
|
-
tracked.delete(el);
|
|
292
|
-
resizeObserver?.unobserve(el);
|
|
293
|
-
};
|
|
282
|
+
export function autoUpdate(element, callback) {
|
|
283
|
+
return trackerFor(element).add(element, callback);
|
|
294
284
|
}
|
|
295
285
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
*
|
|
299
|
-
* @param {Element} ref
|
|
300
|
-
* @param {HTMLElement} float
|
|
301
|
-
* @param {object} [opts]
|
|
302
|
-
* @param {string} [opts.placement] default "bottom-start"
|
|
303
|
-
* @param {number} [opts.distance] px offset from reference
|
|
304
|
-
* @param {boolean} [opts.flip] flip if overflows viewport
|
|
305
|
-
* @param {boolean} [opts.shift] shift if overflows x-axis
|
|
306
|
-
* @param {number} [opts.shiftPadding] px padding when shifting
|
|
307
|
-
* @param {Element} [opts.scope] constrain to a bounding element
|
|
308
|
-
*/
|
|
286
|
+
/* ── Positioning ──────────────────────────────────────── */
|
|
287
|
+
|
|
309
288
|
export function reposition(ref, float, opts = {}) {
|
|
310
|
-
if (!isVisible(float)) return;
|
|
289
|
+
if (!isVisible(float)) return false;
|
|
311
290
|
|
|
312
291
|
const placement = opts.placement || "bottom-start";
|
|
313
292
|
const distance = opts.distance || 0;
|
|
314
293
|
const flip = opts.flip !== false;
|
|
315
294
|
const shift = opts.shift !== false;
|
|
316
|
-
const shiftPad = opts.shiftPadding
|
|
295
|
+
const shiftPad = opts.shiftPadding ?? 4;
|
|
317
296
|
const rtl = isRTL(ref);
|
|
318
297
|
|
|
319
298
|
const rects = ref.getClientRects();
|
|
320
299
|
const refRect = placement.startsWith("bottom") ? rects[rects.length - 1] : rects[0];
|
|
321
|
-
if (!refRect) return;
|
|
300
|
+
if (!refRect) return false;
|
|
322
301
|
|
|
323
302
|
const boundary = getBoundary(ref, opts);
|
|
324
|
-
if (isOutsideBoundary(refRect, boundary))
|
|
325
|
-
float.dispatchEvent(
|
|
326
|
-
new CustomEvent(EVENTS.outOfView, {
|
|
327
|
-
bubbles: false,
|
|
328
|
-
detail: { type: "out-of-view" },
|
|
329
|
-
}),
|
|
330
|
-
);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
303
|
+
if (isOutsideBoundary(refRect, boundary)) return false;
|
|
333
304
|
|
|
334
305
|
const floatRect = getFloatingSize(float);
|
|
335
306
|
const sx = boundary.x;
|
|
@@ -342,7 +313,7 @@ export function reposition(ref, float, opts = {}) {
|
|
|
342
313
|
let axis = getMainAxis(placement);
|
|
343
314
|
let current = placement;
|
|
344
315
|
let coords = computeCoords(refRect, floatRect, current, rtl);
|
|
345
|
-
applyOffset(coords, side, distance
|
|
316
|
+
applyOffset(coords, side, distance);
|
|
346
317
|
|
|
347
318
|
if (flip) {
|
|
348
319
|
const cx = Math.ceil(coords.x);
|
|
@@ -355,11 +326,9 @@ export function reposition(ref, float, opts = {}) {
|
|
|
355
326
|
side = flipSide(side);
|
|
356
327
|
current = align ? `${side}-${align}` : side;
|
|
357
328
|
coords = computeCoords(refRect, floatRect, current, rtl);
|
|
358
|
-
applyOffset(coords, side, distance
|
|
329
|
+
applyOffset(coords, side, distance);
|
|
359
330
|
}
|
|
360
331
|
|
|
361
|
-
// Narrow side placements can fit neither left nor right. In that case,
|
|
362
|
-
// fall back to top so compact mobile layouts get a usable placement.
|
|
363
332
|
if (
|
|
364
333
|
axis === "y" &&
|
|
365
334
|
(coords.x < sx || coords.x + floatRect.width > cw) &&
|
|
@@ -369,7 +338,7 @@ export function reposition(ref, float, opts = {}) {
|
|
|
369
338
|
axis = "x";
|
|
370
339
|
current = align ? `${side}-${align}` : side;
|
|
371
340
|
coords = computeCoords(refRect, floatRect, current, rtl);
|
|
372
|
-
applyOffset(coords, side, distance
|
|
341
|
+
applyOffset(coords, side, distance);
|
|
373
342
|
}
|
|
374
343
|
}
|
|
375
344
|
|
|
@@ -382,7 +351,7 @@ export function reposition(ref, float, opts = {}) {
|
|
|
382
351
|
const nextAlign = getAlignment(current) === "end" ? "start" : "end";
|
|
383
352
|
const candidatePlacement = `${side}-${nextAlign}`;
|
|
384
353
|
const candidate = computeCoords(refRect, floatRect, candidatePlacement, rtl);
|
|
385
|
-
applyOffset(candidate, side, distance
|
|
354
|
+
applyOffset(candidate, side, distance);
|
|
386
355
|
|
|
387
356
|
if (getInlineOverflow(candidate, floatRect, minX, maxX) < currentOverflow) {
|
|
388
357
|
current = candidatePlacement;
|
|
@@ -391,7 +360,6 @@ export function reposition(ref, float, opts = {}) {
|
|
|
391
360
|
}
|
|
392
361
|
}
|
|
393
362
|
|
|
394
|
-
// shift on x axis
|
|
395
363
|
let p = 50;
|
|
396
364
|
if (shift || floatRect.width > refRect.width) {
|
|
397
365
|
const minX = sx + shiftPad;
|
|
@@ -433,6 +401,8 @@ export function reposition(ref, float, opts = {}) {
|
|
|
433
401
|
left: `${coords.x}px`,
|
|
434
402
|
top: `${coords.y}px`,
|
|
435
403
|
});
|
|
404
|
+
|
|
405
|
+
return true;
|
|
436
406
|
}
|
|
437
407
|
|
|
438
408
|
export function repositionAt(x, y, float, opts = {}) {
|
|
@@ -458,5 +428,5 @@ export function repositionAt(x, y, float, opts = {}) {
|
|
|
458
428
|
],
|
|
459
429
|
};
|
|
460
430
|
|
|
461
|
-
reposition(ref, float, opts);
|
|
431
|
+
return reposition(ref, float, opts);
|
|
462
432
|
}
|