actual-css 0.15.0 → 0.16.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 +37 -0
- package/README.md +10 -7
- package/components.json +44 -1
- package/dist/actual.full.css +130 -9
- package/dist/actual.full.js +1 -1
- package/dist/actual.full.min.css +1 -1
- package/docs/design-notes/architecture.md +3 -0
- package/docs/design-notes/enhancement-contract.md +25 -3
- package/docs/design-notes/naming.md +6 -0
- package/docs/design-notes/steps.md +13 -2
- package/docs/design-notes/tokens.md +159 -0
- package/docs/pages/components/avatar.md +10 -0
- package/docs/pages/components/bleed.md +4 -0
- package/docs/pages/components/button.md +27 -7
- package/docs/pages/components/card.md +12 -7
- package/docs/pages/components/dialog.md +26 -0
- package/docs/pages/components/rating.md +29 -5
- package/docs/pages/components/steps.md +32 -16
- package/docs/pages/enhancements/overview.md +13 -20
- package/docs/pages/enhancements/status-bar.md +7 -9
- package/docs/pages/enhancements/tabs.md +11 -15
- package/docs/pages/enhancements/tooltip.md +10 -19
- package/docs/pages/forms/choice-cards.md +2 -1
- package/docs/pages/forms/joined-controls.md +4 -2
- package/docs/pages/forms/overview.md +1 -0
- package/docs/pages/foundations/philosophy.md +26 -62
- package/docs/pages/foundations/theming.md +21 -36
- package/docs/pages/foundations/tokens.md +91 -159
- package/docs/pages/guides/integrating-actual-css.md +1 -1
- package/docs/pages/guides/introduction.md +14 -14
- package/docs/pages/guides/progressive-enhancement.md +22 -0
- package/docs/pages/guides/upgrading.md +2 -2
- package/docs/pages/layout/choosing.md +28 -20
- package/docs/pages/layout/grid.md +8 -16
- package/docs/pages/patterns/intent-nesting.md +13 -1
- package/llms.txt +2 -1
- package/package.json +5 -3
- package/skills/actual-css/SKILL.md +5 -4
- package/skills/actual-css/references/api-and-vocabulary.md +2 -1
- package/src/css/components/app-nav.css +2 -0
- package/src/css/components/avatar.css +4 -2
- package/src/css/components/card.css +1 -1
- package/src/css/components/menu.css +2 -0
- package/src/css/components/rating.css +66 -0
- package/src/css/core/base.css +10 -1
- package/src/css/core/reset.css +5 -0
- package/src/css/core/theme.css +4 -1
- package/src/css/core/tokens.css +8 -2
- package/src/css/forms/form.css +15 -1
- package/src/css/forms/range.css +11 -1
- package/src/css/layout/measure.css +2 -0
- package/src/js/dialog.js +40 -9
- package/src/js/enhance.js +16 -3
- package/tokens.json +117 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# Grid
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
column count.
|
|
3
|
+
Choose what determines the column count:
|
|
5
4
|
|
|
6
5
|
- The **item width** is what matters — use `.grid` and tune `--grid-min`.
|
|
7
6
|
- The **column density** is what matters — use `.grid-2`, `.grid-3`, `.grid-4`,
|
|
@@ -30,9 +29,8 @@ Tune the item minimum with `--grid-min`.
|
|
|
30
29
|
|
|
31
30
|
## Count-driven density
|
|
32
31
|
|
|
33
|
-
`.grid-N`
|
|
34
|
-
|
|
35
|
-
width.
|
|
32
|
+
`.grid-N` fits up to N equal-width columns and reduces the count as space
|
|
33
|
+
narrows. It is responsive without a container wrapper.
|
|
36
34
|
|
|
37
35
|
```html demo resize
|
|
38
36
|
<div class="grid-4">
|
|
@@ -43,8 +41,7 @@ width.
|
|
|
43
41
|
</div>
|
|
44
42
|
```
|
|
45
43
|
|
|
46
|
-
`--grid-min`
|
|
47
|
-
density is `.grid-N`'s. Choose the preset that suits your item size:
|
|
44
|
+
`--grid-min` applies only to `.grid`. Choose a preset that suits your item size:
|
|
48
45
|
|
|
49
46
|
| Item | Preset |
|
|
50
47
|
| --------------------------------- | -------------------- |
|
|
@@ -111,15 +108,10 @@ that width **plus its own padding and borders**:
|
|
|
111
108
|
Round up past the figure rather than matching it exactly, so a later padding
|
|
112
109
|
change cannot drop the region a state.
|
|
113
110
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
to that name, never to an incidental query container, so a region that sets
|
|
119
|
-
`container-type: inline-size` for its own reasons leaves the grid untouched. The container has to be an
|
|
120
|
-
ancestor: an element cannot query its own size without taking inline-size
|
|
121
|
-
containment, which would collapse the grid inside a `.cluster`, a float, or any
|
|
122
|
-
shrink-to-fit box. Put it on a normal block-level wrapper for the same reason.
|
|
111
|
+
Use a normal block-level ancestor as the named container, keeping it separate
|
|
112
|
+
from the grid. Only the name `actual-container` enables balanced subdivision;
|
|
113
|
+
an unnamed query container leaves the baseline behavior unchanged. The same
|
|
114
|
+
named container can serve both a grid and a step flow.
|
|
123
115
|
|
|
124
116
|
The chain balances the **declared density**, not your actual item count. Eight
|
|
125
117
|
items in `.grid-6` still give `6 + 2`. For a paginated collection, choose a page
|
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
# Intent Nesting
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An intent applies to the component carrying it. Nested components keep their
|
|
4
|
+
own default intent unless you give them one:
|
|
5
|
+
|
|
6
|
+
```html
|
|
7
|
+
<div class="alert danger">
|
|
8
|
+
Something went wrong.
|
|
9
|
+
<button class="btn" type="button">Dismiss</button>
|
|
10
|
+
<button class="btn primary" type="button">Retry</button>
|
|
11
|
+
</div>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The alert uses danger colors, Dismiss stays neutral, and Retry uses primary.
|
|
15
|
+
Set an intent on each component that needs it.
|
package/llms.txt
CHANGED
|
@@ -17,7 +17,8 @@ Actual CSS uses a small public grammar: `.component [intent] [variant] [size] [m
|
|
|
17
17
|
- `actual-css/js` — the enhancement-loader entry only: it watches `data-enhance-modules` manifest blocks and imports the declared enhancers on demand.
|
|
18
18
|
- `actual-css/js/full` — the complete runtime with all built-in enhancers pre-registered.
|
|
19
19
|
- `actual-css/reserved-classes.json` — machine-readable list of the framework-owned class namespace. Use it to check whether a class belongs to Actual CSS and to validate claimed framework classes; application-specific classes are expected to exist outside this manifest.
|
|
20
|
-
- `actual-css/components.json` — machine-readable component index, derived from the sources (CSS headers, selectors, package exports, `src/js`) by `scripts/build-catalog.js` and verified by `check:catalog`. Gives each component its import paths, owned classes, hooks, states,
|
|
20
|
+
- `actual-css/components.json` — machine-readable component index, derived from the sources (CSS headers, selectors, package exports, `src/js`) by `scripts/build-catalog.js` and verified by `check:catalog`. Gives each component its import paths, owned classes, hooks, states, registered enhancement tokens, and published `docs` URL — enough to know what exists and where to read more, not a replacement for the docs pages.
|
|
21
|
+
- `actual-css/tokens.json` — the public global tokens (`global`), derived by the same script from `src/css/core`. Use it to check that a `var(--…)` outside a component exists; component hooks are in `components.json`.
|
|
21
22
|
- [Starter agent skill](skills/actual-css/SKILL.md) — a copyable skill for building with Actual CSS (vocabulary, hooks, layouts, enhancements); consuming projects extend it with a local `PROJECT.md`.
|
|
22
23
|
- Individual families and modules are importable separately (`actual-css/css/components`, `actual-css/css/layout/grid`, `actual-css/js/dialog`, …); see [README](README.md) and [Modular imports](docs/pages/guides/modular-import.md).
|
|
23
24
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "actual-css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Plain CSS component framework with semantic classes, universal variants, small tokens, theme hooks, and progressive enhancements.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"packageManager": "bun@1.4.
|
|
6
|
+
"packageManager": "bun@1.4.4",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "Thomas <thomas@lekoala.be>",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/lekoala/actual-css.git"
|
|
12
12
|
},
|
|
13
|
-
"homepage": "https://lekoala.github.io/actual-css/",
|
|
13
|
+
"homepage": "https://lekoala.github.io/actual-css/site/",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/lekoala/actual-css/issues"
|
|
16
16
|
},
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"./js/surface": "./src/js/surface.js",
|
|
77
77
|
"./reserved-classes.json": "./reserved-classes.json",
|
|
78
78
|
"./components.json": "./components.json",
|
|
79
|
+
"./tokens.json": "./tokens.json",
|
|
79
80
|
"./package.json": "./package.json"
|
|
80
81
|
},
|
|
81
82
|
"bin": {
|
|
@@ -100,6 +101,7 @@
|
|
|
100
101
|
"src/tooling",
|
|
101
102
|
"reserved-classes.json",
|
|
102
103
|
"components.json",
|
|
104
|
+
"tokens.json",
|
|
103
105
|
"docs",
|
|
104
106
|
"skills",
|
|
105
107
|
"CHANGELOG.md",
|
|
@@ -15,11 +15,12 @@ The target is not zero application CSS. The target is:
|
|
|
15
15
|
|
|
16
16
|
Actual CSS may evolve between releases. Resolve uncertain API from the version used by the current project, in this order:
|
|
17
17
|
|
|
18
|
-
1. `actual-css/components.json` — component index: classes, public hooks, states, CSS/JS imports, enhancement tokens.
|
|
18
|
+
1. `actual-css/components.json` — component index: classes, public hooks, states, CSS/JS imports, enhancement tokens, docs URL.
|
|
19
19
|
2. `actual-css/reserved-classes.json` — framework-owned class namespace.
|
|
20
|
-
3. `actual-css/
|
|
21
|
-
4. `actual-css/
|
|
22
|
-
5. `actual-css/
|
|
20
|
+
3. `actual-css/tokens.json` — public global tokens; a `var(--…)` outside a component should be one of them.
|
|
21
|
+
4. `actual-css/package.json#exports` — canonical package entrypoints.
|
|
22
|
+
5. `actual-css/src/css/` and `actual-css/src/js/` — exact selectors, defaults, state ownership, and runtime behavior.
|
|
23
|
+
6. `actual-css/docs/` and `actual-css/llms.txt` — intended usage and concise architecture guidance.
|
|
23
24
|
|
|
24
25
|
If this skill was copied into a consuming project, the installed package wins over examples or summaries in this skill.
|
|
25
26
|
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
Use the installed version rather than guessing from names:
|
|
6
6
|
|
|
7
|
-
- `components.json` — component classes, hooks, states, CSS/JS imports, enhancement tokens.
|
|
7
|
+
- `components.json` — component classes, hooks, states, CSS/JS imports, enhancement tokens, docs URL.
|
|
8
8
|
- `reserved-classes.json` — whether Actual CSS owns a class name.
|
|
9
|
+
- `tokens.json` — public global tokens (`--space-40`, `--shadow`, `--primary`…).
|
|
9
10
|
- `package.json#exports` — supported package entrypoints.
|
|
10
11
|
- CSS/JS source — exact behavior and defaults.
|
|
11
12
|
- docs / `llms.txt` — intended usage and framework map.
|
|
@@ -57,6 +57,8 @@
|
|
|
57
57
|
text-align: center;
|
|
58
58
|
text-decoration: none;
|
|
59
59
|
overflow-wrap: anywhere;
|
|
60
|
+
/* A rounded tile: opt out of the bare-link tap flash from base.css. */
|
|
61
|
+
-webkit-tap-highlight-color: transparent;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
.app-nav > a > :where(svg, img, [aria-hidden="true"]) {
|
|
@@ -176,9 +176,11 @@ a.avatar[aria-disabled="true"] {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
/* Avatar stack — explicit class for overlapping avatar groups.
|
|
179
|
-
Does not rely on role="group" auto-detection.
|
|
179
|
+
Does not rely on role="group" auto-detection.
|
|
180
|
+
why an eighth: two-letter initials span most of the disc, so a quarter
|
|
181
|
+
overlap (plus the ring) cut the second letter at every size. */
|
|
180
182
|
.avatar-stack {
|
|
181
|
-
--avatar-stack-overlap: calc(var(--avatar-stack-size, 2.25rem) / -
|
|
183
|
+
--avatar-stack-overlap: calc(var(--avatar-stack-size, 2.25rem) / -8);
|
|
182
184
|
--avatar-stack-ring: 2px;
|
|
183
185
|
|
|
184
186
|
display: inline-flex;
|
|
@@ -7,12 +7,22 @@
|
|
|
7
7
|
* fills preceding stars without reversing DOM or keyboard order. Forced
|
|
8
8
|
* colors restores the platform radio presentation.
|
|
9
9
|
*
|
|
10
|
+
* Read-only display: .rating[role="img"] is one element with no inputs, named
|
|
11
|
+
* by its aria-label. role="img" is the switch on purpose: an unnamed display
|
|
12
|
+
* draws nothing rather than stars no assistive technology can read.
|
|
13
|
+
*
|
|
10
14
|
* Public hooks:
|
|
11
15
|
* --rating-size
|
|
12
16
|
* --rating-gap
|
|
13
17
|
* --rating-color
|
|
14
18
|
* --rating-empty
|
|
15
19
|
* --rating-star
|
|
20
|
+
* --rating-value (display: the shown value, fractions allowed)
|
|
21
|
+
* --rating-max (display: the number of stars)
|
|
22
|
+
*
|
|
23
|
+
* Internal:
|
|
24
|
+
* --rating-fill
|
|
25
|
+
* --rating-direction
|
|
16
26
|
*/
|
|
17
27
|
:where(.rating) {
|
|
18
28
|
--intent: initial;
|
|
@@ -82,6 +92,49 @@
|
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
|
|
95
|
+
/* Each star takes the same size + gap cell as a radio, so a display and an
|
|
96
|
+
input of the same size line up. The fill is a share of the whole row, which
|
|
97
|
+
makes a fractional value a partial star. */
|
|
98
|
+
.rating[role="img"] {
|
|
99
|
+
--rating-value: 0;
|
|
100
|
+
--rating-max: 5;
|
|
101
|
+
--rating-fill: calc(var(--rating-value) / var(--rating-max) * 100%);
|
|
102
|
+
--rating-direction: to right;
|
|
103
|
+
|
|
104
|
+
inline-size: calc(var(--rating-max) * (var(--rating-size) + var(--rating-gap)));
|
|
105
|
+
block-size: var(--rating-size);
|
|
106
|
+
vertical-align: middle;
|
|
107
|
+
background: linear-gradient(
|
|
108
|
+
var(--rating-direction),
|
|
109
|
+
var(--rating-color) var(--rating-fill),
|
|
110
|
+
var(--rating-empty) var(--rating-fill)
|
|
111
|
+
);
|
|
112
|
+
-webkit-mask:
|
|
113
|
+
var(--rating-star) left center / calc(var(--rating-size) + var(--rating-gap)) var(--rating-size)
|
|
114
|
+
repeat-x;
|
|
115
|
+
mask:
|
|
116
|
+
var(--rating-star) left center / calc(var(--rating-size) + var(--rating-gap)) var(--rating-size)
|
|
117
|
+
repeat-x;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/* The fill starts at the inline start; only the direction changes, so the
|
|
121
|
+
forced-colors gradient below follows it too. Safari before 16.4 has no
|
|
122
|
+
:dir(); the attribute path is its fallback, as in avatar.css. Each selector
|
|
123
|
+
is its own rule: a browser that rejects :dir() drops the whole rule, and the
|
|
124
|
+
:dir() rules come after the fallback so a nested LTR island beats an outer
|
|
125
|
+
[dir="rtl"] at equal specificity. */
|
|
126
|
+
[dir="rtl"] .rating[role="img"] {
|
|
127
|
+
--rating-direction: to left;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.rating[role="img"]:dir(ltr) {
|
|
131
|
+
--rating-direction: to right;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.rating[role="img"]:dir(rtl) {
|
|
135
|
+
--rating-direction: to left;
|
|
136
|
+
}
|
|
137
|
+
|
|
85
138
|
.rating.sm {
|
|
86
139
|
--rating-size: 1rem;
|
|
87
140
|
}
|
|
@@ -100,4 +153,17 @@
|
|
|
100
153
|
mask: none;
|
|
101
154
|
opacity: 1;
|
|
102
155
|
}
|
|
156
|
+
|
|
157
|
+
/* why: forced colors drops the gradient, and the filled share is the value
|
|
158
|
+
itself, so the display would vanish. It keeps the gradient, painted in the
|
|
159
|
+
user's own system colors only: Highlight for the value, as progress and
|
|
160
|
+
range do, GrayText for the empty stars. */
|
|
161
|
+
.rating[role="img"] {
|
|
162
|
+
forced-color-adjust: none;
|
|
163
|
+
background: linear-gradient(
|
|
164
|
+
var(--rating-direction),
|
|
165
|
+
Highlight var(--rating-fill),
|
|
166
|
+
GrayText var(--rating-fill)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
103
169
|
}
|
package/src/css/core/base.css
CHANGED
|
@@ -26,10 +26,19 @@ a {
|
|
|
26
26
|
text-underline-offset: 0.18em;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
/* :active stands in for the native tap highlight the reset removes. */
|
|
30
|
+
a:is(:hover, :active) {
|
|
30
31
|
text-decoration-thickness: 0.12em;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/* Bare text links get back the tap flash the reset removes: a text link has
|
|
35
|
+
no pressed state of its own. Tinted from the link ink so it reads on any
|
|
36
|
+
surface. Zero specificity so a component styling classless anchors (an
|
|
37
|
+
.app-nav tile) can opt out with transparent. */
|
|
38
|
+
:where(a[href]:not([class])) {
|
|
39
|
+
-webkit-tap-highlight-color: color-mix(in oklab, currentColor 18%, transparent);
|
|
40
|
+
}
|
|
41
|
+
|
|
33
42
|
/* Global heading chrome: color (--heading or inherit), a tight line-height,
|
|
34
43
|
and progressive text-wrap. No font-size or font-weight is set globally —
|
|
35
44
|
components and .prose own the per-context scale. */
|
package/src/css/core/reset.css
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
html {
|
|
9
9
|
-webkit-text-size-adjust: 100%;
|
|
10
|
+
/* The native tap highlight is a rectangle that ignores border-radius and
|
|
11
|
+
custom surfaces; components use their own interaction states where
|
|
12
|
+
relevant. Inherited, so one declaration covers every element; base.css
|
|
13
|
+
restores a tinted flash on bare text links. */
|
|
14
|
+
-webkit-tap-highlight-color: transparent;
|
|
10
15
|
}
|
|
11
16
|
|
|
12
17
|
body {
|
package/src/css/core/theme.css
CHANGED
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
* translucent surfaces overrides them with opaque values. --border-control is
|
|
12
12
|
* public too: the resting edge of a neutral control, apart from structural
|
|
13
13
|
* separators. --control-default-bg is the inherited resting field fill.
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* Internal:
|
|
16
|
+
* --hgroup-gap
|
|
17
|
+
* --surface-link (link ink relay a painted surface sets; reset at boundaries)
|
|
15
18
|
*/
|
|
16
19
|
:root {
|
|
17
20
|
color-scheme: light dark;
|
package/src/css/core/tokens.css
CHANGED
|
@@ -8,8 +8,14 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Derived: "Theme-derived aliases" and "State tokens" reference intent and
|
|
10
10
|
* surface tokens and follow the theme; do not hard-code values into them.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Every token declared here is listed in tokens.json except these, which
|
|
13
|
+
* components consume but authors do not set:
|
|
14
|
+
*
|
|
15
|
+
* Internal:
|
|
16
|
+
* --indicator-offset
|
|
17
|
+
* --indicator-ring
|
|
18
|
+
* --disabled-opacity
|
|
13
19
|
*
|
|
14
20
|
* Component-local hooks and internal state relays live with their
|
|
15
21
|
* components. See docs/pages/foundations/tokens.md for the public/internal
|
package/src/css/forms/form.css
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* component cannot know whether its siblings are stacked or gridded.
|
|
12
12
|
*
|
|
13
13
|
* Public API: .field, .field-label, .field-help, .field-error, .field-group,
|
|
14
|
-
* .required-mark.
|
|
14
|
+
* .field-group.flush, .required-mark.
|
|
15
15
|
*
|
|
16
16
|
* Public hooks:
|
|
17
17
|
* --fieldset-legend-padding-inline
|
|
@@ -49,6 +49,20 @@
|
|
|
49
49
|
font-size: var(--font-size-xs);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/* Flush — the frame removed, for a group that already sits in a card or a
|
|
53
|
+
form section. With no border to notch, the legend is a plain label above
|
|
54
|
+
the options: no gutter, and the .field label-to-control gap below it. */
|
|
55
|
+
.field-group.flush {
|
|
56
|
+
padding: 0;
|
|
57
|
+
border: 0;
|
|
58
|
+
border-radius: 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.field-group.flush > legend {
|
|
62
|
+
margin-block-end: var(--space-10);
|
|
63
|
+
padding-inline: 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
52
66
|
.field-help {
|
|
53
67
|
color: var(--text-muted);
|
|
54
68
|
font-size: 0.875em;
|
package/src/css/forms/range.css
CHANGED
|
@@ -46,7 +46,17 @@
|
|
|
46
46
|
cursor: pointer;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
:
|
|
49
|
+
/* Separate rules: a browser without :dir() drops a whole rule that names it,
|
|
50
|
+
which took the [dir="rtl"] fallback with it. The :dir() pair outranks the
|
|
51
|
+
fallback, so an LTR island inside an RTL region keeps filling from the left. */
|
|
52
|
+
:where([dir="rtl"]) .range {
|
|
53
|
+
--range-fill-from: to left;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.range:dir(ltr) {
|
|
57
|
+
--range-fill-from: to right;
|
|
58
|
+
}
|
|
59
|
+
|
|
50
60
|
.range:dir(rtl) {
|
|
51
61
|
--range-fill-from: to left;
|
|
52
62
|
}
|
package/src/js/dialog.js
CHANGED
|
@@ -28,12 +28,13 @@
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
import { registerCommands, targetFor } from "./command.js";
|
|
31
|
-
import enhance from "./enhance.js";
|
|
31
|
+
import enhance, { registerEnhancement } from "./enhance.js";
|
|
32
32
|
import { EVENTS } from "./events.js";
|
|
33
33
|
import { CLASSES } from "./selectors.js";
|
|
34
34
|
|
|
35
35
|
const dialogMap = new WeakMap();
|
|
36
36
|
const wiredDialogs = new Set();
|
|
37
|
+
const delegatedDialogs = new WeakSet();
|
|
37
38
|
// HTML has no non-modal dialog keyword, so non-modal opening is the custom
|
|
38
39
|
// `--show` command.
|
|
39
40
|
const DIALOG_COMMANDS = ["show-modal", "--show", "request-close", "close"];
|
|
@@ -46,6 +47,18 @@ function isDialogElement(el) {
|
|
|
46
47
|
return el?.nodeType === 1 && el.localName === "dialog";
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
function allowsDialogEnhancement(dialog) {
|
|
51
|
+
if (delegatedDialogs.has(dialog) || dialog.matches('[data-enhance~="dialog"]')) return true;
|
|
52
|
+
|
|
53
|
+
// Shadow roots and light-DOM custom elements own their dialogs, including
|
|
54
|
+
// hosts that have not upgraded yet. Avoid realm-dependent instanceof checks.
|
|
55
|
+
if (dialog.getRootNode().host) return false;
|
|
56
|
+
for (let parent = dialog.parentElement; parent; parent = parent.parentElement) {
|
|
57
|
+
if (parent.localName.includes("-")) return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
49
62
|
function boolData(el, name) {
|
|
50
63
|
return el.hasAttribute(name) && el.getAttribute(name) !== "false";
|
|
51
64
|
}
|
|
@@ -270,7 +283,7 @@ function finishClose(dialog, returnValue = "") {
|
|
|
270
283
|
export function closeDialog(dialog, returnValue = "") {
|
|
271
284
|
if (!isDialogElement(dialog) || !dialog.open) return;
|
|
272
285
|
|
|
273
|
-
const state =
|
|
286
|
+
const state = ensureDelegatedDialog(dialog);
|
|
274
287
|
if (state.closing) return;
|
|
275
288
|
|
|
276
289
|
const trigger = state.restoreFocusTo;
|
|
@@ -299,7 +312,7 @@ export function closeDialog(dialog, returnValue = "") {
|
|
|
299
312
|
export function requestDialogClose(dialog, returnValue = "") {
|
|
300
313
|
if (!isDialogElement(dialog) || !dialog.open) return;
|
|
301
314
|
|
|
302
|
-
const state =
|
|
315
|
+
const state = ensureDelegatedDialog(dialog);
|
|
303
316
|
state.returnValue = returnValue;
|
|
304
317
|
state.requestingClose = true;
|
|
305
318
|
try {
|
|
@@ -317,7 +330,7 @@ export function requestDialogClose(dialog, returnValue = "") {
|
|
|
317
330
|
export function openDialog(dialog, trigger = null, forcedModal = null) {
|
|
318
331
|
if (!isDialogElement(dialog) || dialog.open || !dialog.isConnected) return;
|
|
319
332
|
|
|
320
|
-
const state =
|
|
333
|
+
const state = ensureDelegatedDialog(dialog);
|
|
321
334
|
const modal = resolveModalMode(dialog, forcedModal);
|
|
322
335
|
syncDialogSemantics(dialog, state, modal);
|
|
323
336
|
|
|
@@ -497,6 +510,18 @@ function ensureDialogWired(dialog) {
|
|
|
497
510
|
|
|
498
511
|
function connectDialog(dialog) {
|
|
499
512
|
ensureDialogWired(dialog);
|
|
513
|
+
return () => disconnectDialog(dialog);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
function ensureDelegatedDialog(dialog) {
|
|
517
|
+
const state = ensureDialogWired(dialog);
|
|
518
|
+
if (!allowsDialogEnhancement(dialog)) {
|
|
519
|
+
delegatedDialogs.add(dialog);
|
|
520
|
+
// Direct API calls delegate ownership too. Enroll light DOM dialogs in
|
|
521
|
+
// document cleanup; shadow-root lifecycles remain application-owned.
|
|
522
|
+
if (dialog.getRootNode() === dialog.ownerDocument) dialogRuntime.refresh(dialog);
|
|
523
|
+
}
|
|
524
|
+
return state;
|
|
500
525
|
}
|
|
501
526
|
|
|
502
527
|
function disconnectDialog(dialog) {
|
|
@@ -512,6 +537,7 @@ function disconnectDialog(dialog) {
|
|
|
512
537
|
restoreOwnedAttributes(state);
|
|
513
538
|
state.modalOpen = false;
|
|
514
539
|
dialogMap.delete(dialog);
|
|
540
|
+
delegatedDialogs.delete(dialog);
|
|
515
541
|
wiredDialogs.delete(dialog);
|
|
516
542
|
syncModalOpenClass(dialog.ownerDocument);
|
|
517
543
|
}
|
|
@@ -519,7 +545,7 @@ function disconnectDialog(dialog) {
|
|
|
519
545
|
registerCommands(DIALOG_COMMANDS, {
|
|
520
546
|
resolve: (trigger) => {
|
|
521
547
|
const dialog = targetFor(trigger);
|
|
522
|
-
return isDialogElement(dialog) ? dialog : null;
|
|
548
|
+
return isDialogElement(dialog) && allowsDialogEnhancement(dialog) ? dialog : null;
|
|
523
549
|
},
|
|
524
550
|
handle: (_event, trigger, dialog, command) => {
|
|
525
551
|
// A dialog inserted since the last enhance() pass is wired on first use.
|
|
@@ -541,9 +567,14 @@ registerCommands(DIALOG_COMMANDS, {
|
|
|
541
567
|
},
|
|
542
568
|
});
|
|
543
569
|
|
|
544
|
-
enhance(
|
|
545
|
-
|
|
546
|
-
connectDialog
|
|
547
|
-
return () => disconnectDialog(dialog);
|
|
570
|
+
const dialogRuntime = enhance(
|
|
571
|
+
{
|
|
572
|
+
[DIALOG_SELECTOR]: connectDialog,
|
|
548
573
|
},
|
|
574
|
+
undefined,
|
|
575
|
+
{ accept: allowsDialogEnhancement },
|
|
576
|
+
);
|
|
577
|
+
|
|
578
|
+
registerEnhancement("dialog", (dialog) => {
|
|
579
|
+
if (isDialogElement(dialog)) return connectDialog(dialog);
|
|
549
580
|
});
|
package/src/js/enhance.js
CHANGED
|
@@ -73,6 +73,12 @@ function createRegistry(root) {
|
|
|
73
73
|
let discovery = "";
|
|
74
74
|
|
|
75
75
|
function start(record, el) {
|
|
76
|
+
// Shared discovery also visits the scan root and other records' matches.
|
|
77
|
+
if (record.accept && !record.keys.some((key) => el.matches(key))) return;
|
|
78
|
+
if (record.accept && !record.accept(el)) {
|
|
79
|
+
stop(record, el);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
76
82
|
let active = record.instances.get(el);
|
|
77
83
|
for (const key of record.keys) {
|
|
78
84
|
if (active?.has(key) || !el.matches(key)) continue;
|
|
@@ -115,7 +121,9 @@ function createRegistry(root) {
|
|
|
115
121
|
function sweepDisconnected() {
|
|
116
122
|
for (const record of records) {
|
|
117
123
|
for (const el of Array.from(record.instances.keys())) {
|
|
118
|
-
if (!el.isConnected || !root.contains(el)
|
|
124
|
+
if (!el.isConnected || !root.contains(el) || (record.accept && !record.accept(el))) {
|
|
125
|
+
stop(record, el);
|
|
126
|
+
}
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
}
|
|
@@ -254,9 +262,14 @@ export function registerEnhancement(name, init, root) {
|
|
|
254
262
|
/**
|
|
255
263
|
* @param {Record<string, (el: Element) => (() => void) | void>} enhancers
|
|
256
264
|
* @param {Document | Element | DocumentFragment} [root]
|
|
265
|
+
* @param {object} [options]
|
|
266
|
+
* @param {(el: Element) => boolean} [options.accept] Lifecycle eligibility, rechecked on moves.
|
|
257
267
|
* @returns {{ refresh: (node: Node) => void, disconnect: () => void }}
|
|
258
268
|
*/
|
|
259
|
-
export default function enhance(enhancers, root) {
|
|
269
|
+
export default function enhance(enhancers, root, { accept } = {}) {
|
|
270
|
+
if (accept !== undefined && typeof accept !== "function") {
|
|
271
|
+
throw new TypeError("enhance() requires a function accept predicate.");
|
|
272
|
+
}
|
|
260
273
|
if (typeof document === "undefined") return noopRuntime();
|
|
261
274
|
|
|
262
275
|
root ??= document.documentElement;
|
|
@@ -272,5 +285,5 @@ export default function enhance(enhancers, root) {
|
|
|
272
285
|
});
|
|
273
286
|
if (!keys.length) return noopRuntime();
|
|
274
287
|
|
|
275
|
-
return registryFor(root).add({ keys, enhancers, query: keys.join(",") });
|
|
288
|
+
return registryFor(root).add({ keys, enhancers, query: keys.join(","), accept });
|
|
276
289
|
}
|