bpmn-moddle 7.1.2 → 8.0.0

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.
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
3
  typeof define === 'function' && define.amd ? define(factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.BpmnModdle = factory());
5
- }(this, (function () { 'use strict';
5
+ })(this, (function () { 'use strict';
6
6
 
7
7
  /**
8
8
  * Flatten array, one level deep.
@@ -14,7 +14,7 @@
14
14
 
15
15
  var nativeToString = Object.prototype.toString;
16
16
  var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
17
- function isUndefined(obj) {
17
+ function isUndefined$1(obj) {
18
18
  return obj === undefined;
19
19
  }
20
20
  function isArray(obj) {
@@ -63,6 +63,26 @@
63
63
  });
64
64
  return match;
65
65
  }
66
+ /**
67
+ * Find element index in collection.
68
+ *
69
+ * @param {Array|Object} collection
70
+ * @param {Function} matcher
71
+ *
72
+ * @return {Object}
73
+ */
74
+
75
+ function findIndex(collection, matcher) {
76
+ matcher = toMatcher(matcher);
77
+ var idx = isArray(collection) ? -1 : undefined;
78
+ forEach(collection, function (val, key) {
79
+ if (matcher(val, key)) {
80
+ idx = key;
81
+ return false;
82
+ }
83
+ });
84
+ return idx;
85
+ }
66
86
  /**
67
87
  * Find element in collection.
68
88
  *
@@ -94,7 +114,7 @@
94
114
  function forEach(collection, iterator) {
95
115
  var val, result;
96
116
 
97
- if (isUndefined(collection)) {
117
+ if (isUndefined$1(collection)) {
98
118
  return;
99
119
  }
100
120
 
@@ -786,7 +806,7 @@
786
806
 
787
807
  var propertyName = property && property.name;
788
808
 
789
- if (isUndefined$1(value)) {
809
+ if (isUndefined(value)) {
790
810
  // unset the property, if the specified value is undefined;
791
811
  // delete from $attrs (for extensions) or the target itself
792
812
  if (property) {
@@ -863,7 +883,7 @@
863
883
  };
864
884
 
865
885
 
866
- function isUndefined$1(val) {
886
+ function isUndefined(val) {
867
887
  return typeof val === 'undefined';
868
888
  }
869
889
 
@@ -1147,11 +1167,11 @@
1147
1167
 
1148
1168
  var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
1149
1169
  var XSI_PREFIX = 'xsi';
1150
- var XSI_TYPE = 'xsi:type';
1170
+ var XSI_TYPE$1 = 'xsi:type';
1151
1171
 
1152
1172
  var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
1153
1173
 
1154
- function error(msg) {
1174
+ function error$1(msg) {
1155
1175
  return new Error(msg);
1156
1176
  }
1157
1177
 
@@ -1272,7 +1292,7 @@
1272
1292
  */
1273
1293
  function handleError(err) {
1274
1294
  if (!(err instanceof Error)) {
1275
- err = error(err);
1295
+ err = error$1(err);
1276
1296
  }
1277
1297
 
1278
1298
  returnError = err;
@@ -1292,7 +1312,7 @@
1292
1312
  }
1293
1313
 
1294
1314
  if (!(err instanceof Error)) {
1295
- err = error(err);
1315
+ err = error$1(err);
1296
1316
  }
1297
1317
 
1298
1318
  onWarning(err, getContext);
@@ -1309,7 +1329,7 @@
1309
1329
  this['on'] = function(name, cb) {
1310
1330
 
1311
1331
  if (typeof cb !== 'function') {
1312
- throw error('required args <name, cb>');
1332
+ throw error$1('required args <name, cb>');
1313
1333
  }
1314
1334
 
1315
1335
  switch (name) {
@@ -1323,7 +1343,7 @@
1323
1343
  case 'question': onQuestion = cb; break; // <? .... ?>
1324
1344
  case 'comment': onComment = cb; break;
1325
1345
  default:
1326
- throw error('unsupported event: ' + name);
1346
+ throw error$1('unsupported event: ' + name);
1327
1347
  }
1328
1348
 
1329
1349
  return this;
@@ -1350,7 +1370,7 @@
1350
1370
  }
1351
1371
 
1352
1372
  if (typeof nsMap !== 'object') {
1353
- throw error('required args <nsMap={}>');
1373
+ throw error$1('required args <nsMap={}>');
1354
1374
  }
1355
1375
 
1356
1376
  var _nsUriToPrefix = {}, k;
@@ -1377,7 +1397,7 @@
1377
1397
  */
1378
1398
  this['parse'] = function(xml) {
1379
1399
  if (typeof xml !== 'string') {
1380
- throw error('required args <xml=string>');
1400
+ throw error$1('required args <xml=string>');
1381
1401
  }
1382
1402
 
1383
1403
  returnError = null;
@@ -1686,7 +1706,7 @@
1686
1706
  // end: normalize ns attribute name
1687
1707
 
1688
1708
  // normalize xsi:type ns attribute value
1689
- if (name === XSI_TYPE) {
1709
+ if (name === XSI_TYPE$1) {
1690
1710
  w = value.indexOf(':');
1691
1711
 
1692
1712
  if (w !== -1) {
@@ -1732,7 +1752,7 @@
1732
1752
  // end: normalize ns attribute name
1733
1753
 
1734
1754
  // normalize xsi:type ns attribute value
1735
- if (name === XSI_TYPE) {
1755
+ if (name === XSI_TYPE$1) {
1736
1756
  w = value.indexOf(':');
1737
1757
 
1738
1758
  if (w !== -1) {
@@ -2175,14 +2195,14 @@
2175
2195
  'xml': 'http://www.w3.org/XML/1998/namespace'
2176
2196
  };
2177
2197
 
2178
- var XSI_TYPE$1 = 'xsi:type';
2198
+ var XSI_TYPE = 'xsi:type';
2179
2199
 
2180
2200
  function serializeFormat(element) {
2181
2201
  return element.xml && element.xml.serialize;
2182
2202
  }
2183
2203
 
2184
2204
  function serializeAsType(element) {
2185
- return serializeFormat(element) === XSI_TYPE$1;
2205
+ return serializeFormat(element) === XSI_TYPE;
2186
2206
  }
2187
2207
 
2188
2208
  function serializeAsProperty(element) {
@@ -2224,7 +2244,7 @@
2224
2244
  return prefixedToName(nameNs, pkg);
2225
2245
  }
2226
2246
 
2227
- function error$1(message) {
2247
+ function error(message) {
2228
2248
  return new Error(message);
2229
2249
  }
2230
2250
 
@@ -2282,7 +2302,7 @@
2282
2302
  this.addElement = function(element) {
2283
2303
 
2284
2304
  if (!element) {
2285
- throw error$1('expected element');
2305
+ throw error('expected element');
2286
2306
  }
2287
2307
 
2288
2308
  var elementsById = this.elementsById;
@@ -2303,7 +2323,7 @@
2303
2323
  }
2304
2324
 
2305
2325
  if (elementsById[id]) {
2306
- throw error$1('duplicate ID <' + id + '>');
2326
+ throw error('duplicate ID <' + id + '>');
2307
2327
  }
2308
2328
 
2309
2329
  elementsById[id] = element;
@@ -2363,7 +2383,7 @@
2363
2383
  ReferenceHandler.prototype.handleNode = function(node) {
2364
2384
 
2365
2385
  if (this.element) {
2366
- throw error$1('expected no sub nodes');
2386
+ throw error('expected no sub nodes');
2367
2387
  } else {
2368
2388
  this.element = this.createReference(node);
2369
2389
  }
@@ -2447,7 +2467,7 @@
2447
2467
  bodyProperty = descriptor.bodyProperty;
2448
2468
 
2449
2469
  if (!bodyProperty) {
2450
- throw error$1('unexpected body text <' + text + '>');
2470
+ throw error('unexpected body text <' + text + '>');
2451
2471
  }
2452
2472
 
2453
2473
  BodyHandler.prototype.handleText.call(this, text);
@@ -2553,7 +2573,7 @@
2553
2573
  if (property && !property.isAttr) {
2554
2574
 
2555
2575
  if (serializeAsType(property)) {
2556
- elementTypeName = node.attributes[XSI_TYPE$1];
2576
+ elementTypeName = node.attributes[XSI_TYPE];
2557
2577
 
2558
2578
  // xsi type is optional, if it does not exists the
2559
2579
  // default type is assumed
@@ -2603,7 +2623,7 @@
2603
2623
  }
2604
2624
  }
2605
2625
 
2606
- throw error$1('unrecognized element <' + nameNs.name + '>');
2626
+ throw error('unrecognized element <' + nameNs.name + '>');
2607
2627
  };
2608
2628
 
2609
2629
  ElementHandler.prototype.toString = function() {
@@ -2706,7 +2726,7 @@
2706
2726
  //
2707
2727
  // this ensures we don't mistakenly import wrong namespace elements
2708
2728
  if (!type.hasType(typeName)) {
2709
- throw error$1('unexpected element <' + node.originalName + '>');
2729
+ throw error('unexpected element <' + node.originalName + '>');
2710
2730
  }
2711
2731
 
2712
2732
  return ElementHandler.prototype.createElement.call(this, node);
@@ -2874,7 +2894,7 @@
2874
2894
 
2875
2895
  return true;
2876
2896
  } else {
2877
- throw error$1(message);
2897
+ throw error(message);
2878
2898
  }
2879
2899
  }
2880
2900
 
@@ -3055,7 +3075,7 @@
3055
3075
  var rootElement = rootHandler.element;
3056
3076
 
3057
3077
  if (!err && !rootElement) {
3058
- err = error$1('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
3078
+ err = error('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
3059
3079
  }
3060
3080
 
3061
3081
  var warnings = context.warnings;
@@ -3569,7 +3589,7 @@
3569
3589
 
3570
3590
  // do not serialize xsi:type attribute
3571
3591
  // it is set manually based on the actual implementation type
3572
- if (attr.name === XSI_TYPE$1) {
3592
+ if (attr.name === XSI_TYPE) {
3573
3593
  return;
3574
3594
  }
3575
3595
 
@@ -3766,7 +3786,23 @@
3766
3786
  value = escapeAttr(value);
3767
3787
  }
3768
3788
 
3769
- attrs.push({ name: name, value: value });
3789
+ // de-duplicate attributes
3790
+ // https://github.com/bpmn-io/moddle-xml/issues/66
3791
+ var idx = findIndex(attrs, function(element) {
3792
+ return (
3793
+ element.name.localName === name.localName &&
3794
+ element.name.uri === name.uri &&
3795
+ element.name.prefix === name.prefix
3796
+ );
3797
+ });
3798
+
3799
+ var attr = { name: name, value: value };
3800
+
3801
+ if (idx !== -1) {
3802
+ attrs.splice(idx, 1, attr);
3803
+ } else {
3804
+ attrs.push(attr);
3805
+ }
3770
3806
  };
3771
3807
 
3772
3808
  ElementSerializer.prototype.serializeAttributes = function(writer) {
@@ -3851,7 +3887,7 @@
3851
3887
  typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
3852
3888
 
3853
3889
  this.addAttribute(
3854
- this.nsAttributeName(XSI_TYPE$1),
3890
+ this.nsAttributeName(XSI_TYPE),
3855
3891
  (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
3856
3892
  );
3857
3893
 
@@ -4026,12 +4062,12 @@
4026
4062
  });
4027
4063
  };
4028
4064
 
4029
- var name = "BPMN20";
4030
- var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
4031
- var prefix = "bpmn";
4032
- var associations = [
4065
+ var name$5 = "BPMN20";
4066
+ var uri$5 = "http://www.omg.org/spec/BPMN/20100524/MODEL";
4067
+ var prefix$5 = "bpmn";
4068
+ var associations$5 = [
4033
4069
  ];
4034
- var types = [
4070
+ var types$5 = [
4035
4071
  {
4036
4072
  name: "Interface",
4037
4073
  superClass: [
@@ -6849,7 +6885,7 @@
6849
6885
  ]
6850
6886
  }
6851
6887
  ];
6852
- var enumerations = [
6888
+ var enumerations$3 = [
6853
6889
  {
6854
6890
  name: "ProcessType",
6855
6891
  literalValues: [
@@ -6980,24 +7016,24 @@
6980
7016
  ]
6981
7017
  }
6982
7018
  ];
6983
- var xml = {
7019
+ var xml$1 = {
6984
7020
  tagAlias: "lowerCase",
6985
7021
  typePrefix: "t"
6986
7022
  };
6987
7023
  var BpmnPackage = {
6988
- name: name,
6989
- uri: uri,
6990
- prefix: prefix,
6991
- associations: associations,
6992
- types: types,
6993
- enumerations: enumerations,
6994
- xml: xml
7024
+ name: name$5,
7025
+ uri: uri$5,
7026
+ prefix: prefix$5,
7027
+ associations: associations$5,
7028
+ types: types$5,
7029
+ enumerations: enumerations$3,
7030
+ xml: xml$1
6995
7031
  };
6996
7032
 
6997
- var name$1 = "BPMNDI";
6998
- var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
6999
- var prefix$1 = "bpmndi";
7000
- var types$1 = [
7033
+ var name$4 = "BPMNDI";
7034
+ var uri$4 = "http://www.omg.org/spec/BPMN/20100524/DI";
7035
+ var prefix$4 = "bpmndi";
7036
+ var types$4 = [
7001
7037
  {
7002
7038
  name: "BPMNDiagram",
7003
7039
  properties: [
@@ -7148,7 +7184,7 @@
7148
7184
  ]
7149
7185
  }
7150
7186
  ];
7151
- var enumerations$1 = [
7187
+ var enumerations$2 = [
7152
7188
  {
7153
7189
  name: "ParticipantBandKind",
7154
7190
  literalValues: [
@@ -7184,21 +7220,21 @@
7184
7220
  ]
7185
7221
  }
7186
7222
  ];
7187
- var associations$1 = [
7223
+ var associations$4 = [
7188
7224
  ];
7189
7225
  var BpmnDiPackage = {
7190
- name: name$1,
7191
- uri: uri$1,
7192
- prefix: prefix$1,
7193
- types: types$1,
7194
- enumerations: enumerations$1,
7195
- associations: associations$1
7226
+ name: name$4,
7227
+ uri: uri$4,
7228
+ prefix: prefix$4,
7229
+ types: types$4,
7230
+ enumerations: enumerations$2,
7231
+ associations: associations$4
7196
7232
  };
7197
7233
 
7198
- var name$2 = "DC";
7199
- var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
7200
- var prefix$2 = "dc";
7201
- var types$2 = [
7234
+ var name$3 = "DC";
7235
+ var uri$3 = "http://www.omg.org/spec/DD/20100524/DC";
7236
+ var prefix$3 = "dc";
7237
+ var types$3 = [
7202
7238
  {
7203
7239
  name: "Boolean"
7204
7240
  },
@@ -7291,20 +7327,20 @@
7291
7327
  ]
7292
7328
  }
7293
7329
  ];
7294
- var associations$2 = [
7330
+ var associations$3 = [
7295
7331
  ];
7296
7332
  var DcPackage = {
7297
- name: name$2,
7298
- uri: uri$2,
7299
- prefix: prefix$2,
7300
- types: types$2,
7301
- associations: associations$2
7333
+ name: name$3,
7334
+ uri: uri$3,
7335
+ prefix: prefix$3,
7336
+ types: types$3,
7337
+ associations: associations$3
7302
7338
  };
7303
7339
 
7304
- var name$3 = "DI";
7305
- var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
7306
- var prefix$3 = "di";
7307
- var types$3 = [
7340
+ var name$2 = "DI";
7341
+ var uri$2 = "http://www.omg.org/spec/DD/20100524/DI";
7342
+ var prefix$2 = "di";
7343
+ var types$2 = [
7308
7344
  {
7309
7345
  name: "DiagramElement",
7310
7346
  isAbstract: true,
@@ -7533,24 +7569,24 @@
7533
7569
  ]
7534
7570
  }
7535
7571
  ];
7536
- var associations$3 = [
7572
+ var associations$2 = [
7537
7573
  ];
7538
- var xml$1 = {
7574
+ var xml = {
7539
7575
  tagAlias: "lowerCase"
7540
7576
  };
7541
7577
  var DiPackage = {
7542
- name: name$3,
7543
- uri: uri$3,
7544
- prefix: prefix$3,
7545
- types: types$3,
7546
- associations: associations$3,
7547
- xml: xml$1
7578
+ name: name$2,
7579
+ uri: uri$2,
7580
+ prefix: prefix$2,
7581
+ types: types$2,
7582
+ associations: associations$2,
7583
+ xml: xml
7548
7584
  };
7549
7585
 
7550
- var name$4 = "bpmn.io colors for BPMN";
7551
- var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
7552
- var prefix$4 = "bioc";
7553
- var types$4 = [
7586
+ var name$1 = "bpmn.io colors for BPMN";
7587
+ var uri$1 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
7588
+ var prefix$1 = "bioc";
7589
+ var types$1 = [
7554
7590
  {
7555
7591
  name: "ColoredShape",
7556
7592
  "extends": [
@@ -7588,23 +7624,23 @@
7588
7624
  ]
7589
7625
  }
7590
7626
  ];
7591
- var enumerations$2 = [
7627
+ var enumerations$1 = [
7592
7628
  ];
7593
- var associations$4 = [
7629
+ var associations$1 = [
7594
7630
  ];
7595
7631
  var BiocPackage = {
7596
- name: name$4,
7597
- uri: uri$4,
7598
- prefix: prefix$4,
7599
- types: types$4,
7600
- enumerations: enumerations$2,
7601
- associations: associations$4
7632
+ name: name$1,
7633
+ uri: uri$1,
7634
+ prefix: prefix$1,
7635
+ types: types$1,
7636
+ enumerations: enumerations$1,
7637
+ associations: associations$1
7602
7638
  };
7603
7639
 
7604
- var name$5 = "BPMN in Color";
7605
- var uri$5 = "http://www.omg.org/spec/BPMN/non-normative/color/1.0";
7606
- var prefix$5 = "color";
7607
- var types$5 = [
7640
+ var name = "BPMN in Color";
7641
+ var uri = "http://www.omg.org/spec/BPMN/non-normative/color/1.0";
7642
+ var prefix = "color";
7643
+ var types = [
7608
7644
  {
7609
7645
  name: "ColoredLabel",
7610
7646
  "extends": [
@@ -7650,17 +7686,17 @@
7650
7686
  ]
7651
7687
  }
7652
7688
  ];
7653
- var enumerations$3 = [
7689
+ var enumerations = [
7654
7690
  ];
7655
- var associations$5 = [
7691
+ var associations = [
7656
7692
  ];
7657
7693
  var BpmnInColorPackage = {
7658
- name: name$5,
7659
- uri: uri$5,
7660
- prefix: prefix$5,
7661
- types: types$5,
7662
- enumerations: enumerations$3,
7663
- associations: associations$5
7694
+ name: name,
7695
+ uri: uri,
7696
+ prefix: prefix,
7697
+ types: types,
7698
+ enumerations: enumerations,
7699
+ associations: associations
7664
7700
  };
7665
7701
 
7666
7702
  var packages = {
@@ -7680,4 +7716,4 @@
7680
7716
 
7681
7717
  return simple;
7682
7718
 
7683
- })));
7719
+ }));