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.csp.esm.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
|
*/
|
|
@@ -12279,6 +12279,21 @@ setMountFunction(mount);
|
|
|
12279
12279
|
* Registry of all scopes
|
|
12280
12280
|
*/
|
|
12281
12281
|
const scopeRegistry = new Map();
|
|
12282
|
+
const warnedReveals = new WeakSet();
|
|
12283
|
+
function diagnoseUnscopedReveals(root) {
|
|
12284
|
+
if (!DEBUG())
|
|
12285
|
+
return;
|
|
12286
|
+
const elements = [...root.querySelectorAll('[g-reveal]')];
|
|
12287
|
+
if (root instanceof Element && root.hasAttribute('g-reveal'))
|
|
12288
|
+
elements.unshift(root);
|
|
12289
|
+
for (const element of elements) {
|
|
12290
|
+
if (warnedReveals.has(element) || isInIgnoredTree(element)
|
|
12291
|
+
|| element.closest('[g-scope]') || getScopeFromElement(element))
|
|
12292
|
+
continue;
|
|
12293
|
+
warnedReveals.add(element);
|
|
12294
|
+
console.warn('[Gyos] g-reveal has no owning scope. Add g-scope to its container; global reveal CSS may otherwise hide this content.', element);
|
|
12295
|
+
}
|
|
12296
|
+
}
|
|
12282
12297
|
/**
|
|
12283
12298
|
* Register a scope
|
|
12284
12299
|
*/
|
|
@@ -12326,6 +12341,7 @@ function mountAll(root) {
|
|
|
12326
12341
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
12327
12342
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
12328
12343
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
12344
|
+
diagnoseUnscopedReveals(document.body);
|
|
12329
12345
|
}
|
|
12330
12346
|
function mountTree(el) {
|
|
12331
12347
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -12336,6 +12352,7 @@ function mountTree(el) {
|
|
|
12336
12352
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
12337
12353
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
12338
12354
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
12355
|
+
diagnoseUnscopedReveals(el);
|
|
12339
12356
|
if (getMountedScope(el))
|
|
12340
12357
|
return;
|
|
12341
12358
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -12354,7 +12371,7 @@ function mount(el) {
|
|
|
12354
12371
|
return;
|
|
12355
12372
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
12356
12373
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
12357
|
-
if (!
|
|
12374
|
+
if (!mountedEl.isConnected) {
|
|
12358
12375
|
disposeEffects(mountedEl);
|
|
12359
12376
|
}
|
|
12360
12377
|
});
|
|
@@ -13666,7 +13683,8 @@ function getPersistKey(el, generateIfMissing = false) {
|
|
|
13666
13683
|
el.dataset.gyosPersistId = key;
|
|
13667
13684
|
return key;
|
|
13668
13685
|
}
|
|
13669
|
-
//
|
|
13686
|
+
// Keep the parking host outside body: body itself may be the swap target.
|
|
13687
|
+
// A disconnected parking host makes browsers pause otherwise persisted media.
|
|
13670
13688
|
const persistParking = typeof document !== 'undefined'
|
|
13671
13689
|
? (() => {
|
|
13672
13690
|
const park = document.createElement('div');
|
|
@@ -13675,12 +13693,7 @@ const persistParking = typeof document !== 'undefined'
|
|
|
13675
13693
|
park.style.top = '-99999px';
|
|
13676
13694
|
park.style.width = '0';
|
|
13677
13695
|
park.style.height = '0';
|
|
13678
|
-
|
|
13679
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
13680
|
-
}
|
|
13681
|
-
else {
|
|
13682
|
-
document.body.appendChild(park);
|
|
13683
|
-
}
|
|
13696
|
+
document.documentElement.appendChild(park);
|
|
13684
13697
|
return park;
|
|
13685
13698
|
})()
|
|
13686
13699
|
: null;
|
|
@@ -13691,8 +13704,8 @@ function elementsIn(root) {
|
|
|
13691
13704
|
return elements;
|
|
13692
13705
|
}
|
|
13693
13706
|
function ensureParkingIsConnected() {
|
|
13694
|
-
if (persistParking &&
|
|
13695
|
-
document.
|
|
13707
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
13708
|
+
document.documentElement.appendChild(persistParking);
|
|
13696
13709
|
}
|
|
13697
13710
|
}
|
|
13698
13711
|
function detachPersist(root = document) {
|
|
@@ -13710,12 +13723,18 @@ function detachPersist(root = document) {
|
|
|
13710
13723
|
});
|
|
13711
13724
|
}
|
|
13712
13725
|
function mergePersistIntoLive(root) {
|
|
13726
|
+
// Return the host to the current body before scope mounting/cleanup inspects it.
|
|
13727
|
+
if (persistParking && persistParking.parentElement !== document.body) {
|
|
13728
|
+
document.body.appendChild(persistParking);
|
|
13729
|
+
}
|
|
13713
13730
|
if (!persistEntries.size)
|
|
13714
13731
|
return;
|
|
13715
13732
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
13716
13733
|
if (persistEntries.size === 1) {
|
|
13717
13734
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
13718
13735
|
elementsIn(root).forEach(el => {
|
|
13736
|
+
if (persistParking?.contains(el))
|
|
13737
|
+
return;
|
|
13719
13738
|
if (!getPersistKey(el, false)) {
|
|
13720
13739
|
el.dataset.gyosPersistId = loneKey;
|
|
13721
13740
|
}
|
|
@@ -13723,6 +13742,8 @@ function mergePersistIntoLive(root) {
|
|
|
13723
13742
|
}
|
|
13724
13743
|
// Element placeholders
|
|
13725
13744
|
elementsIn(root).forEach(placeholder => {
|
|
13745
|
+
if (persistParking?.contains(placeholder))
|
|
13746
|
+
return;
|
|
13726
13747
|
const key = getPersistKey(placeholder, false);
|
|
13727
13748
|
if (!key)
|
|
13728
13749
|
return;
|
|
@@ -13740,6 +13761,8 @@ function mergePersistIntoLive(root) {
|
|
|
13740
13761
|
const toReplace = [];
|
|
13741
13762
|
while (walker.nextNode()) {
|
|
13742
13763
|
const comment = walker.currentNode;
|
|
13764
|
+
if (persistParking?.contains(comment))
|
|
13765
|
+
continue;
|
|
13743
13766
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
13744
13767
|
if (match) {
|
|
13745
13768
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -14397,6 +14420,36 @@ function prepareNavigationHtml(html) {
|
|
|
14397
14420
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
14398
14421
|
*/
|
|
14399
14422
|
const submittingForms = new WeakSet();
|
|
14423
|
+
async function visit(url, options, fresh) {
|
|
14424
|
+
const destination = new URL(url, document.baseURI);
|
|
14425
|
+
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
14426
|
+
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
14427
|
+
}
|
|
14428
|
+
if (options.target !== undefined && !(document.querySelector(options.target) instanceof HTMLElement)) {
|
|
14429
|
+
throw new TypeError('Gyos.navigate target does not exist.');
|
|
14430
|
+
}
|
|
14431
|
+
if (!document.querySelector('[g-boost]')) {
|
|
14432
|
+
throw new TypeError('Gyos.navigate requires a g-boost layout.');
|
|
14433
|
+
}
|
|
14434
|
+
startRouter();
|
|
14435
|
+
let result;
|
|
14436
|
+
await navigateRequest({
|
|
14437
|
+
url: destination.href, method: 'GET',
|
|
14438
|
+
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
14439
|
+
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
14440
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
|
|
14441
|
+
onEnd: context => { result = context; }
|
|
14442
|
+
});
|
|
14443
|
+
return result;
|
|
14444
|
+
}
|
|
14445
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
14446
|
+
function navigate(url, options = {}) {
|
|
14447
|
+
return visit(url, options, false);
|
|
14448
|
+
}
|
|
14449
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
14450
|
+
function refresh(options = {}) {
|
|
14451
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, true);
|
|
14452
|
+
}
|
|
14400
14453
|
const snapshots = new Map();
|
|
14401
14454
|
const preloadCache = new Map();
|
|
14402
14455
|
const preloadControllers = new Map();
|
|
@@ -14783,12 +14836,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
14783
14836
|
}
|
|
14784
14837
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
14785
14838
|
}
|
|
14786
|
-
async function
|
|
14839
|
+
async function navigateRequest(opts) {
|
|
14840
|
+
const finishUnstarted = () => {
|
|
14841
|
+
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
14842
|
+
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
14843
|
+
signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
14844
|
+
};
|
|
14845
|
+
if (opts.signal?.aborted) {
|
|
14846
|
+
finishUnstarted();
|
|
14847
|
+
return;
|
|
14848
|
+
}
|
|
14787
14849
|
while (activeNavigation) {
|
|
14788
14850
|
const previous = activeNavigation;
|
|
14789
14851
|
if (previous.committing) {
|
|
14790
14852
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
14791
|
-
|
|
14853
|
+
try {
|
|
14854
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
14855
|
+
}
|
|
14856
|
+
catch {
|
|
14857
|
+
finishUnstarted();
|
|
14858
|
+
return;
|
|
14859
|
+
}
|
|
14792
14860
|
continue;
|
|
14793
14861
|
}
|
|
14794
14862
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -14807,6 +14875,10 @@ async function navigate(opts) {
|
|
|
14807
14875
|
resolveDone
|
|
14808
14876
|
};
|
|
14809
14877
|
activeNavigation = transaction;
|
|
14878
|
+
const abort = () => cancelNavigation(transaction);
|
|
14879
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
14880
|
+
if (opts.signal?.aborted)
|
|
14881
|
+
abort();
|
|
14810
14882
|
const currentBaseUrl = document.baseURI;
|
|
14811
14883
|
rememberResourceUrls(document, currentBaseUrl);
|
|
14812
14884
|
const context = {
|
|
@@ -14830,6 +14902,7 @@ async function navigate(opts) {
|
|
|
14830
14902
|
}
|
|
14831
14903
|
};
|
|
14832
14904
|
try {
|
|
14905
|
+
assertActiveNavigation(transaction);
|
|
14833
14906
|
if (formEvent)
|
|
14834
14907
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
14835
14908
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -14842,6 +14915,10 @@ async function navigate(opts) {
|
|
|
14842
14915
|
saveScrollPosition();
|
|
14843
14916
|
// Pick target element to swap
|
|
14844
14917
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
14918
|
+
if (opts.strictTarget && (!opts.targetSelector || !target?.matches(opts.targetSelector))) {
|
|
14919
|
+
context.outcome = 'invalid-response';
|
|
14920
|
+
return; // A queued explicit target disappeared; never broaden the swap.
|
|
14921
|
+
}
|
|
14845
14922
|
context.target = target;
|
|
14846
14923
|
if (!target) {
|
|
14847
14924
|
if (isActiveNavigation(transaction))
|
|
@@ -14886,7 +14963,12 @@ async function navigate(opts) {
|
|
|
14886
14963
|
else {
|
|
14887
14964
|
// Check preload cache if GET
|
|
14888
14965
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
14889
|
-
if (opts.
|
|
14966
|
+
if (opts.fresh) {
|
|
14967
|
+
preloadControllers.get(preloadKey)?.abort();
|
|
14968
|
+
preloadControllers.delete(preloadKey);
|
|
14969
|
+
preloadCache.delete(preloadKey);
|
|
14970
|
+
}
|
|
14971
|
+
if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
|
|
14890
14972
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
14891
14973
|
try {
|
|
14892
14974
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -15094,7 +15176,10 @@ async function navigate(opts) {
|
|
|
15094
15176
|
finalizeCommit();
|
|
15095
15177
|
}
|
|
15096
15178
|
// Handle scroll after mount scopes
|
|
15097
|
-
if (
|
|
15179
|
+
if (opts.scroll === false) {
|
|
15180
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
15181
|
+
}
|
|
15182
|
+
else if (changesState) {
|
|
15098
15183
|
handleScroll(targetUrl, opts.trigger);
|
|
15099
15184
|
}
|
|
15100
15185
|
else if (opts.popstate) {
|
|
@@ -15159,6 +15244,7 @@ async function navigate(opts) {
|
|
|
15159
15244
|
activeNavigation = null;
|
|
15160
15245
|
progressBar?.complete();
|
|
15161
15246
|
}
|
|
15247
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
15162
15248
|
transaction.resolveDone();
|
|
15163
15249
|
if (formEvent)
|
|
15164
15250
|
submittingForms.delete(formEvent.form);
|
|
@@ -15169,6 +15255,7 @@ async function navigate(opts) {
|
|
|
15169
15255
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
15170
15256
|
}));
|
|
15171
15257
|
}
|
|
15258
|
+
opts.onEnd?.({ ...context });
|
|
15172
15259
|
}
|
|
15173
15260
|
}
|
|
15174
15261
|
function shouldBoost(el) {
|
|
@@ -15199,7 +15286,7 @@ function onClickRouter(element) {
|
|
|
15199
15286
|
const scope = getScopeFromElement(element);
|
|
15200
15287
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
15201
15288
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
15202
|
-
|
|
15289
|
+
navigateRequest({
|
|
15203
15290
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
15204
15291
|
});
|
|
15205
15292
|
}
|
|
@@ -15248,7 +15335,7 @@ function onClick(event) {
|
|
|
15248
15335
|
return;
|
|
15249
15336
|
event.preventDefault();
|
|
15250
15337
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
15251
|
-
|
|
15338
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
15252
15339
|
}
|
|
15253
15340
|
function onMouseOverCapture(event) {
|
|
15254
15341
|
const target = event.target;
|
|
@@ -15304,7 +15391,7 @@ function onSubmit(event) {
|
|
|
15304
15391
|
return;
|
|
15305
15392
|
const formData = new FormData(form, submitter);
|
|
15306
15393
|
submittingForms.add(form);
|
|
15307
|
-
void
|
|
15394
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
15308
15395
|
}
|
|
15309
15396
|
function onPopState(event) {
|
|
15310
15397
|
const url = window.location.href;
|
|
@@ -15322,14 +15409,14 @@ function onPopState(event) {
|
|
|
15322
15409
|
}
|
|
15323
15410
|
event.preventDefault();
|
|
15324
15411
|
// The browser changes location before popstate fires. Stop any pending page
|
|
15325
|
-
// script immediately, then let
|
|
15412
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
15326
15413
|
if (activeNavigation?.committing)
|
|
15327
15414
|
cancelNavigation(activeNavigation);
|
|
15328
15415
|
// The browser has already moved to the destination history entry. Keep the
|
|
15329
15416
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
15330
15417
|
currentHistoryEntryId = destinationEntryId;
|
|
15331
15418
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
15332
|
-
|
|
15419
|
+
navigateRequest({
|
|
15333
15420
|
url,
|
|
15334
15421
|
method: 'GET',
|
|
15335
15422
|
replace: true,
|
|
@@ -15411,13 +15498,15 @@ const Gyos = {
|
|
|
15411
15498
|
onAfterNavigate,
|
|
15412
15499
|
onBeforeSwap,
|
|
15413
15500
|
onNavigationEnd,
|
|
15501
|
+
navigate,
|
|
15502
|
+
refresh,
|
|
15414
15503
|
portalCreate,
|
|
15415
15504
|
portalDestroy,
|
|
15416
15505
|
setCspNonce,
|
|
15417
|
-
version: '0.
|
|
15506
|
+
version: '0.5.0'
|
|
15418
15507
|
};
|
|
15419
15508
|
|
|
15420
15509
|
setExpressionRuntime(cspExpressionRuntime);
|
|
15421
15510
|
|
|
15422
|
-
export { applyDirective, applyTransitionStyles, batch, disposeEffects as cleanup, clearAllEvents, computed, debounce, Gyos as default, directive, effect, emit, getEventListeners, getGlobalContainer, getStoreNames, getTransitionConfig, getValidator, getValidatorNames, hasStore, inject, isComputed, isSignal, markRaw, mount, mountAll, mountTree, getAllMountedScopes as mountedScopes, nextTick, off, on, onAfterNavigate, onBeforeNavigate, onBeforeSwap, onNavigationEnd, once, pipe, portalCreate, portalDestroy, provide, ready, registerTransition, removeStore, scope, setCspNonce, shallow, signal, startRouter, store, throttle, unref, untrack, useAsync, useCounter, useDebounce, useFetch, useInterval, useLocalStorage, useMediaQuery, useMouse, useThrottle, useTimeout, useToggle, useWindowSize, validate, validator };
|
|
15511
|
+
export { applyDirective, applyTransitionStyles, batch, disposeEffects as cleanup, clearAllEvents, computed, debounce, Gyos as default, directive, effect, emit, getEventListeners, getGlobalContainer, getStoreNames, getTransitionConfig, getValidator, getValidatorNames, hasStore, inject, isComputed, isSignal, markRaw, mount, mountAll, mountTree, getAllMountedScopes as mountedScopes, navigate, nextTick, off, on, onAfterNavigate, onBeforeNavigate, onBeforeSwap, onNavigationEnd, once, pipe, portalCreate, portalDestroy, provide, ready, refresh, registerTransition, removeStore, scope, setCspNonce, shallow, signal, startRouter, store, throttle, unref, untrack, useAsync, useCounter, useDebounce, useFetch, useInterval, useLocalStorage, useMediaQuery, useMouse, useThrottle, useTimeout, useToggle, useWindowSize, validate, validator };
|
|
15423
15512
|
//# sourceMappingURL=gyos.csp.esm.js.map
|