@hadoku/ui-shell 0.1.107 → 0.1.109
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/dist/motion/css.d.ts +1 -1
- package/dist/motion/css.js +23 -1
- package/dist/motion/index.d.ts +2 -2
- package/dist/motion/index.js +10 -8
- package/package.json +2 -2
package/dist/motion/css.d.ts
CHANGED
package/dist/motion/css.js
CHANGED
|
@@ -83,6 +83,7 @@ const norm = (selector) => selector.trim().replace(/\s+/g, ' ');
|
|
|
83
83
|
*/
|
|
84
84
|
function mirrorMedia(media, attr, keep, copy, topKeyframes, stills = new Set()) {
|
|
85
85
|
const copies = [];
|
|
86
|
+
const kept = [];
|
|
86
87
|
media.each((child) => {
|
|
87
88
|
if (child.type === 'rule') {
|
|
88
89
|
const rule = child;
|
|
@@ -91,6 +92,10 @@ function mirrorMedia(media, attr, keep, copy, topKeyframes, stills = new Set())
|
|
|
91
92
|
const calm = rule.clone();
|
|
92
93
|
calm.selectors = still.map((sel) => gateSelector(sel, is('data-ambient', 'off')));
|
|
93
94
|
copies.push(calm);
|
|
95
|
+
// Ambient left to the system, under this query: the still look with card motion forced on too.
|
|
96
|
+
const followed = rule.clone();
|
|
97
|
+
followed.selectors = still.map((sel) => gateSelector(sel, isNot('data-ambient', 'on')));
|
|
98
|
+
kept.push(followed);
|
|
94
99
|
}
|
|
95
100
|
const forced = rule.clone();
|
|
96
101
|
forced.selectors = rule.selectors.map((s) => gateSelector(s, is(attr, copy)));
|
|
@@ -107,6 +112,8 @@ function mirrorMedia(media, attr, keep, copy, topKeyframes, stills = new Set())
|
|
|
107
112
|
throw new Error(`${child.source?.input.file ?? 'a stylesheet'}: @${child.name} inside a prefers-reduced-motion query is not mirrored by motionCss; move it out or teach the pass`);
|
|
108
113
|
}
|
|
109
114
|
});
|
|
115
|
+
if (kept.length > 0)
|
|
116
|
+
media.append(...kept);
|
|
110
117
|
if (copies.length > 0)
|
|
111
118
|
media.after(copies);
|
|
112
119
|
}
|
|
@@ -115,8 +122,11 @@ export const motionCss = {
|
|
|
115
122
|
postcssPlugin: 'hadoku-motion',
|
|
116
123
|
// `unknown`, read as the few node methods this uses: postcss is not this package's dependency, and its own
|
|
117
124
|
// types are not structurally the slice declared above.
|
|
118
|
-
Once(sheet) {
|
|
125
|
+
Once(sheet, helpers) {
|
|
119
126
|
const root = sheet;
|
|
127
|
+
const { AtRule } = helpers;
|
|
128
|
+
// The pauses below that answer to the system's own query: no motion query of the sheet's, so not mirrored.
|
|
129
|
+
const systemPauses = new WeakSet();
|
|
120
130
|
if (!ownSheet(root.source?.input.file))
|
|
121
131
|
return;
|
|
122
132
|
const topKeyframes = new Set();
|
|
@@ -152,8 +162,20 @@ export const motionCss = {
|
|
|
152
162
|
const decl = (rule.nodes ?? []).find((n) => n.type === 'decl').clone({ prop: 'animation-play-state', value: states[states.length - 1] });
|
|
153
163
|
calm.append(decl);
|
|
154
164
|
rule.after(calm);
|
|
165
|
+
// A switch the player has not set is no attribute (`./index.ts`'s `applyMotion`), so the system's query
|
|
166
|
+
// pauses the loop itself, in the frame it changes.
|
|
167
|
+
if (inside(rule, ['media']))
|
|
168
|
+
return;
|
|
169
|
+
const followed = calm.clone();
|
|
170
|
+
followed.selectors = rule.selectors.map((s) => gateSelector(s, isNot('data-ambient', 'on')));
|
|
171
|
+
const media = new AtRule({ name: 'media', params: '(prefers-reduced-motion: reduce)' });
|
|
172
|
+
media.append(followed);
|
|
173
|
+
systemPauses.add(media);
|
|
174
|
+
calm.after(media);
|
|
155
175
|
});
|
|
156
176
|
root.walkAtRules('media', (media) => {
|
|
177
|
+
if (systemPauses.has(media))
|
|
178
|
+
return;
|
|
157
179
|
const params = media.params.trim();
|
|
158
180
|
if (REDUCE.test(params))
|
|
159
181
|
mirrorMedia(media, 'data-motion', 'full', 'reduce', topKeyframes, stills);
|
package/dist/motion/index.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ export declare function setMotionChoices(choices: MotionChoices): void;
|
|
|
24
24
|
export declare function prefersReducedMotion(): boolean;
|
|
25
25
|
/** Whether the table may shake. */
|
|
26
26
|
export declare function screenShakeAllowed(): boolean;
|
|
27
|
-
/** Writes the
|
|
28
|
-
export declare function applyMotion(root: Element,
|
|
27
|
+
/** Writes the player's switches on `root`, where the sheets' rewritten selectors (`./css.ts`) look for them, and the effective shake. */
|
|
28
|
+
export declare function applyMotion(root: Element, choices?: MotionChoices): void;
|
|
29
29
|
export declare function clearMotion(root: Element): void;
|
|
30
30
|
/** Per game (`<key>`, handed in): the choices last applied in this browser, so the first frame is drawn with them. */
|
|
31
31
|
export declare function rememberedMotion(key: string): MotionChoices | null;
|
package/dist/motion/index.js
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
*
|
|
13
13
|
* A switch nobody has set follows the system's `prefers-reduced-motion`: asked for less, all three
|
|
14
14
|
* start off. What the player sets wins either way, so a player can also turn motion ON over the OS.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* A switch the player set is written on the root the sheets resolve on, as `data-motion` (`full`/`reduce`)
|
|
16
|
+
* or `data-ambient` (`on`/`off`); one left to the system is not, so the sheets' own media query answers in
|
|
17
|
+
* the frame the system changes (an attribute written from a `change` event lags it by a frame or more:
|
|
18
|
+
* af70's flyer swayed on under reduced motion). `data-shake` is always written: script reads it.
|
|
18
19
|
*/
|
|
19
20
|
export const MOTION_ATTR = { motion: 'data-motion', shake: 'data-shake', ambient: 'data-ambient' };
|
|
20
21
|
let chosen = {};
|
|
@@ -46,11 +47,12 @@ export function prefersReducedMotion() {
|
|
|
46
47
|
export function screenShakeAllowed() {
|
|
47
48
|
return motionState().screenShake;
|
|
48
49
|
}
|
|
49
|
-
/** Writes the
|
|
50
|
-
export function applyMotion(root,
|
|
51
|
-
root.setAttribute(
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
/** Writes the player's switches on `root`, where the sheets' rewritten selectors (`./css.ts`) look for them, and the effective shake. */
|
|
51
|
+
export function applyMotion(root, choices = chosen) {
|
|
52
|
+
const set = (attr, on, yes, no) => (on === undefined ? root.removeAttribute(attr) : root.setAttribute(attr, on ? yes : no));
|
|
53
|
+
set(MOTION_ATTR.motion, choices.cardMotion, 'full', 'reduce');
|
|
54
|
+
set(MOTION_ATTR.ambient, choices.ambientMotion, 'on', 'off');
|
|
55
|
+
root.setAttribute(MOTION_ATTR.shake, motionState(choices).screenShake ? 'on' : 'off');
|
|
54
56
|
}
|
|
55
57
|
export function clearMotion(root) {
|
|
56
58
|
for (const attr of Object.values(MOTION_ATTR))
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/ui-shell",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.109",
|
|
4
|
+
"gitHead": "39955f54177a81818c694b4e98cd509154171347",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The parts of a game's UI any game keeps: chrome, trim, room shell, embed mount, theme and settings frame, UI scale, usage counting, the sound mixer, motion and generic components. One appId parameterizes its storage keys, events and chat prefix. MIT; imports only react, react-dom and @wolffm/*.",
|