@openpresentation/opf-render 0.31.0 → 0.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -199,7 +199,7 @@ Accessibility of the SVG (FA-30): the slide root is a labelled container, `role=
199
199
 
200
200
  Text as outlines (RR-64): `toSvg(deck, { fonts, text: "paths" })` draws every `<text>` as glyph outlines, so the SVG needs no font and looks the same in every browser, image viewer and design tool. Each glyph is a `<use>` of an outline kept once per slide in `<defs>` (in font units, under an id made of the face's content hash and the glyph id, so SVGs inlined on one page never mix up glyphs); positions and widths are the vector PDF's layout of the renderer's pinned lines, and the glyphs are shaped by HarfBuzz, the shaper browsers use (the Node handle always; a browser handle given `shapeWasm`, the host's copy of `harfbuzzjs/dist/harfbuzz.wasm`; fontkit otherwise). Over the 30 script corpora every outlined glyph has HarfBuzz's id and position (fontkit, which the layout measures with, picks other glyphs on 10 samples: Bengali, Thai, Lao, Khmer, Myanmar, Syriac and Japanese combining marks); a run inside a pinned width is scaled to it, as the browser scales text. Over the core example decks resvg draws an outlined slide like its text (mean channel difference at most 0.006 of 255) and an outlined slide is about 40 KB at the median (60 KB at p90, 106 KB at most) against 0.5 to 4 MB with whole embedded faces. It needs the fonts handle `loadFonts()` returns, which carries the outline engine as `fonts.outlines` (`text-as-paths-needs-fonts` otherwise); the handle's faces are parsed for outlining once, on the first outlined slide. Each outlined element is a group that keeps the element's attributes and `data-opf-*` trace (a tspan's trace stays on a nested group); its glyphs are hidden from assistive technology and each outlined line is also real text, invisible (`fill="none"`, the generic family, so no face is embedded for it) and pinned to the drawn width, in reading order: a screen reader reads the words as text (the FA-30 tree, checked with axe), and selection, copy and find-in-page work. Links stay `<a>`; underline and line-through are rectangles from the font's own metrics. A run stays text where outlines would not be faithful, reported as `text-as-paths-fallback` with its `reason`: a colour or bitmap font (`colour-font`, emoji), a face whose fsType restricts embedding (`restricted`), or a run with no pinned width on which HarfBuzz and the layout's measurement disagree by more than 0.1 px (`shaping`); the SVG embeds just those runs' faces. The trade-offs, which make it the choice for thumbnails, previews and portable SVG files and not for an editing surface: the drawn text is not editable (a caret and an input method need live text in its own font); a vector PDF made from an outlined SVG has paths instead of selectable text, so `toPdf` should get the `<text>` SVG; browsers draw outlines without the hinting they give text, so small text looks a little lighter than browser text (resvg already draws text as outlines); and in `/fonts-browser` the outline engine adds about 85 KB (minified) to the bundle. Plan and later phases: [opf-render#164](https://github.com/OpenPresentation/opf-render/issues/164).
201
201
 
202
- The preview draws three accepted spec fields from tables shared with opf-pptx through core (`@openpresentation/opf`): `code.language` colours code (comments, strings, numbers, keywords, names and types, in theme-derived colours kept at 4.5:1 or more on the code panel; an unknown language stays plain and the text is never changed), `metric.trend` draws an arrow beside the trend word (green up, red down, neutral flat, with "Trend: up" as its text alternative) and colours the delta and trend text, and every one of the 54 DrawingML preset pattern backgrounds draws from its 8 x 8 bitmap (one pixel per 1/96 inch from the slide's top-left). With a core that lacks these exports the preview draws plain, without a new diagnostic. `scripts/derive-pattern-bitmaps.mjs` compares a PowerPoint export of the pattern slides with core's tiles (ECMA-376 names the presets without defining their pixels; core's tiles were measured with it from desktop PowerPoint, Office 365, Windows, 2026-10-01).
202
+ The preview draws three accepted spec fields from tables shared with opf-pptx through core (`@openpresentation/opf`): `code.language` colors code (comments, strings, numbers, keywords, names and types, in theme-derived colors kept at 4.5:1 or more on the code panel; an unknown language stays plain and the text is never changed), `metric.trend` draws an arrow before the delta (green up, red down, neutral flat, with "Trend: up" as its text alternative; LH-53: the trend word is not drawn) and colors the delta text, and every one of the 54 DrawingML preset pattern backgrounds draws from its 8 x 8 bitmap (one pixel per 1/96 inch from the slide's top-left). With a core that lacks these exports the preview draws plain, without a new diagnostic. `scripts/derive-pattern-bitmaps.mjs` compares a PowerPoint export of the pattern slides with core's tiles (ECMA-376 names the presets without defining their pixels; core's tiles were measured with it from desktop PowerPoint, Office 365, Windows, 2026-10-01).
203
203
 
204
204
  ```js
205
205
  import { toSvg } from "@openpresentation/opf-render";
@@ -218,6 +218,16 @@ The installed open font pack works offline. The Aptos family previews with the m
218
218
 
219
219
  Unresolved images produce an `unresolved-asset` diagnostic through `onDiagnostic` (a warning in the CLI report, `render/unresolved-asset`, which `--fail-on warning` turns into a failure), including the OPF path, the `source` the author wrote, the reason and the complete description; the `message` names that source, and the image is skipped, not the render. It covers every place a deck spells an image: slide backgrounds (also tiled), image blocks, header/footer and organization logos, picture watermarks, picture bullets, and `asset:` references. The fallback shows a bounded status label when it fits above the selected readability floor, otherwise an icon with the full accessible description. The label is `Image unavailable` over the description (alt, else title, else `Image`) in semibold at 20 px on a 1280 x 720 canvas, and opf-pptx exports the same placeholder as native shapes. It preserves authored opacity, including faint decorative watermarks; a missing image is still missing even when its fallback fits. Use `strictAssets: true` to reject unresolved images. Supply embedded raster data URIs or a synchronous host `imageResolver` to resolve them; the renderer does not fetch URLs or read local paths. Caller descriptions and other metadata override referenced asset metadata through alias chains. These diagnostics identify unresolved sources, not malformed image bytes or native PowerPoint compatibility.
220
220
 
221
+ Text on a picture background gets an automatic scrim (LH-02), sized for any picture from black to white unless the host measured the picture. `measurePictures(deck, options?)` does that: it decodes each picture background once (a data URI, an `asset:` reference, or what `options.imageResolver` returns; nothing is fetched unless you pass `options.fetch`) and resolves a sampler to pass as `pictureLuminance` to `toSvg` and to opf-pptx's `toPptx`, so a dark photo under white text gets no scrim in either. Node decodes with the optional `sharp` peer, loaded on first use; the browser entries decode on a canvas and import no Node module. Keep `options.cache` (a `Map`) between calls to decode a picture once across edits. A picture that cannot be decoded is reported as `picture-not-measured` and keeps the worst case.
222
+
223
+ ```js
224
+ import { measurePictures, toSvg } from "@openpresentation/opf-render";
225
+ import { toPptx } from "@openpresentation/opf-pptx";
226
+ const pictureLuminance = await measurePictures(deck, { imageResolver });
227
+ const svgs = toSvg(deck, { fonts, imageResolver, pictureLuminance });
228
+ const pptx = await toPptx(deck, { fonts, imageResolver, pictureLuminance });
229
+ ```
230
+
221
231
  Header/footer images and watermarks fit their complete artwork within their allocated regions. Image blocks use their own `fit`, else `design.imageFit` (default `cover`), as core resolves it into `item.image.fit`.
222
232
 
223
233
  An `image/svg+xml` data URI (base64 or text) is drawn as an image wherever a raster is (image block, header/footer, watermark, logo, background, picture bullet), with the raster's box and fit, when it is an `<svg>` in the SVG namespace with an intrinsic size (`width` and `height`, or a `viewBox`); anything else keeps the `Image unavailable` placeholder. opf-pptx exports the same picture as a native SVG picture over a PNG fallback. An SVG used as an image never runs script or loads anything outside its own document, in a browser or in PNG/PDF output; PNG and PDF output draw it with resvg, and its text uses the same bundled fonts.
@@ -362,10 +372,12 @@ It is the layout the editor playground and the OpenPresentation sites serve, and
362
372
 
363
373
  ### `<opf-deck>`
364
374
 
365
- Attributes: `src` (OPF JSON; the other request the element makes), `slide` (1-based; counts the slides that play), `fonts`, `thumbnails` (a strip of slide thumbnails), `controls="none"`, `present` (a Present button), `include-hidden`, `label`, `keyboard="off"`. Instead of `src` set the `document` property (an object or JSON text), or put the document in a child `<script type="application/opf+json">`. Properties and methods: `document`, `slide`, `total`, `fonts` (the font root URL, or a handle that wins over the attribute), `renderOptions` (extra `toSvg` options such as `catalogs` and `imageResolver`), `currentSlide` (`{ slide, total, index, id, title, notes, section }`; `notes` is plain text), `ready`, `next()`, `previous()`, `first()`, `last()`, `goto(n)`, `reload()` and `present(options)`.
375
+ Attributes: `src` (OPF JSON; the other request the element makes), `slide` (1-based; counts the slides that play), `fonts`, `thumbnails` (a strip of slide thumbnails), `controls="none"`, `present` (a Present button), `include-hidden`, `label`, `keyboard="off"`, `continuation="off"` (draw overfull slides as written; see below). Instead of `src` set the `document` property (an object or JSON text), or put the document in a child `<script type="application/opf+json">`. Properties and methods: `document`, `slide`, `total`, `fonts` (the font root URL, or a handle that wins over the attribute), `renderOptions` (extra `toSvg` options such as `catalogs` and `imageResolver`), `currentSlide` (`{ slide, total, index, page, pages, id, title, notes, section }`; `notes` is plain text), `page` and `pages`, `ready`, `next()`, `previous()`, `first()`, `last()`, `goto(n)`, `reload()` and `present(options)`.
366
376
 
367
377
  Events: `ready`, `slidechange` (the same detail as `currentSlide`; bubbles and is composed), `error` (`{ code, message, fatal }`, not bubbling), `presentstart` and `presentend`. Style it with custom properties (`--opf-deck-fg`, `--opf-deck-border`, `--opf-deck-radius`, `--opf-deck-focus`, `--opf-deck-accent`, `--opf-deck-stage`) and the parts `deck`, `viewport`, `slide`, `bar`, `button`, `previous`, `next`, `present`, `counter`, `thumbnails` and `thumbnail`.
368
378
 
379
+ Overfull slides (LH-99): a slide the export continues on further pages (`continueOverfull`, LH-90: two or more sibling blocks of one kind, such as eight timelines, that overflow at the readability floor) shows those pages as steps after it, in `<opf-deck>`, its thumbnails, the player, the speaker view and `toHtml`. Each page is the export's own page, drawn by the same `toSvg` call on the export's deck, so the screen, the PDF and the PPTX agree (the slide-number furniture a page draws is the export's number). Source slides keep their numbers: `slide`, `total`, `goto(n)`, the `slide` attribute, number-then-Enter, the thumbnails and `slidechange`'s `slide` and `index` all address the slides of the document, and the pages are sub-steps of their slide. `page` and `pages` (from 1) say which page shows; next and previous step through the pages (previous from a slide's first page lands on the last page of the slide before, End on the last page of the last slide), and `slidechange` fires for every step with `page` and `pages` in its detail. The counter reads `2 / 3 · 2/2` and the slide's name `Slide 2 of 3, page 2 of 2: Execution paths`; a continued slide's thumbnail is a stack with its page count, and `toHtml` draws each page as its own figure. The player's `startPage` option starts on a page, and the windows of one show share the page. `continuation="off"` (the element) and `continuation: false` (`present` and `toHtml`) draw every slide as written.
380
+
369
381
  Hidden slides (`hidden: true`) are skipped everywhere, so the counter, the `slide` attribute and the player's number-then-Enter all count the sequence that plays; `include-hidden` plays them all. Navigation: the buttons, ArrowLeft, ArrowRight, Page Up, Page Down, Home and End while the slide has focus (Up, Down and Space are left to the page), a horizontal swipe on touch, and the thumbnails. A deck whose `language` is right to left (and a page that sets `dir` or CSS `direction`) turns the controls and the Left and Right keys around.
370
382
 
371
383
  Accessibility: the element is a labelled region (the deck name) holding a focusable group named `Slide 3 of 8: Revenue grew`; slide text is live SVG text in the order the renderer paints it (tag, title, content, footnotes, then header and footer), not an image, so a screen reader can reach it (the DOM structure; see the testing statement below); slide changes made by keyboard or thumbnail are announced through a polite live region; thumbnails are a list of buttons (one tab stop, arrow keys inside, `aria-current`) whose drawings are hidden from assistive technology; the buttons keep their focus ring and have `forced-colors` styles; and animation is limited to a hover colour that `prefers-reduced-motion: reduce` removes. The test suite runs axe-core (WCAG 2.0 to 2.2 A and AA plus best practice) over the element, the player and the speaker view with no violations. There are no transitions or builds (deferred, opf#250).
@@ -426,7 +438,7 @@ The base and Office pack standalone SVGs both contain two Roboto rules (430,764
426
438
 
427
439
  ### The slideshow
428
440
 
429
- `present(source, options)` takes an OPF document, its URL or an `<opf-deck>` element and covers the page with a full-screen player (call it from a click or key handler; full screen and the speaker view need a user gesture). It resolves with a `PlayerSession` (`slide`, `total`, `next()`, `previous()`, `first()`, `last()`, `goto(n)`, `blank('black' | 'white' | 'none')`, `openPresenterView()`, `close()`; events `slidechange`, `blank`, `presenterview`, `close`). One show per document: a second call returns the running one.
441
+ `present(source, options)` takes an OPF document, its URL or an `<opf-deck>` element and covers the page with a full-screen player (call it from a click or key handler; full screen and the speaker view need a user gesture). It resolves with a `PlayerSession` (`slide`, `total`, `page`, `pages`, `next()`, `previous()`, `first()`, `last()`, `goto(n)`, `blank('black' | 'white' | 'none')`, `openPresenterView()`, `close()`; events `slidechange`, `blank`, `presenterview`, `close`). One show per document: a second call returns the running one.
430
442
 
431
443
  Keys: Right, Down, Page Down, Space, Enter and `N` are next; Left, Up, Page Up, Backspace, Shift+Space and `P` are previous; Home and End; a slide number then Enter (Escape clears it); `B` and `W` toggle a black or white screen (any navigation key brings the slide back first); `S` opens the speaker view; `F` toggles full screen; Escape leaves (leaving full screen any other way ends the show too). Click or tap advances (the left third goes back) and a horizontal swipe navigates. The player is a modal dialog: the rest of the page is inert, focus stays inside it and returns to where it was when the show ends, and an element that started it follows the show and fires `slidechange`.
432
444
 
@@ -85,21 +85,21 @@ export function drawAxisTitles(c) {
85
85
 
86
86
  const INSIDE = new Set(["center", "inside-end", "inside-base"]);
87
87
 
88
- /** The label text for one mark: the selected parts, the series' number format (General when it has none), integer percent. */
89
- export function labelString(c, { category, value, share, format }) {
88
+ /** The label text for one mark: the selected parts, the series' number format (General when it has none; LH-141: grouped by the deck language when `group`), integer percent. */
89
+ export function labelString(c, { category, value, share, format, group }) {
90
90
  const labels = c.dataLabels;
91
91
  const parts = {};
92
92
  if (category !== undefined && category !== null) parts.category = String(category);
93
- if (typeof value === "number" && Number.isFinite(value)) parts.value = format !== undefined ? formatDataNumber(value, format) : formatChartLabelNumber(value);
93
+ if (typeof value === "number" && Number.isFinite(value)) parts.value = format !== undefined ? formatDataNumber(value, format) : formatChartLabelNumber(value, group ? { language: typeof c.language === "string" ? c.language : undefined } : undefined);
94
94
  if (typeof share === "number" && Number.isFinite(share)) parts.percent = formatChartLabelPercent(share);
95
95
  return chartLabelText(parts, labels.content, labels.separator);
96
96
  }
97
97
 
98
98
  const labelSize = (c, text) => ({ width: c.width(text) + c.fontPx * 0.5, height: c.lineHeight });
99
99
 
100
- function drawLabel(c, text, rect, path, fill) {
100
+ function drawLabel(c, text, rect, path, fill, weight = 400) {
101
101
  if (!text) return;
102
- const element = c.textElement(text, rect, path, "center", fill);
102
+ const element = c.textElement(text, rect, path, "center", fill, weight);
103
103
  if (element) c.children.push(element);
104
104
  }
105
105
 
@@ -112,7 +112,7 @@ export function labelFill(c, position, fill) {
112
112
  * A label on a bar or column. `rect` is the mark, `direction` the way the bar grows from its base
113
113
  * ("up", "down", "right" or "left"), so inside-end and outside-end follow the sign of the value.
114
114
  */
115
- export function drawBarLabel(c, text, rect, direction, path, fill) {
115
+ export function drawBarLabel(c, text, rect, direction, path, fill, weight = 400) {
116
116
  const position = c.dataLabels.position ?? "center";
117
117
  const { width, height } = labelSize(c, text);
118
118
  let x, y;
@@ -136,7 +136,7 @@ export function drawBarLabel(c, text, rect, direction, path, fill) {
136
136
  else if (position === "inside-base") x = sign < 0 ? baseEdge - width : baseEdge;
137
137
  else x = centerX;
138
138
  }
139
- drawLabel(c, text, { x, y, width, height }, path, labelFill(c, position, fill));
139
+ drawLabel(c, text, { x, y, width, height }, path, labelFill(c, position, fill), weight);
140
140
  }
141
141
 
142
142
  /** A label beside a point mark (line and scatter): above, below, left, right or centred on it. `position` overrides the chart's (a combo chart's line series). */
@@ -160,11 +160,11 @@ export function drawCenteredLabel(c, text, x, y, path, fill) {
160
160
  drawLabel(c, text, { x: x - width / 2, y: y - height / 2, width, height }, path, fill ? labelFill(c, "center", fill) : c.labelColor);
161
161
  }
162
162
 
163
- /** A label on a pie or doughnut slice at the angle `mid`; `inner` is the ring's inner radius (0 for a pie). */
164
- export function drawSliceLabel(c, text, { cx, cy, r, inner, mid }, path, fill) {
163
+ /** A label on a pie or doughnut slice at the angle `mid`; `inner` is the ring's inner radius (0 for a pie). `own` is the slice's own position (LH-105). */
164
+ export function drawSliceLabel(c, text, { cx, cy, r, inner, mid }, path, fill, own) {
165
165
  const { width, height } = labelSize(c, text);
166
166
  const cos = Math.cos(mid), sin = Math.sin(mid);
167
- const position = inner ? "center" : c.dataLabels.position ?? "outside-end";
167
+ const position = inner ? "center" : own ?? c.dataLabels.position ?? "outside-end";
168
168
  const half = (width * Math.abs(cos) + height * Math.abs(sin)) / 2;
169
169
  let radius;
170
170
  if (inner) radius = (r + inner) / 2;