@omerdlw/base-framework 1.0.6 → 2.0.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.
Files changed (231) hide show
  1. package/dist/atoms/index.js +1 -103
  2. package/dist/atoms/index.js.map +1 -1
  3. package/dist/chunk-3BUP64Q6.js +105 -0
  4. package/dist/chunk-3BUP64Q6.js.map +1 -0
  5. package/dist/chunk-3MSK4XGK.js +9888 -0
  6. package/dist/chunk-3MSK4XGK.js.map +1 -0
  7. package/dist/chunk-4GMQKD6F.js +353 -0
  8. package/dist/chunk-4GMQKD6F.js.map +1 -0
  9. package/dist/chunk-65ZB4QTQ.js +888 -0
  10. package/dist/chunk-65ZB4QTQ.js.map +1 -0
  11. package/dist/chunk-6SG7V77J.js +577 -0
  12. package/dist/chunk-6SG7V77J.js.map +1 -0
  13. package/dist/chunk-7HQMXTNP.js +419 -0
  14. package/dist/chunk-7HQMXTNP.js.map +1 -0
  15. package/dist/chunk-7TAVYJ3A.js +371 -0
  16. package/dist/chunk-7TAVYJ3A.js.map +1 -0
  17. package/dist/chunk-AQ4BNXA2.js +349 -0
  18. package/dist/chunk-AQ4BNXA2.js.map +1 -0
  19. package/dist/chunk-CGHZSSFR.js +2166 -0
  20. package/dist/chunk-CGHZSSFR.js.map +1 -0
  21. package/dist/chunk-DGCQWQLZ.js +61 -0
  22. package/dist/chunk-DGCQWQLZ.js.map +1 -0
  23. package/dist/chunk-FIMPHODX.js +67 -0
  24. package/dist/chunk-FIMPHODX.js.map +1 -0
  25. package/dist/chunk-GF7TUX5I.js +1889 -0
  26. package/dist/chunk-GF7TUX5I.js.map +1 -0
  27. package/dist/chunk-JELG4JLT.js +454 -0
  28. package/dist/chunk-JELG4JLT.js.map +1 -0
  29. package/dist/chunk-K676GL7Z.js +51 -0
  30. package/dist/chunk-K676GL7Z.js.map +1 -0
  31. package/dist/chunk-KKQT46TP.js +26 -0
  32. package/dist/chunk-KKQT46TP.js.map +1 -0
  33. package/dist/chunk-QI3ALLIB.js +38 -0
  34. package/dist/chunk-QI3ALLIB.js.map +1 -0
  35. package/dist/chunk-QXR55VVS.js +1139 -0
  36. package/dist/chunk-QXR55VVS.js.map +1 -0
  37. package/dist/chunk-R2YGFJDJ.js +408 -0
  38. package/dist/chunk-R2YGFJDJ.js.map +1 -0
  39. package/dist/chunk-RFZQWLC5.js +27 -0
  40. package/dist/chunk-RFZQWLC5.js.map +1 -0
  41. package/dist/chunk-SYAVGTOX.js +521 -0
  42. package/dist/chunk-SYAVGTOX.js.map +1 -0
  43. package/dist/chunk-TV3WEF5G.js +784 -0
  44. package/dist/chunk-TV3WEF5G.js.map +1 -0
  45. package/dist/chunk-XASQT4CQ.js +280 -0
  46. package/dist/chunk-XASQT4CQ.js.map +1 -0
  47. package/dist/error/index.js +5 -682
  48. package/dist/error/index.js.map +1 -1
  49. package/dist/error/reporter.d.ts.map +1 -1
  50. package/dist/error/theme.d.ts +1 -1
  51. package/dist/error/theme.d.ts.map +1 -1
  52. package/dist/events.js +1 -7
  53. package/dist/events.js.map +1 -1
  54. package/dist/hooks/index.js +1 -358
  55. package/dist/hooks/index.js.map +1 -1
  56. package/dist/hooks/use-global-event.d.ts +1 -1
  57. package/dist/index.js +18 -20029
  58. package/dist/index.js.map +1 -1
  59. package/dist/kernel/index.js +2 -2035
  60. package/dist/kernel/index.js.map +1 -1
  61. package/dist/kernel/types.d.ts +1 -1
  62. package/dist/modules/ambient/analyze.d.ts +46 -0
  63. package/dist/modules/ambient/analyze.d.ts.map +1 -0
  64. package/dist/modules/ambient/constants.d.ts +1 -5
  65. package/dist/modules/ambient/constants.d.ts.map +1 -1
  66. package/dist/modules/ambient/context.d.ts.map +1 -1
  67. package/dist/modules/ambient/dom.d.ts +11 -12
  68. package/dist/modules/ambient/dom.d.ts.map +1 -1
  69. package/dist/modules/ambient/extractor.d.ts +10 -10
  70. package/dist/modules/ambient/extractor.d.ts.map +1 -1
  71. package/dist/modules/ambient/hooks.d.ts +1 -1
  72. package/dist/modules/ambient/hooks.d.ts.map +1 -1
  73. package/dist/modules/ambient/index.d.ts +6 -4
  74. package/dist/modules/ambient/index.d.ts.map +1 -1
  75. package/dist/modules/ambient/index.js +7 -762
  76. package/dist/modules/ambient/index.js.map +1 -1
  77. package/dist/modules/ambient/module.d.ts +1 -1
  78. package/dist/modules/ambient/module.d.ts.map +1 -1
  79. package/dist/modules/ambient/oklab.d.ts +36 -0
  80. package/dist/modules/ambient/oklab.d.ts.map +1 -0
  81. package/dist/modules/ambient/pipeline.d.ts +28 -0
  82. package/dist/modules/ambient/pipeline.d.ts.map +1 -0
  83. package/dist/modules/ambient/quantize.d.ts +22 -0
  84. package/dist/modules/ambient/quantize.d.ts.map +1 -0
  85. package/dist/modules/ambient/server/address.d.ts +8 -0
  86. package/dist/modules/ambient/server/address.d.ts.map +1 -0
  87. package/dist/modules/ambient/server/index.d.ts +53 -0
  88. package/dist/modules/ambient/server/index.d.ts.map +1 -0
  89. package/dist/modules/ambient/server/index.js +221 -0
  90. package/dist/modules/ambient/server/index.js.map +1 -0
  91. package/dist/modules/ambient/settings.d.ts +19 -0
  92. package/dist/modules/ambient/settings.d.ts.map +1 -0
  93. package/dist/modules/ambient/types.d.ts +105 -9
  94. package/dist/modules/ambient/types.d.ts.map +1 -1
  95. package/dist/modules/ambient/worker/index.d.ts +15 -0
  96. package/dist/modules/ambient/worker/index.d.ts.map +1 -0
  97. package/dist/modules/ambient/worker/index.js +114 -0
  98. package/dist/modules/ambient/worker/index.js.map +1 -0
  99. package/dist/modules/background/constants.d.ts +2 -2
  100. package/dist/modules/background/constants.d.ts.map +1 -1
  101. package/dist/modules/background/hooks.d.ts +1 -1
  102. package/dist/modules/background/index.js +6 -3078
  103. package/dist/modules/background/index.js.map +1 -1
  104. package/dist/modules/background/motion.d.ts +9 -7
  105. package/dist/modules/background/motion.d.ts.map +1 -1
  106. package/dist/modules/background/overlay.d.ts +3 -8
  107. package/dist/modules/background/overlay.d.ts.map +1 -1
  108. package/dist/modules/background/types.d.ts +16 -2
  109. package/dist/modules/background/types.d.ts.map +1 -1
  110. package/dist/modules/context-menu/constants.d.ts +2 -2
  111. package/dist/modules/context-menu/constants.d.ts.map +1 -1
  112. package/dist/modules/context-menu/hooks.d.ts +1 -1
  113. package/dist/modules/context-menu/index.js +10 -1896
  114. package/dist/modules/context-menu/index.js.map +1 -1
  115. package/dist/modules/context-menu/motion.d.ts +1 -8
  116. package/dist/modules/context-menu/motion.d.ts.map +1 -1
  117. package/dist/modules/context-menu/overlay.d.ts.map +1 -1
  118. package/dist/modules/context-menu/types.d.ts +16 -2
  119. package/dist/modules/context-menu/types.d.ts.map +1 -1
  120. package/dist/modules/controls/constants.d.ts +1 -1
  121. package/dist/modules/controls/constants.d.ts.map +1 -1
  122. package/dist/modules/controls/entries.d.ts +1 -1
  123. package/dist/modules/controls/hooks.d.ts +1 -1
  124. package/dist/modules/controls/index.js +4 -1110
  125. package/dist/modules/controls/index.js.map +1 -1
  126. package/dist/modules/controls/overlay.d.ts +1 -1
  127. package/dist/modules/controls/types.d.ts +2 -2
  128. package/dist/modules/dock/cards.d.ts +708 -24
  129. package/dist/modules/dock/cards.d.ts.map +1 -1
  130. package/dist/modules/dock/constants.d.ts +2 -2
  131. package/dist/modules/dock/constants.d.ts.map +1 -1
  132. package/dist/modules/dock/helpers.d.ts +2 -2
  133. package/dist/modules/dock/hooks.d.ts +2 -2
  134. package/dist/modules/dock/index.d.ts +1 -1
  135. package/dist/modules/dock/index.d.ts.map +1 -1
  136. package/dist/modules/dock/index.js +9 -12132
  137. package/dist/modules/dock/index.js.map +1 -1
  138. package/dist/modules/dock/module.d.ts +1 -1
  139. package/dist/modules/dock/motion.d.ts +41 -915
  140. package/dist/modules/dock/motion.d.ts.map +1 -1
  141. package/dist/modules/dock/overlay.d.ts.map +1 -1
  142. package/dist/modules/dock/runtime/dock.d.ts +1 -23
  143. package/dist/modules/dock/runtime/dock.d.ts.map +1 -1
  144. package/dist/modules/dock/styles.d.ts +4 -4
  145. package/dist/modules/dock/surface/hooks.d.ts +5 -20
  146. package/dist/modules/dock/surface/hooks.d.ts.map +1 -1
  147. package/dist/modules/dock/surface/machine.d.ts +4 -3
  148. package/dist/modules/dock/surface/machine.d.ts.map +1 -1
  149. package/dist/modules/dock/surface/stack.d.ts.map +1 -1
  150. package/dist/modules/dock/types.d.ts +158 -3
  151. package/dist/modules/dock/types.d.ts.map +1 -1
  152. package/dist/modules/index.js +16 -17883
  153. package/dist/modules/index.js.map +1 -1
  154. package/dist/modules/loading/constants.d.ts +1 -1
  155. package/dist/modules/loading/constants.d.ts.map +1 -1
  156. package/dist/modules/loading/context.d.ts +1 -1
  157. package/dist/modules/loading/hooks.d.ts +1 -1
  158. package/dist/modules/loading/index.js +5 -1153
  159. package/dist/modules/loading/index.js.map +1 -1
  160. package/dist/modules/loading/types.d.ts +2 -2
  161. package/dist/modules/media/context.d.ts +1 -1
  162. package/dist/modules/media/index.js +3 -570
  163. package/dist/modules/media/index.js.map +1 -1
  164. package/dist/modules/media/types.d.ts +2 -2
  165. package/dist/modules/modal/constants.d.ts +2 -2
  166. package/dist/modules/modal/constants.d.ts.map +1 -1
  167. package/dist/modules/modal/context.d.ts +1 -1
  168. package/dist/modules/modal/hooks.d.ts +3 -3
  169. package/dist/modules/modal/index.js +8 -2355
  170. package/dist/modules/modal/index.js.map +1 -1
  171. package/dist/modules/modal/motion.d.ts +3 -8
  172. package/dist/modules/modal/motion.d.ts.map +1 -1
  173. package/dist/modules/modal/overlay.d.ts.map +1 -1
  174. package/dist/modules/modal/types.d.ts +21 -0
  175. package/dist/modules/modal/types.d.ts.map +1 -1
  176. package/dist/modules/notification/constants.d.ts +2 -2
  177. package/dist/modules/notification/constants.d.ts.map +1 -1
  178. package/dist/modules/notification/context.d.ts +1 -1
  179. package/dist/modules/notification/hooks.d.ts +1 -1
  180. package/dist/modules/notification/index.js +4 -828
  181. package/dist/modules/notification/index.js.map +1 -1
  182. package/dist/modules/notification/motion.d.ts +1 -7
  183. package/dist/modules/notification/motion.d.ts.map +1 -1
  184. package/dist/modules/notification/overlay.d.ts.map +1 -1
  185. package/dist/modules/notification/types.d.ts +9 -1
  186. package/dist/modules/notification/types.d.ts.map +1 -1
  187. package/dist/overlay-TZ6L52A5.js +9 -0
  188. package/dist/overlay-TZ6L52A5.js.map +1 -0
  189. package/dist/provider.d.ts +1 -1
  190. package/dist/provider.d.ts.map +1 -1
  191. package/dist/provider.js +6 -1968
  192. package/dist/provider.js.map +1 -1
  193. package/dist/result.js +2 -63
  194. package/dist/result.js.map +1 -1
  195. package/dist/theme.d.ts +45 -8
  196. package/dist/theme.d.ts.map +1 -1
  197. package/dist/theme.js +3 -41
  198. package/dist/theme.js.map +1 -1
  199. package/dist/tokens/index.d.ts +1 -0
  200. package/dist/tokens/index.d.ts.map +1 -1
  201. package/dist/tokens/index.js +126 -155
  202. package/dist/tokens/index.js.map +1 -1
  203. package/dist/tokens/motion-config.d.ts +44 -0
  204. package/dist/tokens/motion-config.d.ts.map +1 -0
  205. package/dist/tokens/motion.d.ts +23 -174
  206. package/dist/tokens/motion.d.ts.map +1 -1
  207. package/dist/utils/index.js +4 -82
  208. package/dist/utils/index.js.map +1 -1
  209. package/dist/utils/report.d.ts.map +1 -1
  210. package/docs/README.md +1 -0
  211. package/docs/architecture-and-rules.md +4 -3
  212. package/docs/core-engine.md +7 -10
  213. package/docs/getting-started.md +4 -2
  214. package/docs/modules/ambient.md +194 -80
  215. package/docs/modules/background.md +3 -3
  216. package/docs/modules/context-menu.md +2 -2
  217. package/docs/modules/dock.md +8 -5
  218. package/docs/modules/modal.md +2 -2
  219. package/docs/modules/notification.md +2 -2
  220. package/docs/theming.md +81 -9
  221. package/package.json +22 -5
  222. package/templates/AGENTS.md +1 -1
  223. package/templates/motion/background.ts +17 -0
  224. package/templates/motion/context-menu.ts +63 -0
  225. package/templates/motion/dock.ts +327 -0
  226. package/templates/motion/modal.ts +79 -0
  227. package/templates/motion/notification.ts +27 -0
  228. package/templates/motion/tokens.ts +47 -0
  229. package/templates/tsconfig.json +7 -0
  230. package/dist/modules/ambient/color.d.ts +0 -21
  231. package/dist/modules/ambient/color.d.ts.map +0 -1
@@ -1,831 +1,7 @@
1
1
  "use client";
2
- import { clsx } from 'clsx';
3
- import { twMerge } from 'tailwind-merge';
4
- import { createContext, useState, useRef, useCallback, useEffect, useMemo, useContext, useSyncExternalStore, use, useLayoutEffect } from 'react';
5
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
- import { createPortal } from 'react-dom';
7
- import { AnimatePresence, motion } from 'motion/react';
8
-
9
- function cn(...inputs) {
10
- return twMerge(clsx(inputs));
11
- }
12
-
13
- // src/utils/dom.ts
14
- var isBrowser = typeof window !== "undefined";
15
-
16
- // src/utils/object.ts
17
- function isObject(value) {
18
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
19
- }
20
- function report(scope, error, level = "error") {
21
- if (process.env.NODE_ENV === "production" && typeof window !== "undefined") {
22
- return;
23
- }
24
- console[level](`[${scope}]`, error);
25
- }
26
-
27
- // src/utils/user-message.ts
28
- var USER_MESSAGES = Object.freeze({
29
- generic: "Something went wrong. Please try again",
30
- network: "You appear to be offline. Check your connection and try again",
31
- timeout: "That took too long. Please try again",
32
- unauthorized: "Your session has expired. Please sign in again",
33
- forbidden: "You don't have permission to do that",
34
- notFound: "We couldn't find what you were looking for",
35
- rateLimited: "Too many attempts. Please wait a moment and try again",
36
- server: "We're having trouble on our end. Please try again in a moment"
37
- });
38
- var UserError = class extends Error {
39
- status;
40
- constructor(message, status) {
41
- super(message);
42
- this.name = "UserError";
43
- this.status = status;
44
- }
45
- };
46
- var NETWORK_FAILURE = /failed to fetch|network|load failed|fetch failed/i;
47
- function readField(source, field, type) {
48
- const value = source?.[field];
49
- return typeof value === type ? value : void 0;
50
- }
51
- function readPayloadMessage(error) {
52
- const payload = error?.payload;
53
- const message = readField(payload, "error", "string")?.trim();
54
- return message || void 0;
55
- }
56
- function toUserMessage(error, { codes, fallback = USER_MESSAGES.generic } = {}) {
57
- if (typeof error === "string") return error.trim() || fallback;
58
- if (!error || typeof error !== "object") return fallback;
59
- if (error instanceof UserError) {
60
- if (error.status === 401) return USER_MESSAGES.unauthorized;
61
- return error.message || fallback;
62
- }
63
- if (error.name === "AbortError") return fallback;
64
- const code = readField(error, "code", "string");
65
- if (code && codes?.[code]) return codes[code];
66
- const status = readField(error, "status", "number");
67
- if (status === 401) return USER_MESSAGES.unauthorized;
68
- if (status === 429) return USER_MESSAGES.rateLimited;
69
- if (status === 408 || status === 504) return USER_MESSAGES.timeout;
70
- if (status !== void 0 && status >= 500) return USER_MESSAGES.server;
71
- if (status !== void 0 && status >= 400) {
72
- const authored = readPayloadMessage(error);
73
- if (authored) return authored;
74
- if (status === 403) return USER_MESSAGES.forbidden;
75
- if (status === 404) return USER_MESSAGES.notFound;
76
- return fallback;
77
- }
78
- const isOffline = typeof navigator !== "undefined" && navigator.onLine === false;
79
- if (isOffline || NETWORK_FAILURE.test(error.message ?? "") && (error instanceof TypeError || /fetch/i.test(error.name))) {
80
- return USER_MESSAGES.network;
81
- }
82
- return fallback;
83
- }
84
-
85
- // src/utils/store.ts
86
- function freezeStoreSnapshot(state) {
87
- if (process.env.NODE_ENV === "production" || !state || typeof state !== "object") {
88
- return state;
89
- }
90
- const seen = /* @__PURE__ */ new WeakSet();
91
- const freeze = (value) => {
92
- if (seen.has(value) || Object.isFrozen(value)) return;
93
- seen.add(value);
94
- const prototype = Object.getPrototypeOf(value);
95
- if (Array.isArray(value) || prototype === Object.prototype || prototype === null) {
96
- for (const key of Reflect.ownKeys(value)) {
97
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
98
- if (descriptor && "value" in descriptor && descriptor.value !== null) {
99
- if (typeof descriptor.value === "object") freeze(descriptor.value);
100
- }
101
- }
102
- }
103
- Object.freeze(value);
104
- };
105
- freeze(state);
106
- return state;
107
- }
108
- function createStore(initialState, { freezeSnapshots = true } = {}) {
109
- const listeners = /* @__PURE__ */ new Set();
110
- const prepare = freezeSnapshots ? freezeStoreSnapshot : (state) => state;
111
- let snapshot = prepare(initialState);
112
- const publish = (nextStateOrUpdater) => {
113
- const nextState = typeof nextStateOrUpdater === "function" ? nextStateOrUpdater(snapshot) : nextStateOrUpdater;
114
- if (Object.is(snapshot, nextState)) return false;
115
- snapshot = prepare(nextState);
116
- for (const listener of listeners) {
117
- try {
118
- listener();
119
- } catch (error) {
120
- report("CoreStore subscriber", error, "warn");
121
- }
122
- }
123
- return true;
124
- };
125
- const setState = (updater) => {
126
- if (typeof updater === "function") {
127
- return publish(updater);
128
- }
129
- if (snapshot && typeof snapshot === "object" && updater && typeof updater === "object") {
130
- return publish({ ...snapshot, ...updater });
131
- }
132
- return publish(updater);
133
- };
134
- return Object.freeze({
135
- getSnapshot() {
136
- return snapshot;
137
- },
138
- publish,
139
- setState,
140
- subscribe(listener) {
141
- if (typeof listener !== "function") return () => {
142
- };
143
- listeners.add(listener);
144
- return () => listeners.delete(listener);
145
- }
146
- });
147
- }
148
- function getOrCreateGlobalContext(name, defaultValue) {
149
- const sym = /* @__PURE__ */ Symbol.for(`@omerdlw/base-framework/context/${name}`);
150
- const store = globalThis;
151
- if (!store[sym]) {
152
- store[sym] = createContext(defaultValue);
153
- }
154
- return store[sym];
155
- }
156
- function useRequiredContext(context, hookName, providerName) {
157
- const value = use(context);
158
- if (value === null) {
159
- throw new Error(`${hookName} must be used within ${providerName}`);
160
- }
161
- return value;
162
- }
163
- function useStore(store, selector = (state) => state, isEqual = Object.is) {
164
- const cacheRef = useRef({
165
- isEqual: null,
166
- selected: void 0,
167
- selector: null,
168
- snapshot: null
169
- });
170
- const getSelectedSnapshot = useCallback(() => {
171
- const snapshot = store.getSnapshot();
172
- const cache = cacheRef.current;
173
- if (cache.snapshot === snapshot && cache.selector === selector && cache.isEqual === isEqual) {
174
- return cache.selected;
175
- }
176
- const selected = selector(snapshot);
177
- if (cache.snapshot !== null && cache.isEqual === isEqual && isEqual(cache.selected, selected)) {
178
- cache.snapshot = snapshot;
179
- cache.selector = selector;
180
- return cache.selected;
181
- }
182
- cacheRef.current = {
183
- isEqual,
184
- selected,
185
- selector,
186
- snapshot
187
- };
188
- return selected;
189
- }, [isEqual, selector, store]);
190
- return useSyncExternalStore(
191
- store.subscribe,
192
- getSelectedSnapshot,
193
- getSelectedSnapshot
194
- );
195
- }
196
- var useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
197
-
198
- // src/events.ts
199
- var EVENT_TYPES = Object.freeze({
200
- API_UNAUTHORIZED: "API_UNAUTHORIZED",
201
- STATE_CHANGE: "STATE_CHANGE",
202
- API_ERROR: "API_ERROR",
203
- APP_ERROR: "APP_ERROR"
204
- });
205
- var EventEmitter = class {
206
- events = /* @__PURE__ */ new Map();
207
- debounceTimers = /* @__PURE__ */ new Map();
208
- subscribe(event, callback) {
209
- if (typeof event !== "string" || !event || typeof callback !== "function") {
210
- return () => {
211
- };
212
- }
213
- const listeners = this.events.get(event) || /* @__PURE__ */ new Set();
214
- listeners.add(callback);
215
- this.events.set(event, listeners);
216
- return () => {
217
- listeners.delete(callback);
218
- if (listeners.size === 0) this.events.delete(event);
219
- };
220
- }
221
- emit(event, payload) {
222
- const listeners = this.events.get(event);
223
- if (!listeners || listeners.size === 0) return;
224
- const snapshot = Array.from(listeners);
225
- for (const callback of snapshot) {
226
- try {
227
- callback(payload);
228
- } catch (error) {
229
- report(`Event listener (${String(event)})`, error);
230
- }
231
- }
232
- }
233
- emitDebounced(event, payload, waitMs = 100) {
234
- const existing = this.debounceTimers.get(event);
235
- if (existing) clearTimeout(existing);
236
- const timer = setTimeout(() => {
237
- this.debounceTimers.delete(event);
238
- this.emit(event, payload);
239
- }, waitMs);
240
- this.debounceTimers.set(event, timer);
241
- }
242
- cancelDebounced(event) {
243
- if (event) {
244
- const timer = this.debounceTimers.get(event);
245
- if (timer) {
246
- clearTimeout(timer);
247
- this.debounceTimers.delete(event);
248
- }
249
- } else {
250
- for (const timer of this.debounceTimers.values()) {
251
- clearTimeout(timer);
252
- }
253
- this.debounceTimers.clear();
254
- }
255
- }
256
- unsubscribeAll(event) {
257
- this.cancelDebounced(event);
258
- if (event) this.events.delete(event);
259
- else this.events.clear();
260
- }
261
- hasListeners(event) {
262
- return Boolean(this.events.get(event)?.size);
263
- }
264
- getListenerCount(event) {
265
- return this.events.get(event)?.size || 0;
266
- }
267
- getAllEvents() {
268
- return [...this.events.keys()];
269
- }
270
- };
271
- var GLOBAL_EVENTS_KEY = /* @__PURE__ */ Symbol.for("__base_framework_global_events__");
272
- var _global = globalThis;
273
- var globalEvents = _global[GLOBAL_EVENTS_KEY] ?? (_global[GLOBAL_EVENTS_KEY] = new EventEmitter());
274
-
275
- // src/hooks/use-global-event.ts
276
- function useGlobalEvent(event, callback, options) {
277
- const callbackRef = useRef(callback);
278
- const debounceTimerRef = useRef(null);
279
- useRef(0);
280
- const throttleTimerRef = useRef(null);
281
- useIsomorphicLayoutEffect(() => {
282
- callbackRef.current = callback;
283
- });
284
- const debounceMs = options?.debounceMs;
285
- const throttleMs = options?.throttleMs;
286
- useEffect(() => {
287
- if (!event) return;
288
- const events = Array.isArray(event) ? event.filter(Boolean) : [event];
289
- if (events.length === 0) return;
290
- const handler = (payload) => {
291
- callbackRef.current?.(payload);
292
- };
293
- const unsubs = events.map((ev) => globalEvents.subscribe(ev, handler));
294
- return () => {
295
- unsubs.forEach((unsub) => unsub());
296
- if (debounceTimerRef.current !== null) {
297
- clearTimeout(debounceTimerRef.current);
298
- debounceTimerRef.current = null;
299
- }
300
- if (throttleTimerRef.current !== null) {
301
- clearTimeout(throttleTimerRef.current);
302
- throttleTimerRef.current = null;
303
- }
304
- };
305
- }, [event, debounceMs, throttleMs]);
306
- }
307
- function defineModule(coreModule) {
308
- return Object.freeze({ ...coreModule });
309
- }
310
- createStore(void 0);
311
-
312
- // src/theme.tsx
313
- function defineThemeSpec(id) {
314
- return Object.freeze({ id });
315
- }
316
- var EMPTY = /* @__PURE__ */ new Map();
317
- var ThemeContext = getOrCreateGlobalContext("ThemeContext", EMPTY);
318
- function useTheme(spec) {
319
- const config = useContext(ThemeContext).get(spec.id);
320
- if (!config) {
321
- throw new Error(
322
- `Theme "${spec.id}" is missing. Ensure its theme configuration is provided to <ThemeProvider themes={[...]}> (e.g. in src/config/ or your theme setup).`
323
- );
324
- }
325
- return {
326
- slots: config.slots,
327
- styles: config.styles ?? {}
328
- };
329
- }
330
-
331
- // src/modules/notification/constants.ts
332
- var TOAST_DURATIONS = Object.freeze({
333
- DEFAULT: 2e3,
334
- SHORT: 1500
335
- });
336
- var SESSION_EXPIRED_MESSAGE = USER_MESSAGES.unauthorized;
337
- var DOCK_STACK_ELEMENT_ID = "dock-card-stack";
338
- var notificationTheme = defineThemeSpec("notification");
339
- var INITIAL_NOTIFICATION_STATE = Object.freeze({
340
- notifications: {}
341
- });
342
- var INERT_NOTIFICATION_ACTIONS = Object.freeze({
343
- dismissAllNotifications: () => {
344
- },
345
- dismissNotification: () => {
346
- },
347
- showNotification: () => null
348
- });
349
-
350
- // src/result.ts
351
- function isResult(value) {
352
- return typeof value === "object" && value !== null && "success" in value && typeof value.success === "boolean" && ("data" in value && value.success === true || "error" in value && value.success === false);
353
- }
354
-
355
- // src/modules/notification/state.ts
356
- function normalizeFeedbackText(value) {
357
- if (typeof value !== "string") return value;
358
- return value.trim().replace(/[.\s]+$/, "");
359
- }
360
- function getActiveNotification(notifications) {
361
- let active = null;
362
- for (const entry of Object.values(notifications)) {
363
- if (!active || entry.timestamp >= active.timestamp) active = entry;
364
- }
365
- return active;
366
- }
367
- function normalizeToastOptions(options) {
368
- return typeof options === "number" ? { duration: options } : options || {};
369
- }
370
- function normalizeDuration(value) {
371
- if (value === null) return null;
372
- if (value === void 0) return TOAST_DURATIONS.DEFAULT;
373
- const duration = Number(value);
374
- return Number.isFinite(duration) && duration > 0 ? duration : null;
375
- }
376
- function withDefaultDuration(duration, options) {
377
- const normalized = normalizeToastOptions(options);
378
- return {
379
- ...normalized,
380
- duration: normalized.duration !== void 0 ? normalized.duration : duration
381
- };
382
- }
383
- function isNotificationDataObject(value) {
384
- return isObject(value) && "message" in value;
385
- }
386
- function resolveMessage(message, arg) {
387
- return typeof message === "function" ? message(arg) : message;
388
- }
389
- function getOutcomeMessage(value, messages) {
390
- if (!isResult(value)) return resolveMessage(messages.success, value);
391
- return value.success ? resolveMessage(messages.success, value.data) : resolveMessage(messages.error, value.error) || toUserMessage(value.error);
392
- }
393
- function createNotificationEntry(messageOrData, options, fallbackId) {
394
- const normalizedOptions = normalizeToastOptions(options);
395
- const payload = isNotificationDataObject(messageOrData) ? { ...normalizedOptions, ...messageOrData } : { ...normalizedOptions, message: messageOrData };
396
- const normalizedMessage = normalizeFeedbackText(payload.message);
397
- if (normalizedMessage === null || normalizedMessage === void 0 || normalizedMessage === "") {
398
- return null;
399
- }
400
- const id = payload.dedupeKey || payload.id || (typeof normalizedMessage === "string" ? normalizedMessage.slice(0, 64) : fallbackId || `notification-${Date.now()}`);
401
- const entry = {
402
- dedupeKey: payload.dedupeKey,
403
- duration: payload.duration,
404
- id,
405
- message: normalizedMessage,
406
- timestamp: Date.now()
407
- };
408
- return {
409
- duration: normalizeDuration(payload.duration),
410
- entry
411
- };
412
- }
413
- var NotificationContext = getOrCreateGlobalContext(
414
- "NotificationContext",
415
- null
416
- );
417
- var NOOP_NOTIFICATION_STORE = createStore(
418
- INITIAL_NOTIFICATION_STATE
419
- );
420
- var notificationIdCounter = 0;
421
- var NotificationProvider = ({
422
- children
423
- }) => {
424
- const [store] = useState(
425
- () => createStore(INITIAL_NOTIFICATION_STATE, {
426
- freezeSnapshots: false
427
- })
428
- );
429
- const timersRef = useRef(
430
- /* @__PURE__ */ new Map()
431
- );
432
- const clearTimers = useCallback(() => {
433
- timersRef.current.forEach(clearTimeout);
434
- timersRef.current.clear();
435
- }, []);
436
- useEffect(() => clearTimers, [clearTimers]);
437
- const dismissNotification = useCallback(
438
- (id) => {
439
- clearTimeout(timersRef.current.get(id));
440
- timersRef.current.delete(id);
441
- store.publish((prev) => {
442
- if (!Object.hasOwn(prev.notifications, id)) return prev;
443
- const notifications = { ...prev.notifications };
444
- delete notifications[id];
445
- return { notifications };
446
- });
447
- },
448
- [store]
449
- );
450
- const dismissAllNotifications = useCallback(() => {
451
- clearTimers();
452
- store.publish(
453
- (prev) => Object.keys(prev.notifications).length === 0 ? prev : { notifications: {} }
454
- );
455
- }, [clearTimers, store]);
456
- const showNotification = useCallback(
457
- (messageOrData, options) => {
458
- const fallbackId = `notification-${++notificationIdCounter}`;
459
- const result = createNotificationEntry(
460
- messageOrData,
461
- options,
462
- fallbackId
463
- );
464
- if (!result) return null;
465
- const { entry, duration } = result;
466
- const { id } = entry;
467
- clearTimers();
468
- store.publish({ notifications: { [id]: entry } });
469
- if (duration) {
470
- timersRef.current.set(
471
- id,
472
- setTimeout(() => dismissNotification(id), duration)
473
- );
474
- }
475
- return id;
476
- },
477
- [clearTimers, dismissNotification, store]
478
- );
479
- const actions = useMemo(
480
- () => ({
481
- dismissAllNotifications,
482
- dismissNotification,
483
- showNotification
484
- }),
485
- [dismissAllNotifications, dismissNotification, showNotification]
486
- );
487
- const value = useMemo(
488
- () => ({ actions, store }),
489
- [actions, store]
490
- );
491
- return /* @__PURE__ */ jsx(NotificationContext, { value, children });
492
- };
493
- var toastPromiseIdCounter = 0;
494
- function useNotificationActions() {
495
- return useRequiredContext(
496
- NotificationContext,
497
- "useNotificationActions",
498
- "NotificationProvider"
499
- ).actions;
500
- }
501
- function useNotificationState() {
502
- const { store } = useRequiredContext(
503
- NotificationContext,
504
- "useNotificationState",
505
- "NotificationProvider"
506
- );
507
- return useStore(store);
508
- }
509
- function useNotification() {
510
- const actions = useNotificationActions();
511
- const state = useNotificationState();
512
- return useMemo(() => ({ ...actions, ...state }), [actions, state]);
513
- }
514
- function useOptionalNotificationState(selector, isEqual) {
515
- const ctx = useContext(NotificationContext);
516
- return useStore(
517
- ctx?.store ?? NOOP_NOTIFICATION_STORE,
518
- selector,
519
- isEqual
520
- );
521
- }
522
- function useOptionalNotificationActions() {
523
- const ctx = useContext(NotificationContext);
524
- return ctx?.actions ?? INERT_NOTIFICATION_ACTIONS;
525
- }
526
- function useNotificationVisible() {
527
- return useOptionalNotificationState(
528
- ({ notifications }) => Object.keys(notifications).length > 0
529
- );
530
- }
531
- function useToast(defaultDuration) {
532
- const { dismissAllNotifications, dismissNotification, showNotification } = useNotificationActions();
533
- const resolvedDefaultDuration = defaultDuration ?? TOAST_DURATIONS.DEFAULT;
534
- const triggerToast = useCallback(
535
- (message, options) => showNotification(
536
- message,
537
- withDefaultDuration(resolvedDefaultDuration, options)
538
- ),
539
- [resolvedDefaultDuration, showNotification]
540
- );
541
- const dismiss = useCallback(
542
- (id) => {
543
- if (id) dismissNotification(id);
544
- else dismissAllNotifications();
545
- },
546
- [dismissAllNotifications, dismissNotification]
547
- );
548
- const fromResult = useCallback(
549
- (result, messages = {}, options) => {
550
- const message = getOutcomeMessage(result, messages);
551
- if (message) triggerToast(message, options);
552
- return result;
553
- },
554
- [triggerToast]
555
- );
556
- const promise = useCallback(
557
- async (promiseOrFn, messages = {}, options) => {
558
- const normalized = normalizeToastOptions(options);
559
- const id = normalized.id || normalized.dedupeKey || `toast-promise-${++toastPromiseIdCounter}`;
560
- const sharedOptions = { ...normalized, id };
561
- if (messages.loading) {
562
- showNotification(messages.loading, {
563
- ...sharedOptions,
564
- duration: null
565
- });
566
- }
567
- try {
568
- const resolved = await (typeof promiseOrFn === "function" ? promiseOrFn() : promiseOrFn);
569
- const message = getOutcomeMessage(resolved, messages);
570
- if (message) triggerToast(message, sharedOptions);
571
- else if (messages.loading) dismiss(id);
572
- return resolved;
573
- } catch (error) {
574
- triggerToast(
575
- resolveMessage(messages.error, error) || toUserMessage(error),
576
- sharedOptions
577
- );
578
- throw error;
579
- }
580
- },
581
- [dismiss, showNotification, triggerToast]
582
- );
583
- return useMemo(
584
- () => Object.assign(
585
- (message, options) => triggerToast(message, options),
586
- { dismiss, dismissAll: dismissAllNotifications, fromResult, promise }
587
- ),
588
- [dismiss, dismissAllNotifications, fromResult, promise, triggerToast]
589
- );
590
- }
591
- var emptySubscribe = () => () => {
592
- };
593
- function NotificationListener() {
594
- const { showNotification } = useNotificationActions();
595
- useGlobalEvent(EVENT_TYPES.API_UNAUTHORIZED, (data) => {
596
- if (data?.source && data.source !== "app") return;
597
- showNotification(SESSION_EXPIRED_MESSAGE);
598
- });
599
- useGlobalEvent(
600
- EVENT_TYPES.APP_ERROR,
601
- (data) => {
602
- if (!data?.notify || !data.message) return;
603
- showNotification(data.message);
604
- }
605
- );
606
- useGlobalEvent(
607
- EVENT_TYPES.STATE_CHANGE,
608
- (data) => {
609
- if (!data?.notify || !data.message) return;
610
- showNotification(data.message);
611
- }
612
- );
613
- return null;
614
- }
615
- function useNotificationContainerModel() {
616
- const { notifications } = useNotificationState();
617
- const { dismissNotification } = useNotificationActions();
618
- const isHydrated = useSyncExternalStore(
619
- emptySubscribe,
620
- () => true,
621
- () => false
622
- );
623
- const activeEntry = useMemo(
624
- () => getActiveNotification(notifications),
625
- [notifications]
626
- );
627
- const theme = useTheme(notificationTheme);
628
- return { dismissNotification, isHydrated, activeEntry, theme };
629
- }
630
-
631
- // src/tokens/motion.ts
632
- var DURATION_TOKENS = Object.freeze({
633
- INSTANT: 0.08,
634
- MICRO: 0.18,
635
- FAST: 0.28,
636
- BASE: 0.36,
637
- MODERATE: 0.44,
638
- SLOW: 0.58,
639
- CINEMATIC: 0.86
640
- });
641
- var EASING_CURVES = Object.freeze({
642
- OUT_EXPO: [0.16, 1, 0.3, 1],
643
- OUT_QUART: [0.25, 1, 0.5, 1],
644
- OUT_QUINT: [0.22, 1, 0.36, 1],
645
- IN_OUT_CUBIC: [0.65, 0, 0.35, 1],
646
- IN_CUBIC: [0.5, 0, 1, 1],
647
- OUT_BACK: [0.34, 1.56, 0.64, 1]
648
- });
649
- var MOTION_EASINGS = Object.freeze({
650
- ENTER: EASING_CURVES.OUT_QUART,
651
- ENTER_EMPHASIZED: EASING_CURVES.OUT_EXPO,
652
- EXIT: EASING_CURVES.IN_CUBIC
653
- });
654
- Object.freeze({
655
- MICRO: Object.freeze({
656
- distance: 4,
657
- duration: DURATION_TOKENS.MICRO,
658
- ease: MOTION_EASINGS.ENTER_EMPHASIZED,
659
- scaleDelta: 8e-3
660
- }),
661
- FAST: Object.freeze({
662
- distance: 9,
663
- duration: DURATION_TOKENS.FAST,
664
- ease: MOTION_EASINGS.ENTER_EMPHASIZED,
665
- scaleDelta: 0.012
666
- }),
667
- STANDARD: Object.freeze({
668
- distance: 18,
669
- duration: DURATION_TOKENS.MODERATE,
670
- ease: MOTION_EASINGS.ENTER,
671
- scaleDelta: 0.018
672
- }),
673
- SURFACE: Object.freeze({
674
- distance: 28,
675
- duration: DURATION_TOKENS.SLOW,
676
- ease: MOTION_EASINGS.ENTER_EMPHASIZED,
677
- scaleDelta: 0.024
678
- })
679
- });
680
- Object.freeze({
681
- duration: DURATION_TOKENS.INSTANT,
682
- ease: "linear"
683
- });
684
-
685
- // src/modules/notification/motion.ts
686
- function toGpuTransform(y = 0, scale = 1) {
687
- return `translate3d(0, ${Math.round(y)}px, 0) scale(${Math.round(scale * 1e3) / 1e3})`;
688
- }
689
- var NOTIFICATION_COMPOSITOR_STYLE = Object.freeze({
690
- WebkitBackfaceVisibility: "hidden",
691
- WebkitFontSmoothing: "antialiased",
692
- backfaceVisibility: "hidden",
693
- transform: "translateZ(0)",
694
- willChange: "transform, opacity, filter"
695
- });
696
- var NOTIFICATION_TRANSITION = Object.freeze({
697
- duration: DURATION_TOKENS.MODERATE,
698
- ease: EASING_CURVES.OUT_EXPO,
699
- type: "tween"
700
- });
701
- var NOTIFICATION_EXIT_TRANSITION = Object.freeze({
702
- duration: DURATION_TOKENS.FAST,
703
- ease: EASING_CURVES.IN_CUBIC,
704
- type: "tween"
705
- });
706
- var toastVariants = Object.freeze({
707
- exit: {
708
- opacity: 0,
709
- transform: toGpuTransform(-6, 0.98),
710
- transition: NOTIFICATION_EXIT_TRANSITION
711
- },
712
- hidden: {
713
- opacity: 0,
714
- transform: toGpuTransform(-10, 0.96)
715
- },
716
- visible: {
717
- opacity: 1,
718
- transform: toGpuTransform(0, 1),
719
- transition: NOTIFICATION_TRANSITION
720
- }
721
- });
722
- function Toast({
723
- className,
724
- entry,
725
- messageClassName,
726
- onDismiss,
727
- polite,
728
- style
729
- }) {
730
- return /* @__PURE__ */ jsx(
731
- motion.div,
732
- {
733
- role: "alert",
734
- "aria-atomic": "true",
735
- "aria-live": polite ? "polite" : void 0,
736
- "aria-keyshortcuts": "Escape",
737
- tabIndex: 0,
738
- variants: toastVariants,
739
- initial: "hidden",
740
- animate: "visible",
741
- exit: "exit",
742
- transition: NOTIFICATION_TRANSITION,
743
- style: { ...NOTIFICATION_COMPOSITOR_STYLE, ...style },
744
- className,
745
- onClick: (event) => {
746
- event.stopPropagation();
747
- onDismiss();
748
- },
749
- onKeyDown: (event) => {
750
- if (event.key !== "Escape") return;
751
- event.preventDefault();
752
- event.stopPropagation();
753
- onDismiss();
754
- },
755
- children: /* @__PURE__ */ jsx("div", { className: messageClassName, children: entry.message })
756
- }
757
- );
758
- }
759
- function NotificationContainer() {
760
- const { dismissNotification, isHydrated, activeEntry, theme } = useNotificationContainerModel();
761
- if (!isHydrated) return null;
762
- const dockElement = document.getElementById(DOCK_STACK_ELEMENT_ID);
763
- const toast = (className, polite) => /* @__PURE__ */ jsx(AnimatePresence, { mode: "wait", children: activeEntry && /* @__PURE__ */ jsx(
764
- Toast,
765
- {
766
- className,
767
- entry: activeEntry,
768
- messageClassName: theme.slots.toastMessage,
769
- polite,
770
- style: theme.styles.toast,
771
- onDismiss: () => dismissNotification(activeEntry.id)
772
- },
773
- activeEntry.id
774
- ) });
775
- if (dockElement) {
776
- return createPortal(
777
- toast(cn(theme.slots.toast, theme.slots.toastDocked), true),
778
- dockElement
779
- );
780
- }
781
- return createPortal(
782
- /* @__PURE__ */ jsx(
783
- "div",
784
- {
785
- "aria-atomic": "true",
786
- "aria-live": "polite",
787
- className: theme.slots.layer,
788
- style: theme.styles.layer,
789
- children: toast(theme.slots.toast)
790
- }
791
- ),
792
- document.body
793
- );
794
- }
795
- function NotificationLayer() {
796
- return /* @__PURE__ */ jsxs(Fragment, { children: [
797
- /* @__PURE__ */ jsx(NotificationListener, {}),
798
- /* @__PURE__ */ jsx(NotificationContainer, {})
799
- ] });
800
- }
801
-
802
- // src/modules/notification/module.tsx
803
- function selectToastDuration(config) {
804
- const notification = config.notification;
805
- if (typeof notification === "number") return notification;
806
- return notification?.duration ?? null;
807
- }
808
- function useNotificationPage(duration, page) {
809
- const toast = useToast(duration);
810
- return useMemo(
811
- () => ({
812
- set: (notification) => page.set({ notification }),
813
- toast
814
- }),
815
- [page, toast]
816
- );
817
- }
818
- var notificationModule = defineModule({
819
- id: "notification",
820
- context: NotificationContext,
821
- Provider: NotificationProvider,
822
- Overlay: NotificationLayer,
823
- page: {
824
- select: selectToastDuration,
825
- use: useNotificationPage
826
- }
827
- });
828
-
829
- export { DOCK_STACK_ELEMENT_ID, INERT_NOTIFICATION_ACTIONS, INITIAL_NOTIFICATION_STATE, NOOP_NOTIFICATION_STORE, NotificationContext, NotificationListener, NotificationProvider, SESSION_EXPIRED_MESSAGE, TOAST_DURATIONS, createNotificationEntry, getActiveNotification, getOutcomeMessage, isNotificationDataObject, normalizeDuration, normalizeFeedbackText, normalizeToastOptions, notificationModule, notificationTheme, useNotification, useNotificationActions, useNotificationContainerModel, useNotificationState, useNotificationVisible, useOptionalNotificationActions, useOptionalNotificationState, useToast, withDefaultDuration };
2
+ export { DOCK_STACK_ELEMENT_ID, INERT_NOTIFICATION_ACTIONS, INITIAL_NOTIFICATION_STATE, NOOP_NOTIFICATION_STORE, NotificationContext, NotificationListener, NotificationProvider, SESSION_EXPIRED_MESSAGE, TOAST_DURATIONS, createNotificationEntry, getActiveNotification, getOutcomeMessage, isNotificationDataObject, normalizeDuration, normalizeFeedbackText, normalizeToastOptions, notificationModule, notificationTheme, useNotification, useNotificationActions, useNotificationContainerModel, useNotificationState, useNotificationVisible, useOptionalNotificationActions, useOptionalNotificationState, useToast, withDefaultDuration } from '../../chunk-SYAVGTOX.js';
3
+ import '../../chunk-7TAVYJ3A.js';
4
+ import '../../chunk-GF7TUX5I.js';
5
+ import '../../chunk-TV3WEF5G.js';
830
6
  //# sourceMappingURL=index.js.map
831
7
  //# sourceMappingURL=index.js.map