@gramlot/gramlot 0.2.3 → 0.2.4
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/gramlot.js
CHANGED
|
@@ -22005,6 +22005,26 @@ function requireNoScriptAttributes(node, attrs, prefixes = []) {
|
|
|
22005
22005
|
function isJavascriptUrl(value) {
|
|
22006
22006
|
return typeof value === "string" && /^javascript:/i.test(value.replace(/[\t\n\r]/g, "").replace(/^[\u0000-\u0020]+/, ""));
|
|
22007
22007
|
}
|
|
22008
|
+
function withDataSrcdocSandbox(node, attrs, prefixes = []) {
|
|
22009
|
+
if (node.nodeTag !== "iframe") return attrs;
|
|
22010
|
+
const bare = (name) => {
|
|
22011
|
+
const prefix = prefixes.find((candidate) => name.startsWith(candidate)) ?? "";
|
|
22012
|
+
return [prefix, name.slice(prefix.length).toLowerCase()];
|
|
22013
|
+
};
|
|
22014
|
+
const declared = Object.fromEntries(sourceAttributeItems(node.getAttr()));
|
|
22015
|
+
const srcdoc = [...Object.keys(declared), ...Object.keys(attrs)].find((name) => bare(name)[1] === "srcdoc");
|
|
22016
|
+
if (srcdoc === void 0 || Object.keys(declared).some((name) => bare(name)[1] === "sandbox")) return attrs;
|
|
22017
|
+
const fromData = (name, seen) => {
|
|
22018
|
+
const raw = declared[name];
|
|
22019
|
+
seen.add(name);
|
|
22020
|
+
return node.pointerType(raw) !== null || isExpression2(raw) || templateParameters(raw).some((param) => Object.hasOwn(declared, param) && !seen.has(param) && fromData(param, seen));
|
|
22021
|
+
};
|
|
22022
|
+
if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc) && fromData(srcdoc, /* @__PURE__ */ new Set()))) {
|
|
22023
|
+
return attrs;
|
|
22024
|
+
}
|
|
22025
|
+
const rest = Object.fromEntries(Object.entries(attrs).filter(([name]) => bare(name)[1] !== "sandbox"));
|
|
22026
|
+
return { [`${bare(srcdoc)[0]}sandbox`]: "", ...rest };
|
|
22027
|
+
}
|
|
22008
22028
|
function withoutNullValues(attrs) {
|
|
22009
22029
|
return Object.fromEntries(Object.entries(attrs).filter(([, value]) => value != null));
|
|
22010
22030
|
}
|
|
@@ -22166,12 +22186,13 @@ var GramlotHtmlRenderer = class extends HtmlRenderer {
|
|
|
22166
22186
|
* Builder's meta; then the noConvertStyle attributes of the tag are set aside, because adaptAttrs
|
|
22167
22187
|
* has no tag. A sub-builder boundary node keeps its attributes literal, with the Gramlot filters and
|
|
22168
22188
|
* names; the `html` boundary inside SVG is a `foreignObject` in the SVG namespace. No attribute
|
|
22169
|
-
* makes the browser run a text: no `on<event>`, no `javascript:` URL
|
|
22189
|
+
* makes the browser run a text: no `on<event>`, no `javascript:` URL, no `srcdoc` from Data without `sandbox`.
|
|
22170
22190
|
*/
|
|
22171
22191
|
_handleMeta(node, runtimeAttrs) {
|
|
22192
|
+
const prefixes = this.builder.constructor.dialectPrefixes;
|
|
22172
22193
|
const evaluated = this.evaluateExpressions(node, runtimeAttrs);
|
|
22173
|
-
requireNoScriptAttributes(node, evaluated,
|
|
22174
|
-
const [tag2, attrs] = super._handleMeta(node, evaluated);
|
|
22194
|
+
requireNoScriptAttributes(node, evaluated, prefixes);
|
|
22195
|
+
const [tag2, attrs] = super._handleMeta(node, withDataSrcdocSandbox(node, evaluated, prefixes));
|
|
22175
22196
|
if (node._getMeta("subbuilder")) {
|
|
22176
22197
|
const boundary = boundaryAttributes(attrs);
|
|
22177
22198
|
if (node._getMeta("subbuilder") === "html") boundary.xmlns = SVG_NS;
|
|
@@ -23148,7 +23169,9 @@ var HtmlElement = class {
|
|
|
23148
23169
|
if (textValue2 === DEFAULT_TEXT) textValue2 = this.text(node);
|
|
23149
23170
|
const nextText = textValue2 == null ? "" : String(textValue2);
|
|
23150
23171
|
if (text.data !== nextText) text.data = nextText;
|
|
23151
|
-
|
|
23172
|
+
const keys = [.../* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(attrs)])];
|
|
23173
|
+
keys.sort((a, b) => (b === "sandbox") - (a === "sandbox"));
|
|
23174
|
+
for (const key of keys) {
|
|
23152
23175
|
if (this.metadataAttributes.has(key) || controlled && key === "value") continue;
|
|
23153
23176
|
const value = attrs[key];
|
|
23154
23177
|
const attrName = key;
|
package/package.json
CHANGED
|
@@ -64,6 +64,36 @@ function isJavascriptUrl(value) {
|
|
|
64
64
|
return typeof value === 'string' && /^javascript:/i.test(value.replace(/[\t\n\r]/g, '').replace(/^[\u0000-\u0020]+/, ''));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* `attrs` of an `iframe` whose `srcdoc` comes from Data, with an empty `sandbox` first: the browser shows
|
|
69
|
+
* the HTML of a datum and runs nothing of it. `srcdoc` comes from Data when it is a `^`/`=` pointer, a `==`
|
|
70
|
+
* expression or a `${…}` template reading one, or when the node value is a pointer, whose datum can carry
|
|
71
|
+
* `srcdoc` in its `_wdg`. The declaration decides, so the iframe has `sandbox` while `srcdoc` is still null.
|
|
72
|
+
* A `sandbox` declared in the Source stays as declared; a literal `srcdoc` gets none. The names are read
|
|
73
|
+
* without the dialect `prefixes` (`html_`); `sandbox` takes the prefix of `srcdoc`.
|
|
74
|
+
*/
|
|
75
|
+
export function withDataSrcdocSandbox(node, attrs, prefixes = []) {
|
|
76
|
+
if (node.nodeTag !== 'iframe') return attrs;
|
|
77
|
+
const bare = name => {
|
|
78
|
+
const prefix = prefixes.find(candidate => name.startsWith(candidate)) ?? '';
|
|
79
|
+
return [prefix, name.slice(prefix.length).toLowerCase()];
|
|
80
|
+
};
|
|
81
|
+
const declared = Object.fromEntries(sourceAttributeItems(node.getAttr()));
|
|
82
|
+
const srcdoc = [...Object.keys(declared), ...Object.keys(attrs)].find(name => bare(name)[1] === 'srcdoc');
|
|
83
|
+
if (srcdoc === undefined || Object.keys(declared).some(name => bare(name)[1] === 'sandbox')) return attrs;
|
|
84
|
+
const fromData = (name, seen) => {
|
|
85
|
+
const raw = declared[name];
|
|
86
|
+
seen.add(name);
|
|
87
|
+
return node.pointerType(raw) !== null || isExpression(raw) || templateParameters(raw)
|
|
88
|
+
.some(param => Object.hasOwn(declared, param) && !seen.has(param) && fromData(param, seen));
|
|
89
|
+
};
|
|
90
|
+
if (node.pointerType(node.value) === null && !(Object.hasOwn(declared, srcdoc) && fromData(srcdoc, new Set()))) {
|
|
91
|
+
return attrs;
|
|
92
|
+
}
|
|
93
|
+
const rest = Object.fromEntries(Object.entries(attrs).filter(([name]) => bare(name)[1] !== 'sandbox'));
|
|
94
|
+
return {[`${bare(srcdoc)[0]}sandbox`]: '', ...rest};
|
|
95
|
+
}
|
|
96
|
+
|
|
67
97
|
/** The attributes of `attrs` whose value is neither null nor undefined. */
|
|
68
98
|
export function withoutNullValues(attrs) {
|
|
69
99
|
return Object.fromEntries(Object.entries(attrs).filter(([, value]) => value != null));
|
|
@@ -2,7 +2,8 @@ import {HtmlBuilder, HtmlRenderer, SvgBuilder, sourceAttributeItems} from '@genr
|
|
|
2
2
|
import {GramlotSvgRenderer} from './gramlot-svg-renderer.js';
|
|
3
3
|
import {
|
|
4
4
|
SVG_NS, XHTML_NS, boundaryAttributes, displayItem, domNames, isExpression, requireNoExpressionTemplate,
|
|
5
|
-
requireNoScriptAttributes, splitNativeAttributes, textValue,
|
|
5
|
+
requireNoScriptAttributes, splitNativeAttributes, textValue, withDataSrcdocSandbox, withoutBindingAttributes,
|
|
6
|
+
withoutNullValues,
|
|
6
7
|
} from './attributes.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -39,12 +40,13 @@ export class GramlotHtmlRenderer extends HtmlRenderer {
|
|
|
39
40
|
* Builder's meta; then the noConvertStyle attributes of the tag are set aside, because adaptAttrs
|
|
40
41
|
* has no tag. A sub-builder boundary node keeps its attributes literal, with the Gramlot filters and
|
|
41
42
|
* names; the `html` boundary inside SVG is a `foreignObject` in the SVG namespace. No attribute
|
|
42
|
-
* makes the browser run a text: no `on<event>`, no `javascript:` URL
|
|
43
|
+
* makes the browser run a text: no `on<event>`, no `javascript:` URL, no `srcdoc` from Data without `sandbox`.
|
|
43
44
|
*/
|
|
44
45
|
_handleMeta(node, runtimeAttrs) {
|
|
46
|
+
const prefixes = this.builder.constructor.dialectPrefixes;
|
|
45
47
|
const evaluated = this.evaluateExpressions(node, runtimeAttrs);
|
|
46
|
-
requireNoScriptAttributes(node, evaluated,
|
|
47
|
-
const [tag, attrs] = super._handleMeta(node, evaluated);
|
|
48
|
+
requireNoScriptAttributes(node, evaluated, prefixes);
|
|
49
|
+
const [tag, attrs] = super._handleMeta(node, withDataSrcdocSandbox(node, evaluated, prefixes));
|
|
48
50
|
if (node._getMeta('subbuilder')) {
|
|
49
51
|
const boundary = boundaryAttributes(attrs);
|
|
50
52
|
if (node._getMeta('subbuilder') === 'html') boundary.xmlns = SVG_NS;
|
package/src/view/html.js
CHANGED
|
@@ -112,7 +112,10 @@ export class HtmlElement {
|
|
|
112
112
|
if (textValue === DEFAULT_TEXT) textValue = this.text(node);
|
|
113
113
|
const nextText = textValue == null ? '' : String(textValue);
|
|
114
114
|
if (text.data !== nextText) text.data = nextText;
|
|
115
|
-
|
|
115
|
+
const keys = [...new Set([...Object.keys(previous), ...Object.keys(attrs)])];
|
|
116
|
+
// The browser reads `sandbox` when `src` or `srcdoc` starts a navigation: `sandbox` is written first.
|
|
117
|
+
keys.sort((a, b) => (b === 'sandbox') - (a === 'sandbox'));
|
|
118
|
+
for (const key of keys) {
|
|
116
119
|
if (this.metadataAttributes.has(key) || (controlled && key === 'value')) continue;
|
|
117
120
|
const value = attrs[key];
|
|
118
121
|
const attrName = key;
|