@hirokisakabe/pom 1.4.0 → 3.0.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 (87) hide show
  1. package/README.md +158 -193
  2. package/dist/buildPptx.d.ts +2 -2
  3. package/dist/buildPptx.d.ts.map +1 -1
  4. package/dist/buildPptx.js +3 -1
  5. package/dist/calcYogaLayout/calcYogaLayout.d.ts.map +1 -1
  6. package/dist/calcYogaLayout/calcYogaLayout.js +95 -19
  7. package/dist/calcYogaLayout/fontLoader.d.ts +0 -7
  8. package/dist/calcYogaLayout/fontLoader.d.ts.map +1 -1
  9. package/dist/calcYogaLayout/fontLoader.js +1 -1
  10. package/dist/calcYogaLayout/measureText.d.ts +0 -4
  11. package/dist/calcYogaLayout/measureText.d.ts.map +1 -1
  12. package/dist/calcYogaLayout/measureText.js +0 -6
  13. package/dist/index.d.ts +2 -5
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -4
  16. package/dist/{inputSchema.d.ts → parseXml/inputSchema.d.ts} +254 -460
  17. package/dist/parseXml/inputSchema.d.ts.map +1 -0
  18. package/dist/{inputSchema.js → parseXml/inputSchema.js} +42 -140
  19. package/dist/{parseXml.d.ts → parseXml/parseXml.d.ts} +6 -2
  20. package/dist/parseXml/parseXml.d.ts.map +1 -0
  21. package/dist/parseXml/parseXml.js +823 -0
  22. package/dist/renderPptx/nodes/flow.d.ts.map +1 -1
  23. package/dist/renderPptx/nodes/flow.js +26 -16
  24. package/dist/renderPptx/nodes/index.d.ts +1 -0
  25. package/dist/renderPptx/nodes/index.d.ts.map +1 -1
  26. package/dist/renderPptx/nodes/index.js +1 -0
  27. package/dist/renderPptx/nodes/list.d.ts +12 -0
  28. package/dist/renderPptx/nodes/list.d.ts.map +1 -0
  29. package/dist/renderPptx/nodes/list.js +145 -0
  30. package/dist/renderPptx/nodes/matrix.d.ts.map +1 -1
  31. package/dist/renderPptx/nodes/matrix.js +43 -31
  32. package/dist/renderPptx/nodes/processArrow.d.ts.map +1 -1
  33. package/dist/renderPptx/nodes/processArrow.js +14 -6
  34. package/dist/renderPptx/nodes/shape.js +2 -2
  35. package/dist/renderPptx/nodes/table.d.ts.map +1 -1
  36. package/dist/renderPptx/nodes/table.js +1 -1
  37. package/dist/renderPptx/nodes/timeline.d.ts.map +1 -1
  38. package/dist/renderPptx/nodes/timeline.js +58 -37
  39. package/dist/renderPptx/nodes/tree.d.ts.map +1 -1
  40. package/dist/renderPptx/nodes/tree.js +49 -40
  41. package/dist/renderPptx/renderPptx.d.ts +1 -2
  42. package/dist/renderPptx/renderPptx.d.ts.map +1 -1
  43. package/dist/renderPptx/renderPptx.js +8 -4
  44. package/dist/renderPptx/textOptions.d.ts +1 -29
  45. package/dist/renderPptx/textOptions.d.ts.map +1 -1
  46. package/dist/renderPptx/textOptions.js +1 -27
  47. package/dist/renderPptx/types.d.ts +0 -2
  48. package/dist/renderPptx/types.d.ts.map +1 -1
  49. package/dist/renderPptx/utils/backgroundBorder.js +1 -1
  50. package/dist/renderPptx/utils/scaleToFit.d.ts +8 -0
  51. package/dist/renderPptx/utils/scaleToFit.d.ts.map +1 -0
  52. package/dist/renderPptx/utils/scaleToFit.js +19 -0
  53. package/dist/shared/measureImage.d.ts.map +1 -0
  54. package/dist/{table/utils.d.ts → shared/tableUtils.d.ts} +1 -3
  55. package/dist/shared/tableUtils.d.ts.map +1 -0
  56. package/dist/{table/utils.js → shared/tableUtils.js} +2 -2
  57. package/dist/toPositioned/toPositioned.d.ts.map +1 -1
  58. package/dist/toPositioned/toPositioned.js +4 -2
  59. package/dist/types.d.ts +271 -154
  60. package/dist/types.d.ts.map +1 -1
  61. package/dist/types.js +67 -33
  62. package/package.json +3 -6
  63. package/dist/calcYogaLayout/measureImage.d.ts.map +0 -1
  64. package/dist/component.d.ts +0 -90
  65. package/dist/component.d.ts.map +0 -1
  66. package/dist/component.js +0 -123
  67. package/dist/inputSchema.d.ts.map +0 -1
  68. package/dist/parseXml.d.ts.map +0 -1
  69. package/dist/parseXml.js +0 -332
  70. package/dist/renderPptx/nodes/box.d.ts +0 -2
  71. package/dist/renderPptx/nodes/box.d.ts.map +0 -1
  72. package/dist/renderPptx/nodes/box.js +0 -3
  73. package/dist/renderPptx/utils/index.d.ts +0 -6
  74. package/dist/renderPptx/utils/index.d.ts.map +0 -1
  75. package/dist/renderPptx/utils/index.js +0 -3
  76. package/dist/renderPptx/utils/shapeDrawing.d.ts +0 -27
  77. package/dist/renderPptx/utils/shapeDrawing.d.ts.map +0 -1
  78. package/dist/renderPptx/utils/shapeDrawing.js +0 -36
  79. package/dist/renderPptx/utils/textDrawing.d.ts +0 -25
  80. package/dist/renderPptx/utils/textDrawing.d.ts.map +0 -1
  81. package/dist/renderPptx/utils/textDrawing.js +0 -25
  82. package/dist/schema.d.ts +0 -23
  83. package/dist/schema.d.ts.map +0 -1
  84. package/dist/schema.js +0 -24
  85. package/dist/table/utils.d.ts.map +0 -1
  86. /package/dist/{calcYogaLayout → shared}/measureImage.d.ts +0 -0
  87. /package/dist/{calcYogaLayout → shared}/measureImage.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputSchema.d.ts","sourceRoot":"","sources":["../../src/parseXml/inputSchema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAoCL,KAAK,YAAY,EAElB,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAa9B,CAAC;AAKH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAa9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAe,CAAC;AAE9C,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;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BAKhC,CAAC;AAUH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAU9B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAS9B,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAatC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAW9B,CAAC"}
@@ -1,23 +1,11 @@
1
1
  /**
2
- * Input schemas for LLM/external input validation
2
+ * Input schemas for LLM/external input validation (internal module)
3
3
  *
4
4
  * These schemas do not include internal properties like `yogaNode`.
5
- * Use these when validating JSON from OpenAI, Claude, or other LLMs.
6
- *
7
- * @example
8
- * ```typescript
9
- * import { inputPomNodeSchema, InputPOMNode } from "@hirokisakabe/pom";
10
- *
11
- * // Validate and parse JSON from LLM
12
- * const json = JSON.parse(llmResponse);
13
- * const result = inputPomNodeSchema.safeParse(json);
14
- * if (result.success) {
15
- * const pptx = await buildPptx([result.data], { w: 1280, h: 720 });
16
- * }
17
- * ```
5
+ * Used by `parseXml` to validate parsed XML input.
18
6
  */
19
7
  import { z } from "zod";
20
- import { lengthSchema, paddingSchema, borderStyleSchema, borderDashSchema, fillStyleSchema, shadowStyleSchema, alignItemsSchema, justifyContentSchema, shapeTypeSchema, tableColumnSchema, tableRowSchema, chartTypeSchema, chartDataSchema, bulletOptionsSchema, radarStyleSchema, timelineDirectionSchema, timelineItemSchema, matrixAxisSchema, matrixQuadrantsSchema, matrixItemSchema, treeLayoutSchema, treeNodeShapeSchema, treeConnectorStyleSchema, flowDirectionSchema, flowNodeItemSchema, flowConnectionSchema, flowConnectorStyleSchema, processArrowDirectionSchema, processArrowStepSchema, lineArrowSchema, underlineSchema, backgroundImageSchema, } from "./types.js";
8
+ import { lengthSchema, paddingSchema, borderStyleSchema, borderDashSchema, fillStyleSchema, shadowStyleSchema, alignItemsSchema, justifyContentSchema, shapeTypeSchema, tableColumnSchema, tableRowSchema, chartTypeSchema, chartDataSchema, liNodeSchema, radarStyleSchema, bulletNumberTypeSchema, timelineDirectionSchema, timelineItemSchema, matrixAxisSchema, matrixQuadrantsSchema, matrixItemSchema, treeLayoutSchema, treeNodeShapeSchema, treeConnectorStyleSchema, flowDirectionSchema, flowNodeItemSchema, flowConnectionSchema, flowConnectorStyleSchema, processArrowDirectionSchema, processArrowStepSchema, lineArrowSchema, underlineSchema, backgroundImageSchema, } from "../types.js";
21
9
  // ===== Base Node Schema =====
22
10
  export const inputBaseNodeSchema = z.object({
23
11
  w: lengthSchema.optional(),
@@ -47,9 +35,39 @@ export const inputTextNodeSchema = inputBaseNodeSchema.extend({
47
35
  highlight: z.string().optional(),
48
36
  fontFamily: z.string().optional(),
49
37
  lineSpacingMultiple: z.number().optional(),
50
- bullet: z.union([z.boolean(), bulletOptionsSchema]).optional(),
51
38
  });
52
- export const inputImageSizingSchema = z.object({
39
+ export const inputLiNodeSchema = liNodeSchema;
40
+ export const inputUlNodeSchema = inputBaseNodeSchema.extend({
41
+ type: z.literal("ul"),
42
+ items: z.array(inputLiNodeSchema),
43
+ fontPx: z.number().optional(),
44
+ color: z.string().optional(),
45
+ alignText: z.enum(["left", "center", "right"]).optional(),
46
+ bold: z.boolean().optional(),
47
+ italic: z.boolean().optional(),
48
+ underline: underlineSchema.optional(),
49
+ strike: z.boolean().optional(),
50
+ highlight: z.string().optional(),
51
+ fontFamily: z.string().optional(),
52
+ lineSpacingMultiple: z.number().optional(),
53
+ });
54
+ export const inputOlNodeSchema = inputBaseNodeSchema.extend({
55
+ type: z.literal("ol"),
56
+ items: z.array(inputLiNodeSchema),
57
+ fontPx: z.number().optional(),
58
+ color: z.string().optional(),
59
+ alignText: z.enum(["left", "center", "right"]).optional(),
60
+ bold: z.boolean().optional(),
61
+ italic: z.boolean().optional(),
62
+ underline: underlineSchema.optional(),
63
+ strike: z.boolean().optional(),
64
+ highlight: z.string().optional(),
65
+ fontFamily: z.string().optional(),
66
+ lineSpacingMultiple: z.number().optional(),
67
+ numberType: bulletNumberTypeSchema.optional(),
68
+ numberStartAt: z.number().optional(),
69
+ });
70
+ const inputImageSizingSchema = z.object({
53
71
  type: z.enum(["contain", "cover", "crop"]),
54
72
  w: z.number().optional(),
55
73
  h: z.number().optional(),
@@ -83,6 +101,8 @@ export const inputShapeNodeSchema = inputBaseNodeSchema.extend({
83
101
  underline: underlineSchema.optional(),
84
102
  strike: z.boolean().optional(),
85
103
  highlight: z.string().optional(),
104
+ fontFamily: z.string().optional(),
105
+ lineSpacingMultiple: z.number().optional(),
86
106
  });
87
107
  export const inputChartNodeSchema = inputBaseNodeSchema.extend({
88
108
  type: z.literal("chart"),
@@ -106,7 +126,7 @@ export const inputMatrixNodeSchema = inputBaseNodeSchema.extend({
106
126
  quadrants: matrixQuadrantsSchema.optional(),
107
127
  items: z.array(matrixItemSchema),
108
128
  });
109
- export const inputTreeDataItemSchema = z.lazy(() => z.object({
129
+ const inputTreeDataItemSchema = z.lazy(() => z.object({
110
130
  label: z.string(),
111
131
  color: z.string().optional(),
112
132
  children: z.array(inputTreeDataItemSchema).optional(),
@@ -186,30 +206,11 @@ const inputLayerNodeSchemaBase = inputBaseNodeSchema.extend({
186
206
  type: z.literal("layer"),
187
207
  children: z.array(inputLayerChildSchemaBase),
188
208
  });
189
- export const inputBoxNodeSchema = inputBoxNodeSchemaBase;
190
- export const inputVStackNodeSchema = inputVStackNodeSchemaBase;
191
- export const inputHStackNodeSchema = inputHStackNodeSchemaBase;
192
- export const inputLayerNodeSchema = inputLayerNodeSchemaBase;
193
- /**
194
- * Input schema for POM nodes (for LLM/external input validation)
195
- *
196
- * @example
197
- * ```typescript
198
- * import { inputPomNodeSchema, buildPptx } from "@hirokisakabe/pom";
199
- *
200
- * const json = JSON.parse(llmResponse);
201
- * const result = inputPomNodeSchema.safeParse(json);
202
- *
203
- * if (result.success) {
204
- * const pptx = await buildPptx([result.data], { w: 1280, h: 720 });
205
- * await pptx.writeFile({ fileName: "output.pptx" });
206
- * } else {
207
- * console.error("Validation failed:", result.error);
208
- * }
209
- * ```
210
- */
211
- export const inputPomNodeSchema = z.lazy(() => z.discriminatedUnion("type", [
209
+ /** Input schema for POM nodes (used internally by parseXml) */
210
+ const inputPomNodeSchema = z.lazy(() => z.discriminatedUnion("type", [
212
211
  inputTextNodeSchema,
212
+ inputUlNodeSchema,
213
+ inputOlNodeSchema,
213
214
  inputImageNodeSchema,
214
215
  inputTableNodeSchema,
215
216
  inputBoxNodeSchemaBase,
@@ -225,102 +226,3 @@ export const inputPomNodeSchema = z.lazy(() => z.discriminatedUnion("type", [
225
226
  inputLineNodeSchema,
226
227
  inputLayerNodeSchemaBase,
227
228
  ]));
228
- // ===== Slide Master Options Schema =====
229
- export const inputMasterTextObjectSchema = z.object({
230
- type: z.literal("text"),
231
- text: z.string(),
232
- x: z.number(),
233
- y: z.number(),
234
- w: z.number(),
235
- h: z.number(),
236
- fontPx: z.number().optional(),
237
- fontFamily: z.string().optional(),
238
- color: z.string().optional(),
239
- bold: z.boolean().optional(),
240
- italic: z.boolean().optional(),
241
- underline: underlineSchema.optional(),
242
- strike: z.boolean().optional(),
243
- highlight: z.string().optional(),
244
- alignText: z.enum(["left", "center", "right"]).optional(),
245
- });
246
- export const inputMasterImageObjectSchema = z.object({
247
- type: z.literal("image"),
248
- src: z.string(),
249
- x: z.number(),
250
- y: z.number(),
251
- w: z.number(),
252
- h: z.number(),
253
- });
254
- export const inputMasterRectObjectSchema = z.object({
255
- type: z.literal("rect"),
256
- x: z.number(),
257
- y: z.number(),
258
- w: z.number(),
259
- h: z.number(),
260
- fill: fillStyleSchema.optional(),
261
- border: borderStyleSchema.optional(),
262
- });
263
- export const inputMasterLineObjectSchema = z.object({
264
- type: z.literal("line"),
265
- x: z.number(),
266
- y: z.number(),
267
- w: z.number(),
268
- h: z.number(),
269
- line: borderStyleSchema.optional(),
270
- });
271
- export const inputMasterObjectSchema = z.discriminatedUnion("type", [
272
- inputMasterTextObjectSchema,
273
- inputMasterImageObjectSchema,
274
- inputMasterRectObjectSchema,
275
- inputMasterLineObjectSchema,
276
- ]);
277
- export const inputSlideNumberOptionsSchema = z.object({
278
- x: z.number(),
279
- y: z.number(),
280
- w: z.number().optional(),
281
- h: z.number().optional(),
282
- fontPx: z.number().optional(),
283
- fontFamily: z.string().optional(),
284
- color: z.string().optional(),
285
- });
286
- export const inputSlideMasterBackgroundSchema = z.union([
287
- z.object({ color: z.string() }),
288
- z.object({ path: z.string() }),
289
- z.object({ data: z.string() }),
290
- z.object({ image: z.string() }),
291
- ]);
292
- export const inputSlideMasterMarginSchema = z.union([
293
- z.number(),
294
- z.object({
295
- top: z.number().optional(),
296
- right: z.number().optional(),
297
- bottom: z.number().optional(),
298
- left: z.number().optional(),
299
- }),
300
- ]);
301
- /**
302
- * Input schema for slide master options (for LLM/external input validation)
303
- *
304
- * @example
305
- * ```typescript
306
- * import { inputSlideMasterOptionsSchema, buildPptx } from "@hirokisakabe/pom";
307
- *
308
- * const masterOptions = inputSlideMasterOptionsSchema.parse({
309
- * title: "MY_MASTER",
310
- * background: { color: "F0F0F0" },
311
- * objects: [
312
- * { type: "text", text: "Header", x: 48, y: 12, w: 200, h: 28, fontPx: 14 },
313
- * ],
314
- * slideNumber: { x: 1100, y: 680, fontPx: 10 },
315
- * });
316
- *
317
- * const pptx = await buildPptx([page], { w: 1280, h: 720 }, { master: masterOptions });
318
- * ```
319
- */
320
- export const inputSlideMasterOptionsSchema = z.object({
321
- title: z.string().optional(),
322
- background: inputSlideMasterBackgroundSchema.optional(),
323
- margin: inputSlideMasterMarginSchema.optional(),
324
- objects: z.array(inputMasterObjectSchema).optional(),
325
- slideNumber: inputSlideNumberOptionsSchema.optional(),
326
- });
@@ -1,10 +1,14 @@
1
- import type { POMNode } from "./types.ts";
1
+ import type { POMNode } from "../types.ts";
2
+ export declare class ParseXmlError extends Error {
3
+ readonly errors: string[];
4
+ constructor(errors: string[]);
5
+ }
2
6
  /**
3
7
  * XML 文字列を POMNode 配列に変換する。
4
8
  *
5
9
  * XML タグは POM ノードタイプにマッピングされ、属性値は Zod スキーマを参照して
6
10
  * 適切な型(number, boolean, array, object)に変換される。
7
- * 組み込みノード以外のタグ名はカスタムコンポーネントとして扱われる。
11
+ * 未知のタグ名が指定された場合はエラーがスローされる。
8
12
  *
9
13
  * @example
10
14
  * ```typescript
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseXml.d.ts","sourceRoot":"","sources":["../../src/parseXml/parseXml.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAmC3C,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,MAAM,EAAE,MAAM,EAAE,CAAC;gBACrB,MAAM,EAAE,MAAM,EAAE;CAM7B;AAk9BD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,EAAE,CAiCrD"}