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.auto.esm.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
|
*/
|
|
@@ -1236,6 +1236,20 @@ pipe('reverse', (value) => {
|
|
|
1236
1236
|
return value;
|
|
1237
1237
|
});
|
|
1238
1238
|
|
|
1239
|
+
let activeRuntime;
|
|
1240
|
+
function setExpressionRuntime(runtime) {
|
|
1241
|
+
activeRuntime = runtime;
|
|
1242
|
+
}
|
|
1243
|
+
function expressionRuntime() {
|
|
1244
|
+
if (!activeRuntime) {
|
|
1245
|
+
throw new Error('[GyosJS] Expression runtime is not configured. Import GyosJS from a public entry point.');
|
|
1246
|
+
}
|
|
1247
|
+
return activeRuntime;
|
|
1248
|
+
}
|
|
1249
|
+
function expressionRuntimeMode() {
|
|
1250
|
+
return activeRuntime?.mode ?? 'standard';
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1239
1253
|
/**
|
|
1240
1254
|
* Expression Evaluation & Interpolation
|
|
1241
1255
|
* Handles template expressions, pipes, and string interpolation
|
|
@@ -1337,24 +1351,7 @@ function evaluateSimpleExpression(expr, scope) {
|
|
|
1337
1351
|
if (!isNaN(Number(expr))) {
|
|
1338
1352
|
return Number(expr);
|
|
1339
1353
|
}
|
|
1340
|
-
|
|
1341
|
-
// This allows getters and signals to be tracked properly
|
|
1342
|
-
try {
|
|
1343
|
-
const method = scope[expr];
|
|
1344
|
-
if (typeof method === "function") {
|
|
1345
|
-
return method.call(scope);
|
|
1346
|
-
}
|
|
1347
|
-
else {
|
|
1348
|
-
// Wrap expression in try-catch to handle null/undefined access gracefully
|
|
1349
|
-
const safeExpr = `try { return ${expr} } catch(e) { return undefined }`;
|
|
1350
|
-
const fn = new Function("$scope", `with($scope) { ${safeExpr} }`);
|
|
1351
|
-
return fn(scope);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
catch (e) {
|
|
1355
|
-
console.error("[GyosJS] Error evaluating expression:", expr, e);
|
|
1356
|
-
return undefined;
|
|
1357
|
-
}
|
|
1354
|
+
return expressionRuntime().evaluate(expr, scope);
|
|
1358
1355
|
}
|
|
1359
1356
|
|
|
1360
1357
|
/**
|
|
@@ -2192,6 +2189,8 @@ function getTransitionConfig(source) {
|
|
|
2192
2189
|
function applyTransitionStyles() {
|
|
2193
2190
|
if (typeof document === 'undefined')
|
|
2194
2191
|
return;
|
|
2192
|
+
if (expressionRuntimeMode() === 'csp')
|
|
2193
|
+
return;
|
|
2195
2194
|
const styleId = 'gyos-transitions';
|
|
2196
2195
|
if (document.getElementById(styleId))
|
|
2197
2196
|
return;
|
|
@@ -2263,32 +2262,24 @@ function applyTransitionStyles() {
|
|
|
2263
2262
|
* Handles:
|
|
2264
2263
|
* 1. Literal string: "fade" or "slide-down"
|
|
2265
2264
|
* 2. Expression with {}: "{transition}"
|
|
2266
|
-
* 3.
|
|
2265
|
+
* 3. Quoted literal kept for backwards compatibility: "'fade'"
|
|
2267
2266
|
*
|
|
2268
2267
|
* @param attrValue - The g-transition attribute value
|
|
2269
2268
|
* @param scope - Current scope for expression evaluation
|
|
2270
2269
|
* @returns The transition name (string)
|
|
2271
2270
|
*/
|
|
2272
2271
|
function parseTransitionName(attrValue, scope) {
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
}
|
|
2272
|
+
const value = attrValue.trim();
|
|
2273
|
+
const expression = /^\{([\s\S]+)\}$/.exec(value);
|
|
2274
|
+
if (expression) {
|
|
2275
|
+
const evaluated = evaluateExpression(expression[1].trim(), scope);
|
|
2276
|
+
return evaluated == null ? '' : String(evaluated);
|
|
2279
2277
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
const evaluated = evaluateExpression(attrValue, scope);
|
|
2284
|
-
if (evaluated !== undefined && evaluated !== null) {
|
|
2285
|
-
return evaluated;
|
|
2286
|
-
}
|
|
2287
|
-
}
|
|
2288
|
-
catch (e) {
|
|
2289
|
-
// If evaluation fails, use value as literal string (built-in transition name)
|
|
2278
|
+
if (value.length >= 2 && ((value.startsWith("'") && value.endsWith("'"))
|
|
2279
|
+
|| (value.startsWith('"') && value.endsWith('"')))) {
|
|
2280
|
+
return value.slice(1, -1);
|
|
2290
2281
|
}
|
|
2291
|
-
return
|
|
2282
|
+
return value;
|
|
2292
2283
|
}
|
|
2293
2284
|
/**
|
|
2294
2285
|
* Parse transition config from element's g-transition attribute
|
|
@@ -3679,24 +3670,7 @@ function executeHandler(handler, scope, e, modifiers) {
|
|
|
3679
3670
|
if (modifiers.includes('stop'))
|
|
3680
3671
|
e.stopPropagation();
|
|
3681
3672
|
try {
|
|
3682
|
-
|
|
3683
|
-
if (isMethodCall) {
|
|
3684
|
-
// Method call with args: "doSomething()" or "method(arg1, arg2)"
|
|
3685
|
-
const fn = new Function('$event', `with(this) { ${handler} }`);
|
|
3686
|
-
fn.call(scope, e);
|
|
3687
|
-
}
|
|
3688
|
-
else {
|
|
3689
|
-
// Check if it's a method name or expression
|
|
3690
|
-
const method = scope[handler];
|
|
3691
|
-
if (typeof method === 'function') {
|
|
3692
|
-
method.call(scope, e);
|
|
3693
|
-
}
|
|
3694
|
-
else {
|
|
3695
|
-
// Expression like "count++", "count = 0"
|
|
3696
|
-
const fn = new Function('$event', `with(this) { ${handler} }`);
|
|
3697
|
-
fn.call(scope, e);
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3673
|
+
expressionRuntime().execute(handler, scope, e);
|
|
3700
3674
|
}
|
|
3701
3675
|
catch (err) {
|
|
3702
3676
|
console.error('[GyosJS] Error in event handler:', err);
|
|
@@ -5672,10 +5646,7 @@ function parseInlineScope(scopeStr) {
|
|
|
5672
5646
|
if (!trimmed.startsWith('{')) {
|
|
5673
5647
|
return undefined; // Not an inline definition
|
|
5674
5648
|
}
|
|
5675
|
-
|
|
5676
|
-
// This allows methods and complex expressions
|
|
5677
|
-
const fn = new Function(`return (${trimmed})`);
|
|
5678
|
-
const definition = fn();
|
|
5649
|
+
const definition = expressionRuntime().parseScope(trimmed);
|
|
5679
5650
|
DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
|
|
5680
5651
|
return definition;
|
|
5681
5652
|
}
|
|
@@ -5739,10 +5710,10 @@ function parseAutoScope(el) {
|
|
|
5739
5710
|
if (forbidden.some(f => expr.includes(f))) {
|
|
5740
5711
|
DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
|
|
5741
5712
|
}
|
|
5742
|
-
const args = key.split(':').slice(1)
|
|
5713
|
+
const args = key.split(':').slice(1);
|
|
5743
5714
|
const propName = key.split(':')[0];
|
|
5744
5715
|
try {
|
|
5745
|
-
definition[propName] =
|
|
5716
|
+
definition[propName] = expressionRuntime().createMethod(args, expr);
|
|
5746
5717
|
removeAttrs.push(attr.name);
|
|
5747
5718
|
}
|
|
5748
5719
|
catch (_) {
|
|
@@ -6722,7 +6693,7 @@ function createTargetSpinner() {
|
|
|
6722
6693
|
</div>
|
|
6723
6694
|
`;
|
|
6724
6695
|
// Inject styles if not already present
|
|
6725
|
-
if (!document.getElementById('gyos-target-spinner-styles')) {
|
|
6696
|
+
if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
|
|
6726
6697
|
const style = document.createElement('style');
|
|
6727
6698
|
style.id = 'gyos-target-spinner-styles';
|
|
6728
6699
|
style.textContent = `
|
|
@@ -6776,6 +6747,16 @@ function hideTargetSpinner(spinner) {
|
|
|
6776
6747
|
}
|
|
6777
6748
|
}
|
|
6778
6749
|
|
|
6750
|
+
let nonceSource;
|
|
6751
|
+
/** Configure the active document nonce used for scripts and styles during MPA navigation. */
|
|
6752
|
+
function setCspNonce(source) {
|
|
6753
|
+
nonceSource = source;
|
|
6754
|
+
}
|
|
6755
|
+
function resolveCspNonce() {
|
|
6756
|
+
const value = typeof nonceSource === 'function' ? nonceSource() : nonceSource;
|
|
6757
|
+
return value || undefined;
|
|
6758
|
+
}
|
|
6759
|
+
|
|
6779
6760
|
// Cache executed scripts to prevent duplicate execution
|
|
6780
6761
|
const executedScripts = new Set();
|
|
6781
6762
|
/**
|
|
@@ -6876,6 +6857,12 @@ async function executeScript(old, signal) {
|
|
|
6876
6857
|
old.remove();
|
|
6877
6858
|
return;
|
|
6878
6859
|
}
|
|
6860
|
+
const activeNonce = resolveCspNonce();
|
|
6861
|
+
if (expressionRuntimeMode() === 'csp' && !old.src && !activeNonce) {
|
|
6862
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
6863
|
+
old.textContent = '';
|
|
6864
|
+
return;
|
|
6865
|
+
}
|
|
6879
6866
|
const executionKey = getScriptExecutionKey(old);
|
|
6880
6867
|
// Check if script should execute
|
|
6881
6868
|
if (!shouldExecuteScript(old)) {
|
|
@@ -6885,6 +6872,10 @@ async function executeScript(old, signal) {
|
|
|
6885
6872
|
}
|
|
6886
6873
|
const newScript = document.createElement('script');
|
|
6887
6874
|
Array.from(old.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
|
|
6875
|
+
if (expressionRuntimeMode() === 'csp')
|
|
6876
|
+
newScript.removeAttribute('nonce');
|
|
6877
|
+
if (activeNonce)
|
|
6878
|
+
newScript.setAttribute('nonce', activeNonce);
|
|
6888
6879
|
newScript.textContent = old.hasAttribute('g-script-wrap')
|
|
6889
6880
|
? wrapScriptExecution(old.textContent)
|
|
6890
6881
|
: old.textContent;
|
|
@@ -7329,9 +7320,33 @@ function handleScroll(url, trigger, savedScroll) {
|
|
|
7329
7320
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
7330
7321
|
}
|
|
7331
7322
|
|
|
7332
|
-
function
|
|
7333
|
-
return
|
|
7334
|
-
|
|
7323
|
+
function isNonceMeta(el) {
|
|
7324
|
+
return el.tagName === 'META' && el.getAttribute('name')?.toLowerCase() === 'csp-nonce';
|
|
7325
|
+
}
|
|
7326
|
+
function isStylesheetLink(el) {
|
|
7327
|
+
return el.tagName === 'LINK'
|
|
7328
|
+
&& (el.getAttribute('rel') || '').toLowerCase().split(/\s+/).includes('stylesheet');
|
|
7329
|
+
}
|
|
7330
|
+
function usesCspNonce(el) {
|
|
7331
|
+
return el.tagName === 'SCRIPT' || el.tagName === 'STYLE' || isStylesheetLink(el);
|
|
7332
|
+
}
|
|
7333
|
+
function serializeAttributes(el, context) {
|
|
7334
|
+
const attributes = new Map();
|
|
7335
|
+
Array.from(el.attributes).forEach(attr => {
|
|
7336
|
+
if (context.csp && usesCspNonce(el) && attr.name.toLowerCase() === 'nonce')
|
|
7337
|
+
return;
|
|
7338
|
+
if (context.csp && isNonceMeta(el) && attr.name.toLowerCase() === 'content')
|
|
7339
|
+
return;
|
|
7340
|
+
attributes.set(attr.name, attr.value);
|
|
7341
|
+
});
|
|
7342
|
+
if (context.csp && usesCspNonce(el) && context.activeNonce) {
|
|
7343
|
+
attributes.set('nonce', context.activeNonce);
|
|
7344
|
+
}
|
|
7345
|
+
if (context.csp && isNonceMeta(el) && context.activeNonce) {
|
|
7346
|
+
attributes.set('content', context.activeNonce);
|
|
7347
|
+
}
|
|
7348
|
+
return Array.from(attributes)
|
|
7349
|
+
.map(([name, value]) => `${name}=${value}`)
|
|
7335
7350
|
.sort()
|
|
7336
7351
|
.join('|');
|
|
7337
7352
|
}
|
|
@@ -7342,23 +7357,61 @@ function hashContent(content) {
|
|
|
7342
7357
|
}
|
|
7343
7358
|
return String(hash);
|
|
7344
7359
|
}
|
|
7345
|
-
function elementKey(el) {
|
|
7360
|
+
function elementKey(el, context) {
|
|
7346
7361
|
const tag = el.tagName.toLowerCase();
|
|
7347
7362
|
const content = tag === 'script' || tag === 'style' ? hashContent(el.textContent || '') : '';
|
|
7348
|
-
return `${tag}|${serializeAttributes(el)}|${content}`;
|
|
7363
|
+
return `${tag}|${serializeAttributes(el, context)}|${content}`;
|
|
7349
7364
|
}
|
|
7350
|
-
function keyedNodes(nodes) {
|
|
7365
|
+
function keyedNodes(nodes, context) {
|
|
7351
7366
|
const occurrences = new Map();
|
|
7352
7367
|
return nodes.map(node => {
|
|
7353
|
-
const baseKey = elementKey(node);
|
|
7368
|
+
const baseKey = elementKey(node, context);
|
|
7354
7369
|
const occurrence = occurrences.get(baseKey) || 0;
|
|
7355
7370
|
occurrences.set(baseKey, occurrence + 1);
|
|
7356
7371
|
return { key: `${baseKey}|${occurrence}`, node };
|
|
7357
7372
|
});
|
|
7358
7373
|
}
|
|
7374
|
+
function canInsertNode(node, context) {
|
|
7375
|
+
if (!context.csp)
|
|
7376
|
+
return true;
|
|
7377
|
+
if (isNonceMeta(node))
|
|
7378
|
+
return Boolean(context.activeNonce);
|
|
7379
|
+
if (node.tagName === 'STYLE')
|
|
7380
|
+
return Boolean(context.activeNonce);
|
|
7381
|
+
if (node.tagName === 'SCRIPT' && !node.hasAttribute('src'))
|
|
7382
|
+
return Boolean(context.activeNonce);
|
|
7383
|
+
return true;
|
|
7384
|
+
}
|
|
7385
|
+
function reconcileCspAttributes(node, context) {
|
|
7386
|
+
if (!context.csp)
|
|
7387
|
+
return;
|
|
7388
|
+
if (isNonceMeta(node)) {
|
|
7389
|
+
if (context.activeNonce)
|
|
7390
|
+
node.setAttribute('content', context.activeNonce);
|
|
7391
|
+
return;
|
|
7392
|
+
}
|
|
7393
|
+
if (!usesCspNonce(node))
|
|
7394
|
+
return;
|
|
7395
|
+
node.removeAttribute('nonce');
|
|
7396
|
+
if (context.activeNonce)
|
|
7397
|
+
node.setAttribute('nonce', context.activeNonce);
|
|
7398
|
+
}
|
|
7399
|
+
function warnSkippedNode(node) {
|
|
7400
|
+
if (node.tagName === 'STYLE') {
|
|
7401
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA style because no active document nonce is configured.');
|
|
7402
|
+
}
|
|
7403
|
+
else if (node.tagName === 'SCRIPT' && !node.hasAttribute('src')) {
|
|
7404
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
7405
|
+
}
|
|
7406
|
+
}
|
|
7359
7407
|
async function diffNodes(currentNodes, nextNodes, container = document.head, signal) {
|
|
7360
|
-
const
|
|
7361
|
-
const
|
|
7408
|
+
const csp = expressionRuntimeMode() === 'csp';
|
|
7409
|
+
const context = {
|
|
7410
|
+
csp,
|
|
7411
|
+
activeNonce: csp ? resolveCspNonce() : undefined
|
|
7412
|
+
};
|
|
7413
|
+
const current = keyedNodes(currentNodes, context);
|
|
7414
|
+
const next = keyedNodes(nextNodes, context);
|
|
7362
7415
|
const currentKeys = new Set(current.map(item => item.key));
|
|
7363
7416
|
const nextKeys = new Set(next.map(item => item.key));
|
|
7364
7417
|
// Remove nodes that are not in the new head
|
|
@@ -7372,6 +7425,20 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7372
7425
|
if (signal?.aborted)
|
|
7373
7426
|
return;
|
|
7374
7427
|
if (!currentKeys.has(key)) {
|
|
7428
|
+
if (!canInsertNode(node, context)) {
|
|
7429
|
+
warnSkippedNode(node);
|
|
7430
|
+
continue;
|
|
7431
|
+
}
|
|
7432
|
+
if (node.tagName === 'STYLE') {
|
|
7433
|
+
const style = document.createElement('style');
|
|
7434
|
+
Array.from(node.attributes).forEach(attr => style.setAttribute(attr.name, attr.value));
|
|
7435
|
+
reconcileCspAttributes(style, context);
|
|
7436
|
+
// CSP checks inline styles as their CSS text is attached. Set the active
|
|
7437
|
+
// nonce first so a response nonce never produces a transient violation.
|
|
7438
|
+
style.textContent = node.textContent || '';
|
|
7439
|
+
container.appendChild(style);
|
|
7440
|
+
continue;
|
|
7441
|
+
}
|
|
7375
7442
|
if (node.tagName === 'SCRIPT') {
|
|
7376
7443
|
const originalScript = node;
|
|
7377
7444
|
const executionKey = getScriptExecutionKey(originalScript);
|
|
@@ -7382,6 +7449,7 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7382
7449
|
}
|
|
7383
7450
|
const script = document.createElement('script');
|
|
7384
7451
|
Array.from(node.attributes).forEach(attr => script.setAttribute(attr.name, attr.value));
|
|
7452
|
+
reconcileCspAttributes(script, context);
|
|
7385
7453
|
script.textContent = node.hasAttribute('g-script-wrap')
|
|
7386
7454
|
? wrapScriptExecution(node.textContent || '')
|
|
7387
7455
|
: node.textContent || '';
|
|
@@ -7391,11 +7459,168 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7391
7459
|
await completion;
|
|
7392
7460
|
continue;
|
|
7393
7461
|
}
|
|
7394
|
-
|
|
7462
|
+
const imported = document.importNode(node, true);
|
|
7463
|
+
reconcileCspAttributes(imported, context);
|
|
7464
|
+
container.appendChild(imported);
|
|
7395
7465
|
}
|
|
7396
7466
|
}
|
|
7397
7467
|
}
|
|
7398
7468
|
|
|
7469
|
+
const RAW_TEXT_ELEMENTS = new Set(['iframe', 'noembed', 'noframes', 'plaintext', 'script', 'textarea', 'title', 'xmp']);
|
|
7470
|
+
function escapeAttribute(value) {
|
|
7471
|
+
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
7472
|
+
}
|
|
7473
|
+
function findTagEnd(html, start) {
|
|
7474
|
+
let quote = '';
|
|
7475
|
+
for (let index = start; index < html.length; index += 1) {
|
|
7476
|
+
const character = html[index];
|
|
7477
|
+
if (quote) {
|
|
7478
|
+
if (character === quote)
|
|
7479
|
+
quote = '';
|
|
7480
|
+
continue;
|
|
7481
|
+
}
|
|
7482
|
+
if (character === '"' || character === "'") {
|
|
7483
|
+
quote = character;
|
|
7484
|
+
continue;
|
|
7485
|
+
}
|
|
7486
|
+
if (character === '>')
|
|
7487
|
+
return index + 1;
|
|
7488
|
+
}
|
|
7489
|
+
return html.length;
|
|
7490
|
+
}
|
|
7491
|
+
function findClosingTag(html, lowerHtml, name, start) {
|
|
7492
|
+
const needle = `</${name}`;
|
|
7493
|
+
let position = lowerHtml.indexOf(needle, start);
|
|
7494
|
+
while (position !== -1) {
|
|
7495
|
+
const boundary = lowerHtml[position + needle.length];
|
|
7496
|
+
if (boundary === '>' || /\s/.test(boundary || '')) {
|
|
7497
|
+
return {
|
|
7498
|
+
start: position,
|
|
7499
|
+
end: findTagEnd(html, position + needle.length)
|
|
7500
|
+
};
|
|
7501
|
+
}
|
|
7502
|
+
position = lowerHtml.indexOf(needle, position + needle.length);
|
|
7503
|
+
}
|
|
7504
|
+
return null;
|
|
7505
|
+
}
|
|
7506
|
+
function removeNonceAttribute(openingTag) {
|
|
7507
|
+
const prefix = /^<\s*style\b/i.exec(openingTag);
|
|
7508
|
+
if (!prefix)
|
|
7509
|
+
return openingTag;
|
|
7510
|
+
let output = prefix[0];
|
|
7511
|
+
let cursor = prefix[0].length;
|
|
7512
|
+
const limit = openingTag.length - 1;
|
|
7513
|
+
while (cursor < limit) {
|
|
7514
|
+
const attributeStart = cursor;
|
|
7515
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7516
|
+
cursor += 1;
|
|
7517
|
+
if (cursor >= limit || openingTag[cursor] === '>') {
|
|
7518
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7519
|
+
break;
|
|
7520
|
+
}
|
|
7521
|
+
const nameStart = cursor;
|
|
7522
|
+
while (cursor < limit && !/[\s=/>]/.test(openingTag[cursor]))
|
|
7523
|
+
cursor += 1;
|
|
7524
|
+
if (cursor === nameStart) {
|
|
7525
|
+
output += openingTag.slice(attributeStart, cursor + 1);
|
|
7526
|
+
cursor += 1;
|
|
7527
|
+
continue;
|
|
7528
|
+
}
|
|
7529
|
+
const name = openingTag.slice(nameStart, cursor).toLowerCase();
|
|
7530
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7531
|
+
cursor += 1;
|
|
7532
|
+
if (openingTag[cursor] === '=') {
|
|
7533
|
+
cursor += 1;
|
|
7534
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7535
|
+
cursor += 1;
|
|
7536
|
+
const quote = openingTag[cursor] === '"' || openingTag[cursor] === "'" ? openingTag[cursor] : '';
|
|
7537
|
+
if (quote) {
|
|
7538
|
+
cursor += 1;
|
|
7539
|
+
while (cursor < limit && openingTag[cursor] !== quote)
|
|
7540
|
+
cursor += 1;
|
|
7541
|
+
if (openingTag[cursor] === quote)
|
|
7542
|
+
cursor += 1;
|
|
7543
|
+
}
|
|
7544
|
+
else {
|
|
7545
|
+
while (cursor < limit && !/[\s>]/.test(openingTag[cursor]))
|
|
7546
|
+
cursor += 1;
|
|
7547
|
+
}
|
|
7548
|
+
}
|
|
7549
|
+
if (name !== 'nonce')
|
|
7550
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7551
|
+
}
|
|
7552
|
+
return output + openingTag.slice(limit);
|
|
7553
|
+
}
|
|
7554
|
+
function withNonce(openingTag, nonce) {
|
|
7555
|
+
const withoutNonce = removeNonceAttribute(openingTag);
|
|
7556
|
+
return `${withoutNonce.slice(0, -1)} nonce="${escapeAttribute(nonce)}">`;
|
|
7557
|
+
}
|
|
7558
|
+
function prepareNavigationHtml(html) {
|
|
7559
|
+
if (expressionRuntimeMode() !== 'csp')
|
|
7560
|
+
return html;
|
|
7561
|
+
const activeNonce = resolveCspNonce();
|
|
7562
|
+
const lowerHtml = html.toLowerCase();
|
|
7563
|
+
let output = '';
|
|
7564
|
+
let cursor = 0;
|
|
7565
|
+
let skippedStyles = 0;
|
|
7566
|
+
while (cursor < html.length) {
|
|
7567
|
+
const tagStart = html.indexOf('<', cursor);
|
|
7568
|
+
if (tagStart === -1) {
|
|
7569
|
+
output += html.slice(cursor);
|
|
7570
|
+
break;
|
|
7571
|
+
}
|
|
7572
|
+
output += html.slice(cursor, tagStart);
|
|
7573
|
+
if (html.startsWith('<!--', tagStart)) {
|
|
7574
|
+
const commentEnd = html.indexOf('-->', tagStart + 4);
|
|
7575
|
+
const end = commentEnd === -1 ? html.length : commentEnd + 3;
|
|
7576
|
+
output += html.slice(tagStart, end);
|
|
7577
|
+
cursor = end;
|
|
7578
|
+
continue;
|
|
7579
|
+
}
|
|
7580
|
+
const tagEnd = findTagEnd(html, tagStart + 1);
|
|
7581
|
+
const openingTag = html.slice(tagStart, tagEnd);
|
|
7582
|
+
const match = /^<\s*(\/?)\s*([a-z][\w:-]*)/i.exec(openingTag);
|
|
7583
|
+
if (!match || match[1]) {
|
|
7584
|
+
output += openingTag;
|
|
7585
|
+
cursor = tagEnd;
|
|
7586
|
+
continue;
|
|
7587
|
+
}
|
|
7588
|
+
const name = match[2].toLowerCase();
|
|
7589
|
+
if (name === 'plaintext') {
|
|
7590
|
+
output += html.slice(tagStart);
|
|
7591
|
+
break;
|
|
7592
|
+
}
|
|
7593
|
+
if (name === 'style' || name === 'noscript' || RAW_TEXT_ELEMENTS.has(name)) {
|
|
7594
|
+
const closingTag = findClosingTag(html, lowerHtml, name, tagEnd);
|
|
7595
|
+
const blockEnd = closingTag?.end ?? html.length;
|
|
7596
|
+
if (name === 'noscript') {
|
|
7597
|
+
cursor = blockEnd;
|
|
7598
|
+
continue;
|
|
7599
|
+
}
|
|
7600
|
+
if (name === 'style') {
|
|
7601
|
+
if (!activeNonce) {
|
|
7602
|
+
skippedStyles += 1;
|
|
7603
|
+
cursor = blockEnd;
|
|
7604
|
+
continue;
|
|
7605
|
+
}
|
|
7606
|
+
output += withNonce(openingTag, activeNonce);
|
|
7607
|
+
output += html.slice(tagEnd, blockEnd);
|
|
7608
|
+
cursor = blockEnd;
|
|
7609
|
+
continue;
|
|
7610
|
+
}
|
|
7611
|
+
output += html.slice(tagStart, blockEnd);
|
|
7612
|
+
cursor = blockEnd;
|
|
7613
|
+
continue;
|
|
7614
|
+
}
|
|
7615
|
+
output += openingTag;
|
|
7616
|
+
cursor = tagEnd;
|
|
7617
|
+
}
|
|
7618
|
+
if (skippedStyles > 0) {
|
|
7619
|
+
console.warn(`[GyosJS CSP] Skipped ${skippedStyles} inline MPA style${skippedStyles === 1 ? '' : 's'} because no active document nonce is configured.`);
|
|
7620
|
+
}
|
|
7621
|
+
return output;
|
|
7622
|
+
}
|
|
7623
|
+
|
|
7399
7624
|
/**
|
|
7400
7625
|
* GyosJs Router v0
|
|
7401
7626
|
* MPA boost navigation inspired by Turbo Drive.
|
|
@@ -7459,7 +7684,10 @@ function stripInertFallbackContent(root) {
|
|
|
7459
7684
|
root.querySelectorAll('noscript').forEach(element => element.remove());
|
|
7460
7685
|
}
|
|
7461
7686
|
function parseNavigationDocument(html) {
|
|
7462
|
-
|
|
7687
|
+
// Chromium applies the active page CSP while DOMParser creates response
|
|
7688
|
+
// styles. Reconcile their nonce before parsing to avoid transient violations;
|
|
7689
|
+
// diffNodes repeats the check before insertion into the live document.
|
|
7690
|
+
const doc = new DOMParser().parseFromString(prepareNavigationHtml(html), 'text/html');
|
|
7463
7691
|
// DOMParser disables scripting and parses noscript children as active markup.
|
|
7464
7692
|
// A boosted page runs with scripting enabled, so those fallbacks must stay inert.
|
|
7465
7693
|
stripInertFallbackContent(doc);
|
|
@@ -8231,7 +8459,7 @@ function onPopState(event) {
|
|
|
8231
8459
|
});
|
|
8232
8460
|
}
|
|
8233
8461
|
|
|
8234
|
-
//
|
|
8462
|
+
// Shared public surface used by the standard and CSP entries.
|
|
8235
8463
|
// Default export remains for convenience (no side effects here)
|
|
8236
8464
|
const Gyos = {
|
|
8237
8465
|
scope,
|
|
@@ -8294,10 +8522,44 @@ const Gyos = {
|
|
|
8294
8522
|
onAfterNavigate,
|
|
8295
8523
|
portalCreate,
|
|
8296
8524
|
portalDestroy,
|
|
8297
|
-
|
|
8525
|
+
setCspNonce,
|
|
8526
|
+
version: '0.3.1'
|
|
8527
|
+
};
|
|
8528
|
+
|
|
8529
|
+
const standardExpressionRuntime = {
|
|
8530
|
+
mode: 'standard',
|
|
8531
|
+
evaluate(expression, scope) {
|
|
8532
|
+
const method = scope?.[expression];
|
|
8533
|
+
if (typeof method === 'function')
|
|
8534
|
+
return method.call(scope);
|
|
8535
|
+
try {
|
|
8536
|
+
const safeExpression = `try { return ${expression} } catch(e) { return undefined }`;
|
|
8537
|
+
const evaluate = new Function('$scope', `with($scope) { ${safeExpression} }`);
|
|
8538
|
+
return evaluate(scope);
|
|
8539
|
+
}
|
|
8540
|
+
catch (error) {
|
|
8541
|
+
console.error('[GyosJS] Error evaluating expression:', expression, error);
|
|
8542
|
+
return undefined;
|
|
8543
|
+
}
|
|
8544
|
+
},
|
|
8545
|
+
execute(expression, scope, event) {
|
|
8546
|
+
const method = scope?.[expression];
|
|
8547
|
+
if (typeof method === 'function')
|
|
8548
|
+
return method.call(scope, event);
|
|
8549
|
+
const execute = new Function('$event', `with(this) { ${expression} }`);
|
|
8550
|
+
return execute.call(scope, event);
|
|
8551
|
+
},
|
|
8552
|
+
parseScope(expression) {
|
|
8553
|
+
const parse = new Function(`return (${expression})`);
|
|
8554
|
+
return parse();
|
|
8555
|
+
},
|
|
8556
|
+
createMethod(parameters, body) {
|
|
8557
|
+
return new Function(parameters.join(', '), `with(this) { ${body} }`);
|
|
8558
|
+
}
|
|
8298
8559
|
};
|
|
8299
8560
|
|
|
8300
8561
|
var _a, _b, _c;
|
|
8562
|
+
setExpressionRuntime(standardExpressionRuntime);
|
|
8301
8563
|
/**
|
|
8302
8564
|
* Browser auto-init entry.
|
|
8303
8565
|
* Attaches Gyos to window, sets debug defaults, injects transitions, starts router,
|