gyosjs 0.4.1 → 0.5.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/component.d.ts.map +1 -1
- package/dist/core/router/persist.d.ts.map +1 -1
- package/dist/core/router/router.d.ts +20 -2
- package/dist/core/router/router.d.ts.map +1 -1
- package/dist/gyos.auto.esm.js +110 -21
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +110 -21
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +110 -21
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +110 -21
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +111 -22
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +112 -21
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +111 -22
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +112 -21
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/public-api.d.ts +5 -3
- 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.5.0
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -5636,6 +5636,21 @@
|
|
|
5636
5636
|
* Registry of all scopes
|
|
5637
5637
|
*/
|
|
5638
5638
|
const scopeRegistry = new Map();
|
|
5639
|
+
const warnedReveals = new WeakSet();
|
|
5640
|
+
function diagnoseUnscopedReveals(root) {
|
|
5641
|
+
if (!DEBUG())
|
|
5642
|
+
return;
|
|
5643
|
+
const elements = [...root.querySelectorAll('[g-reveal]')];
|
|
5644
|
+
if (root instanceof Element && root.hasAttribute('g-reveal'))
|
|
5645
|
+
elements.unshift(root);
|
|
5646
|
+
for (const element of elements) {
|
|
5647
|
+
if (warnedReveals.has(element) || isInIgnoredTree(element)
|
|
5648
|
+
|| element.closest('[g-scope]') || getScopeFromElement(element))
|
|
5649
|
+
continue;
|
|
5650
|
+
warnedReveals.add(element);
|
|
5651
|
+
console.warn('[Gyos] g-reveal has no owning scope. Add g-scope to its container; global reveal CSS may otherwise hide this content.', element);
|
|
5652
|
+
}
|
|
5653
|
+
}
|
|
5639
5654
|
/**
|
|
5640
5655
|
* Register a scope
|
|
5641
5656
|
*/
|
|
@@ -5683,6 +5698,7 @@
|
|
|
5683
5698
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5684
5699
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
5685
5700
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
5701
|
+
diagnoseUnscopedReveals(document.body);
|
|
5686
5702
|
}
|
|
5687
5703
|
function mountTree(el) {
|
|
5688
5704
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -5693,6 +5709,7 @@
|
|
|
5693
5709
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
5694
5710
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5695
5711
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
5712
|
+
diagnoseUnscopedReveals(el);
|
|
5696
5713
|
if (getMountedScope(el))
|
|
5697
5714
|
return;
|
|
5698
5715
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -5711,7 +5728,7 @@
|
|
|
5711
5728
|
return;
|
|
5712
5729
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
5713
5730
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
5714
|
-
if (!
|
|
5731
|
+
if (!mountedEl.isConnected) {
|
|
5715
5732
|
disposeEffects(mountedEl);
|
|
5716
5733
|
}
|
|
5717
5734
|
});
|
|
@@ -7023,7 +7040,8 @@
|
|
|
7023
7040
|
el.dataset.gyosPersistId = key;
|
|
7024
7041
|
return key;
|
|
7025
7042
|
}
|
|
7026
|
-
//
|
|
7043
|
+
// Keep the parking host outside body: body itself may be the swap target.
|
|
7044
|
+
// A disconnected parking host makes browsers pause otherwise persisted media.
|
|
7027
7045
|
const persistParking = typeof document !== 'undefined'
|
|
7028
7046
|
? (() => {
|
|
7029
7047
|
const park = document.createElement('div');
|
|
@@ -7032,12 +7050,7 @@
|
|
|
7032
7050
|
park.style.top = '-99999px';
|
|
7033
7051
|
park.style.width = '0';
|
|
7034
7052
|
park.style.height = '0';
|
|
7035
|
-
|
|
7036
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
7037
|
-
}
|
|
7038
|
-
else {
|
|
7039
|
-
document.body.appendChild(park);
|
|
7040
|
-
}
|
|
7053
|
+
document.documentElement.appendChild(park);
|
|
7041
7054
|
return park;
|
|
7042
7055
|
})()
|
|
7043
7056
|
: null;
|
|
@@ -7048,8 +7061,8 @@
|
|
|
7048
7061
|
return elements;
|
|
7049
7062
|
}
|
|
7050
7063
|
function ensureParkingIsConnected() {
|
|
7051
|
-
if (persistParking &&
|
|
7052
|
-
document.
|
|
7064
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
7065
|
+
document.documentElement.appendChild(persistParking);
|
|
7053
7066
|
}
|
|
7054
7067
|
}
|
|
7055
7068
|
function detachPersist(root = document) {
|
|
@@ -7067,12 +7080,18 @@
|
|
|
7067
7080
|
});
|
|
7068
7081
|
}
|
|
7069
7082
|
function mergePersistIntoLive(root) {
|
|
7083
|
+
// Return the host to the current body before scope mounting/cleanup inspects it.
|
|
7084
|
+
if (persistParking && persistParking.parentElement !== document.body) {
|
|
7085
|
+
document.body.appendChild(persistParking);
|
|
7086
|
+
}
|
|
7070
7087
|
if (!persistEntries.size)
|
|
7071
7088
|
return;
|
|
7072
7089
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
7073
7090
|
if (persistEntries.size === 1) {
|
|
7074
7091
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
7075
7092
|
elementsIn(root).forEach(el => {
|
|
7093
|
+
if (persistParking?.contains(el))
|
|
7094
|
+
return;
|
|
7076
7095
|
if (!getPersistKey(el, false)) {
|
|
7077
7096
|
el.dataset.gyosPersistId = loneKey;
|
|
7078
7097
|
}
|
|
@@ -7080,6 +7099,8 @@
|
|
|
7080
7099
|
}
|
|
7081
7100
|
// Element placeholders
|
|
7082
7101
|
elementsIn(root).forEach(placeholder => {
|
|
7102
|
+
if (persistParking?.contains(placeholder))
|
|
7103
|
+
return;
|
|
7083
7104
|
const key = getPersistKey(placeholder, false);
|
|
7084
7105
|
if (!key)
|
|
7085
7106
|
return;
|
|
@@ -7097,6 +7118,8 @@
|
|
|
7097
7118
|
const toReplace = [];
|
|
7098
7119
|
while (walker.nextNode()) {
|
|
7099
7120
|
const comment = walker.currentNode;
|
|
7121
|
+
if (persistParking?.contains(comment))
|
|
7122
|
+
continue;
|
|
7100
7123
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
7101
7124
|
if (match) {
|
|
7102
7125
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -7754,6 +7777,36 @@
|
|
|
7754
7777
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7755
7778
|
*/
|
|
7756
7779
|
const submittingForms = new WeakSet();
|
|
7780
|
+
async function visit(url, options, fresh) {
|
|
7781
|
+
const destination = new URL(url, document.baseURI);
|
|
7782
|
+
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
7783
|
+
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
7784
|
+
}
|
|
7785
|
+
if (options.target !== undefined && !(document.querySelector(options.target) instanceof HTMLElement)) {
|
|
7786
|
+
throw new TypeError('Gyos.navigate target does not exist.');
|
|
7787
|
+
}
|
|
7788
|
+
if (!document.querySelector('[g-boost]')) {
|
|
7789
|
+
throw new TypeError('Gyos.navigate requires a g-boost layout.');
|
|
7790
|
+
}
|
|
7791
|
+
startRouter();
|
|
7792
|
+
let result;
|
|
7793
|
+
await navigateRequest({
|
|
7794
|
+
url: destination.href, method: 'GET',
|
|
7795
|
+
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
7796
|
+
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
7797
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
|
|
7798
|
+
onEnd: context => { result = context; }
|
|
7799
|
+
});
|
|
7800
|
+
return result;
|
|
7801
|
+
}
|
|
7802
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
7803
|
+
function navigate(url, options = {}) {
|
|
7804
|
+
return visit(url, options, false);
|
|
7805
|
+
}
|
|
7806
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
7807
|
+
function refresh(options = {}) {
|
|
7808
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, true);
|
|
7809
|
+
}
|
|
7757
7810
|
const snapshots = new Map();
|
|
7758
7811
|
const preloadCache = new Map();
|
|
7759
7812
|
const preloadControllers = new Map();
|
|
@@ -8140,12 +8193,27 @@
|
|
|
8140
8193
|
}
|
|
8141
8194
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8142
8195
|
}
|
|
8143
|
-
async function
|
|
8196
|
+
async function navigateRequest(opts) {
|
|
8197
|
+
const finishUnstarted = () => {
|
|
8198
|
+
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8199
|
+
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8200
|
+
signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8201
|
+
};
|
|
8202
|
+
if (opts.signal?.aborted) {
|
|
8203
|
+
finishUnstarted();
|
|
8204
|
+
return;
|
|
8205
|
+
}
|
|
8144
8206
|
while (activeNavigation) {
|
|
8145
8207
|
const previous = activeNavigation;
|
|
8146
8208
|
if (previous.committing) {
|
|
8147
8209
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8148
|
-
|
|
8210
|
+
try {
|
|
8211
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8212
|
+
}
|
|
8213
|
+
catch {
|
|
8214
|
+
finishUnstarted();
|
|
8215
|
+
return;
|
|
8216
|
+
}
|
|
8149
8217
|
continue;
|
|
8150
8218
|
}
|
|
8151
8219
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8164,6 +8232,10 @@
|
|
|
8164
8232
|
resolveDone
|
|
8165
8233
|
};
|
|
8166
8234
|
activeNavigation = transaction;
|
|
8235
|
+
const abort = () => cancelNavigation(transaction);
|
|
8236
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
8237
|
+
if (opts.signal?.aborted)
|
|
8238
|
+
abort();
|
|
8167
8239
|
const currentBaseUrl = document.baseURI;
|
|
8168
8240
|
rememberResourceUrls(document, currentBaseUrl);
|
|
8169
8241
|
const context = {
|
|
@@ -8187,6 +8259,7 @@
|
|
|
8187
8259
|
}
|
|
8188
8260
|
};
|
|
8189
8261
|
try {
|
|
8262
|
+
assertActiveNavigation(transaction);
|
|
8190
8263
|
if (formEvent)
|
|
8191
8264
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8192
8265
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -8199,6 +8272,10 @@
|
|
|
8199
8272
|
saveScrollPosition();
|
|
8200
8273
|
// Pick target element to swap
|
|
8201
8274
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
8275
|
+
if (opts.strictTarget && (!opts.targetSelector || !target?.matches(opts.targetSelector))) {
|
|
8276
|
+
context.outcome = 'invalid-response';
|
|
8277
|
+
return; // A queued explicit target disappeared; never broaden the swap.
|
|
8278
|
+
}
|
|
8202
8279
|
context.target = target;
|
|
8203
8280
|
if (!target) {
|
|
8204
8281
|
if (isActiveNavigation(transaction))
|
|
@@ -8243,7 +8320,12 @@
|
|
|
8243
8320
|
else {
|
|
8244
8321
|
// Check preload cache if GET
|
|
8245
8322
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
8246
|
-
if (opts.
|
|
8323
|
+
if (opts.fresh) {
|
|
8324
|
+
preloadControllers.get(preloadKey)?.abort();
|
|
8325
|
+
preloadControllers.delete(preloadKey);
|
|
8326
|
+
preloadCache.delete(preloadKey);
|
|
8327
|
+
}
|
|
8328
|
+
if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
|
|
8247
8329
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
8248
8330
|
try {
|
|
8249
8331
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -8451,7 +8533,10 @@
|
|
|
8451
8533
|
finalizeCommit();
|
|
8452
8534
|
}
|
|
8453
8535
|
// Handle scroll after mount scopes
|
|
8454
|
-
if (
|
|
8536
|
+
if (opts.scroll === false) {
|
|
8537
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
8538
|
+
}
|
|
8539
|
+
else if (changesState) {
|
|
8455
8540
|
handleScroll(targetUrl, opts.trigger);
|
|
8456
8541
|
}
|
|
8457
8542
|
else if (opts.popstate) {
|
|
@@ -8516,6 +8601,7 @@
|
|
|
8516
8601
|
activeNavigation = null;
|
|
8517
8602
|
progressBar?.complete();
|
|
8518
8603
|
}
|
|
8604
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
8519
8605
|
transaction.resolveDone();
|
|
8520
8606
|
if (formEvent)
|
|
8521
8607
|
submittingForms.delete(formEvent.form);
|
|
@@ -8526,6 +8612,7 @@
|
|
|
8526
8612
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8527
8613
|
}));
|
|
8528
8614
|
}
|
|
8615
|
+
opts.onEnd?.({ ...context });
|
|
8529
8616
|
}
|
|
8530
8617
|
}
|
|
8531
8618
|
function shouldBoost(el) {
|
|
@@ -8556,7 +8643,7 @@
|
|
|
8556
8643
|
const scope = getScopeFromElement(element);
|
|
8557
8644
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
8558
8645
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
8559
|
-
|
|
8646
|
+
navigateRequest({
|
|
8560
8647
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
8561
8648
|
});
|
|
8562
8649
|
}
|
|
@@ -8605,7 +8692,7 @@
|
|
|
8605
8692
|
return;
|
|
8606
8693
|
event.preventDefault();
|
|
8607
8694
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
8608
|
-
|
|
8695
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
8609
8696
|
}
|
|
8610
8697
|
function onMouseOverCapture(event) {
|
|
8611
8698
|
const target = event.target;
|
|
@@ -8661,7 +8748,7 @@
|
|
|
8661
8748
|
return;
|
|
8662
8749
|
const formData = new FormData(form, submitter);
|
|
8663
8750
|
submittingForms.add(form);
|
|
8664
|
-
void
|
|
8751
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8665
8752
|
}
|
|
8666
8753
|
function onPopState(event) {
|
|
8667
8754
|
const url = window.location.href;
|
|
@@ -8679,14 +8766,14 @@
|
|
|
8679
8766
|
}
|
|
8680
8767
|
event.preventDefault();
|
|
8681
8768
|
// The browser changes location before popstate fires. Stop any pending page
|
|
8682
|
-
// script immediately, then let
|
|
8769
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
8683
8770
|
if (activeNavigation?.committing)
|
|
8684
8771
|
cancelNavigation(activeNavigation);
|
|
8685
8772
|
// The browser has already moved to the destination history entry. Keep the
|
|
8686
8773
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
8687
8774
|
currentHistoryEntryId = destinationEntryId;
|
|
8688
8775
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
8689
|
-
|
|
8776
|
+
navigateRequest({
|
|
8690
8777
|
url,
|
|
8691
8778
|
method: 'GET',
|
|
8692
8779
|
replace: true,
|
|
@@ -8768,10 +8855,12 @@
|
|
|
8768
8855
|
onAfterNavigate,
|
|
8769
8856
|
onBeforeSwap,
|
|
8770
8857
|
onNavigationEnd,
|
|
8858
|
+
navigate,
|
|
8859
|
+
refresh,
|
|
8771
8860
|
portalCreate,
|
|
8772
8861
|
portalDestroy,
|
|
8773
8862
|
setCspNonce,
|
|
8774
|
-
version: '0.
|
|
8863
|
+
version: '0.5.0'
|
|
8775
8864
|
};
|
|
8776
8865
|
|
|
8777
8866
|
const standardExpressionRuntime = {
|