sigpro 1.1.20 → 1.2.39
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/Readme.md +28 -24
- package/dist/sigpro.editor.js +1 -0
- package/dist/sigpro.grid.js +78 -0
- package/dist/sigpro.js +1 -480
- package/dist/sigpro.ui.css +2 -0
- package/dist/sigpro.ui.js +1 -0
- package/dist/sigpro.utils.js +1 -0
- package/dist/sigpro.vite.js +4 -0
- package/package.json +57 -32
- package/sigpro.d.ts +395 -0
- package/dist/sigpro.esm.js +0 -437
- package/dist/sigpro.esm.min.js +0 -1
- package/dist/sigpro.min.js +0 -1
- package/index.js +0 -2
- package/sigpro/index.js +0 -473
- package/vite/index.js +0 -77
package/sigpro/index.js
DELETED
|
@@ -1,473 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SigPro Core
|
|
3
|
-
*/
|
|
4
|
-
let activeEffect = null;
|
|
5
|
-
let currentOwner = null;
|
|
6
|
-
const effectQueue = new Set();
|
|
7
|
-
let isFlushing = false;
|
|
8
|
-
const MOUNTED_NODES = new WeakMap();
|
|
9
|
-
|
|
10
|
-
const flush = () => {
|
|
11
|
-
if (isFlushing) return;
|
|
12
|
-
isFlushing = true;
|
|
13
|
-
while (effectQueue.size > 0) {
|
|
14
|
-
const sorted = Array.from(effectQueue).sort((a, b) => (a.depth || 0) - (b.depth || 0));
|
|
15
|
-
effectQueue.clear();
|
|
16
|
-
for (const eff of sorted) if (!eff._deleted) eff();
|
|
17
|
-
}
|
|
18
|
-
isFlushing = false;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const track = (subs) => {
|
|
22
|
-
if (activeEffect && !activeEffect._deleted) {
|
|
23
|
-
subs.add(activeEffect);
|
|
24
|
-
activeEffect._deps.add(subs);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const trigger = (subs) => {
|
|
29
|
-
for (const eff of subs) {
|
|
30
|
-
if (eff === activeEffect || eff._deleted) continue;
|
|
31
|
-
if (eff._isComputed) {
|
|
32
|
-
eff.markDirty();
|
|
33
|
-
if (eff._subs) trigger(eff._subs);
|
|
34
|
-
} else {
|
|
35
|
-
effectQueue.add(eff);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
if (!isFlushing) queueMicrotask(flush);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const sweep = (node) => {
|
|
42
|
-
if (node._cleanups) {
|
|
43
|
-
node._cleanups.forEach((f) => f());
|
|
44
|
-
node._cleanups.clear();
|
|
45
|
-
}
|
|
46
|
-
node.childNodes?.forEach(sweep);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const _view = (fn) => {
|
|
50
|
-
const cleanups = new Set();
|
|
51
|
-
const prev = currentOwner;
|
|
52
|
-
const container = document.createElement("div");
|
|
53
|
-
container.style.display = "contents";
|
|
54
|
-
currentOwner = { cleanups };
|
|
55
|
-
try {
|
|
56
|
-
const res = fn({ onCleanup: (f) => cleanups.add(f) });
|
|
57
|
-
const process = (n) => {
|
|
58
|
-
if (!n) return;
|
|
59
|
-
if (n._isRuntime) {
|
|
60
|
-
cleanups.add(n.destroy);
|
|
61
|
-
container.appendChild(n.container);
|
|
62
|
-
} else if (Array.isArray(n)) n.forEach(process);
|
|
63
|
-
else container.appendChild(n instanceof Node ? n : document.createTextNode(String(n)));
|
|
64
|
-
};
|
|
65
|
-
process(res);
|
|
66
|
-
} finally { currentOwner = prev; }
|
|
67
|
-
return {
|
|
68
|
-
_isRuntime: true,
|
|
69
|
-
container,
|
|
70
|
-
destroy: () => {
|
|
71
|
-
cleanups.forEach((f) => f());
|
|
72
|
-
sweep(container);
|
|
73
|
-
container.remove();
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const $ = (initial, key = null) => {
|
|
79
|
-
if (typeof initial === "function") {
|
|
80
|
-
const subs = new Set();
|
|
81
|
-
let cached, dirty = true;
|
|
82
|
-
const effect = () => {
|
|
83
|
-
if (effect._deleted) return;
|
|
84
|
-
effect._deps.forEach((s) => s.delete(effect));
|
|
85
|
-
effect._deps.clear();
|
|
86
|
-
const prev = activeEffect;
|
|
87
|
-
activeEffect = effect;
|
|
88
|
-
try {
|
|
89
|
-
const val = initial();
|
|
90
|
-
if (!Object.is(cached, val) || dirty) {
|
|
91
|
-
cached = val;
|
|
92
|
-
dirty = false;
|
|
93
|
-
trigger(subs);
|
|
94
|
-
}
|
|
95
|
-
} finally { activeEffect = prev; }
|
|
96
|
-
};
|
|
97
|
-
effect._deps = new Set();
|
|
98
|
-
effect._isComputed = true;
|
|
99
|
-
effect._subs = subs;
|
|
100
|
-
effect._deleted = false;
|
|
101
|
-
effect.markDirty = () => (dirty = true);
|
|
102
|
-
effect.stop = () => {
|
|
103
|
-
effect._deleted = true;
|
|
104
|
-
effect._deps.forEach((s) => s.delete(effect));
|
|
105
|
-
subs.clear();
|
|
106
|
-
};
|
|
107
|
-
if (currentOwner) currentOwner.cleanups.add(effect.stop);
|
|
108
|
-
return () => { if (dirty) effect(); track(subs); return cached; };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let value = initial;
|
|
112
|
-
if (key) {
|
|
113
|
-
try {
|
|
114
|
-
const saved = localStorage.getItem(key);
|
|
115
|
-
if (saved !== null) value = JSON.parse(saved);
|
|
116
|
-
} catch (e) {
|
|
117
|
-
console.warn("SigPro: LocalStorage locked", e);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const subs = new Set();
|
|
121
|
-
return (...args) => {
|
|
122
|
-
if (args.length) {
|
|
123
|
-
const next = typeof args[0] === "function" ? args[0](value) : args[0];
|
|
124
|
-
if (!Object.is(value, next)) {
|
|
125
|
-
value = next;
|
|
126
|
-
if (key) localStorage.setItem(key, JSON.stringify(value));
|
|
127
|
-
trigger(subs);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
track(subs);
|
|
131
|
-
return value;
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const $$ = (obj, cache = new WeakMap()) => {
|
|
136
|
-
if (typeof obj !== "object" || obj === null) return obj;
|
|
137
|
-
if (cache.has(obj)) return cache.get(obj);
|
|
138
|
-
|
|
139
|
-
const subs = {};
|
|
140
|
-
|
|
141
|
-
const proxy = new Proxy(obj, {
|
|
142
|
-
get(target, key) {
|
|
143
|
-
if (activeEffect)
|
|
144
|
-
track(subs[key] ??= new Set());
|
|
145
|
-
|
|
146
|
-
const value = Reflect.get(target, key);
|
|
147
|
-
|
|
148
|
-
return (typeof value === "object" && value !== null)
|
|
149
|
-
? $$(value, cache)
|
|
150
|
-
: value;
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
set(target, key, value) {
|
|
154
|
-
if (Object.is(target[key], value)) return true;
|
|
155
|
-
|
|
156
|
-
const res = Reflect.set(target, key, value);
|
|
157
|
-
|
|
158
|
-
if (subs[key])
|
|
159
|
-
trigger(subs[key]);
|
|
160
|
-
|
|
161
|
-
return res;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
cache.set(obj, proxy);
|
|
166
|
-
return proxy;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const $watch = (target, fn) => {
|
|
170
|
-
const isExplicit = Array.isArray(target);
|
|
171
|
-
const callback = isExplicit ? fn : target;
|
|
172
|
-
const depsInput = isExplicit ? target : null;
|
|
173
|
-
|
|
174
|
-
if (typeof callback !== "function") return () => { };
|
|
175
|
-
|
|
176
|
-
const owner = currentOwner;
|
|
177
|
-
const runner = () => {
|
|
178
|
-
if (runner._deleted) return;
|
|
179
|
-
runner._deps.forEach((s) => s.delete(runner));
|
|
180
|
-
runner._deps.clear();
|
|
181
|
-
runner._cleanups.forEach((c) => c());
|
|
182
|
-
runner._cleanups.clear();
|
|
183
|
-
|
|
184
|
-
const prevEffect = activeEffect;
|
|
185
|
-
const prevOwner = currentOwner;
|
|
186
|
-
activeEffect = runner;
|
|
187
|
-
currentOwner = { cleanups: runner._cleanups };
|
|
188
|
-
runner.depth = prevEffect ? prevEffect.depth + 1 : 0;
|
|
189
|
-
|
|
190
|
-
try {
|
|
191
|
-
if (isExplicit) {
|
|
192
|
-
activeEffect = null;
|
|
193
|
-
callback();
|
|
194
|
-
activeEffect = runner;
|
|
195
|
-
depsInput.forEach(d => typeof d === "function" && d());
|
|
196
|
-
} else {
|
|
197
|
-
callback();
|
|
198
|
-
}
|
|
199
|
-
} finally {
|
|
200
|
-
activeEffect = prevEffect;
|
|
201
|
-
currentOwner = prevOwner;
|
|
202
|
-
}
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
runner._deps = new Set();
|
|
206
|
-
runner._cleanups = new Set();
|
|
207
|
-
runner._deleted = false;
|
|
208
|
-
runner.stop = () => {
|
|
209
|
-
if (runner._deleted) return;
|
|
210
|
-
runner._deleted = true;
|
|
211
|
-
effectQueue.delete(runner);
|
|
212
|
-
runner._deps.forEach((s) => s.delete(runner));
|
|
213
|
-
runner._cleanups.forEach((c) => c());
|
|
214
|
-
if (owner) owner.cleanups.delete(runner.stop);
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
if (owner) owner.cleanups.add(runner.stop);
|
|
218
|
-
runner();
|
|
219
|
-
return runner.stop;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
const $html = (tag, props = {}, content = []) => {
|
|
223
|
-
if (props instanceof Node || Array.isArray(props) || typeof props !== "object") {
|
|
224
|
-
content = props; props = {};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const svgTags = ["svg", "path", "circle", "rect", "line", "polyline", "polygon", "g", "defs", "text", "tspan", "use"];
|
|
228
|
-
const isSVG = svgTags.includes(tag);
|
|
229
|
-
const el = isSVG
|
|
230
|
-
? document.createElementNS("http://www.w3.org/2000/svg", tag)
|
|
231
|
-
: document.createElement(tag);
|
|
232
|
-
|
|
233
|
-
const _sanitize = (key, val) => (key === 'src' || key === 'href') && String(val).toLowerCase().includes('javascript:') ? '#' : val;
|
|
234
|
-
el._cleanups = new Set();
|
|
235
|
-
|
|
236
|
-
const boolAttrs = ["disabled", "checked", "required", "readonly", "selected", "multiple", "autofocus"];
|
|
237
|
-
|
|
238
|
-
for (let [key, val] of Object.entries(props)) {
|
|
239
|
-
if (key === "ref") { (typeof val === "function" ? val(el) : (val.current = el)); continue; }
|
|
240
|
-
const isSignal = typeof val === "function", isInput = ["INPUT", "TEXTAREA", "SELECT"].includes(el.tagName), isBindAttr = (key === "value" || key === "checked");
|
|
241
|
-
|
|
242
|
-
if (isInput && isBindAttr && isSignal) {
|
|
243
|
-
el._cleanups.add($watch(() => { const currentVal = val(); if (el[key] !== currentVal) el[key] = currentVal; }));
|
|
244
|
-
const eventName = key === "checked" ? "change" : "input", handler = (event) => val(event.target[key]);
|
|
245
|
-
el.addEventListener(eventName, handler);
|
|
246
|
-
el._cleanups.add(() => el.removeEventListener(eventName, handler));
|
|
247
|
-
} else if (key.startsWith("on")) {
|
|
248
|
-
const eventName = key.slice(2).toLowerCase().split(".")[0], handler = (event) => val(event);
|
|
249
|
-
el.addEventListener(eventName, handler);
|
|
250
|
-
el._cleanups.add(() => el.removeEventListener(eventName, handler));
|
|
251
|
-
} else if (isSignal) {
|
|
252
|
-
el._cleanups.add($watch(() => {
|
|
253
|
-
const currentVal = _sanitize(key, val());
|
|
254
|
-
if (key === "class") {
|
|
255
|
-
el.className = currentVal || "";
|
|
256
|
-
} else if (boolAttrs.includes(key)) {
|
|
257
|
-
if (currentVal) {
|
|
258
|
-
el.setAttribute(key, "");
|
|
259
|
-
el[key] = true;
|
|
260
|
-
} else {
|
|
261
|
-
el.removeAttribute(key);
|
|
262
|
-
el[key] = false;
|
|
263
|
-
}
|
|
264
|
-
} else {
|
|
265
|
-
if (currentVal == null) {
|
|
266
|
-
el.removeAttribute(key);
|
|
267
|
-
} else if (isSVG && typeof currentVal === 'number') {
|
|
268
|
-
el.setAttribute(key, currentVal);
|
|
269
|
-
} else {
|
|
270
|
-
el.setAttribute(key, currentVal);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}));
|
|
274
|
-
} else {
|
|
275
|
-
if (boolAttrs.includes(key)) {
|
|
276
|
-
if (val) {
|
|
277
|
-
el.setAttribute(key, "");
|
|
278
|
-
el[key] = true;
|
|
279
|
-
} else {
|
|
280
|
-
el.removeAttribute(key);
|
|
281
|
-
el[key] = false;
|
|
282
|
-
}
|
|
283
|
-
} else {
|
|
284
|
-
el.setAttribute(key, _sanitize(key, val));
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const append = (child) => {
|
|
290
|
-
if (Array.isArray(child)) return child.forEach(append);
|
|
291
|
-
if (child instanceof Node) {
|
|
292
|
-
el.appendChild(child);
|
|
293
|
-
} else if (typeof child === "function") {
|
|
294
|
-
const marker = document.createTextNode("");
|
|
295
|
-
el.appendChild(marker);
|
|
296
|
-
let nodes = [];
|
|
297
|
-
el._cleanups.add($watch(() => {
|
|
298
|
-
const res = child(), next = (Array.isArray(res) ? res : [res]).map((i) =>
|
|
299
|
-
i?._isRuntime ? i.container : i instanceof Node ? i : document.createTextNode(i ?? "")
|
|
300
|
-
);
|
|
301
|
-
nodes.forEach((n) => { sweep?.(n); n.remove(); });
|
|
302
|
-
next.forEach((n) => marker.parentNode?.insertBefore(n, marker));
|
|
303
|
-
nodes = next;
|
|
304
|
-
}));
|
|
305
|
-
} else el.appendChild(document.createTextNode(child ?? ""));
|
|
306
|
-
};
|
|
307
|
-
append(content);
|
|
308
|
-
return el;
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
const $if = (condition, thenVal, otherwiseVal = null, transition = null) => {
|
|
312
|
-
const marker = document.createTextNode("");
|
|
313
|
-
const container = $html("div", { style: "display:contents" }, [marker]);
|
|
314
|
-
let current = null, last = null;
|
|
315
|
-
|
|
316
|
-
$watch(() => {
|
|
317
|
-
const state = !!(typeof condition === "function" ? condition() : condition);
|
|
318
|
-
if (state === last) return;
|
|
319
|
-
last = state;
|
|
320
|
-
|
|
321
|
-
if (current && !state && transition?.out) {
|
|
322
|
-
transition.out(current.container, () => {
|
|
323
|
-
current.destroy();
|
|
324
|
-
current = null;
|
|
325
|
-
});
|
|
326
|
-
} else {
|
|
327
|
-
if (current) current.destroy();
|
|
328
|
-
current = null;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (state || (!state && otherwiseVal)) {
|
|
332
|
-
const branch = state ? thenVal : otherwiseVal;
|
|
333
|
-
if (branch) {
|
|
334
|
-
current = _view(() => typeof branch === "function" ? branch() : branch);
|
|
335
|
-
container.insertBefore(current.container, marker);
|
|
336
|
-
if (state && transition?.in) transition.in(current.container);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
return container;
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
$if.not = (condition, thenVal, otherwiseVal) => $if(() => !(typeof condition === "function" ? condition() : condition), thenVal, otherwiseVal);
|
|
345
|
-
|
|
346
|
-
const $for = (source, render, keyFn, tag = "div", props = { style: "display:contents" }) => {
|
|
347
|
-
const marker = document.createTextNode("");
|
|
348
|
-
const container = $html(tag, props, [marker]);
|
|
349
|
-
let cache = new Map();
|
|
350
|
-
|
|
351
|
-
$watch(() => {
|
|
352
|
-
const items = (typeof source === "function" ? source() : source) || [];
|
|
353
|
-
const newCache = new Map();
|
|
354
|
-
const newOrder = [];
|
|
355
|
-
|
|
356
|
-
for (let i = 0; i < items.length; i++) {
|
|
357
|
-
const item = items[i];
|
|
358
|
-
const key = keyFn ? keyFn(item, i) : i;
|
|
359
|
-
|
|
360
|
-
let run = cache.get(key);
|
|
361
|
-
if (!run) {
|
|
362
|
-
run = _view(() => render(item, i));
|
|
363
|
-
} else {
|
|
364
|
-
cache.delete(key);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
newCache.set(key, run);
|
|
368
|
-
newOrder.push(key);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
cache.forEach(run => {
|
|
372
|
-
run.destroy();
|
|
373
|
-
run.container.remove();
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
let anchor = marker;
|
|
377
|
-
for (let i = newOrder.length - 1; i >= 0; i--) {
|
|
378
|
-
const run = newCache.get(newOrder[i]);
|
|
379
|
-
if (run.container.nextSibling !== anchor) {
|
|
380
|
-
container.insertBefore(run.container, anchor);
|
|
381
|
-
}
|
|
382
|
-
anchor = run.container;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
cache = newCache;
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
return container;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
const $router = (routes) => {
|
|
392
|
-
const sPath = $(window.location.hash.replace(/^#/, "") || "/");
|
|
393
|
-
window.addEventListener("hashchange", () => sPath(window.location.hash.replace(/^#/, "") || "/"));
|
|
394
|
-
const outlet = $html("div", { class: "router-outlet" });
|
|
395
|
-
let current = null;
|
|
396
|
-
|
|
397
|
-
$watch([sPath], async () => {
|
|
398
|
-
const path = sPath();
|
|
399
|
-
const route = routes.find(r => {
|
|
400
|
-
const rp = r.path.split("/").filter(Boolean), pp = path.split("/").filter(Boolean);
|
|
401
|
-
return rp.length === pp.length && rp.every((p, i) => p.startsWith(":") || p === pp[i]);
|
|
402
|
-
}) || routes.find(r => r.path === "*");
|
|
403
|
-
|
|
404
|
-
if (route) {
|
|
405
|
-
let comp = route.component;
|
|
406
|
-
if (typeof comp === "function" && comp.toString().includes('import')) {
|
|
407
|
-
comp = (await comp()).default || (await comp());
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const params = {};
|
|
411
|
-
route.path.split("/").filter(Boolean).forEach((p, i) => {
|
|
412
|
-
if (p.startsWith(":")) params[p.slice(1)] = path.split("/").filter(Boolean)[i];
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
if (current) current.destroy();
|
|
416
|
-
if ($router.params) $router.params(params);
|
|
417
|
-
|
|
418
|
-
current = _view(() => {
|
|
419
|
-
try {
|
|
420
|
-
return typeof comp === "function" ? comp(params) : comp;
|
|
421
|
-
} catch (e) {
|
|
422
|
-
return $html("div", { class: "p-4 text-error" }, "Error loading view");
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
outlet.appendChild(current.container);
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
return outlet;
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
$router.params = $({});
|
|
432
|
-
$router.to = (path) => (window.location.hash = path.replace(/^#?\/?/, "#/"));
|
|
433
|
-
$router.back = () => window.history.back();
|
|
434
|
-
$router.path = () => window.location.hash.replace(/^#/, "") || "/";
|
|
435
|
-
|
|
436
|
-
const $mount = (component, target) => {
|
|
437
|
-
const el = typeof target === "string" ? document.querySelector(target) : target;
|
|
438
|
-
if (!el) return;
|
|
439
|
-
if (MOUNTED_NODES.has(el)) MOUNTED_NODES.get(el).destroy();
|
|
440
|
-
const instance = _view(typeof component === "function" ? component : () => component);
|
|
441
|
-
el.replaceChildren(instance.container);
|
|
442
|
-
MOUNTED_NODES.set(el, instance);
|
|
443
|
-
return instance;
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
export const Fragment = ({ children }) => children;
|
|
447
|
-
|
|
448
|
-
const SigProCore = { $, $watch, $html, $if, $for, $router, $mount, Fragment };
|
|
449
|
-
|
|
450
|
-
if (typeof window !== "undefined") {
|
|
451
|
-
const install = (registry) => {
|
|
452
|
-
Object.keys(registry).forEach(key => {
|
|
453
|
-
window[key] = registry[key];
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
const tags = `div span p h1 h2 h3 h4 h5 h6 br hr section article aside nav main header footer address ul ol li dl dt dd a em strong small i b u mark time sub sup pre code blockquote details summary dialog form label input textarea select button option fieldset legend table thead tbody tfoot tr th td caption img video audio canvas svg iframe picture source progress meter`.split(/\s+/);
|
|
457
|
-
tags.forEach((tagName) => {
|
|
458
|
-
const helperName = tagName.charAt(0).toUpperCase() + tagName.slice(1);
|
|
459
|
-
if (!(helperName in window)) {
|
|
460
|
-
window[helperName] = (props, content) => $html(tagName, props, content);
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
window.Fragment = Fragment;
|
|
465
|
-
window.SigPro = Object.freeze(registry);
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
install(SigProCore);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
export { $, $watch, $html, $if, $for, $router, $mount };
|
|
472
|
-
|
|
473
|
-
export default SigProCore;
|
package/vite/index.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SigPro Vite Plugin - File-based Routing
|
|
3
|
-
* @module sigpro/vite
|
|
4
|
-
*/
|
|
5
|
-
import fs from 'node:fs';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
|
|
8
|
-
export default function sigproRouter() {
|
|
9
|
-
const virtualModuleId = 'virtual:sigpro-routes';
|
|
10
|
-
const resolvedVirtualModuleId = '\0' + virtualModuleId;
|
|
11
|
-
|
|
12
|
-
// Helper para escanear archivos
|
|
13
|
-
const getFiles = (dir) => {
|
|
14
|
-
if (!fs.existsSync(dir)) return [];
|
|
15
|
-
return fs.readdirSync(dir, { recursive: true })
|
|
16
|
-
.filter(file => /\.(js|jsx)$/.test(file) && !path.basename(file).startsWith('_'))
|
|
17
|
-
.map(file => path.resolve(dir, file));
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// Transformador de ruta de archivo a URL de router
|
|
21
|
-
const pathToUrl = (pagesDir, filePath) => {
|
|
22
|
-
let relative = path.relative(pagesDir, filePath)
|
|
23
|
-
.replace(/\\/g, '/')
|
|
24
|
-
.replace(/\.(js|jsx)$/, '')
|
|
25
|
-
.replace(/\/index$/, '')
|
|
26
|
-
.replace(/^index$/, '');
|
|
27
|
-
|
|
28
|
-
return ('/' + relative)
|
|
29
|
-
.replace(/\/+/g, '/')
|
|
30
|
-
.replace(/\[\.\.\.([^\]]+)\]/g, '*')
|
|
31
|
-
.replace(/\[([^\]]+)\]/g, ':$1')
|
|
32
|
-
.replace(/\/$/, '') || '/';
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
name: 'sigpro-router',
|
|
37
|
-
|
|
38
|
-
resolveId(id) {
|
|
39
|
-
if (id === virtualModuleId) return resolvedVirtualModuleId;
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
load(id) {
|
|
43
|
-
if (id !== resolvedVirtualModuleId) return;
|
|
44
|
-
|
|
45
|
-
const root = process.cwd();
|
|
46
|
-
const pagesDir = path.resolve(root, 'src/pages');
|
|
47
|
-
|
|
48
|
-
// Obtenemos y ordenamos archivos (rutas estáticas primero, luego dinámicas)
|
|
49
|
-
const files = getFiles(pagesDir).sort((a, b) => {
|
|
50
|
-
const urlA = pathToUrl(pagesDir, a);
|
|
51
|
-
const urlB = pathToUrl(pagesDir, b);
|
|
52
|
-
if (urlA.includes(':') && !urlB.includes(':')) return 1;
|
|
53
|
-
if (!urlA.includes(':') && urlB.includes(':')) return -1;
|
|
54
|
-
return urlB.length - urlA.length;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
let routeEntries = '';
|
|
58
|
-
|
|
59
|
-
files.forEach((fullPath) => {
|
|
60
|
-
const urlPath = pathToUrl(pagesDir, fullPath);
|
|
61
|
-
// Hacemos la ruta relativa al proyecto para que el import de Vite sea limpio
|
|
62
|
-
const relativeImport = './' + path.relative(root, fullPath).replace(/\\/g, '/');
|
|
63
|
-
|
|
64
|
-
routeEntries += ` { path: '${urlPath}', component: async () => (await import('/${relativeImport}')).default },\n`;
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Fallback 404 si no existe una ruta comodín
|
|
68
|
-
if (!routeEntries.includes("path: '*'")) {
|
|
69
|
-
routeEntries += ` { path: '*', component: () => document.createTextNode('404 - Not Found') },\n`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return `export const routes = [\n${routeEntries}];`;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export { sigproRouter };
|