lumina-slides 9.0.6 → 9.0.7

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.
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Prepares a deck for export: strips internal dragKey and adds explicit element ids.
3
+ * Used by Studio export, save, and JSON view.
4
+ * - slide.ids: path → id for every element
5
+ * - each element object that can have an id (features[i], timeline[i], elements[i], nodes[i], etc.) gets id set
6
+ */
7
+ import { toRaw } from 'vue';
8
+ import type { Deck, BaseSlideData } from '../core/types';
9
+ import { getElementPaths, resolveId, pathToKey, getValueAt } from '../core/elementResolver';
10
+
11
+ /** Recursively remove all dragKey properties from an object (mutates in place). */
12
+ export function stripDragKeys(obj: unknown): void {
13
+ if (obj == null || typeof obj !== 'object') return;
14
+ if (Array.isArray(obj)) {
15
+ obj.forEach(stripDragKeys);
16
+ return;
17
+ }
18
+ delete (obj as Record<string, unknown>)['dragKey'];
19
+ Object.values(obj as Record<string, unknown>).forEach(stripDragKeys);
20
+ }
21
+
22
+ /** Prepare deck for export: clone, strip dragKey, add slide.ids, and set id on each element object. */
23
+ export function prepareDeckForExport(deck: Deck): Deck {
24
+ const clone = JSON.parse(JSON.stringify(toRaw(deck))) as Deck;
25
+ stripDragKeys(clone);
26
+ const slides = clone.slides ?? [];
27
+ slides.forEach((slide: BaseSlideData, slideIndex: number) => {
28
+ const paths = getElementPaths(slide);
29
+ if (paths.length === 0) return;
30
+ const slideAny = slide as { ids?: Record<string, string> };
31
+ if (!slideAny.ids) slideAny.ids = {};
32
+ paths.forEach((path) => {
33
+ const pathKey = pathToKey(path);
34
+ const resolvedId = resolveId(slide, slideIndex, path);
35
+ slideAny.ids![pathKey] = resolvedId;
36
+
37
+ // Set id on the element object when it's an object (e.g. features[0], elements[0], nodes[0])
38
+ if (path.length > 0 && path[0] !== 'slide') {
39
+ const value = getValueAt(slide, path);
40
+ if (value != null && typeof value === 'object' && !Array.isArray(value)) {
41
+ (value as Record<string, string>).id = resolvedId;
42
+ }
43
+ }
44
+ });
45
+ });
46
+ return clone;
47
+ }