@particle-academy/last-word 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -105,7 +105,7 @@ interface WriteResult {
105
105
  */
106
106
 
107
107
  /** Feature-parity baseline with PHP last-word; bumped independently on npm. */
108
- declare const VERSION = "0.1.0";
108
+ declare const VERSION = "0.2.0";
109
109
  type Any$2 = any;
110
110
  declare const Agent: {
111
111
  /** Validate a doc without writing. Empty array = valid. */
@@ -239,7 +239,9 @@ declare function resolveImageSize(block: {
239
239
 
240
240
  /**
241
241
  * DocxReader — .docx bytes → Doc JSON model. Handles this package's own
242
- * writer output losslessly (round-trip) and tolerates Word-authored files:
242
+ * writer output losslessly (round-trip), the PHP mirror's output (same
243
+ * metadata slots since 0.2.0, plus the legacy `LastWordCode_{lang}` bookmark
244
+ * fallback for PHP ≤0.1.x files) and tolerates Word-authored files:
243
245
  * headings via pStyle Heading1-9 OR outlineLvl, numPr lists with ilvl nesting,
244
246
  * hyperlinks via rels, images via blip r:embed, page breaks, bottom-border-only
245
247
  * paragraphs → hr. Unknown constructs degrade to plain paragraphs, never throw.
@@ -258,6 +260,12 @@ declare class DocxReader {
258
260
  private walkBody;
259
261
  private parseSdt;
260
262
  private classifyParagraph;
263
+ /**
264
+ * Back-compat: the code language from a PHP last-word ≤0.1.x
265
+ * `LastWordCode_{lang}` bookmark on this paragraph, if present. The
266
+ * canonical carrier is the `lastword:code:{lang}` sdt tag.
267
+ */
268
+ private legacyBookmarkLanguage;
261
269
  /** Concatenated visible text of a paragraph (tabs and soft breaks included). */
262
270
  private plainText;
263
271
  private parseRuns;
package/dist/index.d.ts CHANGED
@@ -105,7 +105,7 @@ interface WriteResult {
105
105
  */
106
106
 
107
107
  /** Feature-parity baseline with PHP last-word; bumped independently on npm. */
108
- declare const VERSION = "0.1.0";
108
+ declare const VERSION = "0.2.0";
109
109
  type Any$2 = any;
110
110
  declare const Agent: {
111
111
  /** Validate a doc without writing. Empty array = valid. */
@@ -239,7 +239,9 @@ declare function resolveImageSize(block: {
239
239
 
240
240
  /**
241
241
  * DocxReader — .docx bytes → Doc JSON model. Handles this package's own
242
- * writer output losslessly (round-trip) and tolerates Word-authored files:
242
+ * writer output losslessly (round-trip), the PHP mirror's output (same
243
+ * metadata slots since 0.2.0, plus the legacy `LastWordCode_{lang}` bookmark
244
+ * fallback for PHP ≤0.1.x files) and tolerates Word-authored files:
243
245
  * headings via pStyle Heading1-9 OR outlineLvl, numPr lists with ilvl nesting,
244
246
  * hyperlinks via rels, images via blip r:embed, page breaks, bottom-border-only
245
247
  * paragraphs → hr. Unknown constructs degrade to plain paragraphs, never throw.
@@ -258,6 +260,12 @@ declare class DocxReader {
258
260
  private walkBody;
259
261
  private parseSdt;
260
262
  private classifyParagraph;
263
+ /**
264
+ * Back-compat: the code language from a PHP last-word ≤0.1.x
265
+ * `LastWordCode_{lang}` bookmark on this paragraph, if present. The
266
+ * canonical carrier is the `lastword:code:{lang}` sdt tag.
267
+ */
268
+ private legacyBookmarkLanguage;
261
269
  /** Concatenated visible text of a paragraph (tabs and soft breaks included). */
262
270
  private plainText;
263
271
  private parseRuns;
package/dist/index.js CHANGED
@@ -1095,6 +1095,7 @@ var DocxReader = class {
1095
1095
  const blocks = [];
1096
1096
  let listBuf = [];
1097
1097
  let codeBuf = null;
1098
+ let codeLang = null;
1098
1099
  let quoteBuf = null;
1099
1100
  const flushList = () => {
1100
1101
  if (listBuf.length > 0) {
@@ -1104,8 +1105,11 @@ var DocxReader = class {
1104
1105
  };
1105
1106
  const flushCode = () => {
1106
1107
  if (codeBuf !== null) {
1107
- blocks.push({ type: "code", text: codeBuf.join("\n") });
1108
+ const block = { type: "code", text: codeBuf.join("\n") };
1109
+ if (codeLang !== null) block.language = codeLang;
1110
+ blocks.push(orderCodeKeys(block));
1108
1111
  codeBuf = null;
1112
+ codeLang = null;
1109
1113
  }
1110
1114
  };
1111
1115
  const flushQuote = () => {
@@ -1130,7 +1134,10 @@ var DocxReader = class {
1130
1134
  } else if (kind.kind === "codeLine") {
1131
1135
  flushList();
1132
1136
  flushQuote();
1133
- if (codeBuf === null) codeBuf = [];
1137
+ if (codeBuf === null) {
1138
+ codeBuf = [];
1139
+ codeLang = kind.language ?? null;
1140
+ }
1134
1141
  codeBuf.push(kind.text);
1135
1142
  } else if (kind.kind === "quoteParagraph" && !ctx.insideQuote) {
1136
1143
  flushList();
@@ -1199,7 +1206,8 @@ var DocxReader = class {
1199
1206
  return { kind: "listItem", item: { numId, ilvl, runs: this.parseRuns(p, void 0) } };
1200
1207
  }
1201
1208
  if (/^(CodeBlock|SourceCode|HTMLPreformatted|Code)$/i.test(styleId)) {
1202
- return { kind: "codeLine", text: this.plainText(p) };
1209
+ const language = this.legacyBookmarkLanguage(p);
1210
+ return language !== void 0 ? { kind: "codeLine", text: this.plainText(p), language } : { kind: "codeLine", text: this.plainText(p) };
1203
1211
  }
1204
1212
  const blocks = [];
1205
1213
  const drawings = findAll(p, "drawing");
@@ -1235,6 +1243,21 @@ var DocxReader = class {
1235
1243
  }
1236
1244
  return { kind: "blocks", blocks };
1237
1245
  }
1246
+ /**
1247
+ * Back-compat: the code language from a PHP last-word ≤0.1.x
1248
+ * `LastWordCode_{lang}` bookmark on this paragraph, if present. The
1249
+ * canonical carrier is the `lastword:code:{lang}` sdt tag.
1250
+ */
1251
+ legacyBookmarkLanguage(p) {
1252
+ for (const child of p.children) {
1253
+ if (child.name !== "bookmarkStart") continue;
1254
+ const name = at(child, "name") ?? "";
1255
+ if (name.startsWith("LastWordCode_") && name.length > "LastWordCode_".length) {
1256
+ return name.slice("LastWordCode_".length);
1257
+ }
1258
+ }
1259
+ return void 0;
1260
+ }
1238
1261
  /** Concatenated visible text of a paragraph (tabs and soft breaks included). */
1239
1262
  plainText(p) {
1240
1263
  return this.parseRuns(p, void 0).map((r) => r.text).join("");
@@ -2283,7 +2306,7 @@ var Validator = class {
2283
2306
  };
2284
2307
 
2285
2308
  // src/agent.ts
2286
- var VERSION = "0.1.0";
2309
+ var VERSION = "0.2.0";
2287
2310
  function toU8(input) {
2288
2311
  return input instanceof Uint8Array ? input : new Uint8Array(input);
2289
2312
  }