@weser/keyframes 0.0.8 → 0.0.10

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.
@@ -1,5 +1,5 @@
1
- import { CSSProperties, createElement } from 'react';
2
- type Key = `${number}%` | 'from' | 'to';
3
- export type T_Keyframe = Partial<Record<Key, CSSProperties>>;
4
- export default function createKeyframe(style: T_Keyframe, nonce?: string): [string, ReturnType<typeof createElement>];
1
+ import createStyleNode from './createStyleNode.js';
2
+ import { T_Keyframe } from './types.js';
3
+ type Node = ReturnType<typeof createStyleNode>;
4
+ export default function createKeyframe(style: T_Keyframe, nonce?: string): [string, Node];
5
5
  export {};
@@ -1,23 +1,9 @@
1
- import { createElement } from 'react';
2
- import { cssifyObject } from 'css-in-js-utils';
3
- import hash from './hash.js';
4
- const cache = new Map();
1
+ import getValueFromCache from './getValueFromCache.js';
2
+ import createStyleNode from './createStyleNode.js';
3
+ import getAnimationName from './getAnimationName.js';
5
4
  export default function createKeyframe(style, nonce) {
6
- const animationName = '_' + hash(JSON.stringify(style));
5
+ const animationName = getAnimationName(style);
7
6
  const css = getValueFromCache(animationName, style);
8
- const node = createElement('style', {
9
- dangerouslySetInnerHTML: { __html: css },
10
- precedence: 'low',
11
- href: animationName,
12
- nonce,
13
- });
7
+ const node = createStyleNode(animationName, css, nonce);
14
8
  return [animationName, node];
15
9
  }
16
- function getValueFromCache(animationName, style) {
17
- if (!cache.has(animationName)) {
18
- const keyframe = Object.entries(style).reduce((keyframe, [key, declaration = {}]) => keyframe + key + '{' + cssifyObject(declaration) + '}', '');
19
- const css = `@keyframes ${animationName}{${keyframe}}`;
20
- cache.set(animationName, css);
21
- }
22
- return cache.get(animationName);
23
- }
@@ -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,9 @@
1
+ /// <reference types="react" />
2
+ export default function createStyleNode(animationName: string, css: string, nonce?: string): import("react").DetailedReactHTMLElement<{
3
+ dangerouslySetInnerHTML: {
4
+ __html: string;
5
+ };
6
+ precedence: string;
7
+ href: string;
8
+ nonce: string | undefined;
9
+ }, HTMLElement>;
@@ -0,0 +1,9 @@
1
+ import { createElement } from 'react';
2
+ export default function createStyleNode(animationName, css, nonce) {
3
+ return createElement('style', {
4
+ dangerouslySetInnerHTML: { __html: css },
5
+ precedence: 'low',
6
+ href: animationName,
7
+ nonce,
8
+ });
9
+ }
@@ -0,0 +1,2 @@
1
+ import { T_Keyframe } from './types.js';
2
+ export default function getAnimationName(style: T_Keyframe): string;
@@ -0,0 +1,4 @@
1
+ import hash from './hash.js';
2
+ export default function getAnimationName(style) {
3
+ return '_' + hash(JSON.stringify(style));
4
+ }
@@ -0,0 +1,2 @@
1
+ import { T_Keyframe } from './types.js';
2
+ export default function getValueFromCache(animationName: string, style: T_Keyframe): any;
@@ -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
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
- export { default as createKeyframe, T_Keyframe } from './createKeyframe.js';
1
+ export { default as createKeyframe } from './createKeyframe.js';
2
+ export { default as createKeyframes } from './createKeyframes.js';
3
+ export { T_Keyframe } from './types.js';
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { default as createKeyframe } from './createKeyframe.js';
2
+ export { default as createKeyframes } from './createKeyframes.js';
@@ -0,0 +1,4 @@
1
+ import { CSSProperties } from 'react';
2
+ type Key = `${number}%` | 'from' | 'to';
3
+ export type T_Keyframe = Partial<Record<Key, CSSProperties>>;
4
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weser/keyframes",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Tiny helpers for CSS keyframes in React",
5
5
  "author": "Robin Weser <robin@weser.io>",
6
6
  "license": "MIT",
@@ -53,5 +53,5 @@
53
53
  "rimraf": "^3.0.2",
54
54
  "typescript": "^5.4.5"
55
55
  },
56
- "gitHead": "9dce5f658f08431e80506b022369229dfeff7dd7"
56
+ "gitHead": "6dd1ad00ab8dacea2878edc99085324ea5d03588"
57
57
  }