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.esm.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
|
*/
|
|
@@ -8145,7 +8145,7 @@ function prepareNavigationHtml(html) {
|
|
|
8145
8145
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
8146
8146
|
*/
|
|
8147
8147
|
const submittingForms = new WeakSet();
|
|
8148
|
-
async function visit(url, options,
|
|
8148
|
+
async function visit(url, options, refreshPolicy) {
|
|
8149
8149
|
const destination = new URL(url, document.baseURI);
|
|
8150
8150
|
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
8151
8151
|
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
@@ -8162,18 +8162,23 @@ async function visit(url, options, fresh) {
|
|
|
8162
8162
|
url: destination.href, method: 'GET',
|
|
8163
8163
|
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
8164
8164
|
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
8165
|
-
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal,
|
|
8165
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, ...refreshPolicy,
|
|
8166
8166
|
onEnd: context => { result = context; }
|
|
8167
8167
|
});
|
|
8168
8168
|
return result;
|
|
8169
8169
|
}
|
|
8170
8170
|
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
8171
8171
|
function navigate(url, options = {}) {
|
|
8172
|
-
return visit(url, options
|
|
8172
|
+
return visit(url, options);
|
|
8173
8173
|
}
|
|
8174
8174
|
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
8175
|
-
function refresh(options = {}) {
|
|
8176
|
-
|
|
8175
|
+
function refresh({ background, strictSource, ...options } = {}) {
|
|
8176
|
+
if (strictSource === true && options.target === undefined) {
|
|
8177
|
+
return Promise.reject(new TypeError('Gyos.refresh with strictSource requires a target selector.'));
|
|
8178
|
+
}
|
|
8179
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, {
|
|
8180
|
+
fresh: true, background: background === true, strictSource: strictSource === true
|
|
8181
|
+
});
|
|
8177
8182
|
}
|
|
8178
8183
|
const snapshots = new Map();
|
|
8179
8184
|
const preloadCache = new Map();
|
|
@@ -8187,6 +8192,7 @@ let progressBarEnabled = true;
|
|
|
8187
8192
|
let currentUrl = canonicalUrl(window.location.href, true);
|
|
8188
8193
|
let currentHistoryEntryId = history.state?.gyosEntryId || null;
|
|
8189
8194
|
let activeNavigation = null;
|
|
8195
|
+
let waitingNavigations = 0;
|
|
8190
8196
|
// Global progress bar instance
|
|
8191
8197
|
let progressBar = null;
|
|
8192
8198
|
const beforeNavigate = [];
|
|
@@ -8580,19 +8586,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
8580
8586
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8581
8587
|
}
|
|
8582
8588
|
async function navigateRequest(opts) {
|
|
8583
|
-
const finishUnstarted = () => {
|
|
8589
|
+
const finishUnstarted = (signal = opts.signal) => {
|
|
8584
8590
|
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8585
8591
|
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8586
|
-
signal
|
|
8592
|
+
signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8587
8593
|
};
|
|
8588
8594
|
if (opts.signal?.aborted) {
|
|
8589
8595
|
finishUnstarted();
|
|
8590
8596
|
return;
|
|
8591
8597
|
}
|
|
8598
|
+
if (opts.background && (activeNavigation || waitingNavigations > 0)) {
|
|
8599
|
+
const skipped = new AbortController();
|
|
8600
|
+
skipped.abort();
|
|
8601
|
+
finishUnstarted(skipped.signal);
|
|
8602
|
+
return;
|
|
8603
|
+
}
|
|
8592
8604
|
while (activeNavigation) {
|
|
8593
8605
|
const previous = activeNavigation;
|
|
8594
8606
|
if (previous.committing) {
|
|
8595
8607
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8608
|
+
// End hooks can request a refresh before this waiter resumes.
|
|
8609
|
+
waitingNavigations++;
|
|
8596
8610
|
try {
|
|
8597
8611
|
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8598
8612
|
}
|
|
@@ -8600,6 +8614,9 @@ async function navigateRequest(opts) {
|
|
|
8600
8614
|
finishUnstarted();
|
|
8601
8615
|
return;
|
|
8602
8616
|
}
|
|
8617
|
+
finally {
|
|
8618
|
+
waitingNavigations--;
|
|
8619
|
+
}
|
|
8603
8620
|
continue;
|
|
8604
8621
|
}
|
|
8605
8622
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8634,14 +8651,16 @@ async function navigateRequest(opts) {
|
|
|
8634
8651
|
? { form: opts.form, url: opts.url, status: null, outcome: null, committed: false, fallback: false }
|
|
8635
8652
|
: null;
|
|
8636
8653
|
const fallback = (url, requestSent) => {
|
|
8637
|
-
context.fallback = context.method === 'GET' || (!requestSent && !!opts.form);
|
|
8654
|
+
context.fallback = !opts.background && (context.method === 'GET' || (!requestSent && !!opts.form));
|
|
8638
8655
|
context.outcome ?? (context.outcome = context.fallback ? 'fallback' : 'invalid-response');
|
|
8639
|
-
|
|
8656
|
+
if (!opts.background)
|
|
8657
|
+
fallbackFromBoost(opts, url, requestSent);
|
|
8640
8658
|
};
|
|
8659
|
+
const navigationProgress = opts.background ? null : progressBar;
|
|
8641
8660
|
const hasTargetSpinner = opts.trigger?.hasAttribute('g-router-spin');
|
|
8642
8661
|
const setRand = () => {
|
|
8643
|
-
if (isActiveNavigation(transaction) &&
|
|
8644
|
-
|
|
8662
|
+
if (isActiveNavigation(transaction) && navigationProgress && navigationProgress.getCurrentProgress() < 70) {
|
|
8663
|
+
navigationProgress.setProgress(navigationProgress.getCurrentProgress() + Math.random() * 8);
|
|
8645
8664
|
}
|
|
8646
8665
|
};
|
|
8647
8666
|
try {
|
|
@@ -8650,7 +8669,7 @@ async function navigateRequest(opts) {
|
|
|
8650
8669
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8651
8670
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
8652
8671
|
assertActiveNavigation(transaction);
|
|
8653
|
-
|
|
8672
|
+
navigationProgress?.start();
|
|
8654
8673
|
// popstate already points history at the destination entry. Keep the visible
|
|
8655
8674
|
// page's position under currentUrl without overwriting that destination state.
|
|
8656
8675
|
rememberScrollPosition(opts.scrollSourceEntryId ?? currentHistoryEntryId);
|
|
@@ -8739,15 +8758,16 @@ async function navigateRequest(opts) {
|
|
|
8739
8758
|
else {
|
|
8740
8759
|
try {
|
|
8741
8760
|
// Update progress to rand 20 - 30%
|
|
8742
|
-
|
|
8743
|
-
|
|
8761
|
+
navigationProgress?.setProgress(Math.random() * 10 + 20);
|
|
8762
|
+
if (navigationProgress)
|
|
8763
|
+
transaction.interval = setInterval(setRand, 300);
|
|
8744
8764
|
response = await fetch(finalUrl, init);
|
|
8745
8765
|
assertActiveNavigation(transaction);
|
|
8746
8766
|
// A successful write can change HTML at any URL, including after a redirect.
|
|
8747
8767
|
if (response.ok && init.method !== 'GET')
|
|
8748
8768
|
clearPreloads();
|
|
8749
8769
|
// Update progress to rand 70 - 80% after fetch
|
|
8750
|
-
|
|
8770
|
+
navigationProgress?.setProgress(Math.random() * 10 + 70);
|
|
8751
8771
|
if (transaction.interval)
|
|
8752
8772
|
clearInterval(transaction.interval);
|
|
8753
8773
|
transaction.interval = null;
|
|
@@ -8785,6 +8805,13 @@ async function navigateRequest(opts) {
|
|
|
8785
8805
|
const doc = html
|
|
8786
8806
|
? parseNavigationDocument(html)
|
|
8787
8807
|
: document.implementation.createHTMLDocument();
|
|
8808
|
+
const matchedSource = opts.strictSource && opts.targetSelector
|
|
8809
|
+
? doc.querySelector(opts.targetSelector)
|
|
8810
|
+
: null;
|
|
8811
|
+
if (opts.strictSource && !(matchedSource instanceof HTMLElement) && isFullDocument(html || '')) {
|
|
8812
|
+
context.outcome = 'invalid-response';
|
|
8813
|
+
return; // A complete response must identify the requested region before any swap or snapshot.
|
|
8814
|
+
}
|
|
8788
8815
|
// Detached parsing cannot tell whether the live CSP permits an incoming base.
|
|
8789
8816
|
// Let native navigation enforce base-uri instead of authorizing its URLs ourselves.
|
|
8790
8817
|
if (doc.querySelector('base[href]') || opts.historyFragment?.querySelector('base[href]')) {
|
|
@@ -8799,7 +8826,9 @@ async function navigateRequest(opts) {
|
|
|
8799
8826
|
&& !opts.historyFragment && (opts.popstate && snapshots.has(urlWithoutHash)
|
|
8800
8827
|
? snapshots.get(urlWithoutHash).fullDocument : isFullDocument(html || ''));
|
|
8801
8828
|
// Pick source fragment
|
|
8802
|
-
const src = opts.historyFragment ||
|
|
8829
|
+
const src = opts.historyFragment || (matchedSource instanceof HTMLElement
|
|
8830
|
+
? matchedSource
|
|
8831
|
+
: pickSourceFragment(doc, target, targetOutletIndex));
|
|
8803
8832
|
stripInertFallbackContent(src);
|
|
8804
8833
|
assertActiveNavigation(transaction);
|
|
8805
8834
|
// Final URL is response.url because in headers there could be redirects
|
|
@@ -8822,7 +8851,7 @@ async function navigateRequest(opts) {
|
|
|
8822
8851
|
runNavigationHooks(beforeSwap, targetUrl, context);
|
|
8823
8852
|
assertActiveNavigation(transaction);
|
|
8824
8853
|
// Update progress to rand 80 - 90% before swap
|
|
8825
|
-
|
|
8854
|
+
navigationProgress?.setProgress(Math.random() * 10 + 80);
|
|
8826
8855
|
const outgoingHistoryFragment = changesState && !opts.replace && !isFullOutletNavigation
|
|
8827
8856
|
? cloneHistoryTarget(target)
|
|
8828
8857
|
: null;
|
|
@@ -8920,7 +8949,7 @@ async function navigateRequest(opts) {
|
|
|
8920
8949
|
target = committedTarget;
|
|
8921
8950
|
context.target = committedTarget;
|
|
8922
8951
|
context.committed = true;
|
|
8923
|
-
|
|
8952
|
+
navigationProgress?.reconnect();
|
|
8924
8953
|
committedRoots = roots;
|
|
8925
8954
|
}
|
|
8926
8955
|
});
|
|
@@ -8952,7 +8981,7 @@ async function navigateRequest(opts) {
|
|
|
8952
8981
|
}
|
|
8953
8982
|
};
|
|
8954
8983
|
// Apply view transition if available
|
|
8955
|
-
if (document.startViewTransition) {
|
|
8984
|
+
if (!opts.background && document.startViewTransition) {
|
|
8956
8985
|
const transition = document.startViewTransition(() => performUpdate());
|
|
8957
8986
|
consumeViewTransitionRejection(transition?.ready);
|
|
8958
8987
|
consumeViewTransitionRejection(transition?.finished);
|
|
@@ -9003,7 +9032,7 @@ async function navigateRequest(opts) {
|
|
|
9003
9032
|
hideTargetSpinner(transaction.spinner);
|
|
9004
9033
|
if (activeNavigation?.id === transaction.id) {
|
|
9005
9034
|
activeNavigation = null;
|
|
9006
|
-
|
|
9035
|
+
navigationProgress?.complete();
|
|
9007
9036
|
}
|
|
9008
9037
|
opts.signal?.removeEventListener('abort', abort);
|
|
9009
9038
|
transaction.resolveDone();
|
|
@@ -9295,7 +9324,7 @@ const Gyos = {
|
|
|
9295
9324
|
portalCreate,
|
|
9296
9325
|
portalDestroy,
|
|
9297
9326
|
setCspNonce,
|
|
9298
|
-
version: '0.
|
|
9327
|
+
version: '0.6.0'
|
|
9299
9328
|
};
|
|
9300
9329
|
|
|
9301
9330
|
setExpressionRuntime(standardExpressionRuntime);
|