@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.
- package/.eslintrc.json +263 -0
- package/.prettierrc.json +5 -0
- package/README.md +167 -0
- package/api-extractor.json +35 -0
- package/core.js +4 -0
- package/dist/ej2-office-common.umd.min.js +11 -0
- package/dist/ej2-office-common.umd.min.js.map +1 -0
- package/dist/es6/ej2-office-common.es2015.js +6585 -0
- package/dist/es6/ej2-office-common.es2015.js.map +1 -0
- package/dist/es6/ej2-office-common.es5.js +7955 -0
- package/dist/es6/ej2-office-common.es5.js.map +1 -0
- package/dist/global/ej2-office-common.min.js +11 -0
- package/dist/global/ej2-office-common.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/encryption.js +4 -0
- package/features.js +4 -0
- package/global.json +6 -0
- package/index.js +4 -0
- package/license +10 -0
- package/nuget.config +7 -0
- package/package.json +23 -0
- package/src/all.d.ts +41 -0
- package/src/all.js +38 -0
- package/src/core/index.d.ts +6 -0
- package/src/core/index.js +6 -0
- package/src/core/xml/index.d.ts +7 -0
- package/src/core/xml/index.js +6 -0
- package/src/core/xml/model.d.ts +71 -0
- package/src/core/xml/model.js +20 -0
- package/src/encryption/agile-constants.d.ts +61 -0
- package/src/encryption/agile-constants.js +71 -0
- package/src/encryption/agile-encryption-info.d.ts +46 -0
- package/src/encryption/agile-encryption-info.js +333 -0
- package/src/encryption/agile-password.d.ts +8 -0
- package/src/encryption/agile-password.js +58 -0
- package/src/encryption/cfb-reader.d.ts +11 -0
- package/src/encryption/cfb-reader.js +345 -0
- package/src/encryption/crypto-primitives.d.ts +74 -0
- package/src/encryption/crypto-primitives.js +302 -0
- package/src/encryption/decrypt-encrypted-package.d.ts +16 -0
- package/src/encryption/decrypt-encrypted-package.js +138 -0
- package/src/encryption/encryption-info-xml.d.ts +21 -0
- package/src/encryption/encryption-info-xml.js +282 -0
- package/src/encryption/errors.d.ts +66 -0
- package/src/encryption/errors.js +124 -0
- package/src/encryption/index.d.ts +35 -0
- package/src/encryption/index.js +100 -0
- package/src/features/diagrams/constants.d.ts +83 -0
- package/src/features/diagrams/constants.js +101 -0
- package/src/features/diagrams/diagram-data-model.d.ts +148 -0
- package/src/features/diagrams/diagram-data-model.js +446 -0
- package/src/features/diagrams/diagram-parsers.d.ts +28 -0
- package/src/features/diagrams/diagram-parsers.js +182 -0
- package/src/features/diagrams/diagram-serializers.d.ts +20 -0
- package/src/features/diagrams/diagram-serializers.js +110 -0
- package/src/features/diagrams/diagram-views.d.ts +60 -0
- package/src/features/diagrams/diagram-views.js +213 -0
- package/src/features/diagrams/element-tree.d.ts +55 -0
- package/src/features/diagrams/element-tree.js +197 -0
- package/src/features/diagrams/errors.d.ts +17 -0
- package/src/features/diagrams/errors.js +59 -0
- package/src/features/diagrams/index.d.ts +17 -0
- package/src/features/diagrams/index.js +17 -0
- package/src/features/diagrams/smart-art-catalog.d.ts +107 -0
- package/src/features/diagrams/smart-art-catalog.js +422 -0
- package/src/features/diagrams/smart-art-diagram.d.ts +96 -0
- package/src/features/diagrams/smart-art-diagram.js +258 -0
- package/src/features/index.d.ts +11 -0
- package/src/features/index.js +11 -0
- package/src/features/ink/constants.d.ts +54 -0
- package/src/features/ink/constants.js +54 -0
- package/src/features/ink/index.d.ts +18 -0
- package/src/features/ink/index.js +15 -0
- package/src/features/ink/ink-effects.d.ts +35 -0
- package/src/features/ink/ink-effects.js +45 -0
- package/src/features/ink/ink-model.d.ts +237 -0
- package/src/features/ink/ink-model.js +406 -0
- package/src/features/ink/ink-parser.d.ts +59 -0
- package/src/features/ink/ink-parser.js +671 -0
- package/src/features/ink/ink-serializer.d.ts +16 -0
- package/src/features/ink/ink-serializer.js +281 -0
- package/src/features/ink/ink-units.d.ts +33 -0
- package/src/features/ink/ink-units.js +92 -0
- package/src/features/ink/ink-xml.d.ts +26 -0
- package/src/features/ink/ink-xml.js +165 -0
- package/src/features/ink/trace-codec.d.ts +127 -0
- package/src/features/ink/trace-codec.js +266 -0
- package/src/features/mathml/constants.d.ts +47 -0
- package/src/features/mathml/constants.js +47 -0
- package/src/features/mathml/errors.d.ts +50 -0
- package/src/features/mathml/errors.js +69 -0
- package/src/features/mathml/index.d.ts +30 -0
- package/src/features/mathml/index.js +22 -0
- package/src/features/mathml/math-factory.d.ts +26 -0
- package/src/features/mathml/math-factory.js +568 -0
- package/src/features/mathml/model/controls.d.ts +896 -0
- package/src/features/mathml/model/controls.js +1541 -0
- package/src/features/mathml/model/enums.d.ts +153 -0
- package/src/features/mathml/model/enums.js +133 -0
- package/src/features/mathml/model/math-element.d.ts +173 -0
- package/src/features/mathml/model/math-element.js +315 -0
- package/src/features/mathml/model/roots.d.ts +82 -0
- package/src/features/mathml/model/roots.js +177 -0
- package/src/features/mathml/openxml.d.ts +56 -0
- package/src/features/mathml/openxml.js +87 -0
- package/src/features/mathml/parse/math-parser.d.ts +43 -0
- package/src/features/mathml/parse/math-parser.js +636 -0
- package/src/features/mathml/serialize/math-serializer.d.ts +34 -0
- package/src/features/mathml/serialize/math-serializer.js +749 -0
- package/src/features/smart-art/diagram-xml.d.ts +63 -0
- package/src/features/smart-art/diagram-xml.js +459 -0
- package/src/features/smart-art/errors.d.ts +24 -0
- package/src/features/smart-art/errors.js +47 -0
- package/src/features/smart-art/index.d.ts +26 -0
- package/src/features/smart-art/index.js +26 -0
- package/src/features/smart-art/minimal-samples.d.ts +18 -0
- package/src/features/smart-art/minimal-samples.js +40 -0
- package/src/features/smart-art/mutators.d.ts +60 -0
- package/src/features/smart-art/mutators.js +566 -0
- package/src/features/smart-art/namespaces.d.ts +153 -0
- package/src/features/smart-art/namespaces.js +163 -0
- package/src/features/smart-art/package-graph.d.ts +61 -0
- package/src/features/smart-art/package-graph.js +413 -0
- package/src/features/smart-art/parse-colors.d.ts +19 -0
- package/src/features/smart-art/parse-colors.js +39 -0
- package/src/features/smart-art/parse-data.d.ts +21 -0
- package/src/features/smart-art/parse-data.js +121 -0
- package/src/features/smart-art/parse-layout.d.ts +20 -0
- package/src/features/smart-art/parse-layout.js +40 -0
- package/src/features/smart-art/parse-rel-ids.d.ts +71 -0
- package/src/features/smart-art/parse-rel-ids.js +233 -0
- package/src/features/smart-art/parse-style.d.ts +19 -0
- package/src/features/smart-art/parse-style.js +39 -0
- package/src/features/smart-art/point-text.d.ts +80 -0
- package/src/features/smart-art/point-text.js +424 -0
- package/src/features/smart-art/register.d.ts +33 -0
- package/src/features/smart-art/register.js +95 -0
- package/src/features/smart-art/serialize.d.ts +40 -0
- package/src/features/smart-art/serialize.js +48 -0
- package/src/features/smart-art/types.d.ts +403 -0
- package/src/features/smart-art/types.js +28 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +21 -0
- package/src/index.js +22 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.harness.json +32 -0
- package/tslint.json +111 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ink DOM model and authoring API (office-common).
|
|
3
|
+
*
|
|
4
|
+
* Contract: `docs/specs/ink-shared-codec.md` / cross-repo
|
|
5
|
+
* `ej2-docx/docs/specs/ink-dom-parse-serialize.md` § Internal semantic model,
|
|
6
|
+
* § Mutation behavior.
|
|
7
|
+
*
|
|
8
|
+
* Trace-group decision (TASK-9002): `OfficeInk.traces` is flat document-order.
|
|
9
|
+
* Nested `traceGroup` structure is reserved for TASK-9003 via an optional
|
|
10
|
+
* internal ordered tree field (`traceTree`) that 9003 may populate; when
|
|
11
|
+
* absent, serialize emits a flat sequence of traces. Consumers of 9002 only
|
|
12
|
+
* see the flat `traces` array.
|
|
13
|
+
*/
|
|
14
|
+
import { InkPoint } from './trace-codec';
|
|
15
|
+
import { computeInkBounds } from './trace-codec';
|
|
16
|
+
/**
|
|
17
|
+
* Visual effect applied to an ink stroke.
|
|
18
|
+
*
|
|
19
|
+
* Source: [MS-ODRAWXML] ink effect tokens + cross-repo effect→color table.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare type InkEffectType = 'none' | 'pencil' | 'rainbow' | 'galaxy' | 'lava' | 'ocean' | 'roseGold' | 'gold' | 'silver' | 'bronze';
|
|
24
|
+
/**
|
|
25
|
+
* A single ink stroke with decoded plane points and brush/context references.
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
export interface InkTrace {
|
|
30
|
+
/** Decoded plane coordinates in document trace order. */
|
|
31
|
+
readonly points: ReadonlyArray<InkPoint>;
|
|
32
|
+
/** Brush reference key (for example `"#br0"`). */
|
|
33
|
+
readonly brushRef: string;
|
|
34
|
+
/** Context reference key (for example `"#ctx0"`). */
|
|
35
|
+
readonly contextRef: string;
|
|
36
|
+
/** Optional time-offset attribute preserved when present on the source. */
|
|
37
|
+
readonly timeOffset?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Channel definition under a context trace format ([MS-ODRAWXML] §2.1.4).
|
|
41
|
+
*
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
export interface InkChannel {
|
|
45
|
+
/** Channel name token such as `X` or `Y`. */
|
|
46
|
+
readonly name: string;
|
|
47
|
+
/** Optional channel value type such as `integer` or `decimal`. */
|
|
48
|
+
readonly type?: string;
|
|
49
|
+
/** Optional minimum value as the authored string. */
|
|
50
|
+
readonly min?: string;
|
|
51
|
+
/** Optional maximum value as the authored string. */
|
|
52
|
+
readonly max?: string;
|
|
53
|
+
/** Optional units token such as `cm` or `dev`. */
|
|
54
|
+
readonly units?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* InkML context under definitions, including channels and optional ink source id.
|
|
58
|
+
*
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
export interface InkContext {
|
|
62
|
+
/** Context key (for example `"#ctx0"`). */
|
|
63
|
+
readonly id: string;
|
|
64
|
+
/** Optional inkSource `@xml:id`, normalized with or without a leading `#` on write. */
|
|
65
|
+
readonly inkSourceId?: string;
|
|
66
|
+
/** Ordered channel definitions for this context. */
|
|
67
|
+
readonly channels: ReadonlyArray<InkChannel>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Brush settings used to render ink strokes.
|
|
71
|
+
*
|
|
72
|
+
* Authoring defaults: color `#000000`, size `1.42pt × 1.42pt`, units `'pt'`,
|
|
73
|
+
* effect `'none'`, and `ignorePressure` `true`. Parse-time [MS-ODRAWXML] §2.1.4
|
|
74
|
+
* defaults (width `.053 cm`, height `.001 cm`, tip `ellipse`, rasterOp `copyPen`)
|
|
75
|
+
* apply during parse, not createInk authoring.
|
|
76
|
+
*
|
|
77
|
+
* After parse, size values are stored in **points** with `units` retained for
|
|
78
|
+
* re-emit. After authoring, size values use the brush `units` (default `pt`).
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
export interface InkBrush {
|
|
83
|
+
/** Stroke color in `#RRGGBB` form. Default is black (`#000000`). */
|
|
84
|
+
color: string;
|
|
85
|
+
/**
|
|
86
|
+
* Brush width and height.
|
|
87
|
+
* After parse: values are in points.
|
|
88
|
+
* After authoring (`createInk` / `addInkTrace`): values use `units` (default `pt`).
|
|
89
|
+
*/
|
|
90
|
+
size: {
|
|
91
|
+
width: number;
|
|
92
|
+
height: number;
|
|
93
|
+
};
|
|
94
|
+
/** Length unit key (`cm`, `mm`, `pt`, `px`, `in`, or `emu`). Default is `pt`. */
|
|
95
|
+
units: string;
|
|
96
|
+
/** Visual ink effect. Default is `'none'`. */
|
|
97
|
+
inkEffect: InkEffectType;
|
|
98
|
+
/** Optional pen tip token such as `ellipse` or `rectangle`, or a preserved value. */
|
|
99
|
+
tip?: string;
|
|
100
|
+
/** Optional raster operation token from [MS-ODRAWXML] §2.1.4. */
|
|
101
|
+
rasterOp?: string;
|
|
102
|
+
/** When true, pressure channel input is ignored. Authoring default is `true`. */
|
|
103
|
+
ignorePressure: boolean;
|
|
104
|
+
/** Optional effect texture horizontal anchor for authored strokes. */
|
|
105
|
+
anchorX?: string;
|
|
106
|
+
/** Optional effect texture vertical anchor for authored strokes. */
|
|
107
|
+
anchorY?: string;
|
|
108
|
+
/** Optional effect texture scale factor for authored strokes. */
|
|
109
|
+
scaleFactor?: string;
|
|
110
|
+
/** Optional transparency from 0 through 1 when present as a brush property. */
|
|
111
|
+
transparency?: number;
|
|
112
|
+
/** Optional anti-alias flag when present as a brush property. */
|
|
113
|
+
antiAliased?: boolean;
|
|
114
|
+
/** Optional fit-to-curve flag when present as a brush property. */
|
|
115
|
+
fitToCurve?: boolean;
|
|
116
|
+
/** Brush key on the owning ink object (for example `"#br0"`). */
|
|
117
|
+
readonly id: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Optional nesting node for TASK-9003 group preservation.
|
|
121
|
+
* 9002 keeps this internal / absent for authored ink.
|
|
122
|
+
*
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
export declare type InkTraceTreeNode = {
|
|
126
|
+
readonly kind: 'trace';
|
|
127
|
+
readonly traceIndex: number;
|
|
128
|
+
} | {
|
|
129
|
+
readonly kind: 'group';
|
|
130
|
+
readonly children: ReadonlyArray<InkTraceTreeNode>;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* One InkML part: ordered traces + brush table.
|
|
134
|
+
*
|
|
135
|
+
* @public
|
|
136
|
+
*/
|
|
137
|
+
export interface OfficeInk {
|
|
138
|
+
/**
|
|
139
|
+
* Ordered traces in document order (root-level and, flattened, from groups).
|
|
140
|
+
*/
|
|
141
|
+
readonly traces: ReadonlyArray<InkTrace>;
|
|
142
|
+
/** Brush table; ids are `"#br{N}"`-style keys. */
|
|
143
|
+
readonly brushes: ReadonlyArray<InkBrush>;
|
|
144
|
+
/**
|
|
145
|
+
* Parsed contexts under `definitions` (TASK-9003). When empty/undefined,
|
|
146
|
+
* serializer emits the default `#ctx0` channel set when needed.
|
|
147
|
+
*
|
|
148
|
+
* @public
|
|
149
|
+
*/
|
|
150
|
+
readonly contexts?: ReadonlyArray<InkContext>;
|
|
151
|
+
/**
|
|
152
|
+
* Optional nested group tree for TASK-9003. When undefined, traces are a
|
|
153
|
+
* flat sequence. Not part of the public authoring surface for 9002.
|
|
154
|
+
*
|
|
155
|
+
* @private
|
|
156
|
+
*/
|
|
157
|
+
readonly traceTree?: ReadonlyArray<InkTraceTreeNode>;
|
|
158
|
+
/**
|
|
159
|
+
* Scale intent for {@link inkPathPoints}: `'authored'` stretch-to-fit
|
|
160
|
+
* (re-zero); `'decoded'` uniform (no re-zero). Defaults to `'authored'`
|
|
161
|
+
* for ink created via {@link createInk}.
|
|
162
|
+
*
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
readonly scaleMode?: 'authored' | 'decoded';
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Build a branded ink from parsed InkML state (`scaleMode: 'decoded'`).
|
|
169
|
+
*
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
export declare function createDecodedInk(init: {
|
|
173
|
+
traces: InkTrace[];
|
|
174
|
+
brushes: InkBrush[];
|
|
175
|
+
contexts?: InkContext[];
|
|
176
|
+
traceTree?: InkTraceTreeNode[];
|
|
177
|
+
}): OfficeInk;
|
|
178
|
+
/**
|
|
179
|
+
* Allocate a fresh, empty ink DOM for authoring.
|
|
180
|
+
*
|
|
181
|
+
* Empty traces; no brushes until the first {@link addInkTrace}. Scale mode
|
|
182
|
+
* is `'authored'` (stretch-to-fit for {@link inkPathPoints}).
|
|
183
|
+
*
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
export declare function createInk(): OfficeInk;
|
|
187
|
+
/**
|
|
188
|
+
* Add a trace to an ink DOM.
|
|
189
|
+
*
|
|
190
|
+
* Brush selection (spec mutation §):
|
|
191
|
+
* - If `brush` partial is provided, clone previous brush (or default) then
|
|
192
|
+
* apply the partial onto a **new** brush id.
|
|
193
|
+
* - Else if a previous trace exists, clone that trace's brush under a new id.
|
|
194
|
+
* - Else allocate the default black `1.42pt × 1.42pt` authored brush as `#br0`.
|
|
195
|
+
*
|
|
196
|
+
* Returns the new trace. Mutates `ink` in place (traces/brushes arrays grow).
|
|
197
|
+
*
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
export declare function addInkTrace(ink: OfficeInk, points: ReadonlyArray<{
|
|
201
|
+
readonly x: number;
|
|
202
|
+
readonly y: number;
|
|
203
|
+
}>, brush?: Partial<InkBrush>): InkTrace;
|
|
204
|
+
/**
|
|
205
|
+
* Deep-copy an ink DOM (independent traces, points, brushes, and contexts).
|
|
206
|
+
*
|
|
207
|
+
* @private
|
|
208
|
+
*/
|
|
209
|
+
export declare function cloneInk(ink: OfficeInk): OfficeInk;
|
|
210
|
+
/**
|
|
211
|
+
* Convert ink traces into plane point paths scaled to a drawing extent.
|
|
212
|
+
*
|
|
213
|
+
* Authored ink (`scaleMode === 'authored'`, default from {@link createInk})
|
|
214
|
+
* uses stretch-to-fit (re-zero). Decoded ink uses uniform scale (no re-zero).
|
|
215
|
+
* Bounds are computed over **all** points in the ink, then each path is scaled
|
|
216
|
+
* with the same transform.
|
|
217
|
+
*
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
export declare function inkPathPoints(ink: OfficeInk, extent: {
|
|
221
|
+
readonly width: number;
|
|
222
|
+
readonly height: number;
|
|
223
|
+
}): ReadonlyArray<ReadonlyArray<InkPoint>>;
|
|
224
|
+
/**
|
|
225
|
+
* Type guard for {@link OfficeInk} instances produced by this module.
|
|
226
|
+
*
|
|
227
|
+
* @private
|
|
228
|
+
*/
|
|
229
|
+
export declare function isOfficeInk(value: unknown): value is OfficeInk;
|
|
230
|
+
/**
|
|
231
|
+
* Mark an ink as authored or decoded (uniform scale path).
|
|
232
|
+
* Hosts and tests use this to select the scale mode for bounds/path computation.
|
|
233
|
+
*
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
export declare function setInkScaleMode(ink: OfficeInk, mode: 'authored' | 'decoded'): void;
|
|
237
|
+
export { computeInkBounds };
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ink DOM model and authoring API (office-common).
|
|
3
|
+
*
|
|
4
|
+
* Contract: `docs/specs/ink-shared-codec.md` / cross-repo
|
|
5
|
+
* `ej2-docx/docs/specs/ink-dom-parse-serialize.md` § Internal semantic model,
|
|
6
|
+
* § Mutation behavior.
|
|
7
|
+
*
|
|
8
|
+
* Trace-group decision (TASK-9002): `OfficeInk.traces` is flat document-order.
|
|
9
|
+
* Nested `traceGroup` structure is reserved for TASK-9003 via an optional
|
|
10
|
+
* internal ordered tree field (`traceTree`) that 9003 may populate; when
|
|
11
|
+
* absent, serialize emits a flat sequence of traces. Consumers of 9002 only
|
|
12
|
+
* see the flat `traces` array.
|
|
13
|
+
*/
|
|
14
|
+
var __assign = (this && this.__assign) || function () {
|
|
15
|
+
__assign = Object.assign || function(t) {
|
|
16
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
17
|
+
s = arguments[i];
|
|
18
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
19
|
+
t[p] = s[p];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
return __assign.apply(this, arguments);
|
|
24
|
+
};
|
|
25
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
+
if (!m) return o;
|
|
28
|
+
var i = m.call(o), r, ar = [], e;
|
|
29
|
+
try {
|
|
30
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
+
}
|
|
32
|
+
catch (error) { e = { error: error }; }
|
|
33
|
+
finally {
|
|
34
|
+
try {
|
|
35
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
+
}
|
|
37
|
+
finally { if (e) throw e.error; }
|
|
38
|
+
}
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
var __spread = (this && this.__spread) || function () {
|
|
42
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
43
|
+
return ar;
|
|
44
|
+
};
|
|
45
|
+
var __values = (this && this.__values) || function (o) {
|
|
46
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
47
|
+
if (m) return m.call(o);
|
|
48
|
+
return {
|
|
49
|
+
next: function () {
|
|
50
|
+
if (o && i >= o.length) o = void 0;
|
|
51
|
+
return { value: o && o[i++], done: !o };
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
import { computeInkBounds, scalePointsStretch, scalePointsUniform } from './trace-codec';
|
|
56
|
+
/** Marker used by {@link isOfficeInk}. */
|
|
57
|
+
var OFFICE_INK_BRAND = Symbol.for('@syncfusion/ej2-office-common.OfficeInk');
|
|
58
|
+
/** Default authored brush size (spec mutation §): 1.42pt × 1.42pt. */
|
|
59
|
+
var DEFAULT_AUTHORED_BRUSH_SIZE = 1.42;
|
|
60
|
+
var DEFAULT_AUTHORED_COLOR = '#000000';
|
|
61
|
+
var DEFAULT_AUTHORED_UNITS = 'pt';
|
|
62
|
+
var DEFAULT_CONTEXT_REF = '#ctx0';
|
|
63
|
+
function isInkEffectType(value) {
|
|
64
|
+
return (value === 'none' ||
|
|
65
|
+
value === 'pencil' ||
|
|
66
|
+
value === 'rainbow' ||
|
|
67
|
+
value === 'galaxy' ||
|
|
68
|
+
value === 'lava' ||
|
|
69
|
+
value === 'ocean' ||
|
|
70
|
+
value === 'roseGold' ||
|
|
71
|
+
value === 'gold' ||
|
|
72
|
+
value === 'silver' ||
|
|
73
|
+
value === 'bronze');
|
|
74
|
+
}
|
|
75
|
+
function cloneBrush(source, id) {
|
|
76
|
+
var next = {
|
|
77
|
+
color: source.color,
|
|
78
|
+
size: { width: source.size.width, height: source.size.height },
|
|
79
|
+
units: source.units,
|
|
80
|
+
inkEffect: source.inkEffect,
|
|
81
|
+
ignorePressure: source.ignorePressure,
|
|
82
|
+
id: id,
|
|
83
|
+
};
|
|
84
|
+
if (source.tip !== undefined) {
|
|
85
|
+
next.tip = source.tip;
|
|
86
|
+
}
|
|
87
|
+
if (source.rasterOp !== undefined) {
|
|
88
|
+
next.rasterOp = source.rasterOp;
|
|
89
|
+
}
|
|
90
|
+
if (source.anchorX !== undefined) {
|
|
91
|
+
next.anchorX = source.anchorX;
|
|
92
|
+
}
|
|
93
|
+
if (source.anchorY !== undefined) {
|
|
94
|
+
next.anchorY = source.anchorY;
|
|
95
|
+
}
|
|
96
|
+
if (source.scaleFactor !== undefined) {
|
|
97
|
+
next.scaleFactor = source.scaleFactor;
|
|
98
|
+
}
|
|
99
|
+
if (source.transparency !== undefined) {
|
|
100
|
+
next.transparency = source.transparency;
|
|
101
|
+
}
|
|
102
|
+
if (source.antiAliased !== undefined) {
|
|
103
|
+
next.antiAliased = source.antiAliased;
|
|
104
|
+
}
|
|
105
|
+
if (source.fitToCurve !== undefined) {
|
|
106
|
+
next.fitToCurve = source.fitToCurve;
|
|
107
|
+
}
|
|
108
|
+
return next;
|
|
109
|
+
}
|
|
110
|
+
function cloneContext(source) {
|
|
111
|
+
var next = {
|
|
112
|
+
id: source.id,
|
|
113
|
+
channels: source.channels.map(function (ch) {
|
|
114
|
+
var c = { name: ch.name };
|
|
115
|
+
if (ch.type !== undefined) {
|
|
116
|
+
c.type = ch.type;
|
|
117
|
+
}
|
|
118
|
+
if (ch.min !== undefined) {
|
|
119
|
+
c.min = ch.min;
|
|
120
|
+
}
|
|
121
|
+
if (ch.max !== undefined) {
|
|
122
|
+
c.max = ch.max;
|
|
123
|
+
}
|
|
124
|
+
if (ch.units !== undefined) {
|
|
125
|
+
c.units = ch.units;
|
|
126
|
+
}
|
|
127
|
+
return c;
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
if (source.inkSourceId !== undefined) {
|
|
131
|
+
next.inkSourceId = source.inkSourceId;
|
|
132
|
+
}
|
|
133
|
+
return next;
|
|
134
|
+
}
|
|
135
|
+
function defaultAuthoredBrush(id) {
|
|
136
|
+
return {
|
|
137
|
+
color: DEFAULT_AUTHORED_COLOR,
|
|
138
|
+
size: { width: DEFAULT_AUTHORED_BRUSH_SIZE, height: DEFAULT_AUTHORED_BRUSH_SIZE },
|
|
139
|
+
units: DEFAULT_AUTHORED_UNITS,
|
|
140
|
+
inkEffect: 'none',
|
|
141
|
+
ignorePressure: true,
|
|
142
|
+
id: id,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function applyBrushPartial(target, partial) {
|
|
146
|
+
if (partial.color !== undefined) {
|
|
147
|
+
target.color = partial.color;
|
|
148
|
+
}
|
|
149
|
+
if (partial.size !== undefined) {
|
|
150
|
+
target.size = {
|
|
151
|
+
width: partial.size.width,
|
|
152
|
+
height: partial.size.height,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (partial.units !== undefined) {
|
|
156
|
+
target.units = partial.units;
|
|
157
|
+
}
|
|
158
|
+
if (partial.inkEffect !== undefined && isInkEffectType(partial.inkEffect)) {
|
|
159
|
+
target.inkEffect = partial.inkEffect;
|
|
160
|
+
}
|
|
161
|
+
if (partial.ignorePressure !== undefined) {
|
|
162
|
+
target.ignorePressure = partial.ignorePressure;
|
|
163
|
+
}
|
|
164
|
+
if (partial.tip !== undefined) {
|
|
165
|
+
target.tip = partial.tip;
|
|
166
|
+
}
|
|
167
|
+
if (partial.rasterOp !== undefined) {
|
|
168
|
+
target.rasterOp = partial.rasterOp;
|
|
169
|
+
}
|
|
170
|
+
if (partial.anchorX !== undefined) {
|
|
171
|
+
target.anchorX = partial.anchorX;
|
|
172
|
+
}
|
|
173
|
+
if (partial.anchorY !== undefined) {
|
|
174
|
+
target.anchorY = partial.anchorY;
|
|
175
|
+
}
|
|
176
|
+
if (partial.scaleFactor !== undefined) {
|
|
177
|
+
target.scaleFactor = partial.scaleFactor;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Allocate the next `#br{N}` key that does not collide with existing brushes.
|
|
182
|
+
*/
|
|
183
|
+
function allocateBrushId(brushes) {
|
|
184
|
+
var used = new Set(brushes.map(function (b) { return b.id; }));
|
|
185
|
+
var n = 0;
|
|
186
|
+
for (;;) {
|
|
187
|
+
var id = "#br" + String(n);
|
|
188
|
+
if (!used.has(id)) {
|
|
189
|
+
return id;
|
|
190
|
+
}
|
|
191
|
+
n += 1;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function brandInk(ink) {
|
|
195
|
+
var internal = ink;
|
|
196
|
+
Object.defineProperty(internal, OFFICE_INK_BRAND, {
|
|
197
|
+
value: true,
|
|
198
|
+
enumerable: false,
|
|
199
|
+
configurable: false,
|
|
200
|
+
writable: false,
|
|
201
|
+
});
|
|
202
|
+
return internal;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Build a branded ink from parsed InkML state (`scaleMode: 'decoded'`).
|
|
206
|
+
*
|
|
207
|
+
* @private
|
|
208
|
+
*/
|
|
209
|
+
export function createDecodedInk(init) {
|
|
210
|
+
return brandInk(__assign({ traces: init.traces, brushes: init.brushes, scaleMode: 'decoded' }, (init.contexts !== undefined ? { contexts: init.contexts } : {}), (init.traceTree !== undefined ? { traceTree: init.traceTree } : {})));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Allocate a fresh, empty ink DOM for authoring.
|
|
214
|
+
*
|
|
215
|
+
* Empty traces; no brushes until the first {@link addInkTrace}. Scale mode
|
|
216
|
+
* is `'authored'` (stretch-to-fit for {@link inkPathPoints}).
|
|
217
|
+
*
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
export function createInk() {
|
|
221
|
+
return brandInk({
|
|
222
|
+
traces: [],
|
|
223
|
+
brushes: [],
|
|
224
|
+
scaleMode: 'authored',
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Add a trace to an ink DOM.
|
|
229
|
+
*
|
|
230
|
+
* Brush selection (spec mutation §):
|
|
231
|
+
* - If `brush` partial is provided, clone previous brush (or default) then
|
|
232
|
+
* apply the partial onto a **new** brush id.
|
|
233
|
+
* - Else if a previous trace exists, clone that trace's brush under a new id.
|
|
234
|
+
* - Else allocate the default black `1.42pt × 1.42pt` authored brush as `#br0`.
|
|
235
|
+
*
|
|
236
|
+
* Returns the new trace. Mutates `ink` in place (traces/brushes arrays grow).
|
|
237
|
+
*
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
export function addInkTrace(ink, points, brush) {
|
|
241
|
+
if (!isOfficeInk(ink)) {
|
|
242
|
+
throw new TypeError('addInkTrace: expected OfficeInk from createInk/cloneInk');
|
|
243
|
+
}
|
|
244
|
+
var internal = ink;
|
|
245
|
+
var pointCopy = points.map(function (p) { return ({ x: p.x, y: p.y }); });
|
|
246
|
+
var sourceBrush;
|
|
247
|
+
var lastTrace = internal.traces[internal.traces.length - 1];
|
|
248
|
+
if (lastTrace !== undefined) {
|
|
249
|
+
sourceBrush = internal.brushes.find(function (b) { return b.id === lastTrace.brushRef; });
|
|
250
|
+
}
|
|
251
|
+
var newId = allocateBrushId(internal.brushes);
|
|
252
|
+
var newBrush = sourceBrush !== undefined
|
|
253
|
+
? cloneBrush(sourceBrush, newId)
|
|
254
|
+
: defaultAuthoredBrush(newId);
|
|
255
|
+
if (brush !== undefined) {
|
|
256
|
+
applyBrushPartial(newBrush, brush);
|
|
257
|
+
}
|
|
258
|
+
internal.brushes.push(newBrush);
|
|
259
|
+
var trace = {
|
|
260
|
+
points: pointCopy,
|
|
261
|
+
brushRef: newBrush.id,
|
|
262
|
+
contextRef: DEFAULT_CONTEXT_REF,
|
|
263
|
+
};
|
|
264
|
+
var traceIndex = internal.traces.length;
|
|
265
|
+
internal.traces.push(trace);
|
|
266
|
+
// Keep ordered tree in sync so serializeInkXml (tree-preferring) emits new traces.
|
|
267
|
+
if (internal.traceTree !== undefined) {
|
|
268
|
+
internal.traceTree = __spread(internal.traceTree, [{ kind: 'trace', traceIndex: traceIndex }]);
|
|
269
|
+
}
|
|
270
|
+
return trace;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Deep-copy an ink DOM (independent traces, points, brushes, and contexts).
|
|
274
|
+
*
|
|
275
|
+
* @private
|
|
276
|
+
*/
|
|
277
|
+
export function cloneInk(ink) {
|
|
278
|
+
if (!isOfficeInk(ink)) {
|
|
279
|
+
throw new TypeError('cloneInk: expected OfficeInk from createInk/cloneInk');
|
|
280
|
+
}
|
|
281
|
+
var internal = ink;
|
|
282
|
+
var brushes = internal.brushes.map(function (b) { return cloneBrush(b, b.id); });
|
|
283
|
+
var traces = internal.traces.map(function (t) {
|
|
284
|
+
var copy = {
|
|
285
|
+
points: t.points.map(function (p) { return ({ x: p.x, y: p.y }); }),
|
|
286
|
+
brushRef: t.brushRef,
|
|
287
|
+
contextRef: t.contextRef,
|
|
288
|
+
};
|
|
289
|
+
if (t.timeOffset !== undefined) {
|
|
290
|
+
copy.timeOffset = t.timeOffset;
|
|
291
|
+
}
|
|
292
|
+
return copy;
|
|
293
|
+
});
|
|
294
|
+
var next = {
|
|
295
|
+
traces: traces,
|
|
296
|
+
brushes: brushes,
|
|
297
|
+
scaleMode: internal.scaleMode,
|
|
298
|
+
};
|
|
299
|
+
if (internal.contexts !== undefined) {
|
|
300
|
+
next.contexts = internal.contexts.map(cloneContext);
|
|
301
|
+
}
|
|
302
|
+
if (internal.traceTree !== undefined) {
|
|
303
|
+
next.traceTree = cloneTraceTree(internal.traceTree);
|
|
304
|
+
}
|
|
305
|
+
return brandInk(next);
|
|
306
|
+
}
|
|
307
|
+
function cloneTraceTree(nodes) {
|
|
308
|
+
return nodes.map(function (n) {
|
|
309
|
+
if (n.kind === 'trace') {
|
|
310
|
+
return { kind: 'trace', traceIndex: n.traceIndex };
|
|
311
|
+
}
|
|
312
|
+
return { kind: 'group', children: cloneTraceTree(n.children) };
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Convert ink traces into plane point paths scaled to a drawing extent.
|
|
317
|
+
*
|
|
318
|
+
* Authored ink (`scaleMode === 'authored'`, default from {@link createInk})
|
|
319
|
+
* uses stretch-to-fit (re-zero). Decoded ink uses uniform scale (no re-zero).
|
|
320
|
+
* Bounds are computed over **all** points in the ink, then each path is scaled
|
|
321
|
+
* with the same transform.
|
|
322
|
+
*
|
|
323
|
+
* @private
|
|
324
|
+
*/
|
|
325
|
+
export function inkPathPoints(ink, extent) {
|
|
326
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
327
|
+
if (!isOfficeInk(ink)) {
|
|
328
|
+
throw new TypeError('inkPathPoints: expected OfficeInk from createInk/cloneInk');
|
|
329
|
+
}
|
|
330
|
+
var internal = ink;
|
|
331
|
+
var allPoints = [];
|
|
332
|
+
try {
|
|
333
|
+
for (var _d = __values(internal.traces), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
334
|
+
var t = _e.value;
|
|
335
|
+
try {
|
|
336
|
+
for (var _f = __values(t.points), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
337
|
+
var p = _g.value;
|
|
338
|
+
allPoints.push(p);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
342
|
+
finally {
|
|
343
|
+
try {
|
|
344
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
345
|
+
}
|
|
346
|
+
finally { if (e_2) throw e_2.error; }
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
351
|
+
finally {
|
|
352
|
+
try {
|
|
353
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
354
|
+
}
|
|
355
|
+
finally { if (e_1) throw e_1.error; }
|
|
356
|
+
}
|
|
357
|
+
if (allPoints.length === 0) {
|
|
358
|
+
return internal.traces.map(function () { return []; });
|
|
359
|
+
}
|
|
360
|
+
// Build a single scaled cloud, then slice back per trace by index.
|
|
361
|
+
var scaledAll = internal.scaleMode === 'decoded'
|
|
362
|
+
? scalePointsUniform(allPoints, extent)
|
|
363
|
+
: scalePointsStretch(allPoints, extent);
|
|
364
|
+
var offset = 0;
|
|
365
|
+
var paths = [];
|
|
366
|
+
try {
|
|
367
|
+
for (var _h = __values(internal.traces), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
368
|
+
var t = _j.value;
|
|
369
|
+
var slice = scaledAll.slice(offset, offset + t.points.length);
|
|
370
|
+
offset += t.points.length;
|
|
371
|
+
paths.push(__spread(slice));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
375
|
+
finally {
|
|
376
|
+
try {
|
|
377
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
378
|
+
}
|
|
379
|
+
finally { if (e_3) throw e_3.error; }
|
|
380
|
+
}
|
|
381
|
+
return paths;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Type guard for {@link OfficeInk} instances produced by this module.
|
|
385
|
+
*
|
|
386
|
+
* @private
|
|
387
|
+
*/
|
|
388
|
+
export function isOfficeInk(value) {
|
|
389
|
+
if (value === null || typeof value !== 'object') {
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
return value[OFFICE_INK_BRAND] === true;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Mark an ink as authored or decoded (uniform scale path).
|
|
396
|
+
* Hosts and tests use this to select the scale mode for bounds/path computation.
|
|
397
|
+
*
|
|
398
|
+
* @private
|
|
399
|
+
*/
|
|
400
|
+
export function setInkScaleMode(ink, mode) {
|
|
401
|
+
if (!isOfficeInk(ink)) {
|
|
402
|
+
throw new TypeError('setInkScaleMode: expected OfficeInk');
|
|
403
|
+
}
|
|
404
|
+
ink.scaleMode = mode;
|
|
405
|
+
}
|
|
406
|
+
export { computeInkBounds };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InkML element-tree → {@link OfficeInk} parser ([MS-ODRAWXML] §2.1.4).
|
|
3
|
+
*
|
|
4
|
+
* The caller supplies an OpenXml element tree; this module never reads bytes
|
|
5
|
+
* and never expands entities. Count guards are surfaced via
|
|
6
|
+
* {@link getLastInkParseDiagnostics} for consumer limits policy.
|
|
7
|
+
*/
|
|
8
|
+
import { OpenXmlElement } from '../../core/xml/model';
|
|
9
|
+
import { OfficeInk } from './ink-model';
|
|
10
|
+
/**
|
|
11
|
+
* Diagnostic code for untokenizable / empty-result malformed traces.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare const DIAG_INVALID_INK_TRACE = "content/invalid-ink-trace";
|
|
16
|
+
/**
|
|
17
|
+
* Single diagnostic entry from an ink parse pass.
|
|
18
|
+
*
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
export interface InkParseDiagnostic {
|
|
22
|
+
/** Diagnostic code identifying the issue class. */
|
|
23
|
+
readonly code: string;
|
|
24
|
+
/** Human-readable description of the diagnostic. */
|
|
25
|
+
readonly message: string;
|
|
26
|
+
/** Optional zero-based index of the related trace when applicable. */
|
|
27
|
+
readonly traceIndex?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Aggregate diagnostics and guard counters from the most recent {@link parseInkXml} call.
|
|
31
|
+
*
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
export interface InkParseDiagnostics {
|
|
35
|
+
/** Ordered diagnostic items collected during the parse pass. */
|
|
36
|
+
readonly items: ReadonlyArray<InkParseDiagnostic>;
|
|
37
|
+
/** Number of traces observed during the parse pass. */
|
|
38
|
+
readonly traceCount: number;
|
|
39
|
+
/** Number of packets observed across traces. */
|
|
40
|
+
readonly packetCount: number;
|
|
41
|
+
/** Number of plane points produced during decode. */
|
|
42
|
+
readonly pointCount: number;
|
|
43
|
+
/** Number of channel values processed during decode. */
|
|
44
|
+
readonly channelValueCount: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Diagnostics from the most recent {@link parseInkXml} invocation.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare function getLastInkParseDiagnostics(): InkParseDiagnostics;
|
|
52
|
+
/**
|
|
53
|
+
* Parse an InkML `ink` root element tree into a branded {@link OfficeInk}.
|
|
54
|
+
*
|
|
55
|
+
* Source: [MS-ODRAWXML] §2.1.4; W3C InkML 1.0; `docs/specs/ink-shared-codec.md`.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseInkXml(root: OpenXmlElement): OfficeInk;
|