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.css
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* GyosJS built-in transition utilities. Required by the CSP build. */
|
|
2
|
+
.gyos-t-opacity-0 { opacity: 0; }
|
|
3
|
+
.gyos-t-opacity-100 { opacity: 1; }
|
|
4
|
+
|
|
5
|
+
.gyos-t-translate-y-0 { transform: translateY(0); }
|
|
6
|
+
.gyos-t-translate-y--100 { transform: translateY(-100%); }
|
|
7
|
+
.gyos-t-translate-y-100 { transform: translateY(100%); }
|
|
8
|
+
.gyos-t-translate-x-0 { transform: translateX(0); }
|
|
9
|
+
.gyos-t-translate-x--100 { transform: translateX(-100%); }
|
|
10
|
+
.gyos-t-translate-x-100 { transform: translateX(100%); }
|
|
11
|
+
|
|
12
|
+
.gyos-t-scale-0 { transform: scale(0); }
|
|
13
|
+
.gyos-t-scale-50 { transform: scale(0.5); }
|
|
14
|
+
.gyos-t-scale-100 { transform: scale(1); }
|
|
15
|
+
|
|
16
|
+
@keyframes gyos-fade-in {
|
|
17
|
+
from { opacity: 0; }
|
|
18
|
+
to { opacity: 1; }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@keyframes gyos-fade-out {
|
|
22
|
+
from { opacity: 1; }
|
|
23
|
+
to { opacity: 0; }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@keyframes gyos-slide-down {
|
|
27
|
+
from { transform: translateY(-100%); opacity: 0; }
|
|
28
|
+
to { transform: translateY(0); opacity: 1; }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@keyframes gyos-slide-up {
|
|
32
|
+
from { transform: translateY(100%); opacity: 0; }
|
|
33
|
+
to { transform: translateY(0); opacity: 1; }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@keyframes gyos-scale-in {
|
|
37
|
+
from { transform: scale(0); opacity: 0; }
|
|
38
|
+
to { transform: scale(1); opacity: 1; }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@keyframes gyos-scale-out {
|
|
42
|
+
from { transform: scale(1); opacity: 1; }
|
|
43
|
+
to { transform: scale(0); opacity: 0; }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
[g-cloak] { display: none !important; }
|
|
47
|
+
|
|
48
|
+
.gyos-target-spinner {
|
|
49
|
+
display: flex;
|
|
50
|
+
align-items: center;
|
|
51
|
+
justify-content: center;
|
|
52
|
+
padding: 20px;
|
|
53
|
+
min-height: 60px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.gyos-spinner-content {
|
|
57
|
+
display: flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: 10px;
|
|
60
|
+
color: var(--gyos-spinner-color, #667eea);
|
|
61
|
+
font-size: 14px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.gyos-spinner-icon {
|
|
65
|
+
width: 24px;
|
|
66
|
+
height: 24px;
|
|
67
|
+
animation: gyos-spin 1s linear infinite;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@keyframes gyos-spin {
|
|
71
|
+
0% { transform: rotate(0deg); }
|
|
72
|
+
100% { transform: rotate(360deg); }
|
|
73
|
+
}
|
package/dist/gyos.esm.js
CHANGED
|
@@ -1,8 +1,54 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GyosJS v0.
|
|
2
|
+
* GyosJS v0.3.1
|
|
3
3
|
* (c) 2026
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
6
|
+
let activeRuntime;
|
|
7
|
+
function setExpressionRuntime(runtime) {
|
|
8
|
+
activeRuntime = runtime;
|
|
9
|
+
}
|
|
10
|
+
function expressionRuntime() {
|
|
11
|
+
if (!activeRuntime) {
|
|
12
|
+
throw new Error('[GyosJS] Expression runtime is not configured. Import GyosJS from a public entry point.');
|
|
13
|
+
}
|
|
14
|
+
return activeRuntime;
|
|
15
|
+
}
|
|
16
|
+
function expressionRuntimeMode() {
|
|
17
|
+
return activeRuntime?.mode ?? 'standard';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const standardExpressionRuntime = {
|
|
21
|
+
mode: 'standard',
|
|
22
|
+
evaluate(expression, scope) {
|
|
23
|
+
const method = scope?.[expression];
|
|
24
|
+
if (typeof method === 'function')
|
|
25
|
+
return method.call(scope);
|
|
26
|
+
try {
|
|
27
|
+
const safeExpression = `try { return ${expression} } catch(e) { return undefined }`;
|
|
28
|
+
const evaluate = new Function('$scope', `with($scope) { ${safeExpression} }`);
|
|
29
|
+
return evaluate(scope);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('[GyosJS] Error evaluating expression:', expression, error);
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
execute(expression, scope, event) {
|
|
37
|
+
const method = scope?.[expression];
|
|
38
|
+
if (typeof method === 'function')
|
|
39
|
+
return method.call(scope, event);
|
|
40
|
+
const execute = new Function('$event', `with(this) { ${expression} }`);
|
|
41
|
+
return execute.call(scope, event);
|
|
42
|
+
},
|
|
43
|
+
parseScope(expression) {
|
|
44
|
+
const parse = new Function(`return (${expression})`);
|
|
45
|
+
return parse();
|
|
46
|
+
},
|
|
47
|
+
createMethod(parameters, body) {
|
|
48
|
+
return new Function(parameters.join(', '), `with(this) { ${body} }`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
6
52
|
/**
|
|
7
53
|
* Utility helpers
|
|
8
54
|
*/
|
|
@@ -1337,24 +1383,7 @@ function evaluateSimpleExpression(expr, scope) {
|
|
|
1337
1383
|
if (!isNaN(Number(expr))) {
|
|
1338
1384
|
return Number(expr);
|
|
1339
1385
|
}
|
|
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
|
-
}
|
|
1386
|
+
return expressionRuntime().evaluate(expr, scope);
|
|
1358
1387
|
}
|
|
1359
1388
|
|
|
1360
1389
|
/**
|
|
@@ -2192,6 +2221,8 @@ function getTransitionConfig(source) {
|
|
|
2192
2221
|
function applyTransitionStyles() {
|
|
2193
2222
|
if (typeof document === 'undefined')
|
|
2194
2223
|
return;
|
|
2224
|
+
if (expressionRuntimeMode() === 'csp')
|
|
2225
|
+
return;
|
|
2195
2226
|
const styleId = 'gyos-transitions';
|
|
2196
2227
|
if (document.getElementById(styleId))
|
|
2197
2228
|
return;
|
|
@@ -2263,32 +2294,24 @@ function applyTransitionStyles() {
|
|
|
2263
2294
|
* Handles:
|
|
2264
2295
|
* 1. Literal string: "fade" or "slide-down"
|
|
2265
2296
|
* 2. Expression with {}: "{transition}"
|
|
2266
|
-
* 3.
|
|
2297
|
+
* 3. Quoted literal kept for backwards compatibility: "'fade'"
|
|
2267
2298
|
*
|
|
2268
2299
|
* @param attrValue - The g-transition attribute value
|
|
2269
2300
|
* @param scope - Current scope for expression evaluation
|
|
2270
2301
|
* @returns The transition name (string)
|
|
2271
2302
|
*/
|
|
2272
2303
|
function parseTransitionName(attrValue, scope) {
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
}
|
|
2304
|
+
const value = attrValue.trim();
|
|
2305
|
+
const expression = /^\{([\s\S]+)\}$/.exec(value);
|
|
2306
|
+
if (expression) {
|
|
2307
|
+
const evaluated = evaluateExpression(expression[1].trim(), scope);
|
|
2308
|
+
return evaluated == null ? '' : String(evaluated);
|
|
2279
2309
|
}
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
const evaluated = evaluateExpression(attrValue, scope);
|
|
2284
|
-
if (evaluated !== undefined && evaluated !== null) {
|
|
2285
|
-
return evaluated;
|
|
2286
|
-
}
|
|
2310
|
+
if (value.length >= 2 && ((value.startsWith("'") && value.endsWith("'"))
|
|
2311
|
+
|| (value.startsWith('"') && value.endsWith('"')))) {
|
|
2312
|
+
return value.slice(1, -1);
|
|
2287
2313
|
}
|
|
2288
|
-
|
|
2289
|
-
// If evaluation fails, use value as literal string (built-in transition name)
|
|
2290
|
-
}
|
|
2291
|
-
return attrValue;
|
|
2314
|
+
return value;
|
|
2292
2315
|
}
|
|
2293
2316
|
/**
|
|
2294
2317
|
* Parse transition config from element's g-transition attribute
|
|
@@ -3679,24 +3702,7 @@ function executeHandler(handler, scope, e, modifiers) {
|
|
|
3679
3702
|
if (modifiers.includes('stop'))
|
|
3680
3703
|
e.stopPropagation();
|
|
3681
3704
|
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
|
-
}
|
|
3705
|
+
expressionRuntime().execute(handler, scope, e);
|
|
3700
3706
|
}
|
|
3701
3707
|
catch (err) {
|
|
3702
3708
|
console.error('[GyosJS] Error in event handler:', err);
|
|
@@ -5672,10 +5678,7 @@ function parseInlineScope(scopeStr) {
|
|
|
5672
5678
|
if (!trimmed.startsWith('{')) {
|
|
5673
5679
|
return undefined; // Not an inline definition
|
|
5674
5680
|
}
|
|
5675
|
-
|
|
5676
|
-
// This allows methods and complex expressions
|
|
5677
|
-
const fn = new Function(`return (${trimmed})`);
|
|
5678
|
-
const definition = fn();
|
|
5681
|
+
const definition = expressionRuntime().parseScope(trimmed);
|
|
5679
5682
|
DEBUG() && console.log('[GyosJS] Parsed inline scope:', definition);
|
|
5680
5683
|
return definition;
|
|
5681
5684
|
}
|
|
@@ -5739,10 +5742,10 @@ function parseAutoScope(el) {
|
|
|
5739
5742
|
if (forbidden.some(f => expr.includes(f))) {
|
|
5740
5743
|
DEBUG() && console.log("[GyosJS] Scope mount error: Forbidden expression:", expr);
|
|
5741
5744
|
}
|
|
5742
|
-
const args = key.split(':').slice(1)
|
|
5745
|
+
const args = key.split(':').slice(1);
|
|
5743
5746
|
const propName = key.split(':')[0];
|
|
5744
5747
|
try {
|
|
5745
|
-
definition[propName] =
|
|
5748
|
+
definition[propName] = expressionRuntime().createMethod(args, expr);
|
|
5746
5749
|
removeAttrs.push(attr.name);
|
|
5747
5750
|
}
|
|
5748
5751
|
catch (_) {
|
|
@@ -6722,7 +6725,7 @@ function createTargetSpinner() {
|
|
|
6722
6725
|
</div>
|
|
6723
6726
|
`;
|
|
6724
6727
|
// Inject styles if not already present
|
|
6725
|
-
if (!document.getElementById('gyos-target-spinner-styles')) {
|
|
6728
|
+
if (expressionRuntimeMode() === 'standard' && !document.getElementById('gyos-target-spinner-styles')) {
|
|
6726
6729
|
const style = document.createElement('style');
|
|
6727
6730
|
style.id = 'gyos-target-spinner-styles';
|
|
6728
6731
|
style.textContent = `
|
|
@@ -6776,6 +6779,16 @@ function hideTargetSpinner(spinner) {
|
|
|
6776
6779
|
}
|
|
6777
6780
|
}
|
|
6778
6781
|
|
|
6782
|
+
let nonceSource;
|
|
6783
|
+
/** Configure the active document nonce used for scripts and styles during MPA navigation. */
|
|
6784
|
+
function setCspNonce(source) {
|
|
6785
|
+
nonceSource = source;
|
|
6786
|
+
}
|
|
6787
|
+
function resolveCspNonce() {
|
|
6788
|
+
const value = typeof nonceSource === 'function' ? nonceSource() : nonceSource;
|
|
6789
|
+
return value || undefined;
|
|
6790
|
+
}
|
|
6791
|
+
|
|
6779
6792
|
// Cache executed scripts to prevent duplicate execution
|
|
6780
6793
|
const executedScripts = new Set();
|
|
6781
6794
|
/**
|
|
@@ -6876,6 +6889,12 @@ async function executeScript(old, signal) {
|
|
|
6876
6889
|
old.remove();
|
|
6877
6890
|
return;
|
|
6878
6891
|
}
|
|
6892
|
+
const activeNonce = resolveCspNonce();
|
|
6893
|
+
if (expressionRuntimeMode() === 'csp' && !old.src && !activeNonce) {
|
|
6894
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
6895
|
+
old.textContent = '';
|
|
6896
|
+
return;
|
|
6897
|
+
}
|
|
6879
6898
|
const executionKey = getScriptExecutionKey(old);
|
|
6880
6899
|
// Check if script should execute
|
|
6881
6900
|
if (!shouldExecuteScript(old)) {
|
|
@@ -6885,6 +6904,10 @@ async function executeScript(old, signal) {
|
|
|
6885
6904
|
}
|
|
6886
6905
|
const newScript = document.createElement('script');
|
|
6887
6906
|
Array.from(old.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value));
|
|
6907
|
+
if (expressionRuntimeMode() === 'csp')
|
|
6908
|
+
newScript.removeAttribute('nonce');
|
|
6909
|
+
if (activeNonce)
|
|
6910
|
+
newScript.setAttribute('nonce', activeNonce);
|
|
6888
6911
|
newScript.textContent = old.hasAttribute('g-script-wrap')
|
|
6889
6912
|
? wrapScriptExecution(old.textContent)
|
|
6890
6913
|
: old.textContent;
|
|
@@ -7329,9 +7352,33 @@ function handleScroll(url, trigger, savedScroll) {
|
|
|
7329
7352
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
7330
7353
|
}
|
|
7331
7354
|
|
|
7332
|
-
function
|
|
7333
|
-
return
|
|
7334
|
-
|
|
7355
|
+
function isNonceMeta(el) {
|
|
7356
|
+
return el.tagName === 'META' && el.getAttribute('name')?.toLowerCase() === 'csp-nonce';
|
|
7357
|
+
}
|
|
7358
|
+
function isStylesheetLink(el) {
|
|
7359
|
+
return el.tagName === 'LINK'
|
|
7360
|
+
&& (el.getAttribute('rel') || '').toLowerCase().split(/\s+/).includes('stylesheet');
|
|
7361
|
+
}
|
|
7362
|
+
function usesCspNonce(el) {
|
|
7363
|
+
return el.tagName === 'SCRIPT' || el.tagName === 'STYLE' || isStylesheetLink(el);
|
|
7364
|
+
}
|
|
7365
|
+
function serializeAttributes(el, context) {
|
|
7366
|
+
const attributes = new Map();
|
|
7367
|
+
Array.from(el.attributes).forEach(attr => {
|
|
7368
|
+
if (context.csp && usesCspNonce(el) && attr.name.toLowerCase() === 'nonce')
|
|
7369
|
+
return;
|
|
7370
|
+
if (context.csp && isNonceMeta(el) && attr.name.toLowerCase() === 'content')
|
|
7371
|
+
return;
|
|
7372
|
+
attributes.set(attr.name, attr.value);
|
|
7373
|
+
});
|
|
7374
|
+
if (context.csp && usesCspNonce(el) && context.activeNonce) {
|
|
7375
|
+
attributes.set('nonce', context.activeNonce);
|
|
7376
|
+
}
|
|
7377
|
+
if (context.csp && isNonceMeta(el) && context.activeNonce) {
|
|
7378
|
+
attributes.set('content', context.activeNonce);
|
|
7379
|
+
}
|
|
7380
|
+
return Array.from(attributes)
|
|
7381
|
+
.map(([name, value]) => `${name}=${value}`)
|
|
7335
7382
|
.sort()
|
|
7336
7383
|
.join('|');
|
|
7337
7384
|
}
|
|
@@ -7342,23 +7389,61 @@ function hashContent(content) {
|
|
|
7342
7389
|
}
|
|
7343
7390
|
return String(hash);
|
|
7344
7391
|
}
|
|
7345
|
-
function elementKey(el) {
|
|
7392
|
+
function elementKey(el, context) {
|
|
7346
7393
|
const tag = el.tagName.toLowerCase();
|
|
7347
7394
|
const content = tag === 'script' || tag === 'style' ? hashContent(el.textContent || '') : '';
|
|
7348
|
-
return `${tag}|${serializeAttributes(el)}|${content}`;
|
|
7395
|
+
return `${tag}|${serializeAttributes(el, context)}|${content}`;
|
|
7349
7396
|
}
|
|
7350
|
-
function keyedNodes(nodes) {
|
|
7397
|
+
function keyedNodes(nodes, context) {
|
|
7351
7398
|
const occurrences = new Map();
|
|
7352
7399
|
return nodes.map(node => {
|
|
7353
|
-
const baseKey = elementKey(node);
|
|
7400
|
+
const baseKey = elementKey(node, context);
|
|
7354
7401
|
const occurrence = occurrences.get(baseKey) || 0;
|
|
7355
7402
|
occurrences.set(baseKey, occurrence + 1);
|
|
7356
7403
|
return { key: `${baseKey}|${occurrence}`, node };
|
|
7357
7404
|
});
|
|
7358
7405
|
}
|
|
7406
|
+
function canInsertNode(node, context) {
|
|
7407
|
+
if (!context.csp)
|
|
7408
|
+
return true;
|
|
7409
|
+
if (isNonceMeta(node))
|
|
7410
|
+
return Boolean(context.activeNonce);
|
|
7411
|
+
if (node.tagName === 'STYLE')
|
|
7412
|
+
return Boolean(context.activeNonce);
|
|
7413
|
+
if (node.tagName === 'SCRIPT' && !node.hasAttribute('src'))
|
|
7414
|
+
return Boolean(context.activeNonce);
|
|
7415
|
+
return true;
|
|
7416
|
+
}
|
|
7417
|
+
function reconcileCspAttributes(node, context) {
|
|
7418
|
+
if (!context.csp)
|
|
7419
|
+
return;
|
|
7420
|
+
if (isNonceMeta(node)) {
|
|
7421
|
+
if (context.activeNonce)
|
|
7422
|
+
node.setAttribute('content', context.activeNonce);
|
|
7423
|
+
return;
|
|
7424
|
+
}
|
|
7425
|
+
if (!usesCspNonce(node))
|
|
7426
|
+
return;
|
|
7427
|
+
node.removeAttribute('nonce');
|
|
7428
|
+
if (context.activeNonce)
|
|
7429
|
+
node.setAttribute('nonce', context.activeNonce);
|
|
7430
|
+
}
|
|
7431
|
+
function warnSkippedNode(node) {
|
|
7432
|
+
if (node.tagName === 'STYLE') {
|
|
7433
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA style because no active document nonce is configured.');
|
|
7434
|
+
}
|
|
7435
|
+
else if (node.tagName === 'SCRIPT' && !node.hasAttribute('src')) {
|
|
7436
|
+
console.warn('[GyosJS CSP] Skipped an inline MPA script because no active document nonce is configured.');
|
|
7437
|
+
}
|
|
7438
|
+
}
|
|
7359
7439
|
async function diffNodes(currentNodes, nextNodes, container = document.head, signal) {
|
|
7360
|
-
const
|
|
7361
|
-
const
|
|
7440
|
+
const csp = expressionRuntimeMode() === 'csp';
|
|
7441
|
+
const context = {
|
|
7442
|
+
csp,
|
|
7443
|
+
activeNonce: csp ? resolveCspNonce() : undefined
|
|
7444
|
+
};
|
|
7445
|
+
const current = keyedNodes(currentNodes, context);
|
|
7446
|
+
const next = keyedNodes(nextNodes, context);
|
|
7362
7447
|
const currentKeys = new Set(current.map(item => item.key));
|
|
7363
7448
|
const nextKeys = new Set(next.map(item => item.key));
|
|
7364
7449
|
// Remove nodes that are not in the new head
|
|
@@ -7372,6 +7457,20 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7372
7457
|
if (signal?.aborted)
|
|
7373
7458
|
return;
|
|
7374
7459
|
if (!currentKeys.has(key)) {
|
|
7460
|
+
if (!canInsertNode(node, context)) {
|
|
7461
|
+
warnSkippedNode(node);
|
|
7462
|
+
continue;
|
|
7463
|
+
}
|
|
7464
|
+
if (node.tagName === 'STYLE') {
|
|
7465
|
+
const style = document.createElement('style');
|
|
7466
|
+
Array.from(node.attributes).forEach(attr => style.setAttribute(attr.name, attr.value));
|
|
7467
|
+
reconcileCspAttributes(style, context);
|
|
7468
|
+
// CSP checks inline styles as their CSS text is attached. Set the active
|
|
7469
|
+
// nonce first so a response nonce never produces a transient violation.
|
|
7470
|
+
style.textContent = node.textContent || '';
|
|
7471
|
+
container.appendChild(style);
|
|
7472
|
+
continue;
|
|
7473
|
+
}
|
|
7375
7474
|
if (node.tagName === 'SCRIPT') {
|
|
7376
7475
|
const originalScript = node;
|
|
7377
7476
|
const executionKey = getScriptExecutionKey(originalScript);
|
|
@@ -7382,6 +7481,7 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7382
7481
|
}
|
|
7383
7482
|
const script = document.createElement('script');
|
|
7384
7483
|
Array.from(node.attributes).forEach(attr => script.setAttribute(attr.name, attr.value));
|
|
7484
|
+
reconcileCspAttributes(script, context);
|
|
7385
7485
|
script.textContent = node.hasAttribute('g-script-wrap')
|
|
7386
7486
|
? wrapScriptExecution(node.textContent || '')
|
|
7387
7487
|
: node.textContent || '';
|
|
@@ -7391,9 +7491,166 @@ async function diffNodes(currentNodes, nextNodes, container = document.head, sig
|
|
|
7391
7491
|
await completion;
|
|
7392
7492
|
continue;
|
|
7393
7493
|
}
|
|
7394
|
-
|
|
7494
|
+
const imported = document.importNode(node, true);
|
|
7495
|
+
reconcileCspAttributes(imported, context);
|
|
7496
|
+
container.appendChild(imported);
|
|
7497
|
+
}
|
|
7498
|
+
}
|
|
7499
|
+
}
|
|
7500
|
+
|
|
7501
|
+
const RAW_TEXT_ELEMENTS = new Set(['iframe', 'noembed', 'noframes', 'plaintext', 'script', 'textarea', 'title', 'xmp']);
|
|
7502
|
+
function escapeAttribute(value) {
|
|
7503
|
+
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
7504
|
+
}
|
|
7505
|
+
function findTagEnd(html, start) {
|
|
7506
|
+
let quote = '';
|
|
7507
|
+
for (let index = start; index < html.length; index += 1) {
|
|
7508
|
+
const character = html[index];
|
|
7509
|
+
if (quote) {
|
|
7510
|
+
if (character === quote)
|
|
7511
|
+
quote = '';
|
|
7512
|
+
continue;
|
|
7513
|
+
}
|
|
7514
|
+
if (character === '"' || character === "'") {
|
|
7515
|
+
quote = character;
|
|
7516
|
+
continue;
|
|
7517
|
+
}
|
|
7518
|
+
if (character === '>')
|
|
7519
|
+
return index + 1;
|
|
7520
|
+
}
|
|
7521
|
+
return html.length;
|
|
7522
|
+
}
|
|
7523
|
+
function findClosingTag(html, lowerHtml, name, start) {
|
|
7524
|
+
const needle = `</${name}`;
|
|
7525
|
+
let position = lowerHtml.indexOf(needle, start);
|
|
7526
|
+
while (position !== -1) {
|
|
7527
|
+
const boundary = lowerHtml[position + needle.length];
|
|
7528
|
+
if (boundary === '>' || /\s/.test(boundary || '')) {
|
|
7529
|
+
return {
|
|
7530
|
+
start: position,
|
|
7531
|
+
end: findTagEnd(html, position + needle.length)
|
|
7532
|
+
};
|
|
7533
|
+
}
|
|
7534
|
+
position = lowerHtml.indexOf(needle, position + needle.length);
|
|
7535
|
+
}
|
|
7536
|
+
return null;
|
|
7537
|
+
}
|
|
7538
|
+
function removeNonceAttribute(openingTag) {
|
|
7539
|
+
const prefix = /^<\s*style\b/i.exec(openingTag);
|
|
7540
|
+
if (!prefix)
|
|
7541
|
+
return openingTag;
|
|
7542
|
+
let output = prefix[0];
|
|
7543
|
+
let cursor = prefix[0].length;
|
|
7544
|
+
const limit = openingTag.length - 1;
|
|
7545
|
+
while (cursor < limit) {
|
|
7546
|
+
const attributeStart = cursor;
|
|
7547
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7548
|
+
cursor += 1;
|
|
7549
|
+
if (cursor >= limit || openingTag[cursor] === '>') {
|
|
7550
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7551
|
+
break;
|
|
7552
|
+
}
|
|
7553
|
+
const nameStart = cursor;
|
|
7554
|
+
while (cursor < limit && !/[\s=/>]/.test(openingTag[cursor]))
|
|
7555
|
+
cursor += 1;
|
|
7556
|
+
if (cursor === nameStart) {
|
|
7557
|
+
output += openingTag.slice(attributeStart, cursor + 1);
|
|
7558
|
+
cursor += 1;
|
|
7559
|
+
continue;
|
|
7560
|
+
}
|
|
7561
|
+
const name = openingTag.slice(nameStart, cursor).toLowerCase();
|
|
7562
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7563
|
+
cursor += 1;
|
|
7564
|
+
if (openingTag[cursor] === '=') {
|
|
7565
|
+
cursor += 1;
|
|
7566
|
+
while (cursor < limit && /\s/.test(openingTag[cursor]))
|
|
7567
|
+
cursor += 1;
|
|
7568
|
+
const quote = openingTag[cursor] === '"' || openingTag[cursor] === "'" ? openingTag[cursor] : '';
|
|
7569
|
+
if (quote) {
|
|
7570
|
+
cursor += 1;
|
|
7571
|
+
while (cursor < limit && openingTag[cursor] !== quote)
|
|
7572
|
+
cursor += 1;
|
|
7573
|
+
if (openingTag[cursor] === quote)
|
|
7574
|
+
cursor += 1;
|
|
7575
|
+
}
|
|
7576
|
+
else {
|
|
7577
|
+
while (cursor < limit && !/[\s>]/.test(openingTag[cursor]))
|
|
7578
|
+
cursor += 1;
|
|
7579
|
+
}
|
|
7580
|
+
}
|
|
7581
|
+
if (name !== 'nonce')
|
|
7582
|
+
output += openingTag.slice(attributeStart, cursor);
|
|
7583
|
+
}
|
|
7584
|
+
return output + openingTag.slice(limit);
|
|
7585
|
+
}
|
|
7586
|
+
function withNonce(openingTag, nonce) {
|
|
7587
|
+
const withoutNonce = removeNonceAttribute(openingTag);
|
|
7588
|
+
return `${withoutNonce.slice(0, -1)} nonce="${escapeAttribute(nonce)}">`;
|
|
7589
|
+
}
|
|
7590
|
+
function prepareNavigationHtml(html) {
|
|
7591
|
+
if (expressionRuntimeMode() !== 'csp')
|
|
7592
|
+
return html;
|
|
7593
|
+
const activeNonce = resolveCspNonce();
|
|
7594
|
+
const lowerHtml = html.toLowerCase();
|
|
7595
|
+
let output = '';
|
|
7596
|
+
let cursor = 0;
|
|
7597
|
+
let skippedStyles = 0;
|
|
7598
|
+
while (cursor < html.length) {
|
|
7599
|
+
const tagStart = html.indexOf('<', cursor);
|
|
7600
|
+
if (tagStart === -1) {
|
|
7601
|
+
output += html.slice(cursor);
|
|
7602
|
+
break;
|
|
7603
|
+
}
|
|
7604
|
+
output += html.slice(cursor, tagStart);
|
|
7605
|
+
if (html.startsWith('<!--', tagStart)) {
|
|
7606
|
+
const commentEnd = html.indexOf('-->', tagStart + 4);
|
|
7607
|
+
const end = commentEnd === -1 ? html.length : commentEnd + 3;
|
|
7608
|
+
output += html.slice(tagStart, end);
|
|
7609
|
+
cursor = end;
|
|
7610
|
+
continue;
|
|
7611
|
+
}
|
|
7612
|
+
const tagEnd = findTagEnd(html, tagStart + 1);
|
|
7613
|
+
const openingTag = html.slice(tagStart, tagEnd);
|
|
7614
|
+
const match = /^<\s*(\/?)\s*([a-z][\w:-]*)/i.exec(openingTag);
|
|
7615
|
+
if (!match || match[1]) {
|
|
7616
|
+
output += openingTag;
|
|
7617
|
+
cursor = tagEnd;
|
|
7618
|
+
continue;
|
|
7619
|
+
}
|
|
7620
|
+
const name = match[2].toLowerCase();
|
|
7621
|
+
if (name === 'plaintext') {
|
|
7622
|
+
output += html.slice(tagStart);
|
|
7623
|
+
break;
|
|
7624
|
+
}
|
|
7625
|
+
if (name === 'style' || name === 'noscript' || RAW_TEXT_ELEMENTS.has(name)) {
|
|
7626
|
+
const closingTag = findClosingTag(html, lowerHtml, name, tagEnd);
|
|
7627
|
+
const blockEnd = closingTag?.end ?? html.length;
|
|
7628
|
+
if (name === 'noscript') {
|
|
7629
|
+
cursor = blockEnd;
|
|
7630
|
+
continue;
|
|
7631
|
+
}
|
|
7632
|
+
if (name === 'style') {
|
|
7633
|
+
if (!activeNonce) {
|
|
7634
|
+
skippedStyles += 1;
|
|
7635
|
+
cursor = blockEnd;
|
|
7636
|
+
continue;
|
|
7637
|
+
}
|
|
7638
|
+
output += withNonce(openingTag, activeNonce);
|
|
7639
|
+
output += html.slice(tagEnd, blockEnd);
|
|
7640
|
+
cursor = blockEnd;
|
|
7641
|
+
continue;
|
|
7642
|
+
}
|
|
7643
|
+
output += html.slice(tagStart, blockEnd);
|
|
7644
|
+
cursor = blockEnd;
|
|
7645
|
+
continue;
|
|
7395
7646
|
}
|
|
7647
|
+
output += openingTag;
|
|
7648
|
+
cursor = tagEnd;
|
|
7649
|
+
}
|
|
7650
|
+
if (skippedStyles > 0) {
|
|
7651
|
+
console.warn(`[GyosJS CSP] Skipped ${skippedStyles} inline MPA style${skippedStyles === 1 ? '' : 's'} because no active document nonce is configured.`);
|
|
7396
7652
|
}
|
|
7653
|
+
return output;
|
|
7397
7654
|
}
|
|
7398
7655
|
|
|
7399
7656
|
/**
|
|
@@ -7459,7 +7716,10 @@ function stripInertFallbackContent(root) {
|
|
|
7459
7716
|
root.querySelectorAll('noscript').forEach(element => element.remove());
|
|
7460
7717
|
}
|
|
7461
7718
|
function parseNavigationDocument(html) {
|
|
7462
|
-
|
|
7719
|
+
// Chromium applies the active page CSP while DOMParser creates response
|
|
7720
|
+
// styles. Reconcile their nonce before parsing to avoid transient violations;
|
|
7721
|
+
// diffNodes repeats the check before insertion into the live document.
|
|
7722
|
+
const doc = new DOMParser().parseFromString(prepareNavigationHtml(html), 'text/html');
|
|
7463
7723
|
// DOMParser disables scripting and parses noscript children as active markup.
|
|
7464
7724
|
// A boosted page runs with scripting enabled, so those fallbacks must stay inert.
|
|
7465
7725
|
stripInertFallbackContent(doc);
|
|
@@ -8231,7 +8491,7 @@ function onPopState(event) {
|
|
|
8231
8491
|
});
|
|
8232
8492
|
}
|
|
8233
8493
|
|
|
8234
|
-
//
|
|
8494
|
+
// Shared public surface used by the standard and CSP entries.
|
|
8235
8495
|
// Default export remains for convenience (no side effects here)
|
|
8236
8496
|
const Gyos = {
|
|
8237
8497
|
scope,
|
|
@@ -8294,8 +8554,11 @@ const Gyos = {
|
|
|
8294
8554
|
onAfterNavigate,
|
|
8295
8555
|
portalCreate,
|
|
8296
8556
|
portalDestroy,
|
|
8297
|
-
|
|
8557
|
+
setCspNonce,
|
|
8558
|
+
version: '0.3.1'
|
|
8298
8559
|
};
|
|
8299
8560
|
|
|
8300
|
-
|
|
8561
|
+
setExpressionRuntime(standardExpressionRuntime);
|
|
8562
|
+
|
|
8563
|
+
export { applyDirective, applyTransitionStyles, batch, disposeEffects as cleanup, clearAllEvents, computed, debounce, Gyos as default, directive, effect, emit, getEventListeners, getGlobalContainer, getStoreNames, getTransitionConfig, getValidator, getValidatorNames, hasStore, inject, isComputed, isSignal, markRaw, mount, mountAll, mountTree, getAllMountedScopes as mountedScopes, nextTick, off, on, onAfterNavigate, onBeforeNavigate, once, pipe, portalCreate, portalDestroy, provide, ready, registerTransition, removeStore, scope, setCspNonce, shallow, signal, startRouter, store, throttle, unref, untrack, useAsync, useCounter, useDebounce, useFetch, useInterval, useLocalStorage, useMediaQuery, useMouse, useThrottle, useTimeout, useToggle, useWindowSize, validate, validator };
|
|
8301
8564
|
//# sourceMappingURL=gyos.esm.js.map
|