@json-to-office/jto 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.
Files changed (39) hide show
  1. package/dist/cli.js +234 -49
  2. package/dist/cli.js.map +1 -1
  3. package/dist/client/assets/HomePage-BuV1dGoc.js +99 -0
  4. package/dist/client/assets/HomePage-BuV1dGoc.js.map +1 -0
  5. package/dist/client/assets/JsonEditorPage-y7DXYaWc.js +3 -0
  6. package/dist/client/assets/JsonEditorPage-y7DXYaWc.js.map +1 -0
  7. package/dist/client/assets/MonacoPluginProvider-B4-PgJ0r.js +3 -0
  8. package/dist/client/assets/MonacoPluginProvider-B4-PgJ0r.js.map +1 -0
  9. package/dist/client/assets/{button-CMkwEplC.js → button-Bf6x7Zjh.js} +2 -2
  10. package/dist/client/assets/{button-CMkwEplC.js.map → button-Bf6x7Zjh.js.map} +1 -1
  11. package/dist/client/assets/{editor-CtwF-qwA.js → editor-Bwuq290w.js} +2 -2
  12. package/dist/client/assets/{editor-CtwF-qwA.js.map → editor-Bwuq290w.js.map} +1 -1
  13. package/dist/client/assets/editor-monaco-json-BrfKPhHP.js +6 -0
  14. package/dist/client/assets/{editor-monaco-json-DHRbpQ-v.js.map → editor-monaco-json-BrfKPhHP.js.map} +1 -1
  15. package/dist/client/assets/index-Dmrqj1a7.css +1 -0
  16. package/dist/client/assets/index-uE8YOnrS.js +3 -0
  17. package/dist/client/assets/index-uE8YOnrS.js.map +1 -0
  18. package/dist/client/assets/preview-kcqt_5hb.js +3 -0
  19. package/dist/client/assets/{preview-38guLS86.js.map → preview-kcqt_5hb.js.map} +1 -1
  20. package/dist/client/assets/{state-vendor-CAMVKh-F.js → state-vendor-DypmJYNT.js} +2 -2
  21. package/dist/client/assets/{state-vendor-CAMVKh-F.js.map → state-vendor-DypmJYNT.js.map} +1 -1
  22. package/dist/client/assets/{ui-vendor-C6DsfOoA.js → ui-vendor-BFdEgxEg.js} +2 -2
  23. package/dist/client/assets/{ui-vendor-C6DsfOoA.js.map → ui-vendor-BFdEgxEg.js.map} +1 -1
  24. package/dist/client/index.html +3 -4
  25. package/dist/index.d.ts +8 -3
  26. package/dist/index.js +110 -19
  27. package/dist/index.js.map +1 -1
  28. package/package.json +6 -6
  29. package/dist/client/assets/HomePage-D9PVR0H8.js +0 -99
  30. package/dist/client/assets/HomePage-D9PVR0H8.js.map +0 -1
  31. package/dist/client/assets/JsonEditorPage-bCBt1A49.js +0 -3
  32. package/dist/client/assets/JsonEditorPage-bCBt1A49.js.map +0 -1
  33. package/dist/client/assets/editor-monaco-json-DHRbpQ-v.js +0 -6
  34. package/dist/client/assets/index-B9dV-vCI.css +0 -1
  35. package/dist/client/assets/index-CGQAncgl.js +0 -3
  36. package/dist/client/assets/index-CGQAncgl.js.map +0 -1
  37. package/dist/client/assets/preview-38guLS86.js +0 -3
  38. package/dist/client/assets/settings-store-provider-BEzje7_o.js +0 -2
  39. package/dist/client/assets/settings-store-provider-BEzje7_o.js.map +0 -1
package/dist/index.js CHANGED
@@ -17,7 +17,9 @@ var DocxFormatAdapter = class {
17
17
  const core = await import("@json-to-office/core-docx");
18
18
  const docDefinition = typeof json === "string" ? JSON.parse(json) : json;
19
19
  const customThemes = await this.loadCustomThemes(options);
20
- return await core.generateBufferFromJson(docDefinition, { customThemes });
20
+ return await core.generateBufferFromJson(docDefinition, {
21
+ customThemes
22
+ });
21
23
  }
22
24
  async createGenerator(plugins, options) {
23
25
  const core = await import("@json-to-office/core-docx");
@@ -27,16 +29,20 @@ var DocxFormatAdapter = class {
27
29
  return {
28
30
  generateBuffer: async (document) => {
29
31
  const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
30
- const customThemes = await this.loadCustomThemes(options);
31
- return await core.generateBufferFromJson(docDefinition, { customThemes });
32
+ const customThemes2 = await this.loadCustomThemes(options);
33
+ return await core.generateBufferFromJson(docDefinition, {
34
+ customThemes: customThemes2
35
+ });
32
36
  },
33
37
  hasPlugins: false,
34
38
  pluginNames: []
35
39
  };
36
40
  }
37
41
  const theme = await this.resolveTheme(options);
42
+ const customThemes = await this.loadCustomThemes(options);
38
43
  let generator = core.createDocumentGenerator({
39
44
  theme,
45
+ customThemes,
40
46
  debug: process.env.DEBUG === "true"
41
47
  });
42
48
  for (const plugin of plugins) {
@@ -222,19 +228,52 @@ var PptxFormatAdapter = class {
222
228
  const core = await import("@json-to-office/core-pptx");
223
229
  const docDefinition = typeof json === "string" ? JSON.parse(json) : json;
224
230
  const customThemes = await this.loadCustomThemes(options);
225
- return await core.generateBufferFromJson(docDefinition, { customThemes });
231
+ return await core.generateBufferFromJson(docDefinition, {
232
+ customThemes
233
+ });
226
234
  }
227
235
  async createGenerator(plugins, options) {
228
236
  const core = await import("@json-to-office/core-pptx");
229
237
  const hasPlugins = plugins.length > 0;
230
238
  const pluginNames = plugins.map((p) => p.name);
239
+ if (!hasPlugins) {
240
+ return {
241
+ generateBuffer: async (document) => {
242
+ const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
243
+ const customThemes2 = await this.loadCustomThemes(options);
244
+ return await core.generateBufferFromJson(docDefinition, {
245
+ customThemes: customThemes2
246
+ });
247
+ },
248
+ hasPlugins: false,
249
+ pluginNames: []
250
+ };
251
+ }
252
+ const theme = await this.resolveTheme(options);
253
+ const customThemes = await this.loadCustomThemes(options);
254
+ let generator = core.createPresentationGenerator({
255
+ theme,
256
+ customThemes,
257
+ debug: process.env.DEBUG === "true"
258
+ });
259
+ for (const plugin of plugins) {
260
+ generator = generator.addComponent(plugin);
261
+ }
231
262
  return {
232
263
  generateBuffer: async (document) => {
233
264
  const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
234
- const customThemes = await this.loadCustomThemes(options);
235
- return await core.generateBufferFromJson(docDefinition, { customThemes });
265
+ const validationResult = generator.validate(docDefinition);
266
+ if (!validationResult.valid) {
267
+ const errors = validationResult.errors || [];
268
+ throw new Error(
269
+ `Presentation validation failed:
270
+ ${errors.map((e) => ` - ${e.path}: ${e.message}`).join("\n")}`
271
+ );
272
+ }
273
+ const result = await generator.generateBuffer(docDefinition);
274
+ return result.buffer;
236
275
  },
237
- hasPlugins,
276
+ hasPlugins: true,
238
277
  pluginNames
239
278
  };
240
279
  }
@@ -635,10 +674,21 @@ var PluginMetadataExtractor = class {
635
674
  const versionKeys = Object.keys(versions);
636
675
  const latestVer = versionKeys.length > 0 ? latestVersion(versionKeys) : void 0;
637
676
  const latestEntry = latestVer ? versions[latestVer] : void 0;
677
+ let format;
678
+ try {
679
+ const source = await fs3.readFile(filePath, "utf-8");
680
+ format = this.detectFormat(source);
681
+ } catch (err) {
682
+ console.warn(
683
+ `Failed to read plugin source for format detection: ${filePath}`,
684
+ err
685
+ );
686
+ }
638
687
  const metadata = {
639
688
  name: component.name,
640
689
  description: latestEntry?.description,
641
690
  version: latestVer,
691
+ format,
642
692
  filePath,
643
693
  relativePath,
644
694
  location,
@@ -676,6 +726,27 @@ var PluginMetadataExtractor = class {
676
726
  }
677
727
  return "upstream";
678
728
  }
729
+ detectFormat(source) {
730
+ const docxSignals = [
731
+ "@json-to-office/shared-docx",
732
+ "@json-to-office/core-docx",
733
+ "@json-to-office/json-to-docx",
734
+ "ComponentDefinition",
735
+ "ReportComponentDefinition"
736
+ ];
737
+ const pptxSignals = [
738
+ "@json-to-office/shared-pptx",
739
+ "@json-to-office/core-pptx",
740
+ "@json-to-office/json-to-pptx",
741
+ "PptxComponentInput",
742
+ "PresentationComponentDefinition"
743
+ ];
744
+ const hasDocx = docxSignals.some((s) => source.includes(s));
745
+ const hasPptx = pptxSignals.some((s) => source.includes(s));
746
+ if (hasDocx && !hasPptx) return "docx";
747
+ if (hasPptx && !hasDocx) return "pptx";
748
+ return void 0;
749
+ }
679
750
  typeboxToJsonSchema(schema) {
680
751
  try {
681
752
  const jsonSchema = JSON.parse(JSON.stringify(schema));
@@ -898,10 +969,10 @@ var PluginDiscoveryService = class {
898
969
  }
899
970
  this.metadataExtractor = new PluginMetadataExtractor(this.searchPath);
900
971
  }
901
- async discover() {
902
- return this.discoverPlugins();
972
+ async discover(format) {
973
+ return this.discoverPlugins(format);
903
974
  }
904
- async discoverPlugins() {
975
+ async discoverPlugins(format) {
905
976
  const startPath = this.searchPath;
906
977
  try {
907
978
  await this.loader.initialize();
@@ -925,6 +996,9 @@ var PluginDiscoveryService = class {
925
996
  if (locationDiff !== 0) return locationDiff;
926
997
  return a.name.localeCompare(b.name);
927
998
  });
999
+ if (format) {
1000
+ return metadata.filter((p) => !p.format || p.format === format);
1001
+ }
928
1002
  return metadata;
929
1003
  } finally {
930
1004
  this.loader.cleanup();
@@ -934,7 +1008,10 @@ var PluginDiscoveryService = class {
934
1008
  const startPath = this.searchPath;
935
1009
  const discoveryType = format === "pptx" ? "pptx-document" : "docx-document";
936
1010
  const ext = format === "pptx" ? ".pptx.json" : ".docx.json";
937
- const allDocumentPaths = await this.searchDownstream(startPath, discoveryType);
1011
+ const allDocumentPaths = await this.searchDownstream(
1012
+ startPath,
1013
+ discoveryType
1014
+ );
938
1015
  const uniquePaths = this.scanner.deduplicatePaths(allDocumentPaths);
939
1016
  const metadata = [];
940
1017
  for (const docPath of uniquePaths) {
@@ -955,7 +1032,11 @@ var PluginDiscoveryService = class {
955
1032
  }
956
1033
  }
957
1034
  metadata.sort((a, b) => {
958
- const locationOrder = { current: 0, downstream: 1, upstream: 2 };
1035
+ const locationOrder = {
1036
+ current: 0,
1037
+ downstream: 1,
1038
+ upstream: 2
1039
+ };
959
1040
  const locationDiff = locationOrder[a.location] - locationOrder[b.location];
960
1041
  if (locationDiff !== 0) return locationDiff;
961
1042
  return a.name.localeCompare(b.name);
@@ -984,7 +1065,11 @@ var PluginDiscoveryService = class {
984
1065
  }
985
1066
  }
986
1067
  metadata.sort((a, b) => {
987
- const locationOrder = { current: 0, downstream: 1, upstream: 2 };
1068
+ const locationOrder = {
1069
+ current: 0,
1070
+ downstream: 1,
1071
+ upstream: 2
1072
+ };
988
1073
  const locationDiff = locationOrder[a.location] - locationOrder[b.location];
989
1074
  if (locationDiff !== 0) return locationDiff;
990
1075
  return a.name.localeCompare(b.name);
@@ -1005,7 +1090,7 @@ var PluginDiscoveryService = class {
1005
1090
  }
1006
1091
  async discoverAll(format) {
1007
1092
  const [plugins, documents, themes] = await Promise.all([
1008
- this.discoverPlugins(),
1093
+ this.discoverPlugins(format),
1009
1094
  this.discoverDocuments(format),
1010
1095
  this.discoverThemes(format)
1011
1096
  ]);
@@ -1081,6 +1166,7 @@ var PluginRegistry = class _PluginRegistry {
1081
1166
  pluginMetadata = /* @__PURE__ */ new Map();
1082
1167
  loader;
1083
1168
  discoveryService;
1169
+ _format;
1084
1170
  constructor() {
1085
1171
  this.loader = new PluginLoader();
1086
1172
  this.discoveryService = new PluginDiscoveryService();
@@ -1091,6 +1177,9 @@ var PluginRegistry = class _PluginRegistry {
1091
1177
  }
1092
1178
  return _PluginRegistry.instance;
1093
1179
  }
1180
+ setFormat(format) {
1181
+ this._format = format;
1182
+ }
1094
1183
  notifyCacheInvalidation() {
1095
1184
  try {
1096
1185
  invalidateAllCaches();
@@ -1162,7 +1251,7 @@ var PluginRegistry = class _PluginRegistry {
1162
1251
  scope: dir,
1163
1252
  maxDepth: 5
1164
1253
  });
1165
- const pluginMetadata = await discovery.discover();
1254
+ const pluginMetadata = await discovery.discover(this._format);
1166
1255
  return await this.loadPluginsFromMetadata(pluginMetadata);
1167
1256
  } catch (error) {
1168
1257
  throw new Error(
@@ -1175,7 +1264,7 @@ var PluginRegistry = class _PluginRegistry {
1175
1264
  async discoverAndLoad() {
1176
1265
  try {
1177
1266
  await this.loader.initialize();
1178
- const pluginMetadata = await this.discoveryService.discover();
1267
+ const pluginMetadata = await this.discoveryService.discover(this._format);
1179
1268
  const discovered = pluginMetadata.length;
1180
1269
  if (discovered === 0) {
1181
1270
  return { discovered: 0, loaded: 0 };
@@ -1193,7 +1282,7 @@ var PluginRegistry = class _PluginRegistry {
1193
1282
  return this.pluginPaths.get(name);
1194
1283
  }
1195
1284
  try {
1196
- const pluginMetadata = await this.discoveryService.discover();
1285
+ const pluginMetadata = await this.discoveryService.discover(this._format);
1197
1286
  const metadata = pluginMetadata.find((p) => p.name === name);
1198
1287
  if (metadata) return metadata.filePath;
1199
1288
  } catch {
@@ -1274,8 +1363,10 @@ var PluginResolver = class {
1274
1363
  discoveredPlugins = /* @__PURE__ */ new Map();
1275
1364
  lastDiscoveryTime = 0;
1276
1365
  CACHE_DURATION = 5 * 60 * 1e3;
1277
- constructor() {
1366
+ format;
1367
+ constructor(format) {
1278
1368
  this.discoveryService = new PluginDiscoveryService();
1369
+ this.format = format;
1279
1370
  }
1280
1371
  async resolve(input) {
1281
1372
  const pathResult = await this.resolveAsPath(input);
@@ -1328,7 +1419,7 @@ ${errors.join("\n")}`);
1328
1419
  }
1329
1420
  async refreshDiscoveryCache() {
1330
1421
  try {
1331
- const plugins = await this.discoveryService.discover();
1422
+ const plugins = await this.discoveryService.discover(this.format);
1332
1423
  this.discoveredPlugins.clear();
1333
1424
  for (const plugin of plugins) {
1334
1425
  this.discoveredPlugins.set(plugin.name, plugin);