gyosjs 0.2.3 → 0.3.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.
Files changed (54) hide show
  1. package/README.md +129 -125
  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/router.d.ts.map +1 -1
  6. package/dist/core/router/script.d.ts.map +1 -1
  7. package/dist/core/transition.d.ts.map +1 -1
  8. package/dist/csp-auto-init.d.ts +3 -0
  9. package/dist/csp-auto-init.d.ts.map +1 -0
  10. package/dist/csp.d.ts +3 -0
  11. package/dist/csp.d.ts.map +1 -0
  12. package/dist/form/form-validation.d.ts.map +1 -1
  13. package/dist/gyos.auto.esm.js +89 -55
  14. package/dist/gyos.auto.esm.js.map +1 -1
  15. package/dist/gyos.auto.js +89 -55
  16. package/dist/gyos.auto.js.map +1 -1
  17. package/dist/gyos.auto.min.js +2 -2
  18. package/dist/gyos.csp.auto.esm.js +14979 -0
  19. package/dist/gyos.csp.auto.esm.js.map +1 -0
  20. package/dist/gyos.csp.auto.js +14989 -0
  21. package/dist/gyos.csp.auto.js.map +1 -0
  22. package/dist/gyos.csp.auto.min.js +6 -0
  23. package/dist/gyos.csp.esm.js +14952 -0
  24. package/dist/gyos.csp.esm.js.map +1 -0
  25. package/dist/gyos.csp.js +15023 -0
  26. package/dist/gyos.csp.js.map +1 -0
  27. package/dist/gyos.csp.min.js +6 -0
  28. package/dist/gyos.css +73 -0
  29. package/dist/gyos.esm.js +91 -56
  30. package/dist/gyos.esm.js.map +1 -1
  31. package/dist/gyos.js +91 -55
  32. package/dist/gyos.js.map +1 -1
  33. package/dist/gyos.min.js +2 -2
  34. package/dist/index.d.ts +2 -85
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/public-api.d.ts +89 -0
  37. package/dist/public-api.d.ts.map +1 -0
  38. package/dist/runtime/csp-evaluator.d.ts +7 -0
  39. package/dist/runtime/csp-evaluator.d.ts.map +1 -0
  40. package/dist/runtime/csp-nonce.d.ts +7 -0
  41. package/dist/runtime/csp-nonce.d.ts.map +1 -0
  42. package/dist/runtime/evaluator.d.ts +12 -0
  43. package/dist/runtime/evaluator.d.ts.map +1 -0
  44. package/dist/runtime/install-csp.d.ts +2 -0
  45. package/dist/runtime/install-csp.d.ts.map +1 -0
  46. package/dist/runtime/install-standard.d.ts +2 -0
  47. package/dist/runtime/install-standard.d.ts.map +1 -0
  48. package/dist/runtime/standard-evaluator.d.ts +3 -0
  49. package/dist/runtime/standard-evaluator.d.ts.map +1 -0
  50. package/dist/template/events.d.ts.map +1 -1
  51. package/dist/template/expression.d.ts.map +1 -1
  52. package/dist/utils/target-spinner.d.ts +0 -4
  53. package/dist/utils/target-spinner.d.ts.map +1 -1
  54. package/package.json +72 -55
package/dist/gyos.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GyosJS v0.2.3
2
+ * GyosJS v0.3.0
3
3
  * (c) 2026
4
4
  * @license MIT
5
5
  */
@@ -9,6 +9,52 @@
9
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Gyos = {}));
10
10
  })(this, (function (exports) { 'use strict';
11
11
 
12
+ let activeRuntime;
13
+ function setExpressionRuntime(runtime) {
14
+ activeRuntime = runtime;
15
+ }
16
+ function expressionRuntime() {
17
+ if (!activeRuntime) {
18
+ throw new Error('[GyosJS] Expression runtime is not configured. Import GyosJS from a public entry point.');
19
+ }
20
+ return activeRuntime;
21
+ }
22
+ function expressionRuntimeMode() {
23
+ return activeRuntime?.mode ?? 'standard';
24
+ }
25
+
26
+ const standardExpressionRuntime = {
27
+ mode: 'standard',
28
+ evaluate(expression, scope) {
29
+ const method = scope?.[expression];
30
+ if (typeof method === 'function')
31
+ return method.call(scope);
32
+ try {
33
+ const safeExpression = `try { return ${expression} } catch(e) { return undefined }`;
34
+ const evaluate = new Function('$scope', `with($scope) { ${safeExpression} }`);
35
+ return evaluate(scope);
36
+ }
37
+ catch (error) {
38
+ console.error('[GyosJS] Error evaluating expression:', expression, error);
39
+ return undefined;
40
+ }
41
+ },
42
+ execute(expression, scope, event) {
43
+ const method = scope?.[expression];
44
+ if (typeof method === 'function')
45
+ return method.call(scope, event);
46
+ const execute = new Function('$event', `with(this) { ${expression} }`);
47
+ return execute.call(scope, event);
48
+ },
49
+ parseScope(expression) {
50
+ const parse = new Function(`return (${expression})`);
51
+ return parse();
52
+ },
53
+ createMethod(parameters, body) {
54
+ return new Function(parameters.join(', '), `with(this) { ${body} }`);
55
+ }
56
+ };
57
+
12
58
  /**
13
59
  * Utility helpers
14
60
  */
@@ -1343,24 +1389,7 @@
1343
1389
  if (!isNaN(Number(expr))) {
1344
1390
  return Number(expr);
1345
1391
  }
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
- }
1392
+ return expressionRuntime().evaluate(expr, scope);
1364
1393
  }
1365
1394
 
1366
1395
  /**
@@ -2198,6 +2227,8 @@
2198
2227
  function applyTransitionStyles() {
2199
2228
  if (typeof document === 'undefined')
2200
2229
  return;
2230
+ if (expressionRuntimeMode() === 'csp')
2231
+ return;
2201
2232
  const styleId = 'gyos-transitions';
2202
2233
  if (document.getElementById(styleId))
2203
2234
  return;
@@ -3268,8 +3299,8 @@
3268
3299
 
3269
3300
  const managedForms = new WeakSet();
3270
3301
  const approvedSubmissions = new WeakSet();
3271
- // Coordinates the validation listener on a form with the Router's earlier
3272
- // document-capture listener without exposing state on application elements.
3302
+ // Coordinates the form capture validator with the Router's document listener
3303
+ // without exposing state on application elements.
3273
3304
  function registerValidatedForm(form) {
3274
3305
  managedForms.add(form);
3275
3306
  }
@@ -3419,7 +3450,6 @@
3419
3450
  const submitListener = async (e) => {
3420
3451
  if (replayingSubmission) {
3421
3452
  replayingSubmission = false;
3422
- cancelApprovedFormSubmission(form);
3423
3453
  return;
3424
3454
  }
3425
3455
  e.preventDefault();
@@ -3450,11 +3480,11 @@
3450
3480
  }
3451
3481
  finally {
3452
3482
  // requestSubmit dispatches synchronously. If native validation or
3453
- // another capture listener stopped it, do not leak approval state.
3483
+ // another listener stopped it, do not leak approval state.
3454
3484
  if (replayingSubmission) {
3455
3485
  replayingSubmission = false;
3456
- cancelApprovedFormSubmission(form);
3457
3486
  }
3487
+ cancelApprovedFormSubmission(form);
3458
3488
  }
3459
3489
  }, 0);
3460
3490
  return;
@@ -3686,24 +3716,7 @@
3686
3716
  if (modifiers.includes('stop'))
3687
3717
  e.stopPropagation();
3688
3718
  try {
3689
- const isMethodCall = handler.includes('(');
3690
- if (isMethodCall) {
3691
- // Method call with args: "doSomething()" or "method(arg1, arg2)"
3692
- const fn = new Function('$event', `with(this) { ${handler} }`);
3693
- fn.call(scope, e);
3694
- }
3695
- else {
3696
- // Check if it's a method name or expression
3697
- const method = scope[handler];
3698
- if (typeof method === 'function') {
3699
- method.call(scope, e);
3700
- }
3701
- else {
3702
- // Expression like "count++", "count = 0"
3703
- const fn = new Function('$event', `with(this) { ${handler} }`);
3704
- fn.call(scope, e);
3705
- }
3706
- }
3719
+ expressionRuntime().execute(handler, scope, e);
3707
3720
  }
3708
3721
  catch (err) {
3709
3722
  console.error('[GyosJS] Error in event handler:', err);
@@ -5679,10 +5692,7 @@
5679
5692
  if (!trimmed.startsWith('{')) {
5680
5693
  return undefined; // Not an inline definition
5681
5694
  }
5682
- // Parse as JavaScript object using Function constructor
5683
- // This allows methods and complex expressions
5684
- const fn = new Function(`return (${trimmed})`);
5685
- const definition = fn();
5695
+ const definition = expressionRuntime().parseScope(trimmed);
5686
5696
  DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
5687
5697
  return definition;
5688
5698
  }
@@ -5746,10 +5756,10 @@
5746
5756
  if (forbidden.some(f => expr.includes(f))) {
5747
5757
  DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
5748
5758
  }
5749
- const args = key.split(':').slice(1).join(', ');
5759
+ const args = key.split(':').slice(1);
5750
5760
  const propName = key.split(':')[0];
5751
5761
  try {
5752
- definition[propName] = new Function(args, `with(this) { ${expr} }`);
5762
+ definition[propName] = expressionRuntime().createMethod(args, expr);
5753
5763
  removeAttrs.push(attr.name);
5754
5764
  }
5755
5765
  catch (_) {
@@ -6729,7 +6739,7 @@
6729
6739
  </div>
6730
6740
  `;
6731
6741
  // Inject styles if not already present
6732
- if (!document.getElementById('gyos-target-spinner-styles')) {
6742
+ if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
6733
6743
  const style = document.createElement('style');
6734
6744
  style.id = 'gyos-target-spinner-styles';
6735
6745
  style.textContent = `
@@ -6783,6 +6793,16 @@
6783
6793
  }
6784
6794
  }
6785
6795
 
6796
+ let nonceSource;
6797
+ /** Configure the nonce used when Gyos recreates scripts during MPA navigation. */
6798
+ function setCspNonce(source) {
6799
+ nonceSource = source;
6800
+ }
6801
+ function resolveCspNonce() {
6802
+ const value = typeof nonceSource === 'function' ? nonceSource() : nonceSource;
6803
+ return value || undefined;
6804
+ }
6805
+
6786
6806
  // Cache executed scripts to prevent duplicate execution
6787
6807
  const executedScripts = new Set();
6788
6808
  /**
@@ -6883,6 +6903,12 @@
6883
6903
  old.remove();
6884
6904
  return;
6885
6905
  }
6906
+ const activeNonce = resolveCspNonce();
6907
+ if (expressionRuntimeMode() === 'csp' && !old.src && !activeNonce) {
6908
+ console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
6909
+ old.textContent = '';
6910
+ return;
6911
+ }
6886
6912
  const executionKey = getScriptExecutionKey(old);
6887
6913
  // Check if script should execute
6888
6914
  if (!shouldExecuteScript(old)) {
@@ -6892,6 +6918,10 @@
6892
6918
  }
6893
6919
  const newScript = document.createElement('script');
6894
6920
  Array.from(old.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
6921
+ if (expressionRuntimeMode() === 'csp')
6922
+ newScript.removeAttribute('nonce');
6923
+ if (activeNonce)
6924
+ newScript.setAttribute('nonce', activeNonce);
6895
6925
  newScript.textContent = old.hasAttribute('g-script-wrap')
6896
6926
  ? wrapScriptExecution(old.textContent)
6897
6927
  : old.textContent;
@@ -7444,8 +7474,8 @@
7444
7474
  if (progressBarEnabled) {
7445
7475
  progressBar = new ProgressBar(progressBarEnabled);
7446
7476
  }
7447
- document.addEventListener('click', onClickCapture, true);
7448
- document.addEventListener('submit', onSubmitCapture, true);
7477
+ document.addEventListener('click', onClick);
7478
+ document.addEventListener('submit', onSubmit);
7449
7479
  document.addEventListener('mouseover', onMouseOverCapture, true);
7450
7480
  window.addEventListener('popstate', onPopState);
7451
7481
  if ('scrollRestoration' in history) {
@@ -8116,7 +8146,7 @@
8116
8146
  return; // this case not link (tag a) or form so do nothing
8117
8147
  }
8118
8148
  }
8119
- function onClickCapture(event) {
8149
+ function onClick(event) {
8120
8150
  if (event.defaultPrevented)
8121
8151
  return;
8122
8152
  if (event.button !== 0)
@@ -8173,7 +8203,9 @@
8173
8203
  return;
8174
8204
  preload(url.toString());
8175
8205
  }
8176
- function onSubmitCapture(event) {
8206
+ function onSubmit(event) {
8207
+ if (event.defaultPrevented)
8208
+ return;
8177
8209
  const form = event.target;
8178
8210
  if (!form || form.tagName.toLowerCase() !== 'form')
8179
8211
  return;
@@ -8236,7 +8268,7 @@
8236
8268
  });
8237
8269
  }
8238
8270
 
8239
- // Default export
8271
+ // Shared public surface used by the standard and CSP entries.
8240
8272
  // Default export remains for convenience (no side effects here)
8241
8273
  const Gyos = {
8242
8274
  scope,
@@ -8299,9 +8331,12 @@
8299
8331
  onAfterNavigate,
8300
8332
  portalCreate,
8301
8333
  portalDestroy,
8302
- version: '0.2.3'
8334
+ setCspNonce,
8335
+ version: '0.3.0'
8303
8336
  };
8304
8337
 
8338
+ setExpressionRuntime(standardExpressionRuntime);
8339
+
8305
8340
  exports.applyDirective = applyDirective;
8306
8341
  exports.applyTransitionStyles = applyTransitionStyles;
8307
8342
  exports.batch = batch;
@@ -8342,6 +8377,7 @@
8342
8377
  exports.registerTransition = registerTransition;
8343
8378
  exports.removeStore = removeStore;
8344
8379
  exports.scope = scope;
8380
+ exports.setCspNonce = setCspNonce;
8345
8381
  exports.shallow = shallow;
8346
8382
  exports.signal = signal;
8347
8383
  exports.startRouter = startRouter;