gyosjs 0.2.4 → 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.
- package/README.md +10 -6
- package/dist/auto-init.d.ts +1 -1
- package/dist/auto-init.d.ts.map +1 -1
- package/dist/core/component.d.ts.map +1 -1
- package/dist/core/router/script.d.ts.map +1 -1
- package/dist/core/transition.d.ts.map +1 -1
- package/dist/csp-auto-init.d.ts +3 -0
- package/dist/csp-auto-init.d.ts.map +1 -0
- package/dist/csp.d.ts +3 -0
- package/dist/csp.d.ts.map +1 -0
- package/dist/gyos.auto.esm.js +79 -46
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +79 -46
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +14979 -0
- package/dist/gyos.csp.auto.esm.js.map +1 -0
- package/dist/gyos.csp.auto.js +14989 -0
- package/dist/gyos.csp.auto.js.map +1 -0
- package/dist/gyos.csp.auto.min.js +6 -0
- package/dist/gyos.csp.esm.js +14952 -0
- package/dist/gyos.csp.esm.js.map +1 -0
- package/dist/gyos.csp.js +15023 -0
- package/dist/gyos.csp.js.map +1 -0
- package/dist/gyos.csp.min.js +6 -0
- package/dist/gyos.css +73 -0
- package/dist/gyos.esm.js +81 -47
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +81 -46
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/index.d.ts +2 -85
- package/dist/index.d.ts.map +1 -1
- package/dist/public-api.d.ts +89 -0
- package/dist/public-api.d.ts.map +1 -0
- package/dist/runtime/csp-evaluator.d.ts +7 -0
- package/dist/runtime/csp-evaluator.d.ts.map +1 -0
- package/dist/runtime/csp-nonce.d.ts +7 -0
- package/dist/runtime/csp-nonce.d.ts.map +1 -0
- package/dist/runtime/evaluator.d.ts +12 -0
- package/dist/runtime/evaluator.d.ts.map +1 -0
- package/dist/runtime/install-csp.d.ts +2 -0
- package/dist/runtime/install-csp.d.ts.map +1 -0
- package/dist/runtime/install-standard.d.ts +2 -0
- package/dist/runtime/install-standard.d.ts.map +1 -0
- package/dist/runtime/standard-evaluator.d.ts +3 -0
- package/dist/runtime/standard-evaluator.d.ts.map +1 -0
- package/dist/template/events.d.ts.map +1 -1
- package/dist/template/expression.d.ts.map +1 -1
- package/dist/utils/target-spinner.d.ts +0 -4
- package/dist/utils/target-spinner.d.ts.map +1 -1
- package/package.json +29 -12
package/dist/gyos.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.
|
|
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
|
-
|
|
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;
|
|
@@ -3685,24 +3716,7 @@
|
|
|
3685
3716
|
if (modifiers.includes('stop'))
|
|
3686
3717
|
e.stopPropagation();
|
|
3687
3718
|
try {
|
|
3688
|
-
|
|
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
|
-
}
|
|
3719
|
+
expressionRuntime().execute(handler, scope, e);
|
|
3706
3720
|
}
|
|
3707
3721
|
catch (err) {
|
|
3708
3722
|
console.error('[GyosJS] Error in event handler:', err);
|
|
@@ -5678,10 +5692,7 @@
|
|
|
5678
5692
|
if (!trimmed.startsWith('{')) {
|
|
5679
5693
|
return undefined; // Not an inline definition
|
|
5680
5694
|
}
|
|
5681
|
-
|
|
5682
|
-
// This allows methods and complex expressions
|
|
5683
|
-
const fn = new Function(`return (${trimmed})`);
|
|
5684
|
-
const definition = fn();
|
|
5695
|
+
const definition = expressionRuntime().parseScope(trimmed);
|
|
5685
5696
|
DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
|
|
5686
5697
|
return definition;
|
|
5687
5698
|
}
|
|
@@ -5745,10 +5756,10 @@
|
|
|
5745
5756
|
if (forbidden.some(f => expr.includes(f))) {
|
|
5746
5757
|
DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
|
|
5747
5758
|
}
|
|
5748
|
-
const args = key.split(':').slice(1)
|
|
5759
|
+
const args = key.split(':').slice(1);
|
|
5749
5760
|
const propName = key.split(':')[0];
|
|
5750
5761
|
try {
|
|
5751
|
-
definition[propName] =
|
|
5762
|
+
definition[propName] = expressionRuntime().createMethod(args, expr);
|
|
5752
5763
|
removeAttrs.push(attr.name);
|
|
5753
5764
|
}
|
|
5754
5765
|
catch (_) {
|
|
@@ -6728,7 +6739,7 @@
|
|
|
6728
6739
|
</div>
|
|
6729
6740
|
`;
|
|
6730
6741
|
// Inject styles if not already present
|
|
6731
|
-
if (!document.getElementById('gyos-target-spinner-styles')) {
|
|
6742
|
+
if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
|
|
6732
6743
|
const style = document.createElement('style');
|
|
6733
6744
|
style.id = 'gyos-target-spinner-styles';
|
|
6734
6745
|
style.textContent = `
|
|
@@ -6782,6 +6793,16 @@
|
|
|
6782
6793
|
}
|
|
6783
6794
|
}
|
|
6784
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
|
+
|
|
6785
6806
|
// Cache executed scripts to prevent duplicate execution
|
|
6786
6807
|
const executedScripts = new Set();
|
|
6787
6808
|
/**
|
|
@@ -6882,6 +6903,12 @@
|
|
|
6882
6903
|
old.remove();
|
|
6883
6904
|
return;
|
|
6884
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
|
+
}
|
|
6885
6912
|
const executionKey = getScriptExecutionKey(old);
|
|
6886
6913
|
// Check if script should execute
|
|
6887
6914
|
if (!shouldExecuteScript(old)) {
|
|
@@ -6891,6 +6918,10 @@
|
|
|
6891
6918
|
}
|
|
6892
6919
|
const newScript = document.createElement('script');
|
|
6893
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);
|
|
6894
6925
|
newScript.textContent = old.hasAttribute('g-script-wrap')
|
|
6895
6926
|
? wrapScriptExecution(old.textContent)
|
|
6896
6927
|
: old.textContent;
|
|
@@ -8237,7 +8268,7 @@
|
|
|
8237
8268
|
});
|
|
8238
8269
|
}
|
|
8239
8270
|
|
|
8240
|
-
//
|
|
8271
|
+
// Shared public surface used by the standard and CSP entries.
|
|
8241
8272
|
// Default export remains for convenience (no side effects here)
|
|
8242
8273
|
const Gyos = {
|
|
8243
8274
|
scope,
|
|
@@ -8300,9 +8331,12 @@
|
|
|
8300
8331
|
onAfterNavigate,
|
|
8301
8332
|
portalCreate,
|
|
8302
8333
|
portalDestroy,
|
|
8303
|
-
|
|
8334
|
+
setCspNonce,
|
|
8335
|
+
version: '0.3.0'
|
|
8304
8336
|
};
|
|
8305
8337
|
|
|
8338
|
+
setExpressionRuntime(standardExpressionRuntime);
|
|
8339
|
+
|
|
8306
8340
|
exports.applyDirective = applyDirective;
|
|
8307
8341
|
exports.applyTransitionStyles = applyTransitionStyles;
|
|
8308
8342
|
exports.batch = batch;
|
|
@@ -8343,6 +8377,7 @@
|
|
|
8343
8377
|
exports.registerTransition = registerTransition;
|
|
8344
8378
|
exports.removeStore = removeStore;
|
|
8345
8379
|
exports.scope = scope;
|
|
8380
|
+
exports.setCspNonce = setCspNonce;
|
|
8346
8381
|
exports.shallow = shallow;
|
|
8347
8382
|
exports.signal = signal;
|
|
8348
8383
|
exports.startRouter = startRouter;
|