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 CHANGED
@@ -34,7 +34,7 @@ GyosJS is not trying to replace a full SPA framework. If your app is primarily c
34
34
  Use the browser auto-init build when you want HTML-first usage with minimal setup.
35
35
 
36
36
  ```html
37
- <script src="https://cdn.jsdelivr.net/npm/gyosjs@0.5.7/dist/gyos.auto.min.js"></script>
37
+ <script src="https://cdn.jsdelivr.net/npm/gyosjs@0.6.0/dist/gyos.auto.min.js"></script>
38
38
  ```
39
39
 
40
40
  That build attaches `window.Gyos`, starts the router when `g-boost` exists, injects transition styles, and mounts scopes when the page is ready.
@@ -47,7 +47,9 @@ interface NavigateOptions {
47
47
  signal?: AbortSignal;
48
48
  scroll?: boolean;
49
49
  fresh?: boolean;
50
+ background?: boolean;
50
51
  strictTarget?: boolean;
52
+ strictSource?: boolean;
51
53
  onEnd?: (context: NavigationContext) => void;
52
54
  historyFragment?: HTMLElement;
53
55
  historyEntryId?: string | null;
@@ -62,10 +64,16 @@ export interface NavigationOptions {
62
64
  currentHead?: boolean;
63
65
  signal?: AbortSignal;
64
66
  }
67
+ export interface RefreshOptions extends NavigationOptions {
68
+ /** Skip when another router transaction is in progress. */
69
+ background?: boolean;
70
+ /** Require the target selector in a complete HTML response. Fragments may omit it. */
71
+ strictSource?: boolean;
72
+ }
65
73
  /** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
66
74
  export declare function navigate(url: string | URL, options?: NavigationOptions): Promise<NavigationContext>;
67
75
  /** Fetch the current URL again, preserving history and scroll by default. */
68
- export declare function refresh(options?: NavigationOptions): Promise<NavigationContext>;
76
+ export declare function refresh({ background, strictSource, ...options }?: RefreshOptions): Promise<NavigationContext>;
69
77
  interface Snapshot {
70
78
  html: string;
71
79
  fullDocument: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/core/router/router.ts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GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAEvG;AAED,6EAA6E;AAC7E,wBAAgB,OAAO,CAAC,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,OAAO,EAAE,GAAE,cAAmB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAOjH;AAgBD,UAAU,QAAQ;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,OAAO,CAAC;CACtB;AA8CD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAErE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAEpE;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAEjE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,GAAG,MAAM,IAAI,CAE1F;AAED,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CA8BzD;AAiED,iBAAS,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAcrD;AAySD,iBAAe,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CA2bnE;AAmMD,iBAAS,gBAAgB,IAAI,IAAI,CAwBhC;AAGD,eAAO,MAAM,YAAY;;;;;iBA1mCuB,OAAO,CAAC,QAAQ,CAAC;oBAAc,eAAe;;;CAgnC7F,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GyosJS v0.5.7
2
+ * GyosJS v0.6.0
3
3
  * (c) 2026
4
4
  * @license MIT
5
5
  */
@@ -7661,8 +7661,10 @@ function morph(target, src) {
7661
7661
  while (idx < toChildren.length || idx < fromChildren.length) {
7662
7662
  const toChild = toChildren[idx] || null;
7663
7663
  let fromChild = fromChildren[idx] || null;
7664
- // Move an existing keyed child into the requested position before morphing it.
7665
- const requestedKey = explicitKeyFor(toChild);
7664
+ // Persist placeholders have their own placement path below, even when
7665
+ // they also carry an id or another explicit morph key.
7666
+ const toPersistKey = getPersistKey(toChild);
7667
+ const requestedKey = toPersistKey ? null : explicitKeyFor(toChild);
7666
7668
  if (requestedKey && explicitKeyFor(fromChild) !== requestedKey) {
7667
7669
  const matchingIndex = fromChildren.findIndex((candidate, candidateIndex) => candidateIndex > idx && explicitKeyFor(candidate) === requestedKey);
7668
7670
  if (matchingIndex !== -1) {
@@ -7677,7 +7679,6 @@ function morph(target, src) {
7677
7679
  }
7678
7680
  }
7679
7681
  // Check if either is persist comment/element
7680
- const toPersistKey = getPersistKey(toChild);
7681
7682
  const fromPersistKey = getPersistKey(fromChild);
7682
7683
  // If toChild is persist, check if we already have matching persist in fromChildren
7683
7684
  if (toPersistKey) {
@@ -8112,7 +8113,7 @@ function prepareNavigationHtml(html) {
8112
8113
  * Implements attribute-driven routing, snapshot caching, and persistent islands.
8113
8114
  */
8114
8115
  const submittingForms = new WeakSet();
8115
- async function visit(url, options, fresh) {
8116
+ async function visit(url, options, refreshPolicy) {
8116
8117
  const destination = new URL(url, document.baseURI);
8117
8118
  if (!['http:', 'https:'].includes(destination.protocol) || destination.origin !== location.origin || destination.username || destination.password) {
8118
8119
  throw new TypeError('Gyos.navigate requires a same-origin HTTP(S) URL without credentials.');
@@ -8129,21 +8130,27 @@ async function visit(url, options, fresh) {
8129
8130
  url: destination.href, method: 'GET',
8130
8131
  changeState: options.history !== 'none', replace: options.history === 'replace',
8131
8132
  targetSelector: options.target, strictTarget: options.target !== undefined, swapMode: options.swap,
8132
- currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, fresh,
8133
+ currentHead: options.currentHead, scroll: options.scroll, signal: options.signal, ...refreshPolicy,
8133
8134
  onEnd: context => { result = context; }
8134
8135
  });
8135
8136
  return result;
8136
8137
  }
8137
8138
  /** Navigate through the boost pipeline. Resolves after navigation-end hooks. */
8138
8139
  function navigate(url, options = {}) {
8139
- return visit(url, options, false);
8140
+ return visit(url, options);
8140
8141
  }
8141
8142
  /** Fetch the current URL again, preserving history and scroll by default. */
8142
- function refresh(options = {}) {
8143
- return visit(location.href, { history: 'none', scroll: false, ...options }, true);
8143
+ function refresh({ background, strictSource, ...options } = {}) {
8144
+ if (strictSource === true && options.target === undefined) {
8145
+ return Promise.reject(new TypeError('Gyos.refresh with strictSource requires a target selector.'));
8146
+ }
8147
+ return visit(location.href, { history: 'none', scroll: false, ...options }, {
8148
+ fresh: true, background: background === true, strictSource: strictSource === true
8149
+ });
8144
8150
  }
8145
8151
  const snapshots = new Map();
8146
8152
  const preloadCache = new Map();
8153
+ let preloadHover;
8147
8154
  const scrollPositions = new Map();
8148
8155
  const historyFragments = new Map();
8149
8156
  let routerStarted = false;
@@ -8153,6 +8160,7 @@ let progressBarEnabled = true;
8153
8160
  let currentUrl = canonicalUrl(window.location.href, true);
8154
8161
  let currentHistoryEntryId = history.state?.gyosEntryId || null;
8155
8162
  let activeNavigation = null;
8163
+ let waitingNavigations = 0;
8156
8164
  // Global progress bar instance
8157
8165
  let progressBar = null;
8158
8166
  const beforeNavigate = [];
@@ -8198,6 +8206,8 @@ function startRouter(options) {
8198
8206
  document.addEventListener('click', onClick);
8199
8207
  document.addEventListener('submit', onSubmit);
8200
8208
  document.addEventListener('mouseover', onMouseOverCapture, true);
8209
+ document.addEventListener('mousemove', onPreloadMouseMove, true);
8210
+ document.addEventListener('mouseleave', clearPreloadHover);
8201
8211
  window.addEventListener('popstate', onPopState);
8202
8212
  if ('scrollRestoration' in history) {
8203
8213
  history.scrollRestoration = 'manual';
@@ -8469,6 +8479,7 @@ function discardPreload(key) {
8469
8479
  entry?.controller.abort();
8470
8480
  }
8471
8481
  function clearPreloads() {
8482
+ clearPreloadHover();
8472
8483
  for (const key of preloadCache.keys())
8473
8484
  discardPreload(key);
8474
8485
  }
@@ -8543,19 +8554,27 @@ function fallbackFromBoost(opts, url, requestSent) {
8543
8554
  console.error(`[GyosRouter] ${method} navigation could not be boosted; the request will not be replayed.`);
8544
8555
  }
8545
8556
  async function navigateRequest(opts) {
8546
- const finishUnstarted = () => {
8557
+ const finishUnstarted = (signal = opts.signal) => {
8547
8558
  opts.onEnd?.({ from: currentUrl, url: opts.url, method: opts.method,
8548
8559
  trigger: opts.trigger || null, target: null, form: null, popstate: false,
8549
- signal: opts.signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
8560
+ signal, status: null, committed: false, fallback: false, outcome: 'aborted' });
8550
8561
  };
8551
8562
  if (opts.signal?.aborted) {
8552
8563
  finishUnstarted();
8553
8564
  return;
8554
8565
  }
8566
+ if (opts.background && (activeNavigation || waitingNavigations > 0)) {
8567
+ const skipped = new AbortController();
8568
+ skipped.abort();
8569
+ finishUnstarted(skipped.signal);
8570
+ return;
8571
+ }
8555
8572
  while (activeNavigation) {
8556
8573
  const previous = activeNavigation;
8557
8574
  if (previous.committing) {
8558
8575
  log('[GyosRouter] Waiting for previous DOM commit');
8576
+ // End hooks can request a refresh before this waiter resumes.
8577
+ waitingNavigations++;
8559
8578
  try {
8560
8579
  await (opts.signal ? waitForNavigation(previous.done, opts.signal) : previous.done);
8561
8580
  }
@@ -8563,6 +8582,9 @@ async function navigateRequest(opts) {
8563
8582
  finishUnstarted();
8564
8583
  return;
8565
8584
  }
8585
+ finally {
8586
+ waitingNavigations--;
8587
+ }
8566
8588
  continue;
8567
8589
  }
8568
8590
  log('[GyosRouter] Cancelling previous navigation');
@@ -8597,14 +8619,16 @@ async function navigateRequest(opts) {
8597
8619
  ? { form: opts.form, url: opts.url, status: null, outcome: null, committed: false, fallback: false }
8598
8620
  : null;
8599
8621
  const fallback = (url, requestSent) => {
8600
- context.fallback = context.method === 'GET' || (!requestSent && !!opts.form);
8622
+ context.fallback = !opts.background && (context.method === 'GET' || (!requestSent && !!opts.form));
8601
8623
  context.outcome ?? (context.outcome = context.fallback ? 'fallback' : 'invalid-response');
8602
- fallbackFromBoost(opts, url, requestSent);
8624
+ if (!opts.background)
8625
+ fallbackFromBoost(opts, url, requestSent);
8603
8626
  };
8627
+ const navigationProgress = opts.background ? null : progressBar;
8604
8628
  const hasTargetSpinner = opts.trigger?.hasAttribute('g-router-spin');
8605
8629
  const setRand = () => {
8606
- if (isActiveNavigation(transaction) && progressBar?.getCurrentProgress() < 70) {
8607
- progressBar?.setProgress(progressBar?.getCurrentProgress() + Math.random() * 8);
8630
+ if (isActiveNavigation(transaction) && navigationProgress && navigationProgress.getCurrentProgress() < 70) {
8631
+ navigationProgress.setProgress(navigationProgress.getCurrentProgress() + Math.random() * 8);
8608
8632
  }
8609
8633
  };
8610
8634
  try {
@@ -8613,7 +8637,7 @@ async function navigateRequest(opts) {
8613
8637
  document.dispatchEvent(new CustomEvent('gyos:form-start', { detail: { ...formEvent } }));
8614
8638
  runNavigationHooks(beforeNavigate, opts.url, context);
8615
8639
  assertActiveNavigation(transaction);
8616
- progressBar?.start();
8640
+ navigationProgress?.start();
8617
8641
  // popstate already points history at the destination entry. Keep the visible
8618
8642
  // page's position under currentUrl without overwriting that destination state.
8619
8643
  rememberScrollPosition(opts.scrollSourceEntryId ?? currentHistoryEntryId);
@@ -8682,6 +8706,8 @@ async function navigateRequest(opts) {
8682
8706
  signal.addEventListener('abort', discard, { once: true });
8683
8707
  try {
8684
8708
  response = await waitForNavigation(entry.request, signal);
8709
+ if (response.ok && preloadHover?.url === preloadKey)
8710
+ preloadHover.used = true;
8685
8711
  }
8686
8712
  catch (error) {
8687
8713
  if (error.name === 'AbortError')
@@ -8700,15 +8726,16 @@ async function navigateRequest(opts) {
8700
8726
  else {
8701
8727
  try {
8702
8728
  // Update progress to rand 20 - 30%
8703
- progressBar?.setProgress(Math.random() * 10 + 20);
8704
- transaction.interval = setInterval(setRand, 300);
8729
+ navigationProgress?.setProgress(Math.random() * 10 + 20);
8730
+ if (navigationProgress)
8731
+ transaction.interval = setInterval(setRand, 300);
8705
8732
  response = await fetch(finalUrl, init);
8706
8733
  assertActiveNavigation(transaction);
8707
8734
  // A successful write can change HTML at any URL, including after a redirect.
8708
8735
  if (response.ok && init.method !== 'GET')
8709
8736
  clearPreloads();
8710
8737
  // Update progress to rand 70 - 80% after fetch
8711
- progressBar?.setProgress(Math.random() * 10 + 70);
8738
+ navigationProgress?.setProgress(Math.random() * 10 + 70);
8712
8739
  if (transaction.interval)
8713
8740
  clearInterval(transaction.interval);
8714
8741
  transaction.interval = null;
@@ -8746,6 +8773,13 @@ async function navigateRequest(opts) {
8746
8773
  const doc = html
8747
8774
  ? parseNavigationDocument(html)
8748
8775
  : document.implementation.createHTMLDocument();
8776
+ const matchedSource = opts.strictSource && opts.targetSelector
8777
+ ? doc.querySelector(opts.targetSelector)
8778
+ : null;
8779
+ if (opts.strictSource && !(matchedSource instanceof HTMLElement) && isFullDocument(html || '')) {
8780
+ context.outcome = 'invalid-response';
8781
+ return; // A complete response must identify the requested region before any swap or snapshot.
8782
+ }
8749
8783
  // Detached parsing cannot tell whether the live CSP permits an incoming base.
8750
8784
  // Let native navigation enforce base-uri instead of authorizing its URLs ourselves.
8751
8785
  if (doc.querySelector('base[href]') || opts.historyFragment?.querySelector('base[href]')) {
@@ -8760,7 +8794,9 @@ async function navigateRequest(opts) {
8760
8794
  && !opts.historyFragment && (opts.popstate && snapshots.has(urlWithoutHash)
8761
8795
  ? snapshots.get(urlWithoutHash).fullDocument : isFullDocument(html || ''));
8762
8796
  // Pick source fragment
8763
- const src = opts.historyFragment || pickSourceFragment(doc, target, targetOutletIndex);
8797
+ const src = opts.historyFragment || (matchedSource instanceof HTMLElement
8798
+ ? matchedSource
8799
+ : pickSourceFragment(doc, target, targetOutletIndex));
8764
8800
  stripInertFallbackContent(src);
8765
8801
  assertActiveNavigation(transaction);
8766
8802
  // Final URL is response.url because in headers there could be redirects
@@ -8783,7 +8819,7 @@ async function navigateRequest(opts) {
8783
8819
  runNavigationHooks(beforeSwap, targetUrl, context);
8784
8820
  assertActiveNavigation(transaction);
8785
8821
  // Update progress to rand 80 - 90% before swap
8786
- progressBar?.setProgress(Math.random() * 10 + 80);
8822
+ navigationProgress?.setProgress(Math.random() * 10 + 80);
8787
8823
  const outgoingHistoryFragment = changesState && !opts.replace && !isFullOutletNavigation
8788
8824
  ? cloneHistoryTarget(target)
8789
8825
  : null;
@@ -8881,7 +8917,7 @@ async function navigateRequest(opts) {
8881
8917
  target = committedTarget;
8882
8918
  context.target = committedTarget;
8883
8919
  context.committed = true;
8884
- progressBar?.reconnect();
8920
+ navigationProgress?.reconnect();
8885
8921
  committedRoots = roots;
8886
8922
  }
8887
8923
  });
@@ -8913,7 +8949,7 @@ async function navigateRequest(opts) {
8913
8949
  }
8914
8950
  };
8915
8951
  // Apply view transition if available
8916
- if (document.startViewTransition) {
8952
+ if (!opts.background && document.startViewTransition) {
8917
8953
  const transition = document.startViewTransition(() => performUpdate());
8918
8954
  consumeViewTransitionRejection(transition?.ready);
8919
8955
  consumeViewTransitionRejection(transition?.finished);
@@ -8964,7 +9000,7 @@ async function navigateRequest(opts) {
8964
9000
  hideTargetSpinner(transaction.spinner);
8965
9001
  if (activeNavigation?.id === transaction.id) {
8966
9002
  activeNavigation = null;
8967
- progressBar?.complete();
9003
+ navigationProgress?.complete();
8968
9004
  }
8969
9005
  opts.signal?.removeEventListener('abort', abort);
8970
9006
  transaction.resolveDone();
@@ -9076,15 +9112,34 @@ function onClick(event) {
9076
9112
  navigateRequest({ url: url.toString(), method: 'GET', trigger: link, changeState: true });
9077
9113
  }
9078
9114
  function onMouseOverCapture(event) {
9079
- const target = event.target;
9080
- if (!target)
9081
- return;
9082
- const link = target.closest('a[g-preload]');
9115
+ const link = event.target instanceof Element ? event.target.closest('a[g-preload]') : null;
9083
9116
  if (!link)
9084
9117
  return;
9085
9118
  const url = eligibleAnchorUrl(link);
9086
- if (url)
9087
- preload(url.href);
9119
+ if (!url)
9120
+ return;
9121
+ const hover = preloadHover;
9122
+ if (hover?.used && hover.url === url.href && ((event.clientX === hover.x && event.clientY === hover.y) ||
9123
+ (event.relatedTarget instanceof Node && link.contains(event.relatedTarget))))
9124
+ return;
9125
+ preloadHover = { url: url.href, x: event.clientX, y: event.clientY, used: false };
9126
+ preload(url.href);
9127
+ }
9128
+ function onPreloadMouseMove(event) {
9129
+ const hover = preloadHover;
9130
+ // The browser can retarget mouse events after a swap with the pointer still in place.
9131
+ if (!hover || (event.clientX === hover.x && event.clientY === hover.y))
9132
+ return;
9133
+ const link = event.target instanceof Element ? event.target.closest('a[g-preload]') : null;
9134
+ if (!(link instanceof HTMLAnchorElement) || link.href !== hover.url) {
9135
+ clearPreloadHover();
9136
+ return;
9137
+ }
9138
+ hover.x = event.clientX;
9139
+ hover.y = event.clientY;
9140
+ }
9141
+ function clearPreloadHover() {
9142
+ preloadHover = undefined;
9088
9143
  }
9089
9144
  function onSubmit(event) {
9090
9145
  if (event.defaultPrevented)
@@ -9237,7 +9292,7 @@ const Gyos = {
9237
9292
  portalCreate,
9238
9293
  portalDestroy,
9239
9294
  setCspNonce,
9240
- version: '0.5.7'
9295
+ version: '0.6.0'
9241
9296
  };
9242
9297
 
9243
9298
  const standardExpressionRuntime = {