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.
- package/README.md +129 -125
- 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/router.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/form/form-validation.d.ts.map +1 -1
- package/dist/gyos.auto.esm.js +89 -55
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +89 -55
- 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 +91 -56
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +91 -55
- 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 +72 -55
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;
|
|
@@ -3268,8 +3267,8 @@
|
|
|
3268
3267
|
|
|
3269
3268
|
const managedForms = new WeakSet();
|
|
3270
3269
|
const approvedSubmissions = new WeakSet();
|
|
3271
|
-
// Coordinates the
|
|
3272
|
-
//
|
|
3270
|
+
// Coordinates the form capture validator with the Router's document listener
|
|
3271
|
+
// without exposing state on application elements.
|
|
3273
3272
|
function registerValidatedForm(form) {
|
|
3274
3273
|
managedForms.add(form);
|
|
3275
3274
|
}
|
|
@@ -3419,7 +3418,6 @@
|
|
|
3419
3418
|
const submitListener = async (e) => {
|
|
3420
3419
|
if (replayingSubmission) {
|
|
3421
3420
|
replayingSubmission = false;
|
|
3422
|
-
cancelApprovedFormSubmission(form);
|
|
3423
3421
|
return;
|
|
3424
3422
|
}
|
|
3425
3423
|
e.preventDefault();
|
|
@@ -3450,11 +3448,11 @@
|
|
|
3450
3448
|
}
|
|
3451
3449
|
finally {
|
|
3452
3450
|
// requestSubmit dispatches synchronously. If native validation or
|
|
3453
|
-
// another
|
|
3451
|
+
// another listener stopped it, do not leak approval state.
|
|
3454
3452
|
if (replayingSubmission) {
|
|
3455
3453
|
replayingSubmission = false;
|
|
3456
|
-
cancelApprovedFormSubmission(form);
|
|
3457
3454
|
}
|
|
3455
|
+
cancelApprovedFormSubmission(form);
|
|
3458
3456
|
}
|
|
3459
3457
|
}, 0);
|
|
3460
3458
|
return;
|
|
@@ -3686,24 +3684,7 @@
|
|
|
3686
3684
|
if (modifiers.includes('stop'))
|
|
3687
3685
|
e.stopPropagation();
|
|
3688
3686
|
try {
|
|
3689
|
-
|
|
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
|
-
}
|
|
3687
|
+
expressionRuntime().execute(handler, scope, e);
|
|
3707
3688
|
}
|
|
3708
3689
|
catch (err) {
|
|
3709
3690
|
console.error('[GyosJS] Error in event handler:', err);
|
|
@@ -5679,10 +5660,7 @@
|
|
|
5679
5660
|
if (!trimmed.startsWith('{')) {
|
|
5680
5661
|
return undefined; // Not an inline definition
|
|
5681
5662
|
}
|
|
5682
|
-
|
|
5683
|
-
// This allows methods and complex expressions
|
|
5684
|
-
const fn = new Function(`return (${trimmed})`);
|
|
5685
|
-
const definition = fn();
|
|
5663
|
+
const definition = expressionRuntime().parseScope(trimmed);
|
|
5686
5664
|
DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
|
|
5687
5665
|
return definition;
|
|
5688
5666
|
}
|
|
@@ -5746,10 +5724,10 @@
|
|
|
5746
5724
|
if (forbidden.some(f => expr.includes(f))) {
|
|
5747
5725
|
DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
|
|
5748
5726
|
}
|
|
5749
|
-
const args = key.split(':').slice(1)
|
|
5727
|
+
const args = key.split(':').slice(1);
|
|
5750
5728
|
const propName = key.split(':')[0];
|
|
5751
5729
|
try {
|
|
5752
|
-
definition[propName] =
|
|
5730
|
+
definition[propName] = expressionRuntime().createMethod(args, expr);
|
|
5753
5731
|
removeAttrs.push(attr.name);
|
|
5754
5732
|
}
|
|
5755
5733
|
catch (_) {
|
|
@@ -6729,7 +6707,7 @@
|
|
|
6729
6707
|
</div>
|
|
6730
6708
|
`;
|
|
6731
6709
|
// Inject styles if not already present
|
|
6732
|
-
if (!document.getElementById('gyos-target-spinner-styles')) {
|
|
6710
|
+
if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
|
|
6733
6711
|
const style = document.createElement('style');
|
|
6734
6712
|
style.id = 'gyos-target-spinner-styles';
|
|
6735
6713
|
style.textContent = `
|
|
@@ -6783,6 +6761,16 @@
|
|
|
6783
6761
|
}
|
|
6784
6762
|
}
|
|
6785
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
|
+
|
|
6786
6774
|
// Cache executed scripts to prevent duplicate execution
|
|
6787
6775
|
const executedScripts = new Set();
|
|
6788
6776
|
/**
|
|
@@ -6883,6 +6871,12 @@
|
|
|
6883
6871
|
old.remove();
|
|
6884
6872
|
return;
|
|
6885
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
|
+
}
|
|
6886
6880
|
const executionKey = getScriptExecutionKey(old);
|
|
6887
6881
|
// Check if script should execute
|
|
6888
6882
|
if (!shouldExecuteScript(old)) {
|
|
@@ -6892,6 +6886,10 @@
|
|
|
6892
6886
|
}
|
|
6893
6887
|
const newScript = document.createElement('script');
|
|
6894
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);
|
|
6895
6893
|
newScript.textContent = old.hasAttribute('g-script-wrap')
|
|
6896
6894
|
? wrapScriptExecution(old.textContent)
|
|
6897
6895
|
: old.textContent;
|
|
@@ -7444,8 +7442,8 @@
|
|
|
7444
7442
|
if (progressBarEnabled) {
|
|
7445
7443
|
progressBar = new ProgressBar(progressBarEnabled);
|
|
7446
7444
|
}
|
|
7447
|
-
document.addEventListener('click',
|
|
7448
|
-
document.addEventListener('submit',
|
|
7445
|
+
document.addEventListener('click', onClick);
|
|
7446
|
+
document.addEventListener('submit', onSubmit);
|
|
7449
7447
|
document.addEventListener('mouseover', onMouseOverCapture, true);
|
|
7450
7448
|
window.addEventListener('popstate', onPopState);
|
|
7451
7449
|
if ('scrollRestoration' in history) {
|
|
@@ -8116,7 +8114,7 @@
|
|
|
8116
8114
|
return; // this case not link (tag a) or form so do nothing
|
|
8117
8115
|
}
|
|
8118
8116
|
}
|
|
8119
|
-
function
|
|
8117
|
+
function onClick(event) {
|
|
8120
8118
|
if (event.defaultPrevented)
|
|
8121
8119
|
return;
|
|
8122
8120
|
if (event.button !== 0)
|
|
@@ -8173,7 +8171,9 @@
|
|
|
8173
8171
|
return;
|
|
8174
8172
|
preload(url.toString());
|
|
8175
8173
|
}
|
|
8176
|
-
function
|
|
8174
|
+
function onSubmit(event) {
|
|
8175
|
+
if (event.defaultPrevented)
|
|
8176
|
+
return;
|
|
8177
8177
|
const form = event.target;
|
|
8178
8178
|
if (!form || form.tagName.toLowerCase() !== 'form')
|
|
8179
8179
|
return;
|
|
@@ -8236,7 +8236,7 @@
|
|
|
8236
8236
|
});
|
|
8237
8237
|
}
|
|
8238
8238
|
|
|
8239
|
-
//
|
|
8239
|
+
// Shared public surface used by the standard and CSP entries.
|
|
8240
8240
|
// Default export remains for convenience (no side effects here)
|
|
8241
8241
|
const Gyos = {
|
|
8242
8242
|
scope,
|
|
@@ -8299,10 +8299,44 @@
|
|
|
8299
8299
|
onAfterNavigate,
|
|
8300
8300
|
portalCreate,
|
|
8301
8301
|
portalDestroy,
|
|
8302
|
-
|
|
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
|
+
}
|
|
8303
8336
|
};
|
|
8304
8337
|
|
|
8305
8338
|
var _a, _b, _c;
|
|
8339
|
+
setExpressionRuntime(standardExpressionRuntime);
|
|
8306
8340
|
/**
|
|
8307
8341
|
* Browser auto-init entry.
|
|
8308
8342
|
* Attaches Gyos to window, sets debug defaults, injects transitions, starts router,
|