@superdoc-dev/cli 0.2.0-next.119 → 0.2.0-next.120

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 +251 -8
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -108924,7 +108924,7 @@ var init_remark_stringify_D8vxv_XI_es = __esm(() => {
108924
108924
  eol = /\r?\n|\r/g;
108925
108925
  });
108926
108926
 
108927
- // ../../packages/superdoc/dist/chunks/DocxZipper-BBV7L99a.es.js
108927
+ // ../../packages/superdoc/dist/chunks/DocxZipper-_tW4mTs0.es.js
108928
108928
  function getLens2(b64) {
108929
108929
  var len$1 = b64.length;
108930
108930
  if (len$1 % 4 > 0)
@@ -109041,7 +109041,200 @@ function ensureXmlString(content2) {
109041
109041
  xml = xml.replace(/(<\?xml\b[^?]*?)\bencoding\s*=\s*["'][^"']*["']/i, '$1encoding="UTF-8"');
109042
109042
  return xml;
109043
109043
  }
109044
- var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", buffer2, base64Js2, lookup2, revLookup2, Arr2, code4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i2, len2, ieee7542, Buffer3, isXmlLike = (name) => /\.xml$|\.rels$/i.test(name), import_lib3, import_jszip_min, IMAGE_EXTS, MIME_TYPE_FOR_EXT, CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.customXmlProperties+xml", DocxZipper = class {
109044
+ function readEntry(path2, baseFiles, updatedDocs) {
109045
+ if (updatedDocs && Object.prototype.hasOwnProperty.call(updatedDocs, path2))
109046
+ return updatedDocs[path2];
109047
+ if (!baseFiles)
109048
+ return;
109049
+ if (Array.isArray(baseFiles))
109050
+ return baseFiles.find((f2) => f2.name === path2)?.content;
109051
+ return baseFiles[path2];
109052
+ }
109053
+ function partExistsInPackage(zipPath, baseFiles, updatedDocs) {
109054
+ return readEntry(zipPath, baseFiles, updatedDocs) != null;
109055
+ }
109056
+ function parseXml(xmlString) {
109057
+ try {
109058
+ return import_lib$12.xml2js(xmlString, { compact: false });
109059
+ } catch {
109060
+ return null;
109061
+ }
109062
+ }
109063
+ function serializeXml(jsObject) {
109064
+ return import_lib$12.js2xml(jsObject, { spaces: 0 });
109065
+ }
109066
+ function findRootElement(parsed, tagName) {
109067
+ return parsed?.elements?.find((el) => {
109068
+ if (!el.name)
109069
+ return false;
109070
+ return (el.name.includes(":") ? el.name.split(":").pop() : el.name) === tagName;
109071
+ });
109072
+ }
109073
+ function createEmptyRels() {
109074
+ return {
109075
+ declaration: { attributes: {
109076
+ version: "1.0",
109077
+ encoding: "UTF-8",
109078
+ standalone: "yes"
109079
+ } },
109080
+ elements: [{
109081
+ type: "element",
109082
+ name: "Relationships",
109083
+ attributes: { xmlns: RELATIONSHIPS_NS },
109084
+ elements: []
109085
+ }]
109086
+ };
109087
+ }
109088
+ function findMaxRId(relsRoot) {
109089
+ let max = 0;
109090
+ for (const el of relsRoot.elements || []) {
109091
+ const id = el.attributes?.Id;
109092
+ if (!id)
109093
+ continue;
109094
+ const match = id.match(/^rId(\d+)$/);
109095
+ if (match)
109096
+ max = Math.max(max, parseInt(match[1], 10));
109097
+ }
109098
+ return max;
109099
+ }
109100
+ function reconcileContentTypes(typesRoot, presentParts) {
109101
+ if (!typesRoot.elements)
109102
+ typesRoot.elements = [];
109103
+ const managedByPartName = /* @__PURE__ */ new Map;
109104
+ for (const entry of MANAGED_PACKAGE_PARTS)
109105
+ managedByPartName.set(`/${entry.zipPath}`, entry);
109106
+ const existingOverrides = /* @__PURE__ */ new Map;
109107
+ for (let i$1 = 0;i$1 < typesRoot.elements.length; i$1++) {
109108
+ const el = typesRoot.elements[i$1];
109109
+ if (el.name !== "Override")
109110
+ continue;
109111
+ const partName = el.attributes?.PartName;
109112
+ if (!partName || !managedByPartName.has(partName))
109113
+ continue;
109114
+ if (!existingOverrides.has(partName))
109115
+ existingOverrides.set(partName, []);
109116
+ existingOverrides.get(partName).push(i$1);
109117
+ }
109118
+ const indicesToRemove = /* @__PURE__ */ new Set;
109119
+ for (const [partName, entry] of managedByPartName) {
109120
+ const isPresent = presentParts.has(entry.zipPath);
109121
+ const indices = existingOverrides.get(partName) || [];
109122
+ if (!isPresent) {
109123
+ for (const idx of indices)
109124
+ indicesToRemove.add(idx);
109125
+ continue;
109126
+ }
109127
+ if (indices.length === 0)
109128
+ typesRoot.elements.push({
109129
+ type: "element",
109130
+ name: "Override",
109131
+ attributes: {
109132
+ PartName: partName,
109133
+ ContentType: entry.contentType
109134
+ }
109135
+ });
109136
+ else {
109137
+ typesRoot.elements[indices[0]].attributes.ContentType = entry.contentType;
109138
+ for (let i$1 = 1;i$1 < indices.length; i$1++)
109139
+ indicesToRemove.add(indices[i$1]);
109140
+ }
109141
+ }
109142
+ if (indicesToRemove.size > 0) {
109143
+ const sorted = [...indicesToRemove].sort((a, b) => b - a);
109144
+ for (const idx of sorted)
109145
+ typesRoot.elements.splice(idx, 1);
109146
+ }
109147
+ }
109148
+ function reconcileRootRels(relsRoot, presentParts) {
109149
+ if (!relsRoot.elements)
109150
+ relsRoot.elements = [];
109151
+ const managedByType = /* @__PURE__ */ new Map;
109152
+ for (const entry of MANAGED_PACKAGE_PARTS)
109153
+ managedByType.set(entry.relationshipType, entry);
109154
+ const existingRels = /* @__PURE__ */ new Map;
109155
+ for (let i$1 = 0;i$1 < relsRoot.elements.length; i$1++) {
109156
+ const el = relsRoot.elements[i$1];
109157
+ if (el.name !== "Relationship")
109158
+ continue;
109159
+ const type = el.attributes?.Type;
109160
+ if (!type || !managedByType.has(type))
109161
+ continue;
109162
+ if (!existingRels.has(type))
109163
+ existingRels.set(type, []);
109164
+ existingRels.get(type).push({
109165
+ index: i$1,
109166
+ element: el
109167
+ });
109168
+ }
109169
+ const indicesToRemove = /* @__PURE__ */ new Set;
109170
+ let maxRId = findMaxRId(relsRoot);
109171
+ for (const [relType, entry] of managedByType) {
109172
+ const isPresent = presentParts.has(entry.zipPath);
109173
+ const existing = existingRels.get(relType) || [];
109174
+ if (!isPresent) {
109175
+ for (const { index: index2 } of existing)
109176
+ indicesToRemove.add(index2);
109177
+ continue;
109178
+ }
109179
+ if (existing.length === 0) {
109180
+ maxRId++;
109181
+ relsRoot.elements.push({
109182
+ type: "element",
109183
+ name: "Relationship",
109184
+ attributes: {
109185
+ Id: `rId${maxRId}`,
109186
+ Type: relType,
109187
+ Target: entry.zipPath
109188
+ }
109189
+ });
109190
+ } else {
109191
+ existing[0].element.attributes.Target = entry.zipPath;
109192
+ for (let i$1 = 1;i$1 < existing.length; i$1++)
109193
+ indicesToRemove.add(existing[i$1].index);
109194
+ }
109195
+ }
109196
+ if (indicesToRemove.size > 0) {
109197
+ const sorted = [...indicesToRemove].sort((a, b) => b - a);
109198
+ for (const idx of sorted)
109199
+ relsRoot.elements.splice(idx, 1);
109200
+ }
109201
+ }
109202
+ function syncPackageMetadata({ baseFiles, updatedDocs }) {
109203
+ const presentParts = /* @__PURE__ */ new Set;
109204
+ for (const entry of MANAGED_PACKAGE_PARTS)
109205
+ if (partExistsInPackage(entry.zipPath, baseFiles, updatedDocs))
109206
+ presentParts.add(entry.zipPath);
109207
+ const rawContentTypes = readEntry("[Content_Types].xml", baseFiles, updatedDocs);
109208
+ if (rawContentTypes == null)
109209
+ throw new Error("syncPackageMetadata: [Content_Types].xml is missing from the package. Cannot safely reconcile package metadata without an existing content types file.");
109210
+ const contentTypesParsed = parseXml(rawContentTypes);
109211
+ if (!contentTypesParsed)
109212
+ throw new Error("syncPackageMetadata: [Content_Types].xml could not be parsed as valid XML. Cannot safely reconcile package metadata from a malformed content types file.");
109213
+ const typesRoot = findRootElement(contentTypesParsed, "Types");
109214
+ if (!typesRoot)
109215
+ throw new Error("syncPackageMetadata: [Content_Types].xml does not contain a <Types> root element.");
109216
+ reconcileContentTypes(typesRoot, presentParts);
109217
+ const rawRels = readEntry("_rels/.rels", baseFiles, updatedDocs);
109218
+ let relsParsed;
109219
+ if (rawRels == null)
109220
+ relsParsed = createEmptyRels();
109221
+ else {
109222
+ relsParsed = parseXml(rawRels);
109223
+ if (!relsParsed)
109224
+ throw new Error("syncPackageMetadata: _rels/.rels could not be parsed as valid XML. Cannot safely reconcile root relationships from a malformed rels file.");
109225
+ }
109226
+ let relsRoot = findRootElement(relsParsed, "Relationships");
109227
+ if (!relsRoot) {
109228
+ relsParsed = createEmptyRels();
109229
+ relsRoot = relsParsed.elements[0];
109230
+ }
109231
+ reconcileRootRels(relsRoot, presentParts);
109232
+ return {
109233
+ contentTypesXml: serializeXml(contentTypesParsed),
109234
+ relsXml: serializeXml(relsParsed)
109235
+ };
109236
+ }
109237
+ var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", buffer2, base64Js2, lookup2, revLookup2, Arr2, code4 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", i2, len2, ieee7542, Buffer3, isXmlLike = (name) => /\.xml$|\.rels$/i.test(name), MANAGED_PACKAGE_PARTS, import_lib$12, RELATIONSHIPS_NS = "http://schemas.openxmlformats.org/package/2006/relationships", import_lib3, import_jszip_min, IMAGE_EXTS, MIME_TYPE_FOR_EXT, CUSTOM_XML_ITEM_PROPS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.customXmlProperties+xml", DocxZipper = class {
109045
109238
  constructor(params = {}) {
109046
109239
  this.debug = params.debug || false;
109047
109240
  this.zip = new import_jszip_min.default;
@@ -109255,6 +109448,24 @@ var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.docum
109255
109448
  return updatedContentTypesXml;
109256
109449
  docx.file(contentTypesPath, updatedContentTypesXml);
109257
109450
  }
109451
+ async#syncPackageMetadataInZip(zip) {
109452
+ const baseForSync = {};
109453
+ zip.forEach((path2) => {
109454
+ baseForSync[path2] = "";
109455
+ });
109456
+ const ctEntry = zip.file("[Content_Types].xml");
109457
+ if (ctEntry)
109458
+ baseForSync["[Content_Types].xml"] = await ctEntry.async("string");
109459
+ const rlEntry = zip.file("_rels/.rels");
109460
+ if (rlEntry)
109461
+ baseForSync["_rels/.rels"] = await rlEntry.async("string");
109462
+ const { contentTypesXml, relsXml } = syncPackageMetadata({
109463
+ baseFiles: baseForSync,
109464
+ updatedDocs: {}
109465
+ });
109466
+ zip.file("[Content_Types].xml", contentTypesXml);
109467
+ zip.file("_rels/.rels", relsXml);
109468
+ }
109258
109469
  async unzip(file) {
109259
109470
  return await this.zip.loadAsync(file);
109260
109471
  }
@@ -109292,6 +109503,7 @@ var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.docum
109292
109503
  for (const [fontName, fontUintArray] of Object.entries(fonts))
109293
109504
  zip.file(fontName, fontUintArray);
109294
109505
  await this.updateContentTypes(zip, media, false, updatedDocs);
109506
+ await this.#syncPackageMetadataInZip(zip);
109295
109507
  return zip;
109296
109508
  }
109297
109509
  async exportFromOriginalFile(originalDocxFile, updatedDocs, media) {
@@ -109314,6 +109526,7 @@ var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.docum
109314
109526
  unzippedOriginalDocx.file(path2, media[path2]);
109315
109527
  });
109316
109528
  await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs);
109529
+ await this.#syncPackageMetadataInZip(unzippedOriginalDocx);
109317
109530
  return unzippedOriginalDocx;
109318
109531
  }
109319
109532
  #detectImageContentType(value) {
@@ -109333,7 +109546,7 @@ var DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.docum
109333
109546
  return `image/${MIME_TYPE_FOR_EXT[detectedType] || detectedType}`;
109334
109547
  }
109335
109548
  }, DocxZipper_default;
109336
- var init_DocxZipper_BBV7L99a_es = __esm(() => {
109549
+ var init_DocxZipper__tW4mTs0_es = __esm(() => {
109337
109550
  init_rolldown_runtime_B2q5OVn9_es();
109338
109551
  init_jszip_ChlR43oI_es();
109339
109552
  init_xml_js_DLE8mr0n_es();
@@ -110952,6 +111165,29 @@ var init_DocxZipper_BBV7L99a_es = __esm(() => {
110952
111165
  buffer2.kStringMaxLength;
110953
111166
  buffer2.resolveObjectURL;
110954
111167
  buffer2.transcode;
111168
+ MANAGED_PACKAGE_PARTS = [
111169
+ {
111170
+ zipPath: "word/document.xml",
111171
+ contentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
111172
+ relationshipType: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
111173
+ },
111174
+ {
111175
+ zipPath: "docProps/core.xml",
111176
+ contentType: "application/vnd.openxmlformats-package.core-properties+xml",
111177
+ relationshipType: "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
111178
+ },
111179
+ {
111180
+ zipPath: "docProps/app.xml",
111181
+ contentType: "application/vnd.openxmlformats-officedocument.extended-properties+xml",
111182
+ relationshipType: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
111183
+ },
111184
+ {
111185
+ zipPath: "docProps/custom.xml",
111186
+ contentType: "application/vnd.openxmlformats-officedocument.custom-properties+xml",
111187
+ relationshipType: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
111188
+ }
111189
+ ];
111190
+ import_lib$12 = /* @__PURE__ */ __toESM2(require_lib(), 1);
110955
111191
  import_lib3 = /* @__PURE__ */ __toESM2(require_lib(), 1);
110956
111192
  import_jszip_min = /* @__PURE__ */ __toESM2(require_jszip_min(), 1);
110957
111193
  IMAGE_EXTS = new Set([
@@ -134408,7 +134644,7 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
134408
134644
  init_remark_gfm_z_sDF4ss_es();
134409
134645
  });
134410
134646
 
134411
- // ../../packages/superdoc/dist/chunks/src-Crr00svT.es.js
134647
+ // ../../packages/superdoc/dist/chunks/src-CA9yZS_s.es.js
134412
134648
  function deleteProps(obj, propOrProps) {
134413
134649
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
134414
134650
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -216522,7 +216758,7 @@ var Node$13 = class Node$14 {
216522
216758
  return false;
216523
216759
  return Boolean(checker(attrs));
216524
216760
  }, SuperToolbar, ICONS, TEXTS, tableActionsOptions;
216525
- var init_src_Crr00svT_es = __esm(() => {
216761
+ var init_src_CA9yZS_s_es = __esm(() => {
216526
216762
  init_rolldown_runtime_B2q5OVn9_es();
216527
216763
  init_SuperConverter_BBGfKYpx_es();
216528
216764
  init_jszip_ChlR43oI_es();
@@ -216531,7 +216767,7 @@ var init_src_Crr00svT_es = __esm(() => {
216531
216767
  init_unified_BRHLwnjP_es();
216532
216768
  init_remark_gfm_z_sDF4ss_es();
216533
216769
  init_remark_stringify_D8vxv_XI_es();
216534
- init_DocxZipper_BBV7L99a_es();
216770
+ init_DocxZipper__tW4mTs0_es();
216535
216771
  init_vue_DQHWm9lq_es();
216536
216772
  init__plugin_vue_export_helper_HmhZBO0u_es();
216537
216773
  init_eventemitter3_DGBTyUUP_es();
@@ -226903,6 +227139,13 @@ function print() { __p += __j.call(arguments, '') }
226903
227139
  const zipper = new DocxZipper_default;
226904
227140
  if (getUpdatedDocs) {
226905
227141
  updatedDocs["[Content_Types].xml"] = await zipper.updateContentTypes({ files: this.options.content }, media2, true, updatedDocs);
227142
+ const content3 = this.options.content;
227143
+ const { contentTypesXml, relsXml } = syncPackageMetadata({
227144
+ baseFiles: Array.isArray(content3) || content3 && typeof content3 === "object" ? content3 : null,
227145
+ updatedDocs
227146
+ });
227147
+ updatedDocs["[Content_Types].xml"] = contentTypesXml;
227148
+ updatedDocs["_rels/.rels"] = relsXml;
226906
227149
  return updatedDocs;
226907
227150
  }
226908
227151
  return await zipper.updateZip({
@@ -250108,13 +250351,13 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
250108
250351
 
250109
250352
  // ../../packages/superdoc/dist/super-editor.es.js
250110
250353
  var init_super_editor_es = __esm(() => {
250111
- init_src_Crr00svT_es();
250354
+ init_src_CA9yZS_s_es();
250112
250355
  init_SuperConverter_BBGfKYpx_es();
250113
250356
  init_jszip_ChlR43oI_es();
250114
250357
  init_xml_js_DLE8mr0n_es();
250115
250358
  init_constants_CMPtQbp7_es();
250116
250359
  init_unified_BRHLwnjP_es();
250117
- init_DocxZipper_BBV7L99a_es();
250360
+ init_DocxZipper__tW4mTs0_es();
250118
250361
  init_vue_DQHWm9lq_es();
250119
250362
  init_eventemitter3_DGBTyUUP_es();
250120
250363
  init_zipper_DqXT7uTa_es();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/cli",
3
- "version": "0.2.0-next.119",
3
+ "version": "0.2.0-next.120",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "superdoc": "./dist/index.js"
@@ -21,8 +21,8 @@
21
21
  "@types/node": "22.19.2",
22
22
  "typescript": "^5.9.2",
23
23
  "@superdoc/document-api": "0.0.1",
24
- "@superdoc/super-editor": "0.0.1",
25
24
  "@superdoc/pm-adapter": "0.0.0",
25
+ "@superdoc/super-editor": "0.0.1",
26
26
  "superdoc": "1.18.0"
27
27
  },
28
28
  "module": "src/index.ts",
@@ -30,11 +30,11 @@
30
30
  "access": "public"
31
31
  },
32
32
  "optionalDependencies": {
33
- "@superdoc-dev/cli-darwin-arm64": "0.2.0-next.119",
34
- "@superdoc-dev/cli-darwin-x64": "0.2.0-next.119",
35
- "@superdoc-dev/cli-linux-x64": "0.2.0-next.119",
36
- "@superdoc-dev/cli-windows-x64": "0.2.0-next.119",
37
- "@superdoc-dev/cli-linux-arm64": "0.2.0-next.119"
33
+ "@superdoc-dev/cli-darwin-arm64": "0.2.0-next.120",
34
+ "@superdoc-dev/cli-darwin-x64": "0.2.0-next.120",
35
+ "@superdoc-dev/cli-linux-x64": "0.2.0-next.120",
36
+ "@superdoc-dev/cli-linux-arm64": "0.2.0-next.120",
37
+ "@superdoc-dev/cli-windows-x64": "0.2.0-next.120"
38
38
  },
39
39
  "scripts": {
40
40
  "dev": "bun run src/index.ts",