arckode-ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,507 @@
1
+ import { c as le, g as de, n as ye, u as me } from "./router-DhUDyb8s.js";
2
+ let y = null;
3
+ function j(e) {
4
+ y !== null && e.add(y);
5
+ }
6
+ function O(e) {
7
+ for (const n of new Set(e))
8
+ n();
9
+ }
10
+ function R(e) {
11
+ let n = e;
12
+ const t = /* @__PURE__ */ new Set();
13
+ return {
14
+ get value() {
15
+ return j(t), n;
16
+ },
17
+ set value(r) {
18
+ Object.is(r, n) || (n = r, O(t));
19
+ },
20
+ get peek() {
21
+ return n;
22
+ }
23
+ };
24
+ }
25
+ function ee(e) {
26
+ let n, t = !0;
27
+ const r = /* @__PURE__ */ new Set();
28
+ function u() {
29
+ t = !0, O(r);
30
+ }
31
+ return {
32
+ get value() {
33
+ if (j(r), t) {
34
+ const o = y;
35
+ y = u;
36
+ try {
37
+ n = e();
38
+ } finally {
39
+ y = o;
40
+ }
41
+ t = !1;
42
+ }
43
+ return n;
44
+ }
45
+ };
46
+ }
47
+ function W(e) {
48
+ let n = !1;
49
+ function t() {
50
+ if (n) return;
51
+ const r = y;
52
+ y = t;
53
+ try {
54
+ e();
55
+ } finally {
56
+ y = r;
57
+ }
58
+ }
59
+ return t(), () => {
60
+ n = !0;
61
+ };
62
+ }
63
+ function F(e, n, t) {
64
+ let r = !1, u;
65
+ function o() {
66
+ if (r) return;
67
+ const a = e.value;
68
+ queueMicrotask(() => {
69
+ r || (n(a, u), u = a);
70
+ });
71
+ }
72
+ const c = y;
73
+ return y = o, u = e.value, y = c, (t == null ? void 0 : t.immediate) === !0 && n(u, u), () => {
74
+ r = !0;
75
+ };
76
+ }
77
+ const _ = typeof process < "u" ? process.env.NODE_ENV !== "production" : !0;
78
+ function m(e) {
79
+ _ && console.warn(`[arckode-ui] ${e}`);
80
+ }
81
+ function I(e, n, t) {
82
+ for (const [r, u] of Object.entries(e)) {
83
+ const o = n[r];
84
+ if (u.required === !0 && o === void 0) {
85
+ m(`[${t}] Prop requerido "${r}" no fue proporcionado.`);
86
+ continue;
87
+ }
88
+ if (o === void 0) continue;
89
+ const c = u.type;
90
+ c === String && typeof o == "string" || c === Number && typeof o == "number" || c === Boolean && typeof o == "boolean" || c === Array && Array.isArray(o) || c === Function && typeof o == "function" || c === Object && typeof o == "object" && !Array.isArray(o) && o !== null || m(
91
+ `[${t}] Prop "${r}" recibió tipo incorrecto. Esperado: ${c.name}, recibido: ${typeof o}.`
92
+ );
93
+ }
94
+ }
95
+ function B(e, n, t) {
96
+ e.includes(n) || m(
97
+ `[${t}] emit("${n}") no está declarado en emits[]. Declarar antes de usar.`
98
+ );
99
+ }
100
+ function K(e, n) {
101
+ if (typeof e != "object" || e === null) {
102
+ m(`[${n}] setup() debe retornar un objeto { state, computed, actions }.`);
103
+ return;
104
+ }
105
+ const t = /* @__PURE__ */ new Set(["state", "computed", "actions"]), r = Object.keys(e);
106
+ for (const u of r)
107
+ t.has(u) || m(
108
+ `[${n}] setup() retornó una key no permitida: "${u}". Solo se permiten: state, computed, actions.`
109
+ );
110
+ }
111
+ function te(e) {
112
+ if (_) {
113
+ if (e.name || m('defineComponent() requiere el campo "name".'), e.emits)
114
+ for (const t of e.emits)
115
+ (t !== t.toLowerCase() || /[A-Z]/.test(t)) && m(
116
+ `[${e.name}] El evento "${t}" en emits[] debe ser kebab-case. Usar "${t.replace(/([A-Z])/g, "-$1").toLowerCase()}" en su lugar.`
117
+ );
118
+ if (e.props)
119
+ for (const [t, r] of Object.entries(e.props))
120
+ r.type || m(`[${e.name}] El prop "${t}" no tiene "type" definido.`);
121
+ }
122
+ const n = (t, r) => {
123
+ _ && I(e.props ?? {}, t, e.name);
124
+ const u = {
125
+ emit(c, a) {
126
+ _ && B(e.emits ?? [], c, e.name), r.emit(c, a);
127
+ }
128
+ }, o = e.setup(t, u);
129
+ return _ && K(o, e.name), o;
130
+ };
131
+ return {
132
+ name: e.name,
133
+ props: e.props ?? {},
134
+ emits: e.emits ?? [],
135
+ meta: e.meta ?? {},
136
+ setup: n
137
+ };
138
+ }
139
+ let x = [], A = [], P = [];
140
+ function Z(e, n, t) {
141
+ x = e, A = n, P = t;
142
+ }
143
+ function ne(e) {
144
+ x.push(e);
145
+ }
146
+ function re(e) {
147
+ A.push(e);
148
+ }
149
+ function oe(e) {
150
+ P.push(e);
151
+ }
152
+ function ce(e, n, ...t) {
153
+ return {
154
+ tag: e,
155
+ props: n ?? {},
156
+ children: U(t)
157
+ };
158
+ }
159
+ function U(e) {
160
+ const n = [];
161
+ for (const t of e)
162
+ t == null || t === !1 || t === !0 || (Array.isArray(t) ? n.push(...U(t)) : typeof t == "number" ? n.push(String(t)) : n.push(t));
163
+ return n;
164
+ }
165
+ function H(e) {
166
+ return typeof e == "object" && e !== null && typeof e.setup == "function";
167
+ }
168
+ function G(e, n) {
169
+ const t = Object.keys(e), r = Object.keys(n);
170
+ if (t.length !== r.length) return !1;
171
+ for (const u of t)
172
+ if (e[u] !== n[u]) return !1;
173
+ return !0;
174
+ }
175
+ function N(e, n) {
176
+ for (const [t, r] of Object.entries(n))
177
+ if (t !== "key") {
178
+ if (t.startsWith("on") && t.length > 2 && typeof r == "function") {
179
+ const u = t.slice(2).toLowerCase();
180
+ e.addEventListener(u, r);
181
+ continue;
182
+ }
183
+ if (t === "class") {
184
+ e.className = r != null ? String(r) : "";
185
+ continue;
186
+ }
187
+ if (t === "style" && typeof r == "object" && r !== null) {
188
+ Object.assign(e.style, r);
189
+ continue;
190
+ }
191
+ if (t === "value") {
192
+ e.value = r != null ? String(r) : "";
193
+ continue;
194
+ }
195
+ if (t === "checked") {
196
+ e.checked = !!r;
197
+ continue;
198
+ }
199
+ r === !1 || r === null || r === void 0 ? e.removeAttribute(t) : e.setAttribute(t, String(r));
200
+ }
201
+ }
202
+ function k(e) {
203
+ if (e == null)
204
+ return document.createTextNode("");
205
+ if (typeof e == "string" || typeof e == "number")
206
+ return document.createTextNode(String(e));
207
+ if (H(e.tag)) {
208
+ const t = document.createElement("div");
209
+ t.style.display = "contents";
210
+ const r = R(e.children), u = {
211
+ ...e.props,
212
+ __slot_default: () => r.value
213
+ };
214
+ for (const [c, a] of Object.entries(e.props))
215
+ if (c.startsWith("on") && c.length > 2 && typeof a == "function") {
216
+ const i = c.slice(2).toLowerCase();
217
+ t.addEventListener(i, (h) => {
218
+ const p = h.detail;
219
+ a(p);
220
+ });
221
+ }
222
+ const o = D(e.tag, u, t, null);
223
+ return t.__arkUnmount = o, t.__arkSlot = r, t.__arkTag = e.tag, t.__arkStaticProps = { ...e.props }, t;
224
+ }
225
+ const n = document.createElement(e.tag);
226
+ N(n, e.props);
227
+ for (const t of e.children)
228
+ n.appendChild(k(t));
229
+ return n;
230
+ }
231
+ function X(e, n) {
232
+ return e == null ? n == null : n == null ? !1 : typeof e == "string" ? typeof n == "string" : typeof n == "string" ? !1 : e.tag === n.tag;
233
+ }
234
+ function L(e, n, t) {
235
+ var h, p, l, v, f, g;
236
+ if (!X(n, t)) {
237
+ const s = k(t);
238
+ return (h = e.parentNode) == null || h.replaceChild(s, e), s;
239
+ }
240
+ if (typeof t == "string" || t === null || t === void 0) {
241
+ const s = t == null ? "" : String(t);
242
+ if (e.nodeType === Node.TEXT_NODE)
243
+ return e.textContent !== s && (e.textContent = s), e;
244
+ const d = document.createTextNode(s);
245
+ return (p = e.parentNode) == null || p.replaceChild(d, e), d;
246
+ }
247
+ if (H(t.tag)) {
248
+ const s = e, d = t, b = s.__arkTag, C = d.tag;
249
+ if (b === C && s.__arkSlot) {
250
+ s.__arkSlot.value = d.children;
251
+ const J = s.__arkStaticProps ?? {}, M = d.props;
252
+ if (!G(J, M)) {
253
+ (l = s.__arkUnmount) == null || l.call(s);
254
+ const w = k(t);
255
+ return (v = e.parentNode) == null || v.replaceChild(w, e), w;
256
+ }
257
+ return e;
258
+ }
259
+ (f = s.__arkUnmount) == null || f.call(s);
260
+ const $ = k(t);
261
+ return (g = e.parentNode) == null || g.replaceChild($, e), $;
262
+ }
263
+ const r = e, u = (n == null ? void 0 : n.props) ?? {}, o = t.props;
264
+ for (const [s, d] of Object.entries(u))
265
+ s.startsWith("on") && s.length > 2 && typeof d == "function" && r.removeEventListener(s.slice(2).toLowerCase(), d);
266
+ for (const s of Object.keys(u))
267
+ !(s in o) && !s.startsWith("on") && r.removeAttribute(s);
268
+ N(r, o);
269
+ const c = n.children, a = t.children, i = Math.max(c.length, a.length);
270
+ for (let s = 0; s < i; s++) {
271
+ const d = c[s], b = a[s], C = r.childNodes[s];
272
+ if (b === void 0) {
273
+ for (; r.childNodes.length > s; )
274
+ r.removeChild(r.childNodes[s]);
275
+ break;
276
+ }
277
+ C === void 0 ? r.appendChild(k(b)) : L(C, d ?? null, b);
278
+ }
279
+ return r;
280
+ }
281
+ function ue(e, n) {
282
+ const t = document.querySelector(n);
283
+ if (!t) throw new Error(`[arckode-ui] mount: "${n}" not found`);
284
+ return D(e, {}, t, null);
285
+ }
286
+ function D(e, n, t, r) {
287
+ const u = [], o = [];
288
+ Z(u, o, []);
289
+ const a = r ?? ((f, g) => {
290
+ t.dispatchEvent(
291
+ new CustomEvent(f, { detail: g, bubbles: !0 })
292
+ );
293
+ }), i = e.setup(n, { emit: a }), h = e.__render;
294
+ if (!h)
295
+ return (typeof process > "u" || process.env.NODE_ENV !== "production") && console.warn(
296
+ `[arckode-ui] ${e.name}: no __render. ¿Compilado por el Vite plugin?`
297
+ ), () => {
298
+ };
299
+ let p = null, l = null;
300
+ const v = W(() => {
301
+ const f = h(
302
+ n,
303
+ i.state ?? {},
304
+ i.computed ?? {},
305
+ i.actions ?? {}
306
+ );
307
+ l === null ? (l = k(f), t.appendChild(l)) : l = L(l, p, f), p = f;
308
+ });
309
+ return queueMicrotask(() => {
310
+ for (const f of u) f();
311
+ }), () => {
312
+ var f;
313
+ v();
314
+ for (const g of o) g();
315
+ l && ((f = l.parentNode) == null || f.removeChild(l));
316
+ };
317
+ }
318
+ const E = /* @__PURE__ */ new Map();
319
+ function q(e) {
320
+ try {
321
+ return e === "localStorage" ? typeof localStorage < "u" ? localStorage : null : typeof sessionStorage < "u" ? sessionStorage : null;
322
+ } catch {
323
+ return null;
324
+ }
325
+ }
326
+ function z(e, n) {
327
+ const t = q(e.storage);
328
+ if (t)
329
+ try {
330
+ const r = t.getItem(e.key);
331
+ if (!r) return;
332
+ const u = JSON.parse(r), o = e.pick ?? Object.keys(n);
333
+ for (const c of o)
334
+ c in u && c in n && (n[c].value = u[c]);
335
+ } catch {
336
+ }
337
+ }
338
+ function Q(e, n) {
339
+ const t = q(e.storage);
340
+ if (t)
341
+ try {
342
+ const r = e.pick ?? Object.keys(n), u = {};
343
+ for (const o of r)
344
+ o in n && (u[o] = n[o].peek);
345
+ t.setItem(e.key, JSON.stringify(u));
346
+ } catch {
347
+ }
348
+ }
349
+ function Y(e, n) {
350
+ z(e, n);
351
+ const t = e.pick ?? Object.keys(n);
352
+ for (const r of t)
353
+ r in n && F(n[r], () => {
354
+ Q(e, n);
355
+ });
356
+ }
357
+ function se(e, n) {
358
+ return (!e || e.trim() === "") && console.warn("[arckode-ui] defineStore: el id del store no puede estar vacío"), (!n.state || typeof n.state != "object" || Array.isArray(n.state)) && console.warn("[arckode-ui] defineStore: state debe ser un objeto de signals"), function() {
359
+ if (E.has(e))
360
+ return E.get(e);
361
+ const r = {
362
+ state: n.state,
363
+ actions: n.actions,
364
+ getters: n.getters ?? {}
365
+ };
366
+ return n.persist && Y(
367
+ n.persist,
368
+ n.state
369
+ ), E.set(e, r), r;
370
+ };
371
+ }
372
+ class T extends Error {
373
+ constructor(n, t, r) {
374
+ super(r), this.status = n, this.body = t, this.name = "ArkServiceError";
375
+ }
376
+ }
377
+ async function S(e, n, t) {
378
+ const r = new AbortController(), u = setTimeout(() => r.abort(), t);
379
+ try {
380
+ const o = await fetch(e, {
381
+ ...n,
382
+ signal: r.signal
383
+ });
384
+ clearTimeout(u);
385
+ let c;
386
+ if ((o.headers.get("content-type") ?? "").includes("application/json"))
387
+ c = await o.json();
388
+ else {
389
+ const i = await o.text();
390
+ try {
391
+ c = JSON.parse(i);
392
+ } catch {
393
+ c = i;
394
+ }
395
+ }
396
+ if (!o.ok)
397
+ throw new T(
398
+ o.status,
399
+ c,
400
+ `HTTP ${o.status}`
401
+ );
402
+ return c;
403
+ } catch (o) {
404
+ throw clearTimeout(u), o instanceof T, o;
405
+ }
406
+ }
407
+ function V(e) {
408
+ const n = e.timeout ?? 5e3, t = e.headers ?? {};
409
+ function r(u) {
410
+ return { ...t, ...u };
411
+ }
412
+ return {
413
+ async get(u, o) {
414
+ const c = `${e.baseUrl}${u}`, a = (o == null ? void 0 : o.timeout) ?? n;
415
+ return S(
416
+ c,
417
+ {
418
+ method: "GET",
419
+ headers: r(o == null ? void 0 : o.headers)
420
+ },
421
+ a
422
+ );
423
+ },
424
+ async post(u, o, c) {
425
+ const a = `${e.baseUrl}${u}`, i = (c == null ? void 0 : c.timeout) ?? n;
426
+ return S(
427
+ a,
428
+ {
429
+ method: "POST",
430
+ headers: {
431
+ "Content-Type": "application/json",
432
+ ...r(c == null ? void 0 : c.headers)
433
+ },
434
+ body: JSON.stringify(o)
435
+ },
436
+ i
437
+ );
438
+ },
439
+ async put(u, o, c) {
440
+ const a = `${e.baseUrl}${u}`, i = (c == null ? void 0 : c.timeout) ?? n;
441
+ return S(
442
+ a,
443
+ {
444
+ method: "PUT",
445
+ headers: {
446
+ "Content-Type": "application/json",
447
+ ...r(c == null ? void 0 : c.headers)
448
+ },
449
+ body: JSON.stringify(o)
450
+ },
451
+ i
452
+ );
453
+ },
454
+ async patch(u, o, c) {
455
+ const a = `${e.baseUrl}${u}`, i = (c == null ? void 0 : c.timeout) ?? n;
456
+ return S(
457
+ a,
458
+ {
459
+ method: "PATCH",
460
+ headers: {
461
+ "Content-Type": "application/json",
462
+ ...r(c == null ? void 0 : c.headers)
463
+ },
464
+ body: JSON.stringify(o)
465
+ },
466
+ i
467
+ );
468
+ },
469
+ async delete(u, o) {
470
+ const c = `${e.baseUrl}${u}`, a = (o == null ? void 0 : o.timeout) ?? n;
471
+ return S(
472
+ c,
473
+ {
474
+ method: "DELETE",
475
+ headers: r(o == null ? void 0 : o.headers)
476
+ },
477
+ a
478
+ );
479
+ }
480
+ };
481
+ }
482
+ function ae(e, n) {
483
+ const t = V(e), r = {};
484
+ for (const u of Object.keys(n))
485
+ r[u] = n[u].bind(t);
486
+ return r;
487
+ }
488
+ export {
489
+ T as ArkServiceError,
490
+ ee as computed,
491
+ le as createRouter,
492
+ ae as createService,
493
+ te as defineComponent,
494
+ se as defineStore,
495
+ W as effect,
496
+ de as getCurrentPath,
497
+ ce as h,
498
+ ue as mount,
499
+ D as mountComponent,
500
+ ye as navigate,
501
+ ne as onMount,
502
+ re as onUnmount,
503
+ oe as onUpdate,
504
+ R as signal,
505
+ me as useRoute,
506
+ F as watch
507
+ };
@@ -0,0 +1,129 @@
1
+ import * as g from "node:fs";
2
+ import * as y from "node:path";
3
+ let u = typeof window < "u" ? window.location.pathname : "/";
4
+ function j() {
5
+ return u;
6
+ }
7
+ function x(n) {
8
+ return n.startsWith("(") && n.endsWith(")") ? "" : n.startsWith("[...") && n.endsWith("]") ? "*" : n.startsWith("[") && n.endsWith("]") ? `:${n.slice(1, -1)}` : n === "index" ? "" : n;
9
+ }
10
+ function W(n) {
11
+ const r = [];
12
+ for (const e of n.split("/"))
13
+ e.startsWith(":") && r.push(e.slice(1));
14
+ return r;
15
+ }
16
+ function v(n) {
17
+ const e = n.replace(/\.ark$/, "").split("/"), o = [];
18
+ for (const s of e) {
19
+ const i = x(s);
20
+ o.push(i);
21
+ }
22
+ const t = o.filter((s) => s !== "");
23
+ if (t.length === 0)
24
+ return "/";
25
+ if (t.includes("*")) {
26
+ const s = t.slice(0, t.indexOf("*"));
27
+ return s.length > 0 ? `/${s.join("/")}/*` : "/*";
28
+ }
29
+ return `/${t.join("/")}`;
30
+ }
31
+ function w(n, r) {
32
+ const e = [], o = g.readdirSync(n, { withFileTypes: !0 });
33
+ for (const t of o) {
34
+ const a = y.join(n, t.name), s = r ? `${r}/${t.name}` : t.name;
35
+ t.isDirectory() ? e.push(...w(a, s)) : t.isFile() && t.name.endsWith(".ark") && e.push(s);
36
+ }
37
+ return e;
38
+ }
39
+ function k(n) {
40
+ const r = w(n, ""), e = [], o = [];
41
+ for (const t of r)
42
+ if ((t.split("/").pop() ?? "") === "_layout.ark") {
43
+ const s = t.split("/").slice(0, -1).join("/");
44
+ o.push({ prefix: s, filePath: t });
45
+ }
46
+ for (const t of r) {
47
+ const a = t.split("/"), s = a[a.length - 1] ?? "", i = s === "_layout.ark", l = s === "_error.ark", f = v(t), m = W(f);
48
+ let h;
49
+ if (!i) {
50
+ const p = a.slice(0, -1).join("/");
51
+ let d = "", P;
52
+ for (const c of o)
53
+ (c.prefix === p || p.startsWith(c.prefix === "" ? "" : `${c.prefix}/`)) && c.prefix.length >= d.length && (d = c.prefix, P = c.filePath);
54
+ h = P;
55
+ }
56
+ e.push({
57
+ path: f,
58
+ filePath: t,
59
+ params: m,
60
+ isLayout: i,
61
+ isError: l,
62
+ ...h !== void 0 ? { layoutPath: h } : {}
63
+ });
64
+ }
65
+ return e;
66
+ }
67
+ function S(n, r) {
68
+ const e = n.split("/").filter(Boolean), o = r.split("/").filter(Boolean), t = {};
69
+ if (e.length > 0 && e[e.length - 1] === "*") {
70
+ const s = e.slice(0, -1);
71
+ if (o.length < s.length) return null;
72
+ for (let i = 0; i < s.length; i++) {
73
+ const l = s[i], f = o[i];
74
+ if (l.startsWith(":"))
75
+ t[l.slice(1)] = f;
76
+ else if (l !== f)
77
+ return null;
78
+ }
79
+ return t["*"] = o.slice(s.length).join("/"), t;
80
+ }
81
+ if (e.length !== o.length) return null;
82
+ for (let s = 0; s < e.length; s++) {
83
+ const i = e[s], l = o[s];
84
+ if (i.startsWith(":"))
85
+ t[i.slice(1)] = l;
86
+ else if (i !== l)
87
+ return null;
88
+ }
89
+ return n === "/" && r !== "/" ? null : t;
90
+ }
91
+ function _(n) {
92
+ const r = n.filter((t) => !t.isLayout && !t.isError);
93
+ function e(t) {
94
+ for (const a of r) {
95
+ const s = S(a.path, t);
96
+ if (s !== null)
97
+ return { route: a, params: s };
98
+ }
99
+ return null;
100
+ }
101
+ function o(t) {
102
+ u = t, typeof window < "u" && window.history.pushState(null, "", t);
103
+ }
104
+ return { match: e, navigate: o };
105
+ }
106
+ function C(n, r) {
107
+ let e = n.path;
108
+ if (r)
109
+ for (const [o, t] of Object.entries(r))
110
+ e = e.replace(`:${o}`, t);
111
+ u = e, typeof window < "u" && window.history.pushState(null, "", e);
112
+ }
113
+ function E() {
114
+ const n = u, r = {};
115
+ return typeof window < "u" && new URLSearchParams(window.location.search).forEach((o, t) => {
116
+ r[t] = o;
117
+ }), {
118
+ params: {},
119
+ query: r,
120
+ path: n
121
+ };
122
+ }
123
+ export {
124
+ _ as c,
125
+ j as g,
126
+ C as n,
127
+ k as s,
128
+ E as u
129
+ };