| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629 | 1×
1×
1×
6918×
1867×
42×
1825×
1825×
1×
1×
1960×
1960×
1244×
716×
716×
296×
2052×
2052×
2052×
716×
1979×
716×
189×
527×
527×
3497×
3497×
3497×
3497×
3497×
3497×
1741×
1741×
3497×
15547×
15547×
15547×
3398×
3398×
3369×
3369×
1756×
1756×
1756×
1756×
1756×
1756×
1756×
1756×
1756×
1756×
3497×
527×
1×
1×
1260×
1260×
1260×
1260×
126×
1134×
1×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
1×
1×
370×
370×
370×
370×
370×
370×
370×
370×
370×
1×
1×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
1×
1×
63×
2×
61×
104×
61×
4×
57×
57×
1×
90×
90×
90×
1×
63×
63×
63×
63×
63×
63×
66×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
63×
1×
1×
1768×
1768×
1768×
1×
6188×
6188×
6188×
6188×
1×
884×
1×
2652×
2652×
15912×
15912×
2652×
1×
884×
884×
884×
884×
884×
1×
884×
884×
884×
6188×
6188×
6188×
6188×
6188×
6188×
884×
1×
6188×
6188×
6188×
1×
1×
884×
1×
10608×
10608×
10608×
10608×
10608×
10608×
10608×
10608×
884×
884×
1×
1×
884×
884×
884×
884×
1×
1×
884×
884×
884×
884×
1×
1×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
884×
1×
1×
1590×
1590×
209031×
17889×
1590×
1590×
1590×
1590×
1590×
1590×
50×
1590×
1590×
1590×
1590×
1590×
1590×
23×
23×
23×
23×
23×
23×
23×
23×
23×
11×
12×
23×
55×
23×
1590×
1×
1×
1590×
1590×
1590×
1590×
1590×
13×
13×
13×
13×
13×
13×
13×
13×
1590×
1×
1×
437×
437×
437×
635×
635×
635×
635×
4×
437×
1×
| define(["require", "exports", "./visio-core", "./visio-models"], function (require, exports, visio_core_1, visio_models_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function setDefaultData(defaultDataValue, attributes) {
var defaultData = defaultDataValue.find(function (obj) { return obj.masterID === attributes.Master; });
if (!defaultData) {
return {};
}
var defaultValues = {
Width: defaultData.Width,
Height: defaultData.Height,
LocPinX: defaultData.LocPinX,
LocPinY: defaultData.LocPinY,
Name: defaultData.shapeName,
beginX: defaultData.beginX,
beginY: defaultData.beginY,
endX: defaultData.endX,
endY: defaultData.endY,
N: 'Geometry',
Row: defaultData.Row,
Ports: defaultData.ports,
shapeStyle: defaultData.shapeStyle,
txtWidth: defaultData.txtWidth,
txtHeight: defaultData.txtHeight,
txtPinX: defaultData.txtPinX,
txtPinY: defaultData.txtPinY,
txtLocalPinX: defaultData.txtLocalPinX,
txtLocalPinY: defaultData.txtLocalPinY,
QuickStyleLineColor: defaultData.QuickStyleLineColor,
QuickStyleFillColor: defaultData.QuickStyleFillColor,
QuickStyleShadowColor: defaultData.QuickStyleShadowColor,
QuickStyleFontColor: defaultData.QuickStyleFontColor,
QuickStyleLineMatrix: defaultData.QuickStyleLineMatrix,
QuickStyleFillMatrix: defaultData.QuickStyleFillMatrix,
QuickStyleEffectsMatrix: defaultData.QuickStyleEffectsMatrix,
QuickStyleFontMatrix: defaultData.QuickStyleFontMatrix
};
return defaultValues;
}
exports.setDefaultData = setDefaultData;
function getVisioPorts(shape, defaultData, width, height) {
var ports = [];
if (!shape.Section) {
return ports;
}
var defaultMap = {};
if (defaultData && defaultData.Ports && defaultData.Ports.length) {
for (var _i = 0, _a = defaultData.Ports; _i < _a.length; _i++) {
var p = _a[_i];
Eif (p.id) {
defaultMap[p.id] = p;
}
}
}
var sections = visio_core_1.ensureArray(shape.Section);
var connSection = sections.find(function (s) { return s && s.$ && s.$.N === 'Connection'; });
if (!connSection || !connSection.Row) {
return ports;
}
var rows = visio_core_1.ensureArray(connSection.Row);
rows.forEach(function (row) {
Eif (row.$ && row.$.T === 'Connection') {
var id = row.$.IX;
var cells = visio_core_1.ensureArray(row.Cell);
var port_1 = {
id: "port" + id,
x: 0, y: 0,
dirX: 0, dirY: 0,
type: 0, autoGen: 0, prompt: ''
};
var def = defaultMap[port_1.id];
if (def) {
port_1.x = def.x;
port_1.y = def.y;
}
cells.forEach(function (cell) {
var name = cell.$.N;
var value = cell.$.V;
switch (name) {
case 'X':
port_1.x = (parseFloat(value)) / width;
break;
case 'Y':
port_1.y = (height - parseFloat(value)) / height;
break;
case 'DirX':
port_1.dirX = parseFloat(value);
break;
case 'DirY':
port_1.dirY = parseFloat(value);
break;
case 'Type':
port_1.type = parseInt(value, 10);
break;
case 'AutoGen':
port_1.autoGen = parseInt(value, 10);
break;
case 'Prompt':
port_1.prompt = value;
break;
}
});
ports.push(port_1);
}
});
return ports;
}
exports.getVisioPorts = getVisioPorts;
function readCellValue(parent, key) {
Iif (!parent) {
return undefined;
}
var cell = parent["" + key];
Iif (!cell) {
return undefined;
}
if (typeof cell.value === 'undefined') {
return undefined;
}
return cell.value;
}
function parseVisioDocumentSettings(obj) {
var settings = new visio_models_1.VisioDocumentSettings();
Iif (!obj) {
return settings;
}
settings.glueSettings = visio_core_1.parseNumberCell(readCellValue(obj, 'GlueSettings'), 0);
settings.snapSettings = visio_core_1.parseNumberCell(readCellValue(obj, 'SnapSettings'), 0);
settings.snapExtensions = visio_core_1.parseNumberCell(readCellValue(obj, 'SnapExtensions'), 0);
settings.snapAngles = visio_core_1.parseNumberCell(readCellValue(obj, 'SnapAngles'), 0);
settings.dynamicGridEnabled = visio_core_1.toBoolean(readCellValue(obj, 'DynamicGridEnabled'), false);
settings.protectStyles = visio_core_1.toBoolean(readCellValue(obj, 'ProtectStyles'), false);
settings.protectShapes = visio_core_1.toBoolean(readCellValue(obj, 'ProtectShapes'), false);
settings.protectMasters = visio_core_1.toBoolean(readCellValue(obj, 'ProtectMasters'), false);
settings.protectBkgnds = visio_core_1.toBoolean(readCellValue(obj, 'ProtectBkgnds'), false);
return settings;
}
exports.parseVisioDocumentSettings = parseVisioDocumentSettings;
function parseVisioMaster(obj) {
var master = new visio_models_1.VisioMaster();
Iif (!obj || !obj.$) {
return master;
}
var pageSheetCell = obj.PageSheet ? visio_core_1.ensureArray(obj.PageSheet.Cell) : [];
master.id = obj.$.ID;
master.shape = obj.$.Name;
master.shapeType = typeof obj.$.MasterType === 'string' ? obj.$.MasterType : '';
master.name = obj.$.NameU;
master.shapeKeywords = visio_core_1.findCellValue(pageSheetCell, 'ShapeKeywords');
return master;
}
exports.parseVisioMaster = parseVisioMaster;
function parseVisioPage(pageSheet) {
var page = new visio_models_1.VisioPage();
Iif (!pageSheet || !pageSheet.Cell) {
page.layers = [];
return page;
}
var cellMap = visio_core_1.mapCellValues(visio_core_1.ensureArray(pageSheet.Cell));
page.pageWidth = visio_core_1.getCellMapNumericValue(cellMap, 'PageWidth');
page.pageHeight = visio_core_1.getCellMapNumericValue(cellMap, 'PageHeight');
page.shdwOffsetX = visio_core_1.getCellMapNumericValue(cellMap, 'ShdwOffsetX');
page.shdwOffsetY = visio_core_1.getCellMapNumericValue(cellMap, 'ShdwOffsetY');
page.pageScale = visio_core_1.getCellMapNumericValue(cellMap, 'PageScale');
page.drawingScale = visio_core_1.getCellMapNumericValue(cellMap, 'DrawingScale');
page.drawingSizeType = visio_core_1.getCellMapNumericValue(cellMap, 'DrawingSizeType');
page.drawingScaleType = visio_core_1.getCellMapNumericValue(cellMap, 'DrawingScaleType');
page.uiVisibility = visio_core_1.getCellMapNumericValue(cellMap, 'UIVisibility');
page.shdwType = visio_core_1.getCellMapNumericValue(cellMap, 'ShdwType');
page.shdwObliqueAngle = visio_core_1.getCellMapNumericValue(cellMap, 'ShdwObliqueAngle');
page.shdwScaleFactor = visio_core_1.getCellMapNumericValue(cellMap, 'ShdwScaleFactor');
page.drawingResizeType = visio_core_1.getCellMapNumericValue(cellMap, 'DrawingResizeType');
page.printPageOrientation = visio_core_1.getCellMapNumericValue(cellMap, 'PrintPageOrientation');
page.bridging = visio_core_1.getCellMapNumericValue(cellMap, 'LineJumpCode', 1);
page.horizontalBridgeSpace = visio_core_1.getCellMapNumericValue(cellMap, 'LineJumpFactorX', 0.6667);
page.verticalBridgeSpace = visio_core_1.getCellMapNumericValue(cellMap, 'LineJumpFactorY', 0.6667);
page.theme = visio_core_1.getCellMapNumericValue(cellMap, 'ThemeIndex');
page.variationStyleIndex = visio_core_1.getCellMapNumericValue(cellMap, 'VariationStyleIndex', 0);
page.inhibitSnap = visio_core_1.getCellMapBooleanValue(cellMap, 'InhibitSnap');
page.pageLockReplace = visio_core_1.getCellMapBooleanValue(cellMap, 'PageLockReplace');
page.pageLockDuplicate = visio_core_1.getCellMapBooleanValue(cellMap, 'PageLockDuplicate');
page.pageShapeSplit = visio_core_1.getCellMapBooleanValue(cellMap, 'PageShapeSplit');
page.fillColor = visio_core_1.getCellMapStringValue(cellMap, 'FillForegnd');
page.lineRouteExt = visio_core_1.getCellMapStringValue(cellMap, 'LineRouteExt', '0');
page.routeStyle = visio_core_1.getCellMapStringValue(cellMap, 'RouteStyle', '0');
page.layers = parseLayerSections(pageSheet.Section);
return page;
}
exports.parseVisioPage = parseVisioPage;
function parseLayerSections(sections) {
if (!sections) {
return [];
}
var sectionsArray = visio_core_1.ensureArray(sections);
var layerSection = sectionsArray.find(function (s) { return s && s.$ && s.$.N === 'Layer'; });
if (!layerSection || !layerSection.Row) {
return [];
}
var rows = visio_core_1.ensureArray(layerSection.Row);
return rows.map(parseLayer).filter(Boolean);
}
function parseLayer(row) {
Iif (!row || !row.Cell) {
return undefined;
}
var cellMap = visio_core_1.mapCellValues(visio_core_1.ensureArray(row.Cell));
return {
objects: [],
name: visio_core_1.getCellMapStringValue(cellMap, 'Name'),
color: visio_core_1.getCellMapNumericValue(cellMap, 'Color'),
status: visio_core_1.getCellMapNumericValue(cellMap, 'Status'),
visible: visio_core_1.getCellMapBooleanValue(cellMap, 'Visible', true),
print: visio_core_1.getCellMapBooleanValue(cellMap, 'Print', true),
active: visio_core_1.getCellMapBooleanValue(cellMap, 'Active'),
lock: visio_core_1.getCellMapBooleanValue(cellMap, 'Lock'),
snap: visio_core_1.getCellMapBooleanValue(cellMap, 'Snap', true),
glue: visio_core_1.getCellMapBooleanValue(cellMap, 'Glue', true),
nameUniv: visio_core_1.getCellMapStringValue(cellMap, 'NameU'),
colorTrans: visio_core_1.getCellMapNumericValue(cellMap, 'ColorTrans')
};
}
function parseVisioWindow(root) {
var window = new visio_models_1.VisioWindow();
Iif (!root) {
return window;
}
Eif (root.$) {
window.clientWidth = visio_core_1.parseNumberCell(root.$.ClientWidth, 0);
window.clientHeight = visio_core_1.parseNumberCell(root.$.ClientHeight, 0);
}
var windows = visio_core_1.ensureArray(root.Window);
var drawing = windows.find(function (w) { return w && w.$ && w.$.WindowType === 'Drawing'; });
Iif (!drawing) {
return window;
}
Eif (drawing.$) {
window.windowType = drawing.$.WindowType;
window.windowWidth = visio_core_1.parseNumberCell(drawing.$.WindowWidth, 0);
window.windowHeight = visio_core_1.parseNumberCell(drawing.$.WindowHeight, 0);
window.viewScale = visio_core_1.parseNumberCell(drawing.$.ViewScale, 1);
window.viewCenterX = visio_core_1.parseNumberCell(drawing.$.ViewCenterX, 0);
window.viewCenterY = visio_core_1.parseNumberCell(drawing.$.ViewCenterY, 0);
}
window.showRulers = visio_core_1.toBoolean(readCellValue(drawing, 'ShowRulers'), false);
window.showGrid = visio_core_1.toBoolean(readCellValue(drawing, 'ShowGrid'), false);
window.showPageBreaks = visio_core_1.toBoolean(readCellValue(drawing, 'ShowPageBreaks'), false);
window.showGuides = visio_core_1.toBoolean(readCellValue(drawing, 'ShowGuides'), false);
window.showConnectionPoints = visio_core_1.toBoolean(readCellValue(drawing, 'ShowConnectionPoints'), false);
window.dynamicGridEnabled = visio_core_1.toBoolean(readCellValue(drawing, 'DynamicGridEnabled'), false);
window.glueSettings = visio_core_1.parseNumberCell(readCellValue(drawing, 'GlueSettings'), 0);
window.snapSettings = visio_core_1.parseNumberCell(readCellValue(drawing, 'SnapSettings'), 0);
window.snapExtensions = visio_core_1.parseNumberCell(readCellValue(drawing, 'SnapExtensions'), 0);
window.snapAngles = visio_core_1.parseNumberCell(readCellValue(drawing, 'SnapAngles'), 0);
window.tabSplitterPos = visio_core_1.parseNumberCell(readCellValue(drawing, 'TabSplitterPos'), 0);
return window;
}
exports.parseVisioWindow = parseVisioWindow;
function clamp(n, min, max) {
Iif (n < min) {
return min;
}
Iif (n > max) {
return max;
}
return n;
}
function toHex(s) {
Iif (typeof s !== 'string') {
return undefined;
}
var hex = s.trim();
Iif (hex.length === 0) {
return undefined;
}
return '#' + hex.toUpperCase();
}
function extHas(ext, key) {
return Object.prototype.hasOwnProperty.call(ext, key);
}
function findExtByUri(exts, uri) {
Iif (!exts) {
return undefined;
}
for (var i = 0; i < exts.length; i++) {
var e = exts[parseInt(i.toString(), 10)];
if (e && e.$ && e.$.uri === uri) {
return e;
}
}
return undefined;
}
function findExtWithKey(exts, key) {
Iif (!exts) {
return undefined;
}
for (var i = 0; i < exts.length; i++) {
var e = exts[parseInt(i.toString(), 10)];
Eif (e && extHas(e, key)) {
return e;
}
}
return undefined;
}
function extractHexColorsFromVariation(variation) {
Iif (!variation) {
return [];
}
var result = [];
for (var i = 1; i <= 7; i++) {
var key = ('vt:varColor' + i);
var color = variation["" + key];
var val = color && color['a:srgbClr'] && color['a:srgbClr'].$ ? color['a:srgbClr'].$.val : undefined;
var hex = toHex(val);
Eif (typeof hex === 'string') {
result.push(hex);
}
}
return result;
}
function toReadonlyArray(value) {
Iif (typeof value === 'undefined') {
return undefined;
}
Eif (Array.isArray(value)) {
return value;
}
return [value];
}
exports.toReadonlyArray = toReadonlyArray;
function extractAndFormatColors(clrScheme) {
Iif (!visio_core_1.isObject(clrScheme)) {
return undefined;
}
function getHex(node) {
Iif (!visio_core_1.isObject(node)) {
return undefined;
}
var srgb = node['a:srgbClr'];
var scheme = node['a:schemeClr'];
var val = undefined;
Eif (visio_core_1.isObject(srgb) && visio_core_1.isObject(srgb.$)) {
val = srgb.$.val;
}
else if (visio_core_1.isObject(scheme) && visio_core_1.isObject(scheme.$)) {
val = scheme.$.val;
}
Eif (typeof val === 'string' && val.length > 0) {
return '#' + val.toUpperCase();
}
return undefined;
}
var result = {
dk1: getHex(clrScheme['a:dk1']),
lt1: getHex(clrScheme['a:lt1']),
dk2: getHex(clrScheme['a:dk2']),
lt2: getHex(clrScheme['a:lt2']),
accent1: getHex(clrScheme['a:accent1']),
accent2: getHex(clrScheme['a:accent2']),
accent3: getHex(clrScheme['a:accent3']),
accent4: getHex(clrScheme['a:accent4']),
accent5: getHex(clrScheme['a:accent5']),
accent6: getHex(clrScheme['a:accent6']),
hlink: getHex(clrScheme['a:hlink']),
folHlink: getHex(clrScheme['a:folHlink'])
};
return result;
}
exports.extractAndFormatColors = extractAndFormatColors;
function buildFmtSchemeFill(fmtScheme) {
Iif (!visio_core_1.isObject(fmtScheme)) {
return undefined;
}
var lst = fmtScheme['a:fillStyleLst'];
Iif (!visio_core_1.isObject(lst)) {
return undefined;
}
return lst['__order__'];
}
exports.buildFmtSchemeFill = buildFmtSchemeFill;
function buildFmtSchemeStroke(fmtScheme) {
Iif (!visio_core_1.isObject(fmtScheme)) {
return undefined;
}
var lst = fmtScheme['a:lnStyleLst'];
Iif (!visio_core_1.isObject(lst)) {
return undefined;
}
return lst['__order__'];
}
exports.buildFmtSchemeStroke = buildFmtSchemeStroke;
function parseVisioTheme(obj, context) {
var theme = {};
var clrExts = undefined;
var clrScheme = obj['a:clrScheme'];
Eif (visio_core_1.isObject(clrScheme)) {
var extLst = clrScheme['a:extLst'];
Eif (extLst && visio_core_1.isObject(extLst)) {
var exts = extLst['a:ext'];
clrExts = toReadonlyArray(exts);
}
}
var rootExts = undefined;
var rootExtList = obj['a:extLst'];
var rootExtsRaw;
Eif (visio_core_1.isObject(rootExtList)) {
rootExtsRaw = rootExtList['a:ext'];
rootExts = toReadonlyArray(rootExtsRaw);
}
var schemeIdExt = rootExtsRaw[1]['vt:themeScheme'];
Eif (schemeIdExt &&
visio_core_1.isObject(schemeIdExt['vt:schemeID']) &&
visio_core_1.isObject(schemeIdExt['vt:schemeID'].$)) {
var schemeAttrs = schemeIdExt['vt:schemeID'].$;
var schemeEnumVal = schemeAttrs.schemeEnum;
Eif (typeof schemeEnumVal === 'string') {
theme.schemeEnum = schemeEnumVal;
}
}
var fmtScheme = obj['a:fmtScheme'];
Eif (visio_core_1.isObject(fmtScheme) && visio_core_1.isObject(fmtScheme.$)) {
var fmtAttrs = fmtScheme.$;
var nameVal = fmtAttrs.name;
Eif (typeof nameVal === 'string') {
theme.name = nameVal;
}
}
var fontScheme = obj['a:fontScheme'];
Eif (visio_core_1.isObject(fontScheme)) {
var major = fontScheme['a:majorFont'];
Eif (visio_core_1.isObject(major)) {
var latin = major['a:latin'];
Eif (visio_core_1.isObject(latin) && visio_core_1.isObject(latin.$)) {
var latinAttrs = latin.$;
var typeface = latinAttrs.typeface;
Eif (typeof typeface === 'string') {
theme.fontFamily = typeface;
}
}
}
}
theme.fontColor = extractAndFormatColors(obj['a:clrScheme']);
Eif (visio_core_1.isObject(fmtScheme)) {
var fillOrder = buildFmtSchemeFill(fmtScheme);
Eif (fillOrder && fillOrder.length > 0) {
theme.fmtSchemeFill = fillOrder;
}
}
Eif (visio_core_1.isObject(fmtScheme)) {
var lnOrder = buildFmtSchemeStroke(fmtScheme);
Eif (lnOrder && lnOrder.length > 0) {
theme.fmtSchemeStroke = lnOrder;
}
}
var fontStylesUri = '{EBE24D50-EC5C-4D6F-A1A3-C5F0A18B936A}';
var fontStylesExt = findExtByUri(rootExts, fontStylesUri);
Iif (!fontStylesExt) {
fontStylesExt = findExtWithKey(rootExts, 'vt:fontStylesGroup');
}
Eif (fontStylesExt && visio_core_1.isObject(fontStylesExt['vt:fontStylesGroup'])) {
var group = fontStylesExt['vt:fontStylesGroup'];
var vtFontStyles = group['vt:fontStyles'];
Eif (visio_core_1.isObject(vtFontStyles) && visio_core_1.isObject(vtFontStyles['vt:fontProps'])) {
var fontProps = vtFontStyles['vt:fontProps'];
var fontPropsArr = toReadonlyArray(fontProps);
Eif (fontPropsArr && fontPropsArr.length > 0) {
theme.fontStyles = fontPropsArr;
}
}
var vtConnectorFontStyles = group['vt:connectorFontStyles'];
Eif (visio_core_1.isObject(vtConnectorFontStyles) &&
visio_core_1.isObject(vtConnectorFontStyles['vt:fontProps'])) {
var connProps = vtConnectorFontStyles['vt:fontProps'];
var connPropsArr = toReadonlyArray(connProps);
Eif (connPropsArr && connPropsArr.length > 0) {
theme.connectorFont = connPropsArr;
}
}
}
var fmtConnectorExt = findExtWithKey(rootExts, 'vt:fmtConnectorScheme');
Eif (fmtConnectorExt && visio_core_1.isObject(fmtConnectorExt['vt:fmtConnectorScheme'])) {
var fmtConn = fmtConnectorExt['vt:fmtConnectorScheme'];
Eif (visio_core_1.isObject(fmtConn['a:lnStyleLst'])) {
theme.connectorStroke = fmtConn['a:lnStyleLst'];
}
}
var variationClrUri = '{DDD2D869-C2EF-471E-B8FA-914AFA308C9F}';
var variationClrExt = findExtByUri(clrExts, variationClrUri);
Iif (!variationClrExt) {
variationClrExt = findExtWithKey(clrExts, 'vt:variationClrSchemeLst');
}
var colorVariations = [];
Eif (variationClrExt &&
visio_core_1.isObject(variationClrExt['vt:variationClrSchemeLst']) &&
visio_core_1.isObject(variationClrExt['vt:variationClrSchemeLst']['vt:variationClrScheme'])) {
var v = variationClrExt['vt:variationClrSchemeLst']['vt:variationClrScheme'];
var vArr = toReadonlyArray(v);
Eif (vArr && vArr.length > 0) {
colorVariations = vArr;
}
}
var variationStyleUri = '{494CE47F-D151-47DC-95E8-85652EA8A67E}';
var variationStyleExt = findExtByUri(rootExts, variationStyleUri);
Iif (!variationStyleExt) {
variationStyleExt = findExtWithKey(rootExts, 'vt:variationStyleSchemeLst');
}
var variationStyleSchemes = [];
Eif (variationStyleExt &&
visio_core_1.isObject(variationStyleExt['vt:variationStyleSchemeLst']) &&
visio_core_1.isObject(variationStyleExt['vt:variationStyleSchemeLst']['vt:variationStyleScheme'])) {
var s = variationStyleExt['vt:variationStyleSchemeLst']['vt:variationStyleScheme'];
var sArr = toReadonlyArray(s);
Eif (sArr && sArr.length > 0) {
variationStyleSchemes = sArr;
}
}
var requestedIndex = 0;
Eif (context && context.data && Array.isArray(context.data.pages) && context.data.pages.length > 0) {
Eif (context.currentPage &&
typeof context.currentPage.variationStyleIndex !== 'undefined') {
var raw = context.currentPage.variationStyleIndex;
var toParse = typeof raw === 'number' ? String(raw) : String(raw);
var parsed = parseInt(toParse, 10);
Eif (!isNaN(parsed)) {
requestedIndex = parsed;
}
}
}
var varIndex = colorVariations.length > 0 ? clamp(requestedIndex, 0, colorVariations.length - 1) : 0;
var chosenVariation = undefined;
Eif (colorVariations.length > varIndex) {
chosenVariation = colorVariations[parseInt(varIndex.toString(), 10)];
}
var styleIndex = variationStyleSchemes.length > 0
? clamp(requestedIndex, 0, variationStyleSchemes.length - 1)
: 0;
Eif (variationStyleSchemes.length > styleIndex) {
var chosenStyle = variationStyleSchemes[parseInt(styleIndex.toString(), 10)];
Eif (visio_core_1.isObject(chosenStyle)) {
var varStyle = chosenStyle['vt:varStyle'];
var varStyleArr = toReadonlyArray(varStyle);
Eif (varStyleArr && varStyleArr.length > 0) {
theme.variant = varStyleArr;
}
}
}
theme.hexColors = extractHexColorsFromVariation(chosenVariation);
return theme;
}
exports.parseVisioTheme = parseVisioTheme;
function parseVisioNodeStyle(shapeData, context, defaultStyle, attributeName) {
var section = shapeData.Section ? (Array.isArray(shapeData.Section) ? shapeData.Section : [shapeData.Section]) : [];
var getCell = function (name) {
var cell = visio_core_1.ensureArray(shapeData.Cell).find(function (c) { return c.$.N === name; });
return cell ? cell.$.V : undefined;
};
var nodeStyle = new visio_models_1.VisioNodeStyle();
nodeStyle.strokeWidth = getCell('LineWeight') != null ? Number(getCell('LineWeight')) : undefined;
nodeStyle.linePattern = getCell('LinePattern') != null ? getCell('LinePattern') : undefined;
nodeStyle.strokeColor = getCell('LineColor') != null ? (nodeStyle.linePattern !== '0' ? getCell('LineColor') : undefined) : undefined;
nodeStyle.strokeDashArray = getCell('LinePattern') != null ? getCell('LinePattern') : undefined;
if (getCell('LinePattern') != null) {
context.addWarning('[WARNING] :: The dashed patterns in EJ2 partially match those in Visio. While the patterns themselves are similar, their appearance, particularly when adjusting the stroke width, is not identical.');
}
nodeStyle.fillColor = getCell('FillForegnd') != null ? getCell('FillForegnd') : undefined;
nodeStyle.fillPattern = getCell('FillPattern') != null ? getCell('FillPattern') : (defaultStyle && defaultStyle.FillPattern) ? defaultStyle.FillPattern : undefined;
nodeStyle.opacity = (attributeName === 'Image')
? (getCell('Transparency') != null ? Number(getCell('Transparency')) : 1)
: (getCell('FillForegndTrans') != null ? Number(getCell('FillForegndTrans')) : (defaultStyle && defaultStyle.FillForegndTrans) ? defaultStyle.FillForegndTrans : 1);
nodeStyle.gradientAngle = getCell('FillGradientAngle') != null ? Number(getCell('FillGradientAngle')) : 0;
nodeStyle.isGradientEnabled = getCell('FillGradientEnabled') != null && getCell('FillGradientEnabled') !== '0';
if (nodeStyle.isGradientEnabled) {
context.addWarning('[WARNING] :: Gradient fills in Visio are approximated in EJ2.');
context.addWarning('[WARNING] :: Line gradients are not supported in EJ2. Additionally, there isn\'t a specific API to adjust line transparency directly. Line transparency is adjusted when the node\'s fill transparency is modified.');
var angleRad = Number(getCell('FillGradientAngle'));
var angleDeg = angleRad * (180 / Math.PI);
var gradientDir = getCell('FillGradientDir');
nodeStyle.gradientType = gradientDir === '0' ? 'Linear' : 'Radial';
context.addWarning('[WARNING] :: EJ2 diagram only supports linear and radial gradients. Rectangle and path gradient types are not supported in EJ2.');
nodeStyle.gradient = getCell('FillBkgnd') != null ? getCell('FillBkgnd') : '#1b2811';
if (nodeStyle.gradientType === 'Linear') {
nodeStyle.gradientCoordinates = visio_core_1.getGradientVectorByAngle(angleDeg);
}
else {
nodeStyle.gradientCoordinates = visio_core_1.getRadialGradient(gradientDir);
}
var fillGradientSection = section.find(function (sec) {
return sec && sec.$ && sec.$.N === 'FillGradient';
});
nodeStyle.gradientStops = visio_core_1.extractGradientStops(fillGradientSection);
}
return nodeStyle;
}
exports.parseVisioNodeStyle = parseVisioNodeStyle;
function parseVisioNodeShadow(cellMap, context) {
var nodeShadow = new visio_models_1.VisioNodeShadow();
nodeShadow.shadowPattern = cellMap.get('ShdwPattern') != null && cellMap.get('ShdwPattern') !== '0';
nodeShadow.shapeShadowType = (cellMap.get('ShapeShdwType') != null && cellMap.get('ShapeShdwType'));
nodeShadow.shapeShadowShow = (cellMap.get('ShapeShdwShow') != null && cellMap.get('ShapeShdwShow'));
if (nodeShadow.shadowPattern && nodeShadow.shapeShadowType) {
context.addWarning('[WARNING] :: In EJ2, among the various shadow types, only \'Outer\' shadows are supported. Furthermore, within the \'Outer\' shadow type, the \'offset center\' effect cannot be replicated in EJ2. Additionally, EJ2 does not support a blur property for shadows, resulting in sharp-edged shadows only.');
var shdwOpacity = cellMap.get('ShdwForegndTrans') != null ? Number(cellMap.get('ShdwForegndTrans')) : 1;
nodeShadow.shadowOpacity = (1 - shdwOpacity);
nodeShadow.shadowcolor = cellMap.get('ShdwForegnd') != null ? cellMap.get('ShdwForegnd') : '#ffffff';
var shdwOffsetX = cellMap.get('ShapeShdwOffsetX') != null ? Number(cellMap.get('ShapeShdwOffsetX')) : 0;
var shdwOffsetY = cellMap.get('ShapeShdwOffsetY') != null ? Number(cellMap.get('ShapeShdwOffsetY')) : 0;
var shdwScaleFactor = cellMap.get('ShapeShdwScaleFactor') != null ? Number(cellMap.get('ShapeShdwScaleFactor')) : 0;
nodeShadow.shadow = visio_core_1.calculateShadowProperties(shdwOffsetX, shdwOffsetY, shdwScaleFactor);
}
return nodeShadow;
}
exports.parseVisioNodeShadow = parseVisioNodeShadow;
function parserVisioRelationship(relationshipInput) {
var relation = new visio_models_1.VisioRelationship();
var relationships = Array.isArray(relationshipInput)
? relationshipInput
: [relationshipInput];
for (var _i = 0, relationships_1 = relationships; _i < relationships_1.length; _i++) {
var rel = relationships_1[_i];
var target = rel.$.Target;
var id = rel.$.Id;
if (target && target.startsWith('../media/')) {
relation.media.push({ Id: id, Target: target });
}
}
return relation.media.length > 0 ? relation : null;
}
exports.parserVisioRelationship = parserVisioRelationship;
});
|