@spark-ui/internal-utils 10.4.1 → 10.4.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [10.4.3](https://github.com/leboncoin/spark-web/compare/v10.4.2...v10.4.3) (2025-05-12)
7
+
8
+ **Note:** Version bump only for package @spark-ui/internal-utils
9
+
10
+ ## [10.4.2](https://github.com/leboncoin/spark-web/compare/v10.4.1...v10.4.2) (2025-05-12)
11
+
12
+ **Note:** Version bump only for package @spark-ui/internal-utils
13
+
6
14
  ## [10.4.1](https://github.com/leboncoin/spark-web/compare/v10.4.0...v10.4.1) (2025-05-12)
7
15
 
8
16
  **Note:** Version bump only for package @spark-ui/internal-utils
@@ -0,0 +1,3 @@
1
+ type EnsureKeys<ExpectedKeys extends (keyof Target)[], Target> = keyof Target extends ExpectedKeys[number] ? unknown : `Missing required keys: ${Exclude<keyof Target, ExpectedKeys[number]> & string}`;
2
+ export declare const createSplitProps: <Target>() => <Keys extends (keyof Target)[], Props extends Target = Target>(props: Props, keys: Keys & EnsureKeys<Keys, Target>) => [Target, Omit<Props, Extract<(Keys & EnsureKeys<Keys, Target>)[number], string>>];
3
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,115 +1,8 @@
1
- import { ReactNode } from 'react';
2
-
3
- /**
4
- * A utility function that serves as a workaround for Tailwind CSS IntelliSense issues
5
- * in large objects or when regex breaks in VSCode.
6
- *
7
- * For more context, see: https://github.com/joe-bell/cva/discussions/85#discussioncomment-4568738
8
- *
9
- * @example
10
- *
11
- * // before
12
- * const styles: cva(['flex bg-main', 'cursor-pointer'], {
13
- * variants: {
14
- * size: {
15
- * small: "h-sz-24",
16
- * medium: "h-sz-48"
17
- * }
18
- * }
19
- * })
20
- *
21
- * // after
22
- * const styles = cva(tw(['flex bg-main', 'cursor-pointer']), {
23
- * variants: {
24
- * size: {
25
- * small: tw("h-sz-24"),
26
- * medium: tw("h-sz-48"),
27
- * }
28
- * }
29
- * })
30
- */
31
- declare function tw<T>(v: T): T;
32
-
33
- declare const sizes: readonly ["current", "sm", "md", "lg", "xl"];
34
- declare const intents: readonly ["current", "main", "support", "success", "error", "info", "alert", "danger", "neutral", "surface", "accent", "basic"];
35
- declare const designs: readonly ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"];
36
- declare const shapes: readonly ["rounded", "square", "pill"];
37
-
38
- declare const constants_designs: typeof designs;
39
- declare const constants_intents: typeof intents;
40
- declare const constants_shapes: typeof shapes;
41
- declare const constants_sizes: typeof sizes;
42
- declare namespace constants {
43
- export { constants_designs as designs, constants_intents as intents, constants_shapes as shapes, constants_sizes as sizes };
44
- }
45
-
46
- type Picks<T extends object, PickedItems extends (keyof T)[], Acc = {}> = PickedItems extends [
47
- infer Head,
48
- ...infer Rest
49
- ] ? Rest extends (keyof T)[] ? Head extends keyof T ? Picks<T, Rest, Acc & Pick<T, Head>> : Acc : Acc : Acc;
50
- type Size = (typeof sizes)[number];
51
- type SizeLookup = Record<Size, string[]>;
52
- type Intent = (typeof intents)[number];
53
- type IntentLookup = Record<Intent, string[]>;
54
- type Design = (typeof designs)[number];
55
- type DesignLookup = Record<Design, string[]>;
56
- type Shape = (typeof shapes)[number];
57
- type ShapeLookup = Record<Shape, string[]>;
58
- interface VariantLookup {
59
- design: DesignLookup;
60
- intent: IntentLookup;
61
- shape: ShapeLookup;
62
- size: SizeLookup;
63
- }
64
-
65
- type types_Design = Design;
66
- type types_DesignLookup = DesignLookup;
67
- type types_Intent = Intent;
68
- type types_IntentLookup = IntentLookup;
69
- type types_Picks<T extends object, PickedItems extends (keyof T)[], Acc = {}> = Picks<T, PickedItems, Acc>;
70
- type types_Shape = Shape;
71
- type types_ShapeLookup = ShapeLookup;
72
- type types_Size = Size;
73
- type types_SizeLookup = SizeLookup;
74
- type types_VariantLookup = VariantLookup;
75
- declare namespace types {
76
- export type { types_Design as Design, types_DesignLookup as DesignLookup, types_Intent as Intent, types_IntentLookup as IntentLookup, types_Picks as Picks, types_Shape as Shape, types_ShapeLookup as ShapeLookup, types_Size as Size, types_SizeLookup as SizeLookup, types_VariantLookup as VariantLookup };
77
- }
78
-
79
- declare function makeVariants<Variant extends 'design' | 'intent' | 'shape' | 'size', P extends (keyof VariantLookup[Variant])[] = []>(variants: P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>): P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>;
80
-
81
- declare function deepFind(children: ReactNode | ReactNode[], deepFindFn: (child: ReactNode, index?: number, children?: ReactNode[]) => boolean): ReactNode | undefined;
82
-
83
- type EnsureKeys<ExpectedKeys extends (keyof Target)[], Target> = keyof Target extends ExpectedKeys[number] ? unknown : `Missing required keys: ${Exclude<keyof Target, ExpectedKeys[number]> & string}`;
84
- declare const createSplitProps: <Target>() => <Keys extends (keyof Target)[], Props extends Target = Target>(props: Props, keys: Keys & EnsureKeys<Keys, Target>) => [Target, Omit<Props, Extract<(Keys & EnsureKeys<Keys, Target>)[number], string>>];
85
-
86
- /**
87
- * Returns a partial copy of an object omitting the keys specified.
88
- *
89
- * @example
90
- *
91
- * const item = {
92
- * label: 'ten',
93
- * id: 10,
94
- * isValid: true
95
- * }
96
- *
97
- * const updatedItem = omit(item, ['label', 'isValid'])
98
- * // updatedItem === { id: 10 }
99
- *
100
- */
101
- declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly (K | undefined)[]): Omit<T, K>;
102
-
103
- type AnyFunction = (...args: any[]) => any;
104
- interface Options {
105
- /**
106
- * Whether to use queueMicrotask or not
107
- */
108
- sync?: boolean;
109
- }
110
- /**
111
- * Returns a memoized callback that will queueMicrotask the callback if sync is true
112
- */
113
- declare function useEvent<T extends AnyFunction>(callback: T | undefined, opts?: Options): T;
114
-
115
- export { types as VariantTypes, createSplitProps, deepFind, makeVariants, omit, tw, useEvent, constants as variantConstants };
1
+ export { tw } from './tw';
2
+ export { makeVariants } from './variants';
3
+ export * as VariantTypes from './variants/types';
4
+ export * as variantConstants from './variants/constants';
5
+ export { deepFind } from './react-children-utilities/deepFind';
6
+ export { createSplitProps } from './create-split-props';
7
+ export { omit } from './object/omit';
8
+ export { useEvent } from './use-event';
package/dist/index.js CHANGED
@@ -1,165 +1 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- VariantTypes: () => types_exports,
24
- createSplitProps: () => createSplitProps,
25
- deepFind: () => deepFind,
26
- makeVariants: () => makeVariants,
27
- omit: () => omit,
28
- tw: () => tw,
29
- useEvent: () => useEvent,
30
- variantConstants: () => constants_exports
31
- });
32
- module.exports = __toCommonJS(index_exports);
33
-
34
- // src/tw/index.ts
35
- function tw(v) {
36
- return v;
37
- }
38
-
39
- // src/variants/index.ts
40
- function makeVariants(variants) {
41
- return variants;
42
- }
43
-
44
- // src/variants/types.ts
45
- var types_exports = {};
46
-
47
- // src/variants/constants.ts
48
- var constants_exports = {};
49
- __export(constants_exports, {
50
- designs: () => designs,
51
- intents: () => intents,
52
- shapes: () => shapes,
53
- sizes: () => sizes
54
- });
55
- var sizes = ["current", "sm", "md", "lg", "xl"];
56
- var intents = [
57
- "current",
58
- "main",
59
- "support",
60
- "success",
61
- "error",
62
- "info",
63
- "alert",
64
- "danger",
65
- "neutral",
66
- "surface",
67
- "accent",
68
- "basic"
69
- ];
70
- var designs = ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"];
71
- var shapes = ["rounded", "square", "pill"];
72
-
73
- // src/react-children-utilities/deepFind.ts
74
- var import_react3 = require("react");
75
-
76
- // src/react-children-utilities/hasComplexChildren.ts
77
- var import_react2 = require("react");
78
-
79
- // src/react-children-utilities/hasChildren.ts
80
- var import_react = require("react");
81
- function hasChildren(element) {
82
- return (0, import_react.isValidElement)(element) && Boolean(element.props.children);
83
- }
84
-
85
- // src/react-children-utilities/hasComplexChildren.ts
86
- function hasComplexChildren(element) {
87
- return (0, import_react2.isValidElement)(element) && hasChildren(element) && import_react2.Children.toArray(element.props.children).reduce(
88
- (response, child) => response || (0, import_react2.isValidElement)(child),
89
- false
90
- );
91
- }
92
-
93
- // src/react-children-utilities/deepFind.ts
94
- function deepFind(children, deepFindFn) {
95
- let found;
96
- import_react3.Children.toArray(children).find((child, index, findChildren) => {
97
- if (deepFindFn(child, index, findChildren)) {
98
- found = child;
99
- return true;
100
- }
101
- if ((0, import_react3.isValidElement)(child) && hasComplexChildren(child)) {
102
- found = deepFind(child.props.children, deepFindFn);
103
- return typeof found !== "undefined";
104
- }
105
- return false;
106
- });
107
- return found;
108
- }
109
-
110
- // src/create-split-props/index.ts
111
- var createSplitProps = () => (props, keys) => keys.reduce(
112
- (previousValue, currentValue) => {
113
- const [target, source] = previousValue;
114
- const key = currentValue;
115
- if (source[key] !== void 0) {
116
- target[key] = source[key];
117
- }
118
- delete source[key];
119
- return [target, source];
120
- },
121
- [{}, { ...props }]
122
- );
123
-
124
- // src/object/omit.ts
125
- function omit(obj, keys) {
126
- const output = {};
127
- Object.keys(obj).forEach((k) => {
128
- const key = k;
129
- if (!keys.includes(key)) {
130
- output[key] = obj[key];
131
- }
132
- });
133
- return output;
134
- }
135
-
136
- // src/use-event/index.ts
137
- var import_react4 = require("react");
138
- function useEvent(callback, opts = {}) {
139
- const { sync = false } = opts;
140
- const callbackRef = useLatestRef(callback);
141
- return (0, import_react4.useCallback)(
142
- (...args) => {
143
- if (sync) return queueMicrotask(() => callbackRef.current?.(...args));
144
- return callbackRef.current?.(...args);
145
- },
146
- [sync, callbackRef]
147
- );
148
- }
149
- function useLatestRef(value) {
150
- const ref = (0, import_react4.useRef)(value);
151
- ref.current = value;
152
- return ref;
153
- }
154
- // Annotate the CommonJS export names for ESM import in node:
155
- 0 && (module.exports = {
156
- VariantTypes,
157
- createSplitProps,
158
- deepFind,
159
- makeVariants,
160
- omit,
161
- tw,
162
- useEvent,
163
- variantConstants
164
- });
165
- //# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),c=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),l=Object.freeze(Object.defineProperty({__proto__:null,designs:["filled","outlined","tinted","ghost","contrast","dashed"],intents:["current","main","support","success","error","info","alert","danger","neutral","surface","accent","basic"],shapes:["rounded","square","pill"],sizes:["current","sm","md","lg","xl"]},Symbol.toStringTag,{value:"Module"}));function a(n){return s.isValidElement(n)&&function(t){return s.isValidElement(t)&&!!t.props.children}(n)&&s.Children.toArray(n.props.children).reduce((t,r)=>t||s.isValidElement(r),!1)}exports.VariantTypes=c,exports.createSplitProps=()=>(n,t)=>t.reduce((r,o)=>{const[e,i]=r,u=o;return i[u]!==void 0&&(e[u]=i[u]),delete i[u],[e,i]},[{},{...n}]),exports.deepFind=function n(t,r){let o;return s.Children.toArray(t).find((e,i,u)=>r(e,i,u)?(o=e,!0):!(!s.isValidElement(e)||!a(e))&&(o=n(e.props.children,r),o!==void 0)),o},exports.makeVariants=function(n){return n},exports.omit=function(n,t){const r={};return Object.keys(n).forEach(o=>{const e=o;t.includes(e)||(r[e]=n[e])}),r},exports.tw=function(n){return n},exports.useEvent=function(n,t={}){const{sync:r=!1}=t,o=function(e){const i=s.useRef(e);return i.current=e,i}(n);return s.useCallback((...e)=>r?queueMicrotask(()=>o.current?.(...e)):o.current?.(...e),[r,o])},exports.variantConstants=l;
package/dist/index.mjs CHANGED
@@ -1,137 +1,45 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/tw/index.ts
8
- function tw(v) {
9
- return v;
10
- }
11
-
12
- // src/variants/index.ts
13
- function makeVariants(variants) {
14
- return variants;
15
- }
16
-
17
- // src/variants/types.ts
18
- var types_exports = {};
19
-
20
- // src/variants/constants.ts
21
- var constants_exports = {};
22
- __export(constants_exports, {
23
- designs: () => designs,
24
- intents: () => intents,
25
- shapes: () => shapes,
26
- sizes: () => sizes
27
- });
28
- var sizes = ["current", "sm", "md", "lg", "xl"];
29
- var intents = [
30
- "current",
31
- "main",
32
- "support",
33
- "success",
34
- "error",
35
- "info",
36
- "alert",
37
- "danger",
38
- "neutral",
39
- "surface",
40
- "accent",
41
- "basic"
42
- ];
43
- var designs = ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"];
44
- var shapes = ["rounded", "square", "pill"];
45
-
46
- // src/react-children-utilities/deepFind.ts
47
- import { Children as Children2, isValidElement as isValidElement3 } from "react";
48
-
49
- // src/react-children-utilities/hasComplexChildren.ts
50
- import { Children, isValidElement as isValidElement2 } from "react";
51
-
52
- // src/react-children-utilities/hasChildren.ts
53
- import { isValidElement } from "react";
54
- function hasChildren(element) {
55
- return isValidElement(element) && Boolean(element.props.children);
56
- }
57
-
58
- // src/react-children-utilities/hasComplexChildren.ts
59
- function hasComplexChildren(element) {
60
- return isValidElement2(element) && hasChildren(element) && Children.toArray(element.props.children).reduce(
61
- (response, child) => response || isValidElement2(child),
62
- false
63
- );
64
- }
65
-
66
- // src/react-children-utilities/deepFind.ts
67
- function deepFind(children, deepFindFn) {
68
- let found;
69
- Children2.toArray(children).find((child, index, findChildren) => {
70
- if (deepFindFn(child, index, findChildren)) {
71
- found = child;
72
- return true;
73
- }
74
- if (isValidElement3(child) && hasComplexChildren(child)) {
75
- found = deepFind(child.props.children, deepFindFn);
76
- return typeof found !== "undefined";
77
- }
78
- return false;
79
- });
80
- return found;
81
- }
82
-
83
- // src/create-split-props/index.ts
84
- var createSplitProps = () => (props, keys) => keys.reduce(
85
- (previousValue, currentValue) => {
86
- const [target, source] = previousValue;
87
- const key = currentValue;
88
- if (source[key] !== void 0) {
89
- target[key] = source[key];
90
- }
91
- delete source[key];
92
- return [target, source];
93
- },
94
- [{}, { ...props }]
95
- );
96
-
97
- // src/object/omit.ts
98
- function omit(obj, keys) {
99
- const output = {};
100
- Object.keys(obj).forEach((k) => {
101
- const key = k;
102
- if (!keys.includes(key)) {
103
- output[key] = obj[key];
104
- }
105
- });
106
- return output;
107
- }
108
-
109
- // src/use-event/index.ts
110
- import { useCallback, useRef } from "react";
111
- function useEvent(callback, opts = {}) {
112
- const { sync = false } = opts;
113
- const callbackRef = useLatestRef(callback);
114
- return useCallback(
115
- (...args) => {
116
- if (sync) return queueMicrotask(() => callbackRef.current?.(...args));
117
- return callbackRef.current?.(...args);
118
- },
119
- [sync, callbackRef]
120
- );
121
- }
122
- function useLatestRef(value) {
123
- const ref = useRef(value);
124
- ref.current = value;
125
- return ref;
1
+ import { isValidElement as c, Children as u, useCallback as i, useRef as l } from "react";
2
+ function m(e) {
3
+ return e;
4
+ }
5
+ function b(e) {
6
+ return e;
7
+ }
8
+ const y = Object.freeze(Object.defineProperty({ __proto__: null }, Symbol.toStringTag, { value: "Module" })), g = Object.freeze(Object.defineProperty({ __proto__: null, designs: ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"], intents: ["current", "main", "support", "success", "error", "info", "alert", "danger", "neutral", "surface", "accent", "basic"], shapes: ["rounded", "square", "pill"], sizes: ["current", "sm", "md", "lg", "xl"] }, Symbol.toStringTag, { value: "Module" }));
9
+ function d(e) {
10
+ return c(e) && function(r) {
11
+ return c(r) && !!r.props.children;
12
+ }(e) && u.toArray(e.props.children).reduce((r, t) => r || c(t), !1);
13
+ }
14
+ function f(e, r) {
15
+ let t;
16
+ return u.toArray(e).find((o, n, s) => r(o, n, s) ? (t = o, !0) : !(!c(o) || !d(o)) && (t = f(o.props.children, r), t !== void 0)), t;
17
+ }
18
+ const h = () => (e, r) => r.reduce((t, o) => {
19
+ const [n, s] = t, a = o;
20
+ return s[a] !== void 0 && (n[a] = s[a]), delete s[a], [n, s];
21
+ }, [{}, { ...e }]);
22
+ function _(e, r) {
23
+ const t = {};
24
+ return Object.keys(e).forEach((o) => {
25
+ const n = o;
26
+ r.includes(n) || (t[n] = e[n]);
27
+ }), t;
28
+ }
29
+ function v(e, r = {}) {
30
+ const { sync: t = !1 } = r, o = function(n) {
31
+ const s = l(n);
32
+ return s.current = n, s;
33
+ }(e);
34
+ return i((...n) => t ? queueMicrotask(() => o.current?.(...n)) : o.current?.(...n), [t, o]);
126
35
  }
127
36
  export {
128
- types_exports as VariantTypes,
129
- createSplitProps,
130
- deepFind,
131
- makeVariants,
132
- omit,
133
- tw,
134
- useEvent,
135
- constants_exports as variantConstants
37
+ y as VariantTypes,
38
+ h as createSplitProps,
39
+ f as deepFind,
40
+ b as makeVariants,
41
+ _ as omit,
42
+ m as tw,
43
+ v as useEvent,
44
+ g as variantConstants
136
45
  };
137
- //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns a partial copy of an object omitting the keys specified.
3
+ *
4
+ * @example
5
+ *
6
+ * const item = {
7
+ * label: 'ten',
8
+ * id: 10,
9
+ * isValid: true
10
+ * }
11
+ *
12
+ * const updatedItem = omit(item, ['label', 'isValid'])
13
+ * // updatedItem === { id: 10 }
14
+ *
15
+ */
16
+ export declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly (K | undefined)[]): Omit<T, K>;
@@ -0,0 +1,3 @@
1
+ import { ReactNode } from 'react';
2
+ declare function deepFind(children: ReactNode | ReactNode[], deepFindFn: (child: ReactNode, index?: number, children?: ReactNode[]) => boolean): ReactNode | undefined;
3
+ export { deepFind };
@@ -0,0 +1,5 @@
1
+ import { ReactElement, ReactNode } from 'react';
2
+ declare function hasChildren(element: ReactNode): element is ReactElement<{
3
+ children: ReactNode | ReactNode[];
4
+ }>;
5
+ export { hasChildren };
@@ -0,0 +1,5 @@
1
+ import { ReactElement, ReactNode } from 'react';
2
+ declare function hasComplexChildren(element: ReactNode): element is ReactElement<{
3
+ children: ReactNode | ReactNode[];
4
+ }>;
5
+ export { hasComplexChildren };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * A utility function that serves as a workaround for Tailwind CSS IntelliSense issues
3
+ * in large objects or when regex breaks in VSCode.
4
+ *
5
+ * For more context, see: https://github.com/joe-bell/cva/discussions/85#discussioncomment-4568738
6
+ *
7
+ * @example
8
+ *
9
+ * // before
10
+ * const styles: cva(['flex bg-main', 'cursor-pointer'], {
11
+ * variants: {
12
+ * size: {
13
+ * small: "h-sz-24",
14
+ * medium: "h-sz-48"
15
+ * }
16
+ * }
17
+ * })
18
+ *
19
+ * // after
20
+ * const styles = cva(tw(['flex bg-main', 'cursor-pointer']), {
21
+ * variants: {
22
+ * size: {
23
+ * small: tw("h-sz-24"),
24
+ * medium: tw("h-sz-48"),
25
+ * }
26
+ * }
27
+ * })
28
+ */
29
+ export declare function tw<T>(v: T): T;
@@ -0,0 +1,12 @@
1
+ type AnyFunction = (...args: any[]) => any;
2
+ interface Options {
3
+ /**
4
+ * Whether to use queueMicrotask or not
5
+ */
6
+ sync?: boolean;
7
+ }
8
+ /**
9
+ * Returns a memoized callback that will queueMicrotask the callback if sync is true
10
+ */
11
+ declare function useEvent<T extends AnyFunction>(callback: T | undefined, opts?: Options): T;
12
+ export { useEvent };
@@ -0,0 +1,5 @@
1
+ declare const sizes: readonly ["current", "sm", "md", "lg", "xl"];
2
+ declare const intents: readonly ["current", "main", "support", "success", "error", "info", "alert", "danger", "neutral", "surface", "accent", "basic"];
3
+ declare const designs: readonly ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"];
4
+ declare const shapes: readonly ["rounded", "square", "pill"];
5
+ export { sizes, intents, designs, shapes };
@@ -0,0 +1,3 @@
1
+ import { Picks, VariantLookup } from './types';
2
+ declare function makeVariants<Variant extends 'design' | 'intent' | 'shape' | 'size', P extends (keyof VariantLookup[Variant])[] = []>(variants: P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>): P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>;
3
+ export { makeVariants };
@@ -0,0 +1,20 @@
1
+ import { designs, intents, shapes, sizes } from './constants';
2
+ type Picks<T extends object, PickedItems extends (keyof T)[], Acc = {}> = PickedItems extends [
3
+ infer Head,
4
+ ...infer Rest
5
+ ] ? Rest extends (keyof T)[] ? Head extends keyof T ? Picks<T, Rest, Acc & Pick<T, Head>> : Acc : Acc : Acc;
6
+ type Size = (typeof sizes)[number];
7
+ type SizeLookup = Record<Size, string[]>;
8
+ type Intent = (typeof intents)[number];
9
+ type IntentLookup = Record<Intent, string[]>;
10
+ type Design = (typeof designs)[number];
11
+ type DesignLookup = Record<Design, string[]>;
12
+ type Shape = (typeof shapes)[number];
13
+ type ShapeLookup = Record<Shape, string[]>;
14
+ interface VariantLookup {
15
+ design: DesignLookup;
16
+ intent: IntentLookup;
17
+ shape: ShapeLookup;
18
+ size: SizeLookup;
19
+ }
20
+ export type { Size, SizeLookup, Intent, IntentLookup, Design, DesignLookup, Shape, ShapeLookup, Picks, VariantLookup, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/internal-utils",
3
- "version": "10.4.1",
3
+ "version": "10.4.3",
4
4
  "description": "package for sharing reusable code and resources across the codebase",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,18 +10,11 @@
10
10
  "util",
11
11
  "utility"
12
12
  ],
13
- "exports": {
14
- ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.mjs",
17
- "require": "./dist/index.js"
18
- }
19
- },
20
13
  "main": "./dist/index.js",
21
14
  "module": "./dist/index.mjs",
22
15
  "types": "./dist/index.d.ts",
23
16
  "scripts": {
24
- "build": "tsup"
17
+ "build": "vite build"
25
18
  },
26
19
  "peerDependencies": {
27
20
  "react": "^19.0",
@@ -41,5 +34,5 @@
41
34
  },
42
35
  "homepage": "https://sparkui.vercel.app",
43
36
  "license": "MIT",
44
- "gitHead": "0ac40eb532fc9d2311359f3bad8eff3629d97ba5"
37
+ "gitHead": "b656379a8dcd619e0be1b4343b20a29160ef3592"
45
38
  }
package/tsconfig.json CHANGED
@@ -1,7 +1,4 @@
1
1
  {
2
2
  "extends": "../../../tsconfig.json",
3
- "include": ["src/**/*", "../../global.d.ts"],
4
- "compilerOptions": {
5
- "incremental": false
6
- }
3
+ "include": ["src/**/*", "../../global.d.ts"]
7
4
  }
package/vite.config.ts ADDED
@@ -0,0 +1,29 @@
1
+ import terser from '@rollup/plugin-terser'
2
+ import dts from 'vite-plugin-dts'
3
+
4
+ const pkg = require('./package.json')
5
+ const peerDeps = Object.keys(pkg.peerDependencies || {})
6
+
7
+ export default async () => {
8
+ const browserslistToEsbuild = await import('browserslist-to-esbuild')
9
+
10
+ return {
11
+ build: {
12
+ target: browserslistToEsbuild.default(),
13
+ lib: {
14
+ entry: 'src/index.ts',
15
+ formats: ['es', 'cjs'],
16
+ fileName: 'index',
17
+ },
18
+ rollupOptions: {
19
+ external: ['node:path', 'node:fs', ...peerDeps],
20
+ plugins: [terser()],
21
+ },
22
+ },
23
+ plugins: [
24
+ dts({
25
+ entryRoot: './src',
26
+ }),
27
+ ],
28
+ }
29
+ }
package/dist/index.d.mts DELETED
@@ -1,115 +0,0 @@
1
- import { ReactNode } from 'react';
2
-
3
- /**
4
- * A utility function that serves as a workaround for Tailwind CSS IntelliSense issues
5
- * in large objects or when regex breaks in VSCode.
6
- *
7
- * For more context, see: https://github.com/joe-bell/cva/discussions/85#discussioncomment-4568738
8
- *
9
- * @example
10
- *
11
- * // before
12
- * const styles: cva(['flex bg-main', 'cursor-pointer'], {
13
- * variants: {
14
- * size: {
15
- * small: "h-sz-24",
16
- * medium: "h-sz-48"
17
- * }
18
- * }
19
- * })
20
- *
21
- * // after
22
- * const styles = cva(tw(['flex bg-main', 'cursor-pointer']), {
23
- * variants: {
24
- * size: {
25
- * small: tw("h-sz-24"),
26
- * medium: tw("h-sz-48"),
27
- * }
28
- * }
29
- * })
30
- */
31
- declare function tw<T>(v: T): T;
32
-
33
- declare const sizes: readonly ["current", "sm", "md", "lg", "xl"];
34
- declare const intents: readonly ["current", "main", "support", "success", "error", "info", "alert", "danger", "neutral", "surface", "accent", "basic"];
35
- declare const designs: readonly ["filled", "outlined", "tinted", "ghost", "contrast", "dashed"];
36
- declare const shapes: readonly ["rounded", "square", "pill"];
37
-
38
- declare const constants_designs: typeof designs;
39
- declare const constants_intents: typeof intents;
40
- declare const constants_shapes: typeof shapes;
41
- declare const constants_sizes: typeof sizes;
42
- declare namespace constants {
43
- export { constants_designs as designs, constants_intents as intents, constants_shapes as shapes, constants_sizes as sizes };
44
- }
45
-
46
- type Picks<T extends object, PickedItems extends (keyof T)[], Acc = {}> = PickedItems extends [
47
- infer Head,
48
- ...infer Rest
49
- ] ? Rest extends (keyof T)[] ? Head extends keyof T ? Picks<T, Rest, Acc & Pick<T, Head>> : Acc : Acc : Acc;
50
- type Size = (typeof sizes)[number];
51
- type SizeLookup = Record<Size, string[]>;
52
- type Intent = (typeof intents)[number];
53
- type IntentLookup = Record<Intent, string[]>;
54
- type Design = (typeof designs)[number];
55
- type DesignLookup = Record<Design, string[]>;
56
- type Shape = (typeof shapes)[number];
57
- type ShapeLookup = Record<Shape, string[]>;
58
- interface VariantLookup {
59
- design: DesignLookup;
60
- intent: IntentLookup;
61
- shape: ShapeLookup;
62
- size: SizeLookup;
63
- }
64
-
65
- type types_Design = Design;
66
- type types_DesignLookup = DesignLookup;
67
- type types_Intent = Intent;
68
- type types_IntentLookup = IntentLookup;
69
- type types_Picks<T extends object, PickedItems extends (keyof T)[], Acc = {}> = Picks<T, PickedItems, Acc>;
70
- type types_Shape = Shape;
71
- type types_ShapeLookup = ShapeLookup;
72
- type types_Size = Size;
73
- type types_SizeLookup = SizeLookup;
74
- type types_VariantLookup = VariantLookup;
75
- declare namespace types {
76
- export type { types_Design as Design, types_DesignLookup as DesignLookup, types_Intent as Intent, types_IntentLookup as IntentLookup, types_Picks as Picks, types_Shape as Shape, types_ShapeLookup as ShapeLookup, types_Size as Size, types_SizeLookup as SizeLookup, types_VariantLookup as VariantLookup };
77
- }
78
-
79
- declare function makeVariants<Variant extends 'design' | 'intent' | 'shape' | 'size', P extends (keyof VariantLookup[Variant])[] = []>(variants: P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>): P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>;
80
-
81
- declare function deepFind(children: ReactNode | ReactNode[], deepFindFn: (child: ReactNode, index?: number, children?: ReactNode[]) => boolean): ReactNode | undefined;
82
-
83
- type EnsureKeys<ExpectedKeys extends (keyof Target)[], Target> = keyof Target extends ExpectedKeys[number] ? unknown : `Missing required keys: ${Exclude<keyof Target, ExpectedKeys[number]> & string}`;
84
- declare const createSplitProps: <Target>() => <Keys extends (keyof Target)[], Props extends Target = Target>(props: Props, keys: Keys & EnsureKeys<Keys, Target>) => [Target, Omit<Props, Extract<(Keys & EnsureKeys<Keys, Target>)[number], string>>];
85
-
86
- /**
87
- * Returns a partial copy of an object omitting the keys specified.
88
- *
89
- * @example
90
- *
91
- * const item = {
92
- * label: 'ten',
93
- * id: 10,
94
- * isValid: true
95
- * }
96
- *
97
- * const updatedItem = omit(item, ['label', 'isValid'])
98
- * // updatedItem === { id: 10 }
99
- *
100
- */
101
- declare function omit<T extends object, K extends keyof T>(obj: T, keys: readonly (K | undefined)[]): Omit<T, K>;
102
-
103
- type AnyFunction = (...args: any[]) => any;
104
- interface Options {
105
- /**
106
- * Whether to use queueMicrotask or not
107
- */
108
- sync?: boolean;
109
- }
110
- /**
111
- * Returns a memoized callback that will queueMicrotask the callback if sync is true
112
- */
113
- declare function useEvent<T extends AnyFunction>(callback: T | undefined, opts?: Options): T;
114
-
115
- export { types as VariantTypes, createSplitProps, deepFind, makeVariants, omit, tw, useEvent, constants as variantConstants };
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/tw/index.ts","../src/variants/index.ts","../src/variants/types.ts","../src/variants/constants.ts","../src/react-children-utilities/deepFind.ts","../src/react-children-utilities/hasComplexChildren.ts","../src/react-children-utilities/hasChildren.ts","../src/create-split-props/index.ts","../src/object/omit.ts","../src/use-event/index.ts"],"sourcesContent":["export { tw } from './tw'\nexport { makeVariants } from './variants'\nexport * as VariantTypes from './variants/types'\nexport * as variantConstants from './variants/constants'\nexport { deepFind } from './react-children-utilities/deepFind'\nexport { createSplitProps } from './create-split-props'\nexport { omit } from './object/omit'\nexport { useEvent } from './use-event'\n","/**\n * A utility function that serves as a workaround for Tailwind CSS IntelliSense issues\n * in large objects or when regex breaks in VSCode.\n *\n * For more context, see: https://github.com/joe-bell/cva/discussions/85#discussioncomment-4568738\n *\n * @example\n *\n * // before\n * const styles: cva(['flex bg-main', 'cursor-pointer'], {\n * variants: {\n * size: {\n * small: \"h-sz-24\",\n * medium: \"h-sz-48\"\n * }\n * }\n * })\n *\n * // after\n * const styles = cva(tw(['flex bg-main', 'cursor-pointer']), {\n * variants: {\n * size: {\n * small: tw(\"h-sz-24\"),\n * medium: tw(\"h-sz-48\"),\n * }\n * }\n * })\n */\nexport function tw<T>(v: T) {\n return v\n}\n","import { Picks, VariantLookup } from './types'\n\nfunction makeVariants<\n Variant extends 'design' | 'intent' | 'shape' | 'size',\n /* eslint-disable-next-line space-before-function-paren */\n P extends (keyof VariantLookup[Variant])[] = [],\n>(\n variants: P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>\n): P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P> {\n return variants\n}\n\nexport { makeVariants }\n","import { designs, intents, shapes, sizes } from './constants'\n\ntype Picks<T extends object, PickedItems extends (keyof T)[], Acc = {}> = PickedItems extends [\n infer Head,\n ...infer Rest,\n]\n ? Rest extends (keyof T)[]\n ? Head extends keyof T\n ? Picks<T, Rest, Acc & Pick<T, Head>>\n : Acc\n : Acc\n : Acc\n\ntype Size = (typeof sizes)[number]\ntype SizeLookup = Record<Size, string[]>\n\ntype Intent = (typeof intents)[number]\ntype IntentLookup = Record<Intent, string[]>\n\ntype Design = (typeof designs)[number]\ntype DesignLookup = Record<Design, string[]>\n\ntype Shape = (typeof shapes)[number]\ntype ShapeLookup = Record<Shape, string[]>\n\ninterface VariantLookup {\n design: DesignLookup\n intent: IntentLookup\n shape: ShapeLookup\n size: SizeLookup\n}\n\nexport type {\n Size,\n SizeLookup,\n Intent,\n IntentLookup,\n Design,\n DesignLookup,\n Shape,\n ShapeLookup,\n Picks,\n VariantLookup,\n}\n","const sizes = ['current', 'sm', 'md', 'lg', 'xl'] as const\n\nconst intents = [\n 'current',\n 'main',\n 'support',\n 'success',\n 'error',\n 'info',\n 'alert',\n 'danger',\n 'neutral',\n 'surface',\n 'accent',\n 'basic',\n] as const\n\nconst designs = ['filled', 'outlined', 'tinted', 'ghost', 'contrast', 'dashed'] as const\n\nconst shapes = ['rounded', 'square', 'pill'] as const\n\nexport { sizes, intents, designs, shapes }\n","import type { ReactNode } from 'react'\nimport { Children, isValidElement } from 'react'\n\nimport { hasComplexChildren } from './hasComplexChildren'\n\n// from https://github.com/fernandopasik/react-children-utilities\nfunction deepFind(\n children: ReactNode | ReactNode[],\n deepFindFn: (child: ReactNode, index?: number, children?: ReactNode[]) => boolean\n): ReactNode | undefined {\n // eslint-disable-next-line @typescript-eslint/init-declarations\n let found\n\n Children.toArray(children).find((child: ReactNode, index: number, findChildren: ReactNode[]) => {\n if (deepFindFn(child, index, findChildren)) {\n found = child\n\n return true\n }\n\n if (isValidElement(child) && hasComplexChildren(child)) {\n // Find inside the child that has children\n found = deepFind(child.props.children, deepFindFn)\n\n return typeof found !== 'undefined'\n }\n\n return false\n })\n\n return found\n}\n\nexport { deepFind }\n","import type { ReactElement, ReactNode } from 'react'\nimport { Children, isValidElement } from 'react'\n\nimport { hasChildren } from './hasChildren'\n\nfunction hasComplexChildren(\n element: ReactNode\n): element is ReactElement<{ children: ReactNode | ReactNode[] }> {\n return (\n isValidElement(element) &&\n hasChildren(element) &&\n Children.toArray(element.props.children).reduce(\n (response: boolean, child: ReactNode): boolean => response || isValidElement(child),\n false\n )\n )\n}\n\nexport { hasComplexChildren }\n","import type { ReactElement, ReactNode } from 'react'\nimport { isValidElement } from 'react'\n\nfunction hasChildren(\n element: ReactNode\n): element is ReactElement<{ children: ReactNode | ReactNode[] }> {\n return isValidElement<{ children?: ReactNode[] }>(element) && Boolean(element.props.children)\n}\n\nexport { hasChildren }\n","type EnsureKeys<\n ExpectedKeys extends (keyof Target)[],\n Target,\n> = keyof Target extends ExpectedKeys[number]\n ? unknown\n : `Missing required keys: ${Exclude<keyof Target, ExpectedKeys[number]> & string}`\n\nexport const createSplitProps =\n <Target>() =>\n <Keys extends (keyof Target)[], Props extends Target = Target>(\n props: Props,\n keys: Keys & EnsureKeys<Keys, Target>\n ) =>\n (keys as string[]).reduce<[Target, Omit<Props, Extract<(typeof keys)[number], string>>]>(\n (previousValue, currentValue) => {\n const [target, source] = previousValue\n const key = currentValue as keyof Target & keyof typeof source\n if (source[key] !== undefined) {\n target[key] = source[key]\n }\n delete source[key]\n\n return [target, source]\n },\n [{} as Target, { ...props }]\n )\n","/**\n * Returns a partial copy of an object omitting the keys specified.\n *\n * @example\n *\n * const item = {\n * label: 'ten',\n * id: 10,\n * isValid: true\n * }\n *\n * const updatedItem = omit(item, ['label', 'isValid'])\n * // updatedItem === { id: 10 }\n *\n */\nexport function omit<T extends object, K extends keyof T>(\n obj: T,\n keys: readonly (K | undefined)[]\n): Omit<T, K> {\n const output = {} as {\n [K in keyof typeof obj]: (typeof obj)[K]\n }\n Object.keys(obj).forEach(k => {\n const key = k as K\n if (!keys.includes(key)) {\n output[key] = obj[key]\n }\n })\n\n return output\n}\n","// 👀 see https://github.com/chakra-ui/ark/blob/main/packages/react/src/utils/use-event.ts\nimport { useCallback, useRef } from 'react'\n\ntype AnyFunction = (...args: any[]) => any\n\ninterface Options {\n /**\n * Whether to use queueMicrotask or not\n */\n sync?: boolean\n}\n\n/**\n * Returns a memoized callback that will queueMicrotask the callback if sync is true\n */\nfunction useEvent<T extends AnyFunction>(callback: T | undefined, opts: Options = {}): T {\n const { sync = false } = opts\n\n const callbackRef = useLatestRef(callback)\n\n return useCallback(\n (...args: any[]) => {\n if (sync) return queueMicrotask(() => callbackRef.current?.(...args))\n\n return callbackRef.current?.(...args)\n },\n [sync, callbackRef]\n ) as T\n}\n\nfunction useLatestRef<T>(value: T) {\n const ref = useRef(value)\n ref.current = value\n\n return ref\n}\n\nexport { useEvent }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BO,SAAS,GAAM,GAAM;AAC1B,SAAO;AACT;;;AC5BA,SAAS,aAKP,UAC0E;AAC1E,SAAO;AACT;;;ACVA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,QAAQ,CAAC,WAAW,MAAM,MAAM,MAAM,IAAI;AAEhD,IAAM,UAAU;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,UAAU,CAAC,UAAU,YAAY,UAAU,SAAS,YAAY,QAAQ;AAE9E,IAAM,SAAS,CAAC,WAAW,UAAU,MAAM;;;AClB3C,IAAAA,gBAAyC;;;ACAzC,IAAAC,gBAAyC;;;ACAzC,mBAA+B;AAE/B,SAAS,YACP,SACgE;AAChE,aAAO,6BAA2C,OAAO,KAAK,QAAQ,QAAQ,MAAM,QAAQ;AAC9F;;;ADFA,SAAS,mBACP,SACgE;AAChE,aACE,8BAAe,OAAO,KACtB,YAAY,OAAO,KACnB,uBAAS,QAAQ,QAAQ,MAAM,QAAQ,EAAE;AAAA,IACvC,CAAC,UAAmB,UAA8B,gBAAY,8BAAe,KAAK;AAAA,IAClF;AAAA,EACF;AAEJ;;;ADVA,SAAS,SACP,UACA,YACuB;AAEvB,MAAI;AAEJ,yBAAS,QAAQ,QAAQ,EAAE,KAAK,CAAC,OAAkB,OAAe,iBAA8B;AAC9F,QAAI,WAAW,OAAO,OAAO,YAAY,GAAG;AAC1C,cAAQ;AAER,aAAO;AAAA,IACT;AAEA,YAAI,8BAAe,KAAK,KAAK,mBAAmB,KAAK,GAAG;AAEtD,cAAQ,SAAS,MAAM,MAAM,UAAU,UAAU;AAEjD,aAAO,OAAO,UAAU;AAAA,IAC1B;AAEA,WAAO;AAAA,EACT,CAAC;AAED,SAAO;AACT;;;AGxBO,IAAM,mBACX,MACA,CACE,OACA,SAEC,KAAkB;AAAA,EACjB,CAAC,eAAe,iBAAiB;AAC/B,UAAM,CAAC,QAAQ,MAAM,IAAI;AACzB,UAAM,MAAM;AACZ,QAAI,OAAO,GAAG,MAAM,QAAW;AAC7B,aAAO,GAAG,IAAI,OAAO,GAAG;AAAA,IAC1B;AACA,WAAO,OAAO,GAAG;AAEjB,WAAO,CAAC,QAAQ,MAAM;AAAA,EACxB;AAAA,EACA,CAAC,CAAC,GAAa,EAAE,GAAG,MAAM,CAAC;AAC7B;;;ACVG,SAAS,KACd,KACA,MACY;AACZ,QAAM,SAAS,CAAC;AAGhB,SAAO,KAAK,GAAG,EAAE,QAAQ,OAAK;AAC5B,UAAM,MAAM;AACZ,QAAI,CAAC,KAAK,SAAS,GAAG,GAAG;AACvB,aAAO,GAAG,IAAI,IAAI,GAAG;AAAA,IACvB;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AC7BA,IAAAC,gBAAoC;AAcpC,SAAS,SAAgC,UAAyB,OAAgB,CAAC,GAAM;AACvF,QAAM,EAAE,OAAO,MAAM,IAAI;AAEzB,QAAM,cAAc,aAAa,QAAQ;AAEzC,aAAO;AAAA,IACL,IAAI,SAAgB;AAClB,UAAI,KAAM,QAAO,eAAe,MAAM,YAAY,UAAU,GAAG,IAAI,CAAC;AAEpE,aAAO,YAAY,UAAU,GAAG,IAAI;AAAA,IACtC;AAAA,IACA,CAAC,MAAM,WAAW;AAAA,EACpB;AACF;AAEA,SAAS,aAAgB,OAAU;AACjC,QAAM,UAAM,sBAAO,KAAK;AACxB,MAAI,UAAU;AAEd,SAAO;AACT;","names":["import_react","import_react","import_react"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tw/index.ts","../src/variants/index.ts","../src/variants/types.ts","../src/variants/constants.ts","../src/react-children-utilities/deepFind.ts","../src/react-children-utilities/hasComplexChildren.ts","../src/react-children-utilities/hasChildren.ts","../src/create-split-props/index.ts","../src/object/omit.ts","../src/use-event/index.ts"],"sourcesContent":["/**\n * A utility function that serves as a workaround for Tailwind CSS IntelliSense issues\n * in large objects or when regex breaks in VSCode.\n *\n * For more context, see: https://github.com/joe-bell/cva/discussions/85#discussioncomment-4568738\n *\n * @example\n *\n * // before\n * const styles: cva(['flex bg-main', 'cursor-pointer'], {\n * variants: {\n * size: {\n * small: \"h-sz-24\",\n * medium: \"h-sz-48\"\n * }\n * }\n * })\n *\n * // after\n * const styles = cva(tw(['flex bg-main', 'cursor-pointer']), {\n * variants: {\n * size: {\n * small: tw(\"h-sz-24\"),\n * medium: tw(\"h-sz-48\"),\n * }\n * }\n * })\n */\nexport function tw<T>(v: T) {\n return v\n}\n","import { Picks, VariantLookup } from './types'\n\nfunction makeVariants<\n Variant extends 'design' | 'intent' | 'shape' | 'size',\n /* eslint-disable-next-line space-before-function-paren */\n P extends (keyof VariantLookup[Variant])[] = [],\n>(\n variants: P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P>\n): P extends [] ? VariantLookup[Variant] : Picks<VariantLookup[Variant], P> {\n return variants\n}\n\nexport { makeVariants }\n","import { designs, intents, shapes, sizes } from './constants'\n\ntype Picks<T extends object, PickedItems extends (keyof T)[], Acc = {}> = PickedItems extends [\n infer Head,\n ...infer Rest,\n]\n ? Rest extends (keyof T)[]\n ? Head extends keyof T\n ? Picks<T, Rest, Acc & Pick<T, Head>>\n : Acc\n : Acc\n : Acc\n\ntype Size = (typeof sizes)[number]\ntype SizeLookup = Record<Size, string[]>\n\ntype Intent = (typeof intents)[number]\ntype IntentLookup = Record<Intent, string[]>\n\ntype Design = (typeof designs)[number]\ntype DesignLookup = Record<Design, string[]>\n\ntype Shape = (typeof shapes)[number]\ntype ShapeLookup = Record<Shape, string[]>\n\ninterface VariantLookup {\n design: DesignLookup\n intent: IntentLookup\n shape: ShapeLookup\n size: SizeLookup\n}\n\nexport type {\n Size,\n SizeLookup,\n Intent,\n IntentLookup,\n Design,\n DesignLookup,\n Shape,\n ShapeLookup,\n Picks,\n VariantLookup,\n}\n","const sizes = ['current', 'sm', 'md', 'lg', 'xl'] as const\n\nconst intents = [\n 'current',\n 'main',\n 'support',\n 'success',\n 'error',\n 'info',\n 'alert',\n 'danger',\n 'neutral',\n 'surface',\n 'accent',\n 'basic',\n] as const\n\nconst designs = ['filled', 'outlined', 'tinted', 'ghost', 'contrast', 'dashed'] as const\n\nconst shapes = ['rounded', 'square', 'pill'] as const\n\nexport { sizes, intents, designs, shapes }\n","import type { ReactNode } from 'react'\nimport { Children, isValidElement } from 'react'\n\nimport { hasComplexChildren } from './hasComplexChildren'\n\n// from https://github.com/fernandopasik/react-children-utilities\nfunction deepFind(\n children: ReactNode | ReactNode[],\n deepFindFn: (child: ReactNode, index?: number, children?: ReactNode[]) => boolean\n): ReactNode | undefined {\n // eslint-disable-next-line @typescript-eslint/init-declarations\n let found\n\n Children.toArray(children).find((child: ReactNode, index: number, findChildren: ReactNode[]) => {\n if (deepFindFn(child, index, findChildren)) {\n found = child\n\n return true\n }\n\n if (isValidElement(child) && hasComplexChildren(child)) {\n // Find inside the child that has children\n found = deepFind(child.props.children, deepFindFn)\n\n return typeof found !== 'undefined'\n }\n\n return false\n })\n\n return found\n}\n\nexport { deepFind }\n","import type { ReactElement, ReactNode } from 'react'\nimport { Children, isValidElement } from 'react'\n\nimport { hasChildren } from './hasChildren'\n\nfunction hasComplexChildren(\n element: ReactNode\n): element is ReactElement<{ children: ReactNode | ReactNode[] }> {\n return (\n isValidElement(element) &&\n hasChildren(element) &&\n Children.toArray(element.props.children).reduce(\n (response: boolean, child: ReactNode): boolean => response || isValidElement(child),\n false\n )\n )\n}\n\nexport { hasComplexChildren }\n","import type { ReactElement, ReactNode } from 'react'\nimport { isValidElement } from 'react'\n\nfunction hasChildren(\n element: ReactNode\n): element is ReactElement<{ children: ReactNode | ReactNode[] }> {\n return isValidElement<{ children?: ReactNode[] }>(element) && Boolean(element.props.children)\n}\n\nexport { hasChildren }\n","type EnsureKeys<\n ExpectedKeys extends (keyof Target)[],\n Target,\n> = keyof Target extends ExpectedKeys[number]\n ? unknown\n : `Missing required keys: ${Exclude<keyof Target, ExpectedKeys[number]> & string}`\n\nexport const createSplitProps =\n <Target>() =>\n <Keys extends (keyof Target)[], Props extends Target = Target>(\n props: Props,\n keys: Keys & EnsureKeys<Keys, Target>\n ) =>\n (keys as string[]).reduce<[Target, Omit<Props, Extract<(typeof keys)[number], string>>]>(\n (previousValue, currentValue) => {\n const [target, source] = previousValue\n const key = currentValue as keyof Target & keyof typeof source\n if (source[key] !== undefined) {\n target[key] = source[key]\n }\n delete source[key]\n\n return [target, source]\n },\n [{} as Target, { ...props }]\n )\n","/**\n * Returns a partial copy of an object omitting the keys specified.\n *\n * @example\n *\n * const item = {\n * label: 'ten',\n * id: 10,\n * isValid: true\n * }\n *\n * const updatedItem = omit(item, ['label', 'isValid'])\n * // updatedItem === { id: 10 }\n *\n */\nexport function omit<T extends object, K extends keyof T>(\n obj: T,\n keys: readonly (K | undefined)[]\n): Omit<T, K> {\n const output = {} as {\n [K in keyof typeof obj]: (typeof obj)[K]\n }\n Object.keys(obj).forEach(k => {\n const key = k as K\n if (!keys.includes(key)) {\n output[key] = obj[key]\n }\n })\n\n return output\n}\n","// 👀 see https://github.com/chakra-ui/ark/blob/main/packages/react/src/utils/use-event.ts\nimport { useCallback, useRef } from 'react'\n\ntype AnyFunction = (...args: any[]) => any\n\ninterface Options {\n /**\n * Whether to use queueMicrotask or not\n */\n sync?: boolean\n}\n\n/**\n * Returns a memoized callback that will queueMicrotask the callback if sync is true\n */\nfunction useEvent<T extends AnyFunction>(callback: T | undefined, opts: Options = {}): T {\n const { sync = false } = opts\n\n const callbackRef = useLatestRef(callback)\n\n return useCallback(\n (...args: any[]) => {\n if (sync) return queueMicrotask(() => callbackRef.current?.(...args))\n\n return callbackRef.current?.(...args)\n },\n [sync, callbackRef]\n ) as T\n}\n\nfunction useLatestRef<T>(value: T) {\n const ref = useRef(value)\n ref.current = value\n\n return ref\n}\n\nexport { useEvent }\n"],"mappings":";;;;;;;AA4BO,SAAS,GAAM,GAAM;AAC1B,SAAO;AACT;;;AC5BA,SAAS,aAKP,UAC0E;AAC1E,SAAO;AACT;;;ACVA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAM,QAAQ,CAAC,WAAW,MAAM,MAAM,MAAM,IAAI;AAEhD,IAAM,UAAU;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,UAAU,CAAC,UAAU,YAAY,UAAU,SAAS,YAAY,QAAQ;AAE9E,IAAM,SAAS,CAAC,WAAW,UAAU,MAAM;;;AClB3C,SAAS,YAAAA,WAAU,kBAAAC,uBAAsB;;;ACAzC,SAAS,UAAU,kBAAAC,uBAAsB;;;ACAzC,SAAS,sBAAsB;AAE/B,SAAS,YACP,SACgE;AAChE,SAAO,eAA2C,OAAO,KAAK,QAAQ,QAAQ,MAAM,QAAQ;AAC9F;;;ADFA,SAAS,mBACP,SACgE;AAChE,SACEC,gBAAe,OAAO,KACtB,YAAY,OAAO,KACnB,SAAS,QAAQ,QAAQ,MAAM,QAAQ,EAAE;AAAA,IACvC,CAAC,UAAmB,UAA8B,YAAYA,gBAAe,KAAK;AAAA,IAClF;AAAA,EACF;AAEJ;;;ADVA,SAAS,SACP,UACA,YACuB;AAEvB,MAAI;AAEJ,EAAAC,UAAS,QAAQ,QAAQ,EAAE,KAAK,CAAC,OAAkB,OAAe,iBAA8B;AAC9F,QAAI,WAAW,OAAO,OAAO,YAAY,GAAG;AAC1C,cAAQ;AAER,aAAO;AAAA,IACT;AAEA,QAAIC,gBAAe,KAAK,KAAK,mBAAmB,KAAK,GAAG;AAEtD,cAAQ,SAAS,MAAM,MAAM,UAAU,UAAU;AAEjD,aAAO,OAAO,UAAU;AAAA,IAC1B;AAEA,WAAO;AAAA,EACT,CAAC;AAED,SAAO;AACT;;;AGxBO,IAAM,mBACX,MACA,CACE,OACA,SAEC,KAAkB;AAAA,EACjB,CAAC,eAAe,iBAAiB;AAC/B,UAAM,CAAC,QAAQ,MAAM,IAAI;AACzB,UAAM,MAAM;AACZ,QAAI,OAAO,GAAG,MAAM,QAAW;AAC7B,aAAO,GAAG,IAAI,OAAO,GAAG;AAAA,IAC1B;AACA,WAAO,OAAO,GAAG;AAEjB,WAAO,CAAC,QAAQ,MAAM;AAAA,EACxB;AAAA,EACA,CAAC,CAAC,GAAa,EAAE,GAAG,MAAM,CAAC;AAC7B;;;ACVG,SAAS,KACd,KACA,MACY;AACZ,QAAM,SAAS,CAAC;AAGhB,SAAO,KAAK,GAAG,EAAE,QAAQ,OAAK;AAC5B,UAAM,MAAM;AACZ,QAAI,CAAC,KAAK,SAAS,GAAG,GAAG;AACvB,aAAO,GAAG,IAAI,IAAI,GAAG;AAAA,IACvB;AAAA,EACF,CAAC;AAED,SAAO;AACT;;;AC7BA,SAAS,aAAa,cAAc;AAcpC,SAAS,SAAgC,UAAyB,OAAgB,CAAC,GAAM;AACvF,QAAM,EAAE,OAAO,MAAM,IAAI;AAEzB,QAAM,cAAc,aAAa,QAAQ;AAEzC,SAAO;AAAA,IACL,IAAI,SAAgB;AAClB,UAAI,KAAM,QAAO,eAAe,MAAM,YAAY,UAAU,GAAG,IAAI,CAAC;AAEpE,aAAO,YAAY,UAAU,GAAG,IAAI;AAAA,IACtC;AAAA,IACA,CAAC,MAAM,WAAW;AAAA,EACpB;AACF;AAEA,SAAS,aAAgB,OAAU;AACjC,QAAM,MAAM,OAAO,KAAK;AACxB,MAAI,UAAU;AAEd,SAAO;AACT;","names":["Children","isValidElement","isValidElement","isValidElement","Children","isValidElement"]}
package/tsup.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig(() => {
4
- return {
5
- entryPoints: ['src/index.ts'],
6
- format: ['cjs', 'esm'],
7
- dts: true,
8
- sourcemap: true,
9
- external: ['node:path', 'node:fs', 'react', 'react-dom'],
10
- clean: true,
11
- }
12
- })