rnwind 0.0.1 → 0.0.2
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/lib/cjs/core/parser/animation.cjs +427 -0
- package/lib/cjs/core/parser/animation.cjs.map +1 -0
- package/lib/cjs/core/parser/animation.d.ts +126 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs +180 -0
- package/lib/cjs/core/parser/border-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/cjs/core/parser/case-convert.cjs +15 -0
- package/lib/cjs/core/parser/case-convert.cjs.map +1 -0
- package/lib/cjs/core/parser/case-convert.d.ts +6 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs +84 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/cjs/core/parser/color.cjs +164 -0
- package/lib/cjs/core/parser/color.cjs.map +1 -0
- package/lib/cjs/core/parser/color.d.ts +12 -0
- package/lib/cjs/core/parser/constants.cjs +21 -0
- package/lib/cjs/core/parser/constants.cjs.map +1 -0
- package/lib/cjs/core/parser/constants.d.ts +8 -0
- package/lib/cjs/core/parser/declaration.cjs +347 -0
- package/lib/cjs/core/parser/declaration.cjs.map +1 -0
- package/lib/cjs/core/parser/declaration.d.ts +15 -0
- package/lib/cjs/core/parser/gradient.cjs +132 -0
- package/lib/cjs/core/parser/gradient.cjs.map +1 -0
- package/lib/cjs/core/parser/gradient.d.ts +59 -0
- package/lib/cjs/core/parser/haptics.cjs +73 -0
- package/lib/cjs/core/parser/haptics.cjs.map +1 -0
- package/lib/cjs/core/parser/haptics.d.ts +47 -0
- package/lib/cjs/core/parser/index.d.ts +8 -0
- package/lib/cjs/core/parser/keyframes.cjs +95 -0
- package/lib/cjs/core/parser/keyframes.cjs.map +1 -0
- package/lib/cjs/core/parser/keyframes.d.ts +26 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs +100 -0
- package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/cjs/core/parser/length.cjs +96 -0
- package/lib/cjs/core/parser/length.cjs.map +1 -0
- package/lib/cjs/core/parser/length.d.ts +48 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs +77 -0
- package/lib/cjs/core/parser/motion-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/property.cjs +22 -0
- package/lib/cjs/core/parser/property.cjs.map +1 -0
- package/lib/cjs/core/parser/property.d.ts +8 -0
- package/lib/cjs/core/parser/safe-area.cjs +404 -0
- package/lib/cjs/core/parser/safe-area.cjs.map +1 -0
- package/lib/cjs/core/parser/safe-area.d.ts +39 -0
- package/lib/cjs/core/parser/selector.cjs +22 -0
- package/lib/cjs/core/parser/selector.cjs.map +1 -0
- package/lib/cjs/core/parser/selector.d.ts +11 -0
- package/lib/cjs/core/parser/shorthand.cjs +156 -0
- package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
- package/lib/cjs/core/parser/shorthand.d.ts +61 -0
- package/lib/cjs/core/parser/text-truncate.cjs +78 -0
- package/lib/cjs/core/parser/text-truncate.cjs.map +1 -0
- package/lib/cjs/core/parser/text-truncate.d.ts +44 -0
- package/lib/cjs/core/parser/theme-vars.cjs +414 -0
- package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
- package/lib/cjs/core/parser/theme-vars.d.ts +61 -0
- package/lib/cjs/core/parser/tokens.cjs +304 -0
- package/lib/cjs/core/parser/tokens.cjs.map +1 -0
- package/lib/cjs/core/parser/tokens.d.ts +45 -0
- package/lib/cjs/core/parser/transform.cjs +198 -0
- package/lib/cjs/core/parser/transform.cjs.map +1 -0
- package/lib/cjs/core/parser/transform.d.ts +36 -0
- package/lib/cjs/core/parser/tw-parser.cjs +1567 -0
- package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
- package/lib/cjs/core/parser/tw-parser.d.ts +194 -0
- package/lib/cjs/core/parser/types.d.ts +37 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs +93 -0
- package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -0
- package/lib/cjs/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/cjs/core/parser/typography.cjs +97 -0
- package/lib/cjs/core/parser/typography.cjs.map +1 -0
- package/lib/cjs/core/parser/typography.d.ts +43 -0
- package/lib/cjs/core/style-builder/build-style.cjs +397 -0
- package/lib/cjs/core/style-builder/build-style.cjs.map +1 -0
- package/lib/cjs/core/style-builder/build-style.d.ts +54 -0
- package/lib/cjs/core/style-builder/index.d.ts +3 -0
- package/lib/cjs/core/style-builder/union-builder.cjs +326 -0
- package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -0
- package/lib/cjs/core/style-builder/union-builder.d.ts +128 -0
- package/lib/cjs/core/types.d.ts +14 -0
- package/lib/cjs/metro/dts.cjs +127 -0
- package/lib/cjs/metro/dts.cjs.map +1 -0
- package/lib/cjs/metro/dts.d.ts +16 -0
- package/lib/cjs/metro/index.cjs +19 -0
- package/lib/cjs/metro/index.cjs.map +1 -0
- package/lib/cjs/metro/index.d.ts +9 -0
- package/lib/cjs/metro/resolver.cjs +47 -0
- package/lib/cjs/metro/resolver.cjs.map +1 -0
- package/lib/cjs/metro/resolver.d.ts +22 -0
- package/lib/cjs/metro/state.cjs +251 -0
- package/lib/cjs/metro/state.cjs.map +1 -0
- package/lib/cjs/metro/state.d.ts +72 -0
- package/lib/cjs/metro/transform-ast.cjs +1255 -0
- package/lib/cjs/metro/transform-ast.cjs.map +1 -0
- package/lib/cjs/metro/transform-ast.d.ts +73 -0
- package/lib/cjs/metro/transformer.cjs +345 -0
- package/lib/cjs/metro/transformer.cjs.map +1 -0
- package/lib/cjs/metro/transformer.d.ts +47 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs +86 -0
- package/lib/cjs/metro/warn-unknown-classes.cjs.map +1 -0
- package/lib/cjs/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/cjs/metro/with-config.cjs +196 -0
- package/lib/cjs/metro/with-config.cjs.map +1 -0
- package/lib/cjs/metro/with-config.d.ts +57 -0
- package/lib/cjs/runtime/chain-handlers.cjs +37 -0
- package/lib/cjs/runtime/chain-handlers.cjs.map +1 -0
- package/lib/cjs/runtime/chain-handlers.d.ts +33 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs +98 -0
- package/lib/cjs/runtime/components/rnwind-provider.cjs.map +1 -0
- package/lib/cjs/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/cjs/runtime/gradient-types.d.ts +58 -0
- package/lib/cjs/runtime/haptics.cjs +113 -0
- package/lib/cjs/runtime/haptics.cjs.map +1 -0
- package/lib/cjs/runtime/haptics.d.ts +48 -0
- package/lib/cjs/runtime/hooks/use-css.cjs +21 -0
- package/lib/cjs/runtime/hooks/use-css.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-css.d.ts +11 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs +46 -0
- package/lib/cjs/runtime/hooks/use-interact.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs +68 -0
- package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -0
- package/lib/cjs/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/cjs/runtime/index.cjs +45 -0
- package/lib/cjs/runtime/index.cjs.map +1 -0
- package/lib/cjs/runtime/index.d.ts +27 -0
- package/lib/cjs/runtime/interactive-box.cjs +35 -0
- package/lib/cjs/runtime/interactive-box.cjs.map +1 -0
- package/lib/cjs/runtime/interactive-box.d.ts +40 -0
- package/lib/cjs/runtime/lookup-css.cjs +542 -0
- package/lib/cjs/runtime/lookup-css.cjs.map +1 -0
- package/lib/cjs/runtime/lookup-css.d.ts +164 -0
- package/lib/cjs/runtime/types.d.ts +29 -0
- package/lib/cjs/testing/index.cjs +367 -0
- package/lib/cjs/testing/index.cjs.map +1 -0
- package/lib/cjs/testing/index.d.ts +145 -0
- package/lib/esm/core/parser/animation.d.ts +126 -0
- package/lib/esm/core/parser/animation.mjs +408 -0
- package/lib/esm/core/parser/animation.mjs.map +1 -0
- package/lib/esm/core/parser/border-dispatcher.d.ts +15 -0
- package/lib/esm/core/parser/border-dispatcher.mjs +178 -0
- package/lib/esm/core/parser/border-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/case-convert.d.ts +6 -0
- package/lib/esm/core/parser/case-convert.mjs +13 -0
- package/lib/esm/core/parser/case-convert.mjs.map +1 -0
- package/lib/esm/core/parser/color-properties-dispatcher.d.ts +19 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs +82 -0
- package/lib/esm/core/parser/color-properties-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/color.d.ts +12 -0
- package/lib/esm/core/parser/color.mjs +162 -0
- package/lib/esm/core/parser/color.mjs.map +1 -0
- package/lib/esm/core/parser/constants.d.ts +8 -0
- package/lib/esm/core/parser/constants.mjs +13 -0
- package/lib/esm/core/parser/constants.mjs.map +1 -0
- package/lib/esm/core/parser/declaration.d.ts +15 -0
- package/lib/esm/core/parser/declaration.mjs +345 -0
- package/lib/esm/core/parser/declaration.mjs.map +1 -0
- package/lib/esm/core/parser/gradient.d.ts +59 -0
- package/lib/esm/core/parser/gradient.mjs +130 -0
- package/lib/esm/core/parser/gradient.mjs.map +1 -0
- package/lib/esm/core/parser/haptics.d.ts +47 -0
- package/lib/esm/core/parser/haptics.mjs +71 -0
- package/lib/esm/core/parser/haptics.mjs.map +1 -0
- package/lib/esm/core/parser/index.d.ts +8 -0
- package/lib/esm/core/parser/keyframes.d.ts +26 -0
- package/lib/esm/core/parser/keyframes.mjs +91 -0
- package/lib/esm/core/parser/keyframes.mjs.map +1 -0
- package/lib/esm/core/parser/layout-dispatcher.d.ts +14 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs +98 -0
- package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/length.d.ts +48 -0
- package/lib/esm/core/parser/length.mjs +90 -0
- package/lib/esm/core/parser/length.mjs.map +1 -0
- package/lib/esm/core/parser/motion-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs +75 -0
- package/lib/esm/core/parser/motion-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/property.d.ts +8 -0
- package/lib/esm/core/parser/property.mjs +20 -0
- package/lib/esm/core/parser/property.mjs.map +1 -0
- package/lib/esm/core/parser/safe-area.d.ts +39 -0
- package/lib/esm/core/parser/safe-area.mjs +402 -0
- package/lib/esm/core/parser/safe-area.mjs.map +1 -0
- package/lib/esm/core/parser/selector.d.ts +11 -0
- package/lib/esm/core/parser/selector.mjs +20 -0
- package/lib/esm/core/parser/selector.mjs.map +1 -0
- package/lib/esm/core/parser/shorthand.d.ts +61 -0
- package/lib/esm/core/parser/shorthand.mjs +148 -0
- package/lib/esm/core/parser/shorthand.mjs.map +1 -0
- package/lib/esm/core/parser/text-truncate.d.ts +44 -0
- package/lib/esm/core/parser/text-truncate.mjs +75 -0
- package/lib/esm/core/parser/text-truncate.mjs.map +1 -0
- package/lib/esm/core/parser/theme-vars.d.ts +61 -0
- package/lib/esm/core/parser/theme-vars.mjs +409 -0
- package/lib/esm/core/parser/theme-vars.mjs.map +1 -0
- package/lib/esm/core/parser/tokens.d.ts +45 -0
- package/lib/esm/core/parser/tokens.mjs +298 -0
- package/lib/esm/core/parser/tokens.mjs.map +1 -0
- package/lib/esm/core/parser/transform.d.ts +36 -0
- package/lib/esm/core/parser/transform.mjs +193 -0
- package/lib/esm/core/parser/transform.mjs.map +1 -0
- package/lib/esm/core/parser/tw-parser.d.ts +194 -0
- package/lib/esm/core/parser/tw-parser.mjs +1565 -0
- package/lib/esm/core/parser/tw-parser.mjs.map +1 -0
- package/lib/esm/core/parser/types.d.ts +37 -0
- package/lib/esm/core/parser/typography-dispatcher.d.ts +11 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs +91 -0
- package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -0
- package/lib/esm/core/parser/typography.d.ts +43 -0
- package/lib/esm/core/parser/typography.mjs +91 -0
- package/lib/esm/core/parser/typography.mjs.map +1 -0
- package/lib/esm/core/style-builder/build-style.d.ts +54 -0
- package/lib/esm/core/style-builder/build-style.mjs +395 -0
- package/lib/esm/core/style-builder/build-style.mjs.map +1 -0
- package/lib/esm/core/style-builder/index.d.ts +3 -0
- package/lib/esm/core/style-builder/union-builder.d.ts +128 -0
- package/lib/esm/core/style-builder/union-builder.mjs +324 -0
- package/lib/esm/core/style-builder/union-builder.mjs.map +1 -0
- package/lib/esm/core/types.d.ts +14 -0
- package/lib/esm/metro/dts.d.ts +16 -0
- package/lib/esm/metro/dts.mjs +125 -0
- package/lib/esm/metro/dts.mjs.map +1 -0
- package/lib/esm/metro/index.d.ts +9 -0
- package/lib/esm/metro/index.mjs +6 -0
- package/lib/esm/metro/index.mjs.map +1 -0
- package/lib/esm/metro/resolver.d.ts +22 -0
- package/lib/esm/metro/resolver.mjs +43 -0
- package/lib/esm/metro/resolver.mjs.map +1 -0
- package/lib/esm/metro/state.d.ts +72 -0
- package/lib/esm/metro/state.mjs +243 -0
- package/lib/esm/metro/state.mjs.map +1 -0
- package/lib/esm/metro/transform-ast.d.ts +73 -0
- package/lib/esm/metro/transform-ast.mjs +1234 -0
- package/lib/esm/metro/transform-ast.mjs.map +1 -0
- package/lib/esm/metro/transformer.d.ts +47 -0
- package/lib/esm/metro/transformer.mjs +322 -0
- package/lib/esm/metro/transformer.mjs.map +1 -0
- package/lib/esm/metro/warn-unknown-classes.d.ts +21 -0
- package/lib/esm/metro/warn-unknown-classes.mjs +84 -0
- package/lib/esm/metro/warn-unknown-classes.mjs.map +1 -0
- package/lib/esm/metro/with-config.d.ts +57 -0
- package/lib/esm/metro/with-config.mjs +194 -0
- package/lib/esm/metro/with-config.mjs.map +1 -0
- package/lib/esm/runtime/chain-handlers.d.ts +33 -0
- package/lib/esm/runtime/chain-handlers.mjs +34 -0
- package/lib/esm/runtime/chain-handlers.mjs.map +1 -0
- package/lib/esm/runtime/components/rnwind-provider.d.ts +84 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs +94 -0
- package/lib/esm/runtime/components/rnwind-provider.mjs.map +1 -0
- package/lib/esm/runtime/gradient-types.d.ts +58 -0
- package/lib/esm/runtime/haptics.d.ts +48 -0
- package/lib/esm/runtime/haptics.mjs +110 -0
- package/lib/esm/runtime/haptics.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-css.d.ts +11 -0
- package/lib/esm/runtime/hooks/use-css.mjs +19 -0
- package/lib/esm/runtime/hooks/use-css.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-interact.d.ts +42 -0
- package/lib/esm/runtime/hooks/use-interact.mjs +44 -0
- package/lib/esm/runtime/hooks/use-interact.mjs.map +1 -0
- package/lib/esm/runtime/hooks/use-scheme.d.ts +34 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs +63 -0
- package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -0
- package/lib/esm/runtime/index.d.ts +27 -0
- package/lib/esm/runtime/index.mjs +18 -0
- package/lib/esm/runtime/index.mjs.map +1 -0
- package/lib/esm/runtime/interactive-box.d.ts +40 -0
- package/lib/esm/runtime/interactive-box.mjs +33 -0
- package/lib/esm/runtime/interactive-box.mjs.map +1 -0
- package/lib/esm/runtime/lookup-css.d.ts +164 -0
- package/lib/esm/runtime/lookup-css.mjs +531 -0
- package/lib/esm/runtime/lookup-css.mjs.map +1 -0
- package/lib/esm/runtime/types.d.ts +29 -0
- package/lib/esm/testing/index.d.ts +145 -0
- package/lib/esm/testing/index.mjs +344 -0
- package/lib/esm/testing/index.mjs.map +1 -0
- package/package.json +79 -13
- package/preset.css +1171 -0
- package/src/core/parser/animation.ts +404 -0
- package/src/core/parser/border-dispatcher.ts +176 -0
- package/src/core/parser/case-convert.ts +10 -0
- package/src/core/parser/color-properties-dispatcher.ts +78 -0
- package/src/core/parser/color.ts +157 -0
- package/src/core/parser/constants.ts +11 -0
- package/src/core/parser/declaration.ts +340 -0
- package/src/core/parser/gradient.ts +148 -0
- package/src/core/parser/haptics.ts +88 -0
- package/src/core/parser/index.ts +8 -0
- package/src/core/parser/keyframes.ts +84 -0
- package/src/core/parser/layout-dispatcher.ts +92 -0
- package/src/core/parser/length.ts +100 -0
- package/src/core/parser/motion-dispatcher.ts +89 -0
- package/src/core/parser/property.ts +15 -0
- package/src/core/parser/safe-area.ts +404 -0
- package/src/core/parser/selector.ts +17 -0
- package/src/core/parser/shorthand.ts +152 -0
- package/src/core/parser/text-truncate.ts +79 -0
- package/src/core/parser/theme-vars.ts +412 -0
- package/src/core/parser/tokens.ts +286 -0
- package/src/core/parser/transform.ts +195 -0
- package/src/core/parser/tw-parser.ts +1709 -0
- package/src/core/parser/types.ts +45 -0
- package/src/core/parser/typography-dispatcher.ts +83 -0
- package/src/core/parser/typography.ts +83 -0
- package/src/core/style-builder/build-style.ts +442 -0
- package/src/core/style-builder/index.ts +3 -0
- package/src/core/style-builder/union-builder.ts +328 -0
- package/src/core/types.ts +15 -0
- package/src/metro/dts.ts +128 -0
- package/src/metro/index.ts +9 -0
- package/src/metro/resolver.ts +42 -0
- package/src/metro/state.ts +257 -0
- package/src/metro/transform-ast.ts +1498 -0
- package/src/metro/transformer.ts +347 -0
- package/src/metro/warn-unknown-classes.ts +79 -0
- package/src/metro/with-config.ts +229 -0
- package/src/runtime/chain-handlers.ts +47 -0
- package/src/runtime/components/rnwind-provider.tsx +144 -0
- package/src/runtime/gradient-types.ts +60 -0
- package/src/runtime/haptics.ts +120 -0
- package/src/runtime/hooks/use-css.ts +16 -0
- package/src/runtime/hooks/use-interact.ts +65 -0
- package/src/runtime/hooks/use-scheme.ts +63 -0
- package/src/runtime/index.ts +54 -0
- package/src/runtime/interactive-box.tsx +57 -0
- package/src/runtime/lookup-css.ts +628 -0
- package/src/runtime/types.ts +32 -0
- package/src/testing/index.ts +507 -0
- package/src/types/tailwindcss-node.d.ts +33 -0
- package/src/index.ts +0 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import type { render as testingLibraryRender, renderHook as testingLibraryRenderHook, RenderHookOptions } from '@testing-library/react-native';
|
|
2
|
+
import type { Insets } from '../runtime/components/rnwind-provider';
|
|
3
|
+
import type { OnHaptics } from '../core/parser/haptics';
|
|
4
|
+
/** Exact signature of `@testing-library/react-native`'s `render`. */
|
|
5
|
+
export type Render = typeof testingLibraryRender;
|
|
6
|
+
/** Exact signature of `@testing-library/react-native`'s `renderHook`. */
|
|
7
|
+
export type RenderHook = typeof testingLibraryRenderHook;
|
|
8
|
+
/**
|
|
9
|
+
* Exact return type of `@testing-library/react-native`'s `render` — we
|
|
10
|
+
* re-export the upstream type so tests get every query (`getByTestId`,
|
|
11
|
+
* `queryByText`, `rerender`, `unmount`, `debug`, `UNSAFE_root`, …) with
|
|
12
|
+
* its real signature.
|
|
13
|
+
*/
|
|
14
|
+
export type TestingLibraryRenderAPI = ReturnType<typeof testingLibraryRender>;
|
|
15
|
+
/** Options accepted by {@link renderWithCss}. */
|
|
16
|
+
export interface RenderWithCssOptions {
|
|
17
|
+
/** Theme CSS fed to rnwind's parser. Defaults to {@link DEFAULT_THEME_CSS}. */
|
|
18
|
+
themeCss?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Active scheme the runtime resolver uses. Defaults to `'light'`.
|
|
21
|
+
* Flip to `'dark'` / `'brand'` / ... to exercise scheme-variant atoms.
|
|
22
|
+
*/
|
|
23
|
+
scheme?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Safe-area insets to inject. When provided, the component tree is
|
|
26
|
+
* rendered under a `<RnwindProvider insets={...}>` so `*-safe` atoms
|
|
27
|
+
* resolve to real numbers instead of the `0` fallback. Partial is
|
|
28
|
+
* accepted — missing sides default to zero.
|
|
29
|
+
*/
|
|
30
|
+
insets?: Partial<Insets>;
|
|
31
|
+
/**
|
|
32
|
+
* Haptic dispatcher forwarded onto the implicit `<RnwindProvider>`.
|
|
33
|
+
* Tests pass a spy callback to assert which haptic atoms fired.
|
|
34
|
+
*/
|
|
35
|
+
onHaptics?: OnHaptics;
|
|
36
|
+
/**
|
|
37
|
+
* `react-native` namespace bindings forwarded into the rewritten
|
|
38
|
+
* module. Defaults to importing the test process's `react-native`
|
|
39
|
+
* (typically a mocked stub). Override to inject custom host elements.
|
|
40
|
+
*/
|
|
41
|
+
reactNative?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of a {@link renderWithCss} call. Every key from
|
|
45
|
+
* `@testing-library/react-native`'s `render` return value is spread onto
|
|
46
|
+
* this object — `getByTestId`, `queryByText`, `rerender`, `unmount`,
|
|
47
|
+
* `debug`, etc. — so tests use the testing-library API directly.
|
|
48
|
+
*
|
|
49
|
+
* Two rnwind-specific handles are added:
|
|
50
|
+
* - `transformedSource` — the exact code the rnwind Metro transformer
|
|
51
|
+
* emitted for your input. Log it to confirm the rewrite.
|
|
52
|
+
* - `cleanup` — tears down the ephemeral rnwind state + chunk cache dir.
|
|
53
|
+
* Call from `afterEach` so successive tests don't share atoms.
|
|
54
|
+
*/
|
|
55
|
+
export type RenderWithCssResult = TestingLibraryRenderAPI & {
|
|
56
|
+
/** The post-transformer source text. Same code Metro would ship. */
|
|
57
|
+
transformedSource: string;
|
|
58
|
+
/** Tear down the ephemeral rnwind state + cache dir. */
|
|
59
|
+
cleanup: () => void;
|
|
60
|
+
};
|
|
61
|
+
/** Options accepted by {@link renderHookWithCss}. */
|
|
62
|
+
export interface RenderHookWithCssOptions<Props> extends RenderHookOptions<Props> {
|
|
63
|
+
/** Theme CSS fed to rnwind's parser. Defaults to the built-in minimal theme. */
|
|
64
|
+
themeCss?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Active scheme the runtime resolver uses. Defaults to `'light'`. When
|
|
67
|
+
* set, the hook is wrapped in `<RnwindProvider scheme={scheme}>` so
|
|
68
|
+
* `useScheme()` / `useCss()` observe the override.
|
|
69
|
+
*/
|
|
70
|
+
scheme?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Class names to pre-register into the runtime atom registry before
|
|
73
|
+
* the hook runs. rnwind synthesizes a throwaway source file mentioning
|
|
74
|
+
* these classes, feeds it through the real Metro transformer, and
|
|
75
|
+
* evaluates the generated `style.js` bundle — so the hook sees
|
|
76
|
+
* exactly the atoms the production bundle would register.
|
|
77
|
+
*/
|
|
78
|
+
classNames?: readonly string[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Result of a {@link renderHookWithCss} call. Mirrors
|
|
82
|
+
* `@testing-library/react-native`'s `renderHook` return type — `result`,
|
|
83
|
+
* `rerender`, `unmount` — and adds a `cleanup` that tears down the
|
|
84
|
+
* ephemeral rnwind state.
|
|
85
|
+
*/
|
|
86
|
+
export type RenderHookWithCssResult<Result, Props> = ReturnType<typeof testingLibraryRenderHook<Result, Props>> & {
|
|
87
|
+
/** Tear down the ephemeral rnwind state + cache dir. */
|
|
88
|
+
cleanup: () => void;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Feed a source string through rnwind's Metro transformer, evaluate
|
|
92
|
+
* the generated `style.js` bundle, evaluate the rewritten module, and
|
|
93
|
+
* render the default-exported component with
|
|
94
|
+
* `@testing-library/react-native`.
|
|
95
|
+
*
|
|
96
|
+
* The rendered RN element's `style` prop is the EXACT array your
|
|
97
|
+
* production bundle would attach — same transformer, same runtime
|
|
98
|
+
* resolver, same atoms. Assert on `flatten(node.props.style)` to verify
|
|
99
|
+
* the resolved values.
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* const handle = await renderWithCss(
|
|
103
|
+
* `import { View } from 'react-native'
|
|
104
|
+
* export default () => <View className="bg-primary p-4" testID="box" />`,
|
|
105
|
+
* { themeCss: `@import 'tailwindcss'; @theme { --color-primary: #6366f1; }` },
|
|
106
|
+
* )
|
|
107
|
+
* const flat = flatten(handle.getByTestId('box').props.style)
|
|
108
|
+
* expect(flat.backgroundColor).toBe('#6366f1')
|
|
109
|
+
* ```
|
|
110
|
+
* @param source User source (one file) to transform + render.
|
|
111
|
+
* @param options Optional theme override, scheme, and `react-native` bindings.
|
|
112
|
+
* @returns Render queries + diagnostic handles.
|
|
113
|
+
*/
|
|
114
|
+
export declare function renderWithCss(source: string, options?: RenderWithCssOptions): Promise<RenderWithCssResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Render-side counterpart to {@link renderWithCss} for testing hooks in
|
|
117
|
+
* isolation. Pre-registers atoms for the supplied `classNames`, wraps
|
|
118
|
+
* the hook in an optional `<RnwindProvider>`, and forwards to
|
|
119
|
+
* `@testing-library/react-native`'s `renderHook`.
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* const { result, cleanup } = await renderHookWithCss(
|
|
123
|
+
* () => useCss('bg-primary'),
|
|
124
|
+
* {
|
|
125
|
+
* themeCss: `@import 'tailwindcss'; @theme { --color-primary: #6366f1; }`,
|
|
126
|
+
* classNames: ['bg-primary'],
|
|
127
|
+
* },
|
|
128
|
+
* )
|
|
129
|
+
* expect(flatten(result.current).backgroundColor).toBe('#6366f1')
|
|
130
|
+
* cleanup()
|
|
131
|
+
* ```
|
|
132
|
+
* @param callback Hook body — same shape as `renderHook(callback)`.
|
|
133
|
+
* @param options Theme, scheme, classNames to pre-register, plus
|
|
134
|
+
* everything `renderHook` itself accepts (`initialProps`, `wrapper`).
|
|
135
|
+
* @returns `renderHook`'s return value plus a `cleanup` function.
|
|
136
|
+
*/
|
|
137
|
+
export declare function renderHookWithCss<Result, Props = unknown>(callback: (props: Props) => Result, options?: RenderHookWithCssOptions<Props>): Promise<RenderHookWithCssResult<Result, Props>>;
|
|
138
|
+
/**
|
|
139
|
+
* Flatten a React Native style array (or single style object) into one
|
|
140
|
+
* merged record. RN flattens left-to-right (later wins), so the returned
|
|
141
|
+
* record is what the native view manager actually applies.
|
|
142
|
+
* @param styles Style array, single object, or null/undefined.
|
|
143
|
+
* @returns Flat style record.
|
|
144
|
+
*/
|
|
145
|
+
export declare function flatten(styles: unknown): Record<string, unknown>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Animation, AnimationDirection, AnimationFillMode, AnimationIterationCount, AnimationName, AnimationPlayState, EasingFunction, PropertyId, Time, Transition } from 'lightningcss';
|
|
2
|
+
import type { RNEntry } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Serialize a lightningcss `EasingFunction` into a CSS string Reanimated
|
|
5
|
+
* v4's CSS engine understands. Reanimated accepts the same timing-function
|
|
6
|
+
* strings as CSS transitions/animations, so we emit the canonical CSS
|
|
7
|
+
* form.
|
|
8
|
+
* @param fn Typed easing function.
|
|
9
|
+
* @returns CSS string, e.g. `'linear'` / `'ease-in-out'` / `'cubic-bezier(0.4, 0, 0.2, 1)'`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function easingFunctionToString(fn: EasingFunction): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a `Time` value into a CSS string (`150ms`, `1s`). Reanimated's
|
|
14
|
+
* CSS engine accepts either `ms` or `s`; we pick `ms` unless the value
|
|
15
|
+
* is a whole-second multiple for readability.
|
|
16
|
+
* @param time Typed time value.
|
|
17
|
+
* @returns CSS time string.
|
|
18
|
+
*/
|
|
19
|
+
export declare function timeToString(time: Time): string;
|
|
20
|
+
/**
|
|
21
|
+
* Convert a single `animation-name` value to a string. Tailwind's
|
|
22
|
+
* `animate-none` produces `{ type: 'none' }` which we drop.
|
|
23
|
+
* @param name Typed animation name.
|
|
24
|
+
* @returns Keyframe identifier, or null when `none`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function animationNameToString(name: AnimationName): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Convert a single `animation-iteration-count` value to the CSS shape
|
|
29
|
+
* Reanimated wants: either a finite integer or the `'infinite'` string.
|
|
30
|
+
* @param count Typed iteration count.
|
|
31
|
+
* @returns Number or `'infinite'`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function iterationCountToValue(count: AnimationIterationCount): number | string;
|
|
34
|
+
/**
|
|
35
|
+
* Decompose the `animation: <name> <duration> <timing> <iteration> …`
|
|
36
|
+
* shorthand into the per-property RN entries Reanimated consumes. A single
|
|
37
|
+
* `animation` declaration can name multiple animations — we emit the first
|
|
38
|
+
* one (Tailwind's `animate-*` utilities always emit exactly one).
|
|
39
|
+
* @param animations Parsed animation list from lightningcss.
|
|
40
|
+
* @returns RN entries, empty when the shorthand names `none`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function animationShorthandToEntries(animations: readonly Animation[]): readonly RNEntry[];
|
|
43
|
+
/**
|
|
44
|
+
* Emit `animationName` for a standalone `animation-name: spin` declaration.
|
|
45
|
+
* @param names Typed `animation-name` list.
|
|
46
|
+
* @returns Single-entry `animationName` or empty when `none`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function animationNameEntries(names: readonly AnimationName[]): readonly RNEntry[];
|
|
49
|
+
/**
|
|
50
|
+
* Emit `animationDuration` for a standalone `animation-duration` declaration.
|
|
51
|
+
* @param durations Typed duration list.
|
|
52
|
+
* @returns Single-entry list.
|
|
53
|
+
*/
|
|
54
|
+
export declare function animationDurationEntries(durations: readonly Time[]): readonly RNEntry[];
|
|
55
|
+
/**
|
|
56
|
+
* Emit `animationTimingFunction` for a standalone `animation-timing-function`.
|
|
57
|
+
* @param fns Typed timing-function list.
|
|
58
|
+
* @returns Single-entry list.
|
|
59
|
+
*/
|
|
60
|
+
export declare function animationTimingFunctionEntries(fns: readonly EasingFunction[]): readonly RNEntry[];
|
|
61
|
+
/**
|
|
62
|
+
* Emit `animationIterationCount` for a standalone declaration.
|
|
63
|
+
* @param counts Typed iteration-count list.
|
|
64
|
+
* @returns Single-entry list.
|
|
65
|
+
*/
|
|
66
|
+
export declare function animationIterationCountEntries(counts: readonly AnimationIterationCount[]): readonly RNEntry[];
|
|
67
|
+
/**
|
|
68
|
+
* Emit `animationDelay` for a standalone declaration.
|
|
69
|
+
* @param delays Typed delay list.
|
|
70
|
+
* @returns Single-entry list.
|
|
71
|
+
*/
|
|
72
|
+
export declare function animationDelayEntries(delays: readonly Time[]): readonly RNEntry[];
|
|
73
|
+
/**
|
|
74
|
+
* Emit `animationDirection` for a standalone declaration.
|
|
75
|
+
* @param directions Typed direction list.
|
|
76
|
+
* @returns Single-entry list.
|
|
77
|
+
*/
|
|
78
|
+
export declare function animationDirectionEntries(directions: readonly AnimationDirection[]): readonly RNEntry[];
|
|
79
|
+
/**
|
|
80
|
+
* Emit `animationFillMode` for a standalone declaration.
|
|
81
|
+
* @param modes Typed fill-mode list.
|
|
82
|
+
* @returns Single-entry list.
|
|
83
|
+
*/
|
|
84
|
+
export declare function animationFillModeEntries(modes: readonly AnimationFillMode[]): readonly RNEntry[];
|
|
85
|
+
/**
|
|
86
|
+
* Emit `animationPlayState` for a standalone declaration.
|
|
87
|
+
* @param states Typed play-state list.
|
|
88
|
+
* @returns Single-entry list.
|
|
89
|
+
*/
|
|
90
|
+
export declare function animationPlayStateEntries(states: readonly AnimationPlayState[]): readonly RNEntry[];
|
|
91
|
+
/**
|
|
92
|
+
* Convert the `transition-property` list into an RN-consumable form.
|
|
93
|
+
* Reanimated accepts either a string (`'all'`, `'opacity'`) or an array
|
|
94
|
+
* of property names. We emit the array shape even for singletons so the
|
|
95
|
+
* runtime can handle it uniformly.
|
|
96
|
+
* @param properties Typed transition-property list.
|
|
97
|
+
* @returns Single-entry list with `transitionProperty`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function transitionPropertyEntries(properties: readonly PropertyId[]): readonly RNEntry[];
|
|
100
|
+
/**
|
|
101
|
+
* Decompose the `transition: <prop> <duration> <timing> <delay>` shorthand
|
|
102
|
+
* into the per-property RN entries Reanimated consumes. A declaration can
|
|
103
|
+
* name multiple transitions; we emit one entry per slot, collapsing
|
|
104
|
+
* identical slots into a scalar.
|
|
105
|
+
* @param transitions Parsed transition list from lightningcss.
|
|
106
|
+
* @returns RN entries — zero or more.
|
|
107
|
+
*/
|
|
108
|
+
export declare function transitionShorthandToEntries(transitions: readonly Transition[]): readonly RNEntry[];
|
|
109
|
+
/**
|
|
110
|
+
* Emit `transitionDuration` for a standalone declaration.
|
|
111
|
+
* @param durations Typed duration list.
|
|
112
|
+
* @returns Single-entry list.
|
|
113
|
+
*/
|
|
114
|
+
export declare function transitionDurationEntries(durations: readonly Time[]): readonly RNEntry[];
|
|
115
|
+
/**
|
|
116
|
+
* Emit `transitionTimingFunction` for a standalone declaration.
|
|
117
|
+
* @param fns Typed timing-function list.
|
|
118
|
+
* @returns Single-entry list.
|
|
119
|
+
*/
|
|
120
|
+
export declare function transitionTimingFunctionEntries(fns: readonly EasingFunction[]): readonly RNEntry[];
|
|
121
|
+
/**
|
|
122
|
+
* Emit `transitionDelay` for a standalone declaration.
|
|
123
|
+
* @param delays Typed delay list.
|
|
124
|
+
* @returns Single-entry list.
|
|
125
|
+
*/
|
|
126
|
+
export declare function transitionDelayEntries(delays: readonly Time[]): readonly RNEntry[];
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { kebabToCamel } from './case-convert.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert one PropertyId ident into the camelCase RN style key
|
|
5
|
+
* Reanimated v4's CSS engine matches against. Tailwind emits CSS names
|
|
6
|
+
* in kebab-case (`background-color`); RN stores `backgroundColor` in
|
|
7
|
+
* the actual style object, and Reanimated only fires a transition when
|
|
8
|
+
* the watched key matches the changed key — so kebab-case here would
|
|
9
|
+
* silently no-op every multi-word color/border transition.
|
|
10
|
+
*
|
|
11
|
+
* Special cases:
|
|
12
|
+
* - `'all'` passes through unchanged.
|
|
13
|
+
* - `--tw-*` Tailwind internal custom props are dropped — they have
|
|
14
|
+
* no RN equivalent and Reanimated can't watch them.
|
|
15
|
+
* - Other `--user-defined` custom props pass through verbatim.
|
|
16
|
+
* @param property Typed property identifier.
|
|
17
|
+
* @returns RN-style key, or null when the property has no RN equivalent.
|
|
18
|
+
*/
|
|
19
|
+
function propertyIdToString(property) {
|
|
20
|
+
// Custom properties surface in two shapes: either as `{property:
|
|
21
|
+
// 'custom', value: {name: '--x'}}` or — when lightningcss recognises
|
|
22
|
+
// the leading `--` directly in propertyId — as `{property: '--x'}`.
|
|
23
|
+
// Handle both, drop Tailwind internals, keep user customs verbatim.
|
|
24
|
+
if (property.property === 'custom' && 'value' in property) {
|
|
25
|
+
const { value } = property;
|
|
26
|
+
const customName = value && typeof value === 'object' && 'name' in value && typeof value.name === 'string' ? value.name : null;
|
|
27
|
+
if (!customName)
|
|
28
|
+
return null;
|
|
29
|
+
return customName.startsWith('--tw-') ? null : customName;
|
|
30
|
+
}
|
|
31
|
+
if (typeof property.property === 'string' && property.property.startsWith('--')) {
|
|
32
|
+
return property.property.startsWith('--tw-') ? null : property.property;
|
|
33
|
+
}
|
|
34
|
+
if (property.property === 'all')
|
|
35
|
+
return 'all';
|
|
36
|
+
return kebabToCamel(property.property);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Collapse a single-element list into its scalar, otherwise return the
|
|
40
|
+
* list unchanged. Reanimated accepts both forms; the scalar is the
|
|
41
|
+
* common case.
|
|
42
|
+
* @param values Values to collapse.
|
|
43
|
+
* @returns A scalar when the list has one element, otherwise the list.
|
|
44
|
+
*/
|
|
45
|
+
function singleOrArray(values) {
|
|
46
|
+
if (values.length === 1)
|
|
47
|
+
return values[0];
|
|
48
|
+
return values;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Render a number without trailing noise (strips IEEE drift beyond 4
|
|
52
|
+
* decimals, then removes trailing zeros).
|
|
53
|
+
* @param value Number to format.
|
|
54
|
+
* @returns Compact string form.
|
|
55
|
+
*/
|
|
56
|
+
function formatNumber(value) {
|
|
57
|
+
const rounded = Math.round(value * 10_000) / 10_000;
|
|
58
|
+
return String(rounded);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reanimated v4's CSS engine doesn't accept `cubic-bezier(...)` as a
|
|
62
|
+
* string — only the predefined keywords `linear`, `ease`, `ease-in`,
|
|
63
|
+
* `ease-out`, `ease-in-out`, `step-start`, `step-end`. Tailwind's
|
|
64
|
+
* `transition-colors` / `ease-in-out` / etc. emit the CSS-standard
|
|
65
|
+
* Material curves as cubic-bezier; we snap those to the closest
|
|
66
|
+
* predefined keyword by matching the well-known control-point shapes,
|
|
67
|
+
* falling back to `ease-in-out` (the most common Tailwind default).
|
|
68
|
+
*
|
|
69
|
+
* Direct matches:
|
|
70
|
+
* - `cubic-bezier(0.25, 0.1, 0.25, 1)` → `ease` (CSS spec default)
|
|
71
|
+
* - `cubic-bezier(0.4, 0, 1, 1)` → `ease-in`
|
|
72
|
+
* - `cubic-bezier(0, 0, 0.2, 1)` → `ease-out`
|
|
73
|
+
* - `cubic-bezier(0.4, 0, 0.2, 1)` → `ease-in-out` (Material standard)
|
|
74
|
+
* - linear shape (`x1=y1=0, x2=y2=1`) → `linear`
|
|
75
|
+
*
|
|
76
|
+
* Anything else: classify by control-point shape — front-loaded curves
|
|
77
|
+
* → `ease-in`, back-loaded → `ease-out`, both → `ease-in-out`.
|
|
78
|
+
* @param x1 First control-point x (0–1).
|
|
79
|
+
* @param y1 First control-point y (0–1).
|
|
80
|
+
* @param x2 Second control-point x (0–1).
|
|
81
|
+
* @param y2 Second control-point y (0–1).
|
|
82
|
+
* @returns Closest matching CSS easing keyword.
|
|
83
|
+
*/
|
|
84
|
+
function snapCubicBezierToKeyword(x1, y1, x2, y2) {
|
|
85
|
+
if (matchesBezier(x1, y1, x2, y2, 0, 0, 1, 1))
|
|
86
|
+
return 'linear';
|
|
87
|
+
if (matchesBezier(x1, y1, x2, y2, 0.25, 0.1, 0.25, 1))
|
|
88
|
+
return 'ease';
|
|
89
|
+
if (matchesBezier(x1, y1, x2, y2, 0.4, 0, 1, 1))
|
|
90
|
+
return 'ease-in';
|
|
91
|
+
if (matchesBezier(x1, y1, x2, y2, 0, 0, 0.2, 1))
|
|
92
|
+
return 'ease-out';
|
|
93
|
+
if (matchesBezier(x1, y1, x2, y2, 0.4, 0, 0.2, 1))
|
|
94
|
+
return 'ease-in-out';
|
|
95
|
+
// Heuristic for unknown bezier shapes:
|
|
96
|
+
// - x1 ≈ 0 → starts straight (decelerates) → ease-out
|
|
97
|
+
// - x2 ≈ 1 → ends straight (accelerates) → ease-in
|
|
98
|
+
// - both small, both medium → ease-in-out
|
|
99
|
+
const startsFlat = x1 < 0.1;
|
|
100
|
+
const endsFlat = x2 > 0.9;
|
|
101
|
+
if (startsFlat && !endsFlat)
|
|
102
|
+
return 'ease-out';
|
|
103
|
+
if (!startsFlat && endsFlat)
|
|
104
|
+
return 'ease-in';
|
|
105
|
+
return 'ease-in-out';
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Approximate equality of two cubic-bezier control-point sets — IEEE
|
|
109
|
+
* float noise from lightningcss / culori means literal `===` rarely
|
|
110
|
+
* holds, so we tolerate a tiny epsilon.
|
|
111
|
+
* @param ax1 Actual first x.
|
|
112
|
+
* @param ay1 Actual first y.
|
|
113
|
+
* @param ax2 Actual second x.
|
|
114
|
+
* @param ay2 Actual second y.
|
|
115
|
+
* @param tx1 Target first x.
|
|
116
|
+
* @param ty1 Target first y.
|
|
117
|
+
* @param tx2 Target second x.
|
|
118
|
+
* @param ty2 Target second y.
|
|
119
|
+
* @returns Whether the two beziers are component-wise within 0.01 of each other.
|
|
120
|
+
*/
|
|
121
|
+
function matchesBezier(ax1, ay1, ax2, ay2, tx1, ty1, tx2, ty2) {
|
|
122
|
+
const tolerance = 0.01;
|
|
123
|
+
return (Math.abs(ax1 - tx1) < tolerance &&
|
|
124
|
+
Math.abs(ay1 - ty1) < tolerance &&
|
|
125
|
+
Math.abs(ax2 - tx2) < tolerance &&
|
|
126
|
+
Math.abs(ay2 - ty2) < tolerance);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Serialize a lightningcss `EasingFunction` into a CSS string Reanimated
|
|
130
|
+
* v4's CSS engine understands. Reanimated accepts the same timing-function
|
|
131
|
+
* strings as CSS transitions/animations, so we emit the canonical CSS
|
|
132
|
+
* form.
|
|
133
|
+
* @param fn Typed easing function.
|
|
134
|
+
* @returns CSS string, e.g. `'linear'` / `'ease-in-out'` / `'cubic-bezier(0.4, 0, 0.2, 1)'`.
|
|
135
|
+
*/
|
|
136
|
+
function easingFunctionToString(fn) {
|
|
137
|
+
switch (fn.type) {
|
|
138
|
+
case 'linear': {
|
|
139
|
+
return 'linear';
|
|
140
|
+
}
|
|
141
|
+
case 'ease':
|
|
142
|
+
case 'ease-in':
|
|
143
|
+
case 'ease-out':
|
|
144
|
+
case 'ease-in-out': {
|
|
145
|
+
return fn.type;
|
|
146
|
+
}
|
|
147
|
+
case 'cubic-bezier': {
|
|
148
|
+
return snapCubicBezierToKeyword(fn.x1, fn.y1, fn.x2, fn.y2);
|
|
149
|
+
}
|
|
150
|
+
case 'steps': {
|
|
151
|
+
const pos = fn.position?.type ?? 'end';
|
|
152
|
+
return `steps(${fn.count}, ${pos})`;
|
|
153
|
+
}
|
|
154
|
+
default: {
|
|
155
|
+
return 'ease';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Format a `Time` value into a CSS string (`150ms`, `1s`). Reanimated's
|
|
161
|
+
* CSS engine accepts either `ms` or `s`; we pick `ms` unless the value
|
|
162
|
+
* is a whole-second multiple for readability.
|
|
163
|
+
* @param time Typed time value.
|
|
164
|
+
* @returns CSS time string.
|
|
165
|
+
*/
|
|
166
|
+
function timeToString(time) {
|
|
167
|
+
if (time.type === 'milliseconds')
|
|
168
|
+
return `${formatNumber(time.value)}ms`;
|
|
169
|
+
return `${formatNumber(time.value)}s`;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Convert a single `animation-name` value to a string. Tailwind's
|
|
173
|
+
* `animate-none` produces `{ type: 'none' }` which we drop.
|
|
174
|
+
* @param name Typed animation name.
|
|
175
|
+
* @returns Keyframe identifier, or null when `none`.
|
|
176
|
+
*/
|
|
177
|
+
function animationNameToString(name) {
|
|
178
|
+
if (name.type === 'none')
|
|
179
|
+
return null;
|
|
180
|
+
if (name.type === 'ident')
|
|
181
|
+
return name.value;
|
|
182
|
+
if (name.type === 'string')
|
|
183
|
+
return name.value;
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Convert a single `animation-iteration-count` value to the CSS shape
|
|
188
|
+
* Reanimated wants: either a finite integer or the `'infinite'` string.
|
|
189
|
+
* @param count Typed iteration count.
|
|
190
|
+
* @returns Number or `'infinite'`.
|
|
191
|
+
*/
|
|
192
|
+
function iterationCountToValue(count) {
|
|
193
|
+
if (count.type === 'infinite')
|
|
194
|
+
return 'infinite';
|
|
195
|
+
return count.value;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Decompose the `animation: <name> <duration> <timing> <iteration> …`
|
|
199
|
+
* shorthand into the per-property RN entries Reanimated consumes. A single
|
|
200
|
+
* `animation` declaration can name multiple animations — we emit the first
|
|
201
|
+
* one (Tailwind's `animate-*` utilities always emit exactly one).
|
|
202
|
+
* @param animations Parsed animation list from lightningcss.
|
|
203
|
+
* @returns RN entries, empty when the shorthand names `none`.
|
|
204
|
+
*/
|
|
205
|
+
function animationShorthandToEntries(animations) {
|
|
206
|
+
const [first] = animations;
|
|
207
|
+
if (!first)
|
|
208
|
+
return [];
|
|
209
|
+
const name = animationNameToString(first.name);
|
|
210
|
+
if (!name)
|
|
211
|
+
return [];
|
|
212
|
+
const entries = [['animationName', name]];
|
|
213
|
+
if (first.duration)
|
|
214
|
+
entries.push(['animationDuration', timeToString(first.duration)]);
|
|
215
|
+
if (first.timingFunction)
|
|
216
|
+
entries.push(['animationTimingFunction', easingFunctionToString(first.timingFunction)]);
|
|
217
|
+
if (first.iterationCount)
|
|
218
|
+
entries.push(['animationIterationCount', iterationCountToValue(first.iterationCount)]);
|
|
219
|
+
if (first.direction && first.direction !== 'normal')
|
|
220
|
+
entries.push(['animationDirection', first.direction]);
|
|
221
|
+
if (first.fillMode && first.fillMode !== 'none')
|
|
222
|
+
entries.push(['animationFillMode', first.fillMode]);
|
|
223
|
+
if (first.delay && first.delay.value !== 0)
|
|
224
|
+
entries.push(['animationDelay', timeToString(first.delay)]);
|
|
225
|
+
if (first.playState && first.playState !== 'running')
|
|
226
|
+
entries.push(['animationPlayState', first.playState]);
|
|
227
|
+
return entries;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Emit `animationName` for a standalone `animation-name: spin` declaration.
|
|
231
|
+
* @param names Typed `animation-name` list.
|
|
232
|
+
* @returns Single-entry `animationName` or empty when `none`.
|
|
233
|
+
*/
|
|
234
|
+
function animationNameEntries(names) {
|
|
235
|
+
const [first] = names;
|
|
236
|
+
if (!first)
|
|
237
|
+
return [];
|
|
238
|
+
const name = animationNameToString(first);
|
|
239
|
+
if (!name)
|
|
240
|
+
return [];
|
|
241
|
+
return [['animationName', name]];
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Emit `animationDuration` for a standalone `animation-duration` declaration.
|
|
245
|
+
* @param durations Typed duration list.
|
|
246
|
+
* @returns Single-entry list.
|
|
247
|
+
*/
|
|
248
|
+
function animationDurationEntries(durations) {
|
|
249
|
+
const [first] = durations;
|
|
250
|
+
if (!first)
|
|
251
|
+
return [];
|
|
252
|
+
return [['animationDuration', timeToString(first)]];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Emit `animationTimingFunction` for a standalone `animation-timing-function`.
|
|
256
|
+
* @param fns Typed timing-function list.
|
|
257
|
+
* @returns Single-entry list.
|
|
258
|
+
*/
|
|
259
|
+
function animationTimingFunctionEntries(fns) {
|
|
260
|
+
const [first] = fns;
|
|
261
|
+
if (!first)
|
|
262
|
+
return [];
|
|
263
|
+
return [['animationTimingFunction', easingFunctionToString(first)]];
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Emit `animationIterationCount` for a standalone declaration.
|
|
267
|
+
* @param counts Typed iteration-count list.
|
|
268
|
+
* @returns Single-entry list.
|
|
269
|
+
*/
|
|
270
|
+
function animationIterationCountEntries(counts) {
|
|
271
|
+
const [first] = counts;
|
|
272
|
+
if (!first)
|
|
273
|
+
return [];
|
|
274
|
+
return [['animationIterationCount', iterationCountToValue(first)]];
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Emit `animationDelay` for a standalone declaration.
|
|
278
|
+
* @param delays Typed delay list.
|
|
279
|
+
* @returns Single-entry list.
|
|
280
|
+
*/
|
|
281
|
+
function animationDelayEntries(delays) {
|
|
282
|
+
const [first] = delays;
|
|
283
|
+
if (!first)
|
|
284
|
+
return [];
|
|
285
|
+
return [['animationDelay', timeToString(first)]];
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Emit `animationDirection` for a standalone declaration.
|
|
289
|
+
* @param directions Typed direction list.
|
|
290
|
+
* @returns Single-entry list.
|
|
291
|
+
*/
|
|
292
|
+
function animationDirectionEntries(directions) {
|
|
293
|
+
const [first] = directions;
|
|
294
|
+
if (!first)
|
|
295
|
+
return [];
|
|
296
|
+
return [['animationDirection', first]];
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Emit `animationFillMode` for a standalone declaration.
|
|
300
|
+
* @param modes Typed fill-mode list.
|
|
301
|
+
* @returns Single-entry list.
|
|
302
|
+
*/
|
|
303
|
+
function animationFillModeEntries(modes) {
|
|
304
|
+
const [first] = modes;
|
|
305
|
+
if (!first)
|
|
306
|
+
return [];
|
|
307
|
+
return [['animationFillMode', first]];
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Emit `animationPlayState` for a standalone declaration.
|
|
311
|
+
* @param states Typed play-state list.
|
|
312
|
+
* @returns Single-entry list.
|
|
313
|
+
*/
|
|
314
|
+
function animationPlayStateEntries(states) {
|
|
315
|
+
const [first] = states;
|
|
316
|
+
if (!first)
|
|
317
|
+
return [];
|
|
318
|
+
return [['animationPlayState', first]];
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Convert the `transition-property` list into an RN-consumable form.
|
|
322
|
+
* Reanimated accepts either a string (`'all'`, `'opacity'`) or an array
|
|
323
|
+
* of property names. We emit the array shape even for singletons so the
|
|
324
|
+
* runtime can handle it uniformly.
|
|
325
|
+
* @param properties Typed transition-property list.
|
|
326
|
+
* @returns Single-entry list with `transitionProperty`.
|
|
327
|
+
*/
|
|
328
|
+
function transitionPropertyEntries(properties) {
|
|
329
|
+
const names = properties.map((p) => propertyIdToString(p)).filter((name) => name !== null);
|
|
330
|
+
if (names.length === 0)
|
|
331
|
+
return [];
|
|
332
|
+
if (names.length === 1)
|
|
333
|
+
return [['transitionProperty', names[0]]];
|
|
334
|
+
return [['transitionProperty', names]];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Decompose the `transition: <prop> <duration> <timing> <delay>` shorthand
|
|
338
|
+
* into the per-property RN entries Reanimated consumes. A declaration can
|
|
339
|
+
* name multiple transitions; we emit one entry per slot, collapsing
|
|
340
|
+
* identical slots into a scalar.
|
|
341
|
+
* @param transitions Parsed transition list from lightningcss.
|
|
342
|
+
* @returns RN entries — zero or more.
|
|
343
|
+
*/
|
|
344
|
+
function transitionShorthandToEntries(transitions) {
|
|
345
|
+
if (transitions.length === 0)
|
|
346
|
+
return [];
|
|
347
|
+
const properties = [];
|
|
348
|
+
const durations = [];
|
|
349
|
+
const timings = [];
|
|
350
|
+
const delays = [];
|
|
351
|
+
for (const t of transitions) {
|
|
352
|
+
const name = propertyIdToString(t.property);
|
|
353
|
+
if (name)
|
|
354
|
+
properties.push(name);
|
|
355
|
+
if (t.duration)
|
|
356
|
+
durations.push(timeToString(t.duration));
|
|
357
|
+
if (t.timingFunction)
|
|
358
|
+
timings.push(easingFunctionToString(t.timingFunction));
|
|
359
|
+
if (t.delay)
|
|
360
|
+
delays.push(timeToString(t.delay));
|
|
361
|
+
}
|
|
362
|
+
const entries = [];
|
|
363
|
+
if (properties.length > 0)
|
|
364
|
+
entries.push(['transitionProperty', singleOrArray(properties)]);
|
|
365
|
+
if (durations.length > 0)
|
|
366
|
+
entries.push(['transitionDuration', singleOrArray(durations)]);
|
|
367
|
+
if (timings.length > 0)
|
|
368
|
+
entries.push(['transitionTimingFunction', singleOrArray(timings)]);
|
|
369
|
+
if (delays.some((d) => d !== '0s'))
|
|
370
|
+
entries.push(['transitionDelay', singleOrArray(delays)]);
|
|
371
|
+
return entries;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Emit `transitionDuration` for a standalone declaration.
|
|
375
|
+
* @param durations Typed duration list.
|
|
376
|
+
* @returns Single-entry list.
|
|
377
|
+
*/
|
|
378
|
+
function transitionDurationEntries(durations) {
|
|
379
|
+
if (durations.length === 0)
|
|
380
|
+
return [];
|
|
381
|
+
const strings = durations.map((d) => timeToString(d));
|
|
382
|
+
return [['transitionDuration', singleOrArray(strings)]];
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Emit `transitionTimingFunction` for a standalone declaration.
|
|
386
|
+
* @param fns Typed timing-function list.
|
|
387
|
+
* @returns Single-entry list.
|
|
388
|
+
*/
|
|
389
|
+
function transitionTimingFunctionEntries(fns) {
|
|
390
|
+
if (fns.length === 0)
|
|
391
|
+
return [];
|
|
392
|
+
const strings = fns.map((f) => easingFunctionToString(f));
|
|
393
|
+
return [['transitionTimingFunction', singleOrArray(strings)]];
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Emit `transitionDelay` for a standalone declaration.
|
|
397
|
+
* @param delays Typed delay list.
|
|
398
|
+
* @returns Single-entry list.
|
|
399
|
+
*/
|
|
400
|
+
function transitionDelayEntries(delays) {
|
|
401
|
+
if (delays.length === 0)
|
|
402
|
+
return [];
|
|
403
|
+
const strings = delays.map((d) => timeToString(d));
|
|
404
|
+
return [['transitionDelay', singleOrArray(strings)]];
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export { animationDelayEntries, animationDirectionEntries, animationDurationEntries, animationFillModeEntries, animationIterationCountEntries, animationNameEntries, animationNameToString, animationPlayStateEntries, animationShorthandToEntries, animationTimingFunctionEntries, easingFunctionToString, iterationCountToValue, timeToString, transitionDelayEntries, transitionDurationEntries, transitionPropertyEntries, transitionShorthandToEntries, transitionTimingFunctionEntries };
|
|
408
|
+
//# sourceMappingURL=animation.mjs.map
|