@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,281 @@
1
+ /**
2
+ * {@link OfficeInk} → InkML element tree serializer ([MS-ODRAWXML] §2.1.4).
3
+ *
4
+ * Trace text is always {@link encodeTrace} from points — never stored XML text.
5
+ * Brush property order matches `docs/specs/ink-shared-codec.md` / TASK-9003.
6
+ */
7
+ var __values = (this && this.__values) || function (o) {
8
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
9
+ if (m) return m.call(o);
10
+ return {
11
+ next: function () {
12
+ if (o && i >= o.length) o = void 0;
13
+ return { value: o && o[i++], done: !o };
14
+ }
15
+ };
16
+ };
17
+ var __read = (this && this.__read) || function (o, n) {
18
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
19
+ if (!m) return o;
20
+ var i = m.call(o), r, ar = [], e;
21
+ try {
22
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
+ }
24
+ catch (error) { e = { error: error }; }
25
+ finally {
26
+ try {
27
+ if (r && !r.done && (m = i["return"])) m.call(i);
28
+ }
29
+ finally { if (e) throw e.error; }
30
+ }
31
+ return ar;
32
+ };
33
+ var __spread = (this && this.__spread) || function () {
34
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
35
+ return ar;
36
+ };
37
+ import { isOfficeInk } from './ink-model';
38
+ import { inkEffectColor } from './ink-effects';
39
+ import { formatUnitValue, pointsToUnit } from './ink-units';
40
+ import { attr, inkElement, inkmlNamespaceDecl, textNode, xmlIdAttr, } from './ink-xml';
41
+ import { encodeTrace } from './trace-codec';
42
+ var DEFAULT_CONTEXT_ID = 'ctx0';
43
+ var DEFAULT_CONTEXT_REF = '#ctx0';
44
+ var DEFAULT_INK_SOURCE_ID = 'inkSrc0';
45
+ var CHANNEL_MIN = '-2.14748E9';
46
+ var CHANNEL_MAX = '2.14748E9';
47
+ var CHANNEL_UNITS = 'cm';
48
+ /**
49
+ * Serialize an {@link OfficeInk} DOM to an InkML `ink` root element.
50
+ *
51
+ * Source: [MS-ODRAWXML] §2.1.4; `docs/specs/ink-shared-codec.md` Serializer behavior.
52
+ *
53
+ * @private
54
+ */
55
+ export function serializeInkXml(ink) {
56
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
57
+ if (!isOfficeInk(ink)) {
58
+ throw new TypeError('serializeInkXml: expected OfficeInk from parseInkXml/createInk');
59
+ }
60
+ var children = [];
61
+ var definitionsChildren = [];
62
+ var needsContext = ink.traces.some(function (t) { return t.contextRef === DEFAULT_CONTEXT_REF || t.contextRef === '' || t.contextRef === "#" + DEFAULT_CONTEXT_ID; }) || ink.traces.length > 0;
63
+ var contexts = (ink.contexts != null ? ink.contexts : []);
64
+ // Emit each known context; ensure default #ctx0 when referenced/needed
65
+ var hasDefaultContext = false;
66
+ try {
67
+ for (var contexts_1 = __values(contexts), contexts_1_1 = contexts_1.next(); !contexts_1_1.done; contexts_1_1 = contexts_1.next()) {
68
+ var ctx = contexts_1_1.value;
69
+ definitionsChildren.push(serializeContext(ctx));
70
+ var bare = stripHash(ctx.id);
71
+ if (bare === DEFAULT_CONTEXT_ID) {
72
+ hasDefaultContext = true;
73
+ }
74
+ }
75
+ }
76
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
77
+ finally {
78
+ try {
79
+ if (contexts_1_1 && !contexts_1_1.done && (_a = contexts_1.return)) _a.call(contexts_1);
80
+ }
81
+ finally { if (e_1) throw e_1.error; }
82
+ }
83
+ if (needsContext && !hasDefaultContext) {
84
+ definitionsChildren.push(serializeContext(defaultContext()));
85
+ }
86
+ // Brushes sorted by id (string key order)
87
+ var sortedBrushes = __spread(ink.brushes).sort(function (a, b) { return (a.id < b.id ? -1 : a.id > b.id ? 1 : 0); });
88
+ try {
89
+ for (var sortedBrushes_1 = __values(sortedBrushes), sortedBrushes_1_1 = sortedBrushes_1.next(); !sortedBrushes_1_1.done; sortedBrushes_1_1 = sortedBrushes_1.next()) {
90
+ var brush = sortedBrushes_1_1.value;
91
+ definitionsChildren.push(serializeBrush(brush));
92
+ }
93
+ }
94
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
95
+ finally {
96
+ try {
97
+ if (sortedBrushes_1_1 && !sortedBrushes_1_1.done && (_b = sortedBrushes_1.return)) _b.call(sortedBrushes_1);
98
+ }
99
+ finally { if (e_2) throw e_2.error; }
100
+ }
101
+ if (definitionsChildren.length > 0) {
102
+ children.push(inkElement('definitions', [], definitionsChildren));
103
+ }
104
+ // Traces / groups
105
+ if (ink.traceTree !== undefined && ink.traceTree.length > 0) {
106
+ try {
107
+ for (var _e = __values(ink.traceTree), _f = _e.next(); !_f.done; _f = _e.next()) {
108
+ var node = _f.value;
109
+ children.push.apply(children, __spread(serializeTreeNode(node, ink.traces)));
110
+ }
111
+ }
112
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
113
+ finally {
114
+ try {
115
+ if (_f && !_f.done && (_c = _e.return)) _c.call(_e);
116
+ }
117
+ finally { if (e_3) throw e_3.error; }
118
+ }
119
+ }
120
+ else {
121
+ try {
122
+ for (var _g = __values(ink.traces), _h = _g.next(); !_h.done; _h = _g.next()) {
123
+ var trace = _h.value;
124
+ children.push(serializeTrace(trace));
125
+ }
126
+ }
127
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
128
+ finally {
129
+ try {
130
+ if (_h && !_h.done && (_d = _g.return)) _d.call(_g);
131
+ }
132
+ finally { if (e_4) throw e_4.error; }
133
+ }
134
+ }
135
+ return inkElement('ink', [], children, [inkmlNamespaceDecl()]);
136
+ }
137
+ function defaultContext() {
138
+ return {
139
+ id: DEFAULT_CONTEXT_REF,
140
+ inkSourceId: DEFAULT_INK_SOURCE_ID,
141
+ channels: [
142
+ {
143
+ name: 'X',
144
+ type: 'integer',
145
+ min: CHANNEL_MIN,
146
+ max: CHANNEL_MAX,
147
+ units: CHANNEL_UNITS,
148
+ },
149
+ {
150
+ name: 'Y',
151
+ type: 'integer',
152
+ min: CHANNEL_MIN,
153
+ max: CHANNEL_MAX,
154
+ units: CHANNEL_UNITS,
155
+ },
156
+ ],
157
+ };
158
+ }
159
+ function serializeContext(ctx) {
160
+ var idBare = stripHash(ctx.id);
161
+ var inkSourceId = stripHash((ctx.inkSourceId != null ? ctx.inkSourceId : DEFAULT_INK_SOURCE_ID));
162
+ var channels = ctx.channels.length > 0
163
+ ? ctx.channels
164
+ : defaultContext().channels;
165
+ var channelEls = channels.map(function (ch) { return serializeChannel(ch); });
166
+ var traceFormat = inkElement('traceFormat', [], channelEls);
167
+ var inkSource = inkElement('inkSource', [xmlIdAttr(inkSourceId)], [traceFormat]);
168
+ return inkElement('context', [xmlIdAttr(idBare)], [inkSource]);
169
+ }
170
+ function serializeChannel(ch) {
171
+ var attrs = [attr('name', ch.name)];
172
+ if (ch.type !== undefined) {
173
+ attrs.push(attr('type', ch.type));
174
+ }
175
+ if (ch.min !== undefined) {
176
+ attrs.push(attr('min', ch.min));
177
+ }
178
+ if (ch.max !== undefined) {
179
+ attrs.push(attr('max', ch.max));
180
+ }
181
+ if (ch.units !== undefined) {
182
+ attrs.push(attr('units', ch.units));
183
+ }
184
+ return inkElement('channel', attrs, []);
185
+ }
186
+ function serializeBrush(brush) {
187
+ var idBare = stripHash(brush.id);
188
+ var props = [];
189
+ var units = brush.units.length > 0 ? brush.units : 'cm';
190
+ // Size is stored in points after parse; authoring may use pt units with pt values.
191
+ // ConvertPointsToUnit always treats size as points → target units.
192
+ var widthOut = pointsToUnit(brush.size.width, units);
193
+ var heightOut = pointsToUnit(brush.size.height, units);
194
+ props.push(brushProperty('width', formatUnitValue(widthOut), units), brushProperty('height', formatUnitValue(heightOut), units));
195
+ var color = resolveBrushColor(brush);
196
+ props.push(brushProperty('color', color.startsWith('#') ? color : "#" + color));
197
+ // Effect-specific series (TASK-9003 / shared-codec)
198
+ // Always emit ignorePressure. Non-none effects emit inkEffects so parse→serialize→parse
199
+ // preserves the effect token (including pencil, which has no color override).
200
+ var effect = brush.inkEffect;
201
+ props.push(brushProperty('ignorePressure', brush.ignorePressure ? '1' : '0'));
202
+ if (effect !== 'pencil' && brush.rasterOp !== undefined && brush.rasterOp.length > 0) {
203
+ props.push(brushProperty('tip', (brush.tip != null ? brush.tip : 'ellipse')));
204
+ props.push(brushProperty('rasterOp', brush.rasterOp));
205
+ }
206
+ if (effect !== 'none') {
207
+ props.push(brushProperty('inkEffects', effectToken(effect)));
208
+ if (effect !== 'pencil') {
209
+ props.push(brushProperty('anchorX', (brush.anchorX != null ? brush.anchorX : '0')));
210
+ props.push(brushProperty('anchorY', (brush.anchorY != null ? brush.anchorY : '0')));
211
+ props.push(brushProperty('scaleFactor', (brush.scaleFactor != null ? brush.scaleFactor : '0.5')));
212
+ }
213
+ }
214
+ return inkElement('brush', [xmlIdAttr(idBare)], props);
215
+ }
216
+ function brushProperty(name, value, units) {
217
+ var attrs = [attr('name', name), attr('value', value)];
218
+ if (units !== undefined) {
219
+ attrs.push(attr('units', units));
220
+ }
221
+ return inkElement('brushProperty', attrs, []);
222
+ }
223
+ function resolveBrushColor(brush) {
224
+ var effectHex = inkEffectColor(brush.inkEffect);
225
+ if (effectHex !== undefined) {
226
+ return effectHex.toUpperCase();
227
+ }
228
+ return brush.color.toUpperCase();
229
+ }
230
+ function effectToken(effect) {
231
+ // Prefer camelCase for roseGold (spec token); others lowercase
232
+ if (effect === 'roseGold') {
233
+ return 'roseGold';
234
+ }
235
+ return effect;
236
+ }
237
+ function serializeTreeNode(node, traces) {
238
+ var e_5, _a;
239
+ if (node.kind === 'trace') {
240
+ var t = traces[node.traceIndex];
241
+ if (t === undefined) {
242
+ return [];
243
+ }
244
+ return [serializeTrace(t)];
245
+ }
246
+ var kids = [];
247
+ try {
248
+ for (var _b = __values(node.children), _c = _b.next(); !_c.done; _c = _b.next()) {
249
+ var child = _c.value;
250
+ kids.push.apply(kids, __spread(serializeTreeNode(child, traces)));
251
+ }
252
+ }
253
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
254
+ finally {
255
+ try {
256
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
257
+ }
258
+ finally { if (e_5) throw e_5.error; }
259
+ }
260
+ return [inkElement('traceGroup', [], kids)];
261
+ }
262
+ function serializeTrace(trace) {
263
+ var attrs = [];
264
+ var contextRef = trace.contextRef.length > 0 ? ensureHash(trace.contextRef) : DEFAULT_CONTEXT_REF;
265
+ attrs.push(attr('contextRef', contextRef));
266
+ if (trace.brushRef.length > 0) {
267
+ attrs.push(attr('brushRef', ensureHash(trace.brushRef)));
268
+ }
269
+ if (trace.timeOffset !== undefined) {
270
+ attrs.push(attr('timeOffset', trace.timeOffset));
271
+ }
272
+ var text = encodeTrace(trace.points);
273
+ var children = text.length > 0 ? [textNode(text)] : [];
274
+ return inkElement('trace', attrs, children);
275
+ }
276
+ function stripHash(id) {
277
+ return id.startsWith('#') ? id.slice(1) : id;
278
+ }
279
+ function ensureHash(id) {
280
+ return id.startsWith('#') ? id : "#" + id;
281
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Length unit conversion for ink brush width/height.
3
+ *
4
+ * Formulas match Compression.Base `OfficeParser.GetPointValue` (unit→pt) and
5
+ * `OfficeSerializer.ConvertPointsToUnit` (pt→unit). EMU factor: 12700 EMU/pt
6
+ * (DrawingML).
7
+ */
8
+ /**
9
+ * DrawingML EMUs per point (OfficeParser / OfficeSerializer).
10
+ *
11
+ * @public
12
+ */
13
+ export declare const EMUS_PER_POINT = 12700;
14
+ /**
15
+ * Convert a numeric length in `units` to points.
16
+ * Result is rounded to 2 decimal places (GetPointValue parity).
17
+ *
18
+ * @public
19
+ */
20
+ export declare function unitValueToPoints(value: number, units: string | undefined): number;
21
+ /**
22
+ * Convert points to the target unit (ConvertPointsToUnit).
23
+ * Default / unknown unit → cm.
24
+ *
25
+ * @public
26
+ */
27
+ export declare function pointsToUnit(points: number, units: string | undefined): number;
28
+ /**
29
+ * Format a unit magnitude with invariant 3-decimal style (`"0.###"`).
30
+ *
31
+ * @public
32
+ */
33
+ export declare function formatUnitValue(value: number): string;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Length unit conversion for ink brush width/height.
3
+ *
4
+ * Formulas match Compression.Base `OfficeParser.GetPointValue` (unit→pt) and
5
+ * `OfficeSerializer.ConvertPointsToUnit` (pt→unit). EMU factor: 12700 EMU/pt
6
+ * (DrawingML).
7
+ */
8
+ /**
9
+ * DrawingML EMUs per point (OfficeParser / OfficeSerializer).
10
+ *
11
+ * @public
12
+ */
13
+ export var EMUS_PER_POINT = 12700;
14
+ /**
15
+ * Convert a numeric length in `units` to points.
16
+ * Result is rounded to 2 decimal places (GetPointValue parity).
17
+ *
18
+ * @public
19
+ */
20
+ export function unitValueToPoints(value, units) {
21
+ var u = ((units != null ? units : 'cm')).trim().toLowerCase();
22
+ var points;
23
+ switch (u) {
24
+ case 'pt':
25
+ points = value;
26
+ break;
27
+ case 'mm':
28
+ points = (value / 25.4) * 72;
29
+ break;
30
+ case 'px':
31
+ points = (value / 4) * 3;
32
+ break;
33
+ case 'in':
34
+ points = value * 72;
35
+ break;
36
+ case 'cm':
37
+ points = (value / 2.54) * 72;
38
+ break;
39
+ case 'emu':
40
+ points = value / EMUS_PER_POINT;
41
+ break;
42
+ default:
43
+ // Unknown unit: treat as EMU-less raw → cm (GetPointValue else branch uses EMU)
44
+ points = value / EMUS_PER_POINT;
45
+ break;
46
+ }
47
+ return round2(points);
48
+ }
49
+ /**
50
+ * Convert points to the target unit (ConvertPointsToUnit).
51
+ * Default / unknown unit → cm.
52
+ *
53
+ * @public
54
+ */
55
+ export function pointsToUnit(points, units) {
56
+ var u = ((units != null ? units : 'cm')).trim().toLowerCase();
57
+ switch (u) {
58
+ case 'pt':
59
+ return points;
60
+ case 'mm':
61
+ return (points * 25.4) / 72;
62
+ case 'px':
63
+ return (points * 96) / 72;
64
+ case 'in':
65
+ return points / 72;
66
+ case 'cm':
67
+ return (points * 2.54) / 72;
68
+ case 'emu':
69
+ return points * EMUS_PER_POINT;
70
+ default:
71
+ return (points * 2.54) / 72;
72
+ }
73
+ }
74
+ /**
75
+ * Format a unit magnitude with invariant 3-decimal style (`"0.###"`).
76
+ *
77
+ * @public
78
+ */
79
+ export function formatUnitValue(value) {
80
+ if (!Number.isFinite(value)) {
81
+ return '0';
82
+ }
83
+ // Trim trailing zeros after up to 3 decimal places (InvariantCulture "0.###").
84
+ var fixed = value.toFixed(3);
85
+ if (!(fixed.indexOf('.') !== -1)) {
86
+ return fixed;
87
+ }
88
+ return fixed.replace(/\.?0+$/, '');
89
+ }
90
+ function round2(n) {
91
+ return Math.round(n * 100) / 100;
92
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Small OpenXml element helpers scoped to InkML serialization.
3
+ */
4
+ import { NamespaceDeclaration, OpenXmlAttribute, OpenXmlChild, OpenXmlElement, OpenXmlText } from '../../core/xml/model';
5
+ import { XML_NAMESPACE, XMLNS_NAMESPACE } from '../../core/xml/model';
6
+ import { INKML_NAMESPACE } from './constants';
7
+ declare const INK_PREFIX = "inkml";
8
+ /** Build an InkML-namespaced element. */
9
+ export declare function inkElement(localName: string, attributes?: ReadonlyArray<OpenXmlAttribute>, children?: ReadonlyArray<OpenXmlChild>, namespaceDeclarations?: ReadonlyArray<NamespaceDeclaration>): OpenXmlElement;
10
+ /** Plain attribute (no namespace). */
11
+ export declare function attr(localName: string, value: string): OpenXmlAttribute;
12
+ /** `xml:id` attribute. */
13
+ export declare function xmlIdAttr(id: string): OpenXmlAttribute;
14
+ /** Text node. */
15
+ export declare function textNode(value: string): OpenXmlText;
16
+ /** `xmlns:inkml` declaration for the ink root. */
17
+ export declare function inkmlNamespaceDecl(): NamespaceDeclaration;
18
+ /** Read attribute by local name (optional namespace filter). */
19
+ export declare function getAttr(el: OpenXmlElement, localName: string, namespaceUri?: string): string | undefined;
20
+ /** Concatenate descendant text of an element. */
21
+ export declare function elementText(el: OpenXmlElement): string;
22
+ /** Direct element children in document order (optional namespace filter). */
23
+ export declare function elementChildren(el: OpenXmlElement, localName?: string, namespaceUri?: string): OpenXmlElement[];
24
+ /** Whether an element is in the InkML namespace (or un-namespaced fixture). */
25
+ export declare function isInkMlElement(el: OpenXmlElement): boolean;
26
+ export { XML_NAMESPACE, XMLNS_NAMESPACE, INKML_NAMESPACE, INK_PREFIX };
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Small OpenXml element helpers scoped to InkML serialization.
3
+ */
4
+ var __values = (this && this.__values) || function (o) {
5
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
6
+ if (m) return m.call(o);
7
+ return {
8
+ next: function () {
9
+ if (o && i >= o.length) o = void 0;
10
+ return { value: o && o[i++], done: !o };
11
+ }
12
+ };
13
+ };
14
+ import { XML_NAMESPACE, XMLNS_NAMESPACE } from '../../core/xml/model';
15
+ import { INKML_NAMESPACE } from './constants';
16
+ var INK_PREFIX = 'inkml';
17
+ /** Build an InkML-namespaced element. */
18
+ export function inkElement(localName, attributes, children, namespaceDeclarations) {
19
+ if (attributes === void 0) { attributes = []; }
20
+ if (children === void 0) { children = []; }
21
+ if (namespaceDeclarations === void 0) { namespaceDeclarations = []; }
22
+ return { kind: 'element',
23
+ namespaceUri: INKML_NAMESPACE,
24
+ localName: localName,
25
+ prefix: INK_PREFIX,
26
+ attributes: attributes,
27
+ namespaceDeclarations: namespaceDeclarations,
28
+ children: children,
29
+ };
30
+ }
31
+ /** Plain attribute (no namespace). */
32
+ export function attr(localName, value) {
33
+ return { namespaceUri: '', localName: localName, prefix: '', value: value };
34
+ }
35
+ /** `xml:id` attribute. */
36
+ export function xmlIdAttr(id) {
37
+ return {
38
+ namespaceUri: XML_NAMESPACE,
39
+ localName: 'id',
40
+ prefix: 'xml',
41
+ value: id,
42
+ };
43
+ }
44
+ /** Text node. */
45
+ export function textNode(value) {
46
+ return { kind: 'text', value: value };
47
+ }
48
+ /** `xmlns:inkml` declaration for the ink root. */
49
+ export function inkmlNamespaceDecl() {
50
+ return { prefix: INK_PREFIX, namespaceUri: INKML_NAMESPACE };
51
+ }
52
+ /** Read attribute by local name (optional namespace filter). */
53
+ export function getAttr(el, localName, namespaceUri) {
54
+ var e_1, _a, e_2, _b;
55
+ try {
56
+ for (var _c = __values(el.attributes), _d = _c.next(); !_d.done; _d = _c.next()) {
57
+ var a = _d.value;
58
+ if (a.localName !== localName) {
59
+ continue;
60
+ }
61
+ if (namespaceUri !== undefined && a.namespaceUri !== namespaceUri) {
62
+ continue;
63
+ }
64
+ return a.value;
65
+ }
66
+ }
67
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
68
+ finally {
69
+ try {
70
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
71
+ }
72
+ finally { if (e_1) throw e_1.error; }
73
+ }
74
+ // xml:id may appear as prefixed without namespace resolution in hand-built trees
75
+ if (localName === 'id') {
76
+ try {
77
+ for (var _e = __values(el.attributes), _f = _e.next(); !_f.done; _f = _e.next()) {
78
+ var a = _f.value;
79
+ if (a.localName === 'id' && (a.prefix === 'xml' || a.namespaceUri === XML_NAMESPACE)) {
80
+ return a.value;
81
+ }
82
+ }
83
+ }
84
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
85
+ finally {
86
+ try {
87
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
88
+ }
89
+ finally { if (e_2) throw e_2.error; }
90
+ }
91
+ }
92
+ return undefined;
93
+ }
94
+ /** Concatenate descendant text of an element. */
95
+ export function elementText(el) {
96
+ var e_3, _a;
97
+ var out = '';
98
+ try {
99
+ for (var _b = __values(el.children), _c = _b.next(); !_c.done; _c = _b.next()) {
100
+ var child = _c.value;
101
+ if (child.kind === 'text') {
102
+ out += child.value;
103
+ }
104
+ else {
105
+ out += elementText(child);
106
+ }
107
+ }
108
+ }
109
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
110
+ finally {
111
+ try {
112
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
113
+ }
114
+ finally { if (e_3) throw e_3.error; }
115
+ }
116
+ return out;
117
+ }
118
+ /** Direct element children in document order (optional namespace filter). */
119
+ export function elementChildren(el, localName, namespaceUri) {
120
+ if (namespaceUri === void 0) { namespaceUri = INKML_NAMESPACE; }
121
+ var e_4, _a;
122
+ var result = [];
123
+ try {
124
+ for (var _b = __values(el.children), _c = _b.next(); !_c.done; _c = _b.next()) {
125
+ var child = _c.value;
126
+ if (child.kind !== 'element') {
127
+ continue;
128
+ }
129
+ if (namespaceUri !== '' && child.namespaceUri !== namespaceUri && child.namespaceUri !== '') {
130
+ // Allow empty namespaceUri for hand-built / defaulted fixtures when local names match InkML.
131
+ if (child.namespaceUri !== INKML_NAMESPACE && namespaceUri === INKML_NAMESPACE) {
132
+ // still accept un-namespaced ink fixtures if localName matches
133
+ if (localName !== undefined && child.localName !== localName) {
134
+ continue;
135
+ }
136
+ if (localName === undefined) {
137
+ // only accept if it looks like ink content (caller filters)
138
+ }
139
+ }
140
+ }
141
+ if (localName !== undefined && child.localName !== localName) {
142
+ continue;
143
+ }
144
+ if (namespaceUri === INKML_NAMESPACE &&
145
+ child.namespaceUri !== INKML_NAMESPACE &&
146
+ child.namespaceUri !== '') {
147
+ continue;
148
+ }
149
+ result.push(child);
150
+ }
151
+ }
152
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
153
+ finally {
154
+ try {
155
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
156
+ }
157
+ finally { if (e_4) throw e_4.error; }
158
+ }
159
+ return result;
160
+ }
161
+ /** Whether an element is in the InkML namespace (or un-namespaced fixture). */
162
+ export function isInkMlElement(el) {
163
+ return el.namespaceUri === INKML_NAMESPACE || el.namespaceUri === '';
164
+ }
165
+ export { XML_NAMESPACE, XMLNS_NAMESPACE, INKML_NAMESPACE, INK_PREFIX };