@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,685 +1,8 @@
1
1
  "use client";
2
- import React, { createContext, useContext, useRef, useCallback, useEffect } from 'react';
3
- import { usePathname } from 'next/navigation';
4
- import { Icon as Icon$1 } from '@iconify-icon/react';
5
- import { jsx, jsxs } from 'react/jsx-runtime';
6
-
7
- // src/error/constants.ts
8
- var ERROR_MESSAGES = Object.freeze({
9
- GLOBAL_TITLE: "Something went wrong",
10
- GLOBAL_MSG: "We ran into an unexpected problem. Please try again",
11
- MODULE_TITLE: "Something went wrong",
12
- MODULE_MSG: "This part of the app isn't working right now. Please try again",
13
- COMPONENT_MSG: "This section couldn't be loaded. Please try again",
14
- FALLBACK_TITLE: "Something went wrong",
15
- FALLBACK_MSG: "This section couldn't be loaded. Please try again"
16
- });
17
- var MAX_CONTEXT = 10;
18
- var MAX_FINGERPRINTS = 100;
19
- var DEFAULT_DEDUPE_WINDOW = 6e4;
20
- var ERROR_LISTENER_CONFIG = Object.freeze({
21
- maxErrors: 10,
22
- throttle: 2e3,
23
- ignored: Object.freeze([
24
- /ResizeObserver loop/i,
25
- /Network request failed/i,
26
- /Loading chunk/i,
27
- /Unexpected end of input/i,
28
- /Failed to fetch/i,
29
- /Script error/i,
30
- /HTTP\s*404/i
31
- ])
32
- });
33
-
34
- // src/error/utils.ts
35
- var IS_BROWSER = typeof window !== "undefined";
36
- var HAS_NAVIGATOR = typeof navigator !== "undefined";
37
- var getRuntimePath = () => typeof window !== "undefined" ? window.location.pathname : null;
38
- var getUserAgent = () => typeof navigator !== "undefined" ? navigator.userAgent : null;
39
- function createErrorContext({
40
- errorInfo,
41
- name,
42
- title,
43
- variant
44
- }) {
45
- return {
46
- componentStack: errorInfo?.componentStack || null,
47
- route: getRuntimePath(),
48
- userAgent: getUserAgent(),
49
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
50
- name: name || title || "ErrorBoundary",
51
- variant: variant || "default",
52
- source: "ErrorBoundary"
53
- };
54
- }
55
- function normalizeSampleRate(value) {
56
- const sampleRate = Number(value);
57
- return Number.isFinite(sampleRate) ? Math.min(1, Math.max(0, sampleRate)) : 1;
58
- }
59
- function normalizeDedupeWindow(value) {
60
- const dedupeWindow = Number(value);
61
- return Number.isFinite(dedupeWindow) ? Math.max(0, dedupeWindow) : DEFAULT_DEDUPE_WINDOW;
62
- }
63
- function getBrowserEnvironment(route) {
64
- return {
65
- route: route || (IS_BROWSER ? window.location.pathname : null),
66
- userAgent: HAS_NAVIGATOR ? navigator.userAgent : null,
67
- platform: HAS_NAVIGATOR ? navigator.platform : null,
68
- language: HAS_NAVIGATOR ? navigator.language : null,
69
- online: HAS_NAVIGATOR ? navigator.onLine : true,
70
- url: IS_BROWSER ? window.location.href : null
71
- };
72
- }
73
- function fingerprint(error, context = {}) {
74
- const stackTop = typeof context.componentStack === "string" ? context.componentStack.split("\n").find(Boolean) || "" : "";
75
- const errObj = error;
76
- const errorMessage = (errObj?.message || String(error || "")).slice(0, 100);
77
- const errorName = errObj?.name || "UnknownError";
78
- const route = context.route || "";
79
- return [stackTop, errorMessage, errorName, route].filter(Boolean).join("::");
80
- }
81
- function createReport(error, {
82
- context = {},
83
- tags = {}
84
- } = {}) {
85
- const errObj = error;
86
- return {
87
- error: {
88
- message: errObj?.message || String(error),
89
- stack: errObj?.stack || null,
90
- name: errObj?.name || "UnknownError"
91
- },
92
- fingerprint: fingerprint(error, context),
93
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
94
- environment: getBrowserEnvironment(context.route),
95
- componentStack: context.componentStack || null,
96
- context,
97
- tags
98
- };
99
- }
100
- function getErrorMessage(error) {
101
- if (!error) return "";
102
- if (typeof error === "string") return error.trim();
103
- if (error instanceof Error) return error.message.trim();
104
- const errObj = error;
105
- return String(errObj?.message || errObj?.toString?.() || error).trim();
106
- }
107
- function shouldIgnoreError(error) {
108
- if (!error) return true;
109
- const errWithNotFound = error;
110
- if (typeof errWithNotFound?.isNotFound === "function" && errWithNotFound.isNotFound()) {
111
- return true;
112
- }
113
- const message = getErrorMessage(error);
114
- return ERROR_LISTENER_CONFIG.ignored.some((pattern) => pattern.test(message));
115
- }
116
-
117
- // src/error/reporter.ts
118
- var IS_PRODUCTION = process.env.NODE_ENV === "production";
119
- var IS_BROWSER2 = typeof window !== "undefined";
120
- var ErrorReporter = class {
121
- handlers = [];
122
- context = {};
123
- tags = {};
124
- seen = /* @__PURE__ */ new Set();
125
- enabled;
126
- sampleRate;
127
- beforeSend;
128
- dedupeWindow;
129
- constructor(options = {}) {
130
- this.enabled = options.enabled ?? true;
131
- this.sampleRate = normalizeSampleRate(options.sampleRate ?? 1);
132
- this.beforeSend = options.beforeSend || null;
133
- this.dedupeWindow = normalizeDedupeWindow(
134
- options.deduplicateWindow ?? DEFAULT_DEDUPE_WINDOW
135
- );
136
- }
137
- addHandler(handler) {
138
- if (typeof handler?.handle === "function") {
139
- this.handlers.push(handler);
140
- }
141
- return this;
142
- }
143
- removeHandler(name) {
144
- this.handlers = this.handlers.filter((handler) => handler.name !== name);
145
- return this;
146
- }
147
- setContext(key, value) {
148
- if (Object.hasOwn(this.context, key) || Object.keys(this.context).length < MAX_CONTEXT) {
149
- this.context[key] = value;
150
- }
151
- return this;
152
- }
153
- setTag(key, value) {
154
- this.tags[key] = String(value);
155
- return this;
156
- }
157
- captureError(error, extraContext = {}) {
158
- if (!this.enabled || Math.random() > this.sampleRate) return;
159
- this.ensureDefaultHandlers();
160
- const context = { ...this.context, ...extraContext };
161
- let report2 = createReport(error, { context, tags: { ...this.tags } });
162
- const dedupeKey = report2.fingerprint;
163
- if (this.seen.has(dedupeKey)) return;
164
- if (this.seen.size >= MAX_FINGERPRINTS) {
165
- const first = this.seen.keys().next().value;
166
- if (first) this.seen.delete(first);
167
- }
168
- this.seen.add(dedupeKey);
169
- setTimeout(() => this.seen.delete(dedupeKey), this.dedupeWindow);
170
- if (typeof this.beforeSend === "function") {
171
- try {
172
- const transformed = this.beforeSend(report2);
173
- if (!transformed) return;
174
- report2 = transformed;
175
- } catch {
176
- }
177
- }
178
- this.handlers.forEach((handler) => {
179
- try {
180
- handler.handle(report2);
181
- } catch {
182
- }
183
- });
184
- return report2;
185
- }
186
- captureMessage(message, level = "info", context = {}) {
187
- const error = new Error(message);
188
- error.name = "Message";
189
- return this.captureError(error, { ...context, level });
190
- }
191
- ensureDefaultHandlers() {
192
- if (this.handlers.length || !IS_BROWSER2) return;
193
- this.handlers.push(createConsoleHandler());
194
- if (window.Sentry) {
195
- const sentryHandler = createSentryHandler(window.Sentry);
196
- if (sentryHandler.name === "sentry") {
197
- this.handlers.push(sentryHandler);
198
- }
199
- }
200
- }
201
- };
202
- var instance = null;
203
- function getErrorReporter(options = {}) {
204
- if (!instance) {
205
- instance = new ErrorReporter(options);
206
- }
207
- return instance;
208
- }
209
- function createConsoleHandler() {
210
- return {
211
- name: "console",
212
- handle(report2) {
213
- if (IS_PRODUCTION) return;
214
- console.error("[ErrorReporter]", {
215
- error: report2.error.message,
216
- fingerprint: report2.fingerprint,
217
- route: report2.environment.route
218
- });
219
- }
220
- };
221
- }
222
- function createSentryHandler(Sentry) {
223
- const sentryObj = Sentry;
224
- if (!sentryObj || typeof sentryObj.captureException !== "function" || typeof sentryObj.withScope !== "function") {
225
- return createConsoleHandler();
226
- }
227
- return {
228
- name: "sentry",
229
- handle(report2) {
230
- sentryObj.withScope((scope) => {
231
- if (report2.fingerprint) scope.setFingerprint([report2.fingerprint]);
232
- if (report2.user) scope.setUser(report2.user);
233
- if (report2.tags && typeof report2.tags === "object") {
234
- Object.entries(report2.tags).forEach(
235
- ([key, value]) => scope.setTag(key, String(value))
236
- );
237
- }
238
- if (report2.environment)
239
- scope.setContext("environment", report2.environment);
240
- if (report2.context) scope.setContext("custom", report2.context);
241
- if (report2.componentStack)
242
- scope.setExtra("componentStack", report2.componentStack);
243
- const error = new Error(report2.error.message);
244
- error.name = report2.error.name || "Error";
245
- error.stack = report2.error.stack || void 0;
246
- sentryObj.captureException(error);
247
- });
248
- }
249
- };
250
- }
251
-
252
- // src/utils/report.ts
253
- var sink = null;
254
- function report(scope, error, level = "error") {
255
- if (sink) {
256
- try {
257
- sink(scope, error, level);
258
- return;
259
- } catch {
260
- }
261
- }
262
- if (process.env.NODE_ENV === "production" && typeof window !== "undefined") {
263
- return;
264
- }
265
- console[level](`[${scope}]`, error);
266
- }
267
- function setReportSink(next) {
268
- sink = next;
269
- return () => {
270
- if (sink === next) sink = null;
271
- };
272
- }
273
-
274
- // src/events.ts
275
- var EVENT_TYPES = Object.freeze({
276
- API_UNAUTHORIZED: "API_UNAUTHORIZED",
277
- STATE_CHANGE: "STATE_CHANGE",
278
- API_ERROR: "API_ERROR",
279
- APP_ERROR: "APP_ERROR"
280
- });
281
- var EventEmitter = class {
282
- events = /* @__PURE__ */ new Map();
283
- debounceTimers = /* @__PURE__ */ new Map();
284
- subscribe(event, callback) {
285
- if (typeof event !== "string" || !event || typeof callback !== "function") {
286
- return () => {
287
- };
288
- }
289
- const listeners = this.events.get(event) || /* @__PURE__ */ new Set();
290
- listeners.add(callback);
291
- this.events.set(event, listeners);
292
- return () => {
293
- listeners.delete(callback);
294
- if (listeners.size === 0) this.events.delete(event);
295
- };
296
- }
297
- emit(event, payload) {
298
- const listeners = this.events.get(event);
299
- if (!listeners || listeners.size === 0) return;
300
- const snapshot = Array.from(listeners);
301
- for (const callback of snapshot) {
302
- try {
303
- callback(payload);
304
- } catch (error) {
305
- report(`Event listener (${String(event)})`, error);
306
- }
307
- }
308
- }
309
- emitDebounced(event, payload, waitMs = 100) {
310
- const existing = this.debounceTimers.get(event);
311
- if (existing) clearTimeout(existing);
312
- const timer = setTimeout(() => {
313
- this.debounceTimers.delete(event);
314
- this.emit(event, payload);
315
- }, waitMs);
316
- this.debounceTimers.set(event, timer);
317
- }
318
- cancelDebounced(event) {
319
- if (event) {
320
- const timer = this.debounceTimers.get(event);
321
- if (timer) {
322
- clearTimeout(timer);
323
- this.debounceTimers.delete(event);
324
- }
325
- } else {
326
- for (const timer of this.debounceTimers.values()) {
327
- clearTimeout(timer);
328
- }
329
- this.debounceTimers.clear();
330
- }
331
- }
332
- unsubscribeAll(event) {
333
- this.cancelDebounced(event);
334
- if (event) this.events.delete(event);
335
- else this.events.clear();
336
- }
337
- hasListeners(event) {
338
- return Boolean(this.events.get(event)?.size);
339
- }
340
- getListenerCount(event) {
341
- return this.events.get(event)?.size || 0;
342
- }
343
- getAllEvents() {
344
- return [...this.events.keys()];
345
- }
346
- };
347
- var GLOBAL_EVENTS_KEY = /* @__PURE__ */ Symbol.for("__base_framework_global_events__");
348
- var _global = globalThis;
349
- var globalEvents = _global[GLOBAL_EVENTS_KEY] ?? (_global[GLOBAL_EVENTS_KEY] = new EventEmitter());
350
- function Icon({
351
- className = "center",
352
- color,
353
- icon,
354
- onClick,
355
- size = 20,
356
- style,
357
- ...props
358
- }) {
359
- return /* @__PURE__ */ jsx(
360
- Icon$1,
361
- {
362
- className,
363
- height: size,
364
- icon,
365
- onClick,
366
- style: { color, ...style },
367
- width: size,
368
- ...props
369
- }
370
- );
371
- }
372
- Icon.displayName = "Icon";
373
- function Button({
374
- ref,
375
- children,
376
- className,
377
- disabled = false,
378
- loading = false,
379
- type = "button",
380
- ...props
381
- }) {
382
- return /* @__PURE__ */ jsx(
383
- "button",
384
- {
385
- ref,
386
- type,
387
- disabled: disabled || loading,
388
- "aria-busy": loading ? true : void 0,
389
- className,
390
- ...props,
391
- children
392
- }
393
- );
394
- }
395
- Button.displayName = "Button";
396
- function getOrCreateGlobalContext(name, defaultValue) {
397
- const sym = /* @__PURE__ */ Symbol.for(`@omerdlw/base-framework/context/${name}`);
398
- const store = globalThis;
399
- if (!store[sym]) {
400
- store[sym] = createContext(defaultValue);
401
- }
402
- return store[sym];
403
- }
404
-
405
- // src/utils/user-message.ts
406
- var USER_MESSAGES = Object.freeze({
407
- generic: "Something went wrong. Please try again",
408
- network: "You appear to be offline. Check your connection and try again",
409
- timeout: "That took too long. Please try again",
410
- unauthorized: "Your session has expired. Please sign in again",
411
- forbidden: "You don't have permission to do that",
412
- notFound: "We couldn't find what you were looking for",
413
- rateLimited: "Too many attempts. Please wait a moment and try again",
414
- server: "We're having trouble on our end. Please try again in a moment"
415
- });
416
- var UserError = class extends Error {
417
- status;
418
- constructor(message, status) {
419
- super(message);
420
- this.name = "UserError";
421
- this.status = status;
422
- }
423
- };
424
- var NETWORK_FAILURE = /failed to fetch|network|load failed|fetch failed/i;
425
- function readField(source, field, type) {
426
- const value = source?.[field];
427
- return typeof value === type ? value : void 0;
428
- }
429
- function readPayloadMessage(error) {
430
- const payload = error?.payload;
431
- const message = readField(payload, "error", "string")?.trim();
432
- return message || void 0;
433
- }
434
- function toUserMessage(error, { codes, fallback = USER_MESSAGES.generic } = {}) {
435
- if (typeof error === "string") return error.trim() || fallback;
436
- if (!error || typeof error !== "object") return fallback;
437
- if (error instanceof UserError) {
438
- if (error.status === 401) return USER_MESSAGES.unauthorized;
439
- return error.message || fallback;
440
- }
441
- if (error.name === "AbortError") return fallback;
442
- const code = readField(error, "code", "string");
443
- if (code && codes?.[code]) return codes[code];
444
- const status = readField(error, "status", "number");
445
- if (status === 401) return USER_MESSAGES.unauthorized;
446
- if (status === 429) return USER_MESSAGES.rateLimited;
447
- if (status === 408 || status === 504) return USER_MESSAGES.timeout;
448
- if (status !== void 0 && status >= 500) return USER_MESSAGES.server;
449
- if (status !== void 0 && status >= 400) {
450
- const authored = readPayloadMessage(error);
451
- if (authored) return authored;
452
- if (status === 403) return USER_MESSAGES.forbidden;
453
- if (status === 404) return USER_MESSAGES.notFound;
454
- return fallback;
455
- }
456
- const isOffline = typeof navigator !== "undefined" && navigator.onLine === false;
457
- if (isOffline || NETWORK_FAILURE.test(error.message ?? "") && (error instanceof TypeError || /fetch/i.test(error.name))) {
458
- return USER_MESSAGES.network;
459
- }
460
- return fallback;
461
- }
462
-
463
- // src/theme.tsx
464
- function defineThemeSpec(id) {
465
- return Object.freeze({ id });
466
- }
467
- var EMPTY = /* @__PURE__ */ new Map();
468
- var ThemeContext = getOrCreateGlobalContext("ThemeContext", EMPTY);
469
- function useTheme(spec) {
470
- const config = useContext(ThemeContext).get(spec.id);
471
- if (!config) {
472
- throw new Error(
473
- `Theme "${spec.id}" is missing. Ensure its theme configuration is provided to <ThemeProvider themes={[...]}> (e.g. in src/config/ or your theme setup).`
474
- );
475
- }
476
- return {
477
- slots: config.slots,
478
- styles: config.styles ?? {}
479
- };
480
- }
481
-
482
- // src/error/theme.ts
483
- var errorTheme = defineThemeSpec("error");
484
- var ActionButton = Button;
485
- function DefaultErrorFallback({
486
- error,
487
- message,
488
- resetError,
489
- title
490
- }) {
491
- const theme = useTheme(errorTheme);
492
- return /* @__PURE__ */ jsxs("div", { className: theme.slots.screen, children: [
493
- /* @__PURE__ */ jsx("div", { className: theme.slots.icon, children: /* @__PURE__ */ jsx(Icon, { icon: "solar:danger-circle-bold", size: 30 }) }),
494
- /* @__PURE__ */ jsx("h3", { className: theme.slots.title, children: message || toUserMessage(error, { fallback: ERROR_MESSAGES.FALLBACK_MSG }) }),
495
- /* @__PURE__ */ jsx(
496
- ActionButton,
497
- {
498
- className: theme.slots.retryButton,
499
- onClick: resetError,
500
- type: "button",
501
- children: "Try again"
502
- }
503
- )
504
- ] });
505
- }
506
- var ErrorBoundaryCore = class extends React.Component {
507
- constructor(props) {
508
- super(props);
509
- this.state = {
510
- error: null,
511
- errorInfo: null,
512
- hasError: false,
513
- lastResetKey: props.resetKey
514
- };
515
- }
516
- static getDerivedStateFromError(error) {
517
- return { error, hasError: true };
518
- }
519
- static getDerivedStateFromProps(props, state) {
520
- if (props.resetKey !== state.lastResetKey) {
521
- return {
522
- error: null,
523
- errorInfo: null,
524
- hasError: false,
525
- lastResetKey: props.resetKey
526
- };
527
- }
528
- return null;
529
- }
530
- componentDidCatch(error, errorInfo) {
531
- this.setState({ errorInfo });
532
- const { message, name, onError, silent, title, variant } = this.props;
533
- const context = createErrorContext({ errorInfo, name, title, variant });
534
- try {
535
- onError?.(error, errorInfo, context);
536
- } catch (callbackError) {
537
- report("ErrorBoundary onError callback", callbackError, "warn");
538
- }
539
- if (!silent) {
540
- globalEvents.emit(EVENT_TYPES.APP_ERROR, {
541
- error,
542
- errorInfo,
543
- message: message || toUserMessage(error),
544
- resetError: this.resetError
545
- });
546
- }
547
- try {
548
- const reporter = getErrorReporter();
549
- reporter?.captureError?.(error, context);
550
- } catch (reportingError) {
551
- report("ErrorBoundary reporting", reportingError, "warn");
552
- }
553
- }
554
- resetError = () => {
555
- this.setState({
556
- error: null,
557
- errorInfo: null,
558
- hasError: false
559
- });
560
- this.props.onReset?.();
561
- };
562
- render() {
563
- if (!this.state.hasError) return this.props.children;
564
- const { fallback, message, title } = this.props;
565
- const { error } = this.state;
566
- if (typeof fallback === "function") {
567
- return fallback({ error, resetError: this.resetError });
568
- }
569
- if (fallback) {
570
- return fallback;
571
- }
572
- return /* @__PURE__ */ jsx(
573
- DefaultErrorFallback,
574
- {
575
- error,
576
- message,
577
- resetError: this.resetError,
578
- title
579
- }
580
- );
581
- }
582
- };
583
- function GlobalError({ children, fallback, onReset }) {
584
- const pathname = usePathname();
585
- return /* @__PURE__ */ jsx(
586
- ErrorBoundaryCore,
587
- {
588
- fallback,
589
- message: ERROR_MESSAGES.GLOBAL_MSG,
590
- onReset,
591
- resetKey: pathname,
592
- title: ERROR_MESSAGES.GLOBAL_TITLE,
593
- variant: "full",
594
- children
595
- }
596
- );
597
- }
598
- function ModuleError({
599
- children,
600
- fallback,
601
- name,
602
- onReset
603
- }) {
604
- return /* @__PURE__ */ jsx(
605
- ErrorBoundaryCore,
606
- {
607
- fallback,
608
- message: ERROR_MESSAGES.MODULE_MSG,
609
- name,
610
- onReset,
611
- title: name ? `${name} Error` : ERROR_MESSAGES.MODULE_TITLE,
612
- variant: "module",
613
- children
614
- }
615
- );
616
- }
617
- function ComponentError({
618
- children,
619
- fallback,
620
- message,
621
- onReset
622
- }) {
623
- return /* @__PURE__ */ jsx(
624
- ErrorBoundaryCore,
625
- {
626
- fallback,
627
- message: message || ERROR_MESSAGES.COMPONENT_MSG,
628
- onReset,
629
- variant: "inline",
630
- children
631
- }
632
- );
633
- }
634
- function GlobalErrorListener() {
635
- const lastError = useRef(0);
636
- const count = useRef(0);
637
- const shown = useRef(/* @__PURE__ */ new Set());
638
- const handleError = useCallback((error, source = "runtime") => {
639
- if (shouldIgnoreError(error)) return;
640
- const now = Date.now();
641
- if (count.current >= ERROR_LISTENER_CONFIG.maxErrors) return;
642
- if (now - lastError.current < ERROR_LISTENER_CONFIG.throttle) return;
643
- const message = getErrorMessage(error);
644
- const key = message || String(error);
645
- if (shown.current.has(key)) return;
646
- shown.current.add(key);
647
- lastError.current = now;
648
- count.current += 1;
649
- try {
650
- const reporter = getErrorReporter();
651
- reporter?.captureError?.(error, {
652
- globalListener: true,
653
- source
654
- });
655
- } catch (reportingError) {
656
- report("GlobalError reporting", reportingError, "warn");
657
- }
658
- globalEvents.emit(EVENT_TYPES.APP_ERROR, {
659
- error,
660
- message: toUserMessage(error)
661
- });
662
- }, []);
663
- useEffect(() => {
664
- const removeSink = setReportSink((scope, error, level) => {
665
- try {
666
- getErrorReporter().captureError(error, { level, scope });
667
- } catch {
668
- }
669
- });
670
- const onError = (event) => handleError(event.error || event.message, "window.onerror");
671
- const onRejection = (event) => handleError(event.reason, "unhandledrejection");
672
- window.addEventListener("error", onError);
673
- window.addEventListener("unhandledrejection", onRejection);
674
- return () => {
675
- removeSink();
676
- window.removeEventListener("error", onError);
677
- window.removeEventListener("unhandledrejection", onRejection);
678
- };
679
- }, [handleError]);
680
- return null;
681
- }
682
-
683
- export { ComponentError, DEFAULT_DEDUPE_WINDOW, ERROR_LISTENER_CONFIG, ERROR_MESSAGES, ErrorBoundaryCore, GlobalError, GlobalErrorListener, MAX_CONTEXT, MAX_FINGERPRINTS, ModuleError, createConsoleHandler, createErrorContext, createReport, createSentryHandler, errorTheme, fingerprint, getBrowserEnvironment, getErrorMessage, getErrorReporter, getRuntimePath, getUserAgent, normalizeDedupeWindow, normalizeSampleRate, shouldIgnoreError };
2
+ export { ComponentError, DEFAULT_DEDUPE_WINDOW, ERROR_LISTENER_CONFIG, ERROR_MESSAGES, ErrorBoundaryCore, GlobalError, GlobalErrorListener, MAX_CONTEXT, MAX_FINGERPRINTS, ModuleError, createConsoleHandler, createErrorContext, createReport, createSentryHandler, errorTheme, fingerprint, getBrowserEnvironment, getErrorMessage, getErrorReporter, getRuntimePath, getUserAgent, normalizeDedupeWindow, normalizeSampleRate, shouldIgnoreError } from '../chunk-JELG4JLT.js';
3
+ import '../chunk-7TAVYJ3A.js';
4
+ import '../chunk-GF7TUX5I.js';
5
+ import '../chunk-TV3WEF5G.js';
6
+ import '../chunk-3BUP64Q6.js';
684
7
  //# sourceMappingURL=index.js.map
685
8
  //# sourceMappingURL=index.js.map