@fusion.dev/helix-core 0.241.3 → 0.242.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/custom-elements.json +1 -1
- package/dist/controllers/count-controller/count-controller.d.ts +52 -0
- package/dist/controllers/count-controller/count-controller.js +61 -0
- package/dist/controllers/hover-mark-controller/hover-mark-controller.d.ts +51 -0
- package/dist/controllers/hover-mark-controller/hover-mark-controller.js +64 -0
- package/dist/controllers/indicator-controller/indicator-controller.d.ts +10 -0
- package/dist/controllers/indicator-controller/indicator-controller.js +31 -0
- package/dist/controllers/layout-motion-controller/layout-motion-controller.d.ts +186 -0
- package/dist/controllers/layout-motion-controller/layout-motion-controller.js +284 -0
- package/dist/controllers/pointer-follow-controller/pointer-follow-controller.d.ts +41 -0
- package/dist/controllers/pointer-follow-controller/pointer-follow-controller.js +59 -0
- package/dist/helix-element/mark-rules.d.ts +19 -0
- package/dist/helix-element/mark-rules.js +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +8 -1
- package/dist/utils/arrive/arrive.d.ts +21 -0
- package/dist/utils/arrive/arrive.js +22 -0
- package/dist/utils/color-mode/color-mode.d.ts +60 -0
- package/dist/utils/color-mode/color-mode.js +95 -0
- package/dist/utils/page-transition/page-transition.d.ts +45 -0
- package/dist/utils/page-transition/page-transition.js +36 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { reducedMotion } from '../page-motion/page-motion.js';
|
|
2
|
+
export const COLOR_MODE_ATTRIBUTE = 'data-color-mode';
|
|
3
|
+
export const COLOR_TRANSITION_ATTRIBUTE = 'data-helix-color-transition';
|
|
4
|
+
let heading;
|
|
5
|
+
let turn = 0;
|
|
6
|
+
export const colorMode = () => {
|
|
7
|
+
if (typeof document === 'undefined') {
|
|
8
|
+
return 'light';
|
|
9
|
+
}
|
|
10
|
+
if (heading) {
|
|
11
|
+
return heading;
|
|
12
|
+
}
|
|
13
|
+
const written = document.documentElement.getAttribute(COLOR_MODE_ATTRIBUTE);
|
|
14
|
+
if (written === 'dark' || written === 'light') {
|
|
15
|
+
return written;
|
|
16
|
+
}
|
|
17
|
+
return typeof matchMedia === 'function' && matchMedia('(prefers-color-scheme: dark)').matches
|
|
18
|
+
? 'dark'
|
|
19
|
+
: 'light';
|
|
20
|
+
};
|
|
21
|
+
export const setColorMode = async (mode, options = {}) => {
|
|
22
|
+
if (typeof document === 'undefined') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const root = document.documentElement;
|
|
26
|
+
const apply = () => {
|
|
27
|
+
root.setAttribute(COLOR_MODE_ATTRIBUTE, mode);
|
|
28
|
+
if (root.style.colorScheme !== '') {
|
|
29
|
+
root.style.colorScheme = mode;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const transition = options.transition ?? 'circle';
|
|
33
|
+
const start = document.startViewTransition;
|
|
34
|
+
if (transition === 'none' ||
|
|
35
|
+
reducedMotion() ||
|
|
36
|
+
typeof start !== 'function' ||
|
|
37
|
+
colorMode() === mode) {
|
|
38
|
+
apply();
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const width = innerWidth;
|
|
42
|
+
const height = innerHeight;
|
|
43
|
+
const x = options.from?.x ?? width / 2;
|
|
44
|
+
const y = options.from?.y ?? height / 2;
|
|
45
|
+
const radius = Math.hypot(Math.max(x, width - x), Math.max(y, height - y));
|
|
46
|
+
root.style.setProperty('--theme-toggle-origin-x', `${x}px`);
|
|
47
|
+
root.style.setProperty('--theme-toggle-origin-y', `${y}px`);
|
|
48
|
+
root.style.setProperty('--theme-toggle-radius', `${Math.ceil(radius)}px`);
|
|
49
|
+
root.setAttribute(COLOR_TRANSITION_ATTRIBUTE, transition);
|
|
50
|
+
heading = mode;
|
|
51
|
+
turn += 1;
|
|
52
|
+
const mine = turn;
|
|
53
|
+
try {
|
|
54
|
+
const running = start.call(document, () => {
|
|
55
|
+
heading = undefined;
|
|
56
|
+
apply();
|
|
57
|
+
});
|
|
58
|
+
running.ready?.catch(() => { });
|
|
59
|
+
await running.finished.catch(() => { });
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
if (mine === turn) {
|
|
63
|
+
heading = undefined;
|
|
64
|
+
root.removeAttribute(COLOR_TRANSITION_ATTRIBUTE);
|
|
65
|
+
for (const name of [
|
|
66
|
+
'--theme-toggle-origin-x',
|
|
67
|
+
'--theme-toggle-origin-y',
|
|
68
|
+
'--theme-toggle-radius',
|
|
69
|
+
]) {
|
|
70
|
+
root.style.removeProperty(name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
export const onColorModeChange = (listener) => {
|
|
76
|
+
if (typeof document === 'undefined') {
|
|
77
|
+
return () => { };
|
|
78
|
+
}
|
|
79
|
+
let last = colorMode();
|
|
80
|
+
const heard = () => {
|
|
81
|
+
const now = colorMode();
|
|
82
|
+
if (now !== last) {
|
|
83
|
+
last = now;
|
|
84
|
+
listener(now);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const watcher = typeof MutationObserver === 'undefined' ? undefined : new MutationObserver(heard);
|
|
88
|
+
watcher?.observe(document.documentElement, { attributeFilter: [COLOR_MODE_ATTRIBUTE] });
|
|
89
|
+
const system = typeof matchMedia === 'function' ? matchMedia('(prefers-color-scheme: dark)') : undefined;
|
|
90
|
+
system?.addEventListener?.('change', heard);
|
|
91
|
+
return () => {
|
|
92
|
+
watcher?.disconnect();
|
|
93
|
+
system?.removeEventListener?.('change', heard);
|
|
94
|
+
};
|
|
95
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Changing the page in place as one page settling into the next, for a site
|
|
3
|
+
* whose router changes the page without loading a new document.
|
|
4
|
+
*
|
|
5
|
+
* A site whose links load a new document needs none of this: importing
|
|
6
|
+
* `page-transitions.css` from `@fusion.dev/helix-styles` on each page is the
|
|
7
|
+
* whole of it.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* How the page moves to the next: fading over it, sliding in from the inline
|
|
11
|
+
* end, sliding in from the inline start for a step back, or taking its place at
|
|
12
|
+
* once.
|
|
13
|
+
*/
|
|
14
|
+
export type PageTransition = 'fade' | 'none' | 'slide' | 'slide-back';
|
|
15
|
+
/**
|
|
16
|
+
* The attribute on the document element that names how the page moves, which
|
|
17
|
+
* `page-transitions.css` draws the view transition by. A page that loads a new
|
|
18
|
+
* document writes it in its markup; `changePage` writes it for the change it
|
|
19
|
+
* makes and takes it off again.
|
|
20
|
+
*/
|
|
21
|
+
export declare const PAGE_TRANSITION_ATTRIBUTE = "data-page-transition";
|
|
22
|
+
/** What `changePage` is told about how to move. */
|
|
23
|
+
export interface PageChangeOptions {
|
|
24
|
+
/**
|
|
25
|
+
* How the page moves. Where this is not given, the way the document element
|
|
26
|
+
* already names, or a fade.
|
|
27
|
+
*/
|
|
28
|
+
transition?: PageTransition;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Runs `update`, which changes the page in place, such as a router drawing the
|
|
32
|
+
* next route, as a view transition between the page before and the page
|
|
33
|
+
* after. Resolves once the move has finished, and rejects where `update` does.
|
|
34
|
+
*
|
|
35
|
+
* **Started by the page's own code, which is why Helix may offer it.** A
|
|
36
|
+
* component never starts a view transition, which draws the whole document:
|
|
37
|
+
* the page is the one owner of that. This runs one only when the page asks.
|
|
38
|
+
*
|
|
39
|
+
* `update` runs at once, with no transition, where the reader asked for
|
|
40
|
+
* reduced motion, where the browser has no view transitions, or for `none`.
|
|
41
|
+
* A change made while another is moving skips the first to where it stood.
|
|
42
|
+
* The moves themselves are drawn by `page-transitions.css`; without that sheet
|
|
43
|
+
* the browser's own fade runs.
|
|
44
|
+
*/
|
|
45
|
+
export declare const changePage: (update: () => unknown, options?: PageChangeOptions) => Promise<void>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { reducedMotion } from '../page-motion/page-motion.js';
|
|
2
|
+
export const PAGE_TRANSITION_ATTRIBUTE = 'data-page-transition';
|
|
3
|
+
let turn = 0;
|
|
4
|
+
export const changePage = async (update, options = {}) => {
|
|
5
|
+
const start = typeof document === 'undefined' ? undefined : document.startViewTransition;
|
|
6
|
+
if (options.transition === 'none' || reducedMotion() || typeof start !== 'function') {
|
|
7
|
+
await update();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const root = document.documentElement;
|
|
11
|
+
const before = root.getAttribute(PAGE_TRANSITION_ATTRIBUTE);
|
|
12
|
+
if (options.transition) {
|
|
13
|
+
root.setAttribute(PAGE_TRANSITION_ATTRIBUTE, options.transition);
|
|
14
|
+
}
|
|
15
|
+
turn += 1;
|
|
16
|
+
const mine = turn;
|
|
17
|
+
try {
|
|
18
|
+
const running = start.call(document, async () => {
|
|
19
|
+
await update();
|
|
20
|
+
});
|
|
21
|
+
running.ready.catch(() => { });
|
|
22
|
+
const finished = running.finished.catch(() => { });
|
|
23
|
+
await running.updateCallbackDone;
|
|
24
|
+
await finished;
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
if (mine === turn && options.transition) {
|
|
28
|
+
if (before === null) {
|
|
29
|
+
root.removeAttribute(PAGE_TRANSITION_ATTRIBUTE);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
root.setAttribute(PAGE_TRANSITION_ATTRIBUTE, before);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.242.0';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusion.dev/helix-core",
|
|
3
3
|
"description": "Helix element primitives: base classes, mixins, decorators, utilities.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.242.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fusion Development Group",
|
|
7
7
|
"repository": {
|
|
@@ -87,12 +87,12 @@
|
|
|
87
87
|
"bugs": "https://github.com/project-fusion/fusion/issues",
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@floating-ui/dom": "^1.8.0",
|
|
90
|
-
"@fusion.dev/helix-icons": "0.
|
|
90
|
+
"@fusion.dev/helix-icons": "0.242.0",
|
|
91
91
|
"tslib": "^2.9.1"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"@fusion.dev/helix-cem": "0.
|
|
95
|
-
"@fusion.dev/helix-testing": "0.
|
|
94
|
+
"@fusion.dev/helix-cem": "0.242.0",
|
|
95
|
+
"@fusion.dev/helix-testing": "0.242.0",
|
|
96
96
|
"@lit-labs/ssr": "^4.1.0",
|
|
97
97
|
"lit": "^3.2.1"
|
|
98
98
|
},
|