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.csp.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
|
*/
|
|
@@ -7681,8 +7681,10 @@
|
|
|
7681
7681
|
while (idx < toChildren.length || idx < fromChildren.length) {
|
|
7682
7682
|
const toChild = toChildren[idx] || null;
|
|
7683
7683
|
let fromChild = fromChildren[idx] || null;
|
|
7684
|
-
//
|
|
7685
|
-
|
|
7684
|
+
// Persist placeholders have their own placement path below, even when
|
|
7685
|
+
// they also carry an id or another explicit morph key.
|
|
7686
|
+
const toPersistKey = getPersistKey(toChild);
|
|
7687
|
+
const requestedKey = toPersistKey ? null : explicitKeyFor(toChild);
|
|
7686
7688
|
if (requestedKey && explicitKeyFor(fromChild) !== requestedKey) {
|
|
7687
7689
|
const matchingIndex = fromChildren.findIndex((candidate, candidateIndex) => candidateIndex > idx && explicitKeyFor(candidate) === requestedKey);
|
|
7688
7690
|
if (matchingIndex !== -1) {
|
|
@@ -7697,7 +7699,6 @@
|
|
|
7697
7699
|
}
|
|
7698
7700
|
}
|
|
7699
7701
|
// Check if either is persist comment/element
|
|
7700
|
-
const toPersistKey = getPersistKey(toChild);
|
|
7701
7702
|
const fromPersistKey = getPersistKey(fromChild);
|
|
7702
7703
|
// If toChild is persist, check if we already have matching persist in fromChildren
|
|
7703
7704
|
if (toPersistKey) {
|
|
@@ -8132,7 +8133,7 @@
|
|
|
8132
8133
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
8133
8134
|
*/
|
|
8134
8135
|
const submittingForms = new WeakSet();
|
|
8135
|
-
async function visit(url, options,
|
|
8136
|
+
async function visit(url, options, refreshPolicy) {
|
|
8136
8137
|
const destination = new URL(url, document.baseURI);
|
|
8137
8138
|
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
8138
8139
|
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
@@ -8149,21 +8150,27 @@
|
|
|
8149
8150
|
url: destination.href, method: 'GET',
|
|
8150
8151
|
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
8151
8152
|
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
8152
|
-
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal,
|
|
8153
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, ...refreshPolicy,
|
|
8153
8154
|
onEnd: context => { result = context; }
|
|
8154
8155
|
});
|
|
8155
8156
|
return result;
|
|
8156
8157
|
}
|
|
8157
8158
|
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
8158
8159
|
function navigate(url, options = {}) {
|
|
8159
|
-
return visit(url, options
|
|
8160
|
+
return visit(url, options);
|
|
8160
8161
|
}
|
|
8161
8162
|
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
8162
|
-
function refresh(options = {}) {
|
|
8163
|
-
|
|
8163
|
+
function refresh({ background, strictSource, ...options } = {}) {
|
|
8164
|
+
if (strictSource === true && options.target === undefined) {
|
|
8165
|
+
return Promise.reject(new TypeError('Gyos.refresh with strictSource requires a target selector.'));
|
|
8166
|
+
}
|
|
8167
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, {
|
|
8168
|
+
fresh: true, background: background === true, strictSource: strictSource === true
|
|
8169
|
+
});
|
|
8164
8170
|
}
|
|
8165
8171
|
const snapshots = new Map();
|
|
8166
8172
|
const preloadCache = new Map();
|
|
8173
|
+
let preloadHover;
|
|
8167
8174
|
const scrollPositions = new Map();
|
|
8168
8175
|
const historyFragments = new Map();
|
|
8169
8176
|
let routerStarted = false;
|
|
@@ -8173,6 +8180,7 @@
|
|
|
8173
8180
|
let currentUrl = canonicalUrl(window.location.href, true);
|
|
8174
8181
|
let currentHistoryEntryId = history.state?.gyosEntryId || null;
|
|
8175
8182
|
let activeNavigation = null;
|
|
8183
|
+
let waitingNavigations = 0;
|
|
8176
8184
|
// Global progress bar instance
|
|
8177
8185
|
let progressBar = null;
|
|
8178
8186
|
const beforeNavigate = [];
|
|
@@ -8218,6 +8226,8 @@
|
|
|
8218
8226
|
document.addEventListener('click', onClick);
|
|
8219
8227
|
document.addEventListener('submit', onSubmit);
|
|
8220
8228
|
document.addEventListener('mouseover', onMouseOverCapture, true);
|
|
8229
|
+
document.addEventListener('mousemove', onPreloadMouseMove, true);
|
|
8230
|
+
document.addEventListener('mouseleave', clearPreloadHover);
|
|
8221
8231
|
window.addEventListener('popstate', onPopState);
|
|
8222
8232
|
if ('scrollRestoration' in history) {
|
|
8223
8233
|
history.scrollRestoration = 'manual';
|
|
@@ -8489,6 +8499,7 @@
|
|
|
8489
8499
|
entry?.controller.abort();
|
|
8490
8500
|
}
|
|
8491
8501
|
function clearPreloads() {
|
|
8502
|
+
clearPreloadHover();
|
|
8492
8503
|
for (const key of preloadCache.keys())
|
|
8493
8504
|
discardPreload(key);
|
|
8494
8505
|
}
|
|
@@ -8563,19 +8574,27 @@
|
|
|
8563
8574
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8564
8575
|
}
|
|
8565
8576
|
async function navigateRequest(opts) {
|
|
8566
|
-
const finishUnstarted = () => {
|
|
8577
|
+
const finishUnstarted = (signal = opts.signal) => {
|
|
8567
8578
|
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8568
8579
|
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8569
|
-
signal
|
|
8580
|
+
signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8570
8581
|
};
|
|
8571
8582
|
if (opts.signal?.aborted) {
|
|
8572
8583
|
finishUnstarted();
|
|
8573
8584
|
return;
|
|
8574
8585
|
}
|
|
8586
|
+
if (opts.background && (activeNavigation || waitingNavigations > 0)) {
|
|
8587
|
+
const skipped = new AbortController();
|
|
8588
|
+
skipped.abort();
|
|
8589
|
+
finishUnstarted(skipped.signal);
|
|
8590
|
+
return;
|
|
8591
|
+
}
|
|
8575
8592
|
while (activeNavigation) {
|
|
8576
8593
|
const previous = activeNavigation;
|
|
8577
8594
|
if (previous.committing) {
|
|
8578
8595
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8596
|
+
// End hooks can request a refresh before this waiter resumes.
|
|
8597
|
+
waitingNavigations++;
|
|
8579
8598
|
try {
|
|
8580
8599
|
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8581
8600
|
}
|
|
@@ -8583,6 +8602,9 @@
|
|
|
8583
8602
|
finishUnstarted();
|
|
8584
8603
|
return;
|
|
8585
8604
|
}
|
|
8605
|
+
finally {
|
|
8606
|
+
waitingNavigations--;
|
|
8607
|
+
}
|
|
8586
8608
|
continue;
|
|
8587
8609
|
}
|
|
8588
8610
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8617,14 +8639,16 @@
|
|
|
8617
8639
|
? { form: opts.form, url: opts.url, status: null, outcome: null, committed: false, fallback: false }
|
|
8618
8640
|
: null;
|
|
8619
8641
|
const fallback = (url, requestSent) => {
|
|
8620
|
-
context.fallback = context.method === 'GET' || (!requestSent && !!opts.form);
|
|
8642
|
+
context.fallback = !opts.background && (context.method === 'GET' || (!requestSent && !!opts.form));
|
|
8621
8643
|
context.outcome ?? (context.outcome = context.fallback ? 'fallback' : 'invalid-response');
|
|
8622
|
-
|
|
8644
|
+
if (!opts.background)
|
|
8645
|
+
fallbackFromBoost(opts, url, requestSent);
|
|
8623
8646
|
};
|
|
8647
|
+
const navigationProgress = opts.background ? null : progressBar;
|
|
8624
8648
|
const hasTargetSpinner = opts.trigger?.hasAttribute('g-router-spin');
|
|
8625
8649
|
const setRand = () => {
|
|
8626
|
-
if (isActiveNavigation(transaction) &&
|
|
8627
|
-
|
|
8650
|
+
if (isActiveNavigation(transaction) && navigationProgress && navigationProgress.getCurrentProgress() < 70) {
|
|
8651
|
+
navigationProgress.setProgress(navigationProgress.getCurrentProgress() + Math.random() * 8);
|
|
8628
8652
|
}
|
|
8629
8653
|
};
|
|
8630
8654
|
try {
|
|
@@ -8633,7 +8657,7 @@
|
|
|
8633
8657
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8634
8658
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
8635
8659
|
assertActiveNavigation(transaction);
|
|
8636
|
-
|
|
8660
|
+
navigationProgress?.start();
|
|
8637
8661
|
// popstate already points history at the destination entry. Keep the visible
|
|
8638
8662
|
// page's position under currentUrl without overwriting that destination state.
|
|
8639
8663
|
rememberScrollPosition(opts.scrollSourceEntryId ?? currentHistoryEntryId);
|
|
@@ -8702,6 +8726,8 @@
|
|
|
8702
8726
|
signal.addEventListener('abort', discard, { once: true });
|
|
8703
8727
|
try {
|
|
8704
8728
|
response = await waitForNavigation(entry.request, signal);
|
|
8729
|
+
if (response.ok && preloadHover?.url === preloadKey)
|
|
8730
|
+
preloadHover.used = true;
|
|
8705
8731
|
}
|
|
8706
8732
|
catch (error) {
|
|
8707
8733
|
if (error.name === 'AbortError')
|
|
@@ -8720,15 +8746,16 @@
|
|
|
8720
8746
|
else {
|
|
8721
8747
|
try {
|
|
8722
8748
|
// Update progress to rand 20 - 30%
|
|
8723
|
-
|
|
8724
|
-
|
|
8749
|
+
navigationProgress?.setProgress(Math.random() * 10 + 20);
|
|
8750
|
+
if (navigationProgress)
|
|
8751
|
+
transaction.interval = setInterval(setRand, 300);
|
|
8725
8752
|
response = await fetch(finalUrl, init);
|
|
8726
8753
|
assertActiveNavigation(transaction);
|
|
8727
8754
|
// A successful write can change HTML at any URL, including after a redirect.
|
|
8728
8755
|
if (response.ok && init.method !== 'GET')
|
|
8729
8756
|
clearPreloads();
|
|
8730
8757
|
// Update progress to rand 70 - 80% after fetch
|
|
8731
|
-
|
|
8758
|
+
navigationProgress?.setProgress(Math.random() * 10 + 70);
|
|
8732
8759
|
if (transaction.interval)
|
|
8733
8760
|
clearInterval(transaction.interval);
|
|
8734
8761
|
transaction.interval = null;
|
|
@@ -8766,6 +8793,13 @@
|
|
|
8766
8793
|
const doc = html
|
|
8767
8794
|
? parseNavigationDocument(html)
|
|
8768
8795
|
: document.implementation.createHTMLDocument();
|
|
8796
|
+
const matchedSource = opts.strictSource && opts.targetSelector
|
|
8797
|
+
? doc.querySelector(opts.targetSelector)
|
|
8798
|
+
: null;
|
|
8799
|
+
if (opts.strictSource && !(matchedSource instanceof HTMLElement) && isFullDocument(html || '')) {
|
|
8800
|
+
context.outcome = 'invalid-response';
|
|
8801
|
+
return; // A complete response must identify the requested region before any swap or snapshot.
|
|
8802
|
+
}
|
|
8769
8803
|
// Detached parsing cannot tell whether the live CSP permits an incoming base.
|
|
8770
8804
|
// Let native navigation enforce base-uri instead of authorizing its URLs ourselves.
|
|
8771
8805
|
if (doc.querySelector('base[href]') || opts.historyFragment?.querySelector('base[href]')) {
|
|
@@ -8780,7 +8814,9 @@
|
|
|
8780
8814
|
&& !opts.historyFragment && (opts.popstate && snapshots.has(urlWithoutHash)
|
|
8781
8815
|
? snapshots.get(urlWithoutHash).fullDocument : isFullDocument(html || ''));
|
|
8782
8816
|
// Pick source fragment
|
|
8783
|
-
const src = opts.historyFragment ||
|
|
8817
|
+
const src = opts.historyFragment || (matchedSource instanceof HTMLElement
|
|
8818
|
+
? matchedSource
|
|
8819
|
+
: pickSourceFragment(doc, target, targetOutletIndex));
|
|
8784
8820
|
stripInertFallbackContent(src);
|
|
8785
8821
|
assertActiveNavigation(transaction);
|
|
8786
8822
|
// Final URL is response.url because in headers there could be redirects
|
|
@@ -8803,7 +8839,7 @@
|
|
|
8803
8839
|
runNavigationHooks(beforeSwap, targetUrl, context);
|
|
8804
8840
|
assertActiveNavigation(transaction);
|
|
8805
8841
|
// Update progress to rand 80 - 90% before swap
|
|
8806
|
-
|
|
8842
|
+
navigationProgress?.setProgress(Math.random() * 10 + 80);
|
|
8807
8843
|
const outgoingHistoryFragment = changesState && !opts.replace && !isFullOutletNavigation
|
|
8808
8844
|
? cloneHistoryTarget(target)
|
|
8809
8845
|
: null;
|
|
@@ -8901,7 +8937,7 @@
|
|
|
8901
8937
|
target = committedTarget;
|
|
8902
8938
|
context.target = committedTarget;
|
|
8903
8939
|
context.committed = true;
|
|
8904
|
-
|
|
8940
|
+
navigationProgress?.reconnect();
|
|
8905
8941
|
committedRoots = roots;
|
|
8906
8942
|
}
|
|
8907
8943
|
});
|
|
@@ -8933,7 +8969,7 @@
|
|
|
8933
8969
|
}
|
|
8934
8970
|
};
|
|
8935
8971
|
// Apply view transition if available
|
|
8936
|
-
if (document.startViewTransition) {
|
|
8972
|
+
if (!opts.background && document.startViewTransition) {
|
|
8937
8973
|
const transition = document.startViewTransition(() => performUpdate());
|
|
8938
8974
|
consumeViewTransitionRejection(transition?.ready);
|
|
8939
8975
|
consumeViewTransitionRejection(transition?.finished);
|
|
@@ -8984,7 +9020,7 @@
|
|
|
8984
9020
|
hideTargetSpinner(transaction.spinner);
|
|
8985
9021
|
if (activeNavigation?.id === transaction.id) {
|
|
8986
9022
|
activeNavigation = null;
|
|
8987
|
-
|
|
9023
|
+
navigationProgress?.complete();
|
|
8988
9024
|
}
|
|
8989
9025
|
opts.signal?.removeEventListener('abort', abort);
|
|
8990
9026
|
transaction.resolveDone();
|
|
@@ -9096,15 +9132,34 @@
|
|
|
9096
9132
|
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
9097
9133
|
}
|
|
9098
9134
|
function onMouseOverCapture(event) {
|
|
9099
|
-
const
|
|
9100
|
-
if (!target)
|
|
9101
|
-
return;
|
|
9102
|
-
const link = target.closest('a[g-preload]');
|
|
9135
|
+
const link = event.target instanceof Element ? event.target.closest('a[g-preload]') : null;
|
|
9103
9136
|
if (!link)
|
|
9104
9137
|
return;
|
|
9105
9138
|
const url = eligibleAnchorUrl(link);
|
|
9106
|
-
if (url)
|
|
9107
|
-
|
|
9139
|
+
if (!url)
|
|
9140
|
+
return;
|
|
9141
|
+
const hover = preloadHover;
|
|
9142
|
+
if (hover?.used && hover.url === url.href && ((event.clientX === hover.x && event.clientY === hover.y) ||
|
|
9143
|
+
(event.relatedTarget instanceof Node && link.contains(event.relatedTarget))))
|
|
9144
|
+
return;
|
|
9145
|
+
preloadHover = { url: url.href, x: event.clientX, y: event.clientY, used: false };
|
|
9146
|
+
preload(url.href);
|
|
9147
|
+
}
|
|
9148
|
+
function onPreloadMouseMove(event) {
|
|
9149
|
+
const hover = preloadHover;
|
|
9150
|
+
// The browser can retarget mouse events after a swap with the pointer still in place.
|
|
9151
|
+
if (!hover || (event.clientX === hover.x && event.clientY === hover.y))
|
|
9152
|
+
return;
|
|
9153
|
+
const link = event.target instanceof Element ? event.target.closest('a[g-preload]') : null;
|
|
9154
|
+
if (!(link instanceof HTMLAnchorElement) || link.href !== hover.url) {
|
|
9155
|
+
clearPreloadHover();
|
|
9156
|
+
return;
|
|
9157
|
+
}
|
|
9158
|
+
hover.x = event.clientX;
|
|
9159
|
+
hover.y = event.clientY;
|
|
9160
|
+
}
|
|
9161
|
+
function clearPreloadHover() {
|
|
9162
|
+
preloadHover = undefined;
|
|
9108
9163
|
}
|
|
9109
9164
|
function onSubmit(event) {
|
|
9110
9165
|
if (event.defaultPrevented)
|
|
@@ -9257,7 +9312,7 @@
|
|
|
9257
9312
|
portalCreate,
|
|
9258
9313
|
portalDestroy,
|
|
9259
9314
|
setCspNonce,
|
|
9260
|
-
version: '0.
|
|
9315
|
+
version: '0.6.0'
|
|
9261
9316
|
};
|
|
9262
9317
|
|
|
9263
9318
|
// This file was generated. Do not modify manually!
|