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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.
|
|
2
|
+
* GyosJS v0.5.0
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -5630,6 +5630,21 @@ setMountFunction(mount);
|
|
|
5630
5630
|
* Registry of all scopes
|
|
5631
5631
|
*/
|
|
5632
5632
|
const scopeRegistry = new Map();
|
|
5633
|
+
const warnedReveals = new WeakSet();
|
|
5634
|
+
function diagnoseUnscopedReveals(root) {
|
|
5635
|
+
if (!DEBUG())
|
|
5636
|
+
return;
|
|
5637
|
+
const elements = [...root.querySelectorAll('[g-reveal]')];
|
|
5638
|
+
if (root instanceof Element && root.hasAttribute('g-reveal'))
|
|
5639
|
+
elements.unshift(root);
|
|
5640
|
+
for (const element of elements) {
|
|
5641
|
+
if (warnedReveals.has(element) || isInIgnoredTree(element)
|
|
5642
|
+
|| element.closest('[g-scope]') || getScopeFromElement(element))
|
|
5643
|
+
continue;
|
|
5644
|
+
warnedReveals.add(element);
|
|
5645
|
+
console.warn('[Gyos] g-reveal has no owning scope. Add g-scope to its container; global reveal CSS may otherwise hide this content.', element);
|
|
5646
|
+
}
|
|
5647
|
+
}
|
|
5633
5648
|
/**
|
|
5634
5649
|
* Register a scope
|
|
5635
5650
|
*/
|
|
@@ -5677,6 +5692,7 @@ function mountAll(root) {
|
|
|
5677
5692
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5678
5693
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
5679
5694
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
5695
|
+
diagnoseUnscopedReveals(document.body);
|
|
5680
5696
|
}
|
|
5681
5697
|
function mountTree(el) {
|
|
5682
5698
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -5687,6 +5703,7 @@ function mountTree(el) {
|
|
|
5687
5703
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
5688
5704
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5689
5705
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
5706
|
+
diagnoseUnscopedReveals(el);
|
|
5690
5707
|
if (getMountedScope(el))
|
|
5691
5708
|
return;
|
|
5692
5709
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -5705,7 +5722,7 @@ function mount(el) {
|
|
|
5705
5722
|
return;
|
|
5706
5723
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
5707
5724
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
5708
|
-
if (!
|
|
5725
|
+
if (!mountedEl.isConnected) {
|
|
5709
5726
|
disposeEffects(mountedEl);
|
|
5710
5727
|
}
|
|
5711
5728
|
});
|
|
@@ -7031,7 +7048,8 @@ function getPersistKey(el, generateIfMissing = false) {
|
|
|
7031
7048
|
el.dataset.gyosPersistId = key;
|
|
7032
7049
|
return key;
|
|
7033
7050
|
}
|
|
7034
|
-
//
|
|
7051
|
+
// Keep the parking host outside body: body itself may be the swap target.
|
|
7052
|
+
// A disconnected parking host makes browsers pause otherwise persisted media.
|
|
7035
7053
|
const persistParking = typeof document !== 'undefined'
|
|
7036
7054
|
? (() => {
|
|
7037
7055
|
const park = document.createElement('div');
|
|
@@ -7040,12 +7058,7 @@ const persistParking = typeof document !== 'undefined'
|
|
|
7040
7058
|
park.style.top = '-99999px';
|
|
7041
7059
|
park.style.width = '0';
|
|
7042
7060
|
park.style.height = '0';
|
|
7043
|
-
|
|
7044
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
7045
|
-
}
|
|
7046
|
-
else {
|
|
7047
|
-
document.body.appendChild(park);
|
|
7048
|
-
}
|
|
7061
|
+
document.documentElement.appendChild(park);
|
|
7049
7062
|
return park;
|
|
7050
7063
|
})()
|
|
7051
7064
|
: null;
|
|
@@ -7056,8 +7069,8 @@ function elementsIn(root) {
|
|
|
7056
7069
|
return elements;
|
|
7057
7070
|
}
|
|
7058
7071
|
function ensureParkingIsConnected() {
|
|
7059
|
-
if (persistParking &&
|
|
7060
|
-
document.
|
|
7072
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
7073
|
+
document.documentElement.appendChild(persistParking);
|
|
7061
7074
|
}
|
|
7062
7075
|
}
|
|
7063
7076
|
function detachPersist(root = document) {
|
|
@@ -7075,12 +7088,18 @@ function detachPersist(root = document) {
|
|
|
7075
7088
|
});
|
|
7076
7089
|
}
|
|
7077
7090
|
function mergePersistIntoLive(root) {
|
|
7091
|
+
// Return the host to the current body before scope mounting/cleanup inspects it.
|
|
7092
|
+
if (persistParking && persistParking.parentElement !== document.body) {
|
|
7093
|
+
document.body.appendChild(persistParking);
|
|
7094
|
+
}
|
|
7078
7095
|
if (!persistEntries.size)
|
|
7079
7096
|
return;
|
|
7080
7097
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
7081
7098
|
if (persistEntries.size === 1) {
|
|
7082
7099
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
7083
7100
|
elementsIn(root).forEach(el => {
|
|
7101
|
+
if (persistParking?.contains(el))
|
|
7102
|
+
return;
|
|
7084
7103
|
if (!getPersistKey(el, false)) {
|
|
7085
7104
|
el.dataset.gyosPersistId = loneKey;
|
|
7086
7105
|
}
|
|
@@ -7088,6 +7107,8 @@ function mergePersistIntoLive(root) {
|
|
|
7088
7107
|
}
|
|
7089
7108
|
// Element placeholders
|
|
7090
7109
|
elementsIn(root).forEach(placeholder => {
|
|
7110
|
+
if (persistParking?.contains(placeholder))
|
|
7111
|
+
return;
|
|
7091
7112
|
const key = getPersistKey(placeholder, false);
|
|
7092
7113
|
if (!key)
|
|
7093
7114
|
return;
|
|
@@ -7105,6 +7126,8 @@ function mergePersistIntoLive(root) {
|
|
|
7105
7126
|
const toReplace = [];
|
|
7106
7127
|
while (walker.nextNode()) {
|
|
7107
7128
|
const comment = walker.currentNode;
|
|
7129
|
+
if (persistParking?.contains(comment))
|
|
7130
|
+
continue;
|
|
7108
7131
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
7109
7132
|
if (match) {
|
|
7110
7133
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -7762,6 +7785,36 @@ function prepareNavigationHtml(html) {
|
|
|
7762
7785
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7763
7786
|
*/
|
|
7764
7787
|
const submittingForms = new WeakSet();
|
|
7788
|
+
async function visit(url, options, fresh) {
|
|
7789
|
+
const destination = new URL(url, document.baseURI);
|
|
7790
|
+
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
7791
|
+
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
7792
|
+
}
|
|
7793
|
+
if (options.target !== undefined && !(document.querySelector(options.target) instanceof HTMLElement)) {
|
|
7794
|
+
throw new TypeError('Gyos.navigate target does not exist.');
|
|
7795
|
+
}
|
|
7796
|
+
if (!document.querySelector('[g-boost]')) {
|
|
7797
|
+
throw new TypeError('Gyos.navigate requires a g-boost layout.');
|
|
7798
|
+
}
|
|
7799
|
+
startRouter();
|
|
7800
|
+
let result;
|
|
7801
|
+
await navigateRequest({
|
|
7802
|
+
url: destination.href, method: 'GET',
|
|
7803
|
+
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
7804
|
+
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
7805
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
|
|
7806
|
+
onEnd: context => { result = context; }
|
|
7807
|
+
});
|
|
7808
|
+
return result;
|
|
7809
|
+
}
|
|
7810
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
7811
|
+
function navigate(url, options = {}) {
|
|
7812
|
+
return visit(url, options, false);
|
|
7813
|
+
}
|
|
7814
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
7815
|
+
function refresh(options = {}) {
|
|
7816
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, true);
|
|
7817
|
+
}
|
|
7765
7818
|
const snapshots = new Map();
|
|
7766
7819
|
const preloadCache = new Map();
|
|
7767
7820
|
const preloadControllers = new Map();
|
|
@@ -8148,12 +8201,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
8148
8201
|
}
|
|
8149
8202
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8150
8203
|
}
|
|
8151
|
-
async function
|
|
8204
|
+
async function navigateRequest(opts) {
|
|
8205
|
+
const finishUnstarted = () => {
|
|
8206
|
+
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8207
|
+
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8208
|
+
signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8209
|
+
};
|
|
8210
|
+
if (opts.signal?.aborted) {
|
|
8211
|
+
finishUnstarted();
|
|
8212
|
+
return;
|
|
8213
|
+
}
|
|
8152
8214
|
while (activeNavigation) {
|
|
8153
8215
|
const previous = activeNavigation;
|
|
8154
8216
|
if (previous.committing) {
|
|
8155
8217
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8156
|
-
|
|
8218
|
+
try {
|
|
8219
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8220
|
+
}
|
|
8221
|
+
catch {
|
|
8222
|
+
finishUnstarted();
|
|
8223
|
+
return;
|
|
8224
|
+
}
|
|
8157
8225
|
continue;
|
|
8158
8226
|
}
|
|
8159
8227
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8172,6 +8240,10 @@ async function navigate(opts) {
|
|
|
8172
8240
|
resolveDone
|
|
8173
8241
|
};
|
|
8174
8242
|
activeNavigation = transaction;
|
|
8243
|
+
const abort = () => cancelNavigation(transaction);
|
|
8244
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
8245
|
+
if (opts.signal?.aborted)
|
|
8246
|
+
abort();
|
|
8175
8247
|
const currentBaseUrl = document.baseURI;
|
|
8176
8248
|
rememberResourceUrls(document, currentBaseUrl);
|
|
8177
8249
|
const context = {
|
|
@@ -8195,6 +8267,7 @@ async function navigate(opts) {
|
|
|
8195
8267
|
}
|
|
8196
8268
|
};
|
|
8197
8269
|
try {
|
|
8270
|
+
assertActiveNavigation(transaction);
|
|
8198
8271
|
if (formEvent)
|
|
8199
8272
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8200
8273
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -8207,6 +8280,10 @@ async function navigate(opts) {
|
|
|
8207
8280
|
saveScrollPosition();
|
|
8208
8281
|
// Pick target element to swap
|
|
8209
8282
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
8283
|
+
if (opts.strictTarget && (!opts.targetSelector || !target?.matches(opts.targetSelector))) {
|
|
8284
|
+
context.outcome = 'invalid-response';
|
|
8285
|
+
return; // A queued explicit target disappeared; never broaden the swap.
|
|
8286
|
+
}
|
|
8210
8287
|
context.target = target;
|
|
8211
8288
|
if (!target) {
|
|
8212
8289
|
if (isActiveNavigation(transaction))
|
|
@@ -8251,7 +8328,12 @@ async function navigate(opts) {
|
|
|
8251
8328
|
else {
|
|
8252
8329
|
// Check preload cache if GET
|
|
8253
8330
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
8254
|
-
if (opts.
|
|
8331
|
+
if (opts.fresh) {
|
|
8332
|
+
preloadControllers.get(preloadKey)?.abort();
|
|
8333
|
+
preloadControllers.delete(preloadKey);
|
|
8334
|
+
preloadCache.delete(preloadKey);
|
|
8335
|
+
}
|
|
8336
|
+
if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
|
|
8255
8337
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
8256
8338
|
try {
|
|
8257
8339
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -8459,7 +8541,10 @@ async function navigate(opts) {
|
|
|
8459
8541
|
finalizeCommit();
|
|
8460
8542
|
}
|
|
8461
8543
|
// Handle scroll after mount scopes
|
|
8462
|
-
if (
|
|
8544
|
+
if (opts.scroll === false) {
|
|
8545
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
8546
|
+
}
|
|
8547
|
+
else if (changesState) {
|
|
8463
8548
|
handleScroll(targetUrl, opts.trigger);
|
|
8464
8549
|
}
|
|
8465
8550
|
else if (opts.popstate) {
|
|
@@ -8524,6 +8609,7 @@ async function navigate(opts) {
|
|
|
8524
8609
|
activeNavigation = null;
|
|
8525
8610
|
progressBar?.complete();
|
|
8526
8611
|
}
|
|
8612
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
8527
8613
|
transaction.resolveDone();
|
|
8528
8614
|
if (formEvent)
|
|
8529
8615
|
submittingForms.delete(formEvent.form);
|
|
@@ -8534,6 +8620,7 @@ async function navigate(opts) {
|
|
|
8534
8620
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8535
8621
|
}));
|
|
8536
8622
|
}
|
|
8623
|
+
opts.onEnd?.({ ...context });
|
|
8537
8624
|
}
|
|
8538
8625
|
}
|
|
8539
8626
|
function shouldBoost(el) {
|
|
@@ -8564,7 +8651,7 @@ function onClickRouter(element) {
|
|
|
8564
8651
|
const scope = getScopeFromElement(element);
|
|
8565
8652
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
8566
8653
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
8567
|
-
|
|
8654
|
+
navigateRequest({
|
|
8568
8655
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
8569
8656
|
});
|
|
8570
8657
|
}
|
|
@@ -8613,7 +8700,7 @@ function onClick(event) {
|
|
|
8613
8700
|
return;
|
|
8614
8701
|
event.preventDefault();
|
|
8615
8702
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
8616
|
-
|
|
8703
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
8617
8704
|
}
|
|
8618
8705
|
function onMouseOverCapture(event) {
|
|
8619
8706
|
const target = event.target;
|
|
@@ -8669,7 +8756,7 @@ function onSubmit(event) {
|
|
|
8669
8756
|
return;
|
|
8670
8757
|
const formData = new FormData(form, submitter);
|
|
8671
8758
|
submittingForms.add(form);
|
|
8672
|
-
void
|
|
8759
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8673
8760
|
}
|
|
8674
8761
|
function onPopState(event) {
|
|
8675
8762
|
const url = window.location.href;
|
|
@@ -8687,14 +8774,14 @@ function onPopState(event) {
|
|
|
8687
8774
|
}
|
|
8688
8775
|
event.preventDefault();
|
|
8689
8776
|
// The browser changes location before popstate fires. Stop any pending page
|
|
8690
|
-
// script immediately, then let
|
|
8777
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
8691
8778
|
if (activeNavigation?.committing)
|
|
8692
8779
|
cancelNavigation(activeNavigation);
|
|
8693
8780
|
// The browser has already moved to the destination history entry. Keep the
|
|
8694
8781
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
8695
8782
|
currentHistoryEntryId = destinationEntryId;
|
|
8696
8783
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
8697
|
-
|
|
8784
|
+
navigateRequest({
|
|
8698
8785
|
url,
|
|
8699
8786
|
method: 'GET',
|
|
8700
8787
|
replace: true,
|
|
@@ -8776,10 +8863,12 @@ const Gyos = {
|
|
|
8776
8863
|
onAfterNavigate,
|
|
8777
8864
|
onBeforeSwap,
|
|
8778
8865
|
onNavigationEnd,
|
|
8866
|
+
navigate,
|
|
8867
|
+
refresh,
|
|
8779
8868
|
portalCreate,
|
|
8780
8869
|
portalDestroy,
|
|
8781
8870
|
setCspNonce,
|
|
8782
|
-
version: '0.
|
|
8871
|
+
version: '0.5.0'
|
|
8783
8872
|
};
|
|
8784
8873
|
|
|
8785
8874
|
// This file was generated. Do not modify manually!
|