gyosjs 0.5.7 → 0.6.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/README.md +1 -1
- package/dist/core/router/router.d.ts +9 -1
- package/dist/core/router/router.d.ts.map +1 -1
- package/dist/gyos.auto.esm.js +86 -31
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +86 -31
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +86 -31
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +86 -31
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +86 -31
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +86 -31
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +86 -31
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +86 -31
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/public-api.d.ts +1 -1
- package/dist/public-api.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/gyos.auto.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.
|
|
2
|
+
* GyosJS v0.6.0
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -7667,8 +7667,10 @@
|
|
|
7667
7667
|
while (idx < toChildren.length || idx < fromChildren.length) {
|
|
7668
7668
|
const toChild = toChildren[idx] || null;
|
|
7669
7669
|
let fromChild = fromChildren[idx] || null;
|
|
7670
|
-
//
|
|
7671
|
-
|
|
7670
|
+
// Persist placeholders have their own placement path below, even when
|
|
7671
|
+
// they also carry an id or another explicit morph key.
|
|
7672
|
+
const toPersistKey = getPersistKey(toChild);
|
|
7673
|
+
const requestedKey = toPersistKey ? null : explicitKeyFor(toChild);
|
|
7672
7674
|
if (requestedKey && explicitKeyFor(fromChild) !== requestedKey) {
|
|
7673
7675
|
const matchingIndex = fromChildren.findIndex((candidate, candidateIndex) => candidateIndex > idx && explicitKeyFor(candidate) === requestedKey);
|
|
7674
7676
|
if (matchingIndex !== -1) {
|
|
@@ -7683,7 +7685,6 @@
|
|
|
7683
7685
|
}
|
|
7684
7686
|
}
|
|
7685
7687
|
// Check if either is persist comment/element
|
|
7686
|
-
const toPersistKey = getPersistKey(toChild);
|
|
7687
7688
|
const fromPersistKey = getPersistKey(fromChild);
|
|
7688
7689
|
// If toChild is persist, check if we already have matching persist in fromChildren
|
|
7689
7690
|
if (toPersistKey) {
|
|
@@ -8118,7 +8119,7 @@
|
|
|
8118
8119
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
8119
8120
|
*/
|
|
8120
8121
|
const submittingForms = new WeakSet();
|
|
8121
|
-
async function visit(url, options,
|
|
8122
|
+
async function visit(url, options, refreshPolicy) {
|
|
8122
8123
|
const destination = new URL(url, document.baseURI);
|
|
8123
8124
|
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
8124
8125
|
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
@@ -8135,21 +8136,27 @@
|
|
|
8135
8136
|
url: destination.href, method: 'GET',
|
|
8136
8137
|
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
8137
8138
|
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
8138
|
-
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal,
|
|
8139
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, ...refreshPolicy,
|
|
8139
8140
|
onEnd: context => { result = context; }
|
|
8140
8141
|
});
|
|
8141
8142
|
return result;
|
|
8142
8143
|
}
|
|
8143
8144
|
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
8144
8145
|
function navigate(url, options = {}) {
|
|
8145
|
-
return visit(url, options
|
|
8146
|
+
return visit(url, options);
|
|
8146
8147
|
}
|
|
8147
8148
|
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
8148
|
-
function refresh(options = {}) {
|
|
8149
|
-
|
|
8149
|
+
function refresh({ background, strictSource, ...options } = {}) {
|
|
8150
|
+
if (strictSource === true && options.target === undefined) {
|
|
8151
|
+
return Promise.reject(new TypeError('Gyos.refresh with strictSource requires a target selector.'));
|
|
8152
|
+
}
|
|
8153
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, {
|
|
8154
|
+
fresh: true, background: background === true, strictSource: strictSource === true
|
|
8155
|
+
});
|
|
8150
8156
|
}
|
|
8151
8157
|
const snapshots = new Map();
|
|
8152
8158
|
const preloadCache = new Map();
|
|
8159
|
+
let preloadHover;
|
|
8153
8160
|
const scrollPositions = new Map();
|
|
8154
8161
|
const historyFragments = new Map();
|
|
8155
8162
|
let routerStarted = false;
|
|
@@ -8159,6 +8166,7 @@
|
|
|
8159
8166
|
let currentUrl = canonicalUrl(window.location.href, true);
|
|
8160
8167
|
let currentHistoryEntryId = history.state?.gyosEntryId || null;
|
|
8161
8168
|
let activeNavigation = null;
|
|
8169
|
+
let waitingNavigations = 0;
|
|
8162
8170
|
// Global progress bar instance
|
|
8163
8171
|
let progressBar = null;
|
|
8164
8172
|
const beforeNavigate = [];
|
|
@@ -8204,6 +8212,8 @@
|
|
|
8204
8212
|
document.addEventListener('click', onClick);
|
|
8205
8213
|
document.addEventListener('submit', onSubmit);
|
|
8206
8214
|
document.addEventListener('mouseover', onMouseOverCapture, true);
|
|
8215
|
+
document.addEventListener('mousemove', onPreloadMouseMove, true);
|
|
8216
|
+
document.addEventListener('mouseleave', clearPreloadHover);
|
|
8207
8217
|
window.addEventListener('popstate', onPopState);
|
|
8208
8218
|
if ('scrollRestoration' in history) {
|
|
8209
8219
|
history.scrollRestoration = 'manual';
|
|
@@ -8475,6 +8485,7 @@
|
|
|
8475
8485
|
entry?.controller.abort();
|
|
8476
8486
|
}
|
|
8477
8487
|
function clearPreloads() {
|
|
8488
|
+
clearPreloadHover();
|
|
8478
8489
|
for (const key of preloadCache.keys())
|
|
8479
8490
|
discardPreload(key);
|
|
8480
8491
|
}
|
|
@@ -8549,19 +8560,27 @@
|
|
|
8549
8560
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8550
8561
|
}
|
|
8551
8562
|
async function navigateRequest(opts) {
|
|
8552
|
-
const finishUnstarted = () => {
|
|
8563
|
+
const finishUnstarted = (signal = opts.signal) => {
|
|
8553
8564
|
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8554
8565
|
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8555
|
-
signal
|
|
8566
|
+
signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8556
8567
|
};
|
|
8557
8568
|
if (opts.signal?.aborted) {
|
|
8558
8569
|
finishUnstarted();
|
|
8559
8570
|
return;
|
|
8560
8571
|
}
|
|
8572
|
+
if (opts.background && (activeNavigation || waitingNavigations > 0)) {
|
|
8573
|
+
const skipped = new AbortController();
|
|
8574
|
+
skipped.abort();
|
|
8575
|
+
finishUnstarted(skipped.signal);
|
|
8576
|
+
return;
|
|
8577
|
+
}
|
|
8561
8578
|
while (activeNavigation) {
|
|
8562
8579
|
const previous = activeNavigation;
|
|
8563
8580
|
if (previous.committing) {
|
|
8564
8581
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8582
|
+
// End hooks can request a refresh before this waiter resumes.
|
|
8583
|
+
waitingNavigations++;
|
|
8565
8584
|
try {
|
|
8566
8585
|
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8567
8586
|
}
|
|
@@ -8569,6 +8588,9 @@
|
|
|
8569
8588
|
finishUnstarted();
|
|
8570
8589
|
return;
|
|
8571
8590
|
}
|
|
8591
|
+
finally {
|
|
8592
|
+
waitingNavigations--;
|
|
8593
|
+
}
|
|
8572
8594
|
continue;
|
|
8573
8595
|
}
|
|
8574
8596
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8603,14 +8625,16 @@
|
|
|
8603
8625
|
? { form: opts.form, url: opts.url, status: null, outcome: null, committed: false, fallback: false }
|
|
8604
8626
|
: null;
|
|
8605
8627
|
const fallback = (url, requestSent) => {
|
|
8606
|
-
context.fallback = context.method === 'GET' || (!requestSent && !!opts.form);
|
|
8628
|
+
context.fallback = !opts.background && (context.method === 'GET' || (!requestSent && !!opts.form));
|
|
8607
8629
|
context.outcome ?? (context.outcome = context.fallback ? 'fallback' : 'invalid-response');
|
|
8608
|
-
|
|
8630
|
+
if (!opts.background)
|
|
8631
|
+
fallbackFromBoost(opts, url, requestSent);
|
|
8609
8632
|
};
|
|
8633
|
+
const navigationProgress = opts.background ? null : progressBar;
|
|
8610
8634
|
const hasTargetSpinner = opts.trigger?.hasAttribute('g-router-spin');
|
|
8611
8635
|
const setRand = () => {
|
|
8612
|
-
if (isActiveNavigation(transaction) &&
|
|
8613
|
-
|
|
8636
|
+
if (isActiveNavigation(transaction) && navigationProgress && navigationProgress.getCurrentProgress() < 70) {
|
|
8637
|
+
navigationProgress.setProgress(navigationProgress.getCurrentProgress() + Math.random() * 8);
|
|
8614
8638
|
}
|
|
8615
8639
|
};
|
|
8616
8640
|
try {
|
|
@@ -8619,7 +8643,7 @@
|
|
|
8619
8643
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8620
8644
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
8621
8645
|
assertActiveNavigation(transaction);
|
|
8622
|
-
|
|
8646
|
+
navigationProgress?.start();
|
|
8623
8647
|
// popstate already points history at the destination entry. Keep the visible
|
|
8624
8648
|
// page's position under currentUrl without overwriting that destination state.
|
|
8625
8649
|
rememberScrollPosition(opts.scrollSourceEntryId ?? currentHistoryEntryId);
|
|
@@ -8688,6 +8712,8 @@
|
|
|
8688
8712
|
signal.addEventListener('abort', discard, { once: true });
|
|
8689
8713
|
try {
|
|
8690
8714
|
response = await waitForNavigation(entry.request, signal);
|
|
8715
|
+
if (response.ok && preloadHover?.url === preloadKey)
|
|
8716
|
+
preloadHover.used = true;
|
|
8691
8717
|
}
|
|
8692
8718
|
catch (error) {
|
|
8693
8719
|
if (error.name === 'AbortError')
|
|
@@ -8706,15 +8732,16 @@
|
|
|
8706
8732
|
else {
|
|
8707
8733
|
try {
|
|
8708
8734
|
// Update progress to rand 20 - 30%
|
|
8709
|
-
|
|
8710
|
-
|
|
8735
|
+
navigationProgress?.setProgress(Math.random() * 10 + 20);
|
|
8736
|
+
if (navigationProgress)
|
|
8737
|
+
transaction.interval = setInterval(setRand, 300);
|
|
8711
8738
|
response = await fetch(finalUrl, init);
|
|
8712
8739
|
assertActiveNavigation(transaction);
|
|
8713
8740
|
// A successful write can change HTML at any URL, including after a redirect.
|
|
8714
8741
|
if (response.ok && init.method !== 'GET')
|
|
8715
8742
|
clearPreloads();
|
|
8716
8743
|
// Update progress to rand 70 - 80% after fetch
|
|
8717
|
-
|
|
8744
|
+
navigationProgress?.setProgress(Math.random() * 10 + 70);
|
|
8718
8745
|
if (transaction.interval)
|
|
8719
8746
|
clearInterval(transaction.interval);
|
|
8720
8747
|
transaction.interval = null;
|
|
@@ -8752,6 +8779,13 @@
|
|
|
8752
8779
|
const doc = html
|
|
8753
8780
|
? parseNavigationDocument(html)
|
|
8754
8781
|
: document.implementation.createHTMLDocument();
|
|
8782
|
+
const matchedSource = opts.strictSource && opts.targetSelector
|
|
8783
|
+
? doc.querySelector(opts.targetSelector)
|
|
8784
|
+
: null;
|
|
8785
|
+
if (opts.strictSource && !(matchedSource instanceof HTMLElement) && isFullDocument(html || '')) {
|
|
8786
|
+
context.outcome = 'invalid-response';
|
|
8787
|
+
return; // A complete response must identify the requested region before any swap or snapshot.
|
|
8788
|
+
}
|
|
8755
8789
|
// Detached parsing cannot tell whether the live CSP permits an incoming base.
|
|
8756
8790
|
// Let native navigation enforce base-uri instead of authorizing its URLs ourselves.
|
|
8757
8791
|
if (doc.querySelector('base[href]') || opts.historyFragment?.querySelector('base[href]')) {
|
|
@@ -8766,7 +8800,9 @@
|
|
|
8766
8800
|
&& !opts.historyFragment && (opts.popstate && snapshots.has(urlWithoutHash)
|
|
8767
8801
|
? snapshots.get(urlWithoutHash).fullDocument : isFullDocument(html || ''));
|
|
8768
8802
|
// Pick source fragment
|
|
8769
|
-
const src = opts.historyFragment ||
|
|
8803
|
+
const src = opts.historyFragment || (matchedSource instanceof HTMLElement
|
|
8804
|
+
? matchedSource
|
|
8805
|
+
: pickSourceFragment(doc, target, targetOutletIndex));
|
|
8770
8806
|
stripInertFallbackContent(src);
|
|
8771
8807
|
assertActiveNavigation(transaction);
|
|
8772
8808
|
// Final URL is response.url because in headers there could be redirects
|
|
@@ -8789,7 +8825,7 @@
|
|
|
8789
8825
|
runNavigationHooks(beforeSwap, targetUrl, context);
|
|
8790
8826
|
assertActiveNavigation(transaction);
|
|
8791
8827
|
// Update progress to rand 80 - 90% before swap
|
|
8792
|
-
|
|
8828
|
+
navigationProgress?.setProgress(Math.random() * 10 + 80);
|
|
8793
8829
|
const outgoingHistoryFragment = changesState && !opts.replace && !isFullOutletNavigation
|
|
8794
8830
|
? cloneHistoryTarget(target)
|
|
8795
8831
|
: null;
|
|
@@ -8887,7 +8923,7 @@
|
|
|
8887
8923
|
target = committedTarget;
|
|
8888
8924
|
context.target = committedTarget;
|
|
8889
8925
|
context.committed = true;
|
|
8890
|
-
|
|
8926
|
+
navigationProgress?.reconnect();
|
|
8891
8927
|
committedRoots = roots;
|
|
8892
8928
|
}
|
|
8893
8929
|
});
|
|
@@ -8919,7 +8955,7 @@
|
|
|
8919
8955
|
}
|
|
8920
8956
|
};
|
|
8921
8957
|
// Apply view transition if available
|
|
8922
|
-
if (document.startViewTransition) {
|
|
8958
|
+
if (!opts.background && document.startViewTransition) {
|
|
8923
8959
|
const transition = document.startViewTransition(() => performUpdate());
|
|
8924
8960
|
consumeViewTransitionRejection(transition?.ready);
|
|
8925
8961
|
consumeViewTransitionRejection(transition?.finished);
|
|
@@ -8970,7 +9006,7 @@
|
|
|
8970
9006
|
hideTargetSpinner(transaction.spinner);
|
|
8971
9007
|
if (activeNavigation?.id === transaction.id) {
|
|
8972
9008
|
activeNavigation = null;
|
|
8973
|
-
|
|
9009
|
+
navigationProgress?.complete();
|
|
8974
9010
|
}
|
|
8975
9011
|
opts.signal?.removeEventListener('abort', abort);
|
|
8976
9012
|
transaction.resolveDone();
|
|
@@ -9082,15 +9118,34 @@
|
|
|
9082
9118
|
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
9083
9119
|
}
|
|
9084
9120
|
function onMouseOverCapture(event) {
|
|
9085
|
-
const
|
|
9086
|
-
if (!target)
|
|
9087
|
-
return;
|
|
9088
|
-
const link = target.closest('a[g-preload]');
|
|
9121
|
+
const link = event.target instanceof Element ? event.target.closest('a[g-preload]') : null;
|
|
9089
9122
|
if (!link)
|
|
9090
9123
|
return;
|
|
9091
9124
|
const url = eligibleAnchorUrl(link);
|
|
9092
|
-
if (url)
|
|
9093
|
-
|
|
9125
|
+
if (!url)
|
|
9126
|
+
return;
|
|
9127
|
+
const hover = preloadHover;
|
|
9128
|
+
if (hover?.used && hover.url === url.href && ((event.clientX === hover.x && event.clientY === hover.y) ||
|
|
9129
|
+
(event.relatedTarget instanceof Node && link.contains(event.relatedTarget))))
|
|
9130
|
+
return;
|
|
9131
|
+
preloadHover = { url: url.href, x: event.clientX, y: event.clientY, used: false };
|
|
9132
|
+
preload(url.href);
|
|
9133
|
+
}
|
|
9134
|
+
function onPreloadMouseMove(event) {
|
|
9135
|
+
const hover = preloadHover;
|
|
9136
|
+
// The browser can retarget mouse events after a swap with the pointer still in place.
|
|
9137
|
+
if (!hover || (event.clientX === hover.x && event.clientY === hover.y))
|
|
9138
|
+
return;
|
|
9139
|
+
const link = event.target instanceof Element ? event.target.closest('a[g-preload]') : null;
|
|
9140
|
+
if (!(link instanceof HTMLAnchorElement) || link.href !== hover.url) {
|
|
9141
|
+
clearPreloadHover();
|
|
9142
|
+
return;
|
|
9143
|
+
}
|
|
9144
|
+
hover.x = event.clientX;
|
|
9145
|
+
hover.y = event.clientY;
|
|
9146
|
+
}
|
|
9147
|
+
function clearPreloadHover() {
|
|
9148
|
+
preloadHover = undefined;
|
|
9094
9149
|
}
|
|
9095
9150
|
function onSubmit(event) {
|
|
9096
9151
|
if (event.defaultPrevented)
|
|
@@ -9243,7 +9298,7 @@
|
|
|
9243
9298
|
portalCreate,
|
|
9244
9299
|
portalDestroy,
|
|
9245
9300
|
setCspNonce,
|
|
9246
|
-
version: '0.
|
|
9301
|
+
version: '0.6.0'
|
|
9247
9302
|
};
|
|
9248
9303
|
|
|
9249
9304
|
const standardExpressionRuntime = {
|