@weser/keyframes 1.0.0 → 1.0.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/README.md +1 -1
- package/dist/createStyleNode.d.ts +0 -1
- package/dist/src/createKeyframe.d.ts +5 -0
- package/dist/src/createKeyframe.js +9 -0
- package/dist/src/createKeyframes.d.ts +5 -0
- package/dist/src/createKeyframes.js +14 -0
- package/dist/src/createStyleNode.d.ts +8 -0
- package/dist/src/createStyleNode.js +9 -0
- package/dist/src/getAnimationName.d.ts +2 -0
- package/dist/src/getAnimationName.js +4 -0
- package/dist/src/getValueFromCache.d.ts +2 -0
- package/dist/src/getValueFromCache.js +10 -0
- package/dist/src/hash.d.ts +1 -0
- package/dist/src/hash.js +16 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +2 -0
- package/dist/src/types.d.ts +4 -0
- package/dist/src/types.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +11 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import getValueFromCache from './getValueFromCache.js';
|
|
2
|
+
import createStyleNode from './createStyleNode.js';
|
|
3
|
+
import getAnimationName from './getAnimationName.js';
|
|
4
|
+
export default function createKeyframe(style, nonce) {
|
|
5
|
+
const animationName = getAnimationName(style);
|
|
6
|
+
const css = getValueFromCache(animationName, style);
|
|
7
|
+
const node = createStyleNode(animationName, css, nonce);
|
|
8
|
+
return [animationName, node];
|
|
9
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import createStyleNode from './createStyleNode.js';
|
|
2
|
+
import { T_Keyframe } from './types.js';
|
|
3
|
+
type Node = ReturnType<typeof createStyleNode>;
|
|
4
|
+
export default function createKeyframes<T extends string>(keyframes: Record<T, T_Keyframe>, nonce?: string): [Record<T, string>, Node];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import getValueFromCache from './getValueFromCache.js';
|
|
2
|
+
import createStyleNode from './createStyleNode.js';
|
|
3
|
+
import getAnimationName from './getAnimationName.js';
|
|
4
|
+
export default function createKeyframes(keyframes, nonce) {
|
|
5
|
+
const animationNameMap = {};
|
|
6
|
+
let css = '';
|
|
7
|
+
for (const key in keyframes) {
|
|
8
|
+
const animationName = getAnimationName(keyframes[key]);
|
|
9
|
+
css += getValueFromCache(animationName, keyframes[key]);
|
|
10
|
+
animationNameMap[key] = animationName;
|
|
11
|
+
}
|
|
12
|
+
const node = createStyleNode(Object.keys(keyframes).join('-'), css, nonce);
|
|
13
|
+
return [animationNameMap, node];
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default function createStyleNode(animationName: string, css: string, nonce?: string): import("react").DetailedReactHTMLElement<{
|
|
2
|
+
dangerouslySetInnerHTML: {
|
|
3
|
+
__html: string;
|
|
4
|
+
};
|
|
5
|
+
precedence: string;
|
|
6
|
+
href: string;
|
|
7
|
+
nonce: string | undefined;
|
|
8
|
+
}, HTMLElement>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { cssifyObject } from 'css-in-js-utils';
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
export default function getValueFromCache(animationName, style) {
|
|
4
|
+
if (!cache.has(animationName)) {
|
|
5
|
+
const keyframe = Object.entries(style).reduce((keyframe, [key, declaration = {}]) => keyframe + key + '{' + cssifyObject(declaration) + '}', '');
|
|
6
|
+
const css = `@keyframes ${animationName}{${keyframe}}`;
|
|
7
|
+
cache.set(animationName, css);
|
|
8
|
+
}
|
|
9
|
+
return cache.get(animationName);
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function hash(str: string): string;
|
package/dist/src/hash.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// copied from restyle
|
|
2
|
+
export default function hash(str) {
|
|
3
|
+
let h = 0 ^ 0x811c9dc5;
|
|
4
|
+
for (let index = 0; index < str.length; index++) {
|
|
5
|
+
h ^= str.charCodeAt(index);
|
|
6
|
+
h = (h * 0x01000193) >>> 0;
|
|
7
|
+
}
|
|
8
|
+
const letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
9
|
+
const base36 = '0123456789' + letters;
|
|
10
|
+
let result = '';
|
|
11
|
+
do {
|
|
12
|
+
result = base36[h % 36] + result;
|
|
13
|
+
h = Math.floor(h / 36);
|
|
14
|
+
} while (h > 0);
|
|
15
|
+
return `x${result}`;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../vitest.config.ts","../src/createkeyframe.ts","../src/createkeyframes.ts","../src/createstylenode.ts","../src/getanimationname.ts","../src/getvaluefromcache.ts","../src/hash.ts","../src/index.ts","../src/types.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weser/keyframes",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Tiny helpers for CSS keyframes in React",
|
|
5
5
|
"author": "Robin Weser <robin@weser.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"clean": "rimraf dist",
|
|
34
34
|
"build": "tsc -b",
|
|
35
35
|
"dev": "pnpm build -w",
|
|
36
|
-
"test": "
|
|
36
|
+
"test": "vitest run"
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|
|
39
39
|
"error handling",
|
|
@@ -48,10 +48,11 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/react": "^18.3.3",
|
|
51
|
-
"
|
|
51
|
+
"jsdom": "^25.0.1",
|
|
52
52
|
"react": "canary",
|
|
53
53
|
"rimraf": "^3.0.2",
|
|
54
|
-
"typescript": "^5.4.5"
|
|
54
|
+
"typescript": "^5.4.5",
|
|
55
|
+
"vitest": "^2.1.8"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "490b5b37e8da7f0cac2880543874914c6f6be5d6"
|
|
57
58
|
}
|