gyosjs 0.2.4 → 0.3.1

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.
Files changed (58) hide show
  1. package/README.md +10 -6
  2. package/dist/auto-init.d.ts +1 -1
  3. package/dist/auto-init.d.ts.map +1 -1
  4. package/dist/core/component.d.ts.map +1 -1
  5. package/dist/core/router/csp-html.d.ts +2 -0
  6. package/dist/core/router/csp-html.d.ts.map +1 -0
  7. package/dist/core/router/diff-nodes.d.ts.map +1 -1
  8. package/dist/core/router/router.d.ts.map +1 -1
  9. package/dist/core/router/script.d.ts.map +1 -1
  10. package/dist/core/transition.d.ts.map +1 -1
  11. package/dist/csp-auto-init.d.ts +3 -0
  12. package/dist/csp-auto-init.d.ts.map +1 -0
  13. package/dist/csp.d.ts +3 -0
  14. package/dist/csp.d.ts.map +1 -0
  15. package/dist/gyos.auto.esm.js +337 -75
  16. package/dist/gyos.auto.esm.js.map +1 -1
  17. package/dist/gyos.auto.js +337 -75
  18. package/dist/gyos.auto.js.map +1 -1
  19. package/dist/gyos.auto.min.js +2 -2
  20. package/dist/gyos.csp.auto.esm.js +15208 -0
  21. package/dist/gyos.csp.auto.esm.js.map +1 -0
  22. package/dist/gyos.csp.auto.js +15218 -0
  23. package/dist/gyos.csp.auto.js.map +1 -0
  24. package/dist/gyos.csp.auto.min.js +6 -0
  25. package/dist/gyos.csp.esm.js +15181 -0
  26. package/dist/gyos.csp.esm.js.map +1 -0
  27. package/dist/gyos.csp.js +15252 -0
  28. package/dist/gyos.csp.js.map +1 -0
  29. package/dist/gyos.csp.min.js +6 -0
  30. package/dist/gyos.css +73 -0
  31. package/dist/gyos.esm.js +339 -76
  32. package/dist/gyos.esm.js.map +1 -1
  33. package/dist/gyos.js +339 -75
  34. package/dist/gyos.js.map +1 -1
  35. package/dist/gyos.min.js +2 -2
  36. package/dist/index.d.ts +2 -85
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/public-api.d.ts +89 -0
  39. package/dist/public-api.d.ts.map +1 -0
  40. package/dist/runtime/csp-evaluator.d.ts +7 -0
  41. package/dist/runtime/csp-evaluator.d.ts.map +1 -0
  42. package/dist/runtime/csp-nonce.d.ts +7 -0
  43. package/dist/runtime/csp-nonce.d.ts.map +1 -0
  44. package/dist/runtime/evaluator.d.ts +12 -0
  45. package/dist/runtime/evaluator.d.ts.map +1 -0
  46. package/dist/runtime/install-csp.d.ts +2 -0
  47. package/dist/runtime/install-csp.d.ts.map +1 -0
  48. package/dist/runtime/install-standard.d.ts +2 -0
  49. package/dist/runtime/install-standard.d.ts.map +1 -0
  50. package/dist/runtime/standard-evaluator.d.ts +3 -0
  51. package/dist/runtime/standard-evaluator.d.ts.map +1 -0
  52. package/dist/template/events.d.ts.map +1 -1
  53. package/dist/template/expression.d.ts.map +1 -1
  54. package/dist/template/structurals/transition-helpers.d.ts +1 -1
  55. package/dist/template/structurals/transition-helpers.d.ts.map +1 -1
  56. package/dist/utils/target-spinner.d.ts +0 -4
  57. package/dist/utils/target-spinner.d.ts.map +1 -1
  58. package/package.json +29 -12
package/dist/gyos.auto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GyosJS v0.2.4
2
+ * GyosJS v0.3.1
3
3
  * (c) 2026
4
4
  * @license MIT
5
5
  */
@@ -1242,6 +1242,20 @@
1242
1242
  return value;
1243
1243
  });
1244
1244
 
1245
+ let activeRuntime;
1246
+ function setExpressionRuntime(runtime) {
1247
+ activeRuntime = runtime;
1248
+ }
1249
+ function expressionRuntime() {
1250
+ if (!activeRuntime) {
1251
+ throw new Error('[GyosJS] Expression runtime is not configured. Import GyosJS from a public entry point.');
1252
+ }
1253
+ return activeRuntime;
1254
+ }
1255
+ function expressionRuntimeMode() {
1256
+ return activeRuntime?.mode ?? 'standard';
1257
+ }
1258
+
1245
1259
  /**
1246
1260
  * Expression Evaluation & Interpolation
1247
1261
  * Handles template expressions, pipes, and string interpolation
@@ -1343,24 +1357,7 @@
1343
1357
  if (!isNaN(Number(expr))) {
1344
1358
  return Number(expr);
1345
1359
  }
1346
- // Use Function to evaluate in scope context
1347
- // This allows getters and signals to be tracked properly
1348
- try {
1349
- const method = scope[expr];
1350
- if (typeof method === "function") {
1351
- return method.call(scope);
1352
- }
1353
- else {
1354
- // Wrap expression in try-catch to handle null/undefined access gracefully
1355
- const safeExpr = `try { return ${expr} } catch(e) { return undefined }`;
1356
- const fn = new Function("$scope", `with($scope) { ${safeExpr} }`);
1357
- return fn(scope);
1358
- }
1359
- }
1360
- catch (e) {
1361
- console.error("[GyosJS] Error evaluating expression:", expr, e);
1362
- return undefined;
1363
- }
1360
+ return expressionRuntime().evaluate(expr, scope);
1364
1361
  }
1365
1362
 
1366
1363
  /**
@@ -2198,6 +2195,8 @@
2198
2195
  function applyTransitionStyles() {
2199
2196
  if (typeof document === 'undefined')
2200
2197
  return;
2198
+ if (expressionRuntimeMode() === 'csp')
2199
+ return;
2201
2200
  const styleId = 'gyos-transitions';
2202
2201
  if (document.getElementById(styleId))
2203
2202
  return;
@@ -2269,32 +2268,24 @@
2269
2268
  * Handles:
2270
2269
  * 1. Literal string: "fade" or "slide-down"
2271
2270
  * 2. Expression with {}: "{transition}"
2272
- * 3. Expression without {}: "transition" (evaluate as variable)
2271
+ * 3. Quoted literal kept for backwards compatibility: "'fade'"
2273
2272
  *
2274
2273
  * @param attrValue - The g-transition attribute value
2275
2274
  * @param scope - Current scope for expression evaluation
2276
2275
  * @returns The transition name (string)
2277
2276
  */
2278
2277
  function parseTransitionName(attrValue, scope) {
2279
- if (attrValue.includes('{') && attrValue.includes('}')) {
2280
- // Extract expression from {} and evaluate it
2281
- const match = attrValue.match(/\{([^}]+)\}/);
2282
- if (match) {
2283
- return evaluateExpression(match[1].trim(), scope);
2284
- }
2278
+ const value = attrValue.trim();
2279
+ const expression = /^\{([\s\S]+)\}$/.exec(value);
2280
+ if (expression) {
2281
+ const evaluated = evaluateExpression(expression[1].trim(), scope);
2282
+ return evaluated == null ? '' : String(evaluated);
2285
2283
  }
2286
- // Try to evaluate as expression first (variable name)
2287
- // If it fails or returns undefined, use as literal string
2288
- try {
2289
- const evaluated = evaluateExpression(attrValue, scope);
2290
- if (evaluated !== undefined && evaluated !== null) {
2291
- return evaluated;
2292
- }
2293
- }
2294
- catch (e) {
2295
- // If evaluation fails, use value as literal string (built-in transition name)
2284
+ if (value.length >= 2 && ((value.startsWith("'") && value.endsWith("'"))
2285
+ || (value.startsWith('"') && value.endsWith('"')))) {
2286
+ return value.slice(1, -1);
2296
2287
  }
2297
- return attrValue;
2288
+ return value;
2298
2289
  }
2299
2290
  /**
2300
2291
  * Parse transition config from element's g-transition attribute
@@ -3685,24 +3676,7 @@
3685
3676
  if (modifiers.includes('stop'))
3686
3677
  e.stopPropagation();
3687
3678
  try {
3688
- const isMethodCall = handler.includes('(');
3689
- if (isMethodCall) {
3690
- // Method call with args: "doSomething()" or "method(arg1, arg2)"
3691
- const fn = new Function('$event', `with(this) { ${handler} }`);
3692
- fn.call(scope, e);
3693
- }
3694
- else {
3695
- // Check if it's a method name or expression
3696
- const method = scope[handler];
3697
- if (typeof method === 'function') {
3698
- method.call(scope, e);
3699
- }
3700
- else {
3701
- // Expression like "count++", "count = 0"
3702
- const fn = new Function('$event', `with(this) { ${handler} }`);
3703
- fn.call(scope, e);
3704
- }
3705
- }
3679
+ expressionRuntime().execute(handler, scope, e);
3706
3680
  }
3707
3681
  catch (err) {
3708
3682
  console.error('[GyosJS] Error in event handler:', err);
@@ -5678,10 +5652,7 @@
5678
5652
  if (!trimmed.startsWith('{')) {
5679
5653
  return undefined; // Not an inline definition
5680
5654
  }
5681
- // Parse as JavaScript object using Function constructor
5682
- // This allows methods and complex expressions
5683
- const fn = new Function(`return (${trimmed})`);
5684
- const definition = fn();
5655
+ const definition = expressionRuntime().parseScope(trimmed);
5685
5656
  DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
5686
5657
  return definition;
5687
5658
  }
@@ -5745,10 +5716,10 @@
5745
5716
  if (forbidden.some(f => expr.includes(f))) {
5746
5717
  DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
5747
5718
  }
5748
- const args = key.split(':').slice(1).join(', ');
5719
+ const args = key.split(':').slice(1);
5749
5720
  const propName = key.split(':')[0];
5750
5721
  try {
5751
- definition[propName] = new Function(args, `with(this) { ${expr} }`);
5722
+ definition[propName] = expressionRuntime().createMethod(args, expr);
5752
5723
  removeAttrs.push(attr.name);
5753
5724
  }
5754
5725
  catch (_) {
@@ -6728,7 +6699,7 @@
6728
6699
  </div>
6729
6700
  `;
6730
6701
  // Inject styles if not already present
6731
- if (!document.getElementById('gyos-target-spinner-styles')) {
6702
+ if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
6732
6703
  const style = document.createElement('style');
6733
6704
  style.id = 'gyos-target-spinner-styles';
6734
6705
  style.textContent = `
@@ -6782,6 +6753,16 @@
6782
6753
  }
6783
6754
  }
6784
6755
 
6756
+ let nonceSource;
6757
+ /** Configure the active document nonce used for scripts and styles during MPA navigation. */
6758
+ function setCspNonce(source) {
6759
+ nonceSource = source;
6760
+ }
6761
+ function resolveCspNonce() {
6762
+ const value = typeof nonceSource === 'function' ? nonceSource() : nonceSource;
6763
+ return value || undefined;
6764
+ }
6765
+
6785
6766
  // Cache executed scripts to prevent duplicate execution
6786
6767
  const executedScripts = new Set();
6787
6768
  /**
@@ -6882,6 +6863,12 @@
6882
6863
  old.remove();
6883
6864
  return;
6884
6865
  }
6866
+ const activeNonce = resolveCspNonce();
6867
+ if (expressionRuntimeMode() === 'csp' && !old.src && !activeNonce) {
6868
+ console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
6869
+ old.textContent = '';
6870
+ return;
6871
+ }
6885
6872
  const executionKey = getScriptExecutionKey(old);
6886
6873
  // Check if script should execute
6887
6874
  if (!shouldExecuteScript(old)) {
@@ -6891,6 +6878,10 @@
6891
6878
  }
6892
6879
  const newScript = document.createElement('script');
6893
6880
  Array.from(old.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
6881
+ if (expressionRuntimeMode() === 'csp')
6882
+ newScript.removeAttribute('nonce');
6883
+ if (activeNonce)
6884
+ newScript.setAttribute('nonce', activeNonce);
6894
6885
  newScript.textContent = old.hasAttribute('g-script-wrap')
6895
6886
  ? wrapScriptExecution(old.textContent)
6896
6887
  : old.textContent;
@@ -7335,9 +7326,33 @@
7335
7326
  window.scrollTo({ top: 0, behavior: 'smooth' });
7336
7327
  }
7337
7328
 
7338
- function serializeAttributes(el) {
7339
- return Array.from(el.attributes)
7340
- .map(attr => `${attr.name}=${attr.value}`)
7329
+ function isNonceMeta(el) {
7330
+ return el.tagName === 'META' && el.getAttribute('name')?.toLowerCase() === 'csp-nonce';
7331
+ }
7332
+ function isStylesheetLink(el) {
7333
+ return el.tagName === 'LINK'
7334
+ && (el.getAttribute('rel') || '').toLowerCase().split(/\s+/).includes('stylesheet');
7335
+ }
7336
+ function usesCspNonce(el) {
7337
+ return el.tagName === 'SCRIPT' || el.tagName === 'STYLE' || isStylesheetLink(el);
7338
+ }
7339
+ function serializeAttributes(el, context) {
7340
+ const attributes = new Map();
7341
+ Array.from(el.attributes).forEach(attr => {
7342
+ if (context.csp && usesCspNonce(el) && attr.name.toLowerCase() === 'nonce')
7343
+ return;
7344
+ if (context.csp && isNonceMeta(el) && attr.name.toLowerCase() === 'content')
7345
+ return;
7346
+ attributes.set(attr.name, attr.value);
7347
+ });
7348
+ if (context.csp && usesCspNonce(el) && context.activeNonce) {
7349
+ attributes.set('nonce', context.activeNonce);
7350
+ }
7351
+ if (context.csp && isNonceMeta(el) && context.activeNonce) {
7352
+ attributes.set('content', context.activeNonce);
7353
+ }
7354
+ return Array.from(attributes)
7355
+ .map(([name, value]) => `${name}=${value}`)
7341
7356
  .sort()
7342
7357
  .join('|');
7343
7358
  }
@@ -7348,23 +7363,61 @@
7348
7363
  }
7349
7364
  return String(hash);
7350
7365
  }
7351
- function elementKey(el) {
7366
+ function elementKey(el, context) {
7352
7367
  const tag = el.tagName.toLowerCase();
7353
7368
  const content = tag === 'script' || tag === 'style' ? hashContent(el.textContent || '') : '';
7354
- return `${tag}|${serializeAttributes(el)}|${content}`;
7369
+ return `${tag}|${serializeAttributes(el, context)}|${content}`;
7355
7370
  }
7356
- function keyedNodes(nodes) {
7371
+ function keyedNodes(nodes, context) {
7357
7372
  const occurrences = new Map();
7358
7373
  return nodes.map(node => {
7359
- const baseKey = elementKey(node);
7374
+ const baseKey = elementKey(node, context);
7360
7375
  const occurrence = occurrences.get(baseKey) || 0;
7361
7376
  occurrences.set(baseKey, occurrence + 1);
7362
7377
  return { key: `${baseKey}|${occurrence}`, node };
7363
7378
  });
7364
7379
  }
7380
+ function canInsertNode(node, context) {
7381
+ if (!context.csp)
7382
+ return true;
7383
+ if (isNonceMeta(node))
7384
+ return Boolean(context.activeNonce);
7385
+ if (node.tagName === 'STYLE')
7386
+ return Boolean(context.activeNonce);
7387
+ if (node.tagName === 'SCRIPT' && !node.hasAttribute('src'))
7388
+ return Boolean(context.activeNonce);
7389
+ return true;
7390
+ }
7391
+ function reconcileCspAttributes(node, context) {
7392
+ if (!context.csp)
7393
+ return;
7394
+ if (isNonceMeta(node)) {
7395
+ if (context.activeNonce)
7396
+ node.setAttribute('content', context.activeNonce);
7397
+ return;
7398
+ }
7399
+ if (!usesCspNonce(node))
7400
+ return;
7401
+ node.removeAttribute('nonce');
7402
+ if (context.activeNonce)
7403
+ node.setAttribute('nonce', context.activeNonce);
7404
+ }
7405
+ function warnSkippedNode(node) {
7406
+ if (node.tagName === 'STYLE') {
7407
+ console.warn('[GyosJS CSP] Skipped an inline MPA style because no active document nonce is configured.');
7408
+ }
7409
+ else if (node.tagName === 'SCRIPT' && !node.hasAttribute('src')) {
7410
+ console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
7411
+ }
7412
+ }
7365
7413
  async function diffNodes(currentNodes, nextNodes, container = document.head, signal) {
7366
- const current = keyedNodes(currentNodes);
7367
- const next = keyedNodes(nextNodes);
7414
+ const csp = expressionRuntimeMode() === 'csp';
7415
+ const context = {
7416
+ csp,
7417
+ activeNonce: csp ? resolveCspNonce() : undefined
7418
+ };
7419
+ const current = keyedNodes(currentNodes, context);
7420
+ const next = keyedNodes(nextNodes, context);
7368
7421
  const currentKeys = new Set(current.map(item => item.key));
7369
7422
  const nextKeys = new Set(next.map(item => item.key));
7370
7423
  // Remove nodes that are not in the new head
@@ -7378,6 +7431,20 @@
7378
7431
  if (signal?.aborted)
7379
7432
  return;
7380
7433
  if (!currentKeys.has(key)) {
7434
+ if (!canInsertNode(node, context)) {
7435
+ warnSkippedNode(node);
7436
+ continue;
7437
+ }
7438
+ if (node.tagName === 'STYLE') {
7439
+ const style = document.createElement('style');
7440
+ Array.from(node.attributes).forEach(attr => style.setAttribute(attr.name, attr.value));
7441
+ reconcileCspAttributes(style, context);
7442
+ // CSP checks inline styles as their CSS text is attached. Set the active
7443
+ // nonce first so a response nonce never produces a transient violation.
7444
+ style.textContent = node.textContent || '';
7445
+ container.appendChild(style);
7446
+ continue;
7447
+ }
7381
7448
  if (node.tagName === 'SCRIPT') {
7382
7449
  const originalScript = node;
7383
7450
  const executionKey = getScriptExecutionKey(originalScript);
@@ -7388,6 +7455,7 @@
7388
7455
  }
7389
7456
  const script = document.createElement('script');
7390
7457
  Array.from(node.attributes).forEach(attr => script.setAttribute(attr.name, attr.value));
7458
+ reconcileCspAttributes(script, context);
7391
7459
  script.textContent = node.hasAttribute('g-script-wrap')
7392
7460
  ? wrapScriptExecution(node.textContent || '')
7393
7461
  : node.textContent || '';
@@ -7397,11 +7465,168 @@
7397
7465
  await completion;
7398
7466
  continue;
7399
7467
  }
7400
- container.appendChild(document.importNode(node, true));
7468
+ const imported = document.importNode(node, true);
7469
+ reconcileCspAttributes(imported, context);
7470
+ container.appendChild(imported);
7401
7471
  }
7402
7472
  }
7403
7473
  }
7404
7474
 
7475
+ const RAW_TEXT_ELEMENTS = new Set(['iframe', 'noembed', 'noframes', 'plaintext', 'script', 'textarea', 'title', 'xmp']);
7476
+ function escapeAttribute(value) {
7477
+ return value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
7478
+ }
7479
+ function findTagEnd(html, start) {
7480
+ let quote = '';
7481
+ for (let index = start; index < html.length; index += 1) {
7482
+ const character = html[index];
7483
+ if (quote) {
7484
+ if (character === quote)
7485
+ quote = '';
7486
+ continue;
7487
+ }
7488
+ if (character === '"' || character === "'") {
7489
+ quote = character;
7490
+ continue;
7491
+ }
7492
+ if (character === '>')
7493
+ return index + 1;
7494
+ }
7495
+ return html.length;
7496
+ }
7497
+ function findClosingTag(html, lowerHtml, name, start) {
7498
+ const needle = `</${name}`;
7499
+ let position = lowerHtml.indexOf(needle, start);
7500
+ while (position !== -1) {
7501
+ const boundary = lowerHtml[position + needle.length];
7502
+ if (boundary === '>' || /\s/.test(boundary || '')) {
7503
+ return {
7504
+ start: position,
7505
+ end: findTagEnd(html, position + needle.length)
7506
+ };
7507
+ }
7508
+ position = lowerHtml.indexOf(needle, position + needle.length);
7509
+ }
7510
+ return null;
7511
+ }
7512
+ function removeNonceAttribute(openingTag) {
7513
+ const prefix = /^<\s*style\b/i.exec(openingTag);
7514
+ if (!prefix)
7515
+ return openingTag;
7516
+ let output = prefix[0];
7517
+ let cursor = prefix[0].length;
7518
+ const limit = openingTag.length - 1;
7519
+ while (cursor < limit) {
7520
+ const attributeStart = cursor;
7521
+ while (cursor < limit && /\s/.test(openingTag[cursor]))
7522
+ cursor += 1;
7523
+ if (cursor >= limit || openingTag[cursor] === '>') {
7524
+ output += openingTag.slice(attributeStart, cursor);
7525
+ break;
7526
+ }
7527
+ const nameStart = cursor;
7528
+ while (cursor < limit && !/[\s=/>]/.test(openingTag[cursor]))
7529
+ cursor += 1;
7530
+ if (cursor === nameStart) {
7531
+ output += openingTag.slice(attributeStart, cursor + 1);
7532
+ cursor += 1;
7533
+ continue;
7534
+ }
7535
+ const name = openingTag.slice(nameStart, cursor).toLowerCase();
7536
+ while (cursor < limit && /\s/.test(openingTag[cursor]))
7537
+ cursor += 1;
7538
+ if (openingTag[cursor] === '=') {
7539
+ cursor += 1;
7540
+ while (cursor < limit && /\s/.test(openingTag[cursor]))
7541
+ cursor += 1;
7542
+ const quote = openingTag[cursor] === '"' || openingTag[cursor] === "'" ? openingTag[cursor] : '';
7543
+ if (quote) {
7544
+ cursor += 1;
7545
+ while (cursor < limit && openingTag[cursor] !== quote)
7546
+ cursor += 1;
7547
+ if (openingTag[cursor] === quote)
7548
+ cursor += 1;
7549
+ }
7550
+ else {
7551
+ while (cursor < limit && !/[\s>]/.test(openingTag[cursor]))
7552
+ cursor += 1;
7553
+ }
7554
+ }
7555
+ if (name !== 'nonce')
7556
+ output += openingTag.slice(attributeStart, cursor);
7557
+ }
7558
+ return output + openingTag.slice(limit);
7559
+ }
7560
+ function withNonce(openingTag, nonce) {
7561
+ const withoutNonce = removeNonceAttribute(openingTag);
7562
+ return `${withoutNonce.slice(0, -1)} nonce="${escapeAttribute(nonce)}">`;
7563
+ }
7564
+ function prepareNavigationHtml(html) {
7565
+ if (expressionRuntimeMode() !== 'csp')
7566
+ return html;
7567
+ const activeNonce = resolveCspNonce();
7568
+ const lowerHtml = html.toLowerCase();
7569
+ let output = '';
7570
+ let cursor = 0;
7571
+ let skippedStyles = 0;
7572
+ while (cursor < html.length) {
7573
+ const tagStart = html.indexOf('<', cursor);
7574
+ if (tagStart === -1) {
7575
+ output += html.slice(cursor);
7576
+ break;
7577
+ }
7578
+ output += html.slice(cursor, tagStart);
7579
+ if (html.startsWith('<!--', tagStart)) {
7580
+ const commentEnd = html.indexOf('-->', tagStart + 4);
7581
+ const end = commentEnd === -1 ? html.length : commentEnd + 3;
7582
+ output += html.slice(tagStart, end);
7583
+ cursor = end;
7584
+ continue;
7585
+ }
7586
+ const tagEnd = findTagEnd(html, tagStart + 1);
7587
+ const openingTag = html.slice(tagStart, tagEnd);
7588
+ const match = /^<\s*(\/?)\s*([a-z][\w:-]*)/i.exec(openingTag);
7589
+ if (!match || match[1]) {
7590
+ output += openingTag;
7591
+ cursor = tagEnd;
7592
+ continue;
7593
+ }
7594
+ const name = match[2].toLowerCase();
7595
+ if (name === 'plaintext') {
7596
+ output += html.slice(tagStart);
7597
+ break;
7598
+ }
7599
+ if (name === 'style' || name === 'noscript' || RAW_TEXT_ELEMENTS.has(name)) {
7600
+ const closingTag = findClosingTag(html, lowerHtml, name, tagEnd);
7601
+ const blockEnd = closingTag?.end ?? html.length;
7602
+ if (name === 'noscript') {
7603
+ cursor = blockEnd;
7604
+ continue;
7605
+ }
7606
+ if (name === 'style') {
7607
+ if (!activeNonce) {
7608
+ skippedStyles += 1;
7609
+ cursor = blockEnd;
7610
+ continue;
7611
+ }
7612
+ output += withNonce(openingTag, activeNonce);
7613
+ output += html.slice(tagEnd, blockEnd);
7614
+ cursor = blockEnd;
7615
+ continue;
7616
+ }
7617
+ output += html.slice(tagStart, blockEnd);
7618
+ cursor = blockEnd;
7619
+ continue;
7620
+ }
7621
+ output += openingTag;
7622
+ cursor = tagEnd;
7623
+ }
7624
+ if (skippedStyles > 0) {
7625
+ console.warn(`[GyosJS CSP] Skipped ${skippedStyles} inline MPA style${skippedStyles === 1 ? '' : 's'} because no active document nonce is configured.`);
7626
+ }
7627
+ return output;
7628
+ }
7629
+
7405
7630
  /**
7406
7631
  * GyosJs Router v0
7407
7632
  * MPA boost navigation inspired by Turbo Drive.
@@ -7465,7 +7690,10 @@
7465
7690
  root.querySelectorAll('noscript').forEach(element => element.remove());
7466
7691
  }
7467
7692
  function parseNavigationDocument(html) {
7468
- const doc = new DOMParser().parseFromString(html, 'text/html');
7693
+ // Chromium applies the active page CSP while DOMParser creates response
7694
+ // styles. Reconcile their nonce before parsing to avoid transient violations;
7695
+ // diffNodes repeats the check before insertion into the live document.
7696
+ const doc = new DOMParser().parseFromString(prepareNavigationHtml(html), 'text/html');
7469
7697
  // DOMParser disables scripting and parses noscript children as active markup.
7470
7698
  // A boosted page runs with scripting enabled, so those fallbacks must stay inert.
7471
7699
  stripInertFallbackContent(doc);
@@ -8237,7 +8465,7 @@
8237
8465
  });
8238
8466
  }
8239
8467
 
8240
- // Default export
8468
+ // Shared public surface used by the standard and CSP entries.
8241
8469
  // Default export remains for convenience (no side effects here)
8242
8470
  const Gyos = {
8243
8471
  scope,
@@ -8300,10 +8528,44 @@
8300
8528
  onAfterNavigate,
8301
8529
  portalCreate,
8302
8530
  portalDestroy,
8303
- version: '0.2.4'
8531
+ setCspNonce,
8532
+ version: '0.3.1'
8533
+ };
8534
+
8535
+ const standardExpressionRuntime = {
8536
+ mode: 'standard',
8537
+ evaluate(expression, scope) {
8538
+ const method = scope?.[expression];
8539
+ if (typeof method === 'function')
8540
+ return method.call(scope);
8541
+ try {
8542
+ const safeExpression = `try { return ${expression} } catch(e) { return undefined }`;
8543
+ const evaluate = new Function('$scope', `with($scope) { ${safeExpression} }`);
8544
+ return evaluate(scope);
8545
+ }
8546
+ catch (error) {
8547
+ console.error('[GyosJS] Error evaluating expression:', expression, error);
8548
+ return undefined;
8549
+ }
8550
+ },
8551
+ execute(expression, scope, event) {
8552
+ const method = scope?.[expression];
8553
+ if (typeof method === 'function')
8554
+ return method.call(scope, event);
8555
+ const execute = new Function('$event', `with(this) { ${expression} }`);
8556
+ return execute.call(scope, event);
8557
+ },
8558
+ parseScope(expression) {
8559
+ const parse = new Function(`return (${expression})`);
8560
+ return parse();
8561
+ },
8562
+ createMethod(parameters, body) {
8563
+ return new Function(parameters.join(', '), `with(this) { ${body} }`);
8564
+ }
8304
8565
  };
8305
8566
 
8306
8567
  var _a, _b, _c;
8568
+ setExpressionRuntime(standardExpressionRuntime);
8307
8569
  /**
8308
8570
  * Browser auto-init entry.
8309
8571
  * Attaches Gyos to window, sets debug defaults, injects transitions, starts router,