@animus-ui/system 0.1.20 → 0.1.22

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.
Files changed (123) hide show
  1. package/dist/appearance/controller.d.ts +35 -0
  2. package/dist/appearance/controller.d.ts.map +1 -0
  3. package/dist/appearance/controller.js +69 -0
  4. package/dist/appearance/index.d.ts +2 -7
  5. package/dist/appearance/react.d.ts +10 -0
  6. package/dist/appearance/react.d.ts.map +1 -0
  7. package/dist/appearance/react.js +12 -0
  8. package/dist/appearance/svelte.d.ts +12 -0
  9. package/dist/appearance/svelte.d.ts.map +1 -0
  10. package/dist/appearance/svelte.js +14 -0
  11. package/dist/bootstrap/index.d.ts +24 -1
  12. package/dist/bootstrap/index.d.ts.map +1 -1
  13. package/dist/bootstrap/index.js +10 -2
  14. package/dist/class-resolver.d.ts +2 -6
  15. package/dist/class-resolver.js +1 -1
  16. package/dist/component-stJhG_A-.d.ts +659 -0
  17. package/dist/component-stJhG_A-.d.ts.map +1 -0
  18. package/dist/compose-BQi7TDtL.d.ts +15 -0
  19. package/dist/compose-BQi7TDtL.d.ts.map +1 -0
  20. package/dist/compose.d.ts +2 -12
  21. package/dist/composeWithContext.d.ts +9 -7
  22. package/dist/composeWithContext.d.ts.map +1 -1
  23. package/dist/createClassResolver-Do1nmvkf.d.ts +71 -0
  24. package/dist/createClassResolver-Do1nmvkf.d.ts.map +1 -0
  25. package/dist/{createClassResolver-DPLExqGy.js → createClassResolver-DtHjTYa7.js} +106 -79
  26. package/dist/createComposedFamily-BbA_d0QH.js +195 -0
  27. package/dist/createComposedFamily-BkrvSsfl.d.ts +40 -0
  28. package/dist/createComposedFamily-BkrvSsfl.d.ts.map +1 -0
  29. package/dist/groups/index.d.ts +702 -699
  30. package/dist/groups/index.d.ts.map +1 -1
  31. package/dist/index-BjJkQo64.d.ts +10 -0
  32. package/dist/index-BjJkQo64.d.ts.map +1 -0
  33. package/dist/index-C1AAiaiJ.d.ts +663 -0
  34. package/dist/index-C1AAiaiJ.d.ts.map +1 -0
  35. package/dist/index.d.ts +6 -26
  36. package/dist/index.js +141 -41
  37. package/dist/runtime-entry.d.ts +3 -5
  38. package/dist/runtime-entry.js +3 -3
  39. package/package.json +15 -3
  40. package/dist/Animus.d.ts +0 -81
  41. package/dist/Animus.d.ts.map +0 -1
  42. package/dist/AnimusExtended.d.ts +0 -82
  43. package/dist/AnimusExtended.d.ts.map +0 -1
  44. package/dist/SystemBuilder.d.ts +0 -305
  45. package/dist/SystemBuilder.d.ts.map +0 -1
  46. package/dist/appearance/index.d.ts.map +0 -1
  47. package/dist/asset.d.ts +0 -16
  48. package/dist/asset.d.ts.map +0 -1
  49. package/dist/bootstrap/createAppearanceBootstrap.d.ts +0 -14
  50. package/dist/bootstrap/createAppearanceBootstrap.d.ts.map +0 -1
  51. package/dist/class-resolver.d.ts.map +0 -1
  52. package/dist/compose.d.ts.map +0 -1
  53. package/dist/conditions.d.ts +0 -94
  54. package/dist/conditions.d.ts.map +0 -1
  55. package/dist/createComposedFamily-C6CLAsMx.js +0 -128
  56. package/dist/declarations.d.ts +0 -38
  57. package/dist/declarations.d.ts.map +0 -1
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/keyframes.d.ts +0 -24
  60. package/dist/keyframes.d.ts.map +0 -1
  61. package/dist/runtime/assert-root-slot.d.ts +0 -6
  62. package/dist/runtime/assert-root-slot.d.ts.map +0 -1
  63. package/dist/runtime/createClassResolver.d.ts +0 -11
  64. package/dist/runtime/createClassResolver.d.ts.map +0 -1
  65. package/dist/runtime/createComposedFamily.d.ts +0 -11
  66. package/dist/runtime/createComposedFamily.d.ts.map +0 -1
  67. package/dist/runtime/index.d.ts +0 -14
  68. package/dist/runtime/index.d.ts.map +0 -1
  69. package/dist/runtime/is-dev.d.ts +0 -6
  70. package/dist/runtime/is-dev.d.ts.map +0 -1
  71. package/dist/runtime/resolveClasses.d.ts +0 -83
  72. package/dist/runtime/resolveClasses.d.ts.map +0 -1
  73. package/dist/runtime/witness.d.ts +0 -10
  74. package/dist/runtime/witness.d.ts.map +0 -1
  75. package/dist/runtime-entry.d.ts.map +0 -1
  76. package/dist/scales/createScale.d.ts +0 -7
  77. package/dist/scales/createScale.d.ts.map +0 -1
  78. package/dist/selectors.d.ts +0 -27
  79. package/dist/selectors.d.ts.map +0 -1
  80. package/dist/theme/createTheme.d.ts +0 -170
  81. package/dist/theme/createTheme.d.ts.map +0 -1
  82. package/dist/theme/flattenScale.d.ts +0 -15
  83. package/dist/theme/flattenScale.d.ts.map +0 -1
  84. package/dist/theme/index.d.ts +0 -5
  85. package/dist/theme/index.d.ts.map +0 -1
  86. package/dist/theme/property-records.d.ts +0 -79
  87. package/dist/theme/property-records.d.ts.map +0 -1
  88. package/dist/theme/resolveReferences.d.ts +0 -27
  89. package/dist/theme/resolveReferences.d.ts.map +0 -1
  90. package/dist/theme/serializeTokens.d.ts +0 -5
  91. package/dist/theme/serializeTokens.d.ts.map +0 -1
  92. package/dist/theme/types.d.ts +0 -20
  93. package/dist/theme/types.d.ts.map +0 -1
  94. package/dist/theme/utils.d.ts +0 -11
  95. package/dist/theme/utils.d.ts.map +0 -1
  96. package/dist/transforms/border.d.ts +0 -3
  97. package/dist/transforms/border.d.ts.map +0 -1
  98. package/dist/transforms/createTransform.d.ts +0 -24
  99. package/dist/transforms/createTransform.d.ts.map +0 -1
  100. package/dist/transforms/grid.d.ts +0 -5
  101. package/dist/transforms/grid.d.ts.map +0 -1
  102. package/dist/transforms/index.d.ts +0 -5
  103. package/dist/transforms/index.d.ts.map +0 -1
  104. package/dist/transforms/size.d.ts +0 -5
  105. package/dist/transforms/size.d.ts.map +0 -1
  106. package/dist/types/component.d.ts +0 -100
  107. package/dist/types/component.d.ts.map +0 -1
  108. package/dist/types/config.d.ts +0 -149
  109. package/dist/types/config.d.ts.map +0 -1
  110. package/dist/types/properties.d.ts +0 -17
  111. package/dist/types/properties.d.ts.map +0 -1
  112. package/dist/types/props.d.ts +0 -19
  113. package/dist/types/props.d.ts.map +0 -1
  114. package/dist/types/scales.d.ts +0 -3
  115. package/dist/types/scales.d.ts.map +0 -1
  116. package/dist/types/shared.d.ts +0 -4
  117. package/dist/types/shared.d.ts.map +0 -1
  118. package/dist/types/theme.d.ts +0 -111
  119. package/dist/types/theme.d.ts.map +0 -1
  120. package/dist/types/utils.d.ts +0 -5
  121. package/dist/types/utils.d.ts.map +0 -1
  122. package/dist/utils/deepMerge.d.ts +0 -2
  123. package/dist/utils/deepMerge.d.ts.map +0 -1
@@ -0,0 +1,195 @@
1
+ import { n as resolveClasses } from "./createClassResolver-DtHjTYa7.js";
2
+ import { t as assertRootSlot } from "./assert-root-slot-C3Lp9MNJ.js";
3
+ import { Children, cloneElement, createElement, forwardRef } from "react";
4
+ //#region src/runtime/index.ts
5
+ /** Sets one ref, returning the cleanup a callback ref hands back, if any. */
6
+ function setRef(ref, value) {
7
+ if (typeof ref === "function") {
8
+ const cleanup = ref(value);
9
+ return typeof cleanup === "function" ? cleanup : void 0;
10
+ }
11
+ if (ref) ref.current = value;
12
+ }
13
+ /**
14
+ * Attaches every ref. When one hands back a cleanup (React 19), the merged
15
+ * callback returns a cleanup that runs it and resets the others with null.
16
+ * Otherwise it returns nothing, since React 18 warns on a returned function,
17
+ * and React detaches by calling it with null, which reaches every ref.
18
+ */
19
+ function mergeRefs(parent, child) {
20
+ return (node) => {
21
+ const refs = [parent, child];
22
+ const cleanups = refs.map((ref) => setRef(ref, node));
23
+ if (!cleanups.some(Boolean)) return;
24
+ return () => {
25
+ refs.forEach((ref, index) => {
26
+ const cleanup = cleanups[index];
27
+ if (cleanup) cleanup();
28
+ else setRef(ref, null);
29
+ });
30
+ };
31
+ };
32
+ }
33
+ const mergedRefs = /* @__PURE__ */ new WeakMap();
34
+ /**
35
+ * The ref an asChild element gets. A single ref needs no merging; a pair gets
36
+ * one merged callback, cached by the refs themselves, so a re-render with
37
+ * unchanged refs hands React the same callback and the refs stay attached.
38
+ * The runtime is hook-free so components work in server components, which
39
+ * rules per-instance memoization out.
40
+ */
41
+ function composeRefs(parent, child) {
42
+ if (!parent) return child;
43
+ if (!child) return parent;
44
+ let byChild = mergedRefs.get(parent);
45
+ if (!byChild) {
46
+ byChild = /* @__PURE__ */ new WeakMap();
47
+ mergedRefs.set(parent, byChild);
48
+ }
49
+ let merged = byChild.get(child);
50
+ if (!merged) {
51
+ merged = mergeRefs(parent, child);
52
+ byChild.set(child, merged);
53
+ }
54
+ return merged;
55
+ }
56
+ /**
57
+ * `data-*` and `aria-*` reach the DOM even when they key a variant or state,
58
+ * so headless libraries driving those attributes still see them.
59
+ */
60
+ function forwardProps(props, filterProps, domProps) {
61
+ for (const [key, value] of Object.entries(props)) {
62
+ if (key === "className") continue;
63
+ if (!(key.startsWith("data-") || key.startsWith("aria-")) && filterProps.has(key)) continue;
64
+ domProps[key] = value;
65
+ }
66
+ }
67
+ /**
68
+ * React 19 carries a ref as a plain prop and warns on `element.ref`; React 18
69
+ * keeps it on the element and guards `props.ref` with a warning getter.
70
+ * Reading the descriptor never invokes either getter.
71
+ */
72
+ function childRefOf(child) {
73
+ const propRef = Object.getOwnPropertyDescriptor(child.props, "ref");
74
+ if (propRef && !propRef.get) return propRef.value;
75
+ return child.ref;
76
+ }
77
+ /**
78
+ * The child wins every conflict: the slot's props spread under the child's
79
+ * own, so a handler declared on the child replaces the slot's instead of
80
+ * chaining. `variables`, Animus's own dynamic styles, win over the child's.
81
+ */
82
+ function renderSlot(children, props, ref, variables) {
83
+ const child = Children.only(children);
84
+ const { asChild: _asChild, children: _children, className, ref: propRef, style, ...slotProps } = props;
85
+ const mergedClassName = [className, child.props.className].filter(Boolean).join(" ");
86
+ const mergedStyle = variables || style || child.props.style ? {
87
+ ...style,
88
+ ...child.props.style,
89
+ ...variables
90
+ } : void 0;
91
+ return cloneElement(child, {
92
+ ...slotProps,
93
+ ...child.props,
94
+ ref: composeRefs(ref ?? propRef, childRefOf(child)),
95
+ className: mergedClassName,
96
+ ...mergedStyle ? { style: mergedStyle } : {}
97
+ });
98
+ }
99
+ /**
100
+ * Renders an `asChild` slot exactly as Animus renders its own: the one child
101
+ * element, with `props` spread under the child's props so the child wins
102
+ * every conflict, class names joined (the slot's first), styles merged and
103
+ * both refs attached. An `asComponent` target that receives `asChild` calls
104
+ * it in place of its element:
105
+ *
106
+ * ```tsx
107
+ * if (asChild) return renderAsChild(children, props, ref);
108
+ * ```
109
+ *
110
+ * `asChild` and `children` in `props` are dropped, and `ref` defaults to
111
+ * `props.ref`. It throws unless `children` is exactly one React element.
112
+ *
113
+ * An `asComponent` component types `children` as any `ReactNode`, whatever
114
+ * the target declares, so a target rendering a void element such as `input`
115
+ * leaves its children out without `asChild`, where React would throw.
116
+ */
117
+ function renderAsChild(children, props, ref) {
118
+ return renderSlot(children, props, ref);
119
+ }
120
+ /**
121
+ * A string terminal renders `as` in place of its tag. A component terminal
122
+ * always renders its component, which receives `as` and `asChild` like any
123
+ * other prop, so its own wiring runs whatever element it ends up rendering.
124
+ */
125
+ function renderElement(element, filterProps, props, ref, classes, dynamicStyle) {
126
+ const target = typeof element === "string" ? props.as || element : element;
127
+ const domProps = {
128
+ ref,
129
+ className: classes.join(" ")
130
+ };
131
+ forwardProps(props, filterProps, domProps);
132
+ if (dynamicStyle) domProps.style = props.style ? {
133
+ ...props.style,
134
+ ...dynamicStyle
135
+ } : dynamicStyle;
136
+ return createElement(target, domProps);
137
+ }
138
+ function createComponent(element, className, config, systemPropMap, dynamicPropConfig) {
139
+ const variantProps = config.variants ? Object.keys(config.variants) : [];
140
+ const stateProps = config.states || [];
141
+ const systemPropNames = config.systemPropNames || [];
142
+ const ownsPolymorphism = typeof element === "string";
143
+ const filterProps = /* @__PURE__ */ new Set([
144
+ ...ownsPolymorphism ? ["as", "asChild"] : [],
145
+ ...variantProps,
146
+ ...stateProps,
147
+ ...systemPropNames
148
+ ]);
149
+ const Component = forwardRef((props, ref) => {
150
+ const { classes, dynamicStyle } = resolveClasses(className, props, config, systemPropMap, dynamicPropConfig);
151
+ if (props.className) classes.push(props.className);
152
+ if (props.asChild && ownsPolymorphism) {
153
+ const slotProps = { className: classes.join(" ") };
154
+ forwardProps(props, filterProps, slotProps);
155
+ return renderSlot(props.children, slotProps, ref, dynamicStyle);
156
+ }
157
+ return renderElement(element, filterProps, props, ref, classes, dynamicStyle);
158
+ });
159
+ Component.displayName = className;
160
+ const variantDefaults = {};
161
+ if (config.variants) {
162
+ for (const [prop, vc] of Object.entries(config.variants)) if (vc.default != null) variantDefaults[prop] = vc.default;
163
+ }
164
+ const customTransforms = {};
165
+ for (const [prop, dc] of Object.entries(config.customDynamicConfig ?? {})) if (dc.transform) customTransforms[prop] = dc.transform;
166
+ return Object.assign(Component, {
167
+ variantDefaults: Object.freeze(variantDefaults),
168
+ customTransforms: Object.freeze(customTransforms),
169
+ extend: () => {
170
+ throw new Error(`Cannot extend extracted component "${className}" at runtime. Extensions must be authored in source code using the builder API (e.g. import the original component and call .extend() there) so the extraction pipeline can resolve them at build time.`);
171
+ }
172
+ });
173
+ }
174
+ //#endregion
175
+ //#region src/runtime/createComposedFamily.ts
176
+ /**
177
+ * The extraction emitter rewrites `compose()` calls to this form. It stays
178
+ * hook- and context-free so composed families work in server components.
179
+ */
180
+ function createComposedFamily(slots, config) {
181
+ assertRootSlot(slots, "createComposedFamily");
182
+ const { name } = config;
183
+ const result = {};
184
+ for (const [slotName, SourceComponent] of Object.entries(slots)) {
185
+ const Wrapper = forwardRef((props, ref) => createElement(SourceComponent, {
186
+ ...props,
187
+ ref
188
+ }, props.children));
189
+ Wrapper.displayName = `${name}.${slotName}`;
190
+ result[slotName] = Wrapper;
191
+ }
192
+ return result;
193
+ }
194
+ //#endregion
195
+ export { createComponent as n, renderAsChild as r, createComposedFamily as t };
@@ -0,0 +1,40 @@
1
+ import { a as DynamicPropConfig, i as ClassResolverConfig, o as SystemPropMap } from "./createClassResolver-Do1nmvkf.js";
2
+ import { ForwardRefExoticComponent, ReactElement, ReactNode, Ref, forwardRef } from "react";
3
+ //#region src/runtime/index.d.ts
4
+ interface ComponentConfig extends ClassResolverConfig {}
5
+ type ElementType = string | React.ComponentType<any>;
6
+ type Transform = NonNullable<DynamicPropConfig[string]['transform']>;
7
+ type AnimusComponent = ReturnType<typeof forwardRef> & {
8
+ extend: () => never;
9
+ variantDefaults: Readonly<Record<string, string>>;
10
+ customTransforms: Readonly<Record<string, Transform>>;
11
+ };
12
+ /**
13
+ * Renders an `asChild` slot exactly as Animus renders its own: the one child
14
+ * element, with `props` spread under the child's props so the child wins
15
+ * every conflict, class names joined (the slot's first), styles merged and
16
+ * both refs attached. An `asComponent` target that receives `asChild` calls
17
+ * it in place of its element:
18
+ *
19
+ * ```tsx
20
+ * if (asChild) return renderAsChild(children, props, ref);
21
+ * ```
22
+ *
23
+ * `asChild` and `children` in `props` are dropped, and `ref` defaults to
24
+ * `props.ref`. It throws unless `children` is exactly one React element.
25
+ *
26
+ * An `asComponent` component types `children` as any `ReactNode`, whatever
27
+ * the target declares, so a target rendering a void element such as `input`
28
+ * leaves its children out without `asChild`, where React would throw.
29
+ */
30
+ declare function renderAsChild(children: ReactNode, props: object, ref?: Ref<any>): ReactElement;
31
+ declare function createComponent(element: ElementType, className: string, config: ComponentConfig, systemPropMap?: SystemPropMap, dynamicPropConfig?: DynamicPropConfig): AnimusComponent;
32
+ //#endregion
33
+ //#region src/runtime/createComposedFamily.d.ts
34
+ interface ComposedFamilyConfig {
35
+ name: string;
36
+ }
37
+ declare function createComposedFamily(slots: Record<string, ForwardRefExoticComponent<any>>, config: ComposedFamilyConfig): Record<string, ForwardRefExoticComponent<any>>;
38
+ //#endregion
39
+ export { createComponent as n, renderAsChild as r, createComposedFamily as t };
40
+ //# sourceMappingURL=createComposedFamily-BkrvSsfl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createComposedFamily-BkrvSsfl.d.ts","names":[],"sources":["../src/runtime/index.ts","../src/runtime/createComposedFamily.ts"],"mappings":";;;UAgBU,wBAAwB;KAE7B,uBAAuB,MAAM;KAE7B,YAAY,YAAY;KAExB,kBAAkB,kBAAkB;EACvC;EACA,iBAAiB,SAAS;EAC1B,kBAAkB,SAAS,eAAe;;;;;;;;;;;;;;;;;;;;iBAyJ5B,cACd,UAAU,WACV,eACA,MAAM,WACL;iBAkCa,gBACd,SAAS,aACT,mBACA,QAAQ,iBACR,gBAAgB,eAChB,oBAAoB,oBACnB;;;UChNO;EACR;;iBAGc,qBACd,OAAO,eAAe,iCACtB,QAAQ,uBACP,eAAe"}