@heyramzi/ui 2.15.0 → 2.15.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/dist/lib/motion.js +22 -0
- package/package.json +1 -1
- package/src/lib/motion.ts +26 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion tokens for code that needs a number: a Svelte `flip`, `slide` or `fade`, a timer. The
|
|
3
|
+
* CSS in `tokens/craft.css` owns the values; these mirror it for the server render and for a
|
|
4
|
+
* page that never loaded the tokens.
|
|
5
|
+
*/
|
|
6
|
+
export const DURATION_MS = {
|
|
7
|
+
quick: 150,
|
|
8
|
+
fast: 250,
|
|
9
|
+
slow: 300
|
|
10
|
+
};
|
|
11
|
+
/** A duration token in ms, read off a mounted element; both `ms` and `s` parse. */
|
|
12
|
+
export function tokenMs(el, name, fallback) {
|
|
13
|
+
const raw = getComputedStyle(el).getPropertyValue(name).trim();
|
|
14
|
+
const n = Number.parseFloat(raw);
|
|
15
|
+
if (Number.isNaN(n)) return fallback;
|
|
16
|
+
return raw.endsWith("ms") ? n : n * 1e3;
|
|
17
|
+
}
|
|
18
|
+
/** `--duration-<token>` in ms off the root, so a token edit retimes the JS motion too. */
|
|
19
|
+
export function durationMs(token) {
|
|
20
|
+
if (typeof document === "undefined") return DURATION_MS[token];
|
|
21
|
+
return tokenMs(document.documentElement, `--duration-${token}`, DURATION_MS[token]);
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heyramzi/ui",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.1",
|
|
4
4
|
"description": "Svelte 5 UI for apps: primitives, effects and animations, plus work (tasks and docs), charts, slides, an editor, onboarding and a canvas as subpaths.",
|
|
5
5
|
"homepage": "https://ui.heyramzi.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion tokens for code that needs a number: a Svelte `flip`, `slide` or `fade`, a timer. The
|
|
3
|
+
* CSS in `tokens/craft.css` owns the values; these mirror it for the server render and for a
|
|
4
|
+
* page that never loaded the tokens.
|
|
5
|
+
*/
|
|
6
|
+
export const DURATION_MS = {
|
|
7
|
+
quick: 150,
|
|
8
|
+
fast: 250,
|
|
9
|
+
slow: 300,
|
|
10
|
+
} as const;
|
|
11
|
+
|
|
12
|
+
export type DurationToken = keyof typeof DURATION_MS;
|
|
13
|
+
|
|
14
|
+
/** A duration token in ms, read off a mounted element; both `ms` and `s` parse. */
|
|
15
|
+
export function tokenMs(el: Element, name: string, fallback: number): number {
|
|
16
|
+
const raw = getComputedStyle(el).getPropertyValue(name).trim();
|
|
17
|
+
const n = Number.parseFloat(raw);
|
|
18
|
+
if (Number.isNaN(n)) return fallback;
|
|
19
|
+
return raw.endsWith("ms") ? n : n * 1000;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** `--duration-<token>` in ms off the root, so a token edit retimes the JS motion too. */
|
|
23
|
+
export function durationMs(token: DurationToken): number {
|
|
24
|
+
if (typeof document === "undefined") return DURATION_MS[token];
|
|
25
|
+
return tokenMs(document.documentElement, `--duration-${token}`, DURATION_MS[token]);
|
|
26
|
+
}
|