gyosjs 0.5.8 → 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 +51 -22
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +51 -22
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +51 -22
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +51 -22
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +51 -22
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +51 -22
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +51 -22
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +51 -22
- 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
|
*/
|
|
@@ -8119,7 +8119,7 @@
|
|
|
8119
8119
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
8120
8120
|
*/
|
|
8121
8121
|
const submittingForms = new WeakSet();
|
|
8122
|
-
async function visit(url, options,
|
|
8122
|
+
async function visit(url, options, refreshPolicy) {
|
|
8123
8123
|
const destination = new URL(url, document.baseURI);
|
|
8124
8124
|
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
8125
8125
|
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
@@ -8136,18 +8136,23 @@
|
|
|
8136
8136
|
url: destination.href, method: 'GET',
|
|
8137
8137
|
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
8138
8138
|
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
8139
|
-
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal,
|
|
8139
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, ...refreshPolicy,
|
|
8140
8140
|
onEnd: context => { result = context; }
|
|
8141
8141
|
});
|
|
8142
8142
|
return result;
|
|
8143
8143
|
}
|
|
8144
8144
|
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
8145
8145
|
function navigate(url, options = {}) {
|
|
8146
|
-
return visit(url, options
|
|
8146
|
+
return visit(url, options);
|
|
8147
8147
|
}
|
|
8148
8148
|
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
8149
|
-
function refresh(options = {}) {
|
|
8150
|
-
|
|
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
|
+
});
|
|
8151
8156
|
}
|
|
8152
8157
|
const snapshots = new Map();
|
|
8153
8158
|
const preloadCache = new Map();
|
|
@@ -8161,6 +8166,7 @@
|
|
|
8161
8166
|
let currentUrl = canonicalUrl(window.location.href, true);
|
|
8162
8167
|
let currentHistoryEntryId = history.state?.gyosEntryId || null;
|
|
8163
8168
|
let activeNavigation = null;
|
|
8169
|
+
let waitingNavigations = 0;
|
|
8164
8170
|
// Global progress bar instance
|
|
8165
8171
|
let progressBar = null;
|
|
8166
8172
|
const beforeNavigate = [];
|
|
@@ -8554,19 +8560,27 @@
|
|
|
8554
8560
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8555
8561
|
}
|
|
8556
8562
|
async function navigateRequest(opts) {
|
|
8557
|
-
const finishUnstarted = () => {
|
|
8563
|
+
const finishUnstarted = (signal = opts.signal) => {
|
|
8558
8564
|
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8559
8565
|
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8560
|
-
signal
|
|
8566
|
+
signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8561
8567
|
};
|
|
8562
8568
|
if (opts.signal?.aborted) {
|
|
8563
8569
|
finishUnstarted();
|
|
8564
8570
|
return;
|
|
8565
8571
|
}
|
|
8572
|
+
if (opts.background && (activeNavigation || waitingNavigations > 0)) {
|
|
8573
|
+
const skipped = new AbortController();
|
|
8574
|
+
skipped.abort();
|
|
8575
|
+
finishUnstarted(skipped.signal);
|
|
8576
|
+
return;
|
|
8577
|
+
}
|
|
8566
8578
|
while (activeNavigation) {
|
|
8567
8579
|
const previous = activeNavigation;
|
|
8568
8580
|
if (previous.committing) {
|
|
8569
8581
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8582
|
+
// End hooks can request a refresh before this waiter resumes.
|
|
8583
|
+
waitingNavigations++;
|
|
8570
8584
|
try {
|
|
8571
8585
|
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8572
8586
|
}
|
|
@@ -8574,6 +8588,9 @@
|
|
|
8574
8588
|
finishUnstarted();
|
|
8575
8589
|
return;
|
|
8576
8590
|
}
|
|
8591
|
+
finally {
|
|
8592
|
+
waitingNavigations--;
|
|
8593
|
+
}
|
|
8577
8594
|
continue;
|
|
8578
8595
|
}
|
|
8579
8596
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8608,14 +8625,16 @@
|
|
|
8608
8625
|
? { form: opts.form, url: opts.url, status: null, outcome: null, committed: false, fallback: false }
|
|
8609
8626
|
: null;
|
|
8610
8627
|
const fallback = (url, requestSent) => {
|
|
8611
|
-
context.fallback = context.method === 'GET' || (!requestSent && !!opts.form);
|
|
8628
|
+
context.fallback = !opts.background && (context.method === 'GET' || (!requestSent && !!opts.form));
|
|
8612
8629
|
context.outcome ?? (context.outcome = context.fallback ? 'fallback' : 'invalid-response');
|
|
8613
|
-
|
|
8630
|
+
if (!opts.background)
|
|
8631
|
+
fallbackFromBoost(opts, url, requestSent);
|
|
8614
8632
|
};
|
|
8633
|
+
const navigationProgress = opts.background ? null : progressBar;
|
|
8615
8634
|
const hasTargetSpinner = opts.trigger?.hasAttribute('g-router-spin');
|
|
8616
8635
|
const setRand = () => {
|
|
8617
|
-
if (isActiveNavigation(transaction) &&
|
|
8618
|
-
|
|
8636
|
+
if (isActiveNavigation(transaction) && navigationProgress && navigationProgress.getCurrentProgress() < 70) {
|
|
8637
|
+
navigationProgress.setProgress(navigationProgress.getCurrentProgress() + Math.random() * 8);
|
|
8619
8638
|
}
|
|
8620
8639
|
};
|
|
8621
8640
|
try {
|
|
@@ -8624,7 +8643,7 @@
|
|
|
8624
8643
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8625
8644
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
8626
8645
|
assertActiveNavigation(transaction);
|
|
8627
|
-
|
|
8646
|
+
navigationProgress?.start();
|
|
8628
8647
|
// popstate already points history at the destination entry. Keep the visible
|
|
8629
8648
|
// page's position under currentUrl without overwriting that destination state.
|
|
8630
8649
|
rememberScrollPosition(opts.scrollSourceEntryId ?? currentHistoryEntryId);
|
|
@@ -8713,15 +8732,16 @@
|
|
|
8713
8732
|
else {
|
|
8714
8733
|
try {
|
|
8715
8734
|
// Update progress to rand 20 - 30%
|
|
8716
|
-
|
|
8717
|
-
|
|
8735
|
+
navigationProgress?.setProgress(Math.random() * 10 + 20);
|
|
8736
|
+
if (navigationProgress)
|
|
8737
|
+
transaction.interval = setInterval(setRand, 300);
|
|
8718
8738
|
response = await fetch(finalUrl, init);
|
|
8719
8739
|
assertActiveNavigation(transaction);
|
|
8720
8740
|
// A successful write can change HTML at any URL, including after a redirect.
|
|
8721
8741
|
if (response.ok && init.method !== 'GET')
|
|
8722
8742
|
clearPreloads();
|
|
8723
8743
|
// Update progress to rand 70 - 80% after fetch
|
|
8724
|
-
|
|
8744
|
+
navigationProgress?.setProgress(Math.random() * 10 + 70);
|
|
8725
8745
|
if (transaction.interval)
|
|
8726
8746
|
clearInterval(transaction.interval);
|
|
8727
8747
|
transaction.interval = null;
|
|
@@ -8759,6 +8779,13 @@
|
|
|
8759
8779
|
const doc = html
|
|
8760
8780
|
? parseNavigationDocument(html)
|
|
8761
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
|
+
}
|
|
8762
8789
|
// Detached parsing cannot tell whether the live CSP permits an incoming base.
|
|
8763
8790
|
// Let native navigation enforce base-uri instead of authorizing its URLs ourselves.
|
|
8764
8791
|
if (doc.querySelector('base[href]') || opts.historyFragment?.querySelector('base[href]')) {
|
|
@@ -8773,7 +8800,9 @@
|
|
|
8773
8800
|
&& !opts.historyFragment && (opts.popstate && snapshots.has(urlWithoutHash)
|
|
8774
8801
|
? snapshots.get(urlWithoutHash).fullDocument : isFullDocument(html || ''));
|
|
8775
8802
|
// Pick source fragment
|
|
8776
|
-
const src = opts.historyFragment ||
|
|
8803
|
+
const src = opts.historyFragment || (matchedSource instanceof HTMLElement
|
|
8804
|
+
? matchedSource
|
|
8805
|
+
: pickSourceFragment(doc, target, targetOutletIndex));
|
|
8777
8806
|
stripInertFallbackContent(src);
|
|
8778
8807
|
assertActiveNavigation(transaction);
|
|
8779
8808
|
// Final URL is response.url because in headers there could be redirects
|
|
@@ -8796,7 +8825,7 @@
|
|
|
8796
8825
|
runNavigationHooks(beforeSwap, targetUrl, context);
|
|
8797
8826
|
assertActiveNavigation(transaction);
|
|
8798
8827
|
// Update progress to rand 80 - 90% before swap
|
|
8799
|
-
|
|
8828
|
+
navigationProgress?.setProgress(Math.random() * 10 + 80);
|
|
8800
8829
|
const outgoingHistoryFragment = changesState && !opts.replace && !isFullOutletNavigation
|
|
8801
8830
|
? cloneHistoryTarget(target)
|
|
8802
8831
|
: null;
|
|
@@ -8894,7 +8923,7 @@
|
|
|
8894
8923
|
target = committedTarget;
|
|
8895
8924
|
context.target = committedTarget;
|
|
8896
8925
|
context.committed = true;
|
|
8897
|
-
|
|
8926
|
+
navigationProgress?.reconnect();
|
|
8898
8927
|
committedRoots = roots;
|
|
8899
8928
|
}
|
|
8900
8929
|
});
|
|
@@ -8926,7 +8955,7 @@
|
|
|
8926
8955
|
}
|
|
8927
8956
|
};
|
|
8928
8957
|
// Apply view transition if available
|
|
8929
|
-
if (document.startViewTransition) {
|
|
8958
|
+
if (!opts.background && document.startViewTransition) {
|
|
8930
8959
|
const transition = document.startViewTransition(() => performUpdate());
|
|
8931
8960
|
consumeViewTransitionRejection(transition?.ready);
|
|
8932
8961
|
consumeViewTransitionRejection(transition?.finished);
|
|
@@ -8977,7 +9006,7 @@
|
|
|
8977
9006
|
hideTargetSpinner(transaction.spinner);
|
|
8978
9007
|
if (activeNavigation?.id === transaction.id) {
|
|
8979
9008
|
activeNavigation = null;
|
|
8980
|
-
|
|
9009
|
+
navigationProgress?.complete();
|
|
8981
9010
|
}
|
|
8982
9011
|
opts.signal?.removeEventListener('abort', abort);
|
|
8983
9012
|
transaction.resolveDone();
|
|
@@ -9269,7 +9298,7 @@
|
|
|
9269
9298
|
portalCreate,
|
|
9270
9299
|
portalDestroy,
|
|
9271
9300
|
setCspNonce,
|
|
9272
|
-
version: '0.
|
|
9301
|
+
version: '0.6.0'
|
|
9273
9302
|
};
|
|
9274
9303
|
|
|
9275
9304
|
const standardExpressionRuntime = {
|