@openpresentation/opf-render 0.30.0 → 0.32.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 +15 -3
- package/dist/chart-options.js +10 -10
- package/dist/charts.js +419 -127
- package/dist/deck-runtime.js +102 -25
- package/dist/element.d.ts +11 -1
- package/dist/element.js +63 -23
- package/dist/font-manifest.js +8 -8
- package/dist/fonts-browser.js +8 -2
- package/dist/fonts.d.ts +3 -2
- package/dist/index.d.ts +46 -1
- package/dist/index.js +2 -0
- package/dist/measure-pictures-node.js +22 -0
- package/dist/measure-pictures.js +185 -0
- package/dist/player.d.ts +22 -4
- package/dist/player.js +48 -33
- package/dist/svg.d.ts +46 -1
- package/dist/svg.js +219 -47
- package/package.json +12 -11
package/dist/svg.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// The layout engine lives in core's `/composition` entry. Every name is a static import, so a core without one fails to
|
|
2
2
|
// load instead of switching a feature (script fonts, right-to-left, patterns, code colours, trend arrows) off.
|
|
3
3
|
import {
|
|
4
|
-
layoutTable, fitList, fitRichText, composeSlide, resolveTextStyle, textWidthMeasurer, fitText, textColorForFill, chartColorForFill,
|
|
5
|
-
resolveColorRef as resolveCoreColorRef, resolveScriptFonts, paragraphDirection, physicalAlignment, patternRuns,
|
|
6
|
-
metricTrendMark as coreMetricTrendMark, metricValueColor, tokenizeCode, codeLineRuns, codeSyntaxPaletteForRoles, readableSchemeColor, resolveChartData,
|
|
7
|
-
timelineMarkerShapes, timelineTextColor, layoutWatermark,
|
|
8
|
-
codeHighlightLines, codeLineNumbers, codeHighlightBands, codeHighlightColors, fitImage, intrinsicImageAspect, intrinsicImageSize,
|
|
4
|
+
layoutTable, fitList, fitRichText, composeSlide, emphasisSurface, resolveTextStyle, textWidthMeasurer, fitText, styledText, LIST_RULE_WIDTH, LIST_ACCENT_RULE_WIDTH, textColorForFill, chartColorForFill,
|
|
5
|
+
resolveColorRef as resolveCoreColorRef, resolveScriptFonts, paragraphDirection, physicalAlignment, patternRuns, isolateNumbers,
|
|
6
|
+
metricTrendMark as coreMetricTrendMark, metricPillFill, metricValueColor, tokenizeCode, codeLineRuns, codeSyntaxPaletteForRoles, readableSchemeColor, resolveChartData,
|
|
7
|
+
timelineMarkerShapes, timelineTextColor, layoutWatermark, tableHighlightColor,
|
|
8
|
+
codeHighlightLines, codeLineNumbers, codeHighlightBands, codeHighlightColors, fitImage, intrinsicImageAspect, intrinsicImageSize, diagramPalette, paintDiagramGroup,
|
|
9
9
|
ENGINE_DEFAULT_THEME, ENGINE_DEFAULT_COLOR_SCHEME, ENGINE_DEFAULT_FONT_SCHEME, ENGINE_DEFAULT_CHART_TYPES
|
|
10
10
|
} from "@openpresentation/opf/composition";
|
|
11
11
|
// The renderer is a library: it never imports a catalog. Hosts register theirs (`options.catalogs`, core `Catalog[]`, for
|
|
@@ -30,6 +30,8 @@ import { rejectRenamedOptions, selectSlides } from "./slide-sources.js";
|
|
|
30
30
|
import { deckInternals } from "./svg-internals.js";
|
|
31
31
|
|
|
32
32
|
export const packageName = "@openpresentation/opf-render";
|
|
33
|
+
// LH-145: the picture sampler of the automatic scrim (the canvas decoder; the Node entry replaces it with the sharp one).
|
|
34
|
+
export { measurePictures } from "./measure-pictures.js";
|
|
33
35
|
|
|
34
36
|
export const releaseLane = Object.freeze({
|
|
35
37
|
githubRepository: "OpenPresentation/opf",
|
|
@@ -337,6 +339,19 @@ function tagFill(design) {
|
|
|
337
339
|
const background = design.backgroundColor ?? design.colors.background;
|
|
338
340
|
return contrastRatio(design.colors.primary, background) < TAG_MIN_CONTRAST ? design.colors.text : design.colors.primary;
|
|
339
341
|
}
|
|
342
|
+
// LH-50: a label core draws as an eyebrow (item.eyebrow) takes the tag's color on its backdrop: its card's fill when it is on one.
|
|
343
|
+
function eyebrowFill(design, item) {
|
|
344
|
+
const backdrop = item.frameBox ? design.roles.neutrals.card.hex : design.backgroundColor ?? design.colors.background;
|
|
345
|
+
return contrastRatio(design.colors.primary, backdrop) < TAG_MIN_CONTRAST ? design.colors.text : design.colors.primary;
|
|
346
|
+
}
|
|
347
|
+
// LH-32: the escaped text of a tracked line with its last character in a tspan of no letter spacing: core spaces an eyebrow's letters
|
|
348
|
+
// between characters (trackingWidth), and a trailing spacing would move a centered or right-aligned line by a rasterizer's own reading.
|
|
349
|
+
function untrackLast(content) {
|
|
350
|
+
if (typeof content !== "string" || content.includes("<")) return content;
|
|
351
|
+
const last = /(&#?\w+;|[\s\S])$/u.exec(content);
|
|
352
|
+
return last && last.index > 0 ? `${content.slice(0, last.index)}<tspan letter-spacing="0">${last[1]}</tspan>` : content;
|
|
353
|
+
}
|
|
354
|
+
const sameBox = (a, b) => !!a && !!b && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
340
355
|
|
|
341
356
|
const LINK_URL = /^(https?:|mailto:|tel:)/i;
|
|
342
357
|
|
|
@@ -345,9 +360,13 @@ const LINK_URL = /^(https?:|mailto:|tel:)/i;
|
|
|
345
360
|
// sorted keys, so the output does not depend on the order a catalog lists a field in. A reference that resolves nowhere never
|
|
346
361
|
// throws (unless `strictReferences`): the context falls back to core's engine defaults (ENGINE_DEFAULT_THEME, _COLOR_SCHEME,
|
|
347
362
|
// _FONT_SCHEME; a layout to automatic composition) and reports `unresolved-reference`, which is forwarded as a render diagnostic.
|
|
363
|
+
// A theme-slot background beside a variant at the same level is not drawn (core colorChoice): the slide is the variant's bg1,
|
|
364
|
+
// so `{ background: "light1", variant: "dark1" }` paints dark1 under its light text, as the PPTX export does.
|
|
365
|
+
const THEME_BACKGROUND_SLOTS = new Set(["light1", "light2", "dark1", "dark2"]);
|
|
366
|
+
const isThemeSlotBackground = (value) => THEME_BACKGROUND_SLOTS.has(value) || (value?.type === "theme" && THEME_BACKGROUND_SLOTS.has(value.slot));
|
|
348
367
|
function drawnBackground(levels) {
|
|
349
368
|
for (const level of levels) {
|
|
350
|
-
if (level.variant !== undefined) return level.background;
|
|
369
|
+
if (level.variant !== undefined) return isThemeSlotBackground(level.background) ? undefined : level.background;
|
|
351
370
|
if (level.background !== undefined && level.background !== null && level.background !== false) return level.background;
|
|
352
371
|
}
|
|
353
372
|
return undefined;
|
|
@@ -363,7 +382,8 @@ function resolveDesign(presentation, slide, slideContext) {
|
|
|
363
382
|
// RR-96: core resolves the slide's roles (its variant's map over the scheme, the accents in order, the scheme-derived neutrals) once, in
|
|
364
383
|
// the slide context every engine shares. A variant hides the background of a less specific level (the slide is then the variant's bg1).
|
|
365
384
|
const roles = resolved.roles;
|
|
366
|
-
|
|
385
|
+
// LH-01: a layout's variant ranks between the slide's design and the deck's (core's resolved.layoutVariant, when it decides).
|
|
386
|
+
const backgroundDefinition = drawnBackground([slideDesign, resolved.layoutVariant ? { variant: resolved.layoutVariant } : {}, deckDesign, theme]);
|
|
367
387
|
const variables = presentation.variables ?? {};
|
|
368
388
|
// A background reference sees only the scheme and the three accent roles; a picture or no background is the variant's bg1.
|
|
369
389
|
const backgroundColor = resolveBackground(backgroundDefinition, colorScheme, { colorScheme, colors: { primary: roles.primary, secondary: roles.secondary, accent: roles.accent }, variables }, roles.background);
|
|
@@ -603,7 +623,7 @@ function bindSlide(presentation, index, context) {
|
|
|
603
623
|
// The rule is core's resolveDrawnFontFamilies, which validate and paginate compose with too (WI-1, P24); the renderer decides
|
|
604
624
|
// the two exceptions from the font policy and symbol tables it already holds.
|
|
605
625
|
design.fonts = resolveDrawnFontFamilies(design.fonts, textMeasurement, (named, resolved) => isSymbolEncodedFamily(named) || fontPolicyFor(named)?.replacement?.weight !== undefined && resolved.toLowerCase() !== named.toLowerCase());
|
|
606
|
-
const geometry = composeSlide(slide, { ...slideContext.options, fontFamilies: design.fonts, textRasterPadding:context.options.textRasterPadding, textMeasurement });
|
|
626
|
+
const geometry = composeSlide(slide, { ...slideContext.options, fontFamilies: design.fonts, textRasterPadding:context.options.textRasterPadding, textMeasurement, ...(typeof context.options.pictureLuminance === "function" ? { pictureLuminance: context.options.pictureLuminance } : {}) });
|
|
607
627
|
return {
|
|
608
628
|
scriptFonts,
|
|
609
629
|
scriptFontsFor,
|
|
@@ -703,6 +723,8 @@ function renderResolvedSlide(resolved, slideIndex, options) {
|
|
|
703
723
|
let content = [
|
|
704
724
|
renderBackground(bound, width, height, options),
|
|
705
725
|
renderBranding(bound, resolved.presentation, width, height, options),
|
|
726
|
+
renderSteps(bound, options),
|
|
727
|
+
renderTitleRule(bound, options),
|
|
706
728
|
...renderSlideContent(bound, width, height, options),
|
|
707
729
|
// RR-34: the footnote area core reserved above the footer band, after the content and before the furniture.
|
|
708
730
|
renderFootnotes(bound, options, drawHelpers),
|
|
@@ -815,17 +837,19 @@ function renderBackgroundImage(background, bound, width, height, options) {
|
|
|
815
837
|
const id = `opf-s${bound.index + 1}-background`, matrix = imageRecolorMatrix(background.recolor, bound);
|
|
816
838
|
const defs = matrix ? tag("defs", {}, tag("filter", { id: `${id}-recolor`, "color-interpolation-filters": "sRGB" }, tag("feColorMatrix", { type: "matrix", values: matrix }))) : "";
|
|
817
839
|
const pixels = matrix || background.opacity !== undefined ? tag("g", { filter: matrix ? `url(#${id}-recolor)` : undefined, opacity: background.opacity === undefined ? undefined : preciseNumber(background.opacity) }, picture) : picture;
|
|
818
|
-
return [canvas, defs, pixels, background.overlay ? renderImageOverlay(background.overlay, bound, options) :
|
|
840
|
+
return [canvas, defs, pixels, background.overlay ? renderImageOverlay(background.overlay, bound, options) : (background.scrims ?? []).map((scrim, index) => renderPictureScrim(scrim, index, bound, options)).join("\n")].filter(Boolean).join("\n");
|
|
819
841
|
}
|
|
820
842
|
|
|
821
|
-
//
|
|
822
|
-
//
|
|
823
|
-
//
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
const
|
|
827
|
-
if (
|
|
828
|
-
|
|
843
|
+
// LH-02: core's automatic scrims under the text on a picture (backgroundImage.scrims) in the slide background color: each a rectangle filled
|
|
844
|
+
// with a linear gradient along its axis whose stops carry the opacity (a band of one opacity is a plain fill), the geometry the PPTX
|
|
845
|
+
// export writes as a native gradient fill. It replaces RR-96's renderer-own 40% scrim on a picture that names its tone.
|
|
846
|
+
function renderPictureScrim(scrim, index, bound, options) {
|
|
847
|
+
const trace = options.trace ? { "data-opf-scrim": scrim.edge ?? scrim.form } : {};
|
|
848
|
+
const rect = { ...HIDDEN, x: stableNumber(scrim.box.x), y: stableNumber(scrim.box.y), width: stableNumber(scrim.box.width), height: stableNumber(scrim.box.height) };
|
|
849
|
+
if (scrim.stops.every(stop => stop.opacity === scrim.opacity)) return tag("rect", { ...rect, fill: scrim.color, "fill-opacity": preciseNumber(scrim.opacity), ...trace });
|
|
850
|
+
const id = `opf-s${bound.index + 1}-scrim-${index + 1}`, vertical = scrim.axis === "vertical";
|
|
851
|
+
const stops = scrim.stops.map(stop => tag("stop", { offset: preciseNumber(stop.position), "stop-color": scrim.color, "stop-opacity": preciseNumber(stop.opacity) })).join("");
|
|
852
|
+
return tag("defs", {}, tag("linearGradient", { id, x1: 0, y1: 0, x2: vertical ? 0 : 1, y2: vertical ? 1 : 0 }, stops)) + tag("rect", { ...rect, fill: `url(#${id})`, ...trace });
|
|
829
853
|
}
|
|
830
854
|
|
|
831
855
|
// tile: a pattern cell of the picture's intrinsic size, anchored at the canvas origin.
|
|
@@ -903,20 +927,82 @@ function imageRecolorMatrix(recolor, bound) {
|
|
|
903
927
|
return [...rows, '0 0 0 1 0'].join(' ');
|
|
904
928
|
}
|
|
905
929
|
|
|
930
|
+
// LH-07: core's step badges, connectors and flows (geometry.steps), under the text they number, as the PPTX export draws them: the chips
|
|
931
|
+
// (card fill and border), the connector (border color), each badge (a primary circle with its numeral centered in the bold body face, in
|
|
932
|
+
// the scheme color readable on the primary) and the arrows (primary block arrows, DrawingML's rightArrow or leftArrow preset). LH-134: a
|
|
933
|
+
// numeral (badge.numeral) draws no circle, its label bold in the tag's color (the primary, or the text color where the primary reads under
|
|
934
|
+
// 4.5:1 on the slide), as the export writes it.
|
|
935
|
+
// With trace each shape names the block or entry it numbers in data-opf-step-path, not data-opf-path: it is the layout's drawing, so
|
|
936
|
+
// hit-testing and the region groups still find each item by its own text.
|
|
937
|
+
function renderSteps(bound, options) {
|
|
938
|
+
const steps = bound.geometry.steps;
|
|
939
|
+
if (!steps?.length) return '';
|
|
940
|
+
const primary = bound.design.colors.primary, numeral = readableSchemeColor(primary, bound.design.roles).hex, family = fontStack(bound.design.fonts.body, bound.design.fontScheme.type);
|
|
941
|
+
return steps.map(step => {
|
|
942
|
+
const parts = [];
|
|
943
|
+
for (const chip of step.chips ?? []) parts.push(tag('rect', {...HIDDEN, x: chip.box.x, y: chip.box.y, width: chip.box.width, height: chip.box.height, rx: chip.radius, fill: bound.design.roles.neutrals.card.hex, stroke: bound.design.roles.neutrals.cardBorder.hex, ...(options.trace ? {'data-opf-step-path': chip.path} : {})}));
|
|
944
|
+
if (step.connector) parts.push(tag('line', {...HIDDEN, ...step.connector, stroke: bound.design.colors.border, 'stroke-width': step.lineWidth, ...(options.trace ? {'data-opf-step-path': step.path} : {})}));
|
|
945
|
+
for (const badge of step.badges) {
|
|
946
|
+
if (!badge.numeral) parts.push(tag('circle', {...HIDDEN, cx: badge.cx, cy: badge.cy, r: badge.radius, fill: primary, ...(options.trace ? {'data-opf-step-path': badge.path} : {})}));
|
|
947
|
+
// LH-137: a check-mark badge (a summary list's tile) draws core's check polygon in the numeral's color in place of a numeral.
|
|
948
|
+
if (badge.check) parts.push(tag('path', {...HIDDEN, d: `M${badge.check.map(([px, py]) => `${stableNumber(px)} ${stableNumber(py)}`).join(' L')} Z`, fill: numeral}));
|
|
949
|
+
else parts.push(tag('text', {x: stableNumber(badge.cx), y: stableNumber(badge.baseline), 'text-anchor': 'middle', 'font-family': family, 'font-size': stableNumber(badge.fontSize), 'font-weight': 700, fill: badge.numeral ? tagFill(bound.design) : numeral, 'aria-hidden': 'true', ...(badge.numeral && options.trace ? {'data-opf-step-path': badge.path} : {})}, escapeText(badge.label)));
|
|
950
|
+
}
|
|
951
|
+
for (const arrow of step.arrows ?? []) parts.push(tag('path', {...HIDDEN, d: blockArrowPath(arrow.box, arrow.direction), fill: primary}));
|
|
952
|
+
return tag('g', options.trace ? {'data-opf-steps': step.form, 'data-opf-region': step.region} : {}, parts.join('\n'));
|
|
953
|
+
}).join('\n');
|
|
954
|
+
}
|
|
955
|
+
// LH-130: the short accent rule core sets above a cover's or section's title (geometry.titleRule), filled in the tag's color (tagFill), as
|
|
956
|
+
// the PPTX export draws it. With trace it names the title it stands for in data-opf-title-rule, not data-opf-path: it is the layout's
|
|
957
|
+
// drawing, so hit-testing still finds the title by its own text.
|
|
958
|
+
function renderTitleRule(bound, options) {
|
|
959
|
+
const rule = bound.geometry.titleRule;
|
|
960
|
+
if (!rule) return '';
|
|
961
|
+
return tag('rect', {...HIDDEN, x: stableNumber(rule.box.x), y: stableNumber(rule.box.y), width: stableNumber(rule.box.width), height: stableNumber(rule.box.height), fill: tagFill(bound.design), ...(options.trace ? {'data-opf-title-rule': rule.path} : {})});
|
|
962
|
+
}
|
|
963
|
+
// DrawingML's rightArrow preset at its default adjustments (adj1 = adj2 = 50000): a shaft half the box's height and a head as long as
|
|
964
|
+
// half its smaller side; leftArrow is its mirror.
|
|
965
|
+
function blockArrowPath(box, direction) {
|
|
966
|
+
const {x, y, width, height} = box, head = Math.min(width, height) / 2, top = y + height / 4, bottom = y + height * 3 / 4, middle = y + height / 2, n = stableNumber;
|
|
967
|
+
const points = direction === 'left'
|
|
968
|
+
? [[x, middle], [x + head, y], [x + head, top], [x + width, top], [x + width, bottom], [x + head, bottom], [x + head, y + height]]
|
|
969
|
+
: [[x, top], [x + width - head, top], [x + width - head, y], [x + width, middle], [x + width - head, y + height], [x + width - head, bottom], [x, bottom]];
|
|
970
|
+
return `M${points.map(([px, py]) => `${n(px)} ${n(py)}`).join(' L')} Z`;
|
|
971
|
+
}
|
|
972
|
+
|
|
906
973
|
function renderSlideContent(bound, width, height, options) {
|
|
907
974
|
for (const diagnostic of [...bound.design.diagnostics, ...bound.geometry.diagnostics]) reportDiagnostic(diagnostic, options);
|
|
975
|
+
// LH-06: core's emphasis surface (geometry.emphasis) is drawn under the first item on it, in the fill core's emphasisSurface gives the
|
|
976
|
+
// slide; every item on it (item.emphasis) is drawn with the surface's roles, whose text reaches 4.5:1 on the fill, as the PPTX export does.
|
|
977
|
+
const emphasis=bound.geometry.emphasis;
|
|
978
|
+
const onSurface=emphasis ? emphasisBound(bound, emphasisSurface(bound.design.colorScheme, bound.design.roles)) : undefined;
|
|
979
|
+
let surfaceDrawn=false,previousFrame;
|
|
908
980
|
return bound.geometry.items.map(item => {
|
|
981
|
+
const itemBound=item.emphasis&&onSurface ? onSurface : bound;
|
|
982
|
+
// LH-131: a featured before and after pair's arrow (emphasis.arrow), a primary block arrow as LH-07's flows draw theirs, with the surface.
|
|
983
|
+
const under=item.emphasis&&onSurface&&!surfaceDrawn ? (surfaceDrawn=true, tag('rect',{...HIDDEN,x:emphasis.box.x,y:emphasis.box.y,width:emphasis.box.width,height:emphasis.box.height,rx:emphasis.radius,fill:onSurface.design.colors.background,...traceAttrs(options,emphasis.path)})
|
|
984
|
+
+(emphasis.arrow?tag('path',{...HIDDEN,d:blockArrowPath(emphasis.arrow.box,emphasis.arrow.direction),fill:bound.design.colors.primary,...(options.trace?{'data-opf-emphasis-arrow':emphasis.path}:{})}):'')) : '';
|
|
909
985
|
// Cards come from core's geometry: item.frameBox is the card core allocated in the item's cell (OPF 0.19: a template
|
|
910
|
-
// region's flow cell; core never gives an item of a bled region a card).
|
|
911
|
-
|
|
912
|
-
|
|
986
|
+
// region's flow cell; core never gives an item of a bled region a card). LH-54: its fill and stroke are core's card neutrals (a filled
|
|
987
|
+
// surface on a dark slide whose scheme surface is the background itself), as the PPTX export draws them.
|
|
988
|
+
// LH-50: a label drawn as an eyebrow shares its paragraph's card (the same frameBox); a card is drawn once, under the first of its items.
|
|
989
|
+
const frame=item.frameBox&&!sameBox(item.frameBox,previousFrame)?item.frameBox:undefined;
|
|
990
|
+
previousFrame=item.frameBox;
|
|
991
|
+
const surface=under+(frame ? tag('rect',{...HIDDEN,x:frame.x,y:frame.y,width:frame.width,height:frame.height,rx:8*Math.min(width,height)/720,fill:bound.design.roles.neutrals.card.hex,stroke:bound.design.roles.neutrals.cardBorder.hex,...traceAttrs(options,item.path)}) : '');
|
|
913
992
|
// RR-34: a captioned item draws its media in item.box and its caption band after it (src/annotations.js).
|
|
914
|
-
const drawn=surface+renderPayload(item, item.box, { ...
|
|
993
|
+
const drawn=surface+renderPayload(item, item.box, { ...itemBound, composition: item.composition }, options)+(item.caption?renderCaption(item,{ ...itemBound, composition: item.composition },options,drawHelpers):'');
|
|
915
994
|
// OPF 0.19 (RR-81): with trace, everything an item of a layout template region draws (card, payload, caption) is
|
|
916
995
|
// grouped under data-opf-region, the region's name (ComposedItem.region). Items outside a template are unchanged.
|
|
917
996
|
return options.trace && item.region !== undefined && drawn ? tag('g',{'data-opf-region':item.region},drawn) : drawn;
|
|
918
997
|
});
|
|
919
998
|
}
|
|
999
|
+
// LH-06: the slide as an item on the emphasis surface sees it: the surface fill is its background and the surface's roles are its colors.
|
|
1000
|
+
function emphasisBound(bound, surface) {
|
|
1001
|
+
const roles = surface.roles;
|
|
1002
|
+
return { ...bound, design: { ...bound.design, backgroundColor: surface.fill, darkBackground: roles.dark, roles, colors: { ...bound.design.colors,
|
|
1003
|
+
background: surface.fill, surface: roles.surface, text: roles.text, mutedText: roles.textSecondary, primary: roles.primary, secondary: roles.secondary,
|
|
1004
|
+
accent: roles.accent, hyperlink: roles.hyperlink, followedHyperlink: roles.followedHyperlink, border: roles.border } } };
|
|
1005
|
+
}
|
|
920
1006
|
// Draw helpers injected into src/annotations.js (captions and footnote areas).
|
|
921
1007
|
const drawHelpers = { tag, renderTextBox, renderRichLines };
|
|
922
1008
|
|
|
@@ -956,6 +1042,8 @@ function renderPayload(item, box, bound, options) {
|
|
|
956
1042
|
return renderQuote(item, box, bound, options);
|
|
957
1043
|
case "timeline":
|
|
958
1044
|
return renderTimeline(item, box, bound, options);
|
|
1045
|
+
case "diagram":
|
|
1046
|
+
return renderDiagram(item, box, bound, options);
|
|
959
1047
|
case "list":
|
|
960
1048
|
return renderList(item, box, bound, options);
|
|
961
1049
|
default:
|
|
@@ -976,10 +1064,11 @@ function renderTextPayload(item, box, bound, options) {
|
|
|
976
1064
|
// The slide tag is the eyebrow label: it draws in the primary colour (scheme accent1), as the
|
|
977
1065
|
// PPTX export writes it, or in the text colour when the primary is under 4.5:1 against the
|
|
978
1066
|
// slide background (FF-61). Every other text payload here uses the text colour.
|
|
979
|
-
fill: item.field === "tag" ? tagFill(bound.design) : bound.design.colors.text,
|
|
1067
|
+
fill: item.field === "tag" ? tagFill(bound.design) : item.eyebrow ? eyebrowFill(bound.design, item) : bound.design.colors.text,
|
|
980
1068
|
fit: item.text,
|
|
981
1069
|
textStyle: item.textStyle,
|
|
982
1070
|
diagnosticsHandled: Boolean(item.text),
|
|
1071
|
+
...(item.titleSplit ? { sourceOffset: item.titleSplit.start } : {}),
|
|
983
1072
|
options
|
|
984
1073
|
});
|
|
985
1074
|
}
|
|
@@ -1012,10 +1101,20 @@ function listEntriesSvg(item, fit, bound, options) {
|
|
|
1012
1101
|
if(entry.marker.none){/* design.listBullet: none draws no marker */}
|
|
1013
1102
|
else if(bullet){const box=entry.bulletBox??{x:entry.marker.x,y:entry.marker.y-entry.marker.fontSize*.65,width:entry.marker.fontSize*.65,height:entry.marker.fontSize*.65};children.push(tag('image',{x:stableNumber(box.x),y:stableNumber(box.y),width:stableNumber(box.width),height:stableNumber(box.height),href:bullet,preserveAspectRatio:'xMidYMid meet','aria-hidden':'true',...(options.trace?{'data-opf-generated':'true'}:{})}));}
|
|
1014
1103
|
else children.push(tag('text',{x:stableNumber(entry.marker.x),y:stableNumber(entry.marker.y),'font-family':fontStack(entry.marker.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(entry.marker.fontSize),...numberMarkerStyle(entry.marker),fill:bound.design.colors.text,'aria-hidden':'true',...(entry.marker.anchor==='end'?{'text-anchor':'end'}:{})},escapeText(entry.marker.text)));
|
|
1015
|
-
|
|
1104
|
+
// LH-133: a glossary's term (entry.accent) draws in the tag's color on its backdrop, as the export writes it.
|
|
1105
|
+
const config={path:entry.textPath,align:'left',fill:entry.accent?eyebrowFill(bound.design,item):bound.design.colors.text,rich:Array.isArray(entry.value),options};
|
|
1016
1106
|
children.push(renderRichLines(typeof entry.value==='string'?[entry.value]:entry.value,entry.text,entry.textBox,bound,config));
|
|
1017
1107
|
if(entry.description)children.push(renderRichLines(typeof entry.descriptionValue==='string'?[entry.descriptionValue]:entry.descriptionValue,entry.description,entry.descriptionBox,bound,{...config,path:entry.descriptionPath,rich:Array.isArray(entry.descriptionValue),fill:bound.design.colors.mutedText}));
|
|
1018
1108
|
}
|
|
1109
|
+
// LH-08: a list drawn as ruled rows (design.listStyle: rows) draws core's hairlines between its rows, LIST_RULE_WIDTH thick in the
|
|
1110
|
+
// scheme's border neutral, as the PPTX export draws them as native lines. LH-133: an accent rule (over a cell of a grid of questions) is
|
|
1111
|
+
// LIST_ACCENT_RULE_WIDTH thick in the tag's color on its backdrop.
|
|
1112
|
+
if(fit.rules?.length){
|
|
1113
|
+
// LH-136: the accent rule over a display heading is core's own thickness; LH-133's accent rules over question cells are
|
|
1114
|
+
// LIST_ACCENT_RULE_WIDTH thick. Both are in the tag's color on their backdrop.
|
|
1115
|
+
const unit=Math.min(bound.design.dimensions.width,bound.design.dimensions.height)/720,border=bound.design.roles.neutrals.border.hex;
|
|
1116
|
+
for(const rule of fit.rules)children.push(tag('line',{x1:stableNumber(rule.x),y1:stableNumber(rule.y),x2:stableNumber(rule.x+rule.width),y2:stableNumber(rule.y),stroke:rule.accent?eyebrowFill(bound.design,item):border,'stroke-width':stableNumber(rule.thickness??(rule.accent?LIST_ACCENT_RULE_WIDTH:LIST_RULE_WIDTH)*unit),'aria-hidden':'true',...(options.trace?{'data-opf-generated':'true'}:{})}));
|
|
1117
|
+
}
|
|
1019
1118
|
return children;
|
|
1020
1119
|
}
|
|
1021
1120
|
|
|
@@ -1397,9 +1496,17 @@ function renderMetric(item, box, bound, options) {
|
|
|
1397
1496
|
const layout=item.metricLayout;
|
|
1398
1497
|
if (!layout) throw new OPFRenderError('missing-metric-layout','Metric rendering requires coordinated core metric geometry.',{path:item.path});
|
|
1399
1498
|
const children=[];
|
|
1400
|
-
// RR-07: a trend draws
|
|
1401
|
-
|
|
1402
|
-
|
|
1499
|
+
// RR-07, LH-53: a trend draws core's arrow (before the delta; the trend word is not drawn) and colors the delta text.
|
|
1500
|
+
// LH-54: a metric in a card is colored against the card fill, not the slide behind it. LH-57: on a dark one, a value whose accent
|
|
1501
|
+
// falls under 4.5:1 takes the text color.
|
|
1502
|
+
const backdrop=item.frameBox?bound.design.roles.neutrals.card.hex:bound.design.backgroundColor??bound.design.colors.background;
|
|
1503
|
+
// LH-137: a delta pill (layout.deltaPill) is filled with core metricPillFill under the delta and its arrow, which are colored against it.
|
|
1504
|
+
const pillFill=layout.deltaPill?metricPillFill(backdrop,bound.design.colors.text):undefined;
|
|
1505
|
+
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'}:{})})); }
|
|
1506
|
+
const trendMark=metricTrendMark(layout,bound,pillFill??backdrop);
|
|
1507
|
+
// LH-53: a unit on its value's line is part of the figure and takes the value's color.
|
|
1508
|
+
// 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.
|
|
1509
|
+
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;
|
|
1403
1510
|
for (const part of layout.parts) {
|
|
1404
1511
|
const invalid=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\uD800-\uDFFF\uFFFE\uFFFF]/u.exec(part.text);
|
|
1405
1512
|
if (invalid) throw new OPFRenderError('invalid-metric-text',`Metric text contains U+${invalid[0].codePointAt(0).toString(16).toUpperCase().padStart(4,'0')} at UTF-16 offset ${invalid.index}, which XML cannot represent; edit that character before rendering.`,{path:part.path});
|
|
@@ -1414,23 +1521,23 @@ function renderMetric(item, box, bound, options) {
|
|
|
1414
1521
|
const origin=part.linePositions[index];
|
|
1415
1522
|
if(factor&&!line.segments.some(segment=>segment.kind==='tab'))return tag('text',{x:stableNumber(origin.x+line.width*factor),y:stableNumber(origin.baseline),'text-anchor':factor===1?'end':'middle',
|
|
1416
1523
|
'font-family':fontStack(part.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(part.fit.fontSize),
|
|
1417
|
-
'font-weight':part.style.fontWeight,'font-style':part.style.italic?'italic':undefined,
|
|
1524
|
+
'font-weight':part.style.fontWeight,'font-style':part.style.italic?'italic':undefined,'letter-spacing':part.style.tracking?stableNumber(part.style.tracking*part.fit.fontSize):undefined,
|
|
1418
1525
|
'xml:space':'preserve',style:'white-space:pre','text-rendering':'geometricPrecision',fill:partFill(part),
|
|
1419
1526
|
...traceAttrs(options,part.path),...(options.trace?{'data-opf-metric-role':part.role,'data-opf-text-start':line.start,
|
|
1420
1527
|
'data-opf-text-end':line.end,'data-opf-text-next-start':line.nextStart,'data-opf-line-boundary':line.boundary}:{}),
|
|
1421
1528
|
},line.segments.map(segment=>segmentSpan({
|
|
1422
1529
|
...(options.trace?{'data-opf-segment':segment.kind,'data-opf-text-start':segment.start,'data-opf-text-end':segment.end}:{}),
|
|
1423
|
-
},segment,part.text.slice(segment.start,segment.end),part.style,bound,bound.design.fontScheme.type,{rtl:partRtl(line.start),fontSize:part.fit.fontSize})).join(''));
|
|
1530
|
+
},segment,styledText(part.text.slice(segment.start,segment.end),part.style),part.style,bound,bound.design.fontScheme.type,{rtl:partRtl(line.start),fontSize:part.fit.fontSize})).join(''));
|
|
1424
1531
|
return tag('text',{x:stableNumber(origin.x),y:stableNumber(origin.baseline),'text-anchor':'start',
|
|
1425
1532
|
'font-family':fontStack(part.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(part.fit.fontSize),
|
|
1426
|
-
'font-weight':part.style.fontWeight,'font-style':part.style.italic?'italic':undefined,
|
|
1533
|
+
'font-weight':part.style.fontWeight,'font-style':part.style.italic?'italic':undefined,'letter-spacing':part.style.tracking?stableNumber(part.style.tracking*part.fit.fontSize):undefined,
|
|
1427
1534
|
'xml:space':'preserve',style:'white-space:pre','text-rendering':'geometricPrecision',fill:partFill(part),
|
|
1428
1535
|
...traceAttrs(options,part.path),...(options.trace?{'data-opf-metric-role':part.role,'data-opf-text-start':line.start,
|
|
1429
1536
|
'data-opf-text-end':line.end,'data-opf-text-next-start':line.nextStart,'data-opf-line-boundary':line.boundary}:{}),
|
|
1430
1537
|
},line.segments.map(segment=>segmentSpan({x:stableNumber(origin.x+segment.x),
|
|
1431
1538
|
...(segment.kind==='tab'?{textLength:stableNumber(segment.width),lengthAdjust:'spacingAndGlyphs'}:{}),
|
|
1432
1539
|
...(options.trace?{'data-opf-segment':segment.kind,'data-opf-text-start':segment.start,'data-opf-text-end':segment.end}:{}),
|
|
1433
|
-
},segment,part.text.slice(segment.start,segment.end),part.style,bound,bound.design.fontScheme.type,{rtl:partRtl(line.start),fontSize:part.fit.fontSize})).join(''));
|
|
1540
|
+
},segment,styledText(part.text.slice(segment.start,segment.end),part.style),part.style,bound,bound.design.fontScheme.type,{rtl:partRtl(line.start),fontSize:part.fit.fontSize})).join(''));
|
|
1434
1541
|
});
|
|
1435
1542
|
children.push(tag('g',{...traceAttrs(options,part.path),...(options.trace?{'data-opf-metric-role':part.role,
|
|
1436
1543
|
'data-opf-box-x':part.box.x,'data-opf-box-y':part.box.y,'data-opf-box-width':part.box.width,'data-opf-box-height':part.box.height}:{}),
|
|
@@ -1441,8 +1548,8 @@ function renderMetric(item, box, bound, options) {
|
|
|
1441
1548
|
}
|
|
1442
1549
|
|
|
1443
1550
|
// The trend arrow and colour for a laid-out metric (core metricTrendMark); undefined without a trend.
|
|
1444
|
-
function metricTrendMark(layout,bound,
|
|
1445
|
-
return coreMetricTrendMark(layout,{background
|
|
1551
|
+
function metricTrendMark(layout,bound,background) {
|
|
1552
|
+
return coreMetricTrendMark(layout,{background,neutral:bound.design.roles.neutrals.trendNeutral.hex});
|
|
1446
1553
|
}
|
|
1447
1554
|
|
|
1448
1555
|
function renderQuote(item, box, bound, options) {
|
|
@@ -1461,6 +1568,8 @@ function renderQuote(item, box, bound, options) {
|
|
|
1461
1568
|
});
|
|
1462
1569
|
// FA-12: the attributed person's headshot, cropped to fill the core circle frame (the clip is the outline the native ellipse picture uses).
|
|
1463
1570
|
if (layout.photo) children.push(renderQuotePhoto(layout.photo, item, bound, options));
|
|
1571
|
+
// LH-114: a pull line's accent rule, in the primary color (core places it; the PPTX export draws the same rectangle).
|
|
1572
|
+
if (layout.rule) children.unshift(tag('rect', {...HIDDEN, x: stableNumber(layout.rule.x), y: stableNumber(layout.rule.y), width: stableNumber(layout.rule.width), height: stableNumber(layout.rule.height), fill: bound.design.colors.primary, ...(options.trace ? {'data-opf-quote-rule': 'true'} : {})}));
|
|
1464
1573
|
return tag("g", traceAttrs(options, item.path), children.join("\n"));
|
|
1465
1574
|
}
|
|
1466
1575
|
|
|
@@ -1477,6 +1586,8 @@ function renderTimeline(item, box, bound, options) {
|
|
|
1477
1586
|
if(!layout)throw new OPFRenderError('missing-timeline-layout','Timeline rendering requires a coordinated core build with shared timeline geometry.',{path:item.path});
|
|
1478
1587
|
const scale=Math.min(bound.design.dimensions.width,bound.design.dimensions.height)/720;
|
|
1479
1588
|
const children=[tag('line',{...HIDDEN,...layout.connector,stroke:bound.design.colors.border,'stroke-width':3*scale,...traceAttrs(options,item.path)})];
|
|
1589
|
+
// LH-121: the connector up to the current event in the primary color, over the border-colored rest.
|
|
1590
|
+
if(layout.progress)children.push(tag('line',{...HIDDEN,...layout.progress,stroke:bound.design.colors.primary,'stroke-width':3*scale,...traceAttrs(options,item.path),...(options.trace?{'data-opf-timeline-progress':'true'}:{})}));
|
|
1480
1591
|
// FA-11: status colors come from the deck (core's timelineMarkerShapes / timelineTextColor); a marker with no status draws the plain primary circle.
|
|
1481
1592
|
const background=bound.design.backgroundColor??bound.design.colors.background;
|
|
1482
1593
|
const statusColors={background,primary:bound.design.colors.primary,text:bound.design.colors.text,mutedText:bound.design.colors.mutedText};
|
|
@@ -1494,13 +1605,23 @@ function renderTimeline(item, box, bound, options) {
|
|
|
1494
1605
|
fill:part.status?timelineTextColor(part,statusColors):bound.design.colors.text,diagnosticsHandled:true,options,
|
|
1495
1606
|
})));
|
|
1496
1607
|
}
|
|
1608
|
+
// LH-121: the generated status word under each label; it traces to its event, not to a source field.
|
|
1609
|
+
for(const label of layout.statusLabels??[]){
|
|
1610
|
+
if(!label.fit)continue;
|
|
1611
|
+
children.push(tag('g',options.trace?{'data-opf-timeline-role':'status'}:{},renderTextBox(label.text,label.box,bound,{
|
|
1612
|
+
path:label.path.replace(/\.status$/,''),fit:label.fit,textStyle:label.style,fontFamily:label.requestedStyle.fontFamily,align:label.alignment,
|
|
1613
|
+
fill:timelineTextColor(label,statusColors),diagnosticsHandled:true,options,
|
|
1614
|
+
})));
|
|
1615
|
+
}
|
|
1497
1616
|
return tag('g',{...traceAttrs(options,item.path),...(options.trace?{'data-opf-timeline-arrangement':layout.arrangement}:{})},children.join('\n'));
|
|
1498
1617
|
}
|
|
1499
1618
|
|
|
1500
1619
|
function renderTable(item, box, bound, options) {
|
|
1501
1620
|
const scale = Math.min(bound.design.dimensions.width, bound.design.dimensions.height) / 720;
|
|
1502
|
-
const layout = layoutTable(item.value, box, {scale, minFontSize:(bound.composition ?? bound.geometry.composition).minFontSize, fontFamily:bound.design.fonts.body, ...(bound.design.fonts.code ? {codeFontFamily:bound.design.fonts.code} : {}), textMeasurement:options.textMeasurement, path:item.path, presentation:bound.presentation, alignment:bound.geometry.design.contentAlignment, ...(bound.geometry?.direction === "rtl" ? {direction:"rtl"} : {})});
|
|
1621
|
+
const layout = layoutTable(item.value, box, {scale, minFontSize:(bound.composition ?? bound.geometry.composition).minFontSize, fontFamily:bound.design.fonts.body, ...(bound.design.fonts.code ? {codeFontFamily:bound.design.fonts.code} : {}), textMeasurement:options.textMeasurement, path:item.path, presentation:bound.presentation, alignment:bound.geometry.design.contentAlignment, ...(bound.geometry?.direction === "rtl" ? {direction:"rtl"} : {}), ...(item.tableGrowth ? {growth:item.tableGrowth} : {}), ...(item.tableHighlight ? {highlight:item.tableHighlight} : {})});
|
|
1503
1622
|
const children = [];
|
|
1623
|
+
// LH-113: a highlighted row (table.highlight, or the rows the slide's texts name) draws on an accent tint of the surface.
|
|
1624
|
+
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;
|
|
1504
1625
|
// RR-54: a dataset table has no rows or columns of its own to point at; every cell reports the table's authored path.
|
|
1505
1626
|
const own = isDatasetTable(item, bound) ? () => item.path : (path) => path;
|
|
1506
1627
|
// WI-5 (P20): a table draws horizontal rules only by default (the header rule and a rule under every row, as the PPTX export writes them).
|
|
@@ -1508,7 +1629,7 @@ function renderTable(item, box, bound, options) {
|
|
|
1508
1629
|
const defaultEdges = [], explicitEdges = [];
|
|
1509
1630
|
for (const row of layout.rows) for (const cell of row.cells) {
|
|
1510
1631
|
const style = cell.style ?? {};
|
|
1511
|
-
const defaultFill = cell.header ? bound.design.colors.primary : bound.design.colors.surface;
|
|
1632
|
+
const defaultFill = cell.header ? bound.design.colors.primary : cell.highlighted ? highlightFill : bound.design.colors.surface;
|
|
1512
1633
|
const fill = style.fill == null
|
|
1513
1634
|
? defaultFill
|
|
1514
1635
|
: resolveColorRef(style.fill, bound, defaultFill);
|
|
@@ -1583,6 +1704,41 @@ function renderTableBorders(defaultEdges, explicitEdges, scale, bound, options)
|
|
|
1583
1704
|
});
|
|
1584
1705
|
}
|
|
1585
1706
|
|
|
1707
|
+
// A diagram is core's drawing (item.diagram, laid out by composition in the deck's measured fonts), painted by core's paintDiagramGroup in
|
|
1708
|
+
// the slide's diagram palette: tints of the variant's first accent over the surface it sits on (its card, else the slide background),
|
|
1709
|
+
// lines and text from the slide's roles, and the chart series of the same slide, so it reads as part of the deck on a light or a dark
|
|
1710
|
+
// slide and matches the PPTX export. It is a picture: role="img" named by its alt (authored, else derived from its labels). A source that
|
|
1711
|
+
// cannot be drawn shows the unavailable-content placeholder; composition reported why (unresolved-content).
|
|
1712
|
+
export function diagramSurface(item, bound) {
|
|
1713
|
+
return item.frameBox ? bound.design.roles.neutrals.card.hex : bound.design.backgroundColor ?? bound.design.colors.background;
|
|
1714
|
+
}
|
|
1715
|
+
export function slideDiagramPalette(item, bound) {
|
|
1716
|
+
const design = bound.design;
|
|
1717
|
+
return diagramPalette({
|
|
1718
|
+
surface: diagramSurface(item, bound), text: design.colors.text, mutedText: design.colors.mutedText, colorScheme: design.colorScheme,
|
|
1719
|
+
context: { accents: design.roles.map.accents, roles: design.colors, variables: design.variables },
|
|
1720
|
+
dark: design.colorScheme.dark1 ?? ENGINE_DEFAULT_COLOR_SCHEME.dark1, light: design.colorScheme.light1 ?? ENGINE_DEFAULT_COLOR_SCHEME.light1,
|
|
1721
|
+
fonts: { body: design.fonts.body, code: design.fonts.code ?? design.fonts.body },
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
function renderDiagram(item, box, bound, options) {
|
|
1725
|
+
const diagram = item.diagram;
|
|
1726
|
+
if (!diagram || diagram.issue || !diagram.svg) {
|
|
1727
|
+
// In a browser a diagram type loads on demand (core's ensureDiagrams, which the fonts handle's `ensure` calls): until then the
|
|
1728
|
+
// block reads as loading, not as a problem of the document.
|
|
1729
|
+
const loading = diagram?.issue?.code === "diagram-unloaded";
|
|
1730
|
+
const scale = Math.min(bound.geometry.width, bound.geometry.height) / 720, area = diagram?.box ?? box;
|
|
1731
|
+
const label = loading ? "Loading diagram" : "Diagram unavailable";
|
|
1732
|
+
const message = loading ? label : diagram?.issue ? `Diagram unavailable: ${diagram.issue.message}` : "Diagram unavailable";
|
|
1733
|
+
return tag("g", { ...traceAttrs(options, item.path), "data-opf-diagram-status": loading ? "loading" : "unresolved", role: "img", "aria-label": message }, [
|
|
1734
|
+
tag("rect", { x: area.x, y: area.y, width: area.width, height: area.height, fill: "none", stroke: bound.design.roles.neutrals.border.hex, "stroke-width": scale, "stroke-dasharray": `${4 * scale} ${3 * scale}` }),
|
|
1735
|
+
tag("text", { x: area.x + area.width / 2, y: area.y + area.height / 2, "text-anchor": "middle", "dominant-baseline": "middle", "font-family": fontStack(bound.design.fonts.body), "font-size": 20 * scale, fill: bound.design.colors.mutedText }, label),
|
|
1736
|
+
].join("\n"));
|
|
1737
|
+
}
|
|
1738
|
+
const painted = paintDiagramGroup(diagram, slideDiagramPalette(item, bound), diagram.box);
|
|
1739
|
+
return tag("g", { ...traceAttrs(options, item.path), "data-opf-diagram": diagram.type, role: "img", "aria-label": diagram.alt }, painted);
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1586
1742
|
function renderChart(item, box, bound, options) {
|
|
1587
1743
|
// Catalog chart types preview the native
|
|
1588
1744
|
// construct opf-pptx exports; other ids keep the legacy single-series preview.
|
|
@@ -1818,11 +1974,15 @@ function rtlTrailingSpace(text) {
|
|
|
1818
1974
|
* chunk with the outer face first and, when a fallback face covers every character, replaces every glyph with that face's (the Latin
|
|
1819
1975
|
* phrase of an Arabic item took a wider fallback face and ran into the bullet).
|
|
1820
1976
|
*/
|
|
1821
|
-
function scriptLine(text, style, bound, type, { rtl = false, placement, runPlacement, trace, fontSize } = {}) {
|
|
1977
|
+
function scriptLine(text, style, bound, type, { rtl = false, numbers = rtl, placement, runPlacement, trace, fontSize } = {}) {
|
|
1822
1978
|
const value = String(text ?? "");
|
|
1823
1979
|
const scripts = (style?.lang && bound.scriptFontsFor?.(style.lang)) || bound.scriptFonts;
|
|
1824
1980
|
rtl = rtl && value !== "";
|
|
1825
1981
|
const isolate = content => rtl ? `${RIGHT_TO_LEFT_ISOLATE}${content}${POP_DIRECTIONAL_ISOLATE}` : content;
|
|
1982
|
+
// LH-118: inside a right-to-left line each number is a left-to-right isolate, so "+16%" keeps its sign before its digits (core
|
|
1983
|
+
// isolateNumbers; the PPTX export writes the same numbers as en-US runs).
|
|
1984
|
+
// `numbers` asks for it in a fragment of a flowing right-to-left line, which is one isolate across its fragments.
|
|
1985
|
+
const escaped = text => escapeText(numbers && text ? isolateNumbers(text) : text);
|
|
1826
1986
|
const runs = value && scripts ? scripts.plan(value, style) : [{ text: value, own: true }];
|
|
1827
1987
|
if (!placement && runPlacement && runs.length > 1) placement = runPlacement;
|
|
1828
1988
|
// 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.
|
|
@@ -1833,14 +1993,14 @@ function scriptLine(text, style, bound, type, { rtl = false, placement, runPlace
|
|
|
1833
1993
|
if (runs.length === 1 && !(symbols && placement && placement.width > 0)) {
|
|
1834
1994
|
const [run] = runs;
|
|
1835
1995
|
// RR-38: a replacement the policy scales (Arabic Typesetting -> Noto Naskh Arabic, 0.64) is drawn at the scaled size; the caller applies it.
|
|
1836
|
-
return { content: isolate(
|
|
1996
|
+
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) };
|
|
1837
1997
|
}
|
|
1838
1998
|
const baseSize = placement?.fontSize ?? fontSize;
|
|
1839
1999
|
const adjusted = run => run.sizeAdjust && baseSize > 0 ? stableNumber(adjustedFontSize(baseSize, run.sizeAdjust)) : undefined;
|
|
1840
2000
|
const widths = placement && placement.width > 0 ? scripts.runWidths(runs, placement.fontSize, style) : undefined;
|
|
1841
2001
|
if (!widths) {
|
|
1842
|
-
return { content: isolate(runs.map(run => run.own ?
|
|
1843
|
-
: tag("tspan", { "font-family": fontStack(run.stack ?? run.family, type), "font-size": adjusted(run), style: nestedReset(style, run) },
|
|
2002
|
+
return { content: isolate(runs.map(run => run.own ? escaped(run.text)
|
|
2003
|
+
: tag("tspan", { "font-family": fontStack(run.stack ?? run.family, type), "font-size": adjusted(run), style: nestedReset(style, run) }, escaped(run.text))).join("")), ...shiftOf(runs) };
|
|
1844
2004
|
}
|
|
1845
2005
|
const natural = symbols ? scripts.runWidths(runs, placement.fontSize, style, { natural: true }) : undefined;
|
|
1846
2006
|
const total = widths.reduce((sum, width) => sum + width, 0), factor = total > 0 ? placement.width / total : 1;
|
|
@@ -1863,7 +2023,7 @@ function scriptLine(text, style, bound, type, { rtl = false, placement, runPlace
|
|
|
1863
2023
|
"font-size": adjusted(run),
|
|
1864
2024
|
style: run.own ? undefined : nestedReset(style, run),
|
|
1865
2025
|
...(trace ? trace(start, offset - trail.length) : {})
|
|
1866
|
-
}, isolate(
|
|
2026
|
+
}, isolate(escaped(drawn)));
|
|
1867
2027
|
}).join("");
|
|
1868
2028
|
return { content, positioned: true, ...shiftOf(runs) };
|
|
1869
2029
|
}
|
|
@@ -2064,10 +2224,14 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2064
2224
|
gap=full>0?Math.min(fragment.width,Math.max(0,fragment.width*(1-measure(fragment.text.slice(0,-trail.length),fragment.fontSize)/full))):0;
|
|
2065
2225
|
if(!asFlow)position.x=stableNumber(originX+fragmentX+gap);
|
|
2066
2226
|
}
|
|
2067
|
-
|
|
2227
|
+
// LH-32: an eyebrow run (core's style.caps, style.tracking) draws its capitals with core's letter spacing.
|
|
2228
|
+
// LH-32: a tracked run (an eyebrow) keeps its natural advance: its letter spacing is in core's width, and a textLength would leave the
|
|
2229
|
+
// trailing spacing to each rasterizer's own reading.
|
|
2230
|
+
const tracked=fragment.kind!=='tab'&&!!fragment.style.tracking;
|
|
2231
|
+
const drawnText=styledText(trail?fragment.text.slice(0,-trail.length):fragment.text,fragment.style),drawnWidth=fragment.width-gap;
|
|
2068
2232
|
// FA-13: an inline code run falls back to a monospace face, and a run with its own language declares it.
|
|
2069
2233
|
const runLang=fragment.kind!=='tab'&&fragment.style.lang?(bound.scriptFontsFor?.(fragment.style.lang)?.profile.bcp47??fragment.style.lang):undefined;
|
|
2070
|
-
const scripted=fragment.kind==='tab'?{content:escapeText(fragment.text)}:scriptLine(drawnText,fragment.style,bound,run.code===true?'monospace':bound.design.fontScheme.type,{rtl:rtl&&!asFlow,
|
|
2234
|
+
const scripted=fragment.kind==='tab'?{content:escapeText(fragment.text)}:scriptLine(drawnText,fragment.style,bound,run.code===true?'monospace':bound.design.fontScheme.type,{rtl:rtl&&!asFlow,numbers:rtl&&run.code!==true,
|
|
2071
2235
|
placement:fixedAdvance&&!asFlow?{x:originX+fragmentX+gap,width:drawnWidth,fontSize:fragment.fontSize}:undefined,
|
|
2072
2236
|
runPlacement:measuredLine&&!fixedAdvance?{x:originX+fragmentX+gap,width:drawnWidth,fontSize:fragment.fontSize}:undefined,fontSize:fragment.fontSize});
|
|
2073
2237
|
if(scripted.positioned)fixedAdvance=false;
|
|
@@ -2075,7 +2239,7 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2075
2239
|
// RR-34: a citation/footnote marker is generated text (no source range): it is traced as a marker
|
|
2076
2240
|
// segment without text offsets, so editors never read it as part of the run, and it is not linked.
|
|
2077
2241
|
const marker=fragment.kind==='marker';
|
|
2078
|
-
const rendered=tag(asFlow?'tspan':'text',{...(runLang?{lang:runLang,'xml:lang':runLang}:{}),...(config.options.trace?marker?{'data-opf-segment':'marker','data-opf-marker':fragment.text}:{'data-opf-text-start':runOffsets[fragment.runIndex]+fragment.start,'data-opf-text-end':runOffsets[fragment.runIndex]+fragment.end-trail.length,'data-opf-segment':fragment.kind}:{}),...position,'xml:space':'preserve','text-rendering':asFlow?undefined:'geometricPrecision',textLength:fixedAdvance?stableNumber(drawnWidth):undefined,lengthAdjust:fixedAdvance?'spacingAndGlyphs':undefined,'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,'text-decoration':marker?undefined:[run.underline||linked?'underline':'',run.strikethrough?'line-through':''].filter(Boolean).join(' ')||undefined,fill:runFill},content);
|
|
2242
|
+
const rendered=tag(asFlow?'tspan':'text',{...(runLang?{lang:runLang,'xml:lang':runLang}:{}),...(config.options.trace?marker?{'data-opf-segment':'marker','data-opf-marker':fragment.text}:{'data-opf-text-start':runOffsets[fragment.runIndex]+fragment.start,'data-opf-text-end':runOffsets[fragment.runIndex]+fragment.end-trail.length,'data-opf-segment':fragment.kind}:{}),...position,'xml:space':'preserve','text-rendering':asFlow?undefined:'geometricPrecision',textLength:fixedAdvance&&!tracked?stableNumber(drawnWidth):undefined,lengthAdjust:fixedAdvance&&!tracked?'spacingAndGlyphs':undefined,'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,'letter-spacing':fragment.kind!=='tab'&&fragment.style.tracking?stableNumber(fragment.style.tracking*fragment.fontSize):undefined,'text-decoration':marker?undefined:[run.underline||linked?'underline':'',run.strikethrough?'line-through':''].filter(Boolean).join(' ')||undefined,fill:runFill},content);
|
|
2079
2243
|
if(linked)return tag('a',{href:run.link,target:'_blank',rel:'noopener noreferrer'},rendered);
|
|
2080
2244
|
return rendered;
|
|
2081
2245
|
};
|
|
@@ -2134,6 +2298,8 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2134
2298
|
const logicalAlignment=fit.placement?.alignment??config.align??bound.geometry.design.contentAlignment;
|
|
2135
2299
|
const type = config.fontFamily === bound.design.fonts.code ? "monospace" : bound.design.fontScheme.type;
|
|
2136
2300
|
const source = String(text ?? ""), boxRtl = paragraphRtl(bound, source);
|
|
2301
|
+
// LH-76: one part of a split "Topic: qualifier" title traces its source ranges in the authored title, the value at its path.
|
|
2302
|
+
const sourceOffset = config.sourceOffset ?? 0;
|
|
2137
2303
|
let cursor = 0;
|
|
2138
2304
|
const lines = fit.lines.map((line, index) => {
|
|
2139
2305
|
// Logical alignment (RR-05): a right-to-left line starts at the right edge.
|
|
@@ -2149,8 +2315,8 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2149
2315
|
let content,family,positioned=false,trimWidth=0,sizeAdjust,shift=0;
|
|
2150
2316
|
if(tabs) content=sourceLine.segments.map(segment=>{
|
|
2151
2317
|
const segmentText=line.slice(segment.start-sourceLine.start,segment.end-sourceLine.start),fixed=segment.kind==='tab'||placed;
|
|
2152
|
-
const traced=(start,end)=>config.options.trace?{'data-opf-source-start':start,'data-opf-source-end':end,'data-opf-segment':segment.kind}:{};
|
|
2153
|
-
const scripted=segment.kind==='tab'?{content:escapeText(segmentText)}:scriptLine(segmentText,style,bound,type,{rtl,
|
|
2318
|
+
const traced=(start,end)=>config.options.trace?{'data-opf-source-start':sourceOffset+start,'data-opf-source-end':sourceOffset+end,'data-opf-segment':segment.kind}:{};
|
|
2319
|
+
const scripted=segment.kind==='tab'?{content:escapeText(segmentText)}:scriptLine(styledText(segmentText,style),style,bound,type,{rtl,
|
|
2154
2320
|
placement:placed?{x:origin+segment.x,width:segment.width,fontSize:size}:undefined,fontSize:size,
|
|
2155
2321
|
trace:config.options.trace?(start,end)=>traced(segment.start+start,segment.start+end):undefined});
|
|
2156
2322
|
if(scripted.positioned)return scripted.content;
|
|
@@ -2165,18 +2331,24 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2165
2331
|
// 2026-10-02), so a soft-wrapped line that keeps its trailing space, or a leading space, draws without it (RR-05).
|
|
2166
2332
|
const edge=rtl&&alignment==='right'?/^(\s*)([\s\S]*?)(\s*)$/.exec(line):null,trimmed=edge&&edge[2]&&(edge[1]||edge[3])?edge:null;
|
|
2167
2333
|
if(trimmed){const measureEdge=textWidthMeasurer(style,config.options.textMeasurement);trimWidth=measureEdge(trimmed[1],size)+measureEdge(trimmed[3],size);}
|
|
2168
|
-
({content,family,positioned=false,sizeAdjust,baselineShift:shift=0}=scriptLine(trimmed?trimmed[2]:line,style,bound,type,{rtl,placement:placed?.width>0?{x:placed.x+trimWidth,width:placed.width-trimWidth,fontSize:size}:undefined,fontSize:size}));
|
|
2334
|
+
({content,family,positioned=false,sizeAdjust,baselineShift:shift=0}=scriptLine(styledText(trimmed?trimmed[2]:line,style),style,bound,type,{rtl,placement:placed?.width>0?{x:placed.x+trimWidth,width:placed.width-trimWidth,fontSize:size}:undefined,fontSize:size}));
|
|
2169
2335
|
}
|
|
2170
2336
|
// Positioned script runs carry their own x and textLength (FF-19).
|
|
2171
2337
|
const start=tabs||positioned;
|
|
2338
|
+
// LH-32: core spaces an eyebrow's letters between characters, so its last character draws with no spacing after it: rasterizers
|
|
2339
|
+
// differ on whether a trailing spacing counts toward a middle or end anchor.
|
|
2340
|
+
if(style.tracking&&!start)content=untrackLast(content);
|
|
2172
2341
|
return tag("text", {
|
|
2173
2342
|
x: stableNumber(tabs?origin:positioned?placed.x:placed?placed.x+placed.width*factor:x), y: stableNumber((placed?.baseline??startY + index * fit.lineHeight) - shift * size),
|
|
2174
2343
|
"text-anchor": start?'start':anchor, "font-family": family ?? fontStack(style.fontFamily, type),
|
|
2175
2344
|
"font-size": stableNumber(adjustedFontSize(size,sizeAdjust)), "font-weight": style.fontWeight, "font-style": style.italic ? "italic" : undefined, fill: config.fill,
|
|
2345
|
+
// LH-32: an eyebrow (the tag, a label core sets as one) draws its capitals with core's letter spacing, as core measured it, at its
|
|
2346
|
+
// natural advance (no textLength: rasterizers differ on whether the spacing after the last letter counts toward it).
|
|
2347
|
+
"letter-spacing": style.tracking ? stableNumber(style.tracking * size) : undefined,
|
|
2176
2348
|
'xml:space':'preserve',style:'white-space:pre','text-rendering':config.options.textMeasurement?.measure?'geometricPrecision':undefined,
|
|
2177
|
-
textLength:!start&&placed?.width>0?stableNumber(placed.width-trimWidth):undefined,lengthAdjust:!start&&placed?.width>0?'spacingAndGlyphs':undefined,
|
|
2349
|
+
textLength:!start&&placed?.width>0&&!style.tracking?stableNumber(placed.width-trimWidth):undefined,lengthAdjust:!start&&placed?.width>0&&!style.tracking?'spacingAndGlyphs':undefined,
|
|
2178
2350
|
...traceAttrs(config.options, config.path),
|
|
2179
|
-
...(config.options.trace&&sourceLine?{'data-opf-source-start':sourceLine.start,'data-opf-source-end':sourceLine.end,'data-opf-source-next-start':sourceLine.nextStart,'data-opf-line-boundary':sourceLine.boundary}:{}),
|
|
2351
|
+
...(config.options.trace&&sourceLine?{'data-opf-source-start':sourceOffset+sourceLine.start,'data-opf-source-end':sourceOffset+sourceLine.end,'data-opf-source-next-start':sourceOffset+sourceLine.nextStart,'data-opf-line-boundary':sourceLine.boundary}:{}),
|
|
2180
2352
|
}, content);
|
|
2181
2353
|
});
|
|
2182
2354
|
return tag("g", { ...traceAttrs(config.options, config.path),
|