@json-to-office/jto 1.5.0 → 1.7.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.
Files changed (36) hide show
  1. package/dist/cli.js +60 -19
  2. package/dist/cli.js.map +1 -1
  3. package/dist/client/assets/HomePage-fDrbL-5G.js +106 -0
  4. package/dist/client/assets/HomePage-fDrbL-5G.js.map +1 -0
  5. package/dist/client/assets/{JsonEditorPage-COHI5Wez.js → JsonEditorPage-CRY9589Y.js} +3 -3
  6. package/dist/client/assets/{JsonEditorPage-COHI5Wez.js.map → JsonEditorPage-CRY9589Y.js.map} +1 -1
  7. package/dist/client/assets/MonacoPluginProvider-n1_V7jsc.js +3 -0
  8. package/dist/client/assets/MonacoPluginProvider-n1_V7jsc.js.map +1 -0
  9. package/dist/client/assets/{editor-BO-KsLDk.js → editor-Y9dek093.js} +2 -2
  10. package/dist/client/assets/{editor-BO-KsLDk.js.map → editor-Y9dek093.js.map} +1 -1
  11. package/dist/client/assets/{editor-monaco-json-CJh63Fsz.js → editor-monaco-json-oBxvTIvi.js} +2 -2
  12. package/dist/client/assets/{editor-monaco-json-CJh63Fsz.js.map → editor-monaco-json-oBxvTIvi.js.map} +1 -1
  13. package/dist/client/assets/{editor-refs-store-CVLA_D5G.js → editor-refs-store-BMwl0ejj.js} +2 -2
  14. package/dist/client/assets/{editor-refs-store-CVLA_D5G.js.map → editor-refs-store-BMwl0ejj.js.map} +1 -1
  15. package/dist/client/assets/{index-otgy8_us.js → index-B4R-AAtI.js} +4 -4
  16. package/dist/client/assets/index-B4R-AAtI.js.map +1 -0
  17. package/dist/client/assets/preview-zCYkbgdR.js +2 -0
  18. package/dist/client/assets/preview-zCYkbgdR.js.map +1 -0
  19. package/dist/client/assets/{useQualityAnalysis-Ci_jNmHv.js → useQualityAnalysis-BFG1bJDp.js} +2 -2
  20. package/dist/client/assets/{useQualityAnalysis-Ci_jNmHv.js.map → useQualityAnalysis-BFG1bJDp.js.map} +1 -1
  21. package/dist/client/index.html +1 -1
  22. package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Bold.otf +0 -0
  23. package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Light.otf +0 -0
  24. package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Medium.otf +0 -0
  25. package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Regular.otf +0 -0
  26. package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Semibold.otf +0 -0
  27. package/dist/client/templates/media/vermilion-annual-report/fonts/FFL.txt +132 -0
  28. package/dist/client/templates/vermilion-annual-report.docx.json +10541 -0
  29. package/package.json +7 -7
  30. package/dist/client/assets/HomePage-ChJyDqzj.js +0 -106
  31. package/dist/client/assets/HomePage-ChJyDqzj.js.map +0 -1
  32. package/dist/client/assets/MonacoPluginProvider-prawCY6T.js +0 -3
  33. package/dist/client/assets/MonacoPluginProvider-prawCY6T.js.map +0 -1
  34. package/dist/client/assets/index-otgy8_us.js.map +0 -1
  35. package/dist/client/assets/preview-3fuCtJiz.js +0 -2
  36. package/dist/client/assets/preview-3fuCtJiz.js.map +0 -1
package/dist/cli.js CHANGED
@@ -249,6 +249,18 @@ function toQualityWarnings(diagnostics) {
249
249
  }
250
250
  }));
251
251
  }
252
+ function documentTitle(config2) {
253
+ const props = config2?.props;
254
+ const metadata = props?.metadata;
255
+ const title = metadata?.title ?? props?.title;
256
+ return typeof title === "string" ? title : void 0;
257
+ }
258
+ function documentFilenameBase(config2) {
259
+ const title = documentTitle(config2);
260
+ if (title === void 0) return void 0;
261
+ const base = title.replace(/[^a-zA-Z0-9._-]/g, "_").slice(0, MAX_FILENAME_BASE);
262
+ return /^[._]*$/.test(base) ? void 0 : base;
263
+ }
252
264
  function collectReferencedNames(config2, customThemes, adapterName) {
253
265
  const collect = adapterName === "docx" ? collectFontNamesFromDocx : collectFontNamesFromPptx;
254
266
  const names = /* @__PURE__ */ new Set();
@@ -395,12 +407,13 @@ function autoGoogleFontEntries(names, skipFamilies, referencedWeights, reference
395
407
  }
396
408
  return entries;
397
409
  }
398
- var GeneratorService;
410
+ var MAX_FILENAME_BASE, GeneratorService;
399
411
  var init_generator = __esm({
400
412
  "src/server/services/generator.ts"() {
401
413
  "use strict";
402
414
  init_esm_shims();
403
415
  init_logger();
416
+ MAX_FILENAME_BASE = 100;
404
417
  GeneratorService = class {
405
418
  adapter;
406
419
  cacheService;
@@ -535,9 +548,9 @@ var init_generator = __esm({
535
548
  if (!bypassCache && !hasDynamicContent) {
536
549
  const cached = this.cacheService.get(cacheKey);
537
550
  if (cached) {
538
- logger.info("Served from cache", { title: config2.metadata?.title });
551
+ logger.info("Served from cache", { title: documentTitle(config2) });
539
552
  return {
540
- filename: `${config2.metadata?.title || this.adapter.label}${this.adapter.extension}`,
553
+ filename: `${documentFilenameBase(config2) || this.adapter.label}${this.adapter.extension}`,
541
554
  fileId: Date.now().toString(),
542
555
  buffer: cached.buffer,
543
556
  // Render warnings ride with bytes. Quality is request policy, so it
@@ -548,7 +561,7 @@ var init_generator = __esm({
548
561
  }
549
562
  }
550
563
  logger.info(`Generating ${this.adapter.label}`, {
551
- title: config2.metadata?.title
564
+ title: documentTitle(config2)
552
565
  });
553
566
  let buffer;
554
567
  if (registry.hasPlugins()) {
@@ -608,7 +621,7 @@ var init_generator = __esm({
608
621
  { bypassCache: bypassCache || hasDynamicContent }
609
622
  );
610
623
  return {
611
- filename: `${config2.metadata?.title || this.adapter.label}${this.adapter.extension}`,
624
+ filename: `${documentFilenameBase(config2) || this.adapter.label}${this.adapter.extension}`,
612
625
  fileId: Date.now().toString(),
613
626
  buffer,
614
627
  cached: false,
@@ -1968,7 +1981,9 @@ function isInlineCandidate(source) {
1968
1981
  return true;
1969
1982
  }
1970
1983
  }
1971
- async function toDataUrl(source, baseDir, state) {
1984
+ async function toDataUrl(source, baseDir, state, mimeByExtension) {
1985
+ const mime = mimeByExtension[path4.extname(source).toLowerCase()];
1986
+ if (!mime) return null;
1972
1987
  let cacheKey = source;
1973
1988
  let result = null;
1974
1989
  try {
@@ -1978,14 +1993,11 @@ async function toDataUrl(source, baseDir, state) {
1978
1993
  if (cached !== void 0) return cached;
1979
1994
  const contained = resolved === state.baseDirReal || resolved.startsWith(state.baseDirReal + path4.sep);
1980
1995
  if (contained) {
1981
- const mime = MIME_BY_EXTENSION[path4.extname(resolved).toLowerCase()];
1982
- if (mime) {
1983
- const stat = await fs2.stat(resolved);
1984
- if (stat.isFile() && stat.size <= state.maxFileBytes && stat.size <= state.totalBudget) {
1985
- const buffer = await fs2.readFile(resolved);
1986
- state.totalBudget -= buffer.length;
1987
- result = `data:${mime};base64,${buffer.toString("base64")}`;
1988
- }
1996
+ const stat = await fs2.stat(resolved);
1997
+ if (stat.isFile() && stat.size <= state.maxFileBytes && stat.size <= state.totalBudget) {
1998
+ const buffer = await fs2.readFile(resolved);
1999
+ state.totalBudget -= buffer.length;
2000
+ result = `data:${mime};base64,${buffer.toString("base64")}`;
1989
2001
  }
1990
2002
  }
1991
2003
  } catch {
@@ -2003,14 +2015,37 @@ async function visit2(value, containerKey, baseDir, state, seen) {
2003
2015
  return;
2004
2016
  }
2005
2017
  const record = value;
2018
+ if (record.kind === "file" && typeof record.path === "string" && isInlineCandidate(record.path)) {
2019
+ const inlined = await toDataUrl(
2020
+ record.path,
2021
+ baseDir,
2022
+ state,
2023
+ FONT_MIME_BY_EXTENSION
2024
+ );
2025
+ if (inlined !== null) {
2026
+ record.kind = "data";
2027
+ record.data = inlined;
2028
+ delete record.path;
2029
+ }
2030
+ }
2006
2031
  const componentName = typeof record.name === "string" ? record.name.toLowerCase() : void 0;
2007
2032
  const props = isRecord2(record.props) ? record.props : void 0;
2008
2033
  if (componentName === "image" && props && typeof props.path === "string" && isInlineCandidate(props.path)) {
2009
- const inlined = await toDataUrl(props.path, baseDir, state);
2034
+ const inlined = await toDataUrl(
2035
+ props.path,
2036
+ baseDir,
2037
+ state,
2038
+ IMAGE_MIME_BY_EXTENSION
2039
+ );
2010
2040
  if (inlined !== null) props.path = inlined;
2011
2041
  }
2012
2042
  if (containerKey === "image" && typeof record.path === "string" && isInlineCandidate(record.path)) {
2013
- const inlined = await toDataUrl(record.path, baseDir, state);
2043
+ const inlined = await toDataUrl(
2044
+ record.path,
2045
+ baseDir,
2046
+ state,
2047
+ IMAGE_MIME_BY_EXTENSION
2048
+ );
2014
2049
  if (inlined !== null) record.path = inlined;
2015
2050
  }
2016
2051
  for (const [key, child] of Object.entries(record)) {
@@ -2044,12 +2079,12 @@ async function inlineTemplateMedia(jsonDefinition, baseDir, options = {}) {
2044
2079
  await visit2(clone, void 0, baseDir, state, /* @__PURE__ */ new WeakSet());
2045
2080
  return clone;
2046
2081
  }
2047
- var MIME_BY_EXTENSION;
2082
+ var IMAGE_MIME_BY_EXTENSION, FONT_MIME_BY_EXTENSION;
2048
2083
  var init_template_media_inliner = __esm({
2049
2084
  "src/server/services/template-media-inliner.ts"() {
2050
2085
  "use strict";
2051
2086
  init_esm_shims();
2052
- MIME_BY_EXTENSION = {
2087
+ IMAGE_MIME_BY_EXTENSION = {
2053
2088
  ".png": "image/png",
2054
2089
  ".jpg": "image/jpeg",
2055
2090
  ".jpeg": "image/jpeg",
@@ -2060,6 +2095,12 @@ var init_template_media_inliner = __esm({
2060
2095
  ".tiff": "image/tiff",
2061
2096
  ".tif": "image/tiff"
2062
2097
  };
2098
+ FONT_MIME_BY_EXTENSION = {
2099
+ ".ttf": "font/ttf",
2100
+ ".otf": "font/otf",
2101
+ ".woff": "font/woff",
2102
+ ".woff2": "font/woff2"
2103
+ };
2063
2104
  }
2064
2105
  });
2065
2106
 
@@ -4329,7 +4370,7 @@ function createDevCommand(adapter) {
4329
4370
  }
4330
4371
 
4331
4372
  // src/cli.ts
4332
- var PACKAGE_VERSION = true ? "1.5.0" : "dev-mode";
4373
+ var PACKAGE_VERSION = true ? "1.7.0" : "dev-mode";
4333
4374
  var program = new Command2();
4334
4375
  program.name("jto").description("JSON to Office CLI - Generate .docx and .pptx from JSON").version(PACKAGE_VERSION);
4335
4376
  registerCoreCommands(program, {