@openpresentation/opf-render 0.36.0 → 0.37.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/README.md +3 -3
- package/dist/chart-options.js +3 -2
- package/dist/charts.js +163 -15
- package/dist/deck-runtime.js +17 -0
- package/dist/element.js +10 -2
- package/dist/font-compatibility.js +24 -0
- package/dist/fonts.d.ts +3 -0
- package/dist/fonts.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/live-embeds.d.ts +38 -0
- package/dist/live-embeds.js +93 -0
- package/dist/pdf-vector.js +37 -4
- package/dist/player.d.ts +6 -0
- package/dist/player.js +23 -5
- package/dist/preview-fonts-node.js +1 -1
- package/dist/script-fonts.js +67 -2
- package/dist/shapes.js +11 -1
- package/dist/svg.d.ts +2 -0
- package/dist/svg.js +115 -14
- package/package.json +8 -4
package/dist/svg.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
layoutTable, fitList, fitRichText, composeSlide, emphasisSurface, resolveTextStyle, textWidthMeasurer, fitText, styledText, LIST_RULE_WIDTH, LIST_ACCENT_RULE_WIDTH, textColorForFill, chartColorForFill,
|
|
5
5
|
resolveColorRef as resolveCoreColorRef, colorTransform, applyColorTransform, stackedText, resolveScriptFonts, paragraphDirection, physicalAlignment, itemAlignment, patternRuns, isolateNumbers,
|
|
6
|
-
metricTrendMark as coreMetricTrendMark, metricPillFill, metricValueColor, tokenizeCode, codeLineRuns, codeSyntaxPaletteForRoles, readableSchemeColor, resolveChartData,
|
|
6
|
+
metricTrendMark as coreMetricTrendMark, metricPillFill, metricValueColor, metricGaugeDrawing, tokenizeCode, codeLineRuns, codeSyntaxPaletteForRoles, readableSchemeColor, resolveChartData,
|
|
7
7
|
timelineMarkerShapes, timelineTextColor, layoutWatermark, tableHighlightColor,
|
|
8
8
|
arrangementPaint, colorContrast,
|
|
9
9
|
codeHighlightLines, codeLineNumbers, codeHighlightBands, codeHighlightColors, fitImage, pictureOverlay, intrinsicImageAspect, intrinsicImageSize, diagramPalette, paintDiagramGroup, iconPathData,
|
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
// The renderer is a library: it never imports a catalog. Hosts register theirs (`options.catalogs`, core `Catalog[]`, for
|
|
13
13
|
// example `defaultCatalog` from `@openpresentation/gallery`) and core resolves every reference against them.
|
|
14
14
|
import {
|
|
15
|
+
collectSlideLinks,
|
|
16
|
+
embedCardLayout,
|
|
17
|
+
embedSite,
|
|
18
|
+
embedTitle,
|
|
19
|
+
embedValue,
|
|
15
20
|
hasContentVariables,
|
|
16
21
|
isTemplate,
|
|
17
22
|
resolveDrawnFontFamilies,
|
|
@@ -25,7 +30,7 @@ import { fontPolicyFor } from "@openpresentation/opf/font-policy";
|
|
|
25
30
|
import { disabledFeaturesStyle } from "./font-compatibility.js";
|
|
26
31
|
import { isDatasetChart, isDatasetTable, renderCatalogChart } from "./charts.js";
|
|
27
32
|
import { renderCaption, renderFootnotes } from "./annotations.js";
|
|
28
|
-
import { renderConnector, renderShapeBlock, strokeElements } from "./shapes.js";
|
|
33
|
+
import { linkAnchorAttrs, renderConnector, renderShapeBlock, strokeElements } from "./shapes.js";
|
|
29
34
|
import { drawnFaces } from "./drawn-faces.js";
|
|
30
35
|
import { dataUrlFsType, embeddingAllowed } from "./font-fstype.js";
|
|
31
36
|
import { rejectRenamedOptions, selectSlides } from "./slide-sources.js";
|
|
@@ -80,6 +85,7 @@ const ROOT_PAYLOAD_FIELDS = [
|
|
|
80
85
|
"bullets",
|
|
81
86
|
"image",
|
|
82
87
|
"video",
|
|
88
|
+
"embed",
|
|
83
89
|
"chart",
|
|
84
90
|
"table",
|
|
85
91
|
"code",
|
|
@@ -94,6 +100,7 @@ const FIELD_TYPE = Object.freeze({
|
|
|
94
100
|
bullets: "list",
|
|
95
101
|
image: "image",
|
|
96
102
|
video: "video",
|
|
103
|
+
embed: "embed",
|
|
97
104
|
chart: "chart",
|
|
98
105
|
table: "table",
|
|
99
106
|
code: "code",
|
|
@@ -309,7 +316,15 @@ function untrackLast(content) {
|
|
|
309
316
|
}
|
|
310
317
|
const sameBox = (a, b) => !!a && !!b && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
311
318
|
|
|
312
|
-
const LINK_URL = /^(https?:|mailto:|tel:)/i;
|
|
319
|
+
const LINK_URL = /^(https?:|mailto:|tel:|slide:)/i;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* FR-03: whether a link opens outside the deck: the schemes the renderer draws as a link except `slide:<id>` (a viewer shows that slide itself).
|
|
323
|
+
* A host that opens links for a read-only slide view asks this and ignores every other address (a `javascript:` or `data:` link is never opened).
|
|
324
|
+
*/
|
|
325
|
+
export function isOpenableLink(href) {
|
|
326
|
+
return typeof href === "string" && LINK_URL.test(href) && !/^slide:/i.test(href);
|
|
327
|
+
}
|
|
313
328
|
|
|
314
329
|
// What the renderer paints with, from the records core's `resolveSlideContext` resolved (slide design, then deck design, then
|
|
315
330
|
// theme, then the engine default, per field: the one order every engine uses). The theme and the color scheme keep their
|
|
@@ -667,6 +682,11 @@ export function toSvg(input, slides, options) {
|
|
|
667
682
|
return numbers.map(number => renderResolvedSlide(resolved, number - 1, drawn));
|
|
668
683
|
}
|
|
669
684
|
|
|
685
|
+
// FR-03: the ids the slide links of the deck name, collected once per resolved deck.
|
|
686
|
+
function linkedSlideIds(resolved) {
|
|
687
|
+
return (resolved.slideLinkIds ??= new Set(collectSlideLinks(resolved.presentation.slides).map(entry => entry.id)));
|
|
688
|
+
}
|
|
689
|
+
|
|
670
690
|
function renderResolvedSlide(resolved, slideIndex, options) {
|
|
671
691
|
const bound = resolved.slides[slideIndex];
|
|
672
692
|
// Paint with the same script-aware measurement composition used.
|
|
@@ -717,6 +737,8 @@ function renderResolvedSlide(resolved, slideIndex, options) {
|
|
|
717
737
|
role: "group",
|
|
718
738
|
"aria-roledescription": "slide",
|
|
719
739
|
"aria-label": title,
|
|
740
|
+
// FR-03: the id of a slide another slide links to (`slide:<id>`), so a PDF page knows which slide it is. Other slides stay as they were.
|
|
741
|
+
"data-opf-slide": linkedSlideIds(resolved).has(bound.slide.id) ? bound.slide.id : undefined,
|
|
720
742
|
viewBox: `0 0 ${width} ${height}`,
|
|
721
743
|
width,
|
|
722
744
|
height,
|
|
@@ -1108,6 +1130,8 @@ function renderPayload(item, box, bound, options) {
|
|
|
1108
1130
|
return renderShapeBlock(item, shapeHelpers(item, bound, options));
|
|
1109
1131
|
case "video":
|
|
1110
1132
|
return renderMedia(item, box, bound, options);
|
|
1133
|
+
case "embed":
|
|
1134
|
+
return renderEmbed(item, box, bound, options);
|
|
1111
1135
|
case "code":
|
|
1112
1136
|
return renderCode(item, box, bound, options);
|
|
1113
1137
|
case "metric":
|
|
@@ -1127,7 +1151,8 @@ function renderPayload(item, box, bound, options) {
|
|
|
1127
1151
|
|
|
1128
1152
|
function renderTextPayload(item, box, bound, options) {
|
|
1129
1153
|
// LH-63: a text whose first line is a run-in heading draws core's runs (item.runs: the same characters, the heading bold).
|
|
1130
|
-
|
|
1154
|
+
// The runs draw only with a fit core laid out from them (richLines); a plain fit draws the authored value.
|
|
1155
|
+
const value = item.runs && (!item.text || "richLines" in item.text) ? item.runs : item.value;
|
|
1131
1156
|
return (Array.isArray(value) ? renderRichTextBox : renderTextBox)(Array.isArray(value) ? value : flattenText(value), box, bound, {
|
|
1132
1157
|
path: item.path,
|
|
1133
1158
|
// Core resolves one alignment per composed item for every engine, from the slide's design, the deck's design
|
|
@@ -1164,7 +1189,7 @@ function renderList(item, box, bound, options) {
|
|
|
1164
1189
|
return tag('g',{...traceAttrs(options,item.path),...(item.listColumns.some(column=>column.text.overflow)?{'data-opf-overflow':'true'}:{})},columns.join('\n'));
|
|
1165
1190
|
}
|
|
1166
1191
|
const scale=Math.min(bound.design.dimensions.width,bound.design.dimensions.height)/720;
|
|
1167
|
-
const fit=item.text?.listEntries?item.text:fitList(item.value,box,25*scale,((bound.composition??bound.geometry.composition).
|
|
1192
|
+
const fit=item.text?.listEntries?item.text:fitList(item.value,box,25*scale,((bound.composition??bound.geometry.composition).minFontSizePx??16)*scale,{style:{fontFamily:bound.design.fonts.body,fontWeight:400,path:item.path},...(bound.design.fonts.code?{codeFontFamily:bound.design.fonts.code}:{}),textMeasurement:options.textMeasurement,...(item.payload?.numbering!==undefined?{numbering:item.payload.numbering}:{})});
|
|
1168
1193
|
return tag('g',{...traceAttrs(options,item.path),...(fit.overflow?{'data-opf-overflow':'true'}:{})},listEntriesSvg(item,fit,bound,options).join('\n'));
|
|
1169
1194
|
}
|
|
1170
1195
|
|
|
@@ -1445,7 +1470,7 @@ function renderImage(item, box, bound, options) {
|
|
|
1445
1470
|
const description=asset.alt??asset.title??'Image';
|
|
1446
1471
|
const label=`Image unavailable\n${description}`;
|
|
1447
1472
|
const style=resolveTextStyle({fontFamily:bound.design.fonts.body,fontWeight:600,path:item.path},options.textMeasurement);
|
|
1448
|
-
const fit=fitText(label,inner,20*scale,((bound.composition??bound.geometry.composition).
|
|
1473
|
+
const fit=fitText(label,inner,20*scale,((bound.composition??bound.geometry.composition).minFontSizePx??16)*scale,textWidthMeasurer(style,options.textMeasurement));
|
|
1449
1474
|
const textColor=textColorForFill(fill,bound.design.colors.text);
|
|
1450
1475
|
reportDiagnostic({code:'unresolved-asset',path:item.path,message,reason,source:asset.src,assetId:missingReference,description,placeholder:fit.overflow?'icon':'label'},options);
|
|
1451
1476
|
const children = [
|
|
@@ -1540,6 +1565,53 @@ function renderMedia(item, box, bound, options) {
|
|
|
1540
1565
|
return tag("g", traceAttrs(options, item.path), children.join("\n"));
|
|
1541
1566
|
}
|
|
1542
1567
|
|
|
1568
|
+
// FR-08: an embed is drawn as its static form, wherever the page is not shown live: the `preview` picture whole (contain) on the scheme's
|
|
1569
|
+
// surface color, or, without a preview (or one that does not resolve), the card (core embedCardLayout: a link badge, the title and the
|
|
1570
|
+
// site name). The frame is a link to `src` that opens a new tab; a web presenter whose host allows the page reads the frame's
|
|
1571
|
+
// data-opf-embed attributes and puts a sandboxed iframe over it (the engines never load `src`). The transparent rect in the link is
|
|
1572
|
+
// the area a PDF link annotation covers.
|
|
1573
|
+
function renderEmbed(item, box, bound, options) {
|
|
1574
|
+
const embed = embedValue(item.value);
|
|
1575
|
+
if (!embed) return "";
|
|
1576
|
+
const title = embedTitle(item.value), site = embedSite(embed.src), scale = Math.min(bound.design.dimensions.width, bound.design.dimensions.height) / 720;
|
|
1577
|
+
const frame = { x: box.x, y: box.y, width: box.width, height: box.height };
|
|
1578
|
+
const children = [];
|
|
1579
|
+
let picture;
|
|
1580
|
+
if (embed.preview !== undefined) {
|
|
1581
|
+
const resolved = resolveImageSource({ value: embed.preview, path: item.path }, bound, options);
|
|
1582
|
+
if (resolved.drawable) picture = resolved.source;
|
|
1583
|
+
else {
|
|
1584
|
+
const reason = resolved.missingReference ? "missing-reference" : "unsupported-source";
|
|
1585
|
+
const message = unresolvedImageMessage("Embed preview", embed.preview, resolved.missingReference, "the preview draws the embed's card instead");
|
|
1586
|
+
if (options.strictAssets) throw new OPFRenderError("unresolved-asset", message, { path: `${item.path}.preview`, reason });
|
|
1587
|
+
reportDiagnostic({ code: "unresolved-asset", path: `${item.path}.preview`, message, reason, source: embed.preview, assetId: resolved.missingReference, description: title, placeholder: "card" }, options);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
if (picture !== undefined) {
|
|
1591
|
+
children.push(tag("rect", { ...HIDDEN, x: frame.x, y: frame.y, width: frame.width, height: frame.height, fill: bound.design.colors.surface, ...traceAttrs(options, item.path) }));
|
|
1592
|
+
children.push(tag("image", { ...HIDDEN, href: picture, x: frame.x, y: frame.y, width: frame.width, height: frame.height, preserveAspectRatio: "xMidYMid meet" }));
|
|
1593
|
+
} else {
|
|
1594
|
+
const card = embedCardLayout({ frame, title, site, headingFamily: bound.design.fonts.heading, bodyFamily: bound.design.fonts.body, scale,
|
|
1595
|
+
minFontSizePx: (bound.composition ?? bound.geometry.composition).minFontSizePx ?? 16, measurement: options.textMeasurement });
|
|
1596
|
+
children.push(tag("rect", { ...HIDDEN, x: frame.x, y: frame.y, width: frame.width, height: frame.height, rx: stableNumber(card.radius), fill: bound.design.colors.surface, stroke: bound.design.colors.border, "stroke-width": 1, ...traceAttrs(options, item.path) }));
|
|
1597
|
+
children.push(tag("circle", { ...HIDDEN, cx: stableNumber(card.icon.badge.x + card.icon.badge.width / 2), cy: stableNumber(card.icon.badge.y + card.icon.badge.height / 2), r: stableNumber(card.icon.badge.width / 2), fill: bound.design.colors.primary }));
|
|
1598
|
+
children.push(tag("path", { ...HIDDEN, d: `M ${card.icon.points.map(([x, y]) => `${stableNumber(x)} ${stableNumber(y)}`).join(" L ")} Z`, fill: readableSchemeColor(bound.design.colors.primary, bound.design.roles).hex }));
|
|
1599
|
+
for (const [text, fill] of [[card.title, bound.design.colors.text], [card.site, bound.design.colors.mutedText]]) {
|
|
1600
|
+
if (!text) continue;
|
|
1601
|
+
const family = fontStack(text.style.fontFamily, bound.design.fontScheme.type);
|
|
1602
|
+
children.push(tag("g", { "data-opf-embed-text": text === card.title ? "title" : "site" }, text.lines.map((line, index) => tag("text", {
|
|
1603
|
+
x: stableNumber(text.box.x + text.box.width / 2), y: stableNumber(text.box.y + text.fontSize + index * text.lineHeight), "text-anchor": "middle", "font-family": family, "font-size": stableNumber(text.fontSize),
|
|
1604
|
+
"font-weight": text.style.fontWeight === 400 ? undefined : text.style.fontWeight, fill
|
|
1605
|
+
}, escapeText(line))).join("\n")));
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
// The area a link annotation covers, and what a presenter measures to put a live frame over this one.
|
|
1609
|
+
children.push(tag("rect", { ...HIDDEN, "data-opf-link-area": "true", x: frame.x, y: frame.y, width: frame.width, height: frame.height, fill: "none", "pointer-events": "all" }));
|
|
1610
|
+
const link = tag("a", { ...linkAnchorAttrs(embed.src, { newTab: true }), "aria-label": title }, children.join("\n"));
|
|
1611
|
+
return tag("g", { ...traceAttrs(options, item.path), "data-opf-embed": item.path, "data-opf-embed-src": embed.src, "data-opf-embed-title": title,
|
|
1612
|
+
"data-opf-embed-x": stableNumber(frame.x), "data-opf-embed-y": stableNumber(frame.y), "data-opf-embed-width": stableNumber(frame.width), "data-opf-embed-height": stableNumber(frame.height) }, link);
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1543
1615
|
function renderCode(item, box, bound, options) {
|
|
1544
1616
|
const layout = item.codeLayout;
|
|
1545
1617
|
if (!layout) throw new OPFRenderError('missing-code-layout', 'Code rendering requires a coordinated core build with shared code geometry.', {path:item.path});
|
|
@@ -1615,6 +1687,8 @@ function renderMetric(item, box, bound, options) {
|
|
|
1615
1687
|
const pillFill=layout.deltaPill?metricPillFill(backdrop,bound.design.colors.text):undefined;
|
|
1616
1688
|
if (layout.deltaPill) { const pill=layout.deltaPill.box; children.push(tag('rect',{...HIDDEN,x:stableNumber(pill.x),y:stableNumber(pill.y),width:stableNumber(pill.width),height:stableNumber(pill.height),rx:stableNumber(layout.deltaPill.radius),fill:pillFill,...(options.trace?{'data-opf-metric-role':'pill'}:{})})); }
|
|
1617
1689
|
const trendMark=metricTrendMark(layout,bound,pillFill??backdrop);
|
|
1690
|
+
// FR-07, part 3: a gauge (layout.gauge) draws core's plan under the text: the arcs as the blockArc preset's outline, the target tick and the ends' labels.
|
|
1691
|
+
if (layout.gauge) children.push(renderGauge(item,layout.gauge,bound,backdrop,options));
|
|
1618
1692
|
// LH-53: a unit on its value's line is part of the figure and takes the value's color.
|
|
1619
1693
|
// LH-135: a label drawn as the metric's eyebrow takes the eyebrow's color on its backdrop (eyebrowFill), in capitals with core's tracking.
|
|
1620
1694
|
const partFill=part=>trendMark&&(part.role==='trend'||part.role==='delta')?trendMark.color:part.role==='value'||part.role==='unit'&&layout.arrangement==='inline-unit'?metricValueColor(bound.design.colors.primary,backdrop,bound.design.colors.text):layout.eyebrow&&part.role==='label'?eyebrowFill(bound.design,item):bound.design.colors.text;
|
|
@@ -1662,6 +1736,22 @@ function renderMetric(item, box, bound, options) {
|
|
|
1662
1736
|
return tag('g',{...traceAttrs(options,item.path),...(options.trace?{'data-opf-metric-container':'true'}:{})},children.join('\n'));
|
|
1663
1737
|
}
|
|
1664
1738
|
|
|
1739
|
+
// FR-07, part 3: the colors a gauge is drawn in (core metricGaugeDrawing), against the metric's backdrop. The PowerPoint export passes the same.
|
|
1740
|
+
function gaugeColors(bound,backdrop) {
|
|
1741
|
+
const text=bound.design.colors.text;
|
|
1742
|
+
return {surface:backdrop,text,primary:bound.design.colors.primary,muted:bound.design.colors.mutedText,resolve:name=>String(resolveColorRef(name,bound,text)??text).slice(0,7).toUpperCase()};
|
|
1743
|
+
}
|
|
1744
|
+
// FR-07, part 3: a metric's gauge. Each arc is PowerPoint's blockArc preset at its frame and adjustments (core presetGeometry draws its
|
|
1745
|
+
// outline), so the preview draws what the native shapes draw; the target is a line, the ends' labels text centered under the arc's ends.
|
|
1746
|
+
function renderGauge(item,gauge,bound,backdrop,options) {
|
|
1747
|
+
const drawing=metricGaugeDrawing(gauge,gaugeColors(bound,backdrop)),out=[];
|
|
1748
|
+
for (const arc of drawing.arcs) out.push(tag('path',{...HIDDEN,d:arc.d,transform:`translate(${stableNumber(arc.frame.x)} ${stableNumber(arc.frame.y)})`,fill:arc.fill,...(options.trace?{'data-opf-metric-role':'mark','data-opf-gauge-part':arc.part}:{})}));
|
|
1749
|
+
if (drawing.target) { const t=drawing.target; out.push(tag('line',{...HIDDEN,x1:stableNumber(t.x1),y1:stableNumber(t.y1),x2:stableNumber(t.x2),y2:stableNumber(t.y2),stroke:t.color,'stroke-width':stableNumber(t.width),...(options.trace?{'data-opf-metric-role':'mark','data-opf-gauge-part':t.part}:{})})); }
|
|
1750
|
+
for (const {part,color,end} of drawing.ends) out.push(tag('text',{x:stableNumber(end.x),y:stableNumber(end.baseline),'text-anchor':'middle','font-family':fontStack(gauge.endStyle.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(end.fontSize),
|
|
1751
|
+
'font-weight':gauge.endStyle.fontWeight,'xml:space':'preserve',style:'white-space:pre','text-rendering':'geometricPrecision',fill:color,direction:'ltr',...(options.trace?{'data-opf-metric-role':'mark','data-opf-gauge-part':part}:{})},escapeText(end.text)));
|
|
1752
|
+
return tag('g',{...traceAttrs(options,`${item.path}.gauge`)},out.join('\n'));
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1665
1755
|
// The trend arrow and color for a laid-out metric (core metricTrendMark); undefined without a trend.
|
|
1666
1756
|
function metricTrendMark(layout,bound,background) {
|
|
1667
1757
|
return coreMetricTrendMark(layout,{background,neutral:bound.design.roles.neutrals.trendNeutral.hex});
|
|
@@ -1742,9 +1832,14 @@ function renderTimeline(item, box, bound, options) {
|
|
|
1742
1832
|
return tag('g',{...traceAttrs(options,item.path),...(options.trace?{'data-opf-timeline-arrangement':layout.arrangement}:{})},children.join('\n'));
|
|
1743
1833
|
}
|
|
1744
1834
|
|
|
1835
|
+
// FR-07: how a color scale's scheme names resolve on this slide (the same ColorRef resolution fills use), and the slide's text color.
|
|
1836
|
+
function tableScaleColors(bound) {
|
|
1837
|
+
return {resolve:(name) => String(resolveColorRef(name, bound, "#000000")).slice(0, 7).toUpperCase(), text:bound.design.colors.text, background:bound.design.colors.background};
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1745
1840
|
function renderTable(item, box, bound, options) {
|
|
1746
1841
|
const scale = Math.min(bound.design.dimensions.width, bound.design.dimensions.height) / 720;
|
|
1747
|
-
const layout = layoutTable(item.value, box, {scale,
|
|
1842
|
+
const layout = layoutTable(item.value, box, {scale, minFontSizePx:(bound.composition ?? bound.geometry.composition).minFontSizePx, fontFamily:bound.design.fonts.body, ...(bound.design.fonts.code ? {codeFontFamily:bound.design.fonts.code} : {}), textMeasurement:options.textMeasurement, path:item.path, presentation:bound.presentation, ...(typeof bound.scriptFonts?.profile?.bcp47 === "string" ? {language:bound.scriptFonts.profile.bcp47} : {}), alignment:itemAlignment(bound.geometry.design.contentAlignment), ...(bound.geometry?.direction === "rtl" ? {direction:"rtl"} : {}), ...(item.tableGrowth ? {growth:item.tableGrowth} : {}), ...(item.tableHighlight ? {highlight:item.tableHighlight} : {}), ...(item.value?.colorScale ? {colorScale:tableScaleColors(bound)} : {})});
|
|
1748
1843
|
const children = [];
|
|
1749
1844
|
// LH-113: a highlighted row (table.highlight, or the rows the slide's texts name) draws on an accent tint of the surface.
|
|
1750
1845
|
const highlightFill = layout.rows.some((row) => row.cells.some((cell) => cell.highlighted)) ? tableHighlightColor(bound.design.colors.surface, bound.design.colors.primary, bound.design.colors.text) : undefined;
|
|
@@ -1755,11 +1850,12 @@ function renderTable(item, box, bound, options) {
|
|
|
1755
1850
|
const defaultEdges = [], explicitEdges = [];
|
|
1756
1851
|
for (const row of layout.rows) for (const cell of row.cells) {
|
|
1757
1852
|
const style = cell.style ?? {};
|
|
1758
|
-
|
|
1853
|
+
// FR-07: a number cell of a color scale takes the scale's fill (a fill of its own wins; the scale wins over the highlight tint).
|
|
1854
|
+
const defaultFill = cell.header ? bound.design.colors.primary : cell.scaled ? cell.scaled.fill : cell.highlighted ? highlightFill : bound.design.colors.surface;
|
|
1759
1855
|
const fill = style.fill == null
|
|
1760
1856
|
? defaultFill
|
|
1761
1857
|
: resolveColorRef(style.fill, bound, defaultFill);
|
|
1762
|
-
const defaultText = cell.header ? readableSchemeColor(fill, bound.design.roles).hex : textColorForFill(fill, bound.design.colors.text);
|
|
1858
|
+
const defaultText = cell.header ? readableSchemeColor(fill, bound.design.roles).hex : cell.scaled && style.fill == null ? cell.scaled.text : textColorForFill(fill, bound.design.colors.text);
|
|
1763
1859
|
const textFill = style.color == null
|
|
1764
1860
|
? defaultText
|
|
1765
1861
|
: resolveColorRef(style.color, bound, defaultText);
|
|
@@ -2116,19 +2212,24 @@ function scriptLine(text, style, bound, type, { rtl = false, numbers = rtl, plac
|
|
|
2116
2212
|
// `numbers` asks for it in a fragment of a flowing right-to-left line, which is one isolate across its fragments.
|
|
2117
2213
|
const escaped = text => escapeText(numbers && text ? isolateNumbers(text) : text);
|
|
2118
2214
|
const runs = value && scripts ? scripts.plan(value, style) : [{ text: value, own: true }];
|
|
2215
|
+
// opf#1472: a tracked line (letter-spacing; a single run draws without textLength) of the line's own face and glyphs replaced at their
|
|
2216
|
+
// exact advance flows like the single run it replaces: a rasterizer applies the letter-spacing again inside a positioned tspan's textLength.
|
|
2217
|
+
// An untracked line takes the positioned path below, as every multi-face line does.
|
|
2218
|
+
const replaced = style?.tracking && runs.some(run => run.advance !== undefined) && runs.every(run => run.own || run.advance !== undefined);
|
|
2219
|
+
if (replaced) placement = runPlacement = undefined;
|
|
2119
2220
|
if (!placement && runPlacement && runs.length > 1) placement = runPlacement;
|
|
2120
2221
|
// RR-38: PowerPoint's baseline of a line in Arabic Typesetting sits above core's (one em below the line top): the caller moves it up by `baselineShift` em.
|
|
2121
2222
|
const shiftOf = list => { const shift = baselineShift(list); return shift ? { baselineShift: shift } : {}; };
|
|
2122
2223
|
// FF-45: symbol runs (Wingdings, Symbol, Webdings codes drawn as their Unicode equivalents) are always positioned when the
|
|
2123
2224
|
// line is placed, one tspan per glyph at the verified symbol font's advance, so a single mapped glyph is never stretched to it.
|
|
2124
2225
|
const symbols = runs.some(run => run.symbol);
|
|
2125
|
-
if (runs.length === 1 && !(symbols && placement && placement.width > 0)) {
|
|
2226
|
+
if (runs.length === 1 && !replaced && !(symbols && placement && placement.width > 0)) {
|
|
2126
2227
|
const [run] = runs;
|
|
2127
2228
|
// RR-38: a replacement the policy scales (Arabic Typesetting -> Noto Naskh Arabic, 0.64) is drawn at the scaled size; the caller applies it.
|
|
2128
2229
|
return { content: isolate(escaped(run.own ? value : run.text)), family: run.own ? undefined : fontStack(run.stack ?? run.family, type), ...(run.sizeAdjust ? { sizeAdjust: run.sizeAdjust } : {}), ...shiftOf(runs) };
|
|
2129
2230
|
}
|
|
2130
2231
|
const baseSize = placement?.fontSize ?? fontSize;
|
|
2131
|
-
const adjusted = run => run.sizeAdjust && baseSize > 0 ? stableNumber(adjustedFontSize(baseSize, run.sizeAdjust)) : undefined;
|
|
2232
|
+
const adjusted = run => run.fontScale && baseSize > 0 ? stableNumber(baseSize * run.fontScale) : run.sizeAdjust && baseSize > 0 ? stableNumber(adjustedFontSize(baseSize, run.sizeAdjust)) : undefined;
|
|
2132
2233
|
const widths = placement && placement.width > 0 ? scripts.runWidths(runs, placement.fontSize, style) : undefined;
|
|
2133
2234
|
if (!widths) {
|
|
2134
2235
|
return { content: isolate(runs.map(run => run.own ? escaped(run.text)
|
|
@@ -2287,7 +2388,7 @@ function renderEmbeddedFonts(fonts = []) {
|
|
|
2287
2388
|
|
|
2288
2389
|
function renderRichTextBox(value, box, bound, config) {
|
|
2289
2390
|
const scale=Math.min(bound.design.dimensions.width,bound.design.dimensions.height)/720;
|
|
2290
|
-
const fit=config.fit??fitRichText(value,box,config.fontSize*scale,((bound.composition??bound.geometry.composition).
|
|
2391
|
+
const fit=config.fit??fitRichText(value,box,config.fontSize*scale,((bound.composition??bound.geometry.composition).minFontSizePx??16)*scale,{style:{fontFamily:config.fontFamily,fontWeight:config.fontWeight??400,path:config.path},...(bound.design.fonts.code?{codeFontFamily:bound.design.fonts.code}:{}),textMeasurement:config.options.textMeasurement});
|
|
2291
2392
|
if(fit.overflow&&!config.diagnosticsHandled){const diagnostic={code:'text-overflow',path:config.path,message:'Mixed-style text exceeds its cell at the minimum font size.'};reportDiagnostic(diagnostic,config.options);if((bound.composition??bound.geometry.composition).overflow==='error')throw new OPFRenderError('layout-overflow',diagnostic.message,{diagnostics:[diagnostic]});}
|
|
2292
2393
|
return renderRichLines(value,fit,box,bound,config);
|
|
2293
2394
|
}
|
|
@@ -2410,7 +2511,7 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2410
2511
|
// and outside the link, so every source offset still has a traced node whose text is its source text (an editor selects by offset;
|
|
2411
2512
|
// a selection ending after that space found no node). Without a trace the output is unchanged.
|
|
2412
2513
|
const cutSpace=config.options.trace&&endTrail&&!marker?tag(asFlow?'tspan':'text',{'data-opf-text-start':runOffsets[fragment.runIndex]+fragment.end-endTrail.length,'data-opf-text-end':runOffsets[fragment.runIndex]+fragment.end,'data-opf-segment':fragment.kind,...(asFlow?{}:{x:stableNumber(originX+fragmentX+gap+drawnWidth),y:position.y}),'xml:space':'preserve','font-family':scripted.family??fontStack(fragment.style.fontFamily,run.code===true?'monospace':bound.design.fontScheme.type),'font-size':stableNumber(adjustedFontSize(fragment.fontSize,scripted.sizeAdjust)),'font-weight':fragment.style.fontWeight,'font-style':fragment.style.italic?'italic':asFlow?'normal':undefined,fill:runFill},escapeText(endTrail)):'';
|
|
2413
|
-
if(linked)return tag('a',
|
|
2514
|
+
if(linked)return tag('a',linkAnchorAttrs(run.link,{newTab:true}),rendered)+cutSpace;
|
|
2414
2515
|
return rendered+cutSpace;
|
|
2415
2516
|
};
|
|
2416
2517
|
if(naturalFlow&&lineHasTab) {
|
|
@@ -2457,7 +2558,7 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2457
2558
|
const scale = Math.min(bound.design.dimensions.width, bound.design.dimensions.height) / 720;
|
|
2458
2559
|
const style = config.textStyle ?? resolveTextStyle({fontFamily:config.fontFamily,fontWeight:config.fontWeight ?? 400,italic:config.italic ?? false,path:config.path},config.options.textMeasurement);
|
|
2459
2560
|
const fit = config.fit ?? fitText(String(text ?? ""), box, config.fontSize * scale,
|
|
2460
|
-
((bound.composition ?? bound.geometry.composition).
|
|
2561
|
+
((bound.composition ?? bound.geometry.composition).minFontSizePx ?? 16) * scale, textWidthMeasurer(style,config.options.textMeasurement));
|
|
2461
2562
|
if (fit.overflow && !config.diagnosticsHandled) {
|
|
2462
2563
|
const diagnostic = { code: "text-overflow", path: config.path,
|
|
2463
2564
|
message: "Text exceeds its cell at the minimum font size; shorten it, increase its space, or split the slide." };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpresentation/opf-render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Deterministic local OPF renderer for SVG, PNG, and PDF output.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -68,6 +68,10 @@
|
|
|
68
68
|
"types": "./dist/player.d.ts",
|
|
69
69
|
"default": "./dist/player.js"
|
|
70
70
|
},
|
|
71
|
+
"./live-embeds": {
|
|
72
|
+
"types": "./dist/live-embeds.d.ts",
|
|
73
|
+
"default": "./dist/live-embeds.js"
|
|
74
|
+
},
|
|
71
75
|
"./element": {
|
|
72
76
|
"types": "./dist/element.d.ts",
|
|
73
77
|
"default": "./dist/element.js"
|
|
@@ -94,7 +98,7 @@
|
|
|
94
98
|
"fontkit": "^3.0.0",
|
|
95
99
|
"harfbuzzjs": "1.6.4",
|
|
96
100
|
"pako": "3.0.3",
|
|
97
|
-
"@openpresentation/opf": "^0.
|
|
101
|
+
"@openpresentation/opf": "^0.37.0"
|
|
98
102
|
},
|
|
99
103
|
"peerDependencies": {
|
|
100
104
|
"@expo-google-fonts/arimo": "0.4.3",
|
|
@@ -343,7 +347,7 @@
|
|
|
343
347
|
"pdfjs-dist": "6.5.438",
|
|
344
348
|
"playwright": "1.65.0",
|
|
345
349
|
"sharp": "0.35.5",
|
|
346
|
-
"@openpresentation/gallery": "0.
|
|
350
|
+
"@openpresentation/gallery": "0.37.0"
|
|
347
351
|
},
|
|
348
352
|
"bin": {
|
|
349
353
|
"opf-preview-fonts": "./dist/preview-fonts-cli.js"
|
|
@@ -400,5 +404,5 @@
|
|
|
400
404
|
"test:preview-a11y-browser": "node test/preview-a11y-browser.mjs",
|
|
401
405
|
"test:forced-colors-browser": "node test/forced-colors-browser.mjs artifacts/forced-colors"
|
|
402
406
|
},
|
|
403
|
-
"gitHead": "
|
|
407
|
+
"gitHead": "e6aa9c9ce3109709b8b8f14171ce71af339c3004"
|
|
404
408
|
}
|