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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.
|
|
2
|
+
* GyosJS v0.6.0
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -8127,7 +8127,7 @@ function prepareNavigationHtml(html) {
|
|
|
8127
8127
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
8128
8128
|
*/
|
|
8129
8129
|
const submittingForms = new WeakSet();
|
|
8130
|
-
async function visit(url, options,
|
|
8130
|
+
async function visit(url, options, refreshPolicy) {
|
|
8131
8131
|
const destination = new URL(url, document.baseURI);
|
|
8132
8132
|
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
8133
8133
|
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
@@ -8144,18 +8144,23 @@ async function visit(url, options, fresh) {
|
|
|
8144
8144
|
url: destination.href, method: 'GET',
|
|
8145
8145
|
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
8146
8146
|
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
8147
|
-
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal,
|
|
8147
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, ...refreshPolicy,
|
|
8148
8148
|
onEnd: context => { result = context; }
|
|
8149
8149
|
});
|
|
8150
8150
|
return result;
|
|
8151
8151
|
}
|
|
8152
8152
|
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
8153
8153
|
function navigate(url, options = {}) {
|
|
8154
|
-
return visit(url, options
|
|
8154
|
+
return visit(url, options);
|
|
8155
8155
|
}
|
|
8156
8156
|
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
8157
|
-
function refresh(options = {}) {
|
|
8158
|
-
|
|
8157
|
+
function refresh({ background, strictSource, ...options } = {}) {
|
|
8158
|
+
if (strictSource === true && options.target === undefined) {
|
|
8159
|
+
return Promise.reject(new TypeError('Gyos.refresh with strictSource requires a target selector.'));
|
|
8160
|
+
}
|
|
8161
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, {
|
|
8162
|
+
fresh: true, background: background === true, strictSource: strictSource === true
|
|
8163
|
+
});
|
|
8159
8164
|
}
|
|
8160
8165
|
const snapshots = new Map();
|
|
8161
8166
|
const preloadCache = new Map();
|
|
@@ -8169,6 +8174,7 @@ let progressBarEnabled = true;
|
|
|
8169
8174
|
let currentUrl = canonicalUrl(window.location.href, true);
|
|
8170
8175
|
let currentHistoryEntryId = history.state?.gyosEntryId || null;
|
|
8171
8176
|
let activeNavigation = null;
|
|
8177
|
+
let waitingNavigations = 0;
|
|
8172
8178
|
// Global progress bar instance
|
|
8173
8179
|
let progressBar = null;
|
|
8174
8180
|
const beforeNavigate = [];
|
|
@@ -8562,19 +8568,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
8562
8568
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8563
8569
|
}
|
|
8564
8570
|
async function navigateRequest(opts) {
|
|
8565
|
-
const finishUnstarted = () => {
|
|
8571
|
+
const finishUnstarted = (signal = opts.signal) => {
|
|
8566
8572
|
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8567
8573
|
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8568
|
-
signal
|
|
8574
|
+
signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8569
8575
|
};
|
|
8570
8576
|
if (opts.signal?.aborted) {
|
|
8571
8577
|
finishUnstarted();
|
|
8572
8578
|
return;
|
|
8573
8579
|
}
|
|
8580
|
+
if (opts.background && (activeNavigation || waitingNavigations > 0)) {
|
|
8581
|
+
const skipped = new AbortController();
|
|
8582
|
+
skipped.abort();
|
|
8583
|
+
finishUnstarted(skipped.signal);
|
|
8584
|
+
return;
|
|
8585
|
+
}
|
|
8574
8586
|
while (activeNavigation) {
|
|
8575
8587
|
const previous = activeNavigation;
|
|
8576
8588
|
if (previous.committing) {
|
|
8577
8589
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8590
|
+
// End hooks can request a refresh before this waiter resumes.
|
|
8591
|
+
waitingNavigations++;
|
|
8578
8592
|
try {
|
|
8579
8593
|
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8580
8594
|
}
|
|
@@ -8582,6 +8596,9 @@ async function navigateRequest(opts) {
|
|
|
8582
8596
|
finishUnstarted();
|
|
8583
8597
|
return;
|
|
8584
8598
|
}
|
|
8599
|
+
finally {
|
|
8600
|
+
waitingNavigations--;
|
|
8601
|
+
}
|
|
8585
8602
|
continue;
|
|
8586
8603
|
}
|
|
8587
8604
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8616,14 +8633,16 @@ async function navigateRequest(opts) {
|
|
|
8616
8633
|
? { form: opts.form, url: opts.url, status: null, outcome: null, committed: false, fallback: false }
|
|
8617
8634
|
: null;
|
|
8618
8635
|
const fallback = (url, requestSent) => {
|
|
8619
|
-
context.fallback = context.method === 'GET' || (!requestSent && !!opts.form);
|
|
8636
|
+
context.fallback = !opts.background && (context.method === 'GET' || (!requestSent && !!opts.form));
|
|
8620
8637
|
context.outcome ?? (context.outcome = context.fallback ? 'fallback' : 'invalid-response');
|
|
8621
|
-
|
|
8638
|
+
if (!opts.background)
|
|
8639
|
+
fallbackFromBoost(opts, url, requestSent);
|
|
8622
8640
|
};
|
|
8641
|
+
const navigationProgress = opts.background ? null : progressBar;
|
|
8623
8642
|
const hasTargetSpinner = opts.trigger?.hasAttribute('g-router-spin');
|
|
8624
8643
|
const setRand = () => {
|
|
8625
|
-
if (isActiveNavigation(transaction) &&
|
|
8626
|
-
|
|
8644
|
+
if (isActiveNavigation(transaction) && navigationProgress && navigationProgress.getCurrentProgress() < 70) {
|
|
8645
|
+
navigationProgress.setProgress(navigationProgress.getCurrentProgress() + Math.random() * 8);
|
|
8627
8646
|
}
|
|
8628
8647
|
};
|
|
8629
8648
|
try {
|
|
@@ -8632,7 +8651,7 @@ async function navigateRequest(opts) {
|
|
|
8632
8651
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8633
8652
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
8634
8653
|
assertActiveNavigation(transaction);
|
|
8635
|
-
|
|
8654
|
+
navigationProgress?.start();
|
|
8636
8655
|
// popstate already points history at the destination entry. Keep the visible
|
|
8637
8656
|
// page's position under currentUrl without overwriting that destination state.
|
|
8638
8657
|
rememberScrollPosition(opts.scrollSourceEntryId ?? currentHistoryEntryId);
|
|
@@ -8721,15 +8740,16 @@ async function navigateRequest(opts) {
|
|
|
8721
8740
|
else {
|
|
8722
8741
|
try {
|
|
8723
8742
|
// Update progress to rand 20 - 30%
|
|
8724
|
-
|
|
8725
|
-
|
|
8743
|
+
navigationProgress?.setProgress(Math.random() * 10 + 20);
|
|
8744
|
+
if (navigationProgress)
|
|
8745
|
+
transaction.interval = setInterval(setRand, 300);
|
|
8726
8746
|
response = await fetch(finalUrl, init);
|
|
8727
8747
|
assertActiveNavigation(transaction);
|
|
8728
8748
|
// A successful write can change HTML at any URL, including after a redirect.
|
|
8729
8749
|
if (response.ok && init.method !== 'GET')
|
|
8730
8750
|
clearPreloads();
|
|
8731
8751
|
// Update progress to rand 70 - 80% after fetch
|
|
8732
|
-
|
|
8752
|
+
navigationProgress?.setProgress(Math.random() * 10 + 70);
|
|
8733
8753
|
if (transaction.interval)
|
|
8734
8754
|
clearInterval(transaction.interval);
|
|
8735
8755
|
transaction.interval = null;
|
|
@@ -8767,6 +8787,13 @@ async function navigateRequest(opts) {
|
|
|
8767
8787
|
const doc = html
|
|
8768
8788
|
? parseNavigationDocument(html)
|
|
8769
8789
|
: document.implementation.createHTMLDocument();
|
|
8790
|
+
const matchedSource = opts.strictSource && opts.targetSelector
|
|
8791
|
+
? doc.querySelector(opts.targetSelector)
|
|
8792
|
+
: null;
|
|
8793
|
+
if (opts.strictSource && !(matchedSource instanceof HTMLElement) && isFullDocument(html || '')) {
|
|
8794
|
+
context.outcome = 'invalid-response';
|
|
8795
|
+
return; // A complete response must identify the requested region before any swap or snapshot.
|
|
8796
|
+
}
|
|
8770
8797
|
// Detached parsing cannot tell whether the live CSP permits an incoming base.
|
|
8771
8798
|
// Let native navigation enforce base-uri instead of authorizing its URLs ourselves.
|
|
8772
8799
|
if (doc.querySelector('base[href]') || opts.historyFragment?.querySelector('base[href]')) {
|
|
@@ -8781,7 +8808,9 @@ async function navigateRequest(opts) {
|
|
|
8781
8808
|
&& !opts.historyFragment && (opts.popstate && snapshots.has(urlWithoutHash)
|
|
8782
8809
|
? snapshots.get(urlWithoutHash).fullDocument : isFullDocument(html || ''));
|
|
8783
8810
|
// Pick source fragment
|
|
8784
|
-
const src = opts.historyFragment ||
|
|
8811
|
+
const src = opts.historyFragment || (matchedSource instanceof HTMLElement
|
|
8812
|
+
? matchedSource
|
|
8813
|
+
: pickSourceFragment(doc, target, targetOutletIndex));
|
|
8785
8814
|
stripInertFallbackContent(src);
|
|
8786
8815
|
assertActiveNavigation(transaction);
|
|
8787
8816
|
// Final URL is response.url because in headers there could be redirects
|
|
@@ -8804,7 +8833,7 @@ async function navigateRequest(opts) {
|
|
|
8804
8833
|
runNavigationHooks(beforeSwap, targetUrl, context);
|
|
8805
8834
|
assertActiveNavigation(transaction);
|
|
8806
8835
|
// Update progress to rand 80 - 90% before swap
|
|
8807
|
-
|
|
8836
|
+
navigationProgress?.setProgress(Math.random() * 10 + 80);
|
|
8808
8837
|
const outgoingHistoryFragment = changesState && !opts.replace && !isFullOutletNavigation
|
|
8809
8838
|
? cloneHistoryTarget(target)
|
|
8810
8839
|
: null;
|
|
@@ -8902,7 +8931,7 @@ async function navigateRequest(opts) {
|
|
|
8902
8931
|
target = committedTarget;
|
|
8903
8932
|
context.target = committedTarget;
|
|
8904
8933
|
context.committed = true;
|
|
8905
|
-
|
|
8934
|
+
navigationProgress?.reconnect();
|
|
8906
8935
|
committedRoots = roots;
|
|
8907
8936
|
}
|
|
8908
8937
|
});
|
|
@@ -8934,7 +8963,7 @@ async function navigateRequest(opts) {
|
|
|
8934
8963
|
}
|
|
8935
8964
|
};
|
|
8936
8965
|
// Apply view transition if available
|
|
8937
|
-
if (document.startViewTransition) {
|
|
8966
|
+
if (!opts.background && document.startViewTransition) {
|
|
8938
8967
|
const transition = document.startViewTransition(() => performUpdate());
|
|
8939
8968
|
consumeViewTransitionRejection(transition?.ready);
|
|
8940
8969
|
consumeViewTransitionRejection(transition?.finished);
|
|
@@ -8985,7 +9014,7 @@ async function navigateRequest(opts) {
|
|
|
8985
9014
|
hideTargetSpinner(transaction.spinner);
|
|
8986
9015
|
if (activeNavigation?.id === transaction.id) {
|
|
8987
9016
|
activeNavigation = null;
|
|
8988
|
-
|
|
9017
|
+
navigationProgress?.complete();
|
|
8989
9018
|
}
|
|
8990
9019
|
opts.signal?.removeEventListener('abort', abort);
|
|
8991
9020
|
transaction.resolveDone();
|
|
@@ -9277,7 +9306,7 @@ const Gyos = {
|
|
|
9277
9306
|
portalCreate,
|
|
9278
9307
|
portalDestroy,
|
|
9279
9308
|
setCspNonce,
|
|
9280
|
-
version: '0.
|
|
9309
|
+
version: '0.6.0'
|
|
9281
9310
|
};
|
|
9282
9311
|
|
|
9283
9312
|
// This file was generated. Do not modify manually!
|