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.
- 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/csp-html.d.ts +2 -0
- package/dist/core/router/csp-html.d.ts.map +1 -0
- package/dist/core/router/diff-nodes.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/gyos.auto.esm.js +337 -75
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +337 -75
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +15208 -0
- package/dist/gyos.csp.auto.esm.js.map +1 -0
- package/dist/gyos.csp.auto.js +15218 -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 +15181 -0
- package/dist/gyos.csp.esm.js.map +1 -0
- package/dist/gyos.csp.js +15252 -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 +339 -76
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +339 -75
- 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/template/structurals/transition-helpers.d.ts +1 -1
- package/dist/template/structurals/transition-helpers.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.1
|
|
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;
|
|
@@ -2269,32 +2300,24 @@
|
|
|
2269
2300
|
* Handles:
|
|
2270
2301
|
* 1. Literal string: "fade" or "slide-down"
|
|
2271
2302
|
* 2. Expression with {}: "{transition}"
|
|
2272
|
-
* 3.
|
|
2303
|
+
* 3. Quoted literal kept for backwards compatibility: "'fade'"
|
|
2273
2304
|
*
|
|
2274
2305
|
* @param attrValue - The g-transition attribute value
|
|
2275
2306
|
* @param scope - Current scope for expression evaluation
|
|
2276
2307
|
* @returns The transition name (string)
|
|
2277
2308
|
*/
|
|
2278
2309
|
function parseTransitionName(attrValue, scope) {
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
}
|
|
2310
|
+
const value = attrValue.trim();
|
|
2311
|
+
const expression = /^\{([\s\S]+)\}$/.exec(value);
|
|
2312
|
+
if (expression) {
|
|
2313
|
+
const evaluated = evaluateExpression(expression[1].trim(), scope);
|
|
2314
|
+
return evaluated == null ? '' : String(evaluated);
|
|
2285
2315
|
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
const evaluated = evaluateExpression(attrValue, scope);
|
|
2290
|
-
if (evaluated !== undefined && evaluated !== null) {
|
|
2291
|
-
return evaluated;
|
|
2292
|
-
}
|
|
2316
|
+
if (value.length >= 2 && ((value.startsWith("'") && value.endsWith("'"))
|
|
2317
|
+
|| (value.startsWith('"') && value.endsWith('"')))) {
|
|
2318
|
+
return value.slice(1, -1);
|
|
2293
2319
|
}
|
|
2294
|
-
|
|
2295
|
-
// If evaluation fails, use value as literal string (built-in transition name)
|
|
2296
|
-
}
|
|
2297
|
-
return attrValue;
|
|
2320
|
+
return value;
|
|
2298
2321
|
}
|
|
2299
2322
|
/**
|
|
2300
2323
|
* Parse transition config from element's g-transition attribute
|
|
@@ -3685,24 +3708,7 @@
|
|
|
3685
3708
|
if (modifiers.includes('stop'))
|
|
3686
3709
|
e.stopPropagation();
|
|
3687
3710
|
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
|
-
}
|
|
3711
|
+
expressionRuntime().execute(handler, scope, e);
|
|
3706
3712
|
}
|
|
3707
3713
|
catch (err) {
|
|
3708
3714
|
console.error('[GyosJS] Error in event handler:', err);
|
|
@@ -5678,10 +5684,7 @@
|
|
|
5678
5684
|
if (!trimmed.startsWith('{')) {
|
|
5679
5685
|
return undefined; // Not an inline definition
|
|
5680
5686
|
}
|
|
5681
|
-
|
|
5682
|
-
// This allows methods and complex expressions
|
|
5683
|
-
const fn = new Function(`return (${trimmed})`);
|
|
5684
|
-
const definition = fn();
|
|
5687
|
+
const definition = expressionRuntime().parseScope(trimmed);
|
|
5685
5688
|
DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
|
|
5686
5689
|
return definition;
|
|
5687
5690
|
}
|
|
@@ -5745,10 +5748,10 @@
|
|
|
5745
5748
|
if (forbidden.some(f => expr.includes(f))) {
|
|
5746
5749
|
DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
|
|
5747
5750
|
}
|
|
5748
|
-
const args = key.split(':').slice(1)
|
|
5751
|
+
const args = key.split(':').slice(1);
|
|
5749
5752
|
const propName = key.split(':')[0];
|
|
5750
5753
|
try {
|
|
5751
|
-
definition[propName] =
|
|
5754
|
+
definition[propName] = expressionRuntime().createMethod(args, expr);
|
|
5752
5755
|
removeAttrs.push(attr.name);
|
|
5753
5756
|
}
|
|
5754
5757
|
catch (_) {
|
|
@@ -6728,7 +6731,7 @@
|
|
|
6728
6731
|
</div>
|
|
6729
6732
|
`;
|
|
6730
6733
|
// Inject styles if not already present
|
|
6731
|
-
if (!document.getElementById('gyos-target-spinner-styles')) {
|
|
6734
|
+
if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
|
|
6732
6735
|
const style = document.createElement('style');
|
|
6733
6736
|
style.id = 'gyos-target-spinner-styles';
|
|
6734
6737
|
style.textContent = `
|
|
@@ -6782,6 +6785,16 @@
|
|
|
6782
6785
|
}
|
|
6783
6786
|
}
|
|
6784
6787
|
|
|
6788
|
+
let nonceSource;
|
|
6789
|
+
/** Configure the active document nonce used for scripts and styles during MPA navigation. */
|
|
6790
|
+
function setCspNonce(source) {
|
|
6791
|
+
nonceSource = source;
|
|
6792
|
+
}
|
|
6793
|
+
function resolveCspNonce() {
|
|
6794
|
+
const value = typeof nonceSource === 'function' ? nonceSource() : nonceSource;
|
|
6795
|
+
return value || undefined;
|
|
6796
|
+
}
|
|
6797
|
+
|
|
6785
6798
|
// Cache executed scripts to prevent duplicate execution
|
|
6786
6799
|
const executedScripts = new Set();
|
|
6787
6800
|
/**
|
|
@@ -6882,6 +6895,12 @@
|
|
|
6882
6895
|
old.remove();
|
|
6883
6896
|
return;
|
|
6884
6897
|
}
|
|
6898
|
+
const activeNonce = resolveCspNonce();
|
|
6899
|
+
if (expressionRuntimeMode() === 'csp' && !old.src && !activeNonce) {
|
|
6900
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
6901
|
+
old.textContent = '';
|
|
6902
|
+
return;
|
|
6903
|
+
}
|
|
6885
6904
|
const executionKey = getScriptExecutionKey(old);
|
|
6886
6905
|
// Check if script should execute
|
|
6887
6906
|
if (!shouldExecuteScript(old)) {
|
|
@@ -6891,6 +6910,10 @@
|
|
|
6891
6910
|
}
|
|
6892
6911
|
const newScript = document.createElement('script');
|
|
6893
6912
|
Array.from(old.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
|
|
6913
|
+
if (expressionRuntimeMode() === 'csp')
|
|
6914
|
+
newScript.removeAttribute('nonce');
|
|
6915
|
+
if (activeNonce)
|
|
6916
|
+
newScript.setAttribute('nonce', activeNonce);
|
|
6894
6917
|
newScript.textContent = old.hasAttribute('g-script-wrap')
|
|
6895
6918
|
? wrapScriptExecution(old.textContent)
|
|
6896
6919
|
: old.textContent;
|
|
@@ -7335,9 +7358,33 @@
|
|
|
7335
7358
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
7336
7359
|
}
|
|
7337
7360
|
|
|
7338
|
-
function
|
|
7339
|
-
return
|
|
7340
|
-
|
|
7361
|
+
function isNonceMeta(el) {
|
|
7362
|
+
return el.tagName === 'META' && el.getAttribute('name')?.toLowerCase() === 'csp-nonce';
|
|
7363
|
+
}
|
|
7364
|
+
function isStylesheetLink(el) {
|
|
7365
|
+
return el.tagName === 'LINK'
|
|
7366
|
+
&& (el.getAttribute('rel') || '').toLowerCase().split(/\s+/).includes('stylesheet');
|
|
7367
|
+
}
|
|
7368
|
+
function usesCspNonce(el) {
|
|
7369
|
+
return el.tagName === 'SCRIPT' || el.tagName === 'STYLE' || isStylesheetLink(el);
|
|
7370
|
+
}
|
|
7371
|
+
function serializeAttributes(el, context) {
|
|
7372
|
+
const attributes = new Map();
|
|
7373
|
+
Array.from(el.attributes).forEach(attr => {
|
|
7374
|
+
if (context.csp && usesCspNonce(el) && attr.name.toLowerCase() === 'nonce')
|
|
7375
|
+
return;
|
|
7376
|
+
if (context.csp && isNonceMeta(el) && attr.name.toLowerCase() === 'content')
|
|
7377
|
+
return;
|
|
7378
|
+
attributes.set(attr.name, attr.value);
|
|
7379
|
+
});
|
|
7380
|
+
if (context.csp && usesCspNonce(el) && context.activeNonce) {
|
|
7381
|
+
attributes.set('nonce', context.activeNonce);
|
|
7382
|
+
}
|
|
7383
|
+
if (context.csp && isNonceMeta(el) && context.activeNonce) {
|
|
7384
|
+
attributes.set('content', context.activeNonce);
|
|
7385
|
+
}
|
|
7386
|
+
return Array.from(attributes)
|
|
7387
|
+
.map(([name, value]) => `${name}=${value}`)
|
|
7341
7388
|
.sort()
|
|
7342
7389
|
.join('|');
|
|
7343
7390
|
}
|
|
@@ -7348,23 +7395,61 @@
|
|
|
7348
7395
|
}
|
|
7349
7396
|
return String(hash);
|
|
7350
7397
|
}
|
|
7351
|
-
function elementKey(el) {
|
|
7398
|
+
function elementKey(el, context) {
|
|
7352
7399
|
const tag = el.tagName.toLowerCase();
|
|
7353
7400
|
const content = tag === 'script' || tag === 'style' ? hashContent(el.textContent || '') : '';
|
|
7354
|
-
return `${tag}|${serializeAttributes(el)}|${content}`;
|
|
7401
|
+
return `${tag}|${serializeAttributes(el, context)}|${content}`;
|
|
7355
7402
|
}
|
|
7356
|
-
function keyedNodes(nodes) {
|
|
7403
|
+
function keyedNodes(nodes, context) {
|
|
7357
7404
|
const occurrences = new Map();
|
|
7358
7405
|
return nodes.map(node => {
|
|
7359
|
-
const baseKey = elementKey(node);
|
|
7406
|
+
const baseKey = elementKey(node, context);
|
|
7360
7407
|
const occurrence = occurrences.get(baseKey) || 0;
|
|
7361
7408
|
occurrences.set(baseKey, occurrence + 1);
|
|
7362
7409
|
return { key: `${baseKey}|${occurrence}`, node };
|
|
7363
7410
|
});
|
|
7364
7411
|
}
|
|
7412
|
+
function canInsertNode(node, context) {
|
|
7413
|
+
if (!context.csp)
|
|
7414
|
+
return true;
|
|
7415
|
+
if (isNonceMeta(node))
|
|
7416
|
+
return Boolean(context.activeNonce);
|
|
7417
|
+
if (node.tagName === 'STYLE')
|
|
7418
|
+
return Boolean(context.activeNonce);
|
|
7419
|
+
if (node.tagName === 'SCRIPT' && !node.hasAttribute('src'))
|
|
7420
|
+
return Boolean(context.activeNonce);
|
|
7421
|
+
return true;
|
|
7422
|
+
}
|
|
7423
|
+
function reconcileCspAttributes(node, context) {
|
|
7424
|
+
if (!context.csp)
|
|
7425
|
+
return;
|
|
7426
|
+
if (isNonceMeta(node)) {
|
|
7427
|
+
if (context.activeNonce)
|
|
7428
|
+
node.setAttribute('content', context.activeNonce);
|
|
7429
|
+
return;
|
|
7430
|
+
}
|
|
7431
|
+
if (!usesCspNonce(node))
|
|
7432
|
+
return;
|
|
7433
|
+
node.removeAttribute('nonce');
|
|
7434
|
+
if (context.activeNonce)
|
|
7435
|
+
node.setAttribute('nonce', context.activeNonce);
|
|
7436
|
+
}
|
|
7437
|
+
function warnSkippedNode(node) {
|
|
7438
|
+
if (node.tagName === 'STYLE') {
|
|
7439
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA style because no active document nonce is configured.');
|
|
7440
|
+
}
|
|
7441
|
+
else if (node.tagName === 'SCRIPT' && !node.hasAttribute('src')) {
|
|
7442
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
7443
|
+
}
|
|
7444
|
+
}
|
|
7365
7445
|
async function diffNodes(currentNodes, nextNodes, container = document.head, signal) {
|
|
7366
|
-
const
|
|
7367
|
-
const
|
|
7446
|
+
const csp = expressionRuntimeMode() === 'csp';
|
|
7447
|
+
const context = {
|
|
7448
|
+
csp,
|
|
7449
|
+
activeNonce: csp ? resolveCspNonce() : undefined
|
|
7450
|
+
};
|
|
7451
|
+
const current = keyedNodes(currentNodes, context);
|
|
7452
|
+
const next = keyedNodes(nextNodes, context);
|
|
7368
7453
|
const currentKeys = new Set(current.map(item => item.key));
|
|
7369
7454
|
const nextKeys = new Set(next.map(item => item.key));
|
|
7370
7455
|
// Remove nodes that are not in the new head
|
|
@@ -7378,6 +7463,20 @@
|
|
|
7378
7463
|
if (signal?.aborted)
|
|
7379
7464
|
return;
|
|
7380
7465
|
if (!currentKeys.has(key)) {
|
|
7466
|
+
if (!canInsertNode(node, context)) {
|
|
7467
|
+
warnSkippedNode(node);
|
|
7468
|
+
continue;
|
|
7469
|
+
}
|
|
7470
|
+
if (node.tagName === 'STYLE') {
|
|
7471
|
+
const style = document.createElement('style');
|
|
7472
|
+
Array.from(node.attributes).forEach(attr => style.setAttribute(attr.name, attr.value));
|
|
7473
|
+
reconcileCspAttributes(style, context);
|
|
7474
|
+
// CSP checks inline styles as their CSS text is attached. Set the active
|
|
7475
|
+
// nonce first so a response nonce never produces a transient violation.
|
|
7476
|
+
style.textContent = node.textContent || '';
|
|
7477
|
+
container.appendChild(style);
|
|
7478
|
+
continue;
|
|
7479
|
+
}
|
|
7381
7480
|
if (node.tagName === 'SCRIPT') {
|
|
7382
7481
|
const originalScript = node;
|
|
7383
7482
|
const executionKey = getScriptExecutionKey(originalScript);
|
|
@@ -7388,6 +7487,7 @@
|
|
|
7388
7487
|
}
|
|
7389
7488
|
const script = document.createElement('script');
|
|
7390
7489
|
Array.from(node.attributes).forEach(attr => script.setAttribute(attr.name, attr.value));
|
|
7490
|
+
reconcileCspAttributes(script, context);
|
|
7391
7491
|
script.textContent = node.hasAttribute('g-script-wrap')
|
|
7392
7492
|
? wrapScriptExecution(node.textContent || '')
|
|
7393
7493
|
: node.textContent || '';
|
|
@@ -7397,9 +7497,166 @@
|
|
|
7397
7497
|
await completion;
|
|
7398
7498
|
continue;
|
|
7399
7499
|
}
|
|
7400
|
-
|
|
7500
|
+
const imported = document.importNode(node, true);
|
|
7501
|
+
reconcileCspAttributes(imported, context);
|
|
7502
|
+
container.appendChild(imported);
|
|
7503
|
+
}
|
|
7504
|
+
}
|
|
7505
|
+
}
|
|
7506
|
+
|
|
7507
|
+
const RAW_TEXT_ELEMENTS = new Set(['iframe', 'noembed', 'noframes', 'plaintext', 'script', 'textarea', 'title', 'xmp']);
|
|
7508
|
+
function escapeAttribute(value) {
|
|
7509
|
+
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
7510
|
+
}
|
|
7511
|
+
function findTagEnd(html, start) {
|
|
7512
|
+
let quote = '';
|
|
7513
|
+
for (let index = start; index < html.length; index += 1) {
|
|
7514
|
+
const character = html[index];
|
|
7515
|
+
if (quote) {
|
|
7516
|
+
if (character === quote)
|
|
7517
|
+
quote = '';
|
|
7518
|
+
continue;
|
|
7519
|
+
}
|
|
7520
|
+
if (character === '"' || character === "'") {
|
|
7521
|
+
quote = character;
|
|
7522
|
+
continue;
|
|
7523
|
+
}
|
|
7524
|
+
if (character === '>')
|
|
7525
|
+
return index + 1;
|
|
7526
|
+
}
|
|
7527
|
+
return html.length;
|
|
7528
|
+
}
|
|
7529
|
+
function findClosingTag(html, lowerHtml, name, start) {
|
|
7530
|
+
const needle = `</${name}`;
|
|
7531
|
+
let position = lowerHtml.indexOf(needle, start);
|
|
7532
|
+
while (position !== -1) {
|
|
7533
|
+
const boundary = lowerHtml[position + needle.length];
|
|
7534
|
+
if (boundary === '>' || /\s/.test(boundary || '')) {
|
|
7535
|
+
return {
|
|
7536
|
+
start: position,
|
|
7537
|
+
end: findTagEnd(html, position + needle.length)
|
|
7538
|
+
};
|
|
7539
|
+
}
|
|
7540
|
+
position = lowerHtml.indexOf(needle, position + needle.length);
|
|
7541
|
+
}
|
|
7542
|
+
return null;
|
|
7543
|
+
}
|
|
7544
|
+
function removeNonceAttribute(openingTag) {
|
|
7545
|
+
const prefix = /^<\s*style\b/i.exec(openingTag);
|
|
7546
|
+
if (!prefix)
|
|
7547
|
+
return openingTag;
|
|
7548
|
+
let output = prefix[0];
|
|
7549
|
+
let cursor = prefix[0].length;
|
|
7550
|
+
const limit = openingTag.length - 1;
|
|
7551
|
+
while (cursor < limit) {
|
|
7552
|
+
const attributeStart = cursor;
|
|
7553
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7554
|
+
cursor += 1;
|
|
7555
|
+
if (cursor >= limit || openingTag[cursor] === '>') {
|
|
7556
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7557
|
+
break;
|
|
7558
|
+
}
|
|
7559
|
+
const nameStart = cursor;
|
|
7560
|
+
while (cursor < limit && !/[\s=/>]/.test(openingTag[cursor]))
|
|
7561
|
+
cursor += 1;
|
|
7562
|
+
if (cursor === nameStart) {
|
|
7563
|
+
output += openingTag.slice(attributeStart, cursor + 1);
|
|
7564
|
+
cursor += 1;
|
|
7565
|
+
continue;
|
|
7566
|
+
}
|
|
7567
|
+
const name = openingTag.slice(nameStart, cursor).toLowerCase();
|
|
7568
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7569
|
+
cursor += 1;
|
|
7570
|
+
if (openingTag[cursor] === '=') {
|
|
7571
|
+
cursor += 1;
|
|
7572
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7573
|
+
cursor += 1;
|
|
7574
|
+
const quote = openingTag[cursor] === '"' || openingTag[cursor] === "'" ? openingTag[cursor] : '';
|
|
7575
|
+
if (quote) {
|
|
7576
|
+
cursor += 1;
|
|
7577
|
+
while (cursor < limit && openingTag[cursor] !== quote)
|
|
7578
|
+
cursor += 1;
|
|
7579
|
+
if (openingTag[cursor] === quote)
|
|
7580
|
+
cursor += 1;
|
|
7581
|
+
}
|
|
7582
|
+
else {
|
|
7583
|
+
while (cursor < limit && !/[\s>]/.test(openingTag[cursor]))
|
|
7584
|
+
cursor += 1;
|
|
7585
|
+
}
|
|
7586
|
+
}
|
|
7587
|
+
if (name !== 'nonce')
|
|
7588
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7589
|
+
}
|
|
7590
|
+
return output + openingTag.slice(limit);
|
|
7591
|
+
}
|
|
7592
|
+
function withNonce(openingTag, nonce) {
|
|
7593
|
+
const withoutNonce = removeNonceAttribute(openingTag);
|
|
7594
|
+
return `${withoutNonce.slice(0, -1)} nonce="${escapeAttribute(nonce)}">`;
|
|
7595
|
+
}
|
|
7596
|
+
function prepareNavigationHtml(html) {
|
|
7597
|
+
if (expressionRuntimeMode() !== 'csp')
|
|
7598
|
+
return html;
|
|
7599
|
+
const activeNonce = resolveCspNonce();
|
|
7600
|
+
const lowerHtml = html.toLowerCase();
|
|
7601
|
+
let output = '';
|
|
7602
|
+
let cursor = 0;
|
|
7603
|
+
let skippedStyles = 0;
|
|
7604
|
+
while (cursor < html.length) {
|
|
7605
|
+
const tagStart = html.indexOf('<', cursor);
|
|
7606
|
+
if (tagStart === -1) {
|
|
7607
|
+
output += html.slice(cursor);
|
|
7608
|
+
break;
|
|
7609
|
+
}
|
|
7610
|
+
output += html.slice(cursor, tagStart);
|
|
7611
|
+
if (html.startsWith('<!--', tagStart)) {
|
|
7612
|
+
const commentEnd = html.indexOf('-->', tagStart + 4);
|
|
7613
|
+
const end = commentEnd === -1 ? html.length : commentEnd + 3;
|
|
7614
|
+
output += html.slice(tagStart, end);
|
|
7615
|
+
cursor = end;
|
|
7616
|
+
continue;
|
|
7617
|
+
}
|
|
7618
|
+
const tagEnd = findTagEnd(html, tagStart + 1);
|
|
7619
|
+
const openingTag = html.slice(tagStart, tagEnd);
|
|
7620
|
+
const match = /^<\s*(\/?)\s*([a-z][\w:-]*)/i.exec(openingTag);
|
|
7621
|
+
if (!match || match[1]) {
|
|
7622
|
+
output += openingTag;
|
|
7623
|
+
cursor = tagEnd;
|
|
7624
|
+
continue;
|
|
7625
|
+
}
|
|
7626
|
+
const name = match[2].toLowerCase();
|
|
7627
|
+
if (name === 'plaintext') {
|
|
7628
|
+
output += html.slice(tagStart);
|
|
7629
|
+
break;
|
|
7630
|
+
}
|
|
7631
|
+
if (name === 'style' || name === 'noscript' || RAW_TEXT_ELEMENTS.has(name)) {
|
|
7632
|
+
const closingTag = findClosingTag(html, lowerHtml, name, tagEnd);
|
|
7633
|
+
const blockEnd = closingTag?.end ?? html.length;
|
|
7634
|
+
if (name === 'noscript') {
|
|
7635
|
+
cursor = blockEnd;
|
|
7636
|
+
continue;
|
|
7637
|
+
}
|
|
7638
|
+
if (name === 'style') {
|
|
7639
|
+
if (!activeNonce) {
|
|
7640
|
+
skippedStyles += 1;
|
|
7641
|
+
cursor = blockEnd;
|
|
7642
|
+
continue;
|
|
7643
|
+
}
|
|
7644
|
+
output += withNonce(openingTag, activeNonce);
|
|
7645
|
+
output += html.slice(tagEnd, blockEnd);
|
|
7646
|
+
cursor = blockEnd;
|
|
7647
|
+
continue;
|
|
7648
|
+
}
|
|
7649
|
+
output += html.slice(tagStart, blockEnd);
|
|
7650
|
+
cursor = blockEnd;
|
|
7651
|
+
continue;
|
|
7401
7652
|
}
|
|
7653
|
+
output += openingTag;
|
|
7654
|
+
cursor = tagEnd;
|
|
7655
|
+
}
|
|
7656
|
+
if (skippedStyles > 0) {
|
|
7657
|
+
console.warn(`[GyosJS CSP] Skipped ${skippedStyles} inline MPA style${skippedStyles === 1 ? '' : 's'} because no active document nonce is configured.`);
|
|
7402
7658
|
}
|
|
7659
|
+
return output;
|
|
7403
7660
|
}
|
|
7404
7661
|
|
|
7405
7662
|
/**
|
|
@@ -7465,7 +7722,10 @@
|
|
|
7465
7722
|
root.querySelectorAll('noscript').forEach(element => element.remove());
|
|
7466
7723
|
}
|
|
7467
7724
|
function parseNavigationDocument(html) {
|
|
7468
|
-
|
|
7725
|
+
// Chromium applies the active page CSP while DOMParser creates response
|
|
7726
|
+
// styles. Reconcile their nonce before parsing to avoid transient violations;
|
|
7727
|
+
// diffNodes repeats the check before insertion into the live document.
|
|
7728
|
+
const doc = new DOMParser().parseFromString(prepareNavigationHtml(html), 'text/html');
|
|
7469
7729
|
// DOMParser disables scripting and parses noscript children as active markup.
|
|
7470
7730
|
// A boosted page runs with scripting enabled, so those fallbacks must stay inert.
|
|
7471
7731
|
stripInertFallbackContent(doc);
|
|
@@ -8237,7 +8497,7 @@
|
|
|
8237
8497
|
});
|
|
8238
8498
|
}
|
|
8239
8499
|
|
|
8240
|
-
//
|
|
8500
|
+
// Shared public surface used by the standard and CSP entries.
|
|
8241
8501
|
// Default export remains for convenience (no side effects here)
|
|
8242
8502
|
const Gyos = {
|
|
8243
8503
|
scope,
|
|
@@ -8300,9 +8560,12 @@
|
|
|
8300
8560
|
onAfterNavigate,
|
|
8301
8561
|
portalCreate,
|
|
8302
8562
|
portalDestroy,
|
|
8303
|
-
|
|
8563
|
+
setCspNonce,
|
|
8564
|
+
version: '0.3.1'
|
|
8304
8565
|
};
|
|
8305
8566
|
|
|
8567
|
+
setExpressionRuntime(standardExpressionRuntime);
|
|
8568
|
+
|
|
8306
8569
|
exports.applyDirective = applyDirective;
|
|
8307
8570
|
exports.applyTransitionStyles = applyTransitionStyles;
|
|
8308
8571
|
exports.batch = batch;
|
|
@@ -8343,6 +8606,7 @@
|
|
|
8343
8606
|
exports.registerTransition = registerTransition;
|
|
8344
8607
|
exports.removeStore = removeStore;
|
|
8345
8608
|
exports.scope = scope;
|
|
8609
|
+
exports.setCspNonce = setCspNonce;
|
|
8346
8610
|
exports.shallow = shallow;
|
|
8347
8611
|
exports.signal = signal;
|
|
8348
8612
|
exports.startRouter = startRouter;
|