@sprawlify/primitives 0.1.6 → 0.1.8

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 (215) hide show
  1. package/dist/core-Bw_czdwX.cjs +383 -0
  2. package/dist/core-CTtbW9qh.mjs +288 -0
  3. package/dist/core.cjs +9 -1
  4. package/dist/core.d.cts +25 -2
  5. package/dist/core.d.mts +25 -2
  6. package/dist/core.mjs +2 -2
  7. package/dist/machines/accordion/index.cjs +1 -1
  8. package/dist/machines/accordion/index.d.cts +2 -2
  9. package/dist/machines/accordion/index.d.mts +2 -2
  10. package/dist/machines/accordion/index.mjs +1 -1
  11. package/dist/machines/angle-slider/index.cjs +1 -1
  12. package/dist/machines/angle-slider/index.d.cts +2 -2
  13. package/dist/machines/angle-slider/index.d.mts +2 -2
  14. package/dist/machines/angle-slider/index.mjs +1 -1
  15. package/dist/machines/aspect-ratio/index.cjs +1 -1
  16. package/dist/machines/aspect-ratio/index.d.cts +1 -1
  17. package/dist/machines/aspect-ratio/index.d.mts +1 -1
  18. package/dist/machines/aspect-ratio/index.mjs +1 -1
  19. package/dist/machines/async-list/index.cjs +1 -1
  20. package/dist/machines/async-list/index.d.cts +1 -1
  21. package/dist/machines/async-list/index.d.mts +1 -1
  22. package/dist/machines/async-list/index.mjs +1 -1
  23. package/dist/machines/avatar/index.cjs +1 -1
  24. package/dist/machines/avatar/index.d.cts +1 -1
  25. package/dist/machines/avatar/index.d.mts +1 -1
  26. package/dist/machines/avatar/index.mjs +1 -1
  27. package/dist/machines/carousel/index.cjs +69 -18
  28. package/dist/machines/carousel/index.d.cts +3 -3
  29. package/dist/machines/carousel/index.d.mts +3 -3
  30. package/dist/machines/carousel/index.mjs +69 -18
  31. package/dist/machines/cascade-select/index.cjs +1 -1
  32. package/dist/machines/cascade-select/index.d.cts +3 -3
  33. package/dist/machines/cascade-select/index.d.mts +3 -3
  34. package/dist/machines/cascade-select/index.mjs +1 -1
  35. package/dist/machines/checkbox/index.cjs +1 -1
  36. package/dist/machines/checkbox/index.d.cts +2 -2
  37. package/dist/machines/checkbox/index.d.mts +2 -2
  38. package/dist/machines/checkbox/index.mjs +1 -1
  39. package/dist/machines/clipboard/index.cjs +1 -1
  40. package/dist/machines/clipboard/index.d.cts +2 -2
  41. package/dist/machines/clipboard/index.d.mts +2 -2
  42. package/dist/machines/clipboard/index.mjs +1 -1
  43. package/dist/machines/collapsible/index.cjs +1 -1
  44. package/dist/machines/collapsible/index.d.cts +1 -1
  45. package/dist/machines/collapsible/index.d.mts +1 -1
  46. package/dist/machines/collapsible/index.mjs +1 -1
  47. package/dist/machines/color-picker/index.cjs +76 -102
  48. package/dist/machines/color-picker/index.d.cts +3 -3
  49. package/dist/machines/color-picker/index.d.mts +3 -3
  50. package/dist/machines/color-picker/index.mjs +76 -102
  51. package/dist/machines/combobox/index.cjs +1 -1
  52. package/dist/machines/combobox/index.d.cts +2 -2
  53. package/dist/machines/combobox/index.d.mts +2 -2
  54. package/dist/machines/combobox/index.mjs +1 -1
  55. package/dist/machines/date-picker/index.cjs +1 -1
  56. package/dist/machines/date-picker/index.d.cts +2 -2
  57. package/dist/machines/date-picker/index.d.mts +2 -2
  58. package/dist/machines/date-picker/index.mjs +1 -1
  59. package/dist/machines/dialog/index.cjs +1 -1
  60. package/dist/machines/dialog/index.d.cts +2 -2
  61. package/dist/machines/dialog/index.d.mts +2 -2
  62. package/dist/machines/dialog/index.mjs +1 -1
  63. package/dist/machines/drawer/index.cjs +1 -1
  64. package/dist/machines/drawer/index.d.cts +2 -2
  65. package/dist/machines/drawer/index.d.mts +2 -2
  66. package/dist/machines/drawer/index.mjs +1 -1
  67. package/dist/machines/dropdown-menu/index.cjs +1 -1
  68. package/dist/machines/dropdown-menu/index.d.cts +2 -2
  69. package/dist/machines/dropdown-menu/index.d.mts +2 -2
  70. package/dist/machines/dropdown-menu/index.mjs +1 -1
  71. package/dist/machines/editable/index.cjs +1 -1
  72. package/dist/machines/editable/index.d.cts +2 -2
  73. package/dist/machines/editable/index.d.mts +2 -2
  74. package/dist/machines/editable/index.mjs +1 -1
  75. package/dist/machines/file-upload/index.cjs +1 -1
  76. package/dist/machines/file-upload/index.d.cts +2 -2
  77. package/dist/machines/file-upload/index.d.mts +2 -2
  78. package/dist/machines/file-upload/index.mjs +1 -1
  79. package/dist/machines/floating-panel/index.cjs +96 -93
  80. package/dist/machines/floating-panel/index.d.cts +3 -3
  81. package/dist/machines/floating-panel/index.d.mts +3 -3
  82. package/dist/machines/floating-panel/index.mjs +96 -93
  83. package/dist/machines/hover-card/index.cjs +1 -1
  84. package/dist/machines/hover-card/index.d.cts +2 -2
  85. package/dist/machines/hover-card/index.d.mts +2 -2
  86. package/dist/machines/hover-card/index.mjs +1 -1
  87. package/dist/machines/image-cropper/index.cjs +1 -1
  88. package/dist/machines/image-cropper/index.d.cts +1 -1
  89. package/dist/machines/image-cropper/index.d.mts +1 -1
  90. package/dist/machines/image-cropper/index.mjs +1 -1
  91. package/dist/machines/listbox/index.cjs +1 -1
  92. package/dist/machines/listbox/index.d.cts +2 -2
  93. package/dist/machines/listbox/index.d.mts +2 -2
  94. package/dist/machines/listbox/index.mjs +1 -1
  95. package/dist/machines/marquee/index.cjs +1 -1
  96. package/dist/machines/marquee/index.d.cts +3 -3
  97. package/dist/machines/marquee/index.d.mts +3 -3
  98. package/dist/machines/marquee/index.mjs +1 -1
  99. package/dist/machines/navigation-menu/index.cjs +1 -1
  100. package/dist/machines/navigation-menu/index.d.cts +2 -2
  101. package/dist/machines/navigation-menu/index.d.mts +2 -2
  102. package/dist/machines/navigation-menu/index.mjs +1 -1
  103. package/dist/machines/number-input/index.cjs +1 -1
  104. package/dist/machines/number-input/index.d.cts +2 -2
  105. package/dist/machines/number-input/index.d.mts +2 -2
  106. package/dist/machines/number-input/index.mjs +1 -1
  107. package/dist/machines/pagination/index.cjs +1 -1
  108. package/dist/machines/pagination/index.d.cts +1 -1
  109. package/dist/machines/pagination/index.d.mts +1 -1
  110. package/dist/machines/pagination/index.mjs +1 -1
  111. package/dist/machines/password-input/index.cjs +1 -1
  112. package/dist/machines/password-input/index.d.cts +2 -2
  113. package/dist/machines/password-input/index.d.mts +2 -2
  114. package/dist/machines/password-input/index.mjs +1 -1
  115. package/dist/machines/pin-input/index.cjs +1 -1
  116. package/dist/machines/pin-input/index.d.cts +2 -2
  117. package/dist/machines/pin-input/index.d.mts +2 -2
  118. package/dist/machines/pin-input/index.mjs +1 -1
  119. package/dist/machines/popover/index.cjs +1 -1
  120. package/dist/machines/popover/index.d.cts +2 -2
  121. package/dist/machines/popover/index.d.mts +2 -2
  122. package/dist/machines/popover/index.mjs +1 -1
  123. package/dist/machines/presence/index.cjs +1 -1
  124. package/dist/machines/presence/index.d.cts +1 -1
  125. package/dist/machines/presence/index.d.mts +1 -1
  126. package/dist/machines/presence/index.mjs +1 -1
  127. package/dist/machines/progress/index.cjs +1 -1
  128. package/dist/machines/progress/index.d.cts +2 -2
  129. package/dist/machines/progress/index.d.mts +2 -2
  130. package/dist/machines/progress/index.mjs +1 -1
  131. package/dist/machines/qr-code/index.cjs +1 -1
  132. package/dist/machines/qr-code/index.d.cts +1 -1
  133. package/dist/machines/qr-code/index.d.mts +1 -1
  134. package/dist/machines/qr-code/index.mjs +1 -1
  135. package/dist/machines/radio-group/index.cjs +1 -1
  136. package/dist/machines/radio-group/index.d.cts +1 -1
  137. package/dist/machines/radio-group/index.d.mts +1 -1
  138. package/dist/machines/radio-group/index.mjs +1 -1
  139. package/dist/machines/rating-group/index.cjs +1 -1
  140. package/dist/machines/rating-group/index.d.cts +2 -2
  141. package/dist/machines/rating-group/index.d.mts +2 -2
  142. package/dist/machines/rating-group/index.mjs +1 -1
  143. package/dist/machines/scroll-area/index.cjs +1 -1
  144. package/dist/machines/scroll-area/index.d.cts +1 -1
  145. package/dist/machines/scroll-area/index.d.mts +1 -1
  146. package/dist/machines/scroll-area/index.mjs +1 -1
  147. package/dist/machines/select/index.cjs +1 -1
  148. package/dist/machines/select/index.d.cts +2 -2
  149. package/dist/machines/select/index.d.mts +2 -2
  150. package/dist/machines/select/index.mjs +1 -1
  151. package/dist/machines/separator/index.cjs +1 -1
  152. package/dist/machines/separator/index.d.cts +1 -1
  153. package/dist/machines/separator/index.d.mts +1 -1
  154. package/dist/machines/separator/index.mjs +1 -1
  155. package/dist/machines/signature-pad/index.cjs +1 -1
  156. package/dist/machines/signature-pad/index.d.cts +2 -2
  157. package/dist/machines/signature-pad/index.d.mts +2 -2
  158. package/dist/machines/signature-pad/index.mjs +1 -1
  159. package/dist/machines/slider/index.cjs +1 -1
  160. package/dist/machines/slider/index.d.cts +2 -2
  161. package/dist/machines/slider/index.d.mts +2 -2
  162. package/dist/machines/slider/index.mjs +1 -1
  163. package/dist/machines/splitter/index.cjs +1 -1
  164. package/dist/machines/splitter/index.d.cts +1 -1
  165. package/dist/machines/splitter/index.d.mts +1 -1
  166. package/dist/machines/splitter/index.mjs +1 -1
  167. package/dist/machines/steps/index.cjs +1 -1
  168. package/dist/machines/steps/index.d.cts +2 -2
  169. package/dist/machines/steps/index.d.mts +2 -2
  170. package/dist/machines/steps/index.mjs +1 -1
  171. package/dist/machines/switch/index.cjs +1 -1
  172. package/dist/machines/switch/index.d.cts +2 -2
  173. package/dist/machines/switch/index.d.mts +2 -2
  174. package/dist/machines/switch/index.mjs +1 -1
  175. package/dist/machines/tabs/index.cjs +1 -1
  176. package/dist/machines/tabs/index.d.cts +2 -2
  177. package/dist/machines/tabs/index.d.mts +2 -2
  178. package/dist/machines/tabs/index.mjs +1 -1
  179. package/dist/machines/tags-input/index.cjs +1 -1
  180. package/dist/machines/tags-input/index.d.cts +2 -2
  181. package/dist/machines/tags-input/index.d.mts +2 -2
  182. package/dist/machines/tags-input/index.mjs +1 -1
  183. package/dist/machines/timer/index.cjs +1 -1
  184. package/dist/machines/timer/index.d.cts +2 -2
  185. package/dist/machines/timer/index.d.mts +2 -2
  186. package/dist/machines/timer/index.mjs +1 -1
  187. package/dist/machines/toast/index.cjs +1 -1
  188. package/dist/machines/toast/index.d.cts +2 -2
  189. package/dist/machines/toast/index.d.mts +2 -2
  190. package/dist/machines/toast/index.mjs +1 -1
  191. package/dist/machines/toggle/index.cjs +1 -1
  192. package/dist/machines/toggle/index.d.cts +1 -1
  193. package/dist/machines/toggle/index.d.mts +1 -1
  194. package/dist/machines/toggle/index.mjs +1 -1
  195. package/dist/machines/toggle-group/index.cjs +1 -1
  196. package/dist/machines/toggle-group/index.d.cts +1 -1
  197. package/dist/machines/toggle-group/index.d.mts +1 -1
  198. package/dist/machines/toggle-group/index.mjs +1 -1
  199. package/dist/machines/tooltip/index.cjs +1 -1
  200. package/dist/machines/tooltip/index.d.cts +2 -2
  201. package/dist/machines/tooltip/index.d.mts +2 -2
  202. package/dist/machines/tooltip/index.mjs +1 -1
  203. package/dist/machines/tour/index.cjs +48 -46
  204. package/dist/machines/tour/index.d.cts +3 -3
  205. package/dist/machines/tour/index.d.mts +3 -3
  206. package/dist/machines/tour/index.mjs +48 -46
  207. package/dist/machines/tree-view/index.cjs +1 -1
  208. package/dist/machines/tree-view/index.d.cts +2 -2
  209. package/dist/machines/tree-view/index.d.mts +2 -2
  210. package/dist/machines/tree-view/index.mjs +1 -1
  211. package/dist/{types-B24gMTKq.d.cts → types-DvUmCWsb.d.mts} +28 -12
  212. package/dist/{types-DUM9rzfD.d.mts → types-u-LWCSDE.d.cts} +28 -12
  213. package/package.json +1 -1
  214. package/dist/core-Ci9Yu6QI.mjs +0 -123
  215. package/dist/core-DwdPztGA.cjs +0 -170
@@ -105,14 +105,26 @@ interface Params<T extends Dict> {
105
105
  guard: (key: T["guard"] | GuardFn<T>) => boolean | undefined;
106
106
  }
107
107
  type GuardFn<T extends Dict> = (params: Params<T>) => boolean;
108
- interface Transition<T extends Dict> {
109
- target?: T["state"] | undefined;
108
+ type TopLevelState<S extends string> = S extends `${infer Top}.${string}` ? Top : S;
109
+ type ChildStateKey<S extends string, Parent extends string> = S extends `${Parent}.${infer Rest}` ? Rest extends `${infer Child}.${string}` ? Child : Rest : never;
110
+ type ParentPath<S extends string> = S extends `${infer Parent}.${string}` ? Parent : never;
111
+ type AncestorPaths<S extends string> = S | (ParentPath<S> extends never ? never : AncestorPaths<ParentPath<S>>);
112
+ type RelativeStateTarget<S extends string, Source extends string> = ChildStateKey<S, AncestorPaths<Source>>;
113
+ type StateIdTarget = `#${string}`;
114
+ interface Transition<T extends Dict, Source extends string | undefined = string | undefined> {
115
+ target?: T["state"] | StateIdTarget | (Source extends string ? RelativeStateTarget<T["state"], Source> : never) | undefined;
110
116
  actions?: T["action"][] | undefined;
111
117
  guard?: T["guard"] | GuardFn<T> | undefined;
112
118
  reenter?: boolean | undefined;
113
119
  }
120
+ type TransitionSet<T extends Dict> = Transition<T> | Transition<T>[] | undefined;
121
+ type TransitionMap<T extends Dict> = Record<string, TransitionSet<T>>;
122
+ type TransitionMatch<T extends Dict> = {
123
+ transitions: TransitionSet<T>;
124
+ source: string | undefined;
125
+ };
114
126
  type MaybeArray<T> = T | T[];
115
- type ChooseFn<T extends Dict> = (transitions: MaybeArray<Omit<Transition<T>, "target">>) => Transition<T> | undefined;
127
+ type ChooseFn<T extends Dict> = (transitions: MaybeArray<Omit<Transition<T, string>, "target">> | null | undefined) => Transition<T> | undefined;
116
128
  interface PropsParams<T extends Dict> {
117
129
  props: Partial<T["props"]>;
118
130
  scope: Scope;
@@ -123,6 +135,16 @@ interface RefsParams<T extends Dict> {
123
135
  }
124
136
  type ActionsOrFn<T extends Dict> = T["action"][] | ((params: Params<T>) => T["action"][] | undefined);
125
137
  type EffectsOrFn<T extends Dict> = T["effect"][] | ((params: Params<T>) => T["effect"][] | undefined);
138
+ interface MachineState<T extends Dict, Parent extends string = string> {
139
+ id?: string | undefined;
140
+ tags?: T["tag"][] | undefined;
141
+ entry?: ActionsOrFn<T> | undefined;
142
+ exit?: ActionsOrFn<T> | undefined;
143
+ effects?: EffectsOrFn<T> | undefined;
144
+ initial?: ChildStateKey<T["state"], Parent> | undefined;
145
+ states?: { [K in ChildStateKey<T["state"], Parent>]?: MachineState<T, `${Parent}.${K}`> } | undefined;
146
+ on?: { [E in T["event"]["type"]]?: Transition<T, Parent> | Array<Transition<T, Parent>> } | undefined;
147
+ }
126
148
  interface Machine<T extends Dict> {
127
149
  debug?: boolean | undefined;
128
150
  props?: ((params: PropsParams<T>) => T["props"]) | undefined;
@@ -136,14 +158,8 @@ interface Machine<T extends Dict> {
136
158
  effects?: EffectsOrFn<T> | undefined;
137
159
  refs?: ((params: RefsParams<T>) => T["refs"]) | undefined;
138
160
  watch?: ((params: Params<T>) => void) | undefined;
139
- on?: { [E in T["event"]["type"]]?: Transition<T> | Array<Transition<T>> } | undefined;
140
- states: { [K in T["state"]]: {
141
- tags?: T["tag"][] | undefined;
142
- entry?: ActionsOrFn<T> | undefined;
143
- exit?: ActionsOrFn<T> | undefined;
144
- effects?: EffectsOrFn<T> | undefined;
145
- on?: { [E in T["event"]["type"]]?: Transition<T> | Array<Transition<T>> } | undefined;
146
- } };
161
+ on?: { [E in T["event"]["type"]]?: Transition<T, undefined> | Array<Transition<T, undefined>> } | undefined;
162
+ states: { [K in TopLevelState<T["state"]>]: MachineState<T, K> };
147
163
  implementations?: {
148
164
  guards?: { [K in T["guard"]]: (params: Params<T>) => boolean } | undefined;
149
165
  actions?: { [K in T["action"]]: (params: Params<T>) => void } | undefined;
@@ -198,4 +214,4 @@ declare enum MachineStatus {
198
214
  }
199
215
  declare const INIT_STATE = "__init__";
200
216
  //#endregion
201
- export { PropFn as _, BindableParams as a, Transition as b, ComputedFn as c, GuardFn as d, INIT_STATE as f, Params as g, MachineStatus as h, BindableFn as i, EffectsOrFn as l, MachineSchema as m, Bindable as n, BindableRefs as o, Machine as p, BindableContext as r, ChooseFn as s, ActionsOrFn as t, EventObject as u, Scope as v, ValueOrFn as x, Service as y };
217
+ export { TransitionMatch as C, TransitionMap as S, ValueOrFn as T, Params as _, BindableParams as a, Service as b, ComputedFn as c, GuardFn as d, INIT_STATE as f, MachineStatus as g, MachineState as h, BindableFn as i, EffectsOrFn as l, MachineSchema as m, Bindable as n, BindableRefs as o, Machine as p, BindableContext as r, ChooseFn as s, ActionsOrFn as t, EventObject as u, PropFn as v, TransitionSet as w, Transition as x, Scope as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprawlify/primitives",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "A set of primitive components for building user interfaces.",
5
5
  "license": "MIT",
6
6
  "author": "sprawlify <npm@sprawlify.com>",
@@ -1,123 +0,0 @@
1
- import { en as getActiveElement, sn as isActiveElement, tn as getDocument } from "./dom-query-BFuRs3l4.mjs";
2
- import { W as callAll, dt as isString, ft as isEqual } from "./utils-VVoZ_v29.mjs";
3
- //#region src/shared/core/merge-props.ts
4
- const clsx = (...args) => args.map((str) => str?.trim?.()).filter(Boolean).join(" ");
5
- const CSS_REGEX = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g;
6
- const serialize = (style) => {
7
- const res = {};
8
- let match;
9
- while (match = CSS_REGEX.exec(style)) res[match[1]] = match[2];
10
- return res;
11
- };
12
- const css = (a, b) => {
13
- if (isString(a)) {
14
- if (isString(b)) return `${a};${b}`;
15
- a = serialize(a);
16
- } else if (isString(b)) b = serialize(b);
17
- return Object.assign({}, a ?? {}, b ?? {});
18
- };
19
- function mergeProps(...args) {
20
- let result = {};
21
- for (let props of args) {
22
- if (!props) continue;
23
- for (let key in result) {
24
- if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
25
- result[key] = callAll(props[key], result[key]);
26
- continue;
27
- }
28
- if (key === "className" || key === "class") {
29
- result[key] = clsx(result[key], props[key]);
30
- continue;
31
- }
32
- if (key === "style") {
33
- result[key] = css(result[key], props[key]);
34
- continue;
35
- }
36
- result[key] = props[key] !== void 0 ? props[key] : result[key];
37
- }
38
- for (let key in props) if (result[key] === void 0) result[key] = props[key];
39
- const symbols = Object.getOwnPropertySymbols(props);
40
- for (let symbol of symbols) result[symbol] = props[symbol];
41
- }
42
- return result;
43
- }
44
- //#endregion
45
- //#region src/shared/core/memo.ts
46
- function memo(getDeps, fn, opts) {
47
- let deps = [];
48
- let result;
49
- return (depArgs) => {
50
- const newDeps = getDeps(depArgs);
51
- if (!(newDeps.length !== deps.length || newDeps.some((dep, index) => !isEqual(deps[index], dep)))) return result;
52
- deps = newDeps;
53
- result = fn(newDeps, depArgs);
54
- opts?.onChange?.(result);
55
- return result;
56
- };
57
- }
58
- //#endregion
59
- //#region src/shared/core/create-machine.ts
60
- function createGuards() {
61
- return {
62
- and: (...guards) => {
63
- return function andGuard(params) {
64
- return guards.every((str) => params.guard(str));
65
- };
66
- },
67
- or: (...guards) => {
68
- return function orGuard(params) {
69
- return guards.some((str) => params.guard(str));
70
- };
71
- },
72
- not: (guard) => {
73
- return function notGuard(params) {
74
- return !params.guard(guard);
75
- };
76
- }
77
- };
78
- }
79
- function createMachine(config) {
80
- return config;
81
- }
82
- function setup() {
83
- return {
84
- guards: createGuards(),
85
- createMachine: (config) => {
86
- return createMachine(config);
87
- },
88
- choose: (transitions) => {
89
- return function chooseFn({ choose }) {
90
- return choose(transitions)?.actions;
91
- };
92
- }
93
- };
94
- }
95
- //#endregion
96
- //#region src/shared/core/types.ts
97
- let MachineStatus = /* @__PURE__ */ function(MachineStatus) {
98
- MachineStatus["NotStarted"] = "Not Started";
99
- MachineStatus["Started"] = "Started";
100
- MachineStatus["Stopped"] = "Stopped";
101
- return MachineStatus;
102
- }({});
103
- const INIT_STATE = "__init__";
104
- //#endregion
105
- //#region src/shared/core/scope.ts
106
- function createScope(props) {
107
- const getRootNode = () => props.getRootNode?.() ?? document;
108
- const getDoc = () => getDocument(getRootNode());
109
- const getWin = () => getDoc().defaultView ?? window;
110
- const getActiveElementFn = () => getActiveElement(getRootNode());
111
- const getById = (id) => getRootNode().getElementById(id);
112
- return {
113
- ...props,
114
- getRootNode,
115
- getDoc,
116
- getWin,
117
- getActiveElement: getActiveElementFn,
118
- isActiveElement,
119
- getById
120
- };
121
- }
122
- //#endregion
123
- export { createMachine as a, mergeProps as c, createGuards as i, INIT_STATE as n, setup as o, MachineStatus as r, memo as s, createScope as t };
@@ -1,170 +0,0 @@
1
- const require_dom_query = require("./dom-query-BUO7rGsg.cjs");
2
- const require_utils = require("./utils-ByNiZU8f.cjs");
3
- //#region src/shared/core/merge-props.ts
4
- const clsx = (...args) => args.map((str) => str?.trim?.()).filter(Boolean).join(" ");
5
- const CSS_REGEX = /((?:--)?(?:\w+-?)+)\s*:\s*([^;]*)/g;
6
- const serialize = (style) => {
7
- const res = {};
8
- let match;
9
- while (match = CSS_REGEX.exec(style)) res[match[1]] = match[2];
10
- return res;
11
- };
12
- const css = (a, b) => {
13
- if (require_utils.isString(a)) {
14
- if (require_utils.isString(b)) return `${a};${b}`;
15
- a = serialize(a);
16
- } else if (require_utils.isString(b)) b = serialize(b);
17
- return Object.assign({}, a ?? {}, b ?? {});
18
- };
19
- function mergeProps(...args) {
20
- let result = {};
21
- for (let props of args) {
22
- if (!props) continue;
23
- for (let key in result) {
24
- if (key.startsWith("on") && typeof result[key] === "function" && typeof props[key] === "function") {
25
- result[key] = require_utils.callAll(props[key], result[key]);
26
- continue;
27
- }
28
- if (key === "className" || key === "class") {
29
- result[key] = clsx(result[key], props[key]);
30
- continue;
31
- }
32
- if (key === "style") {
33
- result[key] = css(result[key], props[key]);
34
- continue;
35
- }
36
- result[key] = props[key] !== void 0 ? props[key] : result[key];
37
- }
38
- for (let key in props) if (result[key] === void 0) result[key] = props[key];
39
- const symbols = Object.getOwnPropertySymbols(props);
40
- for (let symbol of symbols) result[symbol] = props[symbol];
41
- }
42
- return result;
43
- }
44
- //#endregion
45
- //#region src/shared/core/memo.ts
46
- function memo(getDeps, fn, opts) {
47
- let deps = [];
48
- let result;
49
- return (depArgs) => {
50
- const newDeps = getDeps(depArgs);
51
- if (!(newDeps.length !== deps.length || newDeps.some((dep, index) => !require_utils.isEqual(deps[index], dep)))) return result;
52
- deps = newDeps;
53
- result = fn(newDeps, depArgs);
54
- opts?.onChange?.(result);
55
- return result;
56
- };
57
- }
58
- //#endregion
59
- //#region src/shared/core/create-machine.ts
60
- function createGuards() {
61
- return {
62
- and: (...guards) => {
63
- return function andGuard(params) {
64
- return guards.every((str) => params.guard(str));
65
- };
66
- },
67
- or: (...guards) => {
68
- return function orGuard(params) {
69
- return guards.some((str) => params.guard(str));
70
- };
71
- },
72
- not: (guard) => {
73
- return function notGuard(params) {
74
- return !params.guard(guard);
75
- };
76
- }
77
- };
78
- }
79
- function createMachine(config) {
80
- return config;
81
- }
82
- function setup() {
83
- return {
84
- guards: createGuards(),
85
- createMachine: (config) => {
86
- return createMachine(config);
87
- },
88
- choose: (transitions) => {
89
- return function chooseFn({ choose }) {
90
- return choose(transitions)?.actions;
91
- };
92
- }
93
- };
94
- }
95
- //#endregion
96
- //#region src/shared/core/types.ts
97
- let MachineStatus = /* @__PURE__ */ function(MachineStatus) {
98
- MachineStatus["NotStarted"] = "Not Started";
99
- MachineStatus["Started"] = "Started";
100
- MachineStatus["Stopped"] = "Stopped";
101
- return MachineStatus;
102
- }({});
103
- const INIT_STATE = "__init__";
104
- //#endregion
105
- //#region src/shared/core/scope.ts
106
- function createScope(props) {
107
- const getRootNode = () => props.getRootNode?.() ?? document;
108
- const getDoc = () => require_dom_query.getDocument(getRootNode());
109
- const getWin = () => getDoc().defaultView ?? window;
110
- const getActiveElementFn = () => require_dom_query.getActiveElement(getRootNode());
111
- const getById = (id) => getRootNode().getElementById(id);
112
- return {
113
- ...props,
114
- getRootNode,
115
- getDoc,
116
- getWin,
117
- getActiveElement: getActiveElementFn,
118
- isActiveElement: require_dom_query.isActiveElement,
119
- getById
120
- };
121
- }
122
- //#endregion
123
- Object.defineProperty(exports, "INIT_STATE", {
124
- enumerable: true,
125
- get: function() {
126
- return INIT_STATE;
127
- }
128
- });
129
- Object.defineProperty(exports, "MachineStatus", {
130
- enumerable: true,
131
- get: function() {
132
- return MachineStatus;
133
- }
134
- });
135
- Object.defineProperty(exports, "createGuards", {
136
- enumerable: true,
137
- get: function() {
138
- return createGuards;
139
- }
140
- });
141
- Object.defineProperty(exports, "createMachine", {
142
- enumerable: true,
143
- get: function() {
144
- return createMachine;
145
- }
146
- });
147
- Object.defineProperty(exports, "createScope", {
148
- enumerable: true,
149
- get: function() {
150
- return createScope;
151
- }
152
- });
153
- Object.defineProperty(exports, "memo", {
154
- enumerable: true,
155
- get: function() {
156
- return memo;
157
- }
158
- });
159
- Object.defineProperty(exports, "mergeProps", {
160
- enumerable: true,
161
- get: function() {
162
- return mergeProps;
163
- }
164
- });
165
- Object.defineProperty(exports, "setup", {
166
- enumerable: true,
167
- get: function() {
168
- return setup;
169
- }
170
- });