@patterkit/ops 0.3.4 → 0.3.5

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.
Files changed (2) hide show
  1. package/dist/index.js +24 -14
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1972,7 +1972,7 @@ function targetLabel(to, sceneOf, blockTrail) {
1972
1972
  function gameEventLabel(beat) {
1973
1973
  const gd = beat.gameData;
1974
1974
  if (gd && typeof gd === "object") {
1975
- const parts = Object.entries(gd).slice(0, 3).map(([k, v]) => {
1975
+ const parts = Object.entries(gd).map(([k, v]) => {
1976
1976
  const val = v == null ? "" : typeof v === "object" ? JSON.stringify(v) : String(v);
1977
1977
  return val === "" ? k : `${k}: ${val}`;
1978
1978
  });
@@ -2200,7 +2200,7 @@ var isEmoji = (cp) => cp >= 126976 || cp >= 9728 && cp <= 10175;
2200
2200
  async function scriptToPdf(doc) {
2201
2201
  const { scriptFont } = await import("./script-fonts-AQNQOADI.js");
2202
2202
  return new Promise((resolve5, reject) => {
2203
- const pdf = new PDFDocument({ size: "A4", margins: { top: MARGIN, bottom: MARGIN, left: MARGIN, right: MARGIN }, info: { Title: doc.project, Author: "Patter" } });
2203
+ const pdf = new PDFDocument({ size: "A4", margins: { top: MARGIN, bottom: MARGIN, left: MARGIN, right: MARGIN }, info: { Title: doc.project, Author: "Patter" }, font: null });
2204
2204
  pdf.registerFont("Serif", scriptFont("serif"));
2205
2205
  pdf.registerFont("Serif-Bold", scriptFont("serifBold"));
2206
2206
  pdf.registerFont("Serif-Italic", scriptFont("serifItalic"));
@@ -2297,13 +2297,12 @@ async function scriptToPdf(doc) {
2297
2297
  bodyX = cueX + pdf.widthOfString(el.character.toUpperCase()) + CUE_GAP;
2298
2298
  }
2299
2299
  const yTop = pdf.y;
2300
- pdf.fontSize(BODY);
2301
- draw([...el.direction ? split(`(${el.direction}) `, "Serif-Italic", MUTED) : [], ...bodyPieces(el.runs, INK_READ)], bodyX, { width: Math.max(120, pageRight - bodyX), lineGap: LEAD });
2302
- const yEnd = pdf.y;
2303
2300
  if (el.character) {
2304
2301
  pdf.font("Sans-Bold").fontSize(CUE).fillColor(hex(characterColour(el.character))).text(el.character.toUpperCase(), cueX, yTop + ascentPt("Serif", BODY) - ascentPt("Sans-Bold", CUE), { lineBreak: false });
2302
+ pdf.y = yTop;
2305
2303
  }
2306
- pdf.y = yEnd;
2304
+ pdf.fontSize(BODY);
2305
+ draw([...el.direction ? split(`(${el.direction}) `, "Serif-Italic", MUTED) : [], ...bodyPieces(el.runs, INK_READ)], bodyX, { width: Math.max(120, pageRight - bodyX), lineGap: LEAD });
2307
2306
  break;
2308
2307
  }
2309
2308
  case "narration":
@@ -2327,21 +2326,29 @@ async function scriptToPdf(doc) {
2327
2326
  const tag = el.tag ? el.tag.toUpperCase() : "";
2328
2327
  const tagW = tag ? pdf.font("Sans").fontSize(7.5).widthOfString(tag) + 8 : 0;
2329
2328
  const yStart = pdf.y;
2330
- pdf.fontSize(BODY);
2331
- draw([...split("\u25C7 ", "Serif", ACCENT), ...bodyPieces(el.runs, INK)], ox, { width: Math.max(80, pageRight - ox - tagW), indent: -HANG2, lineGap: LEAD });
2332
- const yEnd = pdf.y;
2333
- if (tag && yEnd >= yStart) {
2329
+ if (tag) {
2334
2330
  pdf.font("Sans").fontSize(7.5).fillColor(MUTED).text(tag, pageRight - tagW, yStart, { width: tagW, align: "right", lineBreak: false });
2335
- pdf.y = yEnd;
2331
+ pdf.y = yStart;
2336
2332
  }
2333
+ pdf.fontSize(BODY);
2334
+ draw([...split("\u25C7 ", "Serif", ACCENT), ...bodyPieces(el.runs, INK)], ox, { width: Math.max(80, pageRight - ox - tagW), indent: -HANG2, lineGap: LEAD });
2337
2335
  break;
2338
2336
  }
2339
2337
  case "jump":
2340
2338
  drawRight(split(`\u21AA ${el.text}`, "Sans-Bold", ACCENT), 9.5);
2341
2339
  break;
2342
- case "gameEvent":
2343
- drawRight(split(`\u2699 ${el.text}`, "Mono", ACCENT), 9);
2340
+ case "gameEvent": {
2341
+ const pieces = split(`\u2699 ${el.text}`, "Mono", ACCENT);
2342
+ pdf.fontSize(9);
2343
+ let total = 0;
2344
+ for (const p of pieces) {
2345
+ pdf.font(p.font);
2346
+ total += pdf.widthOfString(p.text);
2347
+ }
2348
+ if (total <= pageRight - cx) drawRight(pieces, 9);
2349
+ else draw(pieces, cx, { width: pageRight - cx });
2344
2350
  break;
2351
+ }
2345
2352
  }
2346
2353
  };
2347
2354
  const leadOf = (k) => k === "scene" ? 24 : k === "block" ? 16 : k === "group" ? 13 : k === "else" ? 9 : 0;
@@ -2355,10 +2362,12 @@ async function scriptToPdf(doc) {
2355
2362
  const sameNext = sid !== void 0 && next !== void 0 && "snippet" in next && next.snippet === sid;
2356
2363
  if (el.kind === "scene") ensure(90);
2357
2364
  else if (el.kind === "block") ensure(70);
2365
+ else ensure(leadOf(el.kind) + BODY + LEAD + 14);
2358
2366
  pdf.y += leadOf(el.kind);
2359
2367
  const base = "indent" in el ? MARGIN + el.indent * INDENT_STEP : MARGIN;
2360
2368
  const cx = base + (sid !== void 0 ? EDGE_INSET : 0);
2361
2369
  const yTop = pdf.y;
2370
+ const pageBefore = pdf.page;
2362
2371
  drawContent(el, cx);
2363
2372
  const bottom = pdf.y;
2364
2373
  const trail = el.kind === "condition" ? TIGHT : el.kind === "scene" ? 12 : el.kind === "block" ? 11 : el.kind === "group" ? 7 : el.kind === "else" ? 4 : sid !== void 0 ? sameNext ? WITHIN2 : BETWEEN : BEAT;
@@ -2368,7 +2377,8 @@ async function scriptToPdf(doc) {
2368
2377
  curBase = "indent" in el ? el.indent : 0;
2369
2378
  }
2370
2379
  const ex = MARGIN + curBase * INDENT_STEP + EDGE_OFF;
2371
- pdf.strokeColor(EDGE).lineWidth(0.75).moveTo(ex, yTop).lineTo(ex, bottom + (sameNext ? trail : 0)).stroke();
2380
+ const top = pdf.page === pageBefore ? yTop : MARGIN;
2381
+ pdf.strokeColor(EDGE).lineWidth(0.75).moveTo(ex, top).lineTo(ex, bottom + (sameNext ? trail : 0)).stroke();
2372
2382
  }
2373
2383
  pdf.y = bottom + trail;
2374
2384
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patterkit/ops",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "The shared operations layer: every project operation (load, validate, export, format, play, ...) as a pure function, consumed by the patter CLI and Patterpad alike.",
5
5
  "type": "module",
6
6
  "license": "MIT",