@syncfusion/ej2-office-common 35.1.37

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 (147) hide show
  1. package/.eslintrc.json +263 -0
  2. package/.prettierrc.json +5 -0
  3. package/README.md +167 -0
  4. package/api-extractor.json +35 -0
  5. package/core.js +4 -0
  6. package/dist/ej2-office-common.umd.min.js +11 -0
  7. package/dist/ej2-office-common.umd.min.js.map +1 -0
  8. package/dist/es6/ej2-office-common.es2015.js +6585 -0
  9. package/dist/es6/ej2-office-common.es2015.js.map +1 -0
  10. package/dist/es6/ej2-office-common.es5.js +7955 -0
  11. package/dist/es6/ej2-office-common.es5.js.map +1 -0
  12. package/dist/global/ej2-office-common.min.js +11 -0
  13. package/dist/global/ej2-office-common.min.js.map +1 -0
  14. package/dist/global/index.d.ts +14 -0
  15. package/encryption.js +4 -0
  16. package/features.js +4 -0
  17. package/global.json +6 -0
  18. package/index.js +4 -0
  19. package/license +10 -0
  20. package/nuget.config +7 -0
  21. package/package.json +23 -0
  22. package/src/all.d.ts +41 -0
  23. package/src/all.js +38 -0
  24. package/src/core/index.d.ts +6 -0
  25. package/src/core/index.js +6 -0
  26. package/src/core/xml/index.d.ts +7 -0
  27. package/src/core/xml/index.js +6 -0
  28. package/src/core/xml/model.d.ts +71 -0
  29. package/src/core/xml/model.js +20 -0
  30. package/src/encryption/agile-constants.d.ts +61 -0
  31. package/src/encryption/agile-constants.js +71 -0
  32. package/src/encryption/agile-encryption-info.d.ts +46 -0
  33. package/src/encryption/agile-encryption-info.js +333 -0
  34. package/src/encryption/agile-password.d.ts +8 -0
  35. package/src/encryption/agile-password.js +58 -0
  36. package/src/encryption/cfb-reader.d.ts +11 -0
  37. package/src/encryption/cfb-reader.js +345 -0
  38. package/src/encryption/crypto-primitives.d.ts +74 -0
  39. package/src/encryption/crypto-primitives.js +302 -0
  40. package/src/encryption/decrypt-encrypted-package.d.ts +16 -0
  41. package/src/encryption/decrypt-encrypted-package.js +138 -0
  42. package/src/encryption/encryption-info-xml.d.ts +21 -0
  43. package/src/encryption/encryption-info-xml.js +282 -0
  44. package/src/encryption/errors.d.ts +66 -0
  45. package/src/encryption/errors.js +124 -0
  46. package/src/encryption/index.d.ts +35 -0
  47. package/src/encryption/index.js +100 -0
  48. package/src/features/diagrams/constants.d.ts +83 -0
  49. package/src/features/diagrams/constants.js +101 -0
  50. package/src/features/diagrams/diagram-data-model.d.ts +148 -0
  51. package/src/features/diagrams/diagram-data-model.js +446 -0
  52. package/src/features/diagrams/diagram-parsers.d.ts +28 -0
  53. package/src/features/diagrams/diagram-parsers.js +182 -0
  54. package/src/features/diagrams/diagram-serializers.d.ts +20 -0
  55. package/src/features/diagrams/diagram-serializers.js +110 -0
  56. package/src/features/diagrams/diagram-views.d.ts +60 -0
  57. package/src/features/diagrams/diagram-views.js +213 -0
  58. package/src/features/diagrams/element-tree.d.ts +55 -0
  59. package/src/features/diagrams/element-tree.js +197 -0
  60. package/src/features/diagrams/errors.d.ts +17 -0
  61. package/src/features/diagrams/errors.js +59 -0
  62. package/src/features/diagrams/index.d.ts +17 -0
  63. package/src/features/diagrams/index.js +17 -0
  64. package/src/features/diagrams/smart-art-catalog.d.ts +107 -0
  65. package/src/features/diagrams/smart-art-catalog.js +422 -0
  66. package/src/features/diagrams/smart-art-diagram.d.ts +96 -0
  67. package/src/features/diagrams/smart-art-diagram.js +258 -0
  68. package/src/features/index.d.ts +11 -0
  69. package/src/features/index.js +11 -0
  70. package/src/features/ink/constants.d.ts +54 -0
  71. package/src/features/ink/constants.js +54 -0
  72. package/src/features/ink/index.d.ts +18 -0
  73. package/src/features/ink/index.js +15 -0
  74. package/src/features/ink/ink-effects.d.ts +35 -0
  75. package/src/features/ink/ink-effects.js +45 -0
  76. package/src/features/ink/ink-model.d.ts +237 -0
  77. package/src/features/ink/ink-model.js +406 -0
  78. package/src/features/ink/ink-parser.d.ts +59 -0
  79. package/src/features/ink/ink-parser.js +671 -0
  80. package/src/features/ink/ink-serializer.d.ts +16 -0
  81. package/src/features/ink/ink-serializer.js +281 -0
  82. package/src/features/ink/ink-units.d.ts +33 -0
  83. package/src/features/ink/ink-units.js +92 -0
  84. package/src/features/ink/ink-xml.d.ts +26 -0
  85. package/src/features/ink/ink-xml.js +165 -0
  86. package/src/features/ink/trace-codec.d.ts +127 -0
  87. package/src/features/ink/trace-codec.js +266 -0
  88. package/src/features/mathml/constants.d.ts +47 -0
  89. package/src/features/mathml/constants.js +47 -0
  90. package/src/features/mathml/errors.d.ts +50 -0
  91. package/src/features/mathml/errors.js +69 -0
  92. package/src/features/mathml/index.d.ts +30 -0
  93. package/src/features/mathml/index.js +22 -0
  94. package/src/features/mathml/math-factory.d.ts +26 -0
  95. package/src/features/mathml/math-factory.js +568 -0
  96. package/src/features/mathml/model/controls.d.ts +896 -0
  97. package/src/features/mathml/model/controls.js +1541 -0
  98. package/src/features/mathml/model/enums.d.ts +153 -0
  99. package/src/features/mathml/model/enums.js +133 -0
  100. package/src/features/mathml/model/math-element.d.ts +173 -0
  101. package/src/features/mathml/model/math-element.js +315 -0
  102. package/src/features/mathml/model/roots.d.ts +82 -0
  103. package/src/features/mathml/model/roots.js +177 -0
  104. package/src/features/mathml/openxml.d.ts +56 -0
  105. package/src/features/mathml/openxml.js +87 -0
  106. package/src/features/mathml/parse/math-parser.d.ts +43 -0
  107. package/src/features/mathml/parse/math-parser.js +636 -0
  108. package/src/features/mathml/serialize/math-serializer.d.ts +34 -0
  109. package/src/features/mathml/serialize/math-serializer.js +749 -0
  110. package/src/features/smart-art/diagram-xml.d.ts +63 -0
  111. package/src/features/smart-art/diagram-xml.js +459 -0
  112. package/src/features/smart-art/errors.d.ts +24 -0
  113. package/src/features/smart-art/errors.js +47 -0
  114. package/src/features/smart-art/index.d.ts +26 -0
  115. package/src/features/smart-art/index.js +26 -0
  116. package/src/features/smart-art/minimal-samples.d.ts +18 -0
  117. package/src/features/smart-art/minimal-samples.js +40 -0
  118. package/src/features/smart-art/mutators.d.ts +60 -0
  119. package/src/features/smart-art/mutators.js +566 -0
  120. package/src/features/smart-art/namespaces.d.ts +153 -0
  121. package/src/features/smart-art/namespaces.js +163 -0
  122. package/src/features/smart-art/package-graph.d.ts +61 -0
  123. package/src/features/smart-art/package-graph.js +413 -0
  124. package/src/features/smart-art/parse-colors.d.ts +19 -0
  125. package/src/features/smart-art/parse-colors.js +39 -0
  126. package/src/features/smart-art/parse-data.d.ts +21 -0
  127. package/src/features/smart-art/parse-data.js +121 -0
  128. package/src/features/smart-art/parse-layout.d.ts +20 -0
  129. package/src/features/smart-art/parse-layout.js +40 -0
  130. package/src/features/smart-art/parse-rel-ids.d.ts +71 -0
  131. package/src/features/smart-art/parse-rel-ids.js +233 -0
  132. package/src/features/smart-art/parse-style.d.ts +19 -0
  133. package/src/features/smart-art/parse-style.js +39 -0
  134. package/src/features/smart-art/point-text.d.ts +80 -0
  135. package/src/features/smart-art/point-text.js +424 -0
  136. package/src/features/smart-art/register.d.ts +33 -0
  137. package/src/features/smart-art/register.js +95 -0
  138. package/src/features/smart-art/serialize.d.ts +40 -0
  139. package/src/features/smart-art/serialize.js +48 -0
  140. package/src/features/smart-art/types.d.ts +403 -0
  141. package/src/features/smart-art/types.js +28 -0
  142. package/src/global.js +1 -0
  143. package/src/index.d.ts +21 -0
  144. package/src/index.js +22 -0
  145. package/tsconfig.build.json +13 -0
  146. package/tsconfig.harness.json +32 -0
  147. package/tslint.json +111 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Built-in minimal diagram part XML seeds for {@link createDiagramInstance}.
3
+ *
4
+ * @remarks
5
+ * Documented sample only — not a layout catalog. Roots match Transitional
6
+ * `dml-diagram.xsd` (`dataModel`, `layoutDef`, `colorsDef`, `styleDef`).
7
+ * ECMA-376 Part 1 §14.2.3–14.2.6.
8
+ *
9
+ * @private
10
+ */
11
+ /** Minimal `dgm:dataModel` with required `ptLst` (doc + one node). */
12
+ export var MINIMAL_DIAGRAM_DATA_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
13
+ '<dgm:dataModel xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"' +
14
+ ' xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">' +
15
+ '<dgm:ptLst>' +
16
+ '<dgm:pt modelId="{00000000-0000-0000-0000-000000000001}" type="doc"/>' +
17
+ '<dgm:pt modelId="{00000000-0000-0000-0000-000000000002}"/>' +
18
+ '</dgm:ptLst>' +
19
+ '</dgm:dataModel>';
20
+ /** Minimal `dgm:layoutDef` with title/desc. */
21
+ export var MINIMAL_DIAGRAM_LAYOUT_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
22
+ '<dgm:layoutDef xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"' +
23
+ ' uniqueId="urn:@syncfusion/ej2-office-common:sample:layout">' +
24
+ '<dgm:title lang="" val="Sample Layout"/>' +
25
+ '<dgm:desc lang="" val="Built-in minimal layoutDef"/>' +
26
+ '</dgm:layoutDef>';
27
+ /** Minimal `dgm:colorsDef`. */
28
+ export var MINIMAL_DIAGRAM_COLORS_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
29
+ '<dgm:colorsDef xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"' +
30
+ ' uniqueId="urn:@syncfusion/ej2-office-common:sample:colors">' +
31
+ '<dgm:title lang="" val="Sample Colors"/>' +
32
+ '<dgm:desc lang="" val="Built-in minimal colorsDef"/>' +
33
+ '</dgm:colorsDef>';
34
+ /** Minimal `dgm:styleDef`. */
35
+ export var MINIMAL_DIAGRAM_STYLE_XML = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
36
+ '<dgm:styleDef xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram"' +
37
+ ' uniqueId="urn:@syncfusion/ej2-office-common:sample:style">' +
38
+ '<dgm:title lang="" val="Sample Style"/>' +
39
+ '<dgm:desc lang="" val="Built-in minimal styleDef"/>' +
40
+ '</dgm:styleDef>';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Create / remove DrawingML diagram instances on a host-neutral package graph.
3
+ *
4
+ * @remarks
5
+ * - {@link createDiagramInstance}: factory per API-RULES R1.6 (not a banned
6
+ * content `add*` verb). Add algorithm in the SmartArt technical spec.
7
+ * - {@link removeDiagramInstance}: content `remove*` verb (R1.1). Remove
8
+ * algorithm: delete four owned diagram parts, drop package-graph relationships
9
+ * targeting or sourced from those parts, and GC image targets from the Data
10
+ * part only when reference count across the graph becomes zero (Part 1 §14.2.4).
11
+ *
12
+ * Host must remove graphic-frame / `dgm:relIds` markup; this module never imports
13
+ * PPT/Word/Excel product types.
14
+ *
15
+ * Citations: ECMA-376 Part 1 §14.2.3–14.2.6; Part 4 §12.2.3–12.2.6;
16
+ * Part 4 Transitional `relationships/image`; `dml-diagram.xsd` `CT_RelIds`.
17
+ *
18
+ * @public
19
+ */
20
+ import { CreateDiagramInstanceOptions, CreateDiagramInstanceResult, DiagramPackageGraph, RemoveDiagramInstanceOptions, RemoveDiagramInstanceResult } from './types';
21
+ /**
22
+ * Creates a new diagram instance: four package parts (exactly one of each type),
23
+ * optional source relationships, and a graphic-frame hook DTO.
24
+ *
25
+ * @param graph - Existing host-neutral package graph (not mutated).
26
+ * @param options - Seeds, optional source part name, optional part name prefix.
27
+ * @returns Updated graph, bound instance, and hook for host markup.
28
+ * @throws {DiagramPartError} When any seed is empty or fails parse — before writing parts.
29
+ *
30
+ * @public
31
+ */
32
+ export declare function createDiagramInstance(graph: DiagramPackageGraph, options?: CreateDiagramInstanceOptions): CreateDiagramInstanceResult;
33
+ /**
34
+ * Removes a diagram instance from a host-neutral package graph.
35
+ *
36
+ * @remarks
37
+ * Implements the Remove algorithm in `docs/specs/smart-art-shared-common.md`:
38
+ * 1. Resolve four owned diagram part names (from `instance` and/or id matchers).
39
+ * 2. Collect Data-part outbound {@link OFFICE_IMAGE_RELATIONSHIP_TYPE} targets;
40
+ * delete image parts only when no remaining graph relationship (outside the
41
+ * deleted diagram parts) still references them (Part 1 §14.2.4).
42
+ * 3. Delete the four diagram parts (content-type entries travel with parts on
43
+ * this host-neutral graph).
44
+ * 4. Delete relationships that target any removed part, or whose source is one
45
+ * of the four diagram parts.
46
+ * 5. Host graphic-frame / `dgm:relIds` XML cleanup remains the host’s duty.
47
+ *
48
+ * Unknown instance id throws {@link DiagramPartError} (explicit mutate policy).
49
+ * Input `graph` is never mutated. Part names that do not carry diagram content
50
+ * types are refused (forged-id safety).
51
+ *
52
+ * @param graph - Current package graph (not mutated).
53
+ * @param options - Instance handle and/or id / dataPartName matchers.
54
+ * @returns Updated graph and list of removed part names.
55
+ * @throws {DiagramPartError} When matchers are missing, the instance is unknown,
56
+ * or claimed part names are not owned diagram parts.
57
+ *
58
+ * @public
59
+ */
60
+ export declare function removeDiagramInstance(graph: DiagramPackageGraph, options: RemoveDiagramInstanceOptions): RemoveDiagramInstanceResult;
@@ -0,0 +1,566 @@
1
+ /**
2
+ * Create / remove DrawingML diagram instances on a host-neutral package graph.
3
+ *
4
+ * @remarks
5
+ * - {@link createDiagramInstance}: factory per API-RULES R1.6 (not a banned
6
+ * content `add*` verb). Add algorithm in the SmartArt technical spec.
7
+ * - {@link removeDiagramInstance}: content `remove*` verb (R1.1). Remove
8
+ * algorithm: delete four owned diagram parts, drop package-graph relationships
9
+ * targeting or sourced from those parts, and GC image targets from the Data
10
+ * part only when reference count across the graph becomes zero (Part 1 §14.2.4).
11
+ *
12
+ * Host must remove graphic-frame / `dgm:relIds` markup; this module never imports
13
+ * PPT/Word/Excel product types.
14
+ *
15
+ * Citations: ECMA-376 Part 1 §14.2.3–14.2.6; Part 4 §12.2.3–12.2.6;
16
+ * Part 4 Transitional `relationships/image`; `dml-diagram.xsd` `CT_RelIds`.
17
+ *
18
+ * @public
19
+ */
20
+ var __values = (this && this.__values) || function (o) {
21
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
22
+ if (m) return m.call(o);
23
+ return {
24
+ next: function () {
25
+ if (o && i >= o.length) o = void 0;
26
+ return { value: o && o[i++], done: !o };
27
+ }
28
+ };
29
+ };
30
+ var __read = (this && this.__read) || function (o, n) {
31
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
32
+ if (!m) return o;
33
+ var i = m.call(o), r, ar = [], e;
34
+ try {
35
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
36
+ }
37
+ catch (error) { e = { error: error }; }
38
+ finally {
39
+ try {
40
+ if (r && !r.done && (m = i["return"])) m.call(i);
41
+ }
42
+ finally { if (e) throw e.error; }
43
+ }
44
+ return ar;
45
+ };
46
+ var __spread = (this && this.__spread) || function () {
47
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
48
+ return ar;
49
+ };
50
+ import { DiagramPartError } from './errors';
51
+ import { MINIMAL_DIAGRAM_COLORS_XML, MINIMAL_DIAGRAM_DATA_XML, MINIMAL_DIAGRAM_LAYOUT_XML, MINIMAL_DIAGRAM_STYLE_XML } from './minimal-samples';
52
+ import { DIAGRAM_COLORS_CONTENT_TYPE, DIAGRAM_COLORS_RELATIONSHIP_TYPE, DIAGRAM_DATA_CONTENT_TYPE, DIAGRAM_DATA_RELATIONSHIP_TYPE, DIAGRAM_GRAPHIC_DATA_URI, DIAGRAM_LAYOUT_CONTENT_TYPE, DIAGRAM_LAYOUT_RELATIONSHIP_TYPE, DIAGRAM_QUICK_STYLE_RELATIONSHIP_TYPE, DIAGRAM_STYLE_CONTENT_TYPE, OFFICE_IMAGE_RELATIONSHIP_TYPE } from './namespaces';
53
+ import { getDiagramInstance, normalizePartName } from './package-graph';
54
+ import { parseDiagramColors } from './parse-colors';
55
+ import { parseDiagramData } from './parse-data';
56
+ import { parseDiagramLayout } from './parse-layout';
57
+ import { parseDiagramStyle } from './parse-style';
58
+ var DEFAULT_PART_PREFIX = '/diagrams';
59
+ function requireNonEmptyXml(label, xml, fallback) {
60
+ if (xml === undefined) {
61
+ return fallback;
62
+ }
63
+ if (xml.trim().length === 0) {
64
+ throw new DiagramPartError("createDiagramInstance: seeds." + label + " must be non-empty XML when provided");
65
+ }
66
+ return xml;
67
+ }
68
+ function resolveSeeds(seeds) {
69
+ var s = seeds != null ? seeds : {};
70
+ return {
71
+ dataXml: requireNonEmptyXml('dataXml', s.dataXml, MINIMAL_DIAGRAM_DATA_XML),
72
+ layoutXml: requireNonEmptyXml('layoutXml', s.layoutXml, MINIMAL_DIAGRAM_LAYOUT_XML),
73
+ colorsXml: requireNonEmptyXml('colorsXml', s.colorsXml, MINIMAL_DIAGRAM_COLORS_XML),
74
+ styleXml: requireNonEmptyXml('styleXml', s.styleXml, MINIMAL_DIAGRAM_STYLE_XML)
75
+ };
76
+ }
77
+ function parseValidatedSeeds(resolved) {
78
+ // Parse before any graph mutation — incomplete seeds must not write parts.
79
+ var data;
80
+ var layout;
81
+ var colors;
82
+ var style;
83
+ try {
84
+ data = parseDiagramData(resolved.dataXml);
85
+ }
86
+ catch (e) {
87
+ var msg = e instanceof Error ? e.message : String(e);
88
+ throw new DiagramPartError("createDiagramInstance: invalid data seed: " + msg);
89
+ }
90
+ try {
91
+ layout = parseDiagramLayout(resolved.layoutXml);
92
+ }
93
+ catch (e) {
94
+ var msg = e instanceof Error ? e.message : String(e);
95
+ throw new DiagramPartError("createDiagramInstance: invalid layout seed: " + msg);
96
+ }
97
+ try {
98
+ colors = parseDiagramColors(resolved.colorsXml);
99
+ }
100
+ catch (e) {
101
+ var msg = e instanceof Error ? e.message : String(e);
102
+ throw new DiagramPartError("createDiagramInstance: invalid colors seed: " + msg);
103
+ }
104
+ try {
105
+ style = parseDiagramStyle(resolved.styleXml);
106
+ }
107
+ catch (e) {
108
+ var msg = e instanceof Error ? e.message : String(e);
109
+ throw new DiagramPartError("createDiagramInstance: invalid style seed: " + msg);
110
+ }
111
+ return {
112
+ data: data,
113
+ layout: layout,
114
+ colors: colors,
115
+ style: style,
116
+ dataXml: resolved.dataXml,
117
+ layoutXml: resolved.layoutXml,
118
+ colorsXml: resolved.colorsXml,
119
+ styleXml: resolved.styleXml
120
+ };
121
+ }
122
+ function occupiedPartNames(parts) {
123
+ var e_1, _a;
124
+ var set = new Set();
125
+ try {
126
+ for (var parts_1 = __values(parts), parts_1_1 = parts_1.next(); !parts_1_1.done; parts_1_1 = parts_1.next()) {
127
+ var p = parts_1_1.value;
128
+ set.add(normalizePartName(p.name));
129
+ }
130
+ }
131
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
132
+ finally {
133
+ try {
134
+ if (parts_1_1 && !parts_1_1.done && (_a = parts_1.return)) _a.call(parts_1);
135
+ }
136
+ finally { if (e_1) throw e_1.error; }
137
+ }
138
+ return set;
139
+ }
140
+ function normalizePrefix(prefix) {
141
+ var raw = prefix === undefined || prefix.trim().length === 0 ? DEFAULT_PART_PREFIX : prefix;
142
+ var p = normalizePartName(raw);
143
+ // Drop trailing slash for join consistency (normalizePartName keeps leading /).
144
+ if (p.length > 1 && p.endsWith('/')) {
145
+ p = p.slice(0, -1);
146
+ }
147
+ return p;
148
+ }
149
+ function allocatePartNames(existing, prefix) {
150
+ var n = 1;
151
+ for (;;) {
152
+ var suffix = String(n);
153
+ var data = prefix + "/data" + suffix + ".xml";
154
+ var layout = prefix + "/layout" + suffix + ".xml";
155
+ var colors = prefix + "/colors" + suffix + ".xml";
156
+ var style = prefix + "/quickStyle" + suffix + ".xml";
157
+ if (!existing.has(data) && !existing.has(layout) && !existing.has(colors) && !existing.has(style)) {
158
+ return {
159
+ data: data,
160
+ layout: layout,
161
+ colors: colors,
162
+ style: style
163
+ };
164
+ }
165
+ n += 1;
166
+ if (n > 1000000) {
167
+ throw new DiagramPartError('createDiagramInstance: could not allocate unique part names');
168
+ }
169
+ }
170
+ }
171
+ /**
172
+ * Collect relationship ids already used from a given source (and globally when
173
+ * source is empty — still avoid id collisions in the graph slice).
174
+ */
175
+ function usedRelationshipIds(relationships, sourceNorm) {
176
+ var e_2, _a, e_3, _b;
177
+ var used = new Set();
178
+ try {
179
+ for (var relationships_1 = __values(relationships), relationships_1_1 = relationships_1.next(); !relationships_1_1.done; relationships_1_1 = relationships_1.next()) {
180
+ var rel = relationships_1_1.value;
181
+ if (sourceNorm !== undefined) {
182
+ if (normalizePartName(rel.source) !== sourceNorm) {
183
+ continue;
184
+ }
185
+ }
186
+ used.add(rel.id);
187
+ }
188
+ }
189
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
190
+ finally {
191
+ try {
192
+ if (relationships_1_1 && !relationships_1_1.done && (_a = relationships_1.return)) _a.call(relationships_1);
193
+ }
194
+ finally { if (e_2) throw e_2.error; }
195
+ }
196
+ try {
197
+ // Also avoid any id already present in the graph (OPC ids are unique per .rels).
198
+ for (var relationships_2 = __values(relationships), relationships_2_1 = relationships_2.next(); !relationships_2_1.done; relationships_2_1 = relationships_2.next()) {
199
+ var rel = relationships_2_1.value;
200
+ used.add(rel.id);
201
+ }
202
+ }
203
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
204
+ finally {
205
+ try {
206
+ if (relationships_2_1 && !relationships_2_1.done && (_b = relationships_2.return)) _b.call(relationships_2);
207
+ }
208
+ finally { if (e_3) throw e_3.error; }
209
+ }
210
+ return used;
211
+ }
212
+ function allocateRelIds(used) {
213
+ var n = 1;
214
+ var take = function () {
215
+ for (;;) {
216
+ var id = "rId" + String(n);
217
+ n += 1;
218
+ if (!used.has(id)) {
219
+ used.add(id);
220
+ return id;
221
+ }
222
+ if (n > 1000000) {
223
+ throw new DiagramPartError('createDiagramInstance: could not allocate relationship ids');
224
+ }
225
+ }
226
+ };
227
+ return {
228
+ dm: take(),
229
+ lo: take(),
230
+ qs: take(),
231
+ cs: take()
232
+ };
233
+ }
234
+ /**
235
+ * Creates a new diagram instance: four package parts (exactly one of each type),
236
+ * optional source relationships, and a graphic-frame hook DTO.
237
+ *
238
+ * @param graph - Existing host-neutral package graph (not mutated).
239
+ * @param options - Seeds, optional source part name, optional part name prefix.
240
+ * @returns Updated graph, bound instance, and hook for host markup.
241
+ * @throws {DiagramPartError} When any seed is empty or fails parse — before writing parts.
242
+ *
243
+ * @public
244
+ */
245
+ export function createDiagramInstance(graph, options) {
246
+ if (options === void 0) { options = {}; }
247
+ var resolved = resolveSeeds(options.seeds);
248
+ var parsed = parseValidatedSeeds(resolved);
249
+ var prefix = normalizePrefix(options.partNamePrefix);
250
+ var occupied = occupiedPartNames(graph.parts);
251
+ var partNames = allocatePartNames(occupied, prefix);
252
+ var sourceRaw = (options.sourcePartName == null ? void 0 : options.sourcePartName.trim());
253
+ var sourcePartName = sourceRaw !== undefined && sourceRaw.length > 0 ? normalizePartName(sourceRaw) : '';
254
+ var usedIds = usedRelationshipIds(graph.relationships, sourcePartName.length > 0 ? sourcePartName : undefined);
255
+ var relIds = allocateRelIds(usedIds);
256
+ var newParts = [{
257
+ name: partNames.data,
258
+ contentType: DIAGRAM_DATA_CONTENT_TYPE,
259
+ xml: parsed.dataXml
260
+ }, {
261
+ name: partNames.layout,
262
+ contentType: DIAGRAM_LAYOUT_CONTENT_TYPE,
263
+ xml: parsed.layoutXml
264
+ }, {
265
+ name: partNames.colors,
266
+ contentType: DIAGRAM_COLORS_CONTENT_TYPE,
267
+ xml: parsed.colorsXml
268
+ }, {
269
+ name: partNames.style,
270
+ contentType: DIAGRAM_STYLE_CONTENT_TYPE,
271
+ xml: parsed.styleXml
272
+ }];
273
+ var newRels = [];
274
+ if (sourcePartName.length > 0) {
275
+ newRels.push({
276
+ id: relIds.dm,
277
+ type: DIAGRAM_DATA_RELATIONSHIP_TYPE,
278
+ target: partNames.data,
279
+ source: sourcePartName
280
+ }, {
281
+ id: relIds.lo,
282
+ type: DIAGRAM_LAYOUT_RELATIONSHIP_TYPE,
283
+ target: partNames.layout,
284
+ source: sourcePartName
285
+ }, {
286
+ id: relIds.qs,
287
+ type: DIAGRAM_QUICK_STYLE_RELATIONSHIP_TYPE,
288
+ target: partNames.style,
289
+ source: sourcePartName
290
+ }, {
291
+ id: relIds.cs,
292
+ type: DIAGRAM_COLORS_RELATIONSHIP_TYPE,
293
+ target: partNames.colors,
294
+ source: sourcePartName
295
+ });
296
+ }
297
+ var nextGraph = {
298
+ parts: __spread(graph.parts, newParts),
299
+ relationships: __spread(graph.relationships, newRels)
300
+ };
301
+ var instance = {
302
+ id: partNames.data,
303
+ data: parsed.data,
304
+ layout: parsed.layout,
305
+ colors: parsed.colors,
306
+ style: parsed.style,
307
+ relIds: relIds,
308
+ partNames: partNames,
309
+ sourcePartName: sourcePartName
310
+ };
311
+ return {
312
+ graph: nextGraph,
313
+ instance: instance,
314
+ hook: {
315
+ graphicDataUri: DIAGRAM_GRAPHIC_DATA_URI,
316
+ relIds: relIds
317
+ }
318
+ };
319
+ }
320
+ function partNamesSet(names) {
321
+ return new Set([normalizePartName(names.data), normalizePartName(names.layout), normalizePartName(names.colors), normalizePartName(names.style)]);
322
+ }
323
+ /**
324
+ * Validates that each claimed diagram part exists with a diagram content type.
325
+ * Rejects forged ids that would delete non-diagram package parts.
326
+ */
327
+ function requireOwnedDiagramParts(graph, names) {
328
+ var e_4, _a, e_5, _b;
329
+ var byName = new Map();
330
+ try {
331
+ for (var _c = __values(graph.parts), _d = _c.next(); !_d.done; _d = _c.next()) {
332
+ var part = _d.value;
333
+ byName.set(normalizePartName(part.name), part);
334
+ }
335
+ }
336
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
337
+ finally {
338
+ try {
339
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
340
+ }
341
+ finally { if (e_4) throw e_4.error; }
342
+ }
343
+ var roles = [{
344
+ role: 'data',
345
+ name: names.data,
346
+ expected: DIAGRAM_DATA_CONTENT_TYPE
347
+ }, {
348
+ role: 'layout',
349
+ name: names.layout,
350
+ expected: DIAGRAM_LAYOUT_CONTENT_TYPE
351
+ }, {
352
+ role: 'colors',
353
+ name: names.colors,
354
+ expected: DIAGRAM_COLORS_CONTENT_TYPE
355
+ }, {
356
+ role: 'style',
357
+ name: names.style,
358
+ expected: DIAGRAM_STYLE_CONTENT_TYPE
359
+ }];
360
+ var resolved = {};
361
+ try {
362
+ for (var roles_1 = __values(roles), roles_1_1 = roles_1.next(); !roles_1_1.done; roles_1_1 = roles_1.next()) {
363
+ var _e = roles_1_1.value, role = _e.role, name_1 = _e.name, expected = _e.expected;
364
+ var key = normalizePartName(name_1);
365
+ var part = byName.get(key);
366
+ if (part === undefined) {
367
+ throw new DiagramPartError("removeDiagramInstance: diagram " + role + " part not found: " + key);
368
+ }
369
+ if (part.contentType !== expected) {
370
+ throw new DiagramPartError("removeDiagramInstance: refused to delete non-diagram part " + key + " " + ("(content type " + part.contentType + ", expected " + expected + ")"));
371
+ }
372
+ resolved[role] = key;
373
+ }
374
+ }
375
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
376
+ finally {
377
+ try {
378
+ if (roles_1_1 && !roles_1_1.done && (_b = roles_1.return)) _b.call(roles_1);
379
+ }
380
+ finally { if (e_5) throw e_5.error; }
381
+ }
382
+ var data = resolved.data;
383
+ var layout = resolved.layout;
384
+ var colors = resolved.colors;
385
+ var style = resolved.style;
386
+ if (data === undefined || layout === undefined || colors === undefined || style === undefined) {
387
+ throw new DiagramPartError('removeDiagramInstance: incomplete diagram part set');
388
+ }
389
+ return {
390
+ data: data,
391
+ layout: layout,
392
+ colors: colors,
393
+ style: style
394
+ };
395
+ }
396
+ function resolveInstanceForRemove(graph, options) {
397
+ var hasInstance = options.instance !== undefined;
398
+ var idRaw = (options.id == null ? void 0 : options.id.trim());
399
+ var dataRaw = (options.dataPartName == null ? void 0 : options.dataPartName.trim());
400
+ var hasId = idRaw !== undefined && idRaw.length > 0;
401
+ var hasData = dataRaw !== undefined && dataRaw.length > 0;
402
+ if (!hasInstance && !hasId && !hasData) {
403
+ throw new DiagramPartError('removeDiagramInstance requires options.instance and/or options.id and/or options.dataPartName');
404
+ }
405
+ if (hasInstance) {
406
+ var inst = options.instance;
407
+ // Prefer live graph binding when id/data matchers are also supplied.
408
+ if (hasId || hasData) {
409
+ var lookup_1 = {};
410
+ if (hasId) {
411
+ lookup_1.id = idRaw;
412
+ }
413
+ lookup_1.dataPartName = hasData ? dataRaw : inst.partNames.data;
414
+ var found_1 = getDiagramInstance(graph, lookup_1);
415
+ if (found_1 === undefined) {
416
+ throw new DiagramPartError('removeDiagramInstance: no diagram instance matches the given id/dataPartName');
417
+ }
418
+ if (normalizePartName(found_1.partNames.data) !== normalizePartName(inst.partNames.data)) {
419
+ throw new DiagramPartError('removeDiagramInstance: options.instance does not match id/dataPartName');
420
+ }
421
+ return requireOwnedDiagramParts(graph, found_1.partNames);
422
+ }
423
+ return requireOwnedDiagramParts(graph, inst.partNames);
424
+ }
425
+ var lookup = {};
426
+ if (hasId) {
427
+ lookup.id = idRaw;
428
+ }
429
+ if (hasData) {
430
+ lookup.dataPartName = dataRaw;
431
+ }
432
+ var found = getDiagramInstance(graph, lookup);
433
+ if (found === undefined) {
434
+ throw new DiagramPartError('removeDiagramInstance: unknown diagram instance (no match for id/dataPartName)');
435
+ }
436
+ return requireOwnedDiagramParts(graph, found.partNames);
437
+ }
438
+ /**
439
+ * Image part names referenced only from the Data part’s outbound image rels
440
+ * that should be deleted after the Data part is removed (ref-count → 0).
441
+ */
442
+ function exclusiveImageTargets(relationships, dataPartName, diagramParts) {
443
+ var e_6, _a, e_7, _b, e_8, _c;
444
+ var dataKey = normalizePartName(dataPartName);
445
+ var candidates = new Set();
446
+ try {
447
+ for (var relationships_3 = __values(relationships), relationships_3_1 = relationships_3.next(); !relationships_3_1.done; relationships_3_1 = relationships_3.next()) {
448
+ var rel = relationships_3_1.value;
449
+ if (rel.type !== OFFICE_IMAGE_RELATIONSHIP_TYPE) {
450
+ continue;
451
+ }
452
+ if (normalizePartName(rel.source) !== dataKey) {
453
+ continue;
454
+ }
455
+ var target = normalizePartName(rel.target);
456
+ // Never treat a diagram part name as an image GC target.
457
+ if (diagramParts.has(target)) {
458
+ continue;
459
+ }
460
+ candidates.add(target);
461
+ }
462
+ }
463
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
464
+ finally {
465
+ try {
466
+ if (relationships_3_1 && !relationships_3_1.done && (_a = relationships_3.return)) _a.call(relationships_3);
467
+ }
468
+ finally { if (e_6) throw e_6.error; }
469
+ }
470
+ var exclusive = [];
471
+ try {
472
+ for (var candidates_1 = __values(candidates), candidates_1_1 = candidates_1.next(); !candidates_1_1.done; candidates_1_1 = candidates_1.next()) {
473
+ var target = candidates_1_1.value;
474
+ // After Data-part (and other deleted diagram) outbound edges are dropped,
475
+ // count surviving image edges from sources outside the deleted set.
476
+ var surviving = 0;
477
+ try {
478
+ for (var relationships_4 = __values(relationships), relationships_4_1 = relationships_4.next(); !relationships_4_1.done; relationships_4_1 = relationships_4.next()) {
479
+ var rel = relationships_4_1.value;
480
+ if (rel.type !== OFFICE_IMAGE_RELATIONSHIP_TYPE) {
481
+ continue;
482
+ }
483
+ if (normalizePartName(rel.target) !== target) {
484
+ continue;
485
+ }
486
+ var src = normalizePartName(rel.source);
487
+ if (src === dataKey || diagramParts.has(src)) {
488
+ continue;
489
+ }
490
+ surviving += 1;
491
+ }
492
+ }
493
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
494
+ finally {
495
+ try {
496
+ if (relationships_4_1 && !relationships_4_1.done && (_c = relationships_4.return)) _c.call(relationships_4);
497
+ }
498
+ finally { if (e_8) throw e_8.error; }
499
+ }
500
+ if (surviving === 0) {
501
+ exclusive.push(target);
502
+ }
503
+ }
504
+ }
505
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
506
+ finally {
507
+ try {
508
+ if (candidates_1_1 && !candidates_1_1.done && (_b = candidates_1.return)) _b.call(candidates_1);
509
+ }
510
+ finally { if (e_7) throw e_7.error; }
511
+ }
512
+ return exclusive;
513
+ }
514
+ /**
515
+ * Removes a diagram instance from a host-neutral package graph.
516
+ *
517
+ * @remarks
518
+ * Implements the Remove algorithm in `docs/specs/smart-art-shared-common.md`:
519
+ * 1. Resolve four owned diagram part names (from `instance` and/or id matchers).
520
+ * 2. Collect Data-part outbound {@link OFFICE_IMAGE_RELATIONSHIP_TYPE} targets;
521
+ * delete image parts only when no remaining graph relationship (outside the
522
+ * deleted diagram parts) still references them (Part 1 §14.2.4).
523
+ * 3. Delete the four diagram parts (content-type entries travel with parts on
524
+ * this host-neutral graph).
525
+ * 4. Delete relationships that target any removed part, or whose source is one
526
+ * of the four diagram parts.
527
+ * 5. Host graphic-frame / `dgm:relIds` XML cleanup remains the host’s duty.
528
+ *
529
+ * Unknown instance id throws {@link DiagramPartError} (explicit mutate policy).
530
+ * Input `graph` is never mutated. Part names that do not carry diagram content
531
+ * types are refused (forged-id safety).
532
+ *
533
+ * @param graph - Current package graph (not mutated).
534
+ * @param options - Instance handle and/or id / dataPartName matchers.
535
+ * @returns Updated graph and list of removed part names.
536
+ * @throws {DiagramPartError} When matchers are missing, the instance is unknown,
537
+ * or claimed part names are not owned diagram parts.
538
+ *
539
+ * @public
540
+ */
541
+ export function removeDiagramInstance(graph, options) {
542
+ var partNames = resolveInstanceForRemove(graph, options);
543
+ var diagramParts = partNamesSet(partNames);
544
+ var imageGc = exclusiveImageTargets(graph.relationships, partNames.data, diagramParts);
545
+ var removeParts = new Set(__spread(diagramParts, imageGc));
546
+ var nextParts = graph.parts.filter(function (p) { return !removeParts.has(normalizePartName(p.name)); });
547
+ var nextRels = graph.relationships.filter(function (r) {
548
+ var src = normalizePartName(r.source);
549
+ var tgt = normalizePartName(r.target);
550
+ if (removeParts.has(tgt)) {
551
+ return false;
552
+ }
553
+ if (diagramParts.has(src)) {
554
+ return false;
555
+ }
556
+ return true;
557
+ });
558
+ var removedPartNames = __spread(removeParts).sort(function (a, b) { return a.localeCompare(b); });
559
+ return {
560
+ graph: {
561
+ parts: nextParts,
562
+ relationships: nextRels
563
+ },
564
+ removedPartNames: removedPartNames
565
+ };
566
+ }