@deepseek-ai/libreoffice-kit 0.2.3-rc.4 → 0.2.4

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 (31) hide show
  1. package/README.md +18 -10
  2. package/README.zh.md +18 -10
  3. package/frame-forwarding/README.md +4 -2
  4. package/frame-forwarding/README.zh.md +4 -2
  5. package/frame-forwarding/include/dsh_frame_forwarding.h +1 -1
  6. package/frame-forwarding/prebuilds/darwin-arm64/frame-forwarding.node +0 -0
  7. package/frame-forwarding/prebuilds/darwin-arm64/libdsh_frame_forwarding_sdk.a +0 -0
  8. package/frame-forwarding/prebuilds/darwin-arm64/manifest.json +11 -11
  9. package/frame-forwarding/prebuilds/darwin-x64/frame-forwarding.node +0 -0
  10. package/frame-forwarding/prebuilds/darwin-x64/libdsh_frame_forwarding_sdk.a +0 -0
  11. package/frame-forwarding/prebuilds/darwin-x64/manifest.json +11 -11
  12. package/frame-forwarding/prebuilds/win32-arm64/dsh_frame_forwarding_sdk.lib +0 -0
  13. package/frame-forwarding/prebuilds/win32-arm64/frame-forwarding.node +0 -0
  14. package/frame-forwarding/prebuilds/win32-arm64/manifest.json +11 -11
  15. package/frame-forwarding/prebuilds/win32-x64/dsh_frame_forwarding_sdk.lib +0 -0
  16. package/frame-forwarding/prebuilds/win32-x64/frame-forwarding.node +0 -0
  17. package/frame-forwarding/prebuilds/win32-x64/manifest.json +11 -11
  18. package/frame-forwarding/receipt.json +7 -7
  19. package/frame-forwarding/scripts/metadata.mjs +2 -2
  20. package/frame-forwarding/sdk.json +2 -2
  21. package/frame-forwarding/src/receiver.cc +33 -8
  22. package/frame-forwarding/src/transport.cc +259 -73
  23. package/frame-forwarding/src/transport.h +15 -0
  24. package/frame-forwarding/verify.mjs +1 -1
  25. package/lib/cli.js +69 -58
  26. package/lib/editor.js +66 -23
  27. package/lib/index.js +69 -58
  28. package/lib/types/engine.d.ts +3 -4
  29. package/lib/types/native.d.ts +8 -19
  30. package/lib/types/runtime.d.ts +4 -1
  31. package/package.json +7 -6
package/lib/cli.js CHANGED
@@ -728,24 +728,41 @@ function fontSearchName(value) {
728
728
  const name = value.replaceAll(/[\uff00-\uff5e]/g, (character) => String.fromCharCode(character.charCodeAt(0) - 65248)).replaceAll(/[A-Z]/g, (character) => character.toLowerCase()).replaceAll(/[^a-z0-9;()\u0080-\uffff]/g, "");
729
729
  return LOCALIZED_FONT_SEARCH_NAMES.get(name) ?? name;
730
730
  }
731
+ function xmlText(value) {
732
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
733
+ }
734
+ /**
735
+ * Fontconfig rules for helpers that resolve fonts through Fontconfig. On Linux, VCL asks Fontconfig's pre-match
736
+ * substitution before its own substitution table, so each missing document family accepts its selected substitute
737
+ * with the requested family's binding; a closer language match therefore cannot replace it. The rules declare no
738
+ * font directories: the helper registers the imported files, which keeps host fonts excluded.
739
+ */
740
+ function nativeFontConfig(substitutions) {
741
+ return `<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"><fontconfig>${substitutions.map(({ family, substitute }) => `<alias binding="same"><family>${xmlText(family)}</family><accept><family>${xmlText(substitute)}</family></accept></alias>`).join("")}</fontconfig>\n`;
742
+ }
731
743
  /**
732
- * Write missing-family choices into the private profile's VCL substitution table.
744
+ * Write missing-family choices into the private profile's VCL substitution table, and on Linux into the profile's
745
+ * Fontconfig rules, which the helper selects in place of the host configuration.
733
746
  * Installed originals and metric-compatible fonts are resolved before this table by LibreOffice.
734
747
  * @param profile - Existing, conversion-owned profile directory.
735
748
  * @param substitutions - Missing document families and the selected installed family.
736
- * @returns Resolves after the exclusive profile file is written; empty choices still disable the interactive CSV warning.
749
+ * @param platform - Host operating system.
750
+ * @returns Resolves after the exclusive profile files are written; empty choices still disable the interactive CSV warning.
737
751
  */
738
- async function prepareNativeFontProfile(profile, substitutions) {
752
+ async function prepareNativeFontProfile(profile, substitutions, platform = process.platform) {
739
753
  const families = new Map(substitutions.map(({ family, substitute }) => [fontSearchName(family), substitute]));
740
754
  for (const [family, substitute] of [...families]) for (let alias = METRIC_SEARCH_NAMES.get(family); alias; alias = METRIC_SEARCH_NAMES.get(alias)) if (!families.has(alias)) families.set(alias, substitute);
741
- const escape = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
742
- const xml = profileXml([...families].map(([family, substitute]) => `<node oor:name="${escape(family)}" oor:op="replace"><prop oor:name="SubstFonts" oor:op="fuse"><value>${escape(substitute)}</value></prop></node>`).join(""));
755
+ const xml = profileXml([...families].map(([family, substitute]) => `<node oor:name="${xmlText(family)}" oor:op="replace"><prop oor:name="SubstFonts" oor:op="fuse"><value>${xmlText(substitute)}</value></prop></node>`).join(""));
743
756
  const user = join(profile, "user");
744
757
  await mkdir(user, { mode: 448 });
745
758
  await writeFile(join(user, "registrymodifications.xcu"), xml, {
746
759
  flag: "wx",
747
760
  mode: 384
748
761
  });
762
+ if (platform === "linux") await writeFile(join(profile, "fonts.conf"), nativeFontConfig(substitutions), {
763
+ flag: "wx",
764
+ mode: 384
765
+ });
749
766
  }
750
767
  /**
751
768
  * Native conversion and rendering disable printer discovery to avoid driver UI and network waits.
@@ -818,40 +835,20 @@ async function withNativeEngine(engine, profile, run) {
818
835
  await prepared.release();
819
836
  }
820
837
  }
821
- /**
822
- * Prepare the document transport accepted by the pinned helper.
823
- * @param engine - Resolved helper and input protocol.
824
- * @param input - Owned document bytes and validated format.
825
- * @param profile - Private directory retained until the helper exits and removed by the operation owner.
826
- * @param signal - Cancellation of input preparation.
827
- * @returns Helper arguments and an optional binary stdin prefix.
828
- */
829
- async function prepareNativeInput(engine, input, profile, signal) {
830
- signal.throwIfAborted();
831
- if (engine.legacyInputPath) {
832
- const path = join(profile, `source.${input.format}`);
833
- await writeFile(path, input.bytes, {
834
- flag: "wx",
835
- mode: 384,
836
- signal
837
- });
838
- return { args: ["--input-path", path] };
839
- }
840
- return {
841
- args: [
842
- "--input-bytes",
843
- String(input.bytes.byteLength),
844
- "--input-format",
845
- input.format
846
- ],
847
- bytes: input.bytes
848
- };
838
+ /** The native helper reads the declared byte count from stdin before any operation frames. */
839
+ function nativeInputArgs(bytes, format) {
840
+ return [
841
+ "--input-bytes",
842
+ String(bytes.byteLength),
843
+ "--input-format",
844
+ format
845
+ ];
849
846
  }
850
847
  /**
851
848
  * Run one native conversion and await bounded result transport.
852
849
  * @param engine - Resolved native engine installation.
853
850
  * @param options - Validated conversion limits.
854
- * @param input - Owned source bytes and format; older pinned helpers receive a private input file.
851
+ * @param input - Owned source bytes and format.
855
852
  * @param output - Private PDF path inside the conversion scratch directory.
856
853
  * @param profile - Conversion-owned profile directory.
857
854
  * @param fonts - Installed font files the helper may load.
@@ -870,12 +867,10 @@ async function runNative(engine, options, input, output, profile, fonts, substit
870
867
  return withNativeEngine(engine, profile, async (engine) => {
871
868
  signal.throwIfAborted();
872
869
  const env = nativeEnvironment(profile, engine.programDirectory);
873
- const transport = await prepareNativeInput(engine, input, profile, signal);
874
- signal.throwIfAborted();
875
870
  const child = spawnNative(engine.executable, [
876
871
  "--program-directory",
877
872
  engine.programDirectory,
878
- ...transport.args,
873
+ ...nativeInputArgs(input.bytes, input.format),
879
874
  "--output-path",
880
875
  output,
881
876
  "--profile-directory",
@@ -915,7 +910,7 @@ async function runNative(engine, options, input, output, profile, fonts, substit
915
910
  failure ??= error;
916
911
  child.kill("SIGKILL");
917
912
  });
918
- child.stdin.end(transport.bytes);
913
+ child.stdin.end(input.bytes);
919
914
  try {
920
915
  const code = await new Promise((resolve, reject) => {
921
916
  child.once("error", (error) => {
@@ -1076,17 +1071,13 @@ async function renderImagesWithNative(request) {
1076
1071
  await mkdir(profile, { mode: 448 });
1077
1072
  await prepareNativeFontProfile(profile, substitutions);
1078
1073
  return withNativeEngine(engine, profile, async (engine) => {
1079
- const transport = await prepareNativeInput(engine, {
1080
- bytes: source,
1081
- format: operation.extension
1082
- }, profile, signal);
1083
1074
  signal.throwIfAborted();
1084
1075
  const child = spawnNative(engine.executable, [
1085
1076
  "--operation",
1086
1077
  "render-images",
1087
1078
  "--program-directory",
1088
1079
  engine.programDirectory,
1089
- ...transport.args,
1080
+ ...nativeInputArgs(source, operation.extension),
1090
1081
  "--scratch-directory",
1091
1082
  scratch,
1092
1083
  "--profile-directory",
@@ -1130,7 +1121,7 @@ async function renderImagesWithNative(request) {
1130
1121
  stopped ??= error;
1131
1122
  child.kill("SIGKILL");
1132
1123
  });
1133
- if (transport.bytes) child.stdin.write(transport.bytes);
1124
+ child.stdin.write(source);
1134
1125
  const next = async () => {
1135
1126
  signal.throwIfAborted();
1136
1127
  if (lines.length > 0) return lines.shift();
@@ -1556,16 +1547,16 @@ function resolveOptions(input = {}) {
1556
1547
  /** Resolve installed, version-matched engine packages without downloads or compilation. */
1557
1548
  const require = createRequire(import.meta.url);
1558
1549
  /** Node API release version returned by runtime discovery. */
1559
- const ENGINE_VERSION = "0.2.3-rc.4";
1550
+ const ENGINE_VERSION = "0.2.4";
1560
1551
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
1561
1552
  const ENGINE_VERSIONS = Object.freeze({
1562
- "darwin-arm64": "0.2.3-rc.4",
1563
- "darwin-x64": "0.2.3-rc.4",
1564
- "linux-arm64-glibc": "0.1.1",
1565
- "linux-x64-glibc": "0.1.1",
1566
- "win32-arm64": "0.2.3-rc.4",
1567
- "win32-x64": "0.2.3-rc.4",
1568
- wasm: "0.2.3-rc.4"
1553
+ "darwin-arm64": "0.2.4",
1554
+ "darwin-x64": "0.2.4",
1555
+ "linux-arm64-glibc": "0.2.4",
1556
+ "linux-x64-glibc": "0.2.4",
1557
+ "win32-arm64": "0.2.4",
1558
+ "win32-x64": "0.2.4",
1559
+ wasm: "0.2.4"
1569
1560
  });
1570
1561
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
1571
1562
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -1627,36 +1618,56 @@ function resolvedManifest(packageFile, name) {
1627
1618
  return packageFile;
1628
1619
  }
1629
1620
  /**
1630
- * Prefer the installed compatible native engine; hosts without one use the shared WASM package.
1621
+ * Whether a resolver failure reports the named package as absent rather than broken.
1622
+ * Node resolution also raises MODULE_NOT_FOUND for other modules, so the default resolver must name this package; a
1623
+ * caller resolver's code alone reports absence.
1624
+ */
1625
+ function packageAbsent(error, name, resolvePackage) {
1626
+ const failure = error;
1627
+ return failure?.code === "MODULE_NOT_FOUND" && (resolvePackage !== installedEnginePackage || typeof failure.message === "string" && failure.message.includes(`${name}/package.json`));
1628
+ }
1629
+ /**
1630
+ * Prefer the installed compatible native engine; hosts without one use the WASM package when the consumer installed it.
1631
1631
  * @param resolvePackage - Engine package manifest resolver; defaults to Node resolution from this module.
1632
1632
  * @param packageExists - Whether a native package that resolved as `MODULE_NOT_FOUND` is nevertheless installed (and
1633
1633
  * therefore incomplete). Only the default resolver probes this module's installation; a caller resolver is the sole
1634
1634
  * authority on whether its packages exist.
1635
1635
  * @param host - Process identification and diagnostic report.
1636
1636
  * @returns the installed native engine, or the installed WASM engine.
1637
+ * @throws Error naming the exact WASM package to install when no native engine is usable and WASM is absent.
1637
1638
  */
1638
1639
  async function resolveEngine(resolvePackage = installedEnginePackage, packageExists = resolvePackage === installedEnginePackage ? installedPackageExists : () => false, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
1639
1640
  const details = platform === "linux" ? report() : {};
1640
1641
  const target = platformTarget(platform, arch, () => details);
1642
+ let reason = `no native engine is built for ${platform}-${arch}${platform === "linux" && ["arm64", "x64"].includes(arch) ? " without glibc" : ""}`;
1641
1643
  if (target !== void 0) {
1642
1644
  const name = `${ENGINE_PREFIX}-${target}`;
1643
1645
  let packageFile;
1644
1646
  try {
1645
1647
  packageFile = resolvedManifest(resolvePackage(name), name);
1646
1648
  } catch (error) {
1647
- const failure = error;
1648
- if (!(failure?.code === "MODULE_NOT_FOUND" && (resolvePackage !== installedEnginePackage || typeof failure.message === "string" && failure.message.includes(`${name}/package.json`)))) throw error;
1649
+ if (!packageAbsent(error, name, resolvePackage)) throw error;
1649
1650
  if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
1651
+ reason = `${name} is not installed`;
1650
1652
  }
1651
1653
  if (packageFile !== void 0) {
1652
1654
  const engine = await readEngine(packageFile, "native", target);
1653
1655
  const minimum = glibcVersion(engine.glibcMinimum);
1654
1656
  const host = glibcVersion(details.header?.glibcVersionRuntime);
1655
1657
  if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
1658
+ reason = `${name} requires glibc ${engine.glibcMinimum} or newer; this host has glibc ${details.header?.glibcVersionRuntime}`;
1656
1659
  }
1657
1660
  }
1658
1661
  const wasm = `${ENGINE_PREFIX}-wasm`;
1659
- return readEngine(resolvedManifest(resolvePackage(wasm), wasm), "wasm", "wasm");
1662
+ let wasmFile;
1663
+ try {
1664
+ wasmFile = resolvePackage(wasm);
1665
+ } catch (error) {
1666
+ if (!packageAbsent(error, wasm, resolvePackage)) throw error;
1667
+ if (packageExists(wasm)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${wasm}`, { cause: error });
1668
+ throw new Error(`No usable native LibreOfficeKit engine is available on this host (${reason}), and the portable WASM engine is not installed. Install it with: npm install ${wasm}@${ENGINE_VERSIONS.wasm}`, { cause: error });
1669
+ }
1670
+ return readEngine(resolvedManifest(wasmFile, wasm), "wasm", "wasm");
1660
1671
  }
1661
1672
  async function engineAsset(root, value, name, kind) {
1662
1673
  const path = asset(root, value);
@@ -1680,7 +1691,6 @@ async function readEngine(packageFile, backend, target) {
1680
1691
  root,
1681
1692
  programDirectory: await engineAsset(root, engine.programDirectory, "programDirectory", "directory"),
1682
1693
  executable,
1683
- ...["0.1.1", "0.1.5"].includes(String(pkg.version)) ? { legacyInputPath: true } : {},
1684
1694
  ...glibcFloor
1685
1695
  };
1686
1696
  }
@@ -1867,10 +1877,11 @@ async function discoverRuntime(options) {
1867
1877
  resolveOptions(options);
1868
1878
  try {
1869
1879
  const engine = await resolveEngine(options?.resolveEnginePackage);
1880
+ const nativePreview = engine.backend === "native" && !platformTarget()?.startsWith("linux-");
1870
1881
  return {
1871
1882
  version: ENGINE_VERSION,
1872
1883
  backend: engine.backend,
1873
- nativePreview: engine.backend === "native" && !engine.legacyInputPath,
1884
+ nativePreview,
1874
1885
  cliPath: fileURLToPath(new URL("./cli.js", import.meta.url)),
1875
1886
  nodeApiPath: fileURLToPath(new URL("./index.js", import.meta.url))
1876
1887
  };
package/lib/editor.js CHANGED
@@ -486,13 +486,13 @@ function resolveOptions(input = {}) {
486
486
  const require = createRequire(import.meta.url);
487
487
  /** Exact compatible engine versions; unchanged platforms retain their published packages. */
488
488
  const ENGINE_VERSIONS = Object.freeze({
489
- "darwin-arm64": "0.2.3-rc.4",
490
- "darwin-x64": "0.2.3-rc.4",
491
- "linux-arm64-glibc": "0.1.1",
492
- "linux-x64-glibc": "0.1.1",
493
- "win32-arm64": "0.2.3-rc.4",
494
- "win32-x64": "0.2.3-rc.4",
495
- wasm: "0.2.3-rc.4"
489
+ "darwin-arm64": "0.2.4",
490
+ "darwin-x64": "0.2.4",
491
+ "linux-arm64-glibc": "0.2.4",
492
+ "linux-x64-glibc": "0.2.4",
493
+ "win32-arm64": "0.2.4",
494
+ "win32-x64": "0.2.4",
495
+ wasm: "0.2.4"
496
496
  });
497
497
  /** npm scope and name prefix shared by the engine packages this adapter installs. */
498
498
  const ENGINE_PREFIX = "@deepseek-ai/libreoffice-kit";
@@ -554,36 +554,56 @@ function resolvedManifest(packageFile, name) {
554
554
  return packageFile;
555
555
  }
556
556
  /**
557
- * Prefer the installed compatible native engine; hosts without one use the shared WASM package.
557
+ * Whether a resolver failure reports the named package as absent rather than broken.
558
+ * Node resolution also raises MODULE_NOT_FOUND for other modules, so the default resolver must name this package; a
559
+ * caller resolver's code alone reports absence.
560
+ */
561
+ function packageAbsent(error, name, resolvePackage) {
562
+ const failure = error;
563
+ return failure?.code === "MODULE_NOT_FOUND" && (resolvePackage !== installedEnginePackage || typeof failure.message === "string" && failure.message.includes(`${name}/package.json`));
564
+ }
565
+ /**
566
+ * Prefer the installed compatible native engine; hosts without one use the WASM package when the consumer installed it.
558
567
  * @param resolvePackage - Engine package manifest resolver; defaults to Node resolution from this module.
559
568
  * @param packageExists - Whether a native package that resolved as `MODULE_NOT_FOUND` is nevertheless installed (and
560
569
  * therefore incomplete). Only the default resolver probes this module's installation; a caller resolver is the sole
561
570
  * authority on whether its packages exist.
562
571
  * @param host - Process identification and diagnostic report.
563
572
  * @returns the installed native engine, or the installed WASM engine.
573
+ * @throws Error naming the exact WASM package to install when no native engine is usable and WASM is absent.
564
574
  */
565
575
  async function resolveEngine(resolvePackage = installedEnginePackage, packageExists = resolvePackage === installedEnginePackage ? installedPackageExists : () => false, { platform = process.platform, arch = process.arch, report = hostReport } = {}) {
566
576
  const details = platform === "linux" ? report() : {};
567
577
  const target = platformTarget(platform, arch, () => details);
578
+ let reason = `no native engine is built for ${platform}-${arch}${platform === "linux" && ["arm64", "x64"].includes(arch) ? " without glibc" : ""}`;
568
579
  if (target !== void 0) {
569
580
  const name = `${ENGINE_PREFIX}-${target}`;
570
581
  let packageFile;
571
582
  try {
572
583
  packageFile = resolvedManifest(resolvePackage(name), name);
573
584
  } catch (error) {
574
- const failure = error;
575
- if (!(failure?.code === "MODULE_NOT_FOUND" && (resolvePackage !== installedEnginePackage || typeof failure.message === "string" && failure.message.includes(`${name}/package.json`)))) throw error;
585
+ if (!packageAbsent(error, name, resolvePackage)) throw error;
576
586
  if (packageExists(name)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${name}`, { cause: error });
587
+ reason = `${name} is not installed`;
577
588
  }
578
589
  if (packageFile !== void 0) {
579
590
  const engine = await readEngine(packageFile, "native", target);
580
591
  const minimum = glibcVersion(engine.glibcMinimum);
581
592
  const host = glibcVersion(details.header?.glibcVersionRuntime);
582
593
  if (!(minimum && host && minimum.some((part, index) => part > (host[index] ?? 0) && minimum.slice(0, index).every((prior, priorIndex) => prior === host[priorIndex])))) return engine;
594
+ reason = `${name} requires glibc ${engine.glibcMinimum} or newer; this host has glibc ${details.header?.glibcVersionRuntime}`;
583
595
  }
584
596
  }
585
597
  const wasm = `${ENGINE_PREFIX}-wasm`;
586
- return readEngine(resolvedManifest(resolvePackage(wasm), wasm), "wasm", "wasm");
598
+ let wasmFile;
599
+ try {
600
+ wasmFile = resolvePackage(wasm);
601
+ } catch (error) {
602
+ if (!packageAbsent(error, wasm, resolvePackage)) throw error;
603
+ if (packageExists(wasm)) throw new Error(`Installed LibreOfficeKit package is incomplete: ${wasm}`, { cause: error });
604
+ throw new Error(`No usable native LibreOfficeKit engine is available on this host (${reason}), and the portable WASM engine is not installed. Install it with: npm install ${wasm}@${ENGINE_VERSIONS.wasm}`, { cause: error });
605
+ }
606
+ return readEngine(resolvedManifest(wasmFile, wasm), "wasm", "wasm");
587
607
  }
588
608
  async function engineAsset(root, value, name, kind) {
589
609
  const path = asset(root, value);
@@ -607,7 +627,6 @@ async function readEngine(packageFile, backend, target) {
607
627
  root,
608
628
  programDirectory: await engineAsset(root, engine.programDirectory, "programDirectory", "directory"),
609
629
  executable,
610
- ...["0.1.1", "0.1.5"].includes(String(pkg.version)) ? { legacyInputPath: true } : {},
611
630
  ...glibcFloor
612
631
  };
613
632
  }
@@ -1403,24 +1422,41 @@ function fontSearchName(value) {
1403
1422
  const name = value.replaceAll(/[\uff00-\uff5e]/g, (character) => String.fromCharCode(character.charCodeAt(0) - 65248)).replaceAll(/[A-Z]/g, (character) => character.toLowerCase()).replaceAll(/[^a-z0-9;()\u0080-\uffff]/g, "");
1404
1423
  return LOCALIZED_FONT_SEARCH_NAMES.get(name) ?? name;
1405
1424
  }
1425
+ function xmlText(value) {
1426
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
1427
+ }
1406
1428
  /**
1407
- * Write missing-family choices into the private profile's VCL substitution table.
1429
+ * Fontconfig rules for helpers that resolve fonts through Fontconfig. On Linux, VCL asks Fontconfig's pre-match
1430
+ * substitution before its own substitution table, so each missing document family accepts its selected substitute
1431
+ * with the requested family's binding; a closer language match therefore cannot replace it. The rules declare no
1432
+ * font directories: the helper registers the imported files, which keeps host fonts excluded.
1433
+ */
1434
+ function nativeFontConfig(substitutions) {
1435
+ return `<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"><fontconfig>${substitutions.map(({ family, substitute }) => `<alias binding="same"><family>${xmlText(family)}</family><accept><family>${xmlText(substitute)}</family></accept></alias>`).join("")}</fontconfig>\n`;
1436
+ }
1437
+ /**
1438
+ * Write missing-family choices into the private profile's VCL substitution table, and on Linux into the profile's
1439
+ * Fontconfig rules, which the helper selects in place of the host configuration.
1408
1440
  * Installed originals and metric-compatible fonts are resolved before this table by LibreOffice.
1409
1441
  * @param profile - Existing, conversion-owned profile directory.
1410
1442
  * @param substitutions - Missing document families and the selected installed family.
1411
- * @returns Resolves after the exclusive profile file is written; empty choices still disable the interactive CSV warning.
1443
+ * @param platform - Host operating system.
1444
+ * @returns Resolves after the exclusive profile files are written; empty choices still disable the interactive CSV warning.
1412
1445
  */
1413
- async function prepareNativeFontProfile(profile, substitutions) {
1446
+ async function prepareNativeFontProfile(profile, substitutions, platform = process.platform) {
1414
1447
  const families = new Map(substitutions.map(({ family, substitute }) => [fontSearchName(family), substitute]));
1415
1448
  for (const [family, substitute] of [...families]) for (let alias = METRIC_SEARCH_NAMES.get(family); alias; alias = METRIC_SEARCH_NAMES.get(alias)) if (!families.has(alias)) families.set(alias, substitute);
1416
- const escape = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
1417
- const xml = profileXml([...families].map(([family, substitute]) => `<node oor:name="${escape(family)}" oor:op="replace"><prop oor:name="SubstFonts" oor:op="fuse"><value>${escape(substitute)}</value></prop></node>`).join(""));
1449
+ const xml = profileXml([...families].map(([family, substitute]) => `<node oor:name="${xmlText(family)}" oor:op="replace"><prop oor:name="SubstFonts" oor:op="fuse"><value>${xmlText(substitute)}</value></prop></node>`).join(""));
1418
1450
  const user = join(profile, "user");
1419
1451
  await mkdir(user, { mode: 448 });
1420
1452
  await writeFile(join(user, "registrymodifications.xcu"), xml, {
1421
1453
  flag: "wx",
1422
1454
  mode: 384
1423
1455
  });
1456
+ if (platform === "linux") await writeFile(join(profile, "fonts.conf"), nativeFontConfig(substitutions), {
1457
+ flag: "wx",
1458
+ mode: 384
1459
+ });
1424
1460
  }
1425
1461
  /**
1426
1462
  * Native conversion and rendering disable printer discovery to avoid driver UI and network waits.
@@ -1478,6 +1514,15 @@ async function prepareNativeEngine(engine, profile) {
1478
1514
  throw error;
1479
1515
  }
1480
1516
  }
1517
+ /** The native helper reads the declared byte count from stdin before any operation frames. */
1518
+ function nativeInputArgs(bytes, format) {
1519
+ return [
1520
+ "--input-bytes",
1521
+ String(bytes.byteLength),
1522
+ "--input-format",
1523
+ format
1524
+ ];
1525
+ }
1481
1526
  //#endregion
1482
1527
  //#region lib/types/editor-protocol.js
1483
1528
  /** Encode a control record; the native editor accepts no binary input. */
@@ -1685,7 +1730,7 @@ var EditorTransport = class {
1685
1730
  return;
1686
1731
  }
1687
1732
  if (c.kind === "ready") {
1688
- if (c.protocol !== 4 || c.frameForwardingProtocol !== 1 || frame.pixels.length !== 0) throw new Error("Native editor requires editor protocol 4 and frame-forwarding protocol 1.");
1733
+ if (c.protocol !== 4 || c.frameForwardingProtocol !== 2 || frame.pixels.length !== 0) throw new Error("Native editor requires editor protocol 4 and frame-forwarding protocol 1.");
1689
1734
  if (c.frameForwardingTransferable !== true) throw new Error("Native editor predates transferable frame-forwarding channels; install the matching engine.");
1690
1735
  this.initialized = true;
1691
1736
  clearTimeout(this.startupTimer);
@@ -1825,7 +1870,8 @@ async function openDocument(request) {
1825
1870
  const signal = request.signal ? AbortSignal.any([request.signal, lifetime.signal]) : lifetime.signal;
1826
1871
  signal.throwIfAborted();
1827
1872
  const engine = await resolveEngine(request.options?.resolveEnginePackage);
1828
- if (engine.backend !== "native" || engine.legacyInputPath) throw new Error("Native editing requires a preview-capable native engine package.");
1873
+ if (engine.backend !== "native") throw new Error("Native editing requires a preview-capable native engine package.");
1874
+ if (platformTarget()?.startsWith("linux-")) throw new Error("Native editing is unavailable with Linux engines, which support conversion and rendering only.");
1829
1875
  const scratch = await mkdtemp(join(tmpdir(), "libreoffice-editor-"));
1830
1876
  let transport;
1831
1877
  let prepared;
@@ -1856,10 +1902,7 @@ async function openDocument(request) {
1856
1902
  renderBackend,
1857
1903
  "--graphite-cache-bytes",
1858
1904
  String(graphiteCacheBytes),
1859
- "--input-bytes",
1860
- String(source.byteLength),
1861
- "--input-format",
1862
- request.format,
1905
+ ...nativeInputArgs(source, request.format),
1863
1906
  "--scratch-directory",
1864
1907
  scratch,
1865
1908
  "--profile-directory",