gyosjs 0.3.0 → 0.3.2
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/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/gyos.auto.esm.js +279 -32
- package/dist/gyos.auto.esm.js.map +1 -1
- package/dist/gyos.auto.js +279 -32
- package/dist/gyos.auto.js.map +1 -1
- package/dist/gyos.auto.min.js +2 -2
- package/dist/gyos.csp.auto.esm.js +375 -208
- package/dist/gyos.csp.auto.esm.js.map +1 -1
- package/dist/gyos.csp.auto.js +375 -208
- package/dist/gyos.csp.auto.js.map +1 -1
- package/dist/gyos.csp.auto.min.js +2 -2
- package/dist/gyos.csp.esm.js +375 -208
- package/dist/gyos.csp.esm.js.map +1 -1
- package/dist/gyos.csp.js +375 -208
- package/dist/gyos.csp.js.map +1 -1
- package/dist/gyos.csp.min.js +2 -2
- package/dist/gyos.esm.js +279 -32
- package/dist/gyos.esm.js.map +1 -1
- package/dist/gyos.js +279 -32
- package/dist/gyos.js.map +1 -1
- package/dist/gyos.min.js +2 -2
- package/dist/runtime/csp-nonce.d.ts +1 -1
- package/dist/runtime/csp-nonce.d.ts.map +1 -1
- package/dist/template/process.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/package.json +1 -1
- package/dist/runtime/install-csp.d.ts +0 -2
- package/dist/runtime/install-csp.d.ts.map +0 -1
- package/dist/runtime/install-standard.d.ts +0 -2
- package/dist/runtime/install-standard.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csp-html.d.ts","sourceRoot":"","sources":["../../../src/core/router/csp-html.ts"],"names":[],"mappings":"AA6FA,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA0E1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff-nodes.d.ts","sourceRoot":"","sources":["../../../src/core/router/diff-nodes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diff-nodes.d.ts","sourceRoot":"","sources":["../../../src/core/router/diff-nodes.ts"],"names":[],"mappings":"AA4FA,wBAAsB,SAAS,CAC9B,YAAY,EAAE,OAAO,EAAE,EACvB,SAAS,EAAE,OAAO,EAAE,EACpB,SAAS,GAAE,WAA2B,EACtC,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC,CA+Df"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/core/router/router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/core/router/router.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,aAAa;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,UAAU,eAAe;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,IAAI,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,WAAW,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAgBD,UAAU,QAAQ;IACjB,IAAI,EAAE,MAAM,CAAC;CACb;AAiCD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAEtE;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAErE;AAED,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI,CA2BzD;AA6DD,iBAAS,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAarD;AAoRD,iBAAe,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAoU5D;AAiKD,iBAAS,gBAAgB,IAAI,IAAI,CAsBhC;AAGD,eAAO,MAAM,YAAY;;;;;;CAMxB,CAAC"}
|
package/dist/gyos.auto.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.3.
|
|
2
|
+
* GyosJS v0.3.2
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -2262,32 +2262,24 @@ function applyTransitionStyles() {
|
|
|
2262
2262
|
* Handles:
|
|
2263
2263
|
* 1. Literal string: "fade" or "slide-down"
|
|
2264
2264
|
* 2. Expression with {}: "{transition}"
|
|
2265
|
-
* 3.
|
|
2265
|
+
* 3. Quoted literal kept for backwards compatibility: "'fade'"
|
|
2266
2266
|
*
|
|
2267
2267
|
* @param attrValue - The g-transition attribute value
|
|
2268
2268
|
* @param scope - Current scope for expression evaluation
|
|
2269
2269
|
* @returns The transition name (string)
|
|
2270
2270
|
*/
|
|
2271
2271
|
function parseTransitionName(attrValue, scope) {
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
// Try to evaluate as expression first (variable name)
|
|
2280
|
-
// If it fails or returns undefined, use as literal string
|
|
2281
|
-
try {
|
|
2282
|
-
const evaluated = evaluateExpression(attrValue, scope);
|
|
2283
|
-
if (evaluated !== undefined && evaluated !== null) {
|
|
2284
|
-
return evaluated;
|
|
2285
|
-
}
|
|
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);
|
|
2286
2277
|
}
|
|
2287
|
-
|
|
2288
|
-
|
|
2278
|
+
if (value.length >= 2 && ((value.startsWith("'") && value.endsWith("'"))
|
|
2279
|
+
|| (value.startsWith('"') && value.endsWith('"')))) {
|
|
2280
|
+
return value.slice(1, -1);
|
|
2289
2281
|
}
|
|
2290
|
-
return
|
|
2282
|
+
return value;
|
|
2291
2283
|
}
|
|
2292
2284
|
/**
|
|
2293
2285
|
* Parse transition config from element's g-transition attribute
|
|
@@ -5191,6 +5183,10 @@ function processStructuralDirectives(elements, scope) {
|
|
|
5191
5183
|
const structuralElements = [];
|
|
5192
5184
|
const root = elements[0];
|
|
5193
5185
|
elements.forEach(el => {
|
|
5186
|
+
// Await branches are detached and parsed only after their alias scope exists.
|
|
5187
|
+
// Do not evaluate nested structural expressions during the parent scan.
|
|
5188
|
+
if (isAwaitBranchDescendant(el))
|
|
5189
|
+
return;
|
|
5194
5190
|
const hasIf = el.hasAttribute('*if');
|
|
5195
5191
|
const hasFor = el.hasAttribute('*for');
|
|
5196
5192
|
const hasSwitch = el.hasAttribute('*switch');
|
|
@@ -5235,6 +5231,20 @@ function processStructuralDirectives(elements, scope) {
|
|
|
5235
5231
|
}
|
|
5236
5232
|
});
|
|
5237
5233
|
}
|
|
5234
|
+
function isAwaitBranchDescendant(element) {
|
|
5235
|
+
let child = element;
|
|
5236
|
+
let parent = element.parentElement;
|
|
5237
|
+
while (parent && parent !== document.body) {
|
|
5238
|
+
if (parent.hasAttribute('*await') && (child.hasAttribute('*pending') ||
|
|
5239
|
+
child.hasAttribute('*then') ||
|
|
5240
|
+
child.hasAttribute('*catch'))) {
|
|
5241
|
+
return true;
|
|
5242
|
+
}
|
|
5243
|
+
child = parent;
|
|
5244
|
+
parent = parent.parentElement;
|
|
5245
|
+
}
|
|
5246
|
+
return false;
|
|
5247
|
+
}
|
|
5238
5248
|
const elementBelongsToAnotherScope = (el, scope) => {
|
|
5239
5249
|
const owner = getScopeFromElement(el);
|
|
5240
5250
|
return Boolean(owner && owner !== scope);
|
|
@@ -6756,7 +6766,7 @@ function hideTargetSpinner(spinner) {
|
|
|
6756
6766
|
}
|
|
6757
6767
|
|
|
6758
6768
|
let nonceSource;
|
|
6759
|
-
/** Configure the nonce used
|
|
6769
|
+
/** Configure the active document nonce used for scripts and styles during MPA navigation. */
|
|
6760
6770
|
function setCspNonce(source) {
|
|
6761
6771
|
nonceSource = source;
|
|
6762
6772
|
}
|
|
@@ -7328,9 +7338,33 @@ function handleScroll(url, trigger, savedScroll) {
|
|
|
7328
7338
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
7329
7339
|
}
|
|
7330
7340
|
|
|
7331
|
-
function
|
|
7332
|
-
return
|
|
7333
|
-
|
|
7341
|
+
function isNonceMeta(el) {
|
|
7342
|
+
return el.tagName === 'META' && el.getAttribute('name')?.toLowerCase() === 'csp-nonce';
|
|
7343
|
+
}
|
|
7344
|
+
function isStylesheetLink(el) {
|
|
7345
|
+
return el.tagName === 'LINK'
|
|
7346
|
+
&& (el.getAttribute('rel') || '').toLowerCase().split(/\s+/).includes('stylesheet');
|
|
7347
|
+
}
|
|
7348
|
+
function usesCspNonce(el) {
|
|
7349
|
+
return el.tagName === 'SCRIPT' || el.tagName === 'STYLE' || isStylesheetLink(el);
|
|
7350
|
+
}
|
|
7351
|
+
function serializeAttributes(el, context) {
|
|
7352
|
+
const attributes = new Map();
|
|
7353
|
+
Array.from(el.attributes).forEach(attr => {
|
|
7354
|
+
if (context.csp && usesCspNonce(el) && attr.name.toLowerCase() === 'nonce')
|
|
7355
|
+
return;
|
|
7356
|
+
if (context.csp && isNonceMeta(el) && attr.name.toLowerCase() === 'content')
|
|
7357
|
+
return;
|
|
7358
|
+
attributes.set(attr.name, attr.value);
|
|
7359
|
+
});
|
|
7360
|
+
if (context.csp && usesCspNonce(el) && context.activeNonce) {
|
|
7361
|
+
attributes.set('nonce', context.activeNonce);
|
|
7362
|
+
}
|
|
7363
|
+
if (context.csp && isNonceMeta(el) && context.activeNonce) {
|
|
7364
|
+
attributes.set('content', context.activeNonce);
|
|
7365
|
+
}
|
|
7366
|
+
return Array.from(attributes)
|
|
7367
|
+
.map(([name, value]) => `${name}=${value}`)
|
|
7334
7368
|
.sort()
|
|
7335
7369
|
.join('|');
|
|
7336
7370
|
}
|
|
@@ -7341,23 +7375,61 @@ function hashContent(content) {
|
|
|
7341
7375
|
}
|
|
7342
7376
|
return String(hash);
|
|
7343
7377
|
}
|
|
7344
|
-
function elementKey(el) {
|
|
7378
|
+
function elementKey(el, context) {
|
|
7345
7379
|
const tag = el.tagName.toLowerCase();
|
|
7346
7380
|
const content = tag === 'script' || tag === 'style' ? hashContent(el.textContent || '') : '';
|
|
7347
|
-
return `${tag}|${serializeAttributes(el)}|${content}`;
|
|
7381
|
+
return `${tag}|${serializeAttributes(el, context)}|${content}`;
|
|
7348
7382
|
}
|
|
7349
|
-
function keyedNodes(nodes) {
|
|
7383
|
+
function keyedNodes(nodes, context) {
|
|
7350
7384
|
const occurrences = new Map();
|
|
7351
7385
|
return nodes.map(node => {
|
|
7352
|
-
const baseKey = elementKey(node);
|
|
7386
|
+
const baseKey = elementKey(node, context);
|
|
7353
7387
|
const occurrence = occurrences.get(baseKey) || 0;
|
|
7354
7388
|
occurrences.set(baseKey, occurrence + 1);
|
|
7355
7389
|
return { key: `${baseKey}|${occurrence}`, node };
|
|
7356
7390
|
});
|
|
7357
7391
|
}
|
|
7392
|
+
function canInsertNode(node, context) {
|
|
7393
|
+
if (!context.csp)
|
|
7394
|
+
return true;
|
|
7395
|
+
if (isNonceMeta(node))
|
|
7396
|
+
return Boolean(context.activeNonce);
|
|
7397
|
+
if (node.tagName === 'STYLE')
|
|
7398
|
+
return Boolean(context.activeNonce);
|
|
7399
|
+
if (node.tagName === 'SCRIPT' && !node.hasAttribute('src'))
|
|
7400
|
+
return Boolean(context.activeNonce);
|
|
7401
|
+
return true;
|
|
7402
|
+
}
|
|
7403
|
+
function reconcileCspAttributes(node, context) {
|
|
7404
|
+
if (!context.csp)
|
|
7405
|
+
return;
|
|
7406
|
+
if (isNonceMeta(node)) {
|
|
7407
|
+
if (context.activeNonce)
|
|
7408
|
+
node.setAttribute('content', context.activeNonce);
|
|
7409
|
+
return;
|
|
7410
|
+
}
|
|
7411
|
+
if (!usesCspNonce(node))
|
|
7412
|
+
return;
|
|
7413
|
+
node.removeAttribute('nonce');
|
|
7414
|
+
if (context.activeNonce)
|
|
7415
|
+
node.setAttribute('nonce', context.activeNonce);
|
|
7416
|
+
}
|
|
7417
|
+
function warnSkippedNode(node) {
|
|
7418
|
+
if (node.tagName === 'STYLE') {
|
|
7419
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA style because no active document nonce is configured.');
|
|
7420
|
+
}
|
|
7421
|
+
else if (node.tagName === 'SCRIPT' && !node.hasAttribute('src')) {
|
|
7422
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
7423
|
+
}
|
|
7424
|
+
}
|
|
7358
7425
|
async function diffNodes(currentNodes, nextNodes, container = document.head, signal) {
|
|
7359
|
-
const
|
|
7360
|
-
const
|
|
7426
|
+
const csp = expressionRuntimeMode() === 'csp';
|
|
7427
|
+
const context = {
|
|
7428
|
+
csp,
|
|
7429
|
+
activeNonce: csp ? resolveCspNonce() : undefined
|
|
7430
|
+
};
|
|
7431
|
+
const current = keyedNodes(currentNodes, context);
|
|
7432
|
+
const next = keyedNodes(nextNodes, context);
|
|
7361
7433
|
const currentKeys = new Set(current.map(item => item.key));
|
|
7362
7434
|
const nextKeys = new Set(next.map(item => item.key));
|
|
7363
7435
|
// Remove nodes that are not in the new head
|
|
@@ -7371,6 +7443,20 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7371
7443
|
if (signal?.aborted)
|
|
7372
7444
|
return;
|
|
7373
7445
|
if (!currentKeys.has(key)) {
|
|
7446
|
+
if (!canInsertNode(node, context)) {
|
|
7447
|
+
warnSkippedNode(node);
|
|
7448
|
+
continue;
|
|
7449
|
+
}
|
|
7450
|
+
if (node.tagName === 'STYLE') {
|
|
7451
|
+
const style = document.createElement('style');
|
|
7452
|
+
Array.from(node.attributes).forEach(attr => style.setAttribute(attr.name, attr.value));
|
|
7453
|
+
reconcileCspAttributes(style, context);
|
|
7454
|
+
// CSP checks inline styles as their CSS text is attached. Set the active
|
|
7455
|
+
// nonce first so a response nonce never produces a transient violation.
|
|
7456
|
+
style.textContent = node.textContent || '';
|
|
7457
|
+
container.appendChild(style);
|
|
7458
|
+
continue;
|
|
7459
|
+
}
|
|
7374
7460
|
if (node.tagName === 'SCRIPT') {
|
|
7375
7461
|
const originalScript = node;
|
|
7376
7462
|
const executionKey = getScriptExecutionKey(originalScript);
|
|
@@ -7381,6 +7467,7 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7381
7467
|
}
|
|
7382
7468
|
const script = document.createElement('script');
|
|
7383
7469
|
Array.from(node.attributes).forEach(attr => script.setAttribute(attr.name, attr.value));
|
|
7470
|
+
reconcileCspAttributes(script, context);
|
|
7384
7471
|
script.textContent = node.hasAttribute('g-script-wrap')
|
|
7385
7472
|
? wrapScriptExecution(node.textContent || '')
|
|
7386
7473
|
: node.textContent || '';
|
|
@@ -7390,9 +7477,166 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7390
7477
|
await completion;
|
|
7391
7478
|
continue;
|
|
7392
7479
|
}
|
|
7393
|
-
|
|
7480
|
+
const imported = document.importNode(node, true);
|
|
7481
|
+
reconcileCspAttributes(imported, context);
|
|
7482
|
+
container.appendChild(imported);
|
|
7483
|
+
}
|
|
7484
|
+
}
|
|
7485
|
+
}
|
|
7486
|
+
|
|
7487
|
+
const RAW_TEXT_ELEMENTS = new Set(['iframe', 'noembed', 'noframes', 'plaintext', 'script', 'textarea', 'title', 'xmp']);
|
|
7488
|
+
function escapeAttribute(value) {
|
|
7489
|
+
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
7490
|
+
}
|
|
7491
|
+
function findTagEnd(html, start) {
|
|
7492
|
+
let quote = '';
|
|
7493
|
+
for (let index = start; index < html.length; index += 1) {
|
|
7494
|
+
const character = html[index];
|
|
7495
|
+
if (quote) {
|
|
7496
|
+
if (character === quote)
|
|
7497
|
+
quote = '';
|
|
7498
|
+
continue;
|
|
7499
|
+
}
|
|
7500
|
+
if (character === '"' || character === "'") {
|
|
7501
|
+
quote = character;
|
|
7502
|
+
continue;
|
|
7503
|
+
}
|
|
7504
|
+
if (character === '>')
|
|
7505
|
+
return index + 1;
|
|
7506
|
+
}
|
|
7507
|
+
return html.length;
|
|
7508
|
+
}
|
|
7509
|
+
function findClosingTag(html, lowerHtml, name, start) {
|
|
7510
|
+
const needle = `</${name}`;
|
|
7511
|
+
let position = lowerHtml.indexOf(needle, start);
|
|
7512
|
+
while (position !== -1) {
|
|
7513
|
+
const boundary = lowerHtml[position + needle.length];
|
|
7514
|
+
if (boundary === '>' || /\s/.test(boundary || '')) {
|
|
7515
|
+
return {
|
|
7516
|
+
start: position,
|
|
7517
|
+
end: findTagEnd(html, position + needle.length)
|
|
7518
|
+
};
|
|
7519
|
+
}
|
|
7520
|
+
position = lowerHtml.indexOf(needle, position + needle.length);
|
|
7521
|
+
}
|
|
7522
|
+
return null;
|
|
7523
|
+
}
|
|
7524
|
+
function removeNonceAttribute(openingTag) {
|
|
7525
|
+
const prefix = /^<\s*style\b/i.exec(openingTag);
|
|
7526
|
+
if (!prefix)
|
|
7527
|
+
return openingTag;
|
|
7528
|
+
let output = prefix[0];
|
|
7529
|
+
let cursor = prefix[0].length;
|
|
7530
|
+
const limit = openingTag.length - 1;
|
|
7531
|
+
while (cursor < limit) {
|
|
7532
|
+
const attributeStart = cursor;
|
|
7533
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7534
|
+
cursor += 1;
|
|
7535
|
+
if (cursor >= limit || openingTag[cursor] === '>') {
|
|
7536
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7537
|
+
break;
|
|
7538
|
+
}
|
|
7539
|
+
const nameStart = cursor;
|
|
7540
|
+
while (cursor < limit && !/[\s=/>]/.test(openingTag[cursor]))
|
|
7541
|
+
cursor += 1;
|
|
7542
|
+
if (cursor === nameStart) {
|
|
7543
|
+
output += openingTag.slice(attributeStart, cursor + 1);
|
|
7544
|
+
cursor += 1;
|
|
7545
|
+
continue;
|
|
7546
|
+
}
|
|
7547
|
+
const name = openingTag.slice(nameStart, cursor).toLowerCase();
|
|
7548
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7549
|
+
cursor += 1;
|
|
7550
|
+
if (openingTag[cursor] === '=') {
|
|
7551
|
+
cursor += 1;
|
|
7552
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7553
|
+
cursor += 1;
|
|
7554
|
+
const quote = openingTag[cursor] === '"' || openingTag[cursor] === "'" ? openingTag[cursor] : '';
|
|
7555
|
+
if (quote) {
|
|
7556
|
+
cursor += 1;
|
|
7557
|
+
while (cursor < limit && openingTag[cursor] !== quote)
|
|
7558
|
+
cursor += 1;
|
|
7559
|
+
if (openingTag[cursor] === quote)
|
|
7560
|
+
cursor += 1;
|
|
7561
|
+
}
|
|
7562
|
+
else {
|
|
7563
|
+
while (cursor < limit && !/[\s>]/.test(openingTag[cursor]))
|
|
7564
|
+
cursor += 1;
|
|
7565
|
+
}
|
|
7566
|
+
}
|
|
7567
|
+
if (name !== 'nonce')
|
|
7568
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7569
|
+
}
|
|
7570
|
+
return output + openingTag.slice(limit);
|
|
7571
|
+
}
|
|
7572
|
+
function withNonce(openingTag, nonce) {
|
|
7573
|
+
const withoutNonce = removeNonceAttribute(openingTag);
|
|
7574
|
+
return `${withoutNonce.slice(0, -1)} nonce="${escapeAttribute(nonce)}">`;
|
|
7575
|
+
}
|
|
7576
|
+
function prepareNavigationHtml(html) {
|
|
7577
|
+
if (expressionRuntimeMode() !== 'csp')
|
|
7578
|
+
return html;
|
|
7579
|
+
const activeNonce = resolveCspNonce();
|
|
7580
|
+
const lowerHtml = html.toLowerCase();
|
|
7581
|
+
let output = '';
|
|
7582
|
+
let cursor = 0;
|
|
7583
|
+
let skippedStyles = 0;
|
|
7584
|
+
while (cursor < html.length) {
|
|
7585
|
+
const tagStart = html.indexOf('<', cursor);
|
|
7586
|
+
if (tagStart === -1) {
|
|
7587
|
+
output += html.slice(cursor);
|
|
7588
|
+
break;
|
|
7589
|
+
}
|
|
7590
|
+
output += html.slice(cursor, tagStart);
|
|
7591
|
+
if (html.startsWith('<!--', tagStart)) {
|
|
7592
|
+
const commentEnd = html.indexOf('-->', tagStart + 4);
|
|
7593
|
+
const end = commentEnd === -1 ? html.length : commentEnd + 3;
|
|
7594
|
+
output += html.slice(tagStart, end);
|
|
7595
|
+
cursor = end;
|
|
7596
|
+
continue;
|
|
7597
|
+
}
|
|
7598
|
+
const tagEnd = findTagEnd(html, tagStart + 1);
|
|
7599
|
+
const openingTag = html.slice(tagStart, tagEnd);
|
|
7600
|
+
const match = /^<\s*(\/?)\s*([a-z][\w:-]*)/i.exec(openingTag);
|
|
7601
|
+
if (!match || match[1]) {
|
|
7602
|
+
output += openingTag;
|
|
7603
|
+
cursor = tagEnd;
|
|
7604
|
+
continue;
|
|
7605
|
+
}
|
|
7606
|
+
const name = match[2].toLowerCase();
|
|
7607
|
+
if (name === 'plaintext') {
|
|
7608
|
+
output += html.slice(tagStart);
|
|
7609
|
+
break;
|
|
7610
|
+
}
|
|
7611
|
+
if (name === 'style' || name === 'noscript' || RAW_TEXT_ELEMENTS.has(name)) {
|
|
7612
|
+
const closingTag = findClosingTag(html, lowerHtml, name, tagEnd);
|
|
7613
|
+
const blockEnd = closingTag?.end ?? html.length;
|
|
7614
|
+
if (name === 'noscript') {
|
|
7615
|
+
cursor = blockEnd;
|
|
7616
|
+
continue;
|
|
7617
|
+
}
|
|
7618
|
+
if (name === 'style') {
|
|
7619
|
+
if (!activeNonce) {
|
|
7620
|
+
skippedStyles += 1;
|
|
7621
|
+
cursor = blockEnd;
|
|
7622
|
+
continue;
|
|
7623
|
+
}
|
|
7624
|
+
output += withNonce(openingTag, activeNonce);
|
|
7625
|
+
output += html.slice(tagEnd, blockEnd);
|
|
7626
|
+
cursor = blockEnd;
|
|
7627
|
+
continue;
|
|
7628
|
+
}
|
|
7629
|
+
output += html.slice(tagStart, blockEnd);
|
|
7630
|
+
cursor = blockEnd;
|
|
7631
|
+
continue;
|
|
7394
7632
|
}
|
|
7633
|
+
output += openingTag;
|
|
7634
|
+
cursor = tagEnd;
|
|
7635
|
+
}
|
|
7636
|
+
if (skippedStyles > 0) {
|
|
7637
|
+
console.warn(`[GyosJS CSP] Skipped ${skippedStyles} inline MPA style${skippedStyles === 1 ? '' : 's'} because no active document nonce is configured.`);
|
|
7395
7638
|
}
|
|
7639
|
+
return output;
|
|
7396
7640
|
}
|
|
7397
7641
|
|
|
7398
7642
|
/**
|
|
@@ -7458,7 +7702,10 @@ function stripInertFallbackContent(root) {
|
|
|
7458
7702
|
root.querySelectorAll('noscript').forEach(element => element.remove());
|
|
7459
7703
|
}
|
|
7460
7704
|
function parseNavigationDocument(html) {
|
|
7461
|
-
|
|
7705
|
+
// Chromium applies the active page CSP while DOMParser creates response
|
|
7706
|
+
// styles. Reconcile their nonce before parsing to avoid transient violations;
|
|
7707
|
+
// diffNodes repeats the check before insertion into the live document.
|
|
7708
|
+
const doc = new DOMParser().parseFromString(prepareNavigationHtml(html), 'text/html');
|
|
7462
7709
|
// DOMParser disables scripting and parses noscript children as active markup.
|
|
7463
7710
|
// A boosted page runs with scripting enabled, so those fallbacks must stay inert.
|
|
7464
7711
|
stripInertFallbackContent(doc);
|
|
@@ -8294,7 +8541,7 @@ const Gyos = {
|
|
|
8294
8541
|
portalCreate,
|
|
8295
8542
|
portalDestroy,
|
|
8296
8543
|
setCspNonce,
|
|
8297
|
-
version: '0.3.
|
|
8544
|
+
version: '0.3.2'
|
|
8298
8545
|
};
|
|
8299
8546
|
|
|
8300
8547
|
const standardExpressionRuntime = {
|