@officedk/pptxdk 0.0.0-stage → 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 (206) hide show
  1. package/LICENSE +21 -0
  2. package/dist/build-zrZuX4fK.d.ts +3 -0
  3. package/dist/build.d.ts +35 -0
  4. package/dist/build.js +128 -0
  5. package/dist/capabilities/dist/all.js +34 -0
  6. package/dist/capabilities/dist/box/box-codegen.js +84 -0
  7. package/dist/capabilities/dist/box/box-declaration.js +32 -0
  8. package/dist/capabilities/dist/box/box-elements.js +17 -0
  9. package/dist/capabilities/dist/box/box.js +142 -0
  10. package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
  11. package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
  12. package/dist/capabilities/dist/chart/chart-elements.js +12 -0
  13. package/dist/capabilities/dist/chart/chart-import.js +2403 -0
  14. package/dist/capabilities/dist/chart/chart-labels.js +86 -0
  15. package/dist/capabilities/dist/chart/chart-model.js +9 -0
  16. package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
  17. package/dist/capabilities/dist/chart/chart-xml.js +788 -0
  18. package/dist/capabilities/dist/chart/chart.js +1119 -0
  19. package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
  20. package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
  21. package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
  22. package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
  23. package/dist/capabilities/dist/chart/preview/index.js +192 -0
  24. package/dist/capabilities/dist/chart/preview/layout.js +592 -0
  25. package/dist/capabilities/dist/chart/preview/legend.js +273 -0
  26. package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
  27. package/dist/capabilities/dist/chart/preview/markers.js +100 -0
  28. package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
  29. package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
  30. package/dist/capabilities/dist/chart/preview/scales.js +365 -0
  31. package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
  32. package/dist/capabilities/dist/chart/preview/style.js +60 -0
  33. package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
  34. package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
  35. package/dist/capabilities/dist/chart/preview/types.js +5 -0
  36. package/dist/capabilities/dist/document.js +168 -0
  37. package/dist/capabilities/dist/font/font-embedding.js +119 -0
  38. package/dist/capabilities/dist/font/font-engine.js +834 -0
  39. package/dist/capabilities/dist/font/font-import.js +766 -0
  40. package/dist/capabilities/dist/font/font-subset.js +55 -0
  41. package/dist/capabilities/dist/font/font.js +72 -0
  42. package/dist/capabilities/dist/group/group-codegen.js +74 -0
  43. package/dist/capabilities/dist/group/group-declaration.js +41 -0
  44. package/dist/capabilities/dist/group/group-elements.js +12 -0
  45. package/dist/capabilities/dist/group/group-import.js +649 -0
  46. package/dist/capabilities/dist/group/group-xml.js +8 -0
  47. package/dist/capabilities/dist/group/group.js +260 -0
  48. package/dist/capabilities/dist/image/gif-decoder.js +244 -0
  49. package/dist/capabilities/dist/image/image-codegen.js +164 -0
  50. package/dist/capabilities/dist/image/image-declaration.js +8 -0
  51. package/dist/capabilities/dist/image/image-decode.js +244 -0
  52. package/dist/capabilities/dist/image/image-elements.js +12 -0
  53. package/dist/capabilities/dist/image/image-import.js +984 -0
  54. package/dist/capabilities/dist/image/image-schemas.js +147 -0
  55. package/dist/capabilities/dist/image/image-xml.js +12 -0
  56. package/dist/capabilities/dist/image/image.js +552 -0
  57. package/dist/capabilities/dist/line/line-codegen.js +89 -0
  58. package/dist/capabilities/dist/line/line-declaration.js +72 -0
  59. package/dist/capabilities/dist/line/line-elements.js +12 -0
  60. package/dist/capabilities/dist/line/line-import.js +504 -0
  61. package/dist/capabilities/dist/line/line-xml.js +9 -0
  62. package/dist/capabilities/dist/line/line.js +331 -0
  63. package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
  64. package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
  65. package/dist/capabilities/dist/masters/masters.js +250 -0
  66. package/dist/capabilities/dist/motion/motion-api.js +757 -0
  67. package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
  68. package/dist/capabilities/dist/motion/motion-elements.js +43 -0
  69. package/dist/capabilities/dist/motion/motion-import.js +1568 -0
  70. package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
  71. package/dist/capabilities/dist/motion/motion-query.js +423 -0
  72. package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
  73. package/dist/capabilities/dist/motion/motion.js +1617 -0
  74. package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
  75. package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
  76. package/dist/capabilities/dist/notes/notes-elements.js +12 -0
  77. package/dist/capabilities/dist/notes/notes-import.js +292 -0
  78. package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
  79. package/dist/capabilities/dist/notes/notes-xml.js +38 -0
  80. package/dist/capabilities/dist/notes/notes.js +194 -0
  81. package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
  82. package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
  83. package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
  84. package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
  85. package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
  86. package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
  87. package/dist/capabilities/dist/shape/shape-elements.js +12 -0
  88. package/dist/capabilities/dist/shape/shape-import.js +628 -0
  89. package/dist/capabilities/dist/shape/shape-xml.js +6 -0
  90. package/dist/capabilities/dist/shape/shape.js +320 -0
  91. package/dist/capabilities/dist/shared/geometry.js +1681 -0
  92. package/dist/capabilities/dist/shared/identity.js +205 -0
  93. package/dist/capabilities/dist/shared/morph-api.js +11 -0
  94. package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
  95. package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
  96. package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
  97. package/dist/capabilities/dist/shared/text-schemas.js +241 -0
  98. package/dist/capabilities/dist/shared/text-service.js +2252 -0
  99. package/dist/capabilities/dist/shared/visual.js +1197 -0
  100. package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
  101. package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
  102. package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
  103. package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
  104. package/dist/capabilities/dist/table/table-codegen.js +125 -0
  105. package/dist/capabilities/dist/table/table-declaration.js +15 -0
  106. package/dist/capabilities/dist/table/table-elements.js +27 -0
  107. package/dist/capabilities/dist/table/table-import.js +606 -0
  108. package/dist/capabilities/dist/table/table-schemas.js +334 -0
  109. package/dist/capabilities/dist/table/table-xml.js +30 -0
  110. package/dist/capabilities/dist/table/table.js +739 -0
  111. package/dist/capabilities/dist/text/text-codegen.js +198 -0
  112. package/dist/capabilities/dist/text/text-declaration.js +27 -0
  113. package/dist/capabilities/dist/text/text-elements.js +54 -0
  114. package/dist/capabilities/dist/text/text-import.js +1224 -0
  115. package/dist/capabilities/dist/text/text-xml.js +9 -0
  116. package/dist/capabilities/dist/text/text.js +320 -0
  117. package/dist/capabilities/dist/transition/transition-api.js +136 -0
  118. package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
  119. package/dist/capabilities/dist/transition/transition-import.js +477 -0
  120. package/dist/capabilities/dist/transition/transition.js +260 -0
  121. package/dist/capability-BbKW9w4O.d.ts +2131 -0
  122. package/dist/cli.js +20 -0
  123. package/dist/codegen/dist/assets.js +79 -0
  124. package/dist/codegen/dist/codegen.js +691 -0
  125. package/dist/codegen/dist/identifiers.js +203 -0
  126. package/dist/codegen/dist/index.js +3 -0
  127. package/dist/codegen/dist/printer.js +143 -0
  128. package/dist/codegen/dist/types.js +77 -0
  129. package/dist/core/dist/author-ids.js +51 -0
  130. package/dist/core/dist/author-schemas.js +330 -0
  131. package/dist/core/dist/block-flex-layout.js +801 -0
  132. package/dist/core/dist/build.js +4 -0
  133. package/dist/core/dist/capability.js +15 -0
  134. package/dist/core/dist/declaration.js +16 -0
  135. package/dist/core/dist/diagnostics.js +353 -0
  136. package/dist/core/dist/document-internals.js +26 -0
  137. package/dist/core/dist/document.js +417 -0
  138. package/dist/core/dist/font-seal.js +204 -0
  139. package/dist/core/dist/geometry-schemas.js +256 -0
  140. package/dist/core/dist/grid-layout.js +449 -0
  141. package/dist/core/dist/host.js +40 -0
  142. package/dist/core/dist/index.js +15 -0
  143. package/dist/core/dist/input-values.js +61 -0
  144. package/dist/core/dist/layout-protocol.js +61 -0
  145. package/dist/core/dist/layout-schemas.js +201 -0
  146. package/dist/core/dist/layout.js +340 -0
  147. package/dist/core/dist/masters.js +194 -0
  148. package/dist/core/dist/morph.js +30 -0
  149. package/dist/core/dist/placeholders.js +275 -0
  150. package/dist/core/dist/query.js +190 -0
  151. package/dist/core/dist/resolution.js +12 -0
  152. package/dist/core/dist/resolve.js +2246 -0
  153. package/dist/core/dist/stage-options.js +300 -0
  154. package/dist/core/dist/theme.js +1023 -0
  155. package/dist/core/dist/transform-geometry.js +72 -0
  156. package/dist/document-41spD7bq.d.ts +1350 -0
  157. package/dist/emit/dist/emit.js +957 -0
  158. package/dist/emit/dist/index.js +5 -0
  159. package/dist/emit/dist/ooxml.js +661 -0
  160. package/dist/emit/dist/shape-tree.js +12 -0
  161. package/dist/import/dist/alternate-content.js +54 -0
  162. package/dist/import/dist/diagnostics.js +157 -0
  163. package/dist/import/dist/fonts.js +309 -0
  164. package/dist/import/dist/import.js +513 -0
  165. package/dist/import/dist/index.js +16 -0
  166. package/dist/import/dist/masters.js +1293 -0
  167. package/dist/import/dist/mechanism.js +10 -0
  168. package/dist/import/dist/namespaces.js +61 -0
  169. package/dist/import/dist/notes-masters.js +300 -0
  170. package/dist/import/dist/opc.js +233 -0
  171. package/dist/import/dist/resources.js +166 -0
  172. package/dist/import/dist/sections.js +139 -0
  173. package/dist/import/dist/themes.js +777 -0
  174. package/dist/import/dist/visual.js +821 -0
  175. package/dist/import/dist/xml-fragments.js +277 -0
  176. package/dist/import/dist/xml-reader.js +267 -0
  177. package/dist/index-1ag7U9Jt.d.ts +63 -0
  178. package/dist/index-BEwhk7c8.d.ts +72 -0
  179. package/dist/index-cK2KtukZ.d.ts +161 -0
  180. package/dist/index-v77CTJev.d.ts +55 -0
  181. package/dist/index.d.ts +8 -0
  182. package/dist/index.js +82 -0
  183. package/dist/node.d.ts +53 -0
  184. package/dist/node.js +225 -0
  185. package/dist/pptxdk/src/cli-commands.js +907 -0
  186. package/dist/pptxdk/src/compose.js +53 -0
  187. package/dist/pptxdk/src/slide.js +9 -0
  188. package/dist/preview/dist/index.js +342 -0
  189. package/dist/preview/dist/options.js +40 -0
  190. package/dist/preview/dist/svg-guard.js +1089 -0
  191. package/dist/preview.d.ts +12 -0
  192. package/dist/preview.js +29 -0
  193. package/dist/react/dist/append.js +66 -0
  194. package/dist/react/dist/document-adapter.js +404 -0
  195. package/dist/react/dist/elements.js +82 -0
  196. package/dist/react/dist/from-vanilla.js +57 -0
  197. package/dist/react/dist/index.js +89 -0
  198. package/dist/react/dist/mount.js +34 -0
  199. package/dist/react/dist/reconciler.js +290 -0
  200. package/dist/react.d.ts +235 -0
  201. package/dist/react.js +31 -0
  202. package/dist/transition-6n8GZxSg.d.ts +9 -0
  203. package/dist/vanilla.d.ts +4 -0
  204. package/dist/vanilla.js +15 -0
  205. package/package.json +79 -3
  206. package/README.md +0 -3
@@ -0,0 +1,205 @@
1
+ import { CapabilityError } from "../../../core/dist/diagnostics.js";
2
+ import { isMorphKey } from "../../../core/dist/morph.js";
3
+ import { parseLinkTarget } from "../../../core/dist/author-schemas.js";
4
+ import "../../../core/dist/capability.js";
5
+ import { xmlEscape } from "../../../emit/dist/ooxml.js";
6
+ import "../../../emit/dist/index.js";
7
+ import { P_NS, REL_HYPERLINK, R_NS } from "../../../import/dist/namespaces.js";
8
+ import { resolvePartPath } from "../../../import/dist/opc.js";
9
+ import { ooxmlBoolSchema } from "../../../import/dist/xml-fragments.js";
10
+ import { resolveExternalRelationshipTarget } from "../../../import/dist/resources.js";
11
+ import "../../../import/dist/index.js";
12
+ import { z } from "zod";
13
+ // ../capabilities/dist/shared/identity.js
14
+ const NvPrUserDrawnSchema = z.object({ userDrawn: ooxmlBoolSchema.optional() });
15
+ function directChildDom(parent, namespaceUri, localName) {
16
+ for (let child = parent.firstChild; child !== null; child = child.nextSibling) {
17
+ if (child.nodeType !== 1) continue;
18
+ const el = child;
19
+ if ((el.namespaceURI ?? "") === namespaceUri && (el.localName ?? el.tagName) === localName) return el;
20
+ }
21
+ }
22
+ /** Side-effect-free check for `<p:ph>` inside an object's `<p:nvPr>`. */
23
+ function hasPlaceholderElement(cursor) {
24
+ for (const wrapperName of [
25
+ "nvSpPr",
26
+ "nvPicPr",
27
+ "nvGrpSpPr",
28
+ "nvGraphicFramePr",
29
+ "nvCxnSpPr"
30
+ ]) {
31
+ const wrapper = directChildDom(cursor.element, P_NS, wrapperName);
32
+ if (wrapper === void 0) continue;
33
+ const nvPr = directChildDom(wrapper, P_NS, "nvPr");
34
+ if (nvPr === void 0) continue;
35
+ if (directChildDom(nvPr, "http://schemas.openxmlformats.org/presentationml/2006/main", "ph") !== void 0) return true;
36
+ }
37
+ return false;
38
+ }
39
+ /** Consumes `<p:nvPr>` (and optional `userDrawn` flag) for non-placeholder objects. */
40
+ function consumeNonPlaceholderNvPr(nvParentCursor) {
41
+ const nvPr = nvParentCursor.child(P_NS, "nvPr");
42
+ if (nvPr === void 0) return;
43
+ const raw = nvPr.attrsObject(["userDrawn"]);
44
+ NvPrUserDrawnSchema.safeParse(raw);
45
+ }
46
+ const optionalNameSchema = z.string().refine((value) => value.trim() !== "", { message: "name must be a non-empty string" });
47
+ const HlinkClickFragmentSchema = z.object({
48
+ id: z.string().optional(),
49
+ action: z.string().optional()
50
+ });
51
+ /** Validates an optional non-empty object name parameter. */
52
+ function parseOptionalName(value, path) {
53
+ if (value === void 0) return void 0;
54
+ const parsed = optionalNameSchema.safeParse(value);
55
+ if (!parsed.success) throw new CapabilityError("invalid-parameter", "name must be a non-empty string", path);
56
+ return parsed.data;
57
+ }
58
+ /** Validates an optional Morph handle created by createMorphScope().handle(name). */
59
+ function parseMorphKey(value, path) {
60
+ if (value === void 0) return void 0;
61
+ if (!isMorphKey(value)) throw new CapabilityError("invalid-morph-key", "morphKey must be created by createMorphScope().handle(name)", path);
62
+ return value;
63
+ }
64
+ /** Native object capabilities share the same click link representation, with relationships and actions pre-resolved by core. */
65
+ function nativeLinkXml(link) {
66
+ if (link === void 0) return "";
67
+ return `<a:hlinkClick ${[...link.relationshipId === void 0 ? [] : [`r:id="${xmlEscape(link.relationshipId)}"`], ...link.action === void 0 ? [] : [`action="${xmlEscape(link.action)}"`]].join(" ")}/>`;
68
+ }
69
+ const homeAction = "ppaction://hlinkshowjump?jump=firstslide";
70
+ const slideJumpAction = "ppaction://hlinksldjump";
71
+ /**
72
+ * Reads an `<a:hlinkClick>` child under `<p:cNvPr>` into a `LinkTarget` or deferred internal slide jump,
73
+ * keeping external URLs offline and diagnosing broken relationships without dropping the host object.
74
+ */
75
+ function readClickLink(hlinkCursor, context, objectIdentity) {
76
+ const clickLocation = {
77
+ part: context.part,
78
+ xpath: hlinkCursor.xpath,
79
+ slideIndex: context.slideIndex,
80
+ ...objectIdentity?.objectId === void 0 ? {} : { objectId: objectIdentity.objectId },
81
+ ...objectIdentity?.objectName === void 0 ? {} : { objectName: objectIdentity.objectName }
82
+ };
83
+ const rawId = hlinkCursor.attr("id", R_NS);
84
+ const rawAction = hlinkCursor.attr("action");
85
+ const parsed = HlinkClickFragmentSchema.safeParse({
86
+ ...rawId === void 0 ? {} : { id: rawId },
87
+ ...rawAction === void 0 ? {} : { action: rawAction }
88
+ });
89
+ if (!parsed.success) return {
90
+ clickLocation,
91
+ diagnostics: [{
92
+ code: "invalid-xml-value",
93
+ category: "corrupt-input",
94
+ disposition: "omitted",
95
+ location: clickLocation,
96
+ attributeOrElement: "a:hlinkClick"
97
+ }]
98
+ };
99
+ const rId = parsed.data.id ?? "";
100
+ const action = parsed.data.action ?? "";
101
+ if (rId === "" && action === homeAction) return {
102
+ link: { action: "home" },
103
+ clickLocation,
104
+ diagnostics: []
105
+ };
106
+ if (rId === "") return {
107
+ clickLocation,
108
+ diagnostics: [{
109
+ code: "broken-relationship",
110
+ category: "corrupt-input",
111
+ disposition: "omitted",
112
+ location: clickLocation,
113
+ relationshipId: ""
114
+ }]
115
+ };
116
+ const relationships = context.relationships ?? /* @__PURE__ */ new Map();
117
+ if (action === slideJumpAction) {
118
+ const rel = relationships.get(rId);
119
+ if (rel === void 0 || rel.Type !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide" || rel.TargetMode === "External") return {
120
+ relationshipId: rId,
121
+ clickLocation,
122
+ diagnostics: [{
123
+ code: "broken-relationship",
124
+ category: "corrupt-input",
125
+ disposition: "omitted",
126
+ location: clickLocation,
127
+ relationshipId: rId
128
+ }]
129
+ };
130
+ const targetPart = resolvePartPath(context.part, rel.Target);
131
+ if (targetPart === void 0 || !context.package.hasPart(targetPart)) return {
132
+ relationshipId: rId,
133
+ clickLocation,
134
+ diagnostics: [{
135
+ code: "missing-target-part",
136
+ category: "corrupt-input",
137
+ disposition: "omitted",
138
+ location: clickLocation,
139
+ relationshipId: rId,
140
+ targetPart: targetPart ?? rel.Target
141
+ }]
142
+ };
143
+ return {
144
+ deferredSlideLink: {
145
+ targetPart,
146
+ relationshipId: rId,
147
+ location: clickLocation
148
+ },
149
+ relationshipId: rId,
150
+ clickLocation,
151
+ diagnostics: []
152
+ };
153
+ }
154
+ if (action !== "") return {
155
+ relationshipId: rId,
156
+ clickLocation,
157
+ diagnostics: [{
158
+ code: "unsupported-mechanism",
159
+ category: "unsupported",
160
+ disposition: "omitted",
161
+ location: clickLocation,
162
+ namespaceUri: hlinkCursor.namespaceUri,
163
+ localName: hlinkCursor.localName,
164
+ mechanismHint: action
165
+ }]
166
+ };
167
+ const resolvedExternal = resolveExternalRelationshipTarget(relationships, rId, clickLocation, REL_HYPERLINK);
168
+ if (!resolvedExternal.ok) return {
169
+ relationshipId: rId,
170
+ clickLocation,
171
+ diagnostics: [resolvedExternal.diagnostic]
172
+ };
173
+ try {
174
+ new URL(resolvedExternal.target);
175
+ } catch {
176
+ return {
177
+ relationshipId: rId,
178
+ clickLocation,
179
+ diagnostics: [{
180
+ code: "invalid-xml-value",
181
+ category: "corrupt-input",
182
+ disposition: "omitted",
183
+ location: clickLocation,
184
+ attributeOrElement: "Relationship/@Target",
185
+ rawValue: resolvedExternal.target
186
+ }]
187
+ };
188
+ }
189
+ return {
190
+ link: { url: resolvedExternal.target },
191
+ relationshipId: rId,
192
+ clickLocation,
193
+ diagnostics: []
194
+ };
195
+ }
196
+ /** Registers a deferred internal slide-jump callback so links resolve via slidePartPath -> allocated Slide.id. */
197
+ function attachDeferredSlideLink(node, deferredSlideLink, context) {
198
+ if (deferredSlideLink !== void 0 && context.registerDeferredSlideLink !== void 0) context.registerDeferredSlideLink({
199
+ ...deferredSlideLink,
200
+ apply(targetSlideId) {
201
+ node.set({ link: { id: targetSlideId } });
202
+ }
203
+ });
204
+ }
205
+ export { attachDeferredSlideLink, consumeNonPlaceholderNvPr, hasPlaceholderElement, nativeLinkXml, optionalNameSchema, parseLinkTarget, parseMorphKey, parseOptionalName, readClickLink };
@@ -0,0 +1,11 @@
1
+ import { isMorphKey } from "../../../core/dist/morph.js";
2
+ import { linkTargetSchema } from "../../../core/dist/author-schemas.js";
3
+ import "../../../core/dist/capability.js";
4
+ import "../../../core/dist/index.js";
5
+ import { z } from "zod";
6
+ // ../capabilities/dist/shared/morph-api.js
7
+ /** Runtime-identity-preserving Zod schema for handles created by `createMorphScope().handle(name)`. */
8
+ const morphKeySchema = z.custom(isMorphKey, "morphKey must be created by createMorphScope().handle(name)");
9
+ z.strictObject({ morphKey: morphKeySchema.optional() }).readonly();
10
+ z.strictObject({ link: linkTargetSchema.optional() }).readonly();
11
+ export { morphKeySchema };
@@ -0,0 +1,238 @@
1
+ import { matchLayoutPlaceholderKey, matchMasterPlaceholderSpec, nativePlaceholderRefSchema, placeholderRoleSchema, resolvePlaceholderBoxFromLayers } from "../../../core/dist/placeholders.js";
2
+ import "../../../core/dist/capability.js";
3
+ import { pxToEmu } from "../../../emit/dist/ooxml.js";
4
+ import "../../../emit/dist/index.js";
5
+ import { P_NS } from "../../../import/dist/namespaces.js";
6
+ import { ooxmlBoolSchema, ooxmlNonNegativeIntSchema } from "../../../import/dist/xml-fragments.js";
7
+ import "../../../import/dist/index.js";
8
+ import { resolvePlaceholderVisualStyle } from "./style-inheritance.js";
9
+ // ../capabilities/dist/shared/placeholder-import.js
10
+ const P14_MOD_ID_EXT_URI = "{D42A27DB-BD31-4B8C-83A1-F6EECF244321}";
11
+ /** Finds a direct child XML element matching namespace URI and local name without mutating cursor tracking. */
12
+ function directElementChild(parent, namespaceUri, localName) {
13
+ for (let child = parent.firstChild; child !== null; child = child.nextSibling) {
14
+ if (child.nodeType !== 1) continue;
15
+ const el = child;
16
+ if ((el.namespaceURI ?? "") === namespaceUri && (el.localName ?? el.tagName) === localName) return el;
17
+ }
18
+ }
19
+ /** Side-effect-free lookup of `<p:ph>` inside `<p:{nvContainer}>/<p:nvPr>`. */
20
+ function directPlaceholderElement(cursor, nvContainerLocalName) {
21
+ const nvContainer = directElementChild(cursor.element, P_NS, nvContainerLocalName);
22
+ if (nvContainer === void 0) return void 0;
23
+ const nvPr = directElementChild(nvContainer, P_NS, "nvPr");
24
+ if (nvPr === void 0) return void 0;
25
+ return directElementChild(nvPr, P_NS, "ph");
26
+ }
27
+ /** Side-effect-free predicate identifying `<p:sp>` elements bound to a placeholder (`<p:ph>`). */
28
+ function isPlaceholderSpElement(cursor) {
29
+ return directPlaceholderElement(cursor, "nvSpPr") !== void 0;
30
+ }
31
+ /** Side-effect-free predicate identifying `<p:pic>` elements bound to a placeholder (`<p:ph>`). */
32
+ function isPlaceholderPicElement(cursor) {
33
+ return directPlaceholderElement(cursor, "nvPicPr") !== void 0;
34
+ }
35
+ /** Side-effect-free predicate identifying `<p:graphicFrame>` elements bound to a placeholder (`<p:ph>`). */
36
+ function isPlaceholderGraphicFrameElement(cursor) {
37
+ return directPlaceholderElement(cursor, "nvGraphicFramePr") !== void 0;
38
+ }
39
+ function consumeSubtree(cursor) {
40
+ const attrs = cursor.element.attributes;
41
+ for (let i = 0; i < attrs.length; i += 1) {
42
+ const attr = attrs.item(i);
43
+ if (attr === null) continue;
44
+ const ns = attr.namespaceURI ?? "";
45
+ const local = attr.localName ?? attr.name;
46
+ if (ns === "http://www.w3.org/2000/xmlns/" || attr.name === "xmlns" || attr.prefix === "xmlns") continue;
47
+ cursor.consumeAttr(local, ns);
48
+ }
49
+ for (const child of cursor.remainingElementChildren()) consumeSubtree(child);
50
+ }
51
+ /**
52
+ * Reads optional `<p:ph>` and benign `p14:modId` extensions inside `<p:nvPr>`.
53
+ * Shared across text, image, table, chart, and unpopulated placeholder importers.
54
+ */
55
+ function readNvPrPlaceholder(nvPr, location, diagnostics) {
56
+ if (nvPr === void 0) return { kind: "none" };
57
+ const extLst = nvPr.child(P_NS, "extLst");
58
+ if (extLst !== void 0) {
59
+ for (const ext of extLst.children(P_NS, "ext")) if (ext.attr("uri") === P14_MOD_ID_EXT_URI) consumeSubtree(ext);
60
+ }
61
+ const ph = nvPr.child(P_NS, "ph");
62
+ if (ph === void 0) return { kind: "none" };
63
+ const rawPh = ph.attrsObject([
64
+ "type",
65
+ "idx",
66
+ "sz",
67
+ "orient",
68
+ "hasCustomPrompt"
69
+ ]);
70
+ const explicitType = rawPh["type"] !== void 0;
71
+ const parsedRole = placeholderRoleSchema.safeParse(rawPh["type"] ?? "obj");
72
+ if (!parsedRole.success) {
73
+ diagnostics.push({
74
+ code: "unsupported-mechanism",
75
+ category: "unsupported",
76
+ disposition: "omitted",
77
+ location: {
78
+ ...location,
79
+ xpath: ph.xpath
80
+ },
81
+ namespaceUri: P_NS,
82
+ localName: "ph",
83
+ mechanismHint: `ph:${rawPh["type"] ?? ""}`
84
+ });
85
+ return { kind: "error" };
86
+ }
87
+ const idxParsed = ooxmlNonNegativeIntSchema.safeParse(rawPh["idx"]);
88
+ const hasPromptParsed = ooxmlBoolSchema.safeParse(rawPh["hasCustomPrompt"]);
89
+ const parsedNativeRef = nativePlaceholderRefSchema.safeParse({
90
+ type: parsedRole.data,
91
+ explicitType,
92
+ ...idxParsed.success ? { idx: idxParsed.data } : {},
93
+ ...rawPh["sz"] !== void 0 ? { size: rawPh["sz"] } : {},
94
+ ...rawPh["orient"] !== void 0 ? { orient: rawPh["orient"] } : {},
95
+ ...hasPromptParsed.success && hasPromptParsed.data ? { hasCustomPrompt: true } : {}
96
+ });
97
+ if (!parsedNativeRef.success) {
98
+ diagnostics.push({
99
+ code: "invalid-xml-value",
100
+ category: "corrupt-input",
101
+ disposition: "omitted",
102
+ location: {
103
+ ...location,
104
+ xpath: ph.xpath
105
+ },
106
+ attributeOrElement: "p:ph",
107
+ rawValue: JSON.stringify(rawPh)
108
+ });
109
+ return { kind: "error" };
110
+ }
111
+ return {
112
+ kind: "ok",
113
+ nativeRef: parsedNativeRef.data
114
+ };
115
+ }
116
+ /**
117
+ * Evaluates whether a slide object carrying `<p:ph>` can keep a 1:1 `placeholder` slot binding,
118
+ * or must materialize its 5-layer master/layout cascade and unbind into a free slide object.
119
+ */
120
+ function resolvePlaceholderImportClaim(args) {
121
+ const { context, nativeRef, compatibleRoles, allowMasterDirectFallback = false } = args;
122
+ const matchedKey = matchLayoutPlaceholderKey(context.layoutPlaceholders, {
123
+ type: nativeRef.type,
124
+ idx: nativeRef.idx
125
+ });
126
+ const layoutPlaceholder = matchedKey === void 0 ? void 0 : context.layoutPlaceholders?.[matchedKey];
127
+ const effectiveRole = layoutPlaceholder?.type ?? nativeRef.type;
128
+ const masterPlaceholder = matchMasterPlaceholderSpec(context.masterPlaceholders, effectiveRole);
129
+ const roleCompatible = compatibleRoles === void 0 || compatibleRoles.has(effectiveRole);
130
+ const alreadyClaimed = matchedKey !== void 0 && context.claimedPlaceholderKeys?.has(matchedKey) === true;
131
+ if (matchedKey !== void 0 && layoutPlaceholder !== void 0 && roleCompatible && !alreadyClaimed) {
132
+ context.claimedPlaceholderKeys?.add(matchedKey);
133
+ return {
134
+ bound: true,
135
+ key: matchedKey,
136
+ layoutPlaceholder,
137
+ ...masterPlaceholder === void 0 ? {} : { masterPlaceholder }
138
+ };
139
+ }
140
+ if (allowMasterDirectFallback && matchedKey === void 0 && nativeRef.idx === 4294967295 && roleCompatible && masterPlaceholder !== void 0) return {
141
+ bound: true,
142
+ masterPlaceholder
143
+ };
144
+ const inheritanceContext = {
145
+ ...layoutPlaceholder === void 0 ? {} : { layoutPlaceholder },
146
+ ...masterPlaceholder === void 0 ? {} : { masterPlaceholder },
147
+ ...context.masterTextStyles === void 0 ? {} : { masterTextStyles: context.masterTextStyles },
148
+ nativeRef,
149
+ slideDimensions: context.slideDimensions ?? {
150
+ width: 960,
151
+ height: 540
152
+ }
153
+ };
154
+ return {
155
+ bound: false,
156
+ reason: matchedKey === void 0 ? "orphan" : alreadyClaimed ? "duplicate" : "incompatible",
157
+ ...layoutPlaceholder === void 0 ? {} : { layoutPlaceholder },
158
+ ...masterPlaceholder === void 0 ? {} : { masterPlaceholder },
159
+ inheritanceContext
160
+ };
161
+ }
162
+ /**
163
+ * Resolves effective free-object box coordinates for an unbound placeholder across
164
+ * master placeholder, layout placeholder, and local `<a:xfrm>`.
165
+ */
166
+ function resolveUnboundPlaceholderBox(args) {
167
+ const { inheritanceContext, localBox, requireHeight } = args;
168
+ const localStyle = {};
169
+ if (localBox?.x !== void 0) localStyle["left"] = localBox.x;
170
+ if (localBox?.y !== void 0) localStyle["top"] = localBox.y;
171
+ if (localBox?.width !== void 0) localStyle["width"] = localBox.width;
172
+ if (localBox?.height !== void 0) localStyle["height"] = localBox.height;
173
+ const resolved = resolvePlaceholderBoxFromLayers([
174
+ inheritanceContext.masterPlaceholder,
175
+ inheritanceContext.layoutPlaceholder,
176
+ Object.keys(localStyle).length === 0 ? void 0 : { style: localStyle }
177
+ ], inheritanceContext.slideDimensions);
178
+ const validCoord = (v) => typeof v === "number" && Number.isFinite(v) && Math.abs(v) <= 1e6;
179
+ const validExtent = (v) => {
180
+ if (typeof v !== "number" || !Number.isFinite(v) || v <= 0) return false;
181
+ const emu = pxToEmu(v);
182
+ return emu >= 1 && emu <= 2147483647;
183
+ };
184
+ if (!validCoord(resolved.x) || !validCoord(resolved.y) || !validExtent(resolved.width)) return;
185
+ const hasHeight = validExtent(resolved.height);
186
+ if (requireHeight && !hasHeight) return;
187
+ return {
188
+ x: resolved.x,
189
+ y: resolved.y,
190
+ width: resolved.width,
191
+ ...hasHeight ? { height: resolved.height } : {}
192
+ };
193
+ }
194
+ /** Removes `"none"` placeholder-clear sentinels from a style record materialized onto a free object. */
195
+ function stripPlaceholderClearSentinels(style) {
196
+ const cleaned = {};
197
+ for (const [key, value] of Object.entries(style)) {
198
+ if (value === void 0) continue;
199
+ if ((key === "background" || key === "border" || key === "boxShadow" || key === "textShadow") && value === "none") continue;
200
+ cleaned[key] = value;
201
+ }
202
+ return cleaned;
203
+ }
204
+ /** Computes corner borderRadius when a geometry specifies DrawingML `roundRect`. */
205
+ function roundRectBorderRadiusForBox(geometry, boxSize) {
206
+ if (geometry === void 0 || boxSize === void 0) return void 0;
207
+ if (geometry === "roundRect") return 16667 / 1e5 * Math.min(boxSize.width, boxSize.height);
208
+ if (typeof geometry === "object" && geometry.type === "preset" && geometry.name === "roundRect") {
209
+ const adj = geometry.adjust?.["adj"] ?? 16667;
210
+ if (adj > 0) return adj / 1e5 * Math.min(boxSize.width, boxSize.height);
211
+ }
212
+ }
213
+ /** Materializes 5-layer visual (`spPr`) overrides onto an unbound free slide object. */
214
+ function materializeUnboundVisualStyle(args) {
215
+ const { inheritanceContext, localVisualStyle, localGeometry, boxSize } = args;
216
+ const resolved = stripPlaceholderClearSentinels({ ...resolvePlaceholderVisualStyle(inheritanceContext, localVisualStyle) });
217
+ if (resolved["borderRadius"] === void 0) {
218
+ const radius = roundRectBorderRadiusForBox(localGeometry ?? inheritanceContext.layoutPlaceholder?.geometry ?? inheritanceContext.masterPlaceholder?.geometry, boxSize);
219
+ if (radius !== void 0) resolved["borderRadius"] = radius;
220
+ }
221
+ return resolved;
222
+ }
223
+ /** Records a `compatibility-fallback` diagnostic when an over-rule placeholder unbinds into a free object. */
224
+ function emitPlaceholderUnbindDiagnostic(args) {
225
+ args.diagnostics.push({
226
+ code: "compatibility-fallback",
227
+ category: "unsupported",
228
+ disposition: "fallback",
229
+ location: args.location,
230
+ preferredMechanism: "placeholder",
231
+ selectedFallback: args.retainedAs,
232
+ loss: {
233
+ lost: "master-layout-inheritance",
234
+ retainedAs: args.retainedAs
235
+ }
236
+ });
237
+ }
238
+ export { directElementChild, directPlaceholderElement, emitPlaceholderUnbindDiagnostic, isPlaceholderGraphicFrameElement, isPlaceholderPicElement, isPlaceholderSpElement, materializeUnboundVisualStyle, readNvPrPlaceholder, resolvePlaceholderImportClaim, resolveUnboundPlaceholderBox, roundRectBorderRadiusForBox, stripPlaceholderClearSentinels };