@scrider/formatter 1.6.2 → 1.7.0
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/index.cjs +22 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -6
- package/dist/index.d.ts +42 -6
- package/dist/index.js +22 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2001,7 +2001,7 @@ var EMBED_RENDERERS = {
|
|
|
2001
2001
|
const float = floatVal != null && typeof floatVal === "string" && floatVal !== "none" ? ` data-float="${escapeHtml(floatVal)}"` : "";
|
|
2002
2002
|
return `<img src="${escapeHtml(src)}"${alt}${width}${height}${float}>`;
|
|
2003
2003
|
},
|
|
2004
|
-
video: (value, attrs) => {
|
|
2004
|
+
video: (value, attrs, context) => {
|
|
2005
2005
|
const src = typeof value === "string" ? value : "";
|
|
2006
2006
|
const floatVal = attrs?.float;
|
|
2007
2007
|
const widthVal = attrs?.width;
|
|
@@ -2019,11 +2019,11 @@ var EMBED_RENDERERS = {
|
|
|
2019
2019
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
2020
2020
|
const embedSrc = toVideoEmbedUrl(src);
|
|
2021
2021
|
if (embedSrc) {
|
|
2022
|
-
return `<iframe src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen
|
|
2022
|
+
return `<iframe src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "video")}${float}${style}></iframe>`;
|
|
2023
2023
|
}
|
|
2024
2024
|
return `<video src="${escapeHtml(src)}" controls${float}${style}></video>`;
|
|
2025
2025
|
},
|
|
2026
|
-
codeWidget: (value, attrs) => {
|
|
2026
|
+
codeWidget: (value, attrs, context) => {
|
|
2027
2027
|
const src = typeof value === "string" ? value : "";
|
|
2028
2028
|
const floatVal = attrs?.float;
|
|
2029
2029
|
const widthVal = attrs?.width;
|
|
@@ -2040,7 +2040,7 @@ var EMBED_RENDERERS = {
|
|
|
2040
2040
|
}
|
|
2041
2041
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
2042
2042
|
const embedSrc = toCodeWidgetEmbedUrl(src);
|
|
2043
|
-
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen
|
|
2043
|
+
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
2044
2044
|
},
|
|
2045
2045
|
formula: (value) => {
|
|
2046
2046
|
const latex = typeof value === "string" ? value : "";
|
|
@@ -2161,6 +2161,17 @@ function appendQueryParam(url, key, value) {
|
|
|
2161
2161
|
return `${base}${next}${hash}`;
|
|
2162
2162
|
}
|
|
2163
2163
|
var CODE_WIDGET_IFRAME_ALLOW = "accelerometer; camera; encrypted-media; geolocation; gyroscope; microphone; midi; payment; usb; vr; xr-spatial-tracking; cross-origin-isolated";
|
|
2164
|
+
function renderEmbedIframeIsolationAttrs(context, kind) {
|
|
2165
|
+
const opts = context?.embed;
|
|
2166
|
+
const parts = [];
|
|
2167
|
+
if (kind === "codeWidget" && opts?.crossOriginIsolated) {
|
|
2168
|
+
parts.push(`allow="${CODE_WIDGET_IFRAME_ALLOW}"`);
|
|
2169
|
+
}
|
|
2170
|
+
if (opts?.credentialless) {
|
|
2171
|
+
parts.push("credentialless");
|
|
2172
|
+
}
|
|
2173
|
+
return parts.length ? ` ${parts.join(" ")}` : "";
|
|
2174
|
+
}
|
|
2164
2175
|
function toCodeWidgetEmbedUrl(url) {
|
|
2165
2176
|
const u = typeof url === "string" ? url.trim() : "";
|
|
2166
2177
|
if (!u) return "";
|
|
@@ -2212,7 +2223,7 @@ var codeWidgetFormat = {
|
|
|
2212
2223
|
return false;
|
|
2213
2224
|
}
|
|
2214
2225
|
},
|
|
2215
|
-
render(value, attributes) {
|
|
2226
|
+
render(value, attributes, context) {
|
|
2216
2227
|
const src = typeof value === "string" ? value : "";
|
|
2217
2228
|
const floatVal = attributes?.float;
|
|
2218
2229
|
const widthVal = attributes?.width;
|
|
@@ -2229,7 +2240,7 @@ var codeWidgetFormat = {
|
|
|
2229
2240
|
}
|
|
2230
2241
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
2231
2242
|
const embedSrc = toCodeWidgetEmbedUrl(src);
|
|
2232
|
-
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen
|
|
2243
|
+
return `<iframe data-code-widget src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "codeWidget")}${float}${style}></iframe>`;
|
|
2233
2244
|
},
|
|
2234
2245
|
match(element) {
|
|
2235
2246
|
if (element.tagName.toLowerCase() !== "iframe") return null;
|
|
@@ -2475,7 +2486,7 @@ var videoFormat = {
|
|
|
2475
2486
|
return false;
|
|
2476
2487
|
}
|
|
2477
2488
|
},
|
|
2478
|
-
render(value, attributes) {
|
|
2489
|
+
render(value, attributes, context) {
|
|
2479
2490
|
const src = typeof value === "string" ? value : "";
|
|
2480
2491
|
const floatVal = attributes?.float;
|
|
2481
2492
|
const widthVal = attributes?.width;
|
|
@@ -2493,7 +2504,7 @@ var videoFormat = {
|
|
|
2493
2504
|
const style = styles.length > 0 ? ` style="${styles.join("; ")}"` : "";
|
|
2494
2505
|
const embedSrc = toVideoEmbedUrl(src);
|
|
2495
2506
|
if (embedSrc) {
|
|
2496
|
-
return `<iframe src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen
|
|
2507
|
+
return `<iframe src="${escapeHtml(embedSrc)}" frameborder="0" allowfullscreen${renderEmbedIframeIsolationAttrs(context, "video")}${float}${style}></iframe>`;
|
|
2497
2508
|
}
|
|
2498
2509
|
return `<video src="${escapeHtml(src)}" controls${float}${style}></video>`;
|
|
2499
2510
|
},
|
|
@@ -3498,16 +3509,17 @@ function renderEmbed(value, attributes, renderers, blockHandlers, options) {
|
|
|
3498
3509
|
return "";
|
|
3499
3510
|
}
|
|
3500
3511
|
const embedValue = value[embedType];
|
|
3512
|
+
const embedContext = options?.embed != null ? { embed: options.embed } : {};
|
|
3501
3513
|
const registry = options?.registry;
|
|
3502
3514
|
if (registry) {
|
|
3503
3515
|
const format = registry.get(embedType);
|
|
3504
3516
|
if (format?.render) {
|
|
3505
|
-
return format.render(embedValue, attributes);
|
|
3517
|
+
return format.render(embedValue, attributes, embedContext);
|
|
3506
3518
|
}
|
|
3507
3519
|
}
|
|
3508
3520
|
const renderer = renderers[embedType];
|
|
3509
3521
|
if (renderer) {
|
|
3510
|
-
return renderer(embedValue, attributes);
|
|
3522
|
+
return renderer(embedValue, attributes, embedContext);
|
|
3511
3523
|
}
|
|
3512
3524
|
return `<span data-embed="${escapeHtml(embedType)}" data-value="${escapeHtml(String(embedValue))}"></span>`;
|
|
3513
3525
|
}
|