@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.
- package/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "./build-zrZuX4fK.js";
|
|
2
|
+
import { Kt as previewErrorSchema, Mt as PreviewError, Nt as PreviewPageRangeError, Pt as PreviewPlaceholder, Z as PreviewTransform, a as CommonNode, et as Resolution, nt as ResolutionReport, qt as previewPlaceholderSchema } from "./capability-BbKW9w4O.js";
|
|
3
|
+
import { a as paint, c as ScreenGeometry, d as previewOptionsSchema, f as previewPageNumberSchema, h as screenPointSchema, i as PreviewResult, l as ScreenPoint, m as screenGeometrySchema, n as PreviewNode, o as PaintOptions, p as previewPagesSchema, r as PreviewPageResult, s as PreviewOptions, t as PaintResult, u as paintOptionsSchema } from "./index-v77CTJev.js";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
/**
|
|
6
|
+
* Default static preview for both plain editable documents and JSX elements.
|
|
7
|
+
*
|
|
8
|
+
* Plain CommonNode documents run synchronously through resolve + paint without loading React or
|
|
9
|
+
* react-reconciler; JSX inputs dynamically load React expansion on demand.
|
|
10
|
+
*/
|
|
11
|
+
export declare function preview(input: ReactNode | CommonNode, options?: PreviewOptions): Promise<PreviewResult>;
|
|
12
|
+
export { type PaintOptions, type PaintResult, type PreviewError, type PreviewNode, type PreviewOptions, PreviewPageRangeError, type PreviewPageResult, type PreviewPlaceholder, type PreviewResult, type PreviewTransform, type Resolution, type ResolutionReport, type ScreenGeometry, type ScreenPoint, paint, paintOptionsSchema, previewErrorSchema, previewOptionsSchema, previewPageNumberSchema, previewPagesSchema, previewPlaceholderSchema, screenGeometrySchema, screenPointSchema };
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PreviewPageRangeError, previewErrorSchema, previewPlaceholderSchema } from "./core/dist/stage-options.js";
|
|
2
|
+
import { createResolver } from "./core/dist/resolve.js";
|
|
3
|
+
import { documentCapabilities } from "./capabilities/dist/all.js";
|
|
4
|
+
import "./core/dist/build.js";
|
|
5
|
+
import { paint } from "./preview/dist/index.js";
|
|
6
|
+
import { paintOptionsSchema, previewOptionsSchema, previewPageNumberSchema, previewPagesSchema, screenGeometrySchema, screenPointSchema, validatePaintOptions } from "./preview/dist/options.js";
|
|
7
|
+
import { resolveDocumentInput } from "./pptxdk/src/compose.js";
|
|
8
|
+
// src/preview.ts
|
|
9
|
+
const resolveDocument = createResolver(documentCapabilities);
|
|
10
|
+
/**
|
|
11
|
+
* Default static preview for both plain editable documents and JSX elements.
|
|
12
|
+
*
|
|
13
|
+
* Plain CommonNode documents run synchronously through resolve + paint without loading React or
|
|
14
|
+
* react-reconciler; JSX inputs dynamically load React expansion on demand.
|
|
15
|
+
*/
|
|
16
|
+
async function preview(input, options = {}) {
|
|
17
|
+
const validatedOptions = validatePaintOptions(options);
|
|
18
|
+
if (validatedOptions.signal?.aborted) throw validatedOptions.signal.reason;
|
|
19
|
+
const signalOption = validatedOptions.signal === void 0 ? {} : { signal: validatedOptions.signal };
|
|
20
|
+
const resolution = await resolveDocumentInput(resolveDocument, input, signalOption);
|
|
21
|
+
const { pages } = paint(resolution, validatedOptions);
|
|
22
|
+
return Object.freeze({
|
|
23
|
+
report: resolution.report,
|
|
24
|
+
pages,
|
|
25
|
+
slides: resolution.slides,
|
|
26
|
+
slide: (id) => resolution.slide(id)
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export { PreviewPageRangeError, paint, paintOptionsSchema, preview, previewErrorSchema, previewOptionsSchema, previewPageNumberSchema, previewPagesSchema, previewPlaceholderSchema, screenGeometrySchema, screenPointSchema };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { validateAuthorIdScopes } from "../../core/dist/author-ids.js";
|
|
2
|
+
import { CommonNode } from "../../core/dist/document.js";
|
|
3
|
+
import "../../core/dist/host.js";
|
|
4
|
+
// ../react/dist/append.js
|
|
5
|
+
function collectAnonymousIds(parent, ids) {
|
|
6
|
+
for (const child of parent.children) {
|
|
7
|
+
if (!(child instanceof CommonNode)) continue;
|
|
8
|
+
const id = child.id;
|
|
9
|
+
if (id !== void 0) ids.add(id);
|
|
10
|
+
else if (child.kind !== "slide") collectAnonymousIds(child, ids);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Finds the node whose direct children share the appended nodes' naming scope.
|
|
15
|
+
*
|
|
16
|
+
* Named nodes, pages, and the deck start a scope. Anonymous nodes stay transparent, so an
|
|
17
|
+
* ownerless anonymous tree keeps one scope rooted at its outermost node even before attachment.
|
|
18
|
+
*/
|
|
19
|
+
function scopeOwner(target) {
|
|
20
|
+
let current = target;
|
|
21
|
+
let outermost = target;
|
|
22
|
+
for (; current !== void 0; current = current.parent) {
|
|
23
|
+
outermost = current;
|
|
24
|
+
if (current.id !== void 0 || current.kind === "slide" || current.kind === "deck") return current;
|
|
25
|
+
}
|
|
26
|
+
return outermost;
|
|
27
|
+
}
|
|
28
|
+
/** Collects the slide ids the formal deck model sees directly or through one Section level. */
|
|
29
|
+
function deckSlideIds(deck) {
|
|
30
|
+
const ids = /* @__PURE__ */ new Set();
|
|
31
|
+
const add = (slide) => {
|
|
32
|
+
if (slide.id !== void 0) ids.add(slide.id);
|
|
33
|
+
};
|
|
34
|
+
for (const child of deck.children) {
|
|
35
|
+
if (!(child instanceof CommonNode)) continue;
|
|
36
|
+
if (child.kind === "slide") add(child);
|
|
37
|
+
else if (child.kind === "section") {
|
|
38
|
+
for (const member of child.children) if (member instanceof CommonNode && member.kind === "slide") add(member);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return ids;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Preflights the ids introduced by one append against the target's current structure.
|
|
45
|
+
*
|
|
46
|
+
* The target can be edited while the fragment expands, so the check runs only when the caller is
|
|
47
|
+
* about to attach. It rejects conflicts caused by this fragment without re-validating unrelated
|
|
48
|
+
* existing content; the formal build remains responsible for all other diagnostics.
|
|
49
|
+
*/
|
|
50
|
+
function assertAppendableAuthorIds(target, nodes) {
|
|
51
|
+
if (nodes.length === 0) return;
|
|
52
|
+
const owner = scopeOwner(target);
|
|
53
|
+
const currentIds = owner.kind === "deck" ? deckSlideIds(owner) : /* @__PURE__ */ new Set();
|
|
54
|
+
if (owner.kind !== "deck") for (const child of owner.children) {
|
|
55
|
+
if (!(child instanceof CommonNode)) continue;
|
|
56
|
+
if (child.id !== void 0) currentIds.add(child.id);
|
|
57
|
+
else if (child.kind !== "slide") collectAnonymousIds(child, currentIds);
|
|
58
|
+
}
|
|
59
|
+
const appended = {
|
|
60
|
+
type: owner.type,
|
|
61
|
+
props: {},
|
|
62
|
+
children: nodes
|
|
63
|
+
};
|
|
64
|
+
validateAuthorIdScopes(appended, target.query.path, currentIds);
|
|
65
|
+
}
|
|
66
|
+
export { assertAppendableAuthorIds };
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { BuildError, toBuildDiagnostic } from "../../core/dist/diagnostics.js";
|
|
2
|
+
import "../../core/dist/index.js";
|
|
3
|
+
import { CommonContainer, CommonNode } from "../../core/dist/document.js";
|
|
4
|
+
import { HostTextNode, hostNodeCreator, insertDeclarationChild, removeDeclarationChild, replaceDeclarationProps, setDeclarationText } from "../../core/dist/host.js";
|
|
5
|
+
import { hostMountPlaceholder } from "./mount.js";
|
|
6
|
+
// ../react/dist/document-adapter.js
|
|
7
|
+
const nodeOwnerContainer = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
const activeMounts = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
const hostChildrenByParent = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function createHostContainer() {
|
|
11
|
+
return {
|
|
12
|
+
children: [],
|
|
13
|
+
hostOrder: [],
|
|
14
|
+
mountedRecords: /* @__PURE__ */ new Set(),
|
|
15
|
+
locked: false
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function isMountHostRecord(value) {
|
|
19
|
+
return typeof value === "object" && value !== null && "kind" in value && value.kind === "mount" && "adoptedNodes" in value;
|
|
20
|
+
}
|
|
21
|
+
function isHostContainer(value) {
|
|
22
|
+
return "hostOrder" in value && "mountedRecords" in value;
|
|
23
|
+
}
|
|
24
|
+
function isLocked(target) {
|
|
25
|
+
if (isMountHostRecord(target)) return target.container.locked;
|
|
26
|
+
if ("hostOrder" in target && "mountedRecords" in target) return target.locked;
|
|
27
|
+
return nodeOwnerContainer.get(target)?.locked === true;
|
|
28
|
+
}
|
|
29
|
+
function mountError(message) {
|
|
30
|
+
return new BuildError([toBuildDiagnostic("mount", "invalid-structure", message)]);
|
|
31
|
+
}
|
|
32
|
+
function isDescendantOf(candidate, ancestor) {
|
|
33
|
+
for (let current = candidate.parent; current !== void 0; current = current.parent) if (current === ancestor) return true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function parseMountDeclaration(props) {
|
|
37
|
+
const rawNode = props["node"];
|
|
38
|
+
const rawSlot = props["slot"];
|
|
39
|
+
const rawPlaceholder = props[hostMountPlaceholder];
|
|
40
|
+
const placeholder = typeof rawPlaceholder === "string" ? rawPlaceholder : void 0;
|
|
41
|
+
if (rawSlot !== void 0) {
|
|
42
|
+
if (!(rawNode instanceof CommonNode)) throw mountError("Mount with a slot requires node to be a single CommonNode");
|
|
43
|
+
if (!(rawSlot instanceof CommonContainer)) throw mountError("Mount slot must be a CommonContainer");
|
|
44
|
+
if (rawSlot !== rawNode && !isDescendantOf(rawSlot, rawNode)) throw mountError("Mount slot must be the adopted node itself or one of its descendant containers");
|
|
45
|
+
return {
|
|
46
|
+
nodes: [rawNode],
|
|
47
|
+
slot: rawSlot,
|
|
48
|
+
placeholder
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (rawNode === null || rawNode === void 0) return {
|
|
52
|
+
nodes: [],
|
|
53
|
+
slot: void 0,
|
|
54
|
+
placeholder
|
|
55
|
+
};
|
|
56
|
+
if (rawNode instanceof CommonNode) return {
|
|
57
|
+
nodes: [rawNode],
|
|
58
|
+
slot: void 0,
|
|
59
|
+
placeholder
|
|
60
|
+
};
|
|
61
|
+
if (Array.isArray(rawNode)) {
|
|
62
|
+
const nodes = [];
|
|
63
|
+
const seen = /* @__PURE__ */ new Set();
|
|
64
|
+
for (const item of rawNode) {
|
|
65
|
+
if (!(item instanceof CommonNode)) throw mountError("Mount node array must contain only CommonNode instances");
|
|
66
|
+
if (seen.has(item)) throw mountError("Mount cannot adopt the same CommonNode instance more than once");
|
|
67
|
+
seen.add(item);
|
|
68
|
+
nodes.push(item);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
nodes,
|
|
72
|
+
slot: void 0,
|
|
73
|
+
placeholder
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
throw mountError("Mount node must be a CommonNode, a readonly CommonNode array, null, or undefined");
|
|
77
|
+
}
|
|
78
|
+
function withoutHostMetadata(props) {
|
|
79
|
+
const { children: _children, [hostNodeCreator]: _create, ...declaration } = props;
|
|
80
|
+
return declaration;
|
|
81
|
+
}
|
|
82
|
+
function isDocumentNodeCreator(value) {
|
|
83
|
+
return typeof value === "function";
|
|
84
|
+
}
|
|
85
|
+
function hostChildrenOf(parent) {
|
|
86
|
+
let list = hostChildrenByParent.get(parent);
|
|
87
|
+
if (list === void 0) {
|
|
88
|
+
list = [...parent.children];
|
|
89
|
+
hostChildrenByParent.set(parent, list);
|
|
90
|
+
}
|
|
91
|
+
return list;
|
|
92
|
+
}
|
|
93
|
+
function orderListOf(parent) {
|
|
94
|
+
if (isHostContainer(parent)) return parent.hostOrder;
|
|
95
|
+
if (isMountHostRecord(parent)) return parent.slotChildren;
|
|
96
|
+
return hostChildrenOf(parent);
|
|
97
|
+
}
|
|
98
|
+
function realSlotContainer(record) {
|
|
99
|
+
if (record.slot === void 0) throw mountError("Mount cannot accept children without a slot container");
|
|
100
|
+
return record.slot;
|
|
101
|
+
}
|
|
102
|
+
function realParentNode(parent) {
|
|
103
|
+
return isMountHostRecord(parent) ? realSlotContainer(parent) : parent;
|
|
104
|
+
}
|
|
105
|
+
function realChildrenOf(parent) {
|
|
106
|
+
if (isHostContainer(parent)) return parent.children;
|
|
107
|
+
return realParentNode(parent).children;
|
|
108
|
+
}
|
|
109
|
+
function firstLiveChildOf(entry, liveChildren) {
|
|
110
|
+
if (!isMountHostRecord(entry)) return liveChildren.includes(entry) ? entry : void 0;
|
|
111
|
+
if (!entry.committed) return void 0;
|
|
112
|
+
for (const adopted of entry.adoptedNodes) if (liveChildren.includes(adopted)) return adopted;
|
|
113
|
+
}
|
|
114
|
+
function resolveAnchorAfter(order, startIndex, liveChildren) {
|
|
115
|
+
for (let i = startIndex; i < order.length; i += 1) {
|
|
116
|
+
const candidate = order[i];
|
|
117
|
+
if (candidate === void 0) continue;
|
|
118
|
+
const live = firstLiveChildOf(candidate, liveChildren);
|
|
119
|
+
if (live !== void 0) return live;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function recordOrderInsert(order, child, before) {
|
|
123
|
+
const existing = order.indexOf(child);
|
|
124
|
+
if (existing !== -1) order.splice(existing, 1);
|
|
125
|
+
const index = before === void 0 ? -1 : order.indexOf(before);
|
|
126
|
+
if (index === -1) order.push(child);
|
|
127
|
+
else order.splice(index, 0, child);
|
|
128
|
+
}
|
|
129
|
+
function sameNodeList(a, b) {
|
|
130
|
+
if (a.length !== b.length) return false;
|
|
131
|
+
for (let i = 0; i < a.length; i += 1) if (!Object.is(a[i], b[i])) return false;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
function assertCanAdopt(nodes, record) {
|
|
135
|
+
for (const node of nodes) {
|
|
136
|
+
const existingMount = activeMounts.get(node);
|
|
137
|
+
if (existingMount !== void 0 && existingMount !== record) throw mountError(`CommonNode (${node.kind}) is already mounted by another active Mount`);
|
|
138
|
+
if (node.parent !== void 0 && existingMount !== record) throw mountError(`CommonNode (${node.kind}) is already attached to a parent container`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function spliceRootChildren(container, items, before) {
|
|
142
|
+
for (const item of items) {
|
|
143
|
+
const current = container.children.indexOf(item);
|
|
144
|
+
if (current !== -1) container.children.splice(current, 1);
|
|
145
|
+
const index = before === void 0 ? -1 : container.children.indexOf(before);
|
|
146
|
+
if (index === -1) container.children.push(item);
|
|
147
|
+
else container.children.splice(index, 0, item);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function removeFromRootChildren(container, items) {
|
|
151
|
+
for (const item of items) {
|
|
152
|
+
const index = container.children.indexOf(item);
|
|
153
|
+
if (index !== -1) container.children.splice(index, 1);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function insertAdoptedIntoParent(parent, nodes, before, record) {
|
|
157
|
+
if (nodes.length === 0) return;
|
|
158
|
+
if (isHostContainer(parent)) {
|
|
159
|
+
spliceRootChildren(parent, nodes, before);
|
|
160
|
+
for (const node of nodes) activeMounts.set(node, record);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const targetNode = realParentNode(parent);
|
|
164
|
+
const inserted = [];
|
|
165
|
+
try {
|
|
166
|
+
for (const node of nodes) {
|
|
167
|
+
insertDeclarationChild(targetNode, node, before);
|
|
168
|
+
inserted.push(node);
|
|
169
|
+
}
|
|
170
|
+
} catch (error) {
|
|
171
|
+
for (const node of inserted) removeDeclarationChild(targetNode, node);
|
|
172
|
+
throw mountError(error instanceof Error ? error.message : String(error));
|
|
173
|
+
}
|
|
174
|
+
for (const node of inserted) activeMounts.set(node, record);
|
|
175
|
+
}
|
|
176
|
+
function detachAdoptedFromParent(parent, nodes, record, locked) {
|
|
177
|
+
for (const node of nodes) if (activeMounts.get(node) === record) activeMounts.delete(node);
|
|
178
|
+
if (isHostContainer(parent)) {
|
|
179
|
+
removeFromRootChildren(parent, nodes);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (locked) return;
|
|
183
|
+
const targetNode = realParentNode(parent);
|
|
184
|
+
for (const node of nodes) removeDeclarationChild(targetNode, node);
|
|
185
|
+
}
|
|
186
|
+
function applyPlaceholderBinding(record) {
|
|
187
|
+
if (record.placeholder === void 0 || record.adoptedNodes.length !== 1) return;
|
|
188
|
+
const node = record.adoptedNodes[0];
|
|
189
|
+
if (record.appliedPlaceholder !== void 0 && record.appliedPlaceholder.node === node) {
|
|
190
|
+
node.set({ placeholder: record.placeholder });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const currentProps = node.props;
|
|
194
|
+
record.appliedPlaceholder = {
|
|
195
|
+
node,
|
|
196
|
+
hasPrevious: Object.prototype.hasOwnProperty.call(currentProps, "placeholder"),
|
|
197
|
+
previousValue: currentProps["placeholder"]
|
|
198
|
+
};
|
|
199
|
+
node.set({ placeholder: record.placeholder });
|
|
200
|
+
}
|
|
201
|
+
function restorePlaceholderBinding(record) {
|
|
202
|
+
const applied = record.appliedPlaceholder;
|
|
203
|
+
if (applied === void 0) return;
|
|
204
|
+
record.appliedPlaceholder = void 0;
|
|
205
|
+
applied.node.set({ placeholder: applied.hasPrevious ? applied.previousValue : void 0 });
|
|
206
|
+
}
|
|
207
|
+
function commitMountIntoParent(parent, record, anchor) {
|
|
208
|
+
const isReposition = record.committed && record.hostParent === parent;
|
|
209
|
+
if (!isReposition) assertCanAdopt(record.adoptedNodes, record);
|
|
210
|
+
record.hostParent = parent;
|
|
211
|
+
insertAdoptedIntoParent(parent, record.adoptedNodes, anchor, record);
|
|
212
|
+
try {
|
|
213
|
+
if (!isReposition) applyPlaceholderBinding(record);
|
|
214
|
+
record.committed = true;
|
|
215
|
+
record.container.mountedRecords.add(record);
|
|
216
|
+
if (!isReposition && record.slot !== void 0) attachSlotChildren(record);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (!isReposition) {
|
|
219
|
+
restorePlaceholderBinding(record);
|
|
220
|
+
detachAdoptedFromParent(parent, record.adoptedNodes, record, false);
|
|
221
|
+
record.committed = false;
|
|
222
|
+
record.container.mountedRecords.delete(record);
|
|
223
|
+
}
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function attachSlotChildren(record) {
|
|
228
|
+
const slot = record.slot;
|
|
229
|
+
if (slot === void 0) return;
|
|
230
|
+
for (const child of record.slotChildren) if (isMountHostRecord(child)) {
|
|
231
|
+
if (!child.committed) commitMountHostInstance(child);
|
|
232
|
+
else insertAdoptedIntoParent(record, child.adoptedNodes, void 0, child);
|
|
233
|
+
} else insertDeclarationChild(slot, child, void 0);
|
|
234
|
+
}
|
|
235
|
+
function detachSlotChildren(record, locked) {
|
|
236
|
+
const slot = record.slot;
|
|
237
|
+
if (slot === void 0) return;
|
|
238
|
+
for (const child of record.slotChildren) if (isMountHostRecord(child)) detachAdoptedFromParent(record, child.adoptedNodes, child, locked);
|
|
239
|
+
else if (!locked) removeDeclarationChild(slot, child);
|
|
240
|
+
}
|
|
241
|
+
function releaseMountSubtree(entry, locked) {
|
|
242
|
+
if (isMountHostRecord(entry)) {
|
|
243
|
+
for (const child of entry.slotChildren) releaseMountSubtree(child, locked);
|
|
244
|
+
if (!locked && entry.slot !== void 0) {
|
|
245
|
+
for (const child of entry.slotChildren) if (!isMountHostRecord(child)) removeDeclarationChild(entry.slot, child);
|
|
246
|
+
}
|
|
247
|
+
if (entry.hostParent !== void 0 && entry.committed) detachAdoptedFromParent(entry.hostParent, entry.adoptedNodes, entry, locked);
|
|
248
|
+
else for (const node of entry.adoptedNodes) if (activeMounts.get(node) === entry) activeMounts.delete(node);
|
|
249
|
+
entry.container.mountedRecords.delete(entry);
|
|
250
|
+
if (!locked) {
|
|
251
|
+
restorePlaceholderBinding(entry);
|
|
252
|
+
entry.committed = false;
|
|
253
|
+
entry.hostParent = void 0;
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (entry instanceof CommonNode) {
|
|
258
|
+
const children = hostChildrenByParent.get(entry);
|
|
259
|
+
if (children !== void 0) {
|
|
260
|
+
for (const child of children) releaseMountSubtree(child, locked);
|
|
261
|
+
if (!locked) hostChildrenByParent.delete(entry);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function createHostInstance(type, props, container) {
|
|
266
|
+
if (props["__pptxdkMount"] === true) {
|
|
267
|
+
const { nodes, slot, placeholder } = parseMountDeclaration(props);
|
|
268
|
+
return {
|
|
269
|
+
kind: "mount",
|
|
270
|
+
container,
|
|
271
|
+
adoptedNodes: nodes,
|
|
272
|
+
slot,
|
|
273
|
+
placeholder,
|
|
274
|
+
appliedPlaceholder: void 0,
|
|
275
|
+
hostParent: void 0,
|
|
276
|
+
committed: false,
|
|
277
|
+
slotChildren: []
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
const create = props[hostNodeCreator];
|
|
281
|
+
const declaration = withoutHostMetadata(props);
|
|
282
|
+
const instance = isDocumentNodeCreator(create) ? create(declaration) : new CommonNode(type, type, declaration);
|
|
283
|
+
nodeOwnerContainer.set(instance, container);
|
|
284
|
+
return instance;
|
|
285
|
+
}
|
|
286
|
+
function createHostText(text, container) {
|
|
287
|
+
const node = new HostTextNode(text);
|
|
288
|
+
nodeOwnerContainer.set(node, container);
|
|
289
|
+
return node;
|
|
290
|
+
}
|
|
291
|
+
function updateHostText(text, next) {
|
|
292
|
+
if (isLocked(text)) return;
|
|
293
|
+
setDeclarationText(text, next);
|
|
294
|
+
}
|
|
295
|
+
function updateMountInstance(record, nextProps) {
|
|
296
|
+
if (isLocked(record)) return;
|
|
297
|
+
const { nodes: nextNodes, slot: nextSlot, placeholder: nextPlaceholder } = parseMountDeclaration(nextProps);
|
|
298
|
+
const nodesUnchanged = sameNodeList(record.adoptedNodes, nextNodes);
|
|
299
|
+
const slotUnchanged = record.slot === nextSlot;
|
|
300
|
+
const placeholderUnchanged = record.placeholder === nextPlaceholder;
|
|
301
|
+
if (nodesUnchanged && slotUnchanged && placeholderUnchanged) return;
|
|
302
|
+
assertCanAdopt(nextNodes, record);
|
|
303
|
+
const prevNodes = record.adoptedNodes;
|
|
304
|
+
const prevSlot = record.slot;
|
|
305
|
+
if (!slotUnchanged && prevSlot !== void 0 && record.committed) detachSlotChildren(record, false);
|
|
306
|
+
if (!nodesUnchanged && record.hostParent !== void 0 && record.committed) {
|
|
307
|
+
const order = orderListOf(record.hostParent);
|
|
308
|
+
const recordIndex = order.indexOf(record);
|
|
309
|
+
const anchor = recordIndex === -1 ? void 0 : resolveAnchorAfter(order, recordIndex + 1, realChildrenOf(record.hostParent));
|
|
310
|
+
restorePlaceholderBinding(record);
|
|
311
|
+
detachAdoptedFromParent(record.hostParent, prevNodes, record, false);
|
|
312
|
+
try {
|
|
313
|
+
insertAdoptedIntoParent(record.hostParent, nextNodes, anchor, record);
|
|
314
|
+
} catch (error) {
|
|
315
|
+
insertAdoptedIntoParent(record.hostParent, prevNodes, anchor, record);
|
|
316
|
+
applyPlaceholderBinding(record);
|
|
317
|
+
if (!slotUnchanged && prevSlot !== void 0) attachSlotChildren(record);
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
record.adoptedNodes = nextNodes;
|
|
322
|
+
record.slot = nextSlot;
|
|
323
|
+
record.placeholder = nextPlaceholder;
|
|
324
|
+
if (record.committed) {
|
|
325
|
+
if (nextPlaceholder === void 0) restorePlaceholderBinding(record);
|
|
326
|
+
else applyPlaceholderBinding(record);
|
|
327
|
+
}
|
|
328
|
+
if (!slotUnchanged && nextSlot !== void 0 && record.committed) attachSlotChildren(record);
|
|
329
|
+
}
|
|
330
|
+
function updateHostInstance(instance, props) {
|
|
331
|
+
if (isLocked(instance)) return;
|
|
332
|
+
if (isMountHostRecord(instance)) {
|
|
333
|
+
updateMountInstance(instance, props);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
replaceDeclarationProps(instance, withoutHostMetadata(props));
|
|
337
|
+
}
|
|
338
|
+
function appendInitialHostChild(parent, child) {
|
|
339
|
+
if (isLocked(parent)) return;
|
|
340
|
+
if (isMountHostRecord(parent) && parent.slot === void 0) throw mountError("Mount cannot accept children without a slot container");
|
|
341
|
+
recordOrderInsert(orderListOf(parent), child, void 0);
|
|
342
|
+
if (isMountHostRecord(child)) {
|
|
343
|
+
child.hostParent = parent;
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (isMountHostRecord(parent)) return;
|
|
347
|
+
insertDeclarationChild(parent, child);
|
|
348
|
+
}
|
|
349
|
+
function commitMountHostInstance(instance) {
|
|
350
|
+
if (!isMountHostRecord(instance) || instance.committed) return;
|
|
351
|
+
if (isLocked(instance)) return;
|
|
352
|
+
if (instance.hostParent !== void 0 && isMountHostRecord(instance.hostParent) && !instance.hostParent.committed) {
|
|
353
|
+
commitMountHostInstance(instance.hostParent);
|
|
354
|
+
if (instance.committed) return;
|
|
355
|
+
}
|
|
356
|
+
const parent = instance.hostParent;
|
|
357
|
+
if (parent === void 0) return;
|
|
358
|
+
const order = orderListOf(parent);
|
|
359
|
+
const index = order.indexOf(instance);
|
|
360
|
+
commitMountIntoParent(parent, instance, index === -1 ? void 0 : resolveAnchorAfter(order, index + 1, realChildrenOf(parent)));
|
|
361
|
+
}
|
|
362
|
+
function insertHostChild(parent, child, before) {
|
|
363
|
+
if (isLocked(parent) || isLocked(child)) return;
|
|
364
|
+
const order = orderListOf(parent);
|
|
365
|
+
const liveChildren = realChildrenOf(parent);
|
|
366
|
+
recordOrderInsert(order, child, before);
|
|
367
|
+
const index = order.indexOf(child);
|
|
368
|
+
const anchor = before === void 0 || index === -1 ? void 0 : resolveAnchorAfter(order, index + 1, liveChildren);
|
|
369
|
+
if (isMountHostRecord(child)) {
|
|
370
|
+
commitMountIntoParent(parent, child, anchor);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (isHostContainer(parent)) spliceRootChildren(parent, [child], anchor);
|
|
374
|
+
else insertDeclarationChild(realParentNode(parent), child, anchor);
|
|
375
|
+
}
|
|
376
|
+
function removeHostChild(parent, child) {
|
|
377
|
+
const locked = isLocked(parent) || isLocked(child);
|
|
378
|
+
const order = orderListOf(parent);
|
|
379
|
+
const index = order.indexOf(child);
|
|
380
|
+
if (index !== -1) order.splice(index, 1);
|
|
381
|
+
releaseMountSubtree(child, locked);
|
|
382
|
+
if (locked) return;
|
|
383
|
+
if (!isMountHostRecord(child)) {
|
|
384
|
+
if (isHostContainer(parent)) removeFromRootChildren(parent, [child]);
|
|
385
|
+
else removeDeclarationChild(realParentNode(parent), child);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Closes the React ownership window on the completed candidate before renderer teardown. The
|
|
390
|
+
* candidate shares its nodes with the returned document; teardown must only detach the renderer
|
|
391
|
+
* root, never clear this content.
|
|
392
|
+
*/
|
|
393
|
+
function lockHandoffTree(container) {
|
|
394
|
+
container.locked = true;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Releases active mount tracking for a finished or aborted root. When the root was not handed off
|
|
398
|
+
* (for example, an error or abort interrupted commit), any adopted nodes attached during the failed
|
|
399
|
+
* commit are detached cleanly so they remain unowned.
|
|
400
|
+
*/
|
|
401
|
+
function releaseContainerMounts(container) {
|
|
402
|
+
for (const record of Array.from(container.mountedRecords)) releaseMountSubtree(record, container.locked);
|
|
403
|
+
}
|
|
404
|
+
export { appendInitialHostChild, commitMountHostInstance, createHostContainer, createHostInstance, createHostText, insertHostChild, isMountHostRecord, lockHandoffTree, releaseContainerMounts, removeHostChild, updateHostInstance, updateHostText };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CommonNode, RichTextContainer, createDeckNode, createSectionNode, createSlideLayoutNode, createSlideMasterNode, createSlideNode } from "../../core/dist/document.js";
|
|
2
|
+
import { hostNodeCreator } from "../../core/dist/host.js";
|
|
3
|
+
import { Mount, createPlaceholderMount } from "./mount.js";
|
|
4
|
+
import { cloneElement, createElement, isValidElement } from "react";
|
|
5
|
+
// ../react/dist/elements.js
|
|
6
|
+
const inlineTextMarker = Symbol.for("@pptxdk/text-inline-element");
|
|
7
|
+
function createPlaceholderTextNode(props) {
|
|
8
|
+
return new RichTextContainer("text", "text", props);
|
|
9
|
+
}
|
|
10
|
+
function isInlineTextElement(value) {
|
|
11
|
+
if (!isValidElement(value)) return false;
|
|
12
|
+
if (typeof value.type === "function") return inlineTextMarker in value.type;
|
|
13
|
+
return value.type === "paragraph" || value.type === "span" || value.type === "sup" || value.type === "sub" || value.type === "slide-number";
|
|
14
|
+
}
|
|
15
|
+
function isInlineTextNode(node) {
|
|
16
|
+
return node.type === "paragraph" || node.type === "span" || node.type === "sup" || node.type === "sub" || node.type === "slide-number";
|
|
17
|
+
}
|
|
18
|
+
function expandPlaceholderEntry(key, value) {
|
|
19
|
+
if (value === void 0) return null;
|
|
20
|
+
if (value instanceof CommonNode) {
|
|
21
|
+
if (isInlineTextNode(value)) return createElement("text", {
|
|
22
|
+
key: `__ph_${key}`,
|
|
23
|
+
placeholder: key,
|
|
24
|
+
[hostNodeCreator]: createPlaceholderTextNode
|
|
25
|
+
}, createElement(Mount, { node: value }));
|
|
26
|
+
return createPlaceholderMount(key, value);
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
const mapped = value.map((item, index) => item instanceof CommonNode ? createElement(Mount, {
|
|
30
|
+
key: `__ph_${key}_${index}`,
|
|
31
|
+
node: item
|
|
32
|
+
}) : item);
|
|
33
|
+
return createElement("text", {
|
|
34
|
+
key: `__ph_${key}`,
|
|
35
|
+
placeholder: key,
|
|
36
|
+
[hostNodeCreator]: createPlaceholderTextNode
|
|
37
|
+
}, ...mapped);
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === "string" || isInlineTextElement(value)) return createElement("text", {
|
|
40
|
+
key: `__ph_${key}`,
|
|
41
|
+
placeholder: key,
|
|
42
|
+
[hostNodeCreator]: createPlaceholderTextNode
|
|
43
|
+
}, value);
|
|
44
|
+
if (isValidElement(value)) {
|
|
45
|
+
value.props;
|
|
46
|
+
return cloneElement(value, {
|
|
47
|
+
...value.key === null ? { key: `__ph_${key}` } : {},
|
|
48
|
+
placeholder: key
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function hostElement(type, create) {
|
|
54
|
+
return function HostElement(props) {
|
|
55
|
+
return createElement(type, {
|
|
56
|
+
...props,
|
|
57
|
+
[hostNodeCreator]: create
|
|
58
|
+
}, props.children);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const Deck = hostElement("deck", createDeckNode);
|
|
62
|
+
const SlideMaster = hostElement("slide-master", createSlideMasterNode);
|
|
63
|
+
const SlideLayout = hostElement("slide-layout", createSlideLayoutNode);
|
|
64
|
+
function Slide(props) {
|
|
65
|
+
const { placeholders, children, ...rest } = props;
|
|
66
|
+
if (placeholders === void 0) return createElement("slide", {
|
|
67
|
+
...rest,
|
|
68
|
+
[hostNodeCreator]: createSlideNode
|
|
69
|
+
}, children);
|
|
70
|
+
const entries = Object.entries(placeholders).filter(([, value]) => value !== void 0);
|
|
71
|
+
const keepEmpty = props.layout === void 0 && entries.length === 0;
|
|
72
|
+
const placeholderChildren = entries.map(([key, value]) => expandPlaceholderEntry(key, value));
|
|
73
|
+
return createElement("slide", {
|
|
74
|
+
...keepEmpty ? {
|
|
75
|
+
...rest,
|
|
76
|
+
placeholders
|
|
77
|
+
} : rest,
|
|
78
|
+
[hostNodeCreator]: createSlideNode
|
|
79
|
+
}, ...placeholderChildren, children);
|
|
80
|
+
}
|
|
81
|
+
const Section = hostElement("section", createSectionNode);
|
|
82
|
+
export { Deck, Section, Slide, SlideLayout, SlideMaster };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { BuildError, toBuildDiagnostic } from "../../core/dist/diagnostics.js";
|
|
2
|
+
import "../../core/dist/index.js";
|
|
3
|
+
import { CommonContainer, CommonNode } from "../../core/dist/document.js";
|
|
4
|
+
import { Mount } from "./mount.js";
|
|
5
|
+
import { createElement, useRef } from "react";
|
|
6
|
+
// ../react/dist/from-vanilla.js
|
|
7
|
+
function isVanillaSlotResult(value) {
|
|
8
|
+
if (typeof value !== "object" || value === null) return false;
|
|
9
|
+
if (value instanceof CommonNode) return false;
|
|
10
|
+
if (!("node" in value) || !("slot" in value)) return false;
|
|
11
|
+
return value.node instanceof CommonNode && value.slot instanceof CommonContainer;
|
|
12
|
+
}
|
|
13
|
+
function hasNonEmptyChildren(children) {
|
|
14
|
+
if (children === void 0 || children === null || typeof children === "boolean") return false;
|
|
15
|
+
if (Array.isArray(children)) return children.some(hasNonEmptyChildren);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
function shallowEqualProps(a, b) {
|
|
19
|
+
const keysA = Object.keys(a);
|
|
20
|
+
const keysB = Object.keys(b);
|
|
21
|
+
if (keysA.length !== keysB.length) return false;
|
|
22
|
+
for (const key of keysA) {
|
|
23
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
|
|
24
|
+
if (!Object.is(a[key], b[key])) return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
function bridgeError(message) {
|
|
29
|
+
return new BuildError([toBuildDiagnostic("mount", "invalid-structure", message)]);
|
|
30
|
+
}
|
|
31
|
+
function fromVanilla(factory) {
|
|
32
|
+
function VanillaComponent(props) {
|
|
33
|
+
const { children, ...vanillaProps } = props;
|
|
34
|
+
const cacheRef = useRef(null);
|
|
35
|
+
let output;
|
|
36
|
+
if (cacheRef.current !== null && shallowEqualProps(cacheRef.current.props, vanillaProps)) output = cacheRef.current.output;
|
|
37
|
+
else {
|
|
38
|
+
output = factory(vanillaProps);
|
|
39
|
+
cacheRef.current = {
|
|
40
|
+
props: vanillaProps,
|
|
41
|
+
output
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (isVanillaSlotResult(output)) return createElement(Mount, {
|
|
45
|
+
node: output.node,
|
|
46
|
+
slot: output.slot
|
|
47
|
+
}, children);
|
|
48
|
+
if (output instanceof CommonNode) {
|
|
49
|
+
if (hasNonEmptyChildren(children)) throw bridgeError("Closed vanilla component returned a CommonNode and cannot accept children");
|
|
50
|
+
return createElement(Mount, { node: output });
|
|
51
|
+
}
|
|
52
|
+
throw bridgeError("fromVanilla factory must return a CommonNode or a { node, slot } container result");
|
|
53
|
+
}
|
|
54
|
+
VanillaComponent.displayName = factory.name !== "" ? `Vanilla(${factory.name})` : "VanillaComponent";
|
|
55
|
+
return VanillaComponent;
|
|
56
|
+
}
|
|
57
|
+
export { fromVanilla };
|