gyosjs 0.3.2 → 0.4.1
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 +128 -126
- package/dist/core/router/diff-nodes.d.ts +2 -1
- package/dist/core/router/diff-nodes.d.ts.map +1 -1
- package/dist/core/router/router.d.ts +30 -2
- package/dist/core/router/router.d.ts.map +1 -1
- package/dist/gyos.auto.esm.js +415 -191
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +415 -191
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +591 -287
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +591 -287
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +592 -288
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +593 -287
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +416 -192
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +417 -191
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/public-api.d.ts +5 -2
- package/dist/public-api.d.ts.map +1 -1
- package/dist/reactivity/signal.d.ts.map +1 -1
- package/dist/utils/progress-bar.d.ts +1 -0
- package/dist/utils/progress-bar.d.ts.map +1 -1
- package/package.json +91 -90
package/dist/gyos.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.
|
|
2
|
+
* GyosJS v0.4.1
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -229,10 +229,35 @@ function hasStructuralParent(el) {
|
|
|
229
229
|
* count.value++; // Triggers effect
|
|
230
230
|
* ```
|
|
231
231
|
*/
|
|
232
|
-
/**
|
|
233
|
-
* Current effect being tracked
|
|
234
|
-
*/
|
|
235
232
|
let currentEffect = null;
|
|
233
|
+
function track(source) {
|
|
234
|
+
if (!currentEffect)
|
|
235
|
+
return;
|
|
236
|
+
source.subscribers.add(currentEffect);
|
|
237
|
+
currentEffect.__dependencies?.add(source.subscribers);
|
|
238
|
+
currentEffect.__versions?.set(source, source.version);
|
|
239
|
+
}
|
|
240
|
+
function dependenciesChanged(versions) {
|
|
241
|
+
return untrack(() => {
|
|
242
|
+
for (const [source, version] of versions) {
|
|
243
|
+
source.refresh?.();
|
|
244
|
+
if (source.version !== version)
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
return false;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
// Invalidate derived caches synchronously; only user effects are deferred.
|
|
251
|
+
function notifySubscribers(subscribers) {
|
|
252
|
+
for (const sub of Array.from(subscribers)) {
|
|
253
|
+
if (sub.__invalidate)
|
|
254
|
+
sub();
|
|
255
|
+
else if (isBatching)
|
|
256
|
+
batchedEffects.add(sub);
|
|
257
|
+
else
|
|
258
|
+
queueEffect(sub);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
236
261
|
// Simple counter for debug-friendly IDs
|
|
237
262
|
let signalIdCounter = 0;
|
|
238
263
|
const WARN_SUBSCRIBERS = () => typeof window !== 'undefined' && window.GYOS_DEBUG_WARN_SUBSCRIBERS;
|
|
@@ -270,6 +295,9 @@ function flushEffectQueue() {
|
|
|
270
295
|
}
|
|
271
296
|
});
|
|
272
297
|
isFlushingQueue = false;
|
|
298
|
+
// A plain subscribe callback can enqueue more work without entering effect().
|
|
299
|
+
if (effectQueue.size > 0)
|
|
300
|
+
queueMicrotask(flushEffectQueue);
|
|
273
301
|
}
|
|
274
302
|
/**
|
|
275
303
|
* Queue an effect for execution in next microtask
|
|
@@ -328,17 +356,14 @@ function signal(initialValue, debugOrOptions) {
|
|
|
328
356
|
const debugId = ++signalIdCounter;
|
|
329
357
|
let value = initialValue;
|
|
330
358
|
const subscribers = new Set();
|
|
359
|
+
const source = { subscribers, version: 0 };
|
|
331
360
|
let warnedSubscribers = false;
|
|
332
361
|
const read = () => {
|
|
333
362
|
// Track dependency
|
|
334
363
|
if (currentEffect) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
// Store the subscribers Set in the effect's dependencies for cleanup
|
|
339
|
-
if (currentEffect.__dependencies) {
|
|
340
|
-
currentEffect.__dependencies.add(subscribers);
|
|
341
|
-
}
|
|
364
|
+
const wasSubscribed = subscribers.has(currentEffect);
|
|
365
|
+
track(source);
|
|
366
|
+
if (!wasSubscribed) {
|
|
342
367
|
if (DEBUG_VERBOSE()) {
|
|
343
368
|
console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Added subscriber, total:', subscribers.size);
|
|
344
369
|
}
|
|
@@ -357,18 +382,13 @@ function signal(initialValue, debugOrOptions) {
|
|
|
357
382
|
// For objects/arrays, check if it's actually the same reference
|
|
358
383
|
// Deep equality is expensive, let user handle it
|
|
359
384
|
value = newValue;
|
|
385
|
+
source.version++;
|
|
360
386
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Value changed to:', newValue);
|
|
361
387
|
notify();
|
|
362
388
|
};
|
|
363
389
|
const notify = () => {
|
|
364
390
|
DEBUG_VERBOSE() && console.log('[Signal]', formatDebugLabel(debugId, debugLabel), 'Notifying', subscribers.size, 'subscribers');
|
|
365
|
-
|
|
366
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
// Always queue effects to prevent cascading updates
|
|
370
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
371
|
-
}
|
|
391
|
+
notifySubscribers(subscribers);
|
|
372
392
|
};
|
|
373
393
|
// Create callable signal (like Angular/SolidJS)
|
|
374
394
|
// Call without args = read, call with arg = write
|
|
@@ -403,8 +423,16 @@ function signal(initialValue, debugOrOptions) {
|
|
|
403
423
|
},
|
|
404
424
|
subscribe: {
|
|
405
425
|
value: function (fn) {
|
|
406
|
-
|
|
407
|
-
|
|
426
|
+
let active = true;
|
|
427
|
+
const callback = () => { if (active)
|
|
428
|
+
untrack(fn); };
|
|
429
|
+
subscribers.add(callback);
|
|
430
|
+
return () => {
|
|
431
|
+
active = false;
|
|
432
|
+
subscribers.delete(callback);
|
|
433
|
+
effectQueue.delete(callback);
|
|
434
|
+
batchedEffects.delete(callback);
|
|
435
|
+
};
|
|
408
436
|
},
|
|
409
437
|
enumerable: true,
|
|
410
438
|
configurable: true
|
|
@@ -464,49 +492,60 @@ function computed(fn) {
|
|
|
464
492
|
let value;
|
|
465
493
|
let isDirty = true;
|
|
466
494
|
let isFirstRun = true;
|
|
495
|
+
let computing = false;
|
|
467
496
|
const subscribers = new Set();
|
|
468
|
-
|
|
497
|
+
const dependencies = new Set();
|
|
498
|
+
const versions = new Map();
|
|
499
|
+
const source = { subscribers, version: 0, refresh: () => compute() };
|
|
500
|
+
const invalidate = () => {
|
|
501
|
+
// A later batched write must also move already queued consumers into
|
|
502
|
+
// the batch, even when an earlier ordinary write dirtied this cache.
|
|
503
|
+
if (isDirty && !isBatching)
|
|
504
|
+
return;
|
|
505
|
+
isDirty = true;
|
|
506
|
+
notifySubscribers(subscribers);
|
|
507
|
+
};
|
|
508
|
+
invalidate.__invalidate = true;
|
|
509
|
+
invalidate.__dependencies = dependencies;
|
|
510
|
+
invalidate.__versions = versions;
|
|
469
511
|
const compute = () => {
|
|
470
512
|
if (!isDirty && !isFirstRun)
|
|
471
513
|
return;
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
value = newValue;
|
|
482
|
-
isFirstRun = false;
|
|
483
|
-
isDirty = false;
|
|
484
|
-
// Notify subscribers
|
|
485
|
-
if (!isBatching) {
|
|
486
|
-
subscribers.forEach(sub => queueEffect(sub));
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
subscribers.forEach(sub => batchedEffects.add(sub));
|
|
490
|
-
}
|
|
491
|
-
}
|
|
514
|
+
if (computing)
|
|
515
|
+
throw new Error('[Computed] Circular dependency');
|
|
516
|
+
computing = true;
|
|
517
|
+
const previousEffect = currentEffect;
|
|
518
|
+
try {
|
|
519
|
+
// A dirty upstream computed may still resolve to its previous value.
|
|
520
|
+
if (!isFirstRun && !dependenciesChanged(versions)) {
|
|
521
|
+
isDirty = false;
|
|
522
|
+
return;
|
|
492
523
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
524
|
+
dependencies.forEach(dependency => dependency.delete(invalidate));
|
|
525
|
+
dependencies.clear();
|
|
526
|
+
versions.clear();
|
|
527
|
+
currentEffect = invalidate;
|
|
528
|
+
const nextValue = fn();
|
|
529
|
+
if (isFirstRun || !Object.is(value, nextValue)) {
|
|
530
|
+
value = nextValue;
|
|
531
|
+
source.version++;
|
|
496
532
|
}
|
|
497
|
-
|
|
498
|
-
|
|
533
|
+
isFirstRun = false;
|
|
534
|
+
isDirty = false;
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
// Preserve error isolation and the last successful value.
|
|
538
|
+
console.error('[Computed] Error in computation:', error);
|
|
539
|
+
isDirty = false;
|
|
540
|
+
}
|
|
541
|
+
finally {
|
|
542
|
+
currentEffect = previousEffect;
|
|
543
|
+
computing = false;
|
|
544
|
+
}
|
|
499
545
|
};
|
|
500
546
|
const read = () => {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
// Track dependency
|
|
504
|
-
if (currentEffect && !subscribers.has(currentEffect)) {
|
|
505
|
-
subscribers.add(currentEffect);
|
|
506
|
-
if (currentEffect.__dependencies) {
|
|
507
|
-
currentEffect.__dependencies.add(subscribers);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
547
|
+
compute();
|
|
548
|
+
track(source);
|
|
510
549
|
return value;
|
|
511
550
|
};
|
|
512
551
|
// Create callable computed (read-only)
|
|
@@ -531,8 +570,14 @@ function computed(fn) {
|
|
|
531
570
|
},
|
|
532
571
|
subscribe: {
|
|
533
572
|
value: function (fn) {
|
|
534
|
-
|
|
535
|
-
|
|
573
|
+
// Establish dependencies even if subscribe() is the first access.
|
|
574
|
+
let first = true;
|
|
575
|
+
return effect(() => {
|
|
576
|
+
read();
|
|
577
|
+
if (!first)
|
|
578
|
+
untrack(fn);
|
|
579
|
+
first = false;
|
|
580
|
+
});
|
|
536
581
|
},
|
|
537
582
|
enumerable: true,
|
|
538
583
|
configurable: true
|
|
@@ -583,11 +628,15 @@ function computed(fn) {
|
|
|
583
628
|
*/
|
|
584
629
|
function effect(fn) {
|
|
585
630
|
let cleanup;
|
|
586
|
-
|
|
631
|
+
const dependencies = new Set();
|
|
632
|
+
const versions = new Map();
|
|
587
633
|
let active = true;
|
|
634
|
+
let initialized = false;
|
|
588
635
|
const execute = () => {
|
|
589
636
|
if (!active)
|
|
590
637
|
return;
|
|
638
|
+
if (initialized && !dependenciesChanged(versions))
|
|
639
|
+
return;
|
|
591
640
|
// Prevent recursive execution - if already running, skip
|
|
592
641
|
if (runningEffects.has(execute)) {
|
|
593
642
|
DEBUG() && console.warn('[Effect] Skipped recursive execution');
|
|
@@ -602,10 +651,13 @@ function effect(fn) {
|
|
|
602
651
|
});
|
|
603
652
|
DEBUG() && console.log('[Effect] Cleaned up dependencies, count:', dependencies.size);
|
|
604
653
|
dependencies.clear();
|
|
654
|
+
versions.clear();
|
|
605
655
|
// Clean up previous run
|
|
606
656
|
if (cleanup) {
|
|
657
|
+
const previousCleanup = cleanup;
|
|
658
|
+
cleanup = undefined;
|
|
607
659
|
try {
|
|
608
|
-
|
|
660
|
+
untrack(previousCleanup);
|
|
609
661
|
}
|
|
610
662
|
catch (error) {
|
|
611
663
|
console.error('[Effect] Error in cleanup:', error);
|
|
@@ -616,6 +668,7 @@ function effect(fn) {
|
|
|
616
668
|
currentEffect = execute;
|
|
617
669
|
// Store dependencies for cleanup
|
|
618
670
|
execute.__dependencies = dependencies;
|
|
671
|
+
execute.__versions = versions;
|
|
619
672
|
try {
|
|
620
673
|
const nextCleanup = fn();
|
|
621
674
|
cleanup = typeof nextCleanup === 'function' ? nextCleanup : undefined;
|
|
@@ -625,6 +678,7 @@ function effect(fn) {
|
|
|
625
678
|
// Don't throw - allow other effects to continue
|
|
626
679
|
}
|
|
627
680
|
finally {
|
|
681
|
+
initialized = true;
|
|
628
682
|
currentEffect = prevEffect;
|
|
629
683
|
effectDepth--;
|
|
630
684
|
runningEffects.delete(execute);
|
|
@@ -641,14 +695,17 @@ function effect(fn) {
|
|
|
641
695
|
if (!active)
|
|
642
696
|
return;
|
|
643
697
|
active = false;
|
|
698
|
+
effectQueue.delete(execute);
|
|
699
|
+
batchedEffects.delete(execute);
|
|
644
700
|
// Remove from all dependencies
|
|
645
701
|
dependencies.forEach(depSet => {
|
|
646
702
|
depSet.delete(execute);
|
|
647
703
|
});
|
|
648
704
|
dependencies.clear();
|
|
705
|
+
versions.clear();
|
|
649
706
|
if (cleanup) {
|
|
650
707
|
try {
|
|
651
|
-
cleanup
|
|
708
|
+
untrack(cleanup);
|
|
652
709
|
}
|
|
653
710
|
catch (error) {
|
|
654
711
|
console.error('[Effect] Error in final cleanup:', error);
|
|
@@ -708,6 +765,8 @@ function batch(fn) {
|
|
|
708
765
|
const effects = Array.from(batchedEffects);
|
|
709
766
|
batchedEffects.clear();
|
|
710
767
|
effects.forEach(effect => {
|
|
768
|
+
// This batch also settles any earlier queued write to this observer.
|
|
769
|
+
effectQueue.delete(effect);
|
|
711
770
|
try {
|
|
712
771
|
effect();
|
|
713
772
|
}
|
|
@@ -2228,59 +2287,59 @@ function applyTransitionStyles() {
|
|
|
2228
2287
|
return;
|
|
2229
2288
|
const style = document.createElement('style');
|
|
2230
2289
|
style.id = styleId;
|
|
2231
|
-
style.textContent = `
|
|
2232
|
-
/* Opacity utilities */
|
|
2290
|
+
style.textContent = `
|
|
2291
|
+
/* Opacity utilities */
|
|
2233
2292
|
.gyos-t-opacity-0 { opacity: 0; }
|
|
2234
2293
|
.gyos-t-opacity-100 { opacity: 1; }
|
|
2235
|
-
|
|
2236
|
-
/* Transform - Translate Y */
|
|
2294
|
+
|
|
2295
|
+
/* Transform - Translate Y */
|
|
2237
2296
|
.gyos-t-translate-y-0 { transform: translateY(0); }
|
|
2238
2297
|
.gyos-t-translate-y--100 { transform: translateY(-100%); }
|
|
2239
2298
|
.gyos-t-translate-y-100 { transform: translateY(100%); }
|
|
2240
|
-
|
|
2241
|
-
/* Transform - Translate X */
|
|
2299
|
+
|
|
2300
|
+
/* Transform - Translate X */
|
|
2242
2301
|
.gyos-t-translate-x-0 { transform: translateX(0); }
|
|
2243
2302
|
.gyos-t-translate-x--100 { transform: translateX(-100%); }
|
|
2244
2303
|
.gyos-t-translate-x-100 { transform: translateX(100%); }
|
|
2245
|
-
|
|
2246
|
-
/* Transform - Scale */
|
|
2304
|
+
|
|
2305
|
+
/* Transform - Scale */
|
|
2247
2306
|
.gyos-t-scale-0 { transform: scale(0); }
|
|
2248
2307
|
.gyos-t-scale-50 { transform: scale(0.5); }
|
|
2249
2308
|
.gyos-t-scale-100 { transform: scale(1); }
|
|
2250
|
-
|
|
2251
|
-
/* Animation Keyframes */
|
|
2252
|
-
@keyframes gyos-fade-in {
|
|
2253
|
-
from { opacity: 0; }
|
|
2254
|
-
to { opacity: 1; }
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
|
-
@keyframes gyos-fade-out {
|
|
2258
|
-
from { opacity: 1; }
|
|
2259
|
-
to { opacity: 0; }
|
|
2260
|
-
}
|
|
2261
|
-
|
|
2262
|
-
@keyframes gyos-slide-down {
|
|
2263
|
-
from { transform: translateY(-100%); opacity: 0; }
|
|
2264
|
-
to { transform: translateY(0); opacity: 1; }
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
@keyframes gyos-slide-up {
|
|
2268
|
-
from { transform: translateY(100%); opacity: 0; }
|
|
2269
|
-
to { transform: translateY(0); opacity: 1; }
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
|
-
@keyframes gyos-scale-in {
|
|
2273
|
-
from { transform: scale(0); opacity: 0; }
|
|
2274
|
-
to { transform: scale(1); opacity: 1; }
|
|
2275
|
-
}
|
|
2276
|
-
|
|
2277
|
-
@keyframes gyos-scale-out {
|
|
2278
|
-
from { transform: scale(1); opacity: 1; }
|
|
2279
|
-
to { transform: scale(0); opacity: 0; }
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
[g-cloak] {
|
|
2283
|
-
display: none !important;
|
|
2309
|
+
|
|
2310
|
+
/* Animation Keyframes */
|
|
2311
|
+
@keyframes gyos-fade-in {
|
|
2312
|
+
from { opacity: 0; }
|
|
2313
|
+
to { opacity: 1; }
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
@keyframes gyos-fade-out {
|
|
2317
|
+
from { opacity: 1; }
|
|
2318
|
+
to { opacity: 0; }
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
@keyframes gyos-slide-down {
|
|
2322
|
+
from { transform: translateY(-100%); opacity: 0; }
|
|
2323
|
+
to { transform: translateY(0); opacity: 1; }
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
@keyframes gyos-slide-up {
|
|
2327
|
+
from { transform: translateY(100%); opacity: 0; }
|
|
2328
|
+
to { transform: translateY(0); opacity: 1; }
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
@keyframes gyos-scale-in {
|
|
2332
|
+
from { transform: scale(0); opacity: 0; }
|
|
2333
|
+
to { transform: scale(1); opacity: 1; }
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
@keyframes gyos-scale-out {
|
|
2337
|
+
from { transform: scale(1); opacity: 1; }
|
|
2338
|
+
to { transform: scale(0); opacity: 0; }
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
[g-cloak] {
|
|
2342
|
+
display: none !important;
|
|
2284
2343
|
}`;
|
|
2285
2344
|
document.head.appendChild(style);
|
|
2286
2345
|
}
|
|
@@ -6637,33 +6696,44 @@ class ProgressBar {
|
|
|
6637
6696
|
getCurrentProgress() {
|
|
6638
6697
|
return this.currentProgress;
|
|
6639
6698
|
}
|
|
6699
|
+
reconnect() {
|
|
6700
|
+
if (!this.element || !this.progressBarEnabled || !document.body)
|
|
6701
|
+
return;
|
|
6702
|
+
// Snapshots may contain a clone of the runtime bar. Keep this instance.
|
|
6703
|
+
document.querySelectorAll('#gyos-progress-bar').forEach(node => {
|
|
6704
|
+
if (node !== this.element)
|
|
6705
|
+
node.remove();
|
|
6706
|
+
});
|
|
6707
|
+
if (!this.element.isConnected)
|
|
6708
|
+
document.body.appendChild(this.element);
|
|
6709
|
+
}
|
|
6640
6710
|
createBar() {
|
|
6641
6711
|
if (typeof document === 'undefined')
|
|
6642
6712
|
return;
|
|
6643
6713
|
// Create progress bar element
|
|
6644
6714
|
this.element = document.createElement('div');
|
|
6645
6715
|
this.element.id = 'gyos-progress-bar';
|
|
6646
|
-
this.element.style.cssText = `
|
|
6647
|
-
position: fixed;
|
|
6648
|
-
top: 0;
|
|
6649
|
-
left: 0;
|
|
6650
|
-
width: 0%;
|
|
6651
|
-
height: 6px;
|
|
6652
|
-
background: var(--gyos-progress-color, linear-gradient(90deg, #aab9ff, #77889f));
|
|
6653
|
-
z-index: 999999;
|
|
6654
|
-
transition: width 0.3s linear, opacity 0.3s linear;
|
|
6655
|
-
opacity: 0;
|
|
6656
|
-
pointer-events: none;
|
|
6657
|
-
box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
|
|
6716
|
+
this.element.style.cssText = `
|
|
6717
|
+
position: fixed;
|
|
6718
|
+
top: 0;
|
|
6719
|
+
left: 0;
|
|
6720
|
+
width: 0%;
|
|
6721
|
+
height: 6px;
|
|
6722
|
+
background: var(--gyos-progress-color, linear-gradient(90deg, #aab9ff, #77889f));
|
|
6723
|
+
z-index: 999999;
|
|
6724
|
+
transition: width 0.3s linear, opacity 0.3s linear;
|
|
6725
|
+
opacity: 0;
|
|
6726
|
+
pointer-events: none;
|
|
6727
|
+
box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
|
|
6658
6728
|
`;
|
|
6659
6729
|
// Insert into DOM when ready
|
|
6660
6730
|
if (document.readyState === 'loading') {
|
|
6661
6731
|
document.addEventListener('DOMContentLoaded', () => {
|
|
6662
|
-
|
|
6663
|
-
});
|
|
6732
|
+
this.reconnect();
|
|
6733
|
+
}, { once: true });
|
|
6664
6734
|
}
|
|
6665
6735
|
else {
|
|
6666
|
-
|
|
6736
|
+
this.reconnect();
|
|
6667
6737
|
}
|
|
6668
6738
|
}
|
|
6669
6739
|
start() {
|
|
@@ -6687,6 +6757,7 @@ class ProgressBar {
|
|
|
6687
6757
|
setProgress(percent) {
|
|
6688
6758
|
if (!this.element || !this.progressBarEnabled)
|
|
6689
6759
|
return;
|
|
6760
|
+
this.reconnect();
|
|
6690
6761
|
// Clamp between 0-100
|
|
6691
6762
|
percent = Math.min(100, Math.max(0, percent));
|
|
6692
6763
|
this.currentProgress = percent;
|
|
@@ -6735,41 +6806,41 @@ class ProgressBar {
|
|
|
6735
6806
|
function createTargetSpinner() {
|
|
6736
6807
|
const spinner = document.createElement('div');
|
|
6737
6808
|
spinner.className = 'gyos-target-spinner';
|
|
6738
|
-
spinner.innerHTML = `
|
|
6739
|
-
<div class="gyos-spinner-content">
|
|
6740
|
-
<svg class="gyos-spinner-icon" viewBox="0 0 50 50">
|
|
6741
|
-
<circle cx="25" cy="25" r="20" fill="none" stroke="currentColor" stroke-width="4" stroke-dasharray="31.4 31.4" />
|
|
6742
|
-
</svg>
|
|
6743
|
-
</div>
|
|
6809
|
+
spinner.innerHTML = `
|
|
6810
|
+
<div class="gyos-spinner-content">
|
|
6811
|
+
<svg class="gyos-spinner-icon" viewBox="0 0 50 50">
|
|
6812
|
+
<circle cx="25" cy="25" r="20" fill="none" stroke="currentColor" stroke-width="4" stroke-dasharray="31.4 31.4" />
|
|
6813
|
+
</svg>
|
|
6814
|
+
</div>
|
|
6744
6815
|
`;
|
|
6745
6816
|
// Inject styles if not already present
|
|
6746
6817
|
if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
|
|
6747
6818
|
const style = document.createElement('style');
|
|
6748
6819
|
style.id = 'gyos-target-spinner-styles';
|
|
6749
|
-
style.textContent = `
|
|
6750
|
-
.gyos-target-spinner {
|
|
6751
|
-
display: flex;
|
|
6752
|
-
align-items: center;
|
|
6753
|
-
justify-content: center;
|
|
6754
|
-
padding: 20px;
|
|
6755
|
-
min-height: 60px;
|
|
6756
|
-
}
|
|
6757
|
-
.gyos-spinner-content {
|
|
6758
|
-
display: flex;
|
|
6759
|
-
align-items: center;
|
|
6760
|
-
gap: 10px;
|
|
6761
|
-
color: var(--gyos-spinner-color, #667eea);
|
|
6762
|
-
font-size: 14px;
|
|
6763
|
-
}
|
|
6764
|
-
.gyos-spinner-icon {
|
|
6765
|
-
width: 24px;
|
|
6766
|
-
height: 24px;
|
|
6767
|
-
animation: gyos-spin 1s linear infinite;
|
|
6768
|
-
}
|
|
6769
|
-
@keyframes gyos-spin {
|
|
6770
|
-
0% { transform: rotate(0deg); }
|
|
6771
|
-
100% { transform: rotate(360deg); }
|
|
6772
|
-
}
|
|
6820
|
+
style.textContent = `
|
|
6821
|
+
.gyos-target-spinner {
|
|
6822
|
+
display: flex;
|
|
6823
|
+
align-items: center;
|
|
6824
|
+
justify-content: center;
|
|
6825
|
+
padding: 20px;
|
|
6826
|
+
min-height: 60px;
|
|
6827
|
+
}
|
|
6828
|
+
.gyos-spinner-content {
|
|
6829
|
+
display: flex;
|
|
6830
|
+
align-items: center;
|
|
6831
|
+
gap: 10px;
|
|
6832
|
+
color: var(--gyos-spinner-color, #667eea);
|
|
6833
|
+
font-size: 14px;
|
|
6834
|
+
}
|
|
6835
|
+
.gyos-spinner-icon {
|
|
6836
|
+
width: 24px;
|
|
6837
|
+
height: 24px;
|
|
6838
|
+
animation: gyos-spin 1s linear infinite;
|
|
6839
|
+
}
|
|
6840
|
+
@keyframes gyos-spin {
|
|
6841
|
+
0% { transform: rotate(0deg); }
|
|
6842
|
+
100% { transform: rotate(360deg); }
|
|
6843
|
+
}
|
|
6773
6844
|
`;
|
|
6774
6845
|
document.head.appendChild(style);
|
|
6775
6846
|
}
|
|
@@ -7129,8 +7200,8 @@ async function performSwap(target, src, mode, options = {}) {
|
|
|
7129
7200
|
}
|
|
7130
7201
|
result = target;
|
|
7131
7202
|
}
|
|
7132
|
-
await options.beforeScripts?.();
|
|
7133
7203
|
options.onCommitted?.(result, normalized === 'append' || normalized === 'prepend' ? incomingChildren : [result]);
|
|
7204
|
+
await options.beforeScripts?.();
|
|
7134
7205
|
// Additive swaps must not re-run scripts that already existed in the target.
|
|
7135
7206
|
if (normalized === 'append' || normalized === 'prepend') {
|
|
7136
7207
|
await executeScriptsInNodes(incomingChildren, options.signal);
|
|
@@ -7370,6 +7441,21 @@ function handleScroll(url, trigger, savedScroll) {
|
|
|
7370
7441
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
7371
7442
|
}
|
|
7372
7443
|
|
|
7444
|
+
// A retained relative URL still identifies the resource loaded on its original
|
|
7445
|
+
// page, even after pushState changes document.baseURI.
|
|
7446
|
+
const resourceUrls = new WeakMap();
|
|
7447
|
+
function rememberResourceUrls(root, baseUrl) {
|
|
7448
|
+
root.querySelectorAll('script[src], link[href]').forEach(node => {
|
|
7449
|
+
const attribute = node.tagName === 'SCRIPT' ? 'src' : 'href';
|
|
7450
|
+
const source = node.getAttribute(attribute);
|
|
7451
|
+
if (resourceUrls.get(node)?.source === source)
|
|
7452
|
+
return;
|
|
7453
|
+
try {
|
|
7454
|
+
resourceUrls.set(node, { source, url: new URL(source, baseUrl).href });
|
|
7455
|
+
}
|
|
7456
|
+
catch { /* Invalid resource URLs retain their literal identity. */ }
|
|
7457
|
+
});
|
|
7458
|
+
}
|
|
7373
7459
|
function isNonceMeta(el) {
|
|
7374
7460
|
return el.tagName === 'META' && el.getAttribute('name')?.toLowerCase() === 'csp-nonce';
|
|
7375
7461
|
}
|
|
@@ -7387,7 +7473,20 @@ function serializeAttributes(el, context) {
|
|
|
7387
7473
|
return;
|
|
7388
7474
|
if (context.csp && isNonceMeta(el) && attr.name.toLowerCase() === 'content')
|
|
7389
7475
|
return;
|
|
7390
|
-
|
|
7476
|
+
let value = attr.value;
|
|
7477
|
+
if ((el.tagName === 'SCRIPT' && attr.name === 'src') || (el.tagName === 'LINK' && attr.name === 'href')) {
|
|
7478
|
+
const cached = resourceUrls.get(el);
|
|
7479
|
+
if (cached?.source === value)
|
|
7480
|
+
value = cached.url;
|
|
7481
|
+
else {
|
|
7482
|
+
try {
|
|
7483
|
+
value = new URL(value, context.baseUrl || el.baseURI).href;
|
|
7484
|
+
resourceUrls.set(el, { source: attr.value, url: value });
|
|
7485
|
+
}
|
|
7486
|
+
catch { /* Keep invalid URLs distinct. */ }
|
|
7487
|
+
}
|
|
7488
|
+
}
|
|
7489
|
+
attributes.set(attr.name, value);
|
|
7391
7490
|
});
|
|
7392
7491
|
if (context.csp && usesCspNonce(el) && context.activeNonce) {
|
|
7393
7492
|
attributes.set('nonce', context.activeNonce);
|
|
@@ -7454,19 +7553,21 @@ function warnSkippedNode(node) {
|
|
|
7454
7553
|
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
7455
7554
|
}
|
|
7456
7555
|
}
|
|
7457
|
-
async function diffNodes(currentNodes, nextNodes, container = document.head, signal) {
|
|
7556
|
+
async function diffNodes(currentNodes, nextNodes, container = document.head, signal, currentBaseUrl = document.baseURI) {
|
|
7458
7557
|
const csp = expressionRuntimeMode() === 'csp';
|
|
7459
7558
|
const context = {
|
|
7460
7559
|
csp,
|
|
7461
7560
|
activeNonce: csp ? resolveCspNonce() : undefined
|
|
7462
7561
|
};
|
|
7463
|
-
const current = keyedNodes(currentNodes, context);
|
|
7562
|
+
const current = keyedNodes(currentNodes, { ...context, baseUrl: currentBaseUrl });
|
|
7464
7563
|
const next = keyedNodes(nextNodes, context);
|
|
7564
|
+
const persistentKey = (node) => container === document.head ? node.getAttribute('g-head-persist') : null;
|
|
7565
|
+
const persistent = new Set(currentNodes.map(persistentKey).filter(Boolean));
|
|
7465
7566
|
const currentKeys = new Set(current.map(item => item.key));
|
|
7466
7567
|
const nextKeys = new Set(next.map(item => item.key));
|
|
7467
7568
|
// Remove nodes that are not in the new head
|
|
7468
7569
|
current.forEach(({ key, node }) => {
|
|
7469
|
-
if (!nextKeys.has(key)) {
|
|
7570
|
+
if (!nextKeys.has(key) && !persistentKey(node)) {
|
|
7470
7571
|
node.remove();
|
|
7471
7572
|
}
|
|
7472
7573
|
});
|
|
@@ -7474,6 +7575,8 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7474
7575
|
for (const { key, node } of next) {
|
|
7475
7576
|
if (signal?.aborted)
|
|
7476
7577
|
return;
|
|
7578
|
+
if (persistent.has(persistentKey(node)))
|
|
7579
|
+
continue;
|
|
7477
7580
|
if (!currentKeys.has(key)) {
|
|
7478
7581
|
if (!canInsertNode(node, context)) {
|
|
7479
7582
|
warnSkippedNode(node);
|
|
@@ -7676,6 +7779,7 @@ function prepareNavigationHtml(html) {
|
|
|
7676
7779
|
* MPA boost navigation inspired by Turbo Drive.
|
|
7677
7780
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7678
7781
|
*/
|
|
7782
|
+
const submittingForms = new WeakSet();
|
|
7679
7783
|
const snapshots = new Map();
|
|
7680
7784
|
const preloadCache = new Map();
|
|
7681
7785
|
const preloadControllers = new Map();
|
|
@@ -7692,12 +7796,30 @@ let activeNavigation = null;
|
|
|
7692
7796
|
let progressBar = null;
|
|
7693
7797
|
const beforeNavigate = [];
|
|
7694
7798
|
const afterNavigate = [];
|
|
7799
|
+
const beforeSwap = [];
|
|
7800
|
+
const navigationEnd = [];
|
|
7801
|
+
function registerNavigationHook(hooks, callback) {
|
|
7802
|
+
// A wrapper gives each registration its own unsubscribe identity.
|
|
7803
|
+
const entry = (url, context) => callback(url, context);
|
|
7804
|
+
hooks.push(entry);
|
|
7805
|
+
return () => {
|
|
7806
|
+
const index = hooks.indexOf(entry);
|
|
7807
|
+
if (index !== -1)
|
|
7808
|
+
hooks.splice(index, 1);
|
|
7809
|
+
};
|
|
7810
|
+
}
|
|
7695
7811
|
// Expose hooks to register before/after navigation callbacks
|
|
7696
7812
|
function onBeforeNavigate(callback) {
|
|
7697
|
-
beforeNavigate
|
|
7813
|
+
return registerNavigationHook(beforeNavigate, callback);
|
|
7698
7814
|
}
|
|
7699
7815
|
function onAfterNavigate(callback) {
|
|
7700
|
-
afterNavigate
|
|
7816
|
+
return registerNavigationHook(afterNavigate, callback);
|
|
7817
|
+
}
|
|
7818
|
+
function onBeforeSwap(callback) {
|
|
7819
|
+
return registerNavigationHook(beforeSwap, callback);
|
|
7820
|
+
}
|
|
7821
|
+
function onNavigationEnd(callback) {
|
|
7822
|
+
return registerNavigationHook(navigationEnd, (_url, context) => callback(context));
|
|
7701
7823
|
}
|
|
7702
7824
|
function startRouter(options) {
|
|
7703
7825
|
// If not has g-boost attribute, do not start router
|
|
@@ -7721,6 +7843,7 @@ function startRouter(options) {
|
|
|
7721
7843
|
}
|
|
7722
7844
|
// Cache scripts from initial page to prevent re-execution on first navigation back
|
|
7723
7845
|
cacheInitialPageScripts();
|
|
7846
|
+
rememberResourceUrls(document, document.baseURI);
|
|
7724
7847
|
routerStarted = true;
|
|
7725
7848
|
log('[GyosRouter] started');
|
|
7726
7849
|
}
|
|
@@ -7777,9 +7900,13 @@ function resolveTarget(trigger, targetSelector, targetOutletIndex) {
|
|
|
7777
7900
|
const outlet = findGlobalOutlet();
|
|
7778
7901
|
return outlet instanceof HTMLElement ? outlet : null;
|
|
7779
7902
|
}
|
|
7903
|
+
function isFullDocument(html) {
|
|
7904
|
+
return /^\s*(?:<!--[^]*?-->\s*)*(?:<!doctype\s+html\b|<html(?:\s|>))/i.test(html);
|
|
7905
|
+
}
|
|
7780
7906
|
function saveSnapshot(url, html) {
|
|
7781
7907
|
// create HTMLElement by html string to remove scripts and get clean snapshot
|
|
7782
7908
|
const doc = parseNavigationDocument(html);
|
|
7909
|
+
doc.querySelectorAll('#gyos-progress-bar').forEach(node => node.remove());
|
|
7783
7910
|
// Ignore hash for snapshot keys
|
|
7784
7911
|
if (url.includes('#'))
|
|
7785
7912
|
url = url.split('#')[0];
|
|
@@ -7788,7 +7915,7 @@ function saveSnapshot(url, html) {
|
|
|
7788
7915
|
if (s.hasAttribute('g-script-once'))
|
|
7789
7916
|
s.textContent = '';
|
|
7790
7917
|
});
|
|
7791
|
-
snapshots.set(url, { html: doc.documentElement.outerHTML });
|
|
7918
|
+
snapshots.set(url, { html: doc.documentElement.outerHTML, fullDocument: isFullDocument(html) });
|
|
7792
7919
|
log('[GyosRouter] snapshot saved for', url);
|
|
7793
7920
|
}
|
|
7794
7921
|
function getOutletIndex(root, target) {
|
|
@@ -7900,10 +8027,10 @@ function consumeViewTransitionRejection(promise) {
|
|
|
7900
8027
|
// update callback remains the navigation source of truth and is awaited below.
|
|
7901
8028
|
void promise?.catch(() => undefined);
|
|
7902
8029
|
}
|
|
7903
|
-
function runNavigationHooks(callbacks, url) {
|
|
7904
|
-
callbacks.forEach(callback => {
|
|
8030
|
+
function runNavigationHooks(callbacks, url, context) {
|
|
8031
|
+
[...callbacks].forEach(callback => {
|
|
7905
8032
|
try {
|
|
7906
|
-
callback(url);
|
|
8033
|
+
callback(url, { ...context });
|
|
7907
8034
|
}
|
|
7908
8035
|
catch (error) {
|
|
7909
8036
|
console.error('[GyosRouter] navigation hook error', error);
|
|
@@ -7941,7 +8068,13 @@ function buildRequest(opts) {
|
|
|
7941
8068
|
url = mergeFormDataIntoUrl(url, opts.formData);
|
|
7942
8069
|
}
|
|
7943
8070
|
else {
|
|
7944
|
-
|
|
8071
|
+
if (opts.formEncoding === 'application/x-www-form-urlencoded') {
|
|
8072
|
+
const encoded = new URLSearchParams();
|
|
8073
|
+
opts.formData.forEach((value, name) => encoded.append(name, typeof value === 'string' ? value : value.name));
|
|
8074
|
+
init.body = encoded;
|
|
8075
|
+
}
|
|
8076
|
+
else
|
|
8077
|
+
init.body = opts.formData;
|
|
7945
8078
|
}
|
|
7946
8079
|
}
|
|
7947
8080
|
else if (opts.jsonData) {
|
|
@@ -7984,25 +8117,26 @@ function preload(url) {
|
|
|
7984
8117
|
preloadControllers.delete(cacheKey);
|
|
7985
8118
|
});
|
|
7986
8119
|
}
|
|
7987
|
-
async function updateHead(fromDoc, signal) {
|
|
8120
|
+
async function updateHead(fromDoc, signal, currentBaseUrl) {
|
|
7988
8121
|
const allowedSelector = 'meta, link, style:not(#gyos-transitions), script';
|
|
7989
8122
|
const currentNodes = Array.from(document.head.querySelectorAll(allowedSelector));
|
|
7990
8123
|
const nextNodes = Array.from(fromDoc.head.querySelectorAll(allowedSelector));
|
|
7991
|
-
await diffNodes(currentNodes, nextNodes, document.head, signal);
|
|
8124
|
+
await diffNodes(currentNodes, nextNodes, document.head, signal, currentBaseUrl);
|
|
7992
8125
|
}
|
|
7993
|
-
async function scriptNotInOutletTarget(fromDoc, target, source, signal) {
|
|
8126
|
+
async function scriptNotInOutletTarget(fromDoc, target, source, signal, currentBaseUrl) {
|
|
7994
8127
|
// scripts in current document and it not in target outlet
|
|
7995
8128
|
const currentScripts = Array.from(document.scripts).filter(s => !target.contains(s) && !document.head.contains(s));
|
|
7996
8129
|
// scripts in fromDoc and it not in source outlet
|
|
7997
8130
|
const incomingScripts = Array.from(fromDoc.scripts).filter(s => !source.contains(s) && !fromDoc.head.contains(s));
|
|
7998
8131
|
// Diff and update scripts not in outlet/target
|
|
7999
|
-
await diffNodes(currentScripts, incomingScripts, document.body, signal);
|
|
8132
|
+
await diffNodes(currentScripts, incomingScripts, document.body, signal, currentBaseUrl);
|
|
8000
8133
|
}
|
|
8001
8134
|
function resolveIncomingScriptUrls(root, baseUrl) {
|
|
8002
|
-
root.querySelectorAll('script[src]').forEach(
|
|
8003
|
-
const
|
|
8135
|
+
root.querySelectorAll('script[src], link[href]').forEach(node => {
|
|
8136
|
+
const attribute = node.tagName === 'SCRIPT' ? 'src' : 'href';
|
|
8137
|
+
const source = node.getAttribute(attribute);
|
|
8004
8138
|
if (source)
|
|
8005
|
-
|
|
8139
|
+
node.setAttribute(attribute, new URL(source, baseUrl).href);
|
|
8006
8140
|
});
|
|
8007
8141
|
}
|
|
8008
8142
|
function isNavigableHtmlResponse(response) {
|
|
@@ -8056,6 +8190,22 @@ async function navigate(opts) {
|
|
|
8056
8190
|
resolveDone
|
|
8057
8191
|
};
|
|
8058
8192
|
activeNavigation = transaction;
|
|
8193
|
+
const currentBaseUrl = document.baseURI;
|
|
8194
|
+
rememberResourceUrls(document, currentBaseUrl);
|
|
8195
|
+
const context = {
|
|
8196
|
+
from: currentUrl, url: opts.url, method: opts.method.toUpperCase(),
|
|
8197
|
+
trigger: opts.trigger || null, target: null, form: opts.form || null,
|
|
8198
|
+
popstate: opts.popstate === true, signal: transaction.controller.signal,
|
|
8199
|
+
status: null, committed: false, fallback: false, outcome: null
|
|
8200
|
+
};
|
|
8201
|
+
const formEvent = opts.form
|
|
8202
|
+
? { form: opts.form, url: opts.url, status: null, outcome: null, committed: false, fallback: false }
|
|
8203
|
+
: null;
|
|
8204
|
+
const fallback = (url, requestSent) => {
|
|
8205
|
+
context.fallback = context.method === 'GET' || (!requestSent && !!opts.form);
|
|
8206
|
+
context.outcome ?? (context.outcome = context.fallback ? 'fallback' : 'invalid-response');
|
|
8207
|
+
fallbackFromBoost(opts, url, requestSent);
|
|
8208
|
+
};
|
|
8059
8209
|
const hasTargetSpinner = opts.trigger?.hasAttribute('g-router-spin');
|
|
8060
8210
|
const setRand = () => {
|
|
8061
8211
|
if (isActiveNavigation(transaction) && progressBar?.getCurrentProgress() < 70) {
|
|
@@ -8063,7 +8213,10 @@ async function navigate(opts) {
|
|
|
8063
8213
|
}
|
|
8064
8214
|
};
|
|
8065
8215
|
try {
|
|
8066
|
-
|
|
8216
|
+
if (formEvent)
|
|
8217
|
+
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8218
|
+
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
8219
|
+
assertActiveNavigation(transaction);
|
|
8067
8220
|
progressBar?.start();
|
|
8068
8221
|
// popstate already points history at the destination entry. Keep the visible
|
|
8069
8222
|
// page's position under currentUrl without overwriting that destination state.
|
|
@@ -8072,9 +8225,10 @@ async function navigate(opts) {
|
|
|
8072
8225
|
saveScrollPosition();
|
|
8073
8226
|
// Pick target element to swap
|
|
8074
8227
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
8228
|
+
context.target = target;
|
|
8075
8229
|
if (!target) {
|
|
8076
8230
|
if (isActiveNavigation(transaction))
|
|
8077
|
-
|
|
8231
|
+
fallback(opts.url, false);
|
|
8078
8232
|
return;
|
|
8079
8233
|
}
|
|
8080
8234
|
const swapMode = (opts.swapMode || opts.trigger?.getAttribute('g-swap') || 'inner').toLowerCase();
|
|
@@ -8099,6 +8253,7 @@ async function navigate(opts) {
|
|
|
8099
8253
|
if (hasTargetSpinner)
|
|
8100
8254
|
transaction.spinner = showTargetSpinner(target, swapMode);
|
|
8101
8255
|
const { finalUrl, init } = buildRequest(opts);
|
|
8256
|
+
context.url = finalUrl;
|
|
8102
8257
|
// Add abort signal to request
|
|
8103
8258
|
init.signal = transaction.controller.signal;
|
|
8104
8259
|
let html;
|
|
@@ -8126,7 +8281,8 @@ async function navigate(opts) {
|
|
|
8126
8281
|
if (error.name === 'AbortError')
|
|
8127
8282
|
throw error;
|
|
8128
8283
|
assertActiveNavigation(transaction);
|
|
8129
|
-
|
|
8284
|
+
context.outcome = 'network-error';
|
|
8285
|
+
fallback(finalUrl, true);
|
|
8130
8286
|
return;
|
|
8131
8287
|
}
|
|
8132
8288
|
preloadCache.delete(preloadKey); // consume cache
|
|
@@ -8151,28 +8307,46 @@ async function navigate(opts) {
|
|
|
8151
8307
|
log('[GyosRouter] Navigation cancelled');
|
|
8152
8308
|
return;
|
|
8153
8309
|
}
|
|
8310
|
+
context.outcome = 'network-error';
|
|
8154
8311
|
if (isActiveNavigation(transaction))
|
|
8155
|
-
|
|
8312
|
+
fallback(finalUrl, true);
|
|
8156
8313
|
return;
|
|
8157
8314
|
}
|
|
8158
8315
|
}
|
|
8159
8316
|
assertActiveNavigation(transaction);
|
|
8160
|
-
|
|
8161
|
-
|
|
8317
|
+
context.status = response?.status ?? null;
|
|
8318
|
+
context.url = response?.url || finalUrl;
|
|
8319
|
+
const acceptedErrors = (opts.trigger?.getAttribute('g-boost-errors') || '').split(/[\s,]+/);
|
|
8320
|
+
const renderHttpError = !!response && response.status >= 400 && response.status <= 599
|
|
8321
|
+
&& acceptedErrors.includes(String(response.status));
|
|
8322
|
+
if (response && !response.ok)
|
|
8323
|
+
context.outcome = 'http-error';
|
|
8324
|
+
if (!response || (!response.ok && !renderHttpError) || !isNavigableHtmlResponse(response)) {
|
|
8325
|
+
context.outcome ?? (context.outcome = 'invalid-response');
|
|
8162
8326
|
if (isActiveNavigation(transaction))
|
|
8163
|
-
|
|
8327
|
+
fallback(finalUrl, true);
|
|
8164
8328
|
return;
|
|
8165
8329
|
}
|
|
8166
8330
|
html = await response.text();
|
|
8167
8331
|
assertActiveNavigation(transaction);
|
|
8168
|
-
if (!opts.popstate && target.hasAttribute('g-snapshot')) {
|
|
8169
|
-
saveSnapshot(canonicalUrl(response.url || finalUrl), html);
|
|
8170
|
-
}
|
|
8171
8332
|
}
|
|
8172
8333
|
// Parse HTML
|
|
8173
8334
|
const doc = html
|
|
8174
8335
|
? parseNavigationDocument(html)
|
|
8175
8336
|
: document.implementation.createHTMLDocument();
|
|
8337
|
+
// Detached parsing cannot tell whether the live CSP permits an incoming base.
|
|
8338
|
+
// Let native navigation enforce base-uri instead of authorizing its URLs ourselves.
|
|
8339
|
+
if (doc.querySelector('base[href]') || opts.historyFragment?.querySelector('base[href]')) {
|
|
8340
|
+
context.outcome = 'invalid-response';
|
|
8341
|
+
fallback(response?.url || finalUrl, true);
|
|
8342
|
+
return;
|
|
8343
|
+
}
|
|
8344
|
+
if (response?.ok && !opts.popstate && target.hasAttribute('g-snapshot')) {
|
|
8345
|
+
saveSnapshot(canonicalUrl(response.url || finalUrl), html);
|
|
8346
|
+
}
|
|
8347
|
+
const syncDocumentAttributes = isFullOutletNavigation && destructiveSwap && !currentHead
|
|
8348
|
+
&& !opts.historyFragment && (opts.popstate && snapshots.has(urlWithoutHash)
|
|
8349
|
+
? snapshots.get(urlWithoutHash).fullDocument : isFullDocument(html || ''));
|
|
8176
8350
|
// Pick source fragment
|
|
8177
8351
|
const src = opts.historyFragment || pickSourceFragment(doc, target, targetOutletIndex);
|
|
8178
8352
|
stripInertFallbackContent(src);
|
|
@@ -8184,15 +8358,18 @@ async function navigate(opts) {
|
|
|
8184
8358
|
targetUrl += finalUrl.substring(finalUrl.indexOf('#'));
|
|
8185
8359
|
}
|
|
8186
8360
|
resolveIncomingScriptUrls(doc, targetUrl);
|
|
8361
|
+
context.url = targetUrl;
|
|
8187
8362
|
if (opts.historyFragment)
|
|
8188
8363
|
resolveIncomingScriptUrls(src, targetUrl);
|
|
8189
8364
|
const triggerChangesState = opts.trigger?.hasAttribute('g-change-state') || false;
|
|
8190
8365
|
const keepsCurrentState = opts.trigger?.hasAttribute('g-current-state') || false;
|
|
8191
8366
|
const redirectedSubmission = opts.method.toUpperCase() !== 'GET' && response?.redirected === true;
|
|
8192
|
-
const changesState = !keepsCurrentState && (opts.changeState === true || triggerChangesState || redirectedSubmission);
|
|
8367
|
+
const changesState = context.outcome !== 'http-error' && !keepsCurrentState && (opts.changeState === true || triggerChangesState || redirectedSubmission);
|
|
8193
8368
|
const performUpdate = async () => {
|
|
8194
8369
|
assertActiveNavigation(transaction);
|
|
8195
8370
|
transaction.committing = true;
|
|
8371
|
+
runNavigationHooks(beforeSwap, targetUrl, context);
|
|
8372
|
+
assertActiveNavigation(transaction);
|
|
8196
8373
|
// Update progress to rand 80 - 90% before swap
|
|
8197
8374
|
progressBar?.setProgress(Math.random() * 10 + 80);
|
|
8198
8375
|
const outgoingHistoryFragment = changesState && !opts.replace && !isFullOutletNavigation
|
|
@@ -8263,21 +8440,34 @@ async function navigate(opts) {
|
|
|
8263
8440
|
beforeScripts: async () => {
|
|
8264
8441
|
if (!isFullOutletNavigation || currentHead)
|
|
8265
8442
|
return;
|
|
8443
|
+
if (syncDocumentAttributes) {
|
|
8444
|
+
for (const name of ['lang', 'dir']) {
|
|
8445
|
+
const value = doc.documentElement.getAttribute(name);
|
|
8446
|
+
if (value === null)
|
|
8447
|
+
document.documentElement.removeAttribute(name);
|
|
8448
|
+
else
|
|
8449
|
+
document.documentElement.setAttribute(name, value);
|
|
8450
|
+
}
|
|
8451
|
+
}
|
|
8266
8452
|
const incomingTitle = doc.querySelector('title');
|
|
8267
8453
|
if (incomingTitle) {
|
|
8268
8454
|
document.title = incomingTitle.textContent || document.title;
|
|
8269
8455
|
}
|
|
8270
|
-
await updateHead(doc, transaction.controller.signal);
|
|
8456
|
+
await updateHead(doc, transaction.controller.signal, currentBaseUrl);
|
|
8271
8457
|
assertActiveNavigation(transaction);
|
|
8272
8458
|
},
|
|
8273
8459
|
onCommitted: (committedTarget, roots) => {
|
|
8274
8460
|
target = committedTarget;
|
|
8461
|
+
context.target = committedTarget;
|
|
8462
|
+
context.committed = true;
|
|
8463
|
+
progressBar?.reconnect();
|
|
8275
8464
|
committedRoots = roots;
|
|
8276
8465
|
}
|
|
8277
8466
|
});
|
|
8467
|
+
context.committed = true;
|
|
8278
8468
|
assertActiveNavigation(transaction);
|
|
8279
8469
|
if (isFullOutletNavigation) {
|
|
8280
|
-
await scriptNotInOutletTarget(doc, target, src, transaction.controller.signal);
|
|
8470
|
+
await scriptNotInOutletTarget(doc, target, src, transaction.controller.signal, currentBaseUrl);
|
|
8281
8471
|
assertActiveNavigation(transaction);
|
|
8282
8472
|
}
|
|
8283
8473
|
}
|
|
@@ -8311,14 +8501,15 @@ async function navigate(opts) {
|
|
|
8311
8501
|
await performUpdate();
|
|
8312
8502
|
}
|
|
8313
8503
|
assertActiveNavigation(transaction);
|
|
8314
|
-
if (removeTriggerAfterCommit && opts.trigger instanceof HTMLElement && opts.trigger.isConnected) {
|
|
8504
|
+
if (removeTriggerAfterCommit && context.outcome !== 'http-error' && opts.trigger instanceof HTMLElement && opts.trigger.isConnected) {
|
|
8315
8505
|
disposeEffects(opts.trigger);
|
|
8316
8506
|
opts.trigger.remove();
|
|
8317
8507
|
}
|
|
8318
8508
|
if (hasTargetSpinner)
|
|
8319
8509
|
hideTargetSpinner(transaction.spinner);
|
|
8320
8510
|
transaction.spinner = null;
|
|
8321
|
-
|
|
8511
|
+
context.outcome ?? (context.outcome = 'success');
|
|
8512
|
+
runNavigationHooks(afterNavigate, targetUrl, context);
|
|
8322
8513
|
log('[GyosRouter] navigated to', targetUrl);
|
|
8323
8514
|
currentUrl = changesState
|
|
8324
8515
|
? canonicalUrl(targetUrl, true)
|
|
@@ -8334,11 +8525,15 @@ async function navigate(opts) {
|
|
|
8334
8525
|
return;
|
|
8335
8526
|
}
|
|
8336
8527
|
if (isActiveNavigation(transaction)) {
|
|
8528
|
+
context.outcome ?? (context.outcome = 'error');
|
|
8337
8529
|
console.error('[GyosRouter] navigation error', error);
|
|
8338
|
-
|
|
8530
|
+
fallback(opts.url, true);
|
|
8339
8531
|
}
|
|
8340
8532
|
}
|
|
8341
8533
|
finally {
|
|
8534
|
+
if (transaction.controller.signal.aborted)
|
|
8535
|
+
context.outcome = 'aborted';
|
|
8536
|
+
context.outcome ?? (context.outcome = 'aborted');
|
|
8342
8537
|
if (transaction.interval)
|
|
8343
8538
|
clearInterval(transaction.interval);
|
|
8344
8539
|
if (transaction.spinner)
|
|
@@ -8348,6 +8543,15 @@ async function navigate(opts) {
|
|
|
8348
8543
|
progressBar?.complete();
|
|
8349
8544
|
}
|
|
8350
8545
|
transaction.resolveDone();
|
|
8546
|
+
if (formEvent)
|
|
8547
|
+
submittingForms.delete(formEvent.form);
|
|
8548
|
+
runNavigationHooks(navigationEnd, context.url, context);
|
|
8549
|
+
if (formEvent) {
|
|
8550
|
+
const { url, status, outcome, committed, fallback } = context;
|
|
8551
|
+
document.dispatchEvent(new CustomEvent('gyos:form-end', {
|
|
8552
|
+
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8553
|
+
}));
|
|
8554
|
+
}
|
|
8351
8555
|
}
|
|
8352
8556
|
}
|
|
8353
8557
|
function shouldBoost(el) {
|
|
@@ -8456,16 +8660,34 @@ function onSubmit(event) {
|
|
|
8456
8660
|
return;
|
|
8457
8661
|
if (shouldDeferToFormValidation(form))
|
|
8458
8662
|
return;
|
|
8459
|
-
event.
|
|
8460
|
-
const
|
|
8461
|
-
const
|
|
8462
|
-
const
|
|
8463
|
-
|
|
8464
|
-
|
|
8663
|
+
const submitter = event.submitter;
|
|
8664
|
+
const override = (name) => submitter?.getAttribute(`form${name}`) ?? form.getAttribute(name);
|
|
8665
|
+
const target = override('target') ?? document.querySelector('base[target]')?.getAttribute('target');
|
|
8666
|
+
const declaredMethod = (override('method') || 'GET').toUpperCase();
|
|
8667
|
+
const method = ['GET', 'POST', 'DIALOG'].includes(declaredMethod) ? declaredMethod : 'GET';
|
|
8668
|
+
const formEncoding = override('enctype')?.toLowerCase();
|
|
8669
|
+
if ((target && target.toLowerCase() !== '_self') || method === 'DIALOG' || formEncoding === 'text/plain')
|
|
8670
|
+
return;
|
|
8671
|
+
if (!resolveTarget(form))
|
|
8672
|
+
return;
|
|
8673
|
+
// Image submitters carry click coordinates which SubmitEvent does not expose.
|
|
8674
|
+
if (submitter instanceof HTMLInputElement && submitter.type === 'image')
|
|
8465
8675
|
return;
|
|
8676
|
+
let url;
|
|
8677
|
+
try {
|
|
8678
|
+
url = new URL(override('action') || window.location.href, document.baseURI);
|
|
8466
8679
|
}
|
|
8467
|
-
|
|
8468
|
-
|
|
8680
|
+
catch {
|
|
8681
|
+
return;
|
|
8682
|
+
}
|
|
8683
|
+
if (url.origin !== window.location.origin)
|
|
8684
|
+
return;
|
|
8685
|
+
event.preventDefault();
|
|
8686
|
+
if (submittingForms.has(form))
|
|
8687
|
+
return;
|
|
8688
|
+
const formData = new FormData(form, submitter);
|
|
8689
|
+
submittingForms.add(form);
|
|
8690
|
+
void navigate({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8469
8691
|
}
|
|
8470
8692
|
function onPopState(event) {
|
|
8471
8693
|
const url = window.location.href;
|
|
@@ -8570,13 +8792,15 @@ const Gyos = {
|
|
|
8570
8792
|
startRouter,
|
|
8571
8793
|
onBeforeNavigate,
|
|
8572
8794
|
onAfterNavigate,
|
|
8795
|
+
onBeforeSwap,
|
|
8796
|
+
onNavigationEnd,
|
|
8573
8797
|
portalCreate,
|
|
8574
8798
|
portalDestroy,
|
|
8575
8799
|
setCspNonce,
|
|
8576
|
-
version: '0.
|
|
8800
|
+
version: '0.4.1'
|
|
8577
8801
|
};
|
|
8578
8802
|
|
|
8579
8803
|
setExpressionRuntime(standardExpressionRuntime);
|
|
8580
8804
|
|
|
8581
|
-
export { applyDirective, applyTransitionStyles, batch, disposeEffects as cleanup, clearAllEvents, computed, debounce, Gyos as default, directive, effect, emit, getEventListeners, getGlobalContainer, getStoreNames, getTransitionConfig, getValidator, getValidatorNames, hasStore, inject, isComputed, isSignal, markRaw, mount, mountAll, mountTree, getAllMountedScopes as mountedScopes, nextTick, off, on, onAfterNavigate, onBeforeNavigate, once, pipe, portalCreate, portalDestroy, provide, ready, registerTransition, removeStore, scope, setCspNonce, shallow, signal, startRouter, store, throttle, unref, untrack, useAsync, useCounter, useDebounce, useFetch, useInterval, useLocalStorage, useMediaQuery, useMouse, useThrottle, useTimeout, useToggle, useWindowSize, validate, validator };
|
|
8805
|
+
export { applyDirective, applyTransitionStyles, batch, disposeEffects as cleanup, clearAllEvents, computed, debounce, Gyos as default, directive, effect, emit, getEventListeners, getGlobalContainer, getStoreNames, getTransitionConfig, getValidator, getValidatorNames, hasStore, inject, isComputed, isSignal, markRaw, mount, mountAll, mountTree, getAllMountedScopes as mountedScopes, nextTick, off, on, onAfterNavigate, onBeforeNavigate, onBeforeSwap, onNavigationEnd, once, pipe, portalCreate, portalDestroy, provide, ready, registerTransition, removeStore, scope, setCspNonce, shallow, signal, startRouter, store, throttle, unref, untrack, useAsync, useCounter, useDebounce, useFetch, useInterval, useLocalStorage, useMediaQuery, useMouse, useThrottle, useTimeout, useToggle, useWindowSize, validate, validator };
|
|
8582
8806
|
//# sourceMappingURL=gyos.esm.js.map
|