@zag-js/types 0.36.3 → 0.37.0

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/dist/index.d.mts CHANGED
@@ -1158,6 +1158,9 @@ type NormalizeProps<T extends PropTypes> = {
1158
1158
  };
1159
1159
  declare function createNormalizer<T extends PropTypes>(fn: (props: Dict) => Dict): NormalizeProps<T>;
1160
1160
 
1161
+ type StrictKeys<K extends (keyof T)[], T> = K extends (keyof T)[] ? [keyof T] extends [K[number]] ? unknown : `Missing required keys: ${Exclude<keyof T, K[number]>}` : never;
1162
+ declare const createProps: <T extends Record<never, never>>() => <K extends (keyof T)[]>(props: K & StrictKeys<K, T>) => (keyof T)[];
1163
+
1161
1164
  type RequiredBy<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>;
1162
1165
  type Direction = "ltr" | "rtl";
1163
1166
  type Orientation = "horizontal" | "vertical";
@@ -1193,22 +1196,6 @@ interface CommonProperties {
1193
1196
  */
1194
1197
  getRootNode?: () => ShadowRoot | Document | Node;
1195
1198
  }
1196
- interface RootProperties {
1197
- /**
1198
- * The owner document of the machine.
1199
- */
1200
- doc?: Document;
1201
- /**
1202
- * The root node of the machine. Useful for shadow DOM.
1203
- */
1204
- rootNode?: ShadowRoot;
1205
- /**
1206
- * The related target when the element is blurred.
1207
- * Used as a polyfill for `e.relatedTarget`
1208
- */
1209
- pointerdownNode?: HTMLElement | null;
1210
- }
1211
- type Context<T> = T & RootProperties;
1212
1199
  type Style = JSX.CSSProperties;
1213
1200
 
1214
- export { type CommonProperties, type Context, type Direction, type DirectionProperty, JSX, type LocaleProperties, type MaybeElement, type NormalizeProps, type Orientation, type OrientationProperty, type PropTypes, type RequiredBy, type RootProperties, type Style, createNormalizer };
1201
+ export { type CommonProperties, type Direction, type DirectionProperty, JSX, type LocaleProperties, type MaybeElement, type NormalizeProps, type Orientation, type OrientationProperty, type PropTypes, type RequiredBy, type Style, createNormalizer, createProps };
package/dist/index.d.ts CHANGED
@@ -1158,6 +1158,9 @@ type NormalizeProps<T extends PropTypes> = {
1158
1158
  };
1159
1159
  declare function createNormalizer<T extends PropTypes>(fn: (props: Dict) => Dict): NormalizeProps<T>;
1160
1160
 
1161
+ type StrictKeys<K extends (keyof T)[], T> = K extends (keyof T)[] ? [keyof T] extends [K[number]] ? unknown : `Missing required keys: ${Exclude<keyof T, K[number]>}` : never;
1162
+ declare const createProps: <T extends Record<never, never>>() => <K extends (keyof T)[]>(props: K & StrictKeys<K, T>) => (keyof T)[];
1163
+
1161
1164
  type RequiredBy<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>;
1162
1165
  type Direction = "ltr" | "rtl";
1163
1166
  type Orientation = "horizontal" | "vertical";
@@ -1193,22 +1196,6 @@ interface CommonProperties {
1193
1196
  */
1194
1197
  getRootNode?: () => ShadowRoot | Document | Node;
1195
1198
  }
1196
- interface RootProperties {
1197
- /**
1198
- * The owner document of the machine.
1199
- */
1200
- doc?: Document;
1201
- /**
1202
- * The root node of the machine. Useful for shadow DOM.
1203
- */
1204
- rootNode?: ShadowRoot;
1205
- /**
1206
- * The related target when the element is blurred.
1207
- * Used as a polyfill for `e.relatedTarget`
1208
- */
1209
- pointerdownNode?: HTMLElement | null;
1210
- }
1211
- type Context<T> = T & RootProperties;
1212
1199
  type Style = JSX.CSSProperties;
1213
1200
 
1214
- export { type CommonProperties, type Context, type Direction, type DirectionProperty, JSX, type LocaleProperties, type MaybeElement, type NormalizeProps, type Orientation, type OrientationProperty, type PropTypes, type RequiredBy, type RootProperties, type Style, createNormalizer };
1201
+ export { type CommonProperties, type Direction, type DirectionProperty, JSX, type LocaleProperties, type MaybeElement, type NormalizeProps, type Orientation, type OrientationProperty, type PropTypes, type RequiredBy, type Style, createNormalizer, createProps };
package/dist/index.js CHANGED
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- createNormalizer: () => createNormalizer
23
+ createNormalizer: () => createNormalizer,
24
+ createProps: () => createProps
24
25
  });
25
26
  module.exports = __toCommonJS(src_exports);
26
27
 
@@ -32,8 +33,12 @@ function createNormalizer(fn) {
32
33
  }
33
34
  });
34
35
  }
36
+
37
+ // src/create-props.ts
38
+ var createProps = () => (props) => Array.from(new Set(props));
35
39
  // Annotate the CommonJS export names for ESM import in node:
36
40
  0 && (module.exports = {
37
- createNormalizer
41
+ createNormalizer,
42
+ createProps
38
43
  });
39
44
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/prop-types.ts"],"sourcesContent":["import type { JSX } from \"./jsx\"\n\nexport type RequiredBy<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>\n\nexport type Direction = \"ltr\" | \"rtl\"\n\nexport type Orientation = \"horizontal\" | \"vertical\"\n\nexport type MaybeElement<T extends HTMLElement = HTMLElement> = T | null\n\nexport interface OrientationProperty {\n /**\n * The orientation of the element.\n * @default \"horizontal\"\n */\n orientation?: Orientation\n}\n\nexport interface DirectionProperty {\n /**\n * The document's text/writing direction.\n * @default \"ltr\"\n */\n dir?: \"ltr\" | \"rtl\"\n}\n\nexport interface LocaleProperties extends DirectionProperty {\n /**\n * The current locale. Based on the BCP 47 definition.\n * @default \"en-US\"\n */\n locale?: string\n}\n\nexport interface CommonProperties {\n /**\n * The unique identifier of the machine.\n */\n id: string\n /**\n * A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron.\n */\n getRootNode?: () => ShadowRoot | Document | Node\n}\n\nexport interface RootProperties {\n /**\n * The owner document of the machine.\n */\n doc?: Document\n /**\n * The root node of the machine. Useful for shadow DOM.\n */\n rootNode?: ShadowRoot\n /**\n * The related target when the element is blurred.\n * Used as a polyfill for `e.relatedTarget`\n */\n pointerdownNode?: HTMLElement | null\n}\n\nexport type Context<T> = T & RootProperties\n\nexport type Style = JSX.CSSProperties\n\nexport * from \"./prop-types\"\nexport type { JSX }\n","import type { JSX } from \"./jsx\"\n\ntype Dict<T = any> = Record<string, T>\n\ntype Booleanish = boolean | \"true\" | \"false\"\n\ntype DataAttr = {\n \"data-selected\"?: Booleanish\n \"data-expanded\"?: Booleanish\n \"data-highlighted\"?: Booleanish\n \"data-readonly\"?: Booleanish\n \"data-indeterminate\"?: Booleanish\n \"data-invalid\"?: Booleanish\n \"data-hover\"?: Booleanish\n \"data-active\"?: Booleanish\n \"data-focus\"?: Booleanish\n \"data-disabled\"?: Booleanish\n \"data-open\"?: Booleanish\n \"data-checked\"?: Booleanish\n \"data-pressed\"?: Booleanish\n \"data-complete\"?: Booleanish\n \"data-empty\"?: Booleanish\n \"data-placeholder-shown\"?: Booleanish\n \"data-half\"?: Booleanish\n \"data-scope\"?: string\n\n \"data-uid\"?: string\n \"data-name\"?: string\n \"data-ownedby\"?: string\n \"data-type\"?: string\n \"data-valuetext\"?: string\n \"data-placement\"?: string\n \"data-controls\"?: string\n \"data-part\"?: string\n \"data-label\"?: string\n \"data-state\"?: string | null\n \"data-value\"?: string | number\n\n \"data-orientation\"?: \"horizontal\" | \"vertical\"\n\n \"data-count\"?: number\n \"data-index\"?: number\n} & {\n [key in `data-${string}`]?: string | number | Booleanish\n}\n\nexport type PropTypes<T = Dict> = Record<\n \"button\" | \"label\" | \"input\" | \"textarea\" | \"img\" | \"output\" | \"element\" | \"select\" | \"style\" | \"circle\" | \"svg\",\n T\n>\n\nexport type NormalizeProps<T extends PropTypes> = {\n [K in keyof T]: (props: K extends keyof JSX.IntrinsicElements ? DataAttr & JSX.IntrinsicElements[K] : never) => T[K]\n} & {\n element(props: DataAttr & JSX.HTMLAttributes<HTMLElement> & Record<string, any>): T[\"element\"]\n style: JSX.CSSProperties\n}\nexport function createNormalizer<T extends PropTypes>(fn: (props: Dict) => Dict): NormalizeProps<T> {\n return new Proxy({} as any, {\n get() {\n return fn\n },\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACyDO,SAAS,iBAAsC,IAA8C;AAClG,SAAO,IAAI,MAAM,CAAC,GAAU;AAAA,IAC1B,MAAM;AACJ,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/prop-types.ts","../src/create-props.ts"],"sourcesContent":["import type { JSX } from \"./jsx\"\n\nexport type RequiredBy<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>\n\nexport type Direction = \"ltr\" | \"rtl\"\n\nexport type Orientation = \"horizontal\" | \"vertical\"\n\nexport type MaybeElement<T extends HTMLElement = HTMLElement> = T | null\n\nexport interface OrientationProperty {\n /**\n * The orientation of the element.\n * @default \"horizontal\"\n */\n orientation?: Orientation\n}\n\nexport interface DirectionProperty {\n /**\n * The document's text/writing direction.\n * @default \"ltr\"\n */\n dir?: \"ltr\" | \"rtl\"\n}\n\nexport interface LocaleProperties extends DirectionProperty {\n /**\n * The current locale. Based on the BCP 47 definition.\n * @default \"en-US\"\n */\n locale?: string\n}\n\nexport interface CommonProperties {\n /**\n * The unique identifier of the machine.\n */\n id: string\n /**\n * A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron.\n */\n getRootNode?: () => ShadowRoot | Document | Node\n}\n\nexport type Style = JSX.CSSProperties\n\nexport * from \"./prop-types\"\nexport type { JSX }\nexport * from \"./create-props\"\n","import type { JSX } from \"./jsx\"\n\ntype Dict<T = any> = Record<string, T>\n\ntype Booleanish = boolean | \"true\" | \"false\"\n\ntype DataAttr = {\n \"data-selected\"?: Booleanish\n \"data-expanded\"?: Booleanish\n \"data-highlighted\"?: Booleanish\n \"data-readonly\"?: Booleanish\n \"data-indeterminate\"?: Booleanish\n \"data-invalid\"?: Booleanish\n \"data-hover\"?: Booleanish\n \"data-active\"?: Booleanish\n \"data-focus\"?: Booleanish\n \"data-disabled\"?: Booleanish\n \"data-open\"?: Booleanish\n \"data-checked\"?: Booleanish\n \"data-pressed\"?: Booleanish\n \"data-complete\"?: Booleanish\n \"data-empty\"?: Booleanish\n \"data-placeholder-shown\"?: Booleanish\n \"data-half\"?: Booleanish\n \"data-scope\"?: string\n\n \"data-uid\"?: string\n \"data-name\"?: string\n \"data-ownedby\"?: string\n \"data-type\"?: string\n \"data-valuetext\"?: string\n \"data-placement\"?: string\n \"data-controls\"?: string\n \"data-part\"?: string\n \"data-label\"?: string\n \"data-state\"?: string | null\n \"data-value\"?: string | number\n\n \"data-orientation\"?: \"horizontal\" | \"vertical\"\n\n \"data-count\"?: number\n \"data-index\"?: number\n} & {\n [key in `data-${string}`]?: string | number | Booleanish\n}\n\nexport type PropTypes<T = Dict> = Record<\n \"button\" | \"label\" | \"input\" | \"textarea\" | \"img\" | \"output\" | \"element\" | \"select\" | \"style\" | \"circle\" | \"svg\",\n T\n>\n\nexport type NormalizeProps<T extends PropTypes> = {\n [K in keyof T]: (props: K extends keyof JSX.IntrinsicElements ? DataAttr & JSX.IntrinsicElements[K] : never) => T[K]\n} & {\n element(props: DataAttr & JSX.HTMLAttributes<HTMLElement> & Record<string, any>): T[\"element\"]\n style: JSX.CSSProperties\n}\n\nexport function createNormalizer<T extends PropTypes>(fn: (props: Dict) => Dict): NormalizeProps<T> {\n return new Proxy({} as any, {\n get() {\n return fn\n },\n })\n}\n","type StrictKeys<K extends (keyof T)[], T> = K extends (keyof T)[]\n ? [keyof T] extends [K[number]]\n ? unknown\n : `Missing required keys: ${Exclude<keyof T, K[number]>}`\n : never\n\nexport const createProps =\n <T extends Record<never, never>>() =>\n <K extends (keyof T)[]>(props: K & StrictKeys<K, T>) =>\n Array.from(new Set(props))\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0DO,SAAS,iBAAsC,IAA8C;AAClG,SAAO,IAAI,MAAM,CAAC,GAAU;AAAA,IAC1B,MAAM;AACJ,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;;;AC1DO,IAAM,cACX,MACA,CAAwB,UACtB,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC;","names":[]}
package/dist/index.mjs CHANGED
@@ -6,7 +6,11 @@ function createNormalizer(fn) {
6
6
  }
7
7
  });
8
8
  }
9
+
10
+ // src/create-props.ts
11
+ var createProps = () => (props) => Array.from(new Set(props));
9
12
  export {
10
- createNormalizer
13
+ createNormalizer,
14
+ createProps
11
15
  };
12
16
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/prop-types.ts"],"sourcesContent":["import type { JSX } from \"./jsx\"\n\ntype Dict<T = any> = Record<string, T>\n\ntype Booleanish = boolean | \"true\" | \"false\"\n\ntype DataAttr = {\n \"data-selected\"?: Booleanish\n \"data-expanded\"?: Booleanish\n \"data-highlighted\"?: Booleanish\n \"data-readonly\"?: Booleanish\n \"data-indeterminate\"?: Booleanish\n \"data-invalid\"?: Booleanish\n \"data-hover\"?: Booleanish\n \"data-active\"?: Booleanish\n \"data-focus\"?: Booleanish\n \"data-disabled\"?: Booleanish\n \"data-open\"?: Booleanish\n \"data-checked\"?: Booleanish\n \"data-pressed\"?: Booleanish\n \"data-complete\"?: Booleanish\n \"data-empty\"?: Booleanish\n \"data-placeholder-shown\"?: Booleanish\n \"data-half\"?: Booleanish\n \"data-scope\"?: string\n\n \"data-uid\"?: string\n \"data-name\"?: string\n \"data-ownedby\"?: string\n \"data-type\"?: string\n \"data-valuetext\"?: string\n \"data-placement\"?: string\n \"data-controls\"?: string\n \"data-part\"?: string\n \"data-label\"?: string\n \"data-state\"?: string | null\n \"data-value\"?: string | number\n\n \"data-orientation\"?: \"horizontal\" | \"vertical\"\n\n \"data-count\"?: number\n \"data-index\"?: number\n} & {\n [key in `data-${string}`]?: string | number | Booleanish\n}\n\nexport type PropTypes<T = Dict> = Record<\n \"button\" | \"label\" | \"input\" | \"textarea\" | \"img\" | \"output\" | \"element\" | \"select\" | \"style\" | \"circle\" | \"svg\",\n T\n>\n\nexport type NormalizeProps<T extends PropTypes> = {\n [K in keyof T]: (props: K extends keyof JSX.IntrinsicElements ? DataAttr & JSX.IntrinsicElements[K] : never) => T[K]\n} & {\n element(props: DataAttr & JSX.HTMLAttributes<HTMLElement> & Record<string, any>): T[\"element\"]\n style: JSX.CSSProperties\n}\nexport function createNormalizer<T extends PropTypes>(fn: (props: Dict) => Dict): NormalizeProps<T> {\n return new Proxy({} as any, {\n get() {\n return fn\n },\n })\n}\n"],"mappings":";AAyDO,SAAS,iBAAsC,IAA8C;AAClG,SAAO,IAAI,MAAM,CAAC,GAAU;AAAA,IAC1B,MAAM;AACJ,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../src/prop-types.ts","../src/create-props.ts"],"sourcesContent":["import type { JSX } from \"./jsx\"\n\ntype Dict<T = any> = Record<string, T>\n\ntype Booleanish = boolean | \"true\" | \"false\"\n\ntype DataAttr = {\n \"data-selected\"?: Booleanish\n \"data-expanded\"?: Booleanish\n \"data-highlighted\"?: Booleanish\n \"data-readonly\"?: Booleanish\n \"data-indeterminate\"?: Booleanish\n \"data-invalid\"?: Booleanish\n \"data-hover\"?: Booleanish\n \"data-active\"?: Booleanish\n \"data-focus\"?: Booleanish\n \"data-disabled\"?: Booleanish\n \"data-open\"?: Booleanish\n \"data-checked\"?: Booleanish\n \"data-pressed\"?: Booleanish\n \"data-complete\"?: Booleanish\n \"data-empty\"?: Booleanish\n \"data-placeholder-shown\"?: Booleanish\n \"data-half\"?: Booleanish\n \"data-scope\"?: string\n\n \"data-uid\"?: string\n \"data-name\"?: string\n \"data-ownedby\"?: string\n \"data-type\"?: string\n \"data-valuetext\"?: string\n \"data-placement\"?: string\n \"data-controls\"?: string\n \"data-part\"?: string\n \"data-label\"?: string\n \"data-state\"?: string | null\n \"data-value\"?: string | number\n\n \"data-orientation\"?: \"horizontal\" | \"vertical\"\n\n \"data-count\"?: number\n \"data-index\"?: number\n} & {\n [key in `data-${string}`]?: string | number | Booleanish\n}\n\nexport type PropTypes<T = Dict> = Record<\n \"button\" | \"label\" | \"input\" | \"textarea\" | \"img\" | \"output\" | \"element\" | \"select\" | \"style\" | \"circle\" | \"svg\",\n T\n>\n\nexport type NormalizeProps<T extends PropTypes> = {\n [K in keyof T]: (props: K extends keyof JSX.IntrinsicElements ? DataAttr & JSX.IntrinsicElements[K] : never) => T[K]\n} & {\n element(props: DataAttr & JSX.HTMLAttributes<HTMLElement> & Record<string, any>): T[\"element\"]\n style: JSX.CSSProperties\n}\n\nexport function createNormalizer<T extends PropTypes>(fn: (props: Dict) => Dict): NormalizeProps<T> {\n return new Proxy({} as any, {\n get() {\n return fn\n },\n })\n}\n","type StrictKeys<K extends (keyof T)[], T> = K extends (keyof T)[]\n ? [keyof T] extends [K[number]]\n ? unknown\n : `Missing required keys: ${Exclude<keyof T, K[number]>}`\n : never\n\nexport const createProps =\n <T extends Record<never, never>>() =>\n <K extends (keyof T)[]>(props: K & StrictKeys<K, T>) =>\n Array.from(new Set(props))\n"],"mappings":";AA0DO,SAAS,iBAAsC,IAA8C;AAClG,SAAO,IAAI,MAAM,CAAC,GAAU;AAAA,IAC1B,MAAM;AACJ,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;;;AC1DO,IAAM,cACX,MACA,CAAwB,UACtB,MAAM,KAAK,IAAI,IAAI,KAAK,CAAC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/types",
3
- "version": "0.36.3",
3
+ "version": "0.37.0",
4
4
  "keywords": [
5
5
  "js",
6
6
  "utils",
@@ -0,0 +1,10 @@
1
+ type StrictKeys<K extends (keyof T)[], T> = K extends (keyof T)[]
2
+ ? [keyof T] extends [K[number]]
3
+ ? unknown
4
+ : `Missing required keys: ${Exclude<keyof T, K[number]>}`
5
+ : never
6
+
7
+ export const createProps =
8
+ <T extends Record<never, never>>() =>
9
+ <K extends (keyof T)[]>(props: K & StrictKeys<K, T>) =>
10
+ Array.from(new Set(props))
package/src/index.ts CHANGED
@@ -43,25 +43,8 @@ export interface CommonProperties {
43
43
  getRootNode?: () => ShadowRoot | Document | Node
44
44
  }
45
45
 
46
- export interface RootProperties {
47
- /**
48
- * The owner document of the machine.
49
- */
50
- doc?: Document
51
- /**
52
- * The root node of the machine. Useful for shadow DOM.
53
- */
54
- rootNode?: ShadowRoot
55
- /**
56
- * The related target when the element is blurred.
57
- * Used as a polyfill for `e.relatedTarget`
58
- */
59
- pointerdownNode?: HTMLElement | null
60
- }
61
-
62
- export type Context<T> = T & RootProperties
63
-
64
46
  export type Style = JSX.CSSProperties
65
47
 
66
48
  export * from "./prop-types"
67
49
  export type { JSX }
50
+ export * from "./create-props"
package/src/prop-types.ts CHANGED
@@ -55,6 +55,7 @@ export type NormalizeProps<T extends PropTypes> = {
55
55
  element(props: DataAttr & JSX.HTMLAttributes<HTMLElement> & Record<string, any>): T["element"]
56
56
  style: JSX.CSSProperties
57
57
  }
58
+
58
59
  export function createNormalizer<T extends PropTypes>(fn: (props: Dict) => Dict): NormalizeProps<T> {
59
60
  return new Proxy({} as any, {
60
61
  get() {