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.auto.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
|
*/
|
|
@@ -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
|
-
|
|
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;
|
|
@@ -3685,24 +3684,7 @@
|
|
|
3685
3684
|
if (modifiers.includes('stop'))
|
|
3686
3685
|
e.stopPropagation();
|
|
3687
3686
|
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
|
-
}
|
|
3687
|
+
expressionRuntime().execute(handler, scope, e);
|
|
3706
3688
|
}
|
|
3707
3689
|
catch (err) {
|
|
3708
3690
|
console.error('[GyosJS] Error in event handler:', err);
|
|
@@ -5678,10 +5660,7 @@
|
|
|
5678
5660
|
if (!trimmed.startsWith('{')) {
|
|
5679
5661
|
return undefined; // Not an inline definition
|
|
5680
5662
|
}
|
|
5681
|
-
|
|
5682
|
-
// This allows methods and complex expressions
|
|
5683
|
-
const fn = new Function(`return (${trimmed})`);
|
|
5684
|
-
const definition = fn();
|
|
5663
|
+
const definition = expressionRuntime().parseScope(trimmed);
|
|
5685
5664
|
DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
|
|
5686
5665
|
return definition;
|
|
5687
5666
|
}
|
|
@@ -5745,10 +5724,10 @@
|
|
|
5745
5724
|
if (forbidden.some(f => expr.includes(f))) {
|
|
5746
5725
|
DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
|
|
5747
5726
|
}
|
|
5748
|
-
const args = key.split(':').slice(1)
|
|
5727
|
+
const args = key.split(':').slice(1);
|
|
5749
5728
|
const propName = key.split(':')[0];
|
|
5750
5729
|
try {
|
|
5751
|
-
definition[propName] =
|
|
5730
|
+
definition[propName] = expressionRuntime().createMethod(args, expr);
|
|
5752
5731
|
removeAttrs.push(attr.name);
|
|
5753
5732
|
}
|
|
5754
5733
|
catch (_) {
|
|
@@ -6728,7 +6707,7 @@
|
|
|
6728
6707
|
</div>
|
|
6729
6708
|
`;
|
|
6730
6709
|
// Inject styles if not already present
|
|
6731
|
-
if (!document.getElementById('gyos-target-spinner-styles')) {
|
|
6710
|
+
if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
|
|
6732
6711
|
const style = document.createElement('style');
|
|
6733
6712
|
style.id = 'gyos-target-spinner-styles';
|
|
6734
6713
|
style.textContent = `
|
|
@@ -6782,6 +6761,16 @@
|
|
|
6782
6761
|
}
|
|
6783
6762
|
}
|
|
6784
6763
|
|
|
6764
|
+
let nonceSource;
|
|
6765
|
+
/** Configure the nonce used when Gyos recreates scripts during MPA navigation. */
|
|
6766
|
+
function setCspNonce(source) {
|
|
6767
|
+
nonceSource = source;
|
|
6768
|
+
}
|
|
6769
|
+
function resolveCspNonce() {
|
|
6770
|
+
const value = typeof nonceSource === 'function' ? nonceSource() : nonceSource;
|
|
6771
|
+
return value || undefined;
|
|
6772
|
+
}
|
|
6773
|
+
|
|
6785
6774
|
// Cache executed scripts to prevent duplicate execution
|
|
6786
6775
|
const executedScripts = new Set();
|
|
6787
6776
|
/**
|
|
@@ -6882,6 +6871,12 @@
|
|
|
6882
6871
|
old.remove();
|
|
6883
6872
|
return;
|
|
6884
6873
|
}
|
|
6874
|
+
const activeNonce = resolveCspNonce();
|
|
6875
|
+
if (expressionRuntimeMode() === 'csp' && !old.src && !activeNonce) {
|
|
6876
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
6877
|
+
old.textContent = '';
|
|
6878
|
+
return;
|
|
6879
|
+
}
|
|
6885
6880
|
const executionKey = getScriptExecutionKey(old);
|
|
6886
6881
|
// Check if script should execute
|
|
6887
6882
|
if (!shouldExecuteScript(old)) {
|
|
@@ -6891,6 +6886,10 @@
|
|
|
6891
6886
|
}
|
|
6892
6887
|
const newScript = document.createElement('script');
|
|
6893
6888
|
Array.from(old.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
|
|
6889
|
+
if (expressionRuntimeMode() === 'csp')
|
|
6890
|
+
newScript.removeAttribute('nonce');
|
|
6891
|
+
if (activeNonce)
|
|
6892
|
+
newScript.setAttribute('nonce', activeNonce);
|
|
6894
6893
|
newScript.textContent = old.hasAttribute('g-script-wrap')
|
|
6895
6894
|
? wrapScriptExecution(old.textContent)
|
|
6896
6895
|
: old.textContent;
|
|
@@ -8237,7 +8236,7 @@
|
|
|
8237
8236
|
});
|
|
8238
8237
|
}
|
|
8239
8238
|
|
|
8240
|
-
//
|
|
8239
|
+
// Shared public surface used by the standard and CSP entries.
|
|
8241
8240
|
// Default export remains for convenience (no side effects here)
|
|
8242
8241
|
const Gyos = {
|
|
8243
8242
|
scope,
|
|
@@ -8300,10 +8299,44 @@
|
|
|
8300
8299
|
onAfterNavigate,
|
|
8301
8300
|
portalCreate,
|
|
8302
8301
|
portalDestroy,
|
|
8303
|
-
|
|
8302
|
+
setCspNonce,
|
|
8303
|
+
version: '0.3.0'
|
|
8304
|
+
};
|
|
8305
|
+
|
|
8306
|
+
const standardExpressionRuntime = {
|
|
8307
|
+
mode: 'standard',
|
|
8308
|
+
evaluate(expression, scope) {
|
|
8309
|
+
const method = scope?.[expression];
|
|
8310
|
+
if (typeof method === 'function')
|
|
8311
|
+
return method.call(scope);
|
|
8312
|
+
try {
|
|
8313
|
+
const safeExpression = `try { return ${expression} } catch(e) { return undefined }`;
|
|
8314
|
+
const evaluate = new Function('$scope', `with($scope) { ${safeExpression} }`);
|
|
8315
|
+
return evaluate(scope);
|
|
8316
|
+
}
|
|
8317
|
+
catch (error) {
|
|
8318
|
+
console.error('[GyosJS] Error evaluating expression:', expression, error);
|
|
8319
|
+
return undefined;
|
|
8320
|
+
}
|
|
8321
|
+
},
|
|
8322
|
+
execute(expression, scope, event) {
|
|
8323
|
+
const method = scope?.[expression];
|
|
8324
|
+
if (typeof method === 'function')
|
|
8325
|
+
return method.call(scope, event);
|
|
8326
|
+
const execute = new Function('$event', `with(this) { ${expression} }`);
|
|
8327
|
+
return execute.call(scope, event);
|
|
8328
|
+
},
|
|
8329
|
+
parseScope(expression) {
|
|
8330
|
+
const parse = new Function(`return (${expression})`);
|
|
8331
|
+
return parse();
|
|
8332
|
+
},
|
|
8333
|
+
createMethod(parameters, body) {
|
|
8334
|
+
return new Function(parameters.join(', '), `with(this) { ${body} }`);
|
|
8335
|
+
}
|
|
8304
8336
|
};
|
|
8305
8337
|
|
|
8306
8338
|
var _a, _b, _c;
|
|
8339
|
+
setExpressionRuntime(standardExpressionRuntime);
|
|
8307
8340
|
/**
|
|
8308
8341
|
* Browser auto-init entry.
|
|
8309
8342
|
* Attaches Gyos to window, sets debug defaults, injects transitions, starts router,
|