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.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
|
*/
|
|
@@ -5662,6 +5662,21 @@ setMountFunction(mount);
|
|
|
5662
5662
|
* Registry of all scopes
|
|
5663
5663
|
*/
|
|
5664
5664
|
const scopeRegistry = new Map();
|
|
5665
|
+
const warnedReveals = new WeakSet();
|
|
5666
|
+
function diagnoseUnscopedReveals(root) {
|
|
5667
|
+
if (!DEBUG())
|
|
5668
|
+
return;
|
|
5669
|
+
const elements = [...root.querySelectorAll('[g-reveal]')];
|
|
5670
|
+
if (root instanceof Element && root.hasAttribute('g-reveal'))
|
|
5671
|
+
elements.unshift(root);
|
|
5672
|
+
for (const element of elements) {
|
|
5673
|
+
if (warnedReveals.has(element) || isInIgnoredTree(element)
|
|
5674
|
+
|| element.closest('[g-scope]') || getScopeFromElement(element))
|
|
5675
|
+
continue;
|
|
5676
|
+
warnedReveals.add(element);
|
|
5677
|
+
console.warn('[Gyos] g-reveal has no owning scope. Add g-scope to its container; global reveal CSS may otherwise hide this content.', element);
|
|
5678
|
+
}
|
|
5679
|
+
}
|
|
5665
5680
|
/**
|
|
5666
5681
|
* Register a scope
|
|
5667
5682
|
*/
|
|
@@ -5709,6 +5724,7 @@ function mountAll(root) {
|
|
|
5709
5724
|
allElements.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5710
5725
|
// Filter out elements inside structural directives - they will be mounted by structural processor
|
|
5711
5726
|
allElements.forEach(el => !hasStructuralParent(el) && mount(el));
|
|
5727
|
+
diagnoseUnscopedReveals(document.body);
|
|
5712
5728
|
}
|
|
5713
5729
|
function mountTree(el) {
|
|
5714
5730
|
if (isInIgnoredTree(el) || !document.body.contains(el))
|
|
@@ -5719,6 +5735,7 @@ function mountTree(el) {
|
|
|
5719
5735
|
// Child scopes own their subtree before an existing parent scope parses the insertion.
|
|
5720
5736
|
candidates.sort((a, b) => getDepth(b) - getDepth(a));
|
|
5721
5737
|
candidates.forEach(element => !hasStructuralParent(element) && mount(element));
|
|
5738
|
+
diagnoseUnscopedReveals(el);
|
|
5722
5739
|
if (getMountedScope(el))
|
|
5723
5740
|
return;
|
|
5724
5741
|
const ownerScope = getScopeFromElement(el);
|
|
@@ -5737,7 +5754,7 @@ function mount(el) {
|
|
|
5737
5754
|
return;
|
|
5738
5755
|
// Check if element removed but still has g-scope (possible in some edge cases)
|
|
5739
5756
|
getAllMountedScopes().forEach((_, mountedEl) => {
|
|
5740
|
-
if (!
|
|
5757
|
+
if (!mountedEl.isConnected) {
|
|
5741
5758
|
disposeEffects(mountedEl);
|
|
5742
5759
|
}
|
|
5743
5760
|
});
|
|
@@ -7049,7 +7066,8 @@ function getPersistKey(el, generateIfMissing = false) {
|
|
|
7049
7066
|
el.dataset.gyosPersistId = key;
|
|
7050
7067
|
return key;
|
|
7051
7068
|
}
|
|
7052
|
-
//
|
|
7069
|
+
// Keep the parking host outside body: body itself may be the swap target.
|
|
7070
|
+
// A disconnected parking host makes browsers pause otherwise persisted media.
|
|
7053
7071
|
const persistParking = typeof document !== 'undefined'
|
|
7054
7072
|
? (() => {
|
|
7055
7073
|
const park = document.createElement('div');
|
|
@@ -7058,12 +7076,7 @@ const persistParking = typeof document !== 'undefined'
|
|
|
7058
7076
|
park.style.top = '-99999px';
|
|
7059
7077
|
park.style.width = '0';
|
|
7060
7078
|
park.style.height = '0';
|
|
7061
|
-
|
|
7062
|
-
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(park));
|
|
7063
|
-
}
|
|
7064
|
-
else {
|
|
7065
|
-
document.body.appendChild(park);
|
|
7066
|
-
}
|
|
7079
|
+
document.documentElement.appendChild(park);
|
|
7067
7080
|
return park;
|
|
7068
7081
|
})()
|
|
7069
7082
|
: null;
|
|
@@ -7074,8 +7087,8 @@ function elementsIn(root) {
|
|
|
7074
7087
|
return elements;
|
|
7075
7088
|
}
|
|
7076
7089
|
function ensureParkingIsConnected() {
|
|
7077
|
-
if (persistParking &&
|
|
7078
|
-
document.
|
|
7090
|
+
if (persistParking && persistParking.parentElement !== document.documentElement) {
|
|
7091
|
+
document.documentElement.appendChild(persistParking);
|
|
7079
7092
|
}
|
|
7080
7093
|
}
|
|
7081
7094
|
function detachPersist(root = document) {
|
|
@@ -7093,12 +7106,18 @@ function detachPersist(root = document) {
|
|
|
7093
7106
|
});
|
|
7094
7107
|
}
|
|
7095
7108
|
function mergePersistIntoLive(root) {
|
|
7109
|
+
// Return the host to the current body before scope mounting/cleanup inspects it.
|
|
7110
|
+
if (persistParking && persistParking.parentElement !== document.body) {
|
|
7111
|
+
document.body.appendChild(persistParking);
|
|
7112
|
+
}
|
|
7096
7113
|
if (!persistEntries.size)
|
|
7097
7114
|
return;
|
|
7098
7115
|
// If placeholders lack ids but we only have one persist entry, assign its key for convenience
|
|
7099
7116
|
if (persistEntries.size === 1) {
|
|
7100
7117
|
const loneKey = Array.from(persistEntries.keys())[0];
|
|
7101
7118
|
elementsIn(root).forEach(el => {
|
|
7119
|
+
if (persistParking?.contains(el))
|
|
7120
|
+
return;
|
|
7102
7121
|
if (!getPersistKey(el, false)) {
|
|
7103
7122
|
el.dataset.gyosPersistId = loneKey;
|
|
7104
7123
|
}
|
|
@@ -7106,6 +7125,8 @@ function mergePersistIntoLive(root) {
|
|
|
7106
7125
|
}
|
|
7107
7126
|
// Element placeholders
|
|
7108
7127
|
elementsIn(root).forEach(placeholder => {
|
|
7128
|
+
if (persistParking?.contains(placeholder))
|
|
7129
|
+
return;
|
|
7109
7130
|
const key = getPersistKey(placeholder, false);
|
|
7110
7131
|
if (!key)
|
|
7111
7132
|
return;
|
|
@@ -7123,6 +7144,8 @@ function mergePersistIntoLive(root) {
|
|
|
7123
7144
|
const toReplace = [];
|
|
7124
7145
|
while (walker.nextNode()) {
|
|
7125
7146
|
const comment = walker.currentNode;
|
|
7147
|
+
if (persistParking?.contains(comment))
|
|
7148
|
+
continue;
|
|
7126
7149
|
const match = comment.data.match(/g-persist[:=]\s*([A-Za-z0-9_\-:.]+)/);
|
|
7127
7150
|
if (match) {
|
|
7128
7151
|
toReplace.push({ node: comment, key: match[1] });
|
|
@@ -7780,6 +7803,36 @@ function prepareNavigationHtml(html) {
|
|
|
7780
7803
|
* Implements attribute-driven routing, snapshot caching, and persistent islands.
|
|
7781
7804
|
*/
|
|
7782
7805
|
const submittingForms = new WeakSet();
|
|
7806
|
+
async function visit(url, options, fresh) {
|
|
7807
|
+
const destination = new URL(url, document.baseURI);
|
|
7808
|
+
if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
|
|
7809
|
+
throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
|
|
7810
|
+
}
|
|
7811
|
+
if (options.target !== undefined && !(document.querySelector(options.target) instanceof HTMLElement)) {
|
|
7812
|
+
throw new TypeError('Gyos.navigate target does not exist.');
|
|
7813
|
+
}
|
|
7814
|
+
if (!document.querySelector('[g-boost]')) {
|
|
7815
|
+
throw new TypeError('Gyos.navigate requires a g-boost layout.');
|
|
7816
|
+
}
|
|
7817
|
+
startRouter();
|
|
7818
|
+
let result;
|
|
7819
|
+
await navigateRequest({
|
|
7820
|
+
url: destination.href, method: 'GET',
|
|
7821
|
+
changeState: options.history !== 'none', replace: options.history === 'replace',
|
|
7822
|
+
targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
|
|
7823
|
+
currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
|
|
7824
|
+
onEnd: context => { result = context; }
|
|
7825
|
+
});
|
|
7826
|
+
return result;
|
|
7827
|
+
}
|
|
7828
|
+
/** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
|
|
7829
|
+
function navigate(url, options = {}) {
|
|
7830
|
+
return visit(url, options, false);
|
|
7831
|
+
}
|
|
7832
|
+
/** Fetch the current URL again, preserving history and scroll by default. */
|
|
7833
|
+
function refresh(options = {}) {
|
|
7834
|
+
return visit(location.href, { history: 'none', scroll: false, ...options }, true);
|
|
7835
|
+
}
|
|
7783
7836
|
const snapshots = new Map();
|
|
7784
7837
|
const preloadCache = new Map();
|
|
7785
7838
|
const preloadControllers = new Map();
|
|
@@ -8166,12 +8219,27 @@ function fallbackFromBoost(opts, url, requestSent) {
|
|
|
8166
8219
|
}
|
|
8167
8220
|
console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
|
|
8168
8221
|
}
|
|
8169
|
-
async function
|
|
8222
|
+
async function navigateRequest(opts) {
|
|
8223
|
+
const finishUnstarted = () => {
|
|
8224
|
+
opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
|
|
8225
|
+
trigger: opts.trigger || null, target: null, form: null, popstate: false,
|
|
8226
|
+
signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
|
|
8227
|
+
};
|
|
8228
|
+
if (opts.signal?.aborted) {
|
|
8229
|
+
finishUnstarted();
|
|
8230
|
+
return;
|
|
8231
|
+
}
|
|
8170
8232
|
while (activeNavigation) {
|
|
8171
8233
|
const previous = activeNavigation;
|
|
8172
8234
|
if (previous.committing) {
|
|
8173
8235
|
log('[GyosRouter] Waiting for previous DOM commit');
|
|
8174
|
-
|
|
8236
|
+
try {
|
|
8237
|
+
await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
|
|
8238
|
+
}
|
|
8239
|
+
catch {
|
|
8240
|
+
finishUnstarted();
|
|
8241
|
+
return;
|
|
8242
|
+
}
|
|
8175
8243
|
continue;
|
|
8176
8244
|
}
|
|
8177
8245
|
log('[GyosRouter] Cancelling previous navigation');
|
|
@@ -8190,6 +8258,10 @@ async function navigate(opts) {
|
|
|
8190
8258
|
resolveDone
|
|
8191
8259
|
};
|
|
8192
8260
|
activeNavigation = transaction;
|
|
8261
|
+
const abort = () => cancelNavigation(transaction);
|
|
8262
|
+
opts.signal?.addEventListener('abort', abort, { once: true });
|
|
8263
|
+
if (opts.signal?.aborted)
|
|
8264
|
+
abort();
|
|
8193
8265
|
const currentBaseUrl = document.baseURI;
|
|
8194
8266
|
rememberResourceUrls(document, currentBaseUrl);
|
|
8195
8267
|
const context = {
|
|
@@ -8213,6 +8285,7 @@ async function navigate(opts) {
|
|
|
8213
8285
|
}
|
|
8214
8286
|
};
|
|
8215
8287
|
try {
|
|
8288
|
+
assertActiveNavigation(transaction);
|
|
8216
8289
|
if (formEvent)
|
|
8217
8290
|
document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
|
|
8218
8291
|
runNavigationHooks(beforeNavigate, opts.url, context);
|
|
@@ -8225,6 +8298,10 @@ async function navigate(opts) {
|
|
|
8225
8298
|
saveScrollPosition();
|
|
8226
8299
|
// Pick target element to swap
|
|
8227
8300
|
let target = resolveTarget(opts.trigger, opts.targetSelector, opts.targetOutletIndex);
|
|
8301
|
+
if (opts.strictTarget && (!opts.targetSelector || !target?.matches(opts.targetSelector))) {
|
|
8302
|
+
context.outcome = 'invalid-response';
|
|
8303
|
+
return; // A queued explicit target disappeared; never broaden the swap.
|
|
8304
|
+
}
|
|
8228
8305
|
context.target = target;
|
|
8229
8306
|
if (!target) {
|
|
8230
8307
|
if (isActiveNavigation(transaction))
|
|
@@ -8269,7 +8346,12 @@ async function navigate(opts) {
|
|
|
8269
8346
|
else {
|
|
8270
8347
|
// Check preload cache if GET
|
|
8271
8348
|
const preloadKey = canonicalUrl(finalUrl, true);
|
|
8272
|
-
if (opts.
|
|
8349
|
+
if (opts.fresh) {
|
|
8350
|
+
preloadControllers.get(preloadKey)?.abort();
|
|
8351
|
+
preloadControllers.delete(preloadKey);
|
|
8352
|
+
preloadCache.delete(preloadKey);
|
|
8353
|
+
}
|
|
8354
|
+
if (!opts.fresh && opts.method.toUpperCase() === 'GET' && preloadCache.has(preloadKey)) {
|
|
8273
8355
|
log('[GyosRouter] using preload cache for', finalUrl);
|
|
8274
8356
|
try {
|
|
8275
8357
|
response = await waitForNavigation(preloadCache.get(preloadKey), transaction.controller.signal);
|
|
@@ -8477,7 +8559,10 @@ async function navigate(opts) {
|
|
|
8477
8559
|
finalizeCommit();
|
|
8478
8560
|
}
|
|
8479
8561
|
// Handle scroll after mount scopes
|
|
8480
|
-
if (
|
|
8562
|
+
if (opts.scroll === false) {
|
|
8563
|
+
// Explicit refresh/navigation policy keeps the current viewport.
|
|
8564
|
+
}
|
|
8565
|
+
else if (changesState) {
|
|
8481
8566
|
handleScroll(targetUrl, opts.trigger);
|
|
8482
8567
|
}
|
|
8483
8568
|
else if (opts.popstate) {
|
|
@@ -8542,6 +8627,7 @@ async function navigate(opts) {
|
|
|
8542
8627
|
activeNavigation = null;
|
|
8543
8628
|
progressBar?.complete();
|
|
8544
8629
|
}
|
|
8630
|
+
opts.signal?.removeEventListener('abort', abort);
|
|
8545
8631
|
transaction.resolveDone();
|
|
8546
8632
|
if (formEvent)
|
|
8547
8633
|
submittingForms.delete(formEvent.form);
|
|
@@ -8552,6 +8638,7 @@ async function navigate(opts) {
|
|
|
8552
8638
|
detail: { ...formEvent, url, status, outcome, committed, fallback }
|
|
8553
8639
|
}));
|
|
8554
8640
|
}
|
|
8641
|
+
opts.onEnd?.({ ...context });
|
|
8555
8642
|
}
|
|
8556
8643
|
}
|
|
8557
8644
|
function shouldBoost(el) {
|
|
@@ -8582,7 +8669,7 @@ function onClickRouter(element) {
|
|
|
8582
8669
|
const scope = getScopeFromElement(element);
|
|
8583
8670
|
const jsonData = evaluateExpression(decodeURIComponent(element.getAttribute(paramsAttr) || ''), scope, false);
|
|
8584
8671
|
// The default changeState is false, as this is commonly used for: load more, infinite scroll, etc.
|
|
8585
|
-
|
|
8672
|
+
navigateRequest({
|
|
8586
8673
|
url: parsedUrl.toString(), method, trigger: element, jsonData, changeState: false
|
|
8587
8674
|
});
|
|
8588
8675
|
}
|
|
@@ -8631,7 +8718,7 @@ function onClick(event) {
|
|
|
8631
8718
|
return;
|
|
8632
8719
|
event.preventDefault();
|
|
8633
8720
|
// The default changeState is true, as this is commonly used for: navigation, etc.
|
|
8634
|
-
|
|
8721
|
+
navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
|
|
8635
8722
|
}
|
|
8636
8723
|
function onMouseOverCapture(event) {
|
|
8637
8724
|
const target = event.target;
|
|
@@ -8687,7 +8774,7 @@ function onSubmit(event) {
|
|
|
8687
8774
|
return;
|
|
8688
8775
|
const formData = new FormData(form, submitter);
|
|
8689
8776
|
submittingForms.add(form);
|
|
8690
|
-
void
|
|
8777
|
+
void navigateRequest({ url: url.toString(), method, trigger: form, form, formData, formEncoding, changeState: method === 'GET' });
|
|
8691
8778
|
}
|
|
8692
8779
|
function onPopState(event) {
|
|
8693
8780
|
const url = window.location.href;
|
|
@@ -8705,14 +8792,14 @@ function onPopState(event) {
|
|
|
8705
8792
|
}
|
|
8706
8793
|
event.preventDefault();
|
|
8707
8794
|
// The browser changes location before popstate fires. Stop any pending page
|
|
8708
|
-
// script immediately, then let
|
|
8795
|
+
// script immediately, then let navigateRequest() wait for its DOM finalizer.
|
|
8709
8796
|
if (activeNavigation?.committing)
|
|
8710
8797
|
cancelNavigation(activeNavigation);
|
|
8711
8798
|
// The browser has already moved to the destination history entry. Keep the
|
|
8712
8799
|
// router's entry pointer aligned before any restored page script can navigate.
|
|
8713
8800
|
currentHistoryEntryId = destinationEntryId;
|
|
8714
8801
|
// No snapshot, do a normal navigation without changing history (changeState: false)
|
|
8715
|
-
|
|
8802
|
+
navigateRequest({
|
|
8716
8803
|
url,
|
|
8717
8804
|
method: 'GET',
|
|
8718
8805
|
replace: true,
|
|
@@ -8794,13 +8881,15 @@ const Gyos = {
|
|
|
8794
8881
|
onAfterNavigate,
|
|
8795
8882
|
onBeforeSwap,
|
|
8796
8883
|
onNavigationEnd,
|
|
8884
|
+
navigate,
|
|
8885
|
+
refresh,
|
|
8797
8886
|
portalCreate,
|
|
8798
8887
|
portalDestroy,
|
|
8799
8888
|
setCspNonce,
|
|
8800
|
-
version: '0.
|
|
8889
|
+
version: '0.5.0'
|
|
8801
8890
|
};
|
|
8802
8891
|
|
|
8803
8892
|
setExpressionRuntime(standardExpressionRuntime);
|
|
8804
8893
|
|
|
8805
|
-
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 };
|
|
8894
|
+
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 };
|
|
8806
8895
|
//# sourceMappingURL=gyos.esm.js.map
|