bpmn-js 18.13.2 → 18.14.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * bpmn-js - bpmn-modeler v18.13.2
2
+ * bpmn-js - bpmn-modeler v18.14.0
3
3
  *
4
4
  * Copyright (c) 2014-present, camunda Services GmbH
5
5
  *
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * Source Code: https://github.com/bpmn-io/bpmn-js
10
10
  *
11
- * Date: 2026-03-23
11
+ * Date: 2026-03-27
12
12
  */
13
13
  (function (global, factory) {
14
14
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -123,7 +123,7 @@
123
123
  *
124
124
  * @param {Object} [element] element to bind the id to
125
125
  *
126
- * @return {String} id
126
+ * @return {string} id
127
127
  */
128
128
  Ids$1.prototype.next = function(element) {
129
129
  return this._seed(element || true);
@@ -134,7 +134,7 @@
134
134
  *
135
135
  * @param {Object} [element] element to bind the id to
136
136
  *
137
- * @return {String} id
137
+ * @return {string} id
138
138
  */
139
139
  Ids$1.prototype.nextPrefixed = function(prefix, element) {
140
140
  var id;
@@ -153,8 +153,8 @@
153
153
  /**
154
154
  * Manually claim an existing id.
155
155
  *
156
- * @param {String} id
157
- * @param {String} [element] element the id is claimed by
156
+ * @param {string} id
157
+ * @param {any} [element] element the id is claimed by
158
158
  */
159
159
  Ids$1.prototype.claim = function(id, element) {
160
160
  this._seed.set(id, element || true);
@@ -163,8 +163,8 @@
163
163
  /**
164
164
  * Returns true if the given id has already been assigned.
165
165
  *
166
- * @param {String} id
167
- * @return {Boolean}
166
+ * @param {string} id
167
+ * @return {boolean}
168
168
  */
169
169
  Ids$1.prototype.assigned = function(id) {
170
170
  return this._seed.get(id) || false;
@@ -173,7 +173,7 @@
173
173
  /**
174
174
  * Unclaim an id.
175
175
  *
176
- * @param {String} id the id to unclaim
176
+ * @param {string} id the id to unclaim
177
177
  */
178
178
  Ids$1.prototype.unclaim = function(id) {
179
179
  delete this._seed.hats[id];
@@ -28757,11 +28757,16 @@
28757
28757
  /**
28758
28758
  * @typedef { {
28759
28759
  * index: number;
28760
- * match: boolean;
28761
- * value: string;
28762
- * } } Token
28760
+ * value: string,
28761
+ * match?: boolean;
28762
+ * start?: boolean;
28763
+ * end?: boolean;
28764
+ * wordStart?: boolean;
28765
+ * wordEnd?: boolean;
28766
+ * all?: boolean;
28767
+ * } } BaseToken
28763
28768
  *
28764
- * @typedef {Token[]} Tokens
28769
+ * @typedef { BaseToken | BaseToken[] } Token
28765
28770
  */
28766
28771
 
28767
28772
  /**
@@ -28769,7 +28774,7 @@
28769
28774
  *
28770
28775
  * @typedef { {
28771
28776
  * item: R,
28772
- * tokens: Record<string, Tokens>
28777
+ * tokens: Record<string, Token[]>
28773
28778
  * } } SearchResult
28774
28779
  */
28775
28780
 
@@ -28780,15 +28785,15 @@
28780
28785
  /**
28781
28786
  * Search items by query.
28782
28787
  *
28783
- * @template {SearchItem} T
28788
+ * @template { SearchItem } T
28784
28789
  *
28785
- * @param {T[]} items elements to search in
28786
- * @param {string} pattern pattern to search for
28790
+ * @param { T[] } items elements to search in
28791
+ * @param { string } pattern pattern to search for
28787
28792
  * @param { {
28788
28793
  * keys: string[];
28789
28794
  * } } options
28790
28795
  *
28791
- * @returns {SearchResult<T>[]}
28796
+ * @returns { SearchResult<T>[] }
28792
28797
  */
28793
28798
  function search(items, pattern, options) {
28794
28799
 
@@ -28804,7 +28809,7 @@
28804
28809
 
28805
28810
  const words = pattern.trim().toLowerCase().split(/\s+/);
28806
28811
 
28807
- return items.flatMap((item) => {
28812
+ return items.flatMap((/** @type {T} */ item) => {
28808
28813
  const tokens = matchItem(item, words, keys);
28809
28814
 
28810
28815
  if (!tokens) {
@@ -28821,11 +28826,11 @@
28821
28826
  /**
28822
28827
  * Match an item and return tokens in case of a match.
28823
28828
  *
28824
- * @param {SearchItem} item element to be matched
28825
- * @param {string[]} words words from search pattern to find
28826
- * @param {string[]} keys keys to search in the item
28829
+ * @param { SearchItem } item element to be matched
28830
+ * @param { string[] } words words from search pattern to find
28831
+ * @param { string[] } keys keys to search in the item
28827
28832
  *
28828
- * @returns {Record<string, Tokens>}
28833
+ * @returns { Record<string, Token[]> | null }
28829
28834
  */
28830
28835
  function matchItem(item, words, keys) {
28831
28836
 
@@ -28852,8 +28857,8 @@
28852
28857
  };
28853
28858
  },
28854
28859
  {
28855
- matchedWords: {},
28856
- tokens: []
28860
+ matchedWords: /** @type { Record<string, boolean> } */ ({}),
28861
+ tokens: /** @type { Token[] } */ ([])
28857
28862
  }
28858
28863
  )
28859
28864
  ) : (
@@ -28886,15 +28891,17 @@
28886
28891
  /**
28887
28892
  * Creates a compare function that can be used in Array.sort() based on a custom scoring function
28888
28893
  *
28889
- * @param {string[]} keys
28894
+ * @template {SearchItem} T
28890
28895
  *
28891
- * @returns { (resultA: SearchResult, resultB: SearchResult) => number}
28896
+ * @param { string[] } keys
28897
+ *
28898
+ * @returns { (resultA: SearchResult<T>, resultB: SearchResult<T>) => number }
28892
28899
  */
28893
28900
  function createResultSorter(keys) {
28894
28901
 
28895
28902
  /**
28896
- * @param {SearchResult} resultA
28897
- * @param {SearchResult} resultB
28903
+ * @param { SearchResult<T> } resultA
28904
+ * @param { SearchResult<T> } resultB
28898
28905
  */
28899
28906
  return (resultA, resultB) => {
28900
28907
  let comparison = 0;
@@ -28911,7 +28918,7 @@
28911
28918
 
28912
28919
  if (tokenComparison !== 0) {
28913
28920
  comparison += tokenComparison * modifier;
28914
- modifier *= 0.9;
28921
+ modifier *= DECAY_MODIFIER;
28915
28922
  continue;
28916
28923
  }
28917
28924
 
@@ -28922,7 +28929,7 @@
28922
28929
 
28923
28930
  if (stringComparison !== 0) {
28924
28931
  comparison += stringComparison * modifier;
28925
- modifier *= 0.9;
28932
+ modifier *= DECAY_MODIFIER;
28926
28933
  continue;
28927
28934
  }
28928
28935
  }
@@ -28935,21 +28942,43 @@
28935
28942
  /**
28936
28943
  * Compares two token arrays.
28937
28944
  *
28938
- * @param {Token[]} [tokensA]
28939
- * @param {Token[]} [tokensB]
28945
+ * @param { Token[] } tokensA
28946
+ * @param { Token[] } tokensB
28940
28947
  *
28941
- * @returns {number}
28948
+ * @returns { number }
28942
28949
  */
28943
28950
  function compareTokens(tokensA, tokensB) {
28944
28951
  return scoreTokens(tokensB) - scoreTokens(tokensA);
28945
28952
  }
28946
28953
 
28954
+ const DECAY_MODIFIER = 0.5;
28955
+
28956
+ const TOKEN_MATCH_SCORES = {
28957
+ FULL: 131.9,
28958
+ START_FULL_WORD: 8.0,
28959
+ START_WORD_PART: 7.87,
28960
+ WORD_START: 2.19,
28961
+ WORD_PART: 1,
28962
+ NO_MATCH: -0.07
28963
+ };
28964
+
28947
28965
  /**
28948
28966
  * @param { Token[] } tokens
28949
28967
  * @returns { number }
28950
28968
  */
28951
28969
  function scoreTokens(tokens) {
28952
- return tokens.reduce((sum, token) => sum + scoreToken(token), 0);
28970
+ const baseScore = tokens.reduce((sum, token) => sum + scoreToken(token), 0);
28971
+
28972
+ const flatTokens = tokens.flat();
28973
+
28974
+ const totalLength = flatTokens.reduce((sum, token) => sum + token.value.length, 0);
28975
+ const matchedLength = flatTokens.reduce((sum, token) => sum + (token.match ? token.value.length : 0), 0);
28976
+
28977
+ const density = totalLength ? matchedLength / totalLength : 0;
28978
+
28979
+ const score = baseScore * (1 + density);
28980
+
28981
+ return score;
28953
28982
  }
28954
28983
 
28955
28984
  /**
@@ -28968,28 +28997,30 @@
28968
28997
  const modifier = Math.log(token.value.length);
28969
28998
 
28970
28999
  if (!token.match) {
28971
- return -0.07 * modifier;
29000
+ return TOKEN_MATCH_SCORES.NO_MATCH * modifier;
28972
29001
  }
28973
29002
 
28974
29003
  return (
28975
29004
  token.start
28976
29005
  ? (
28977
29006
  token.end
28978
- ? 131.9
28979
- : 7.87
29007
+ ? TOKEN_MATCH_SCORES.FULL
29008
+ : token.wordEnd
29009
+ ? TOKEN_MATCH_SCORES.START_FULL_WORD
29010
+ : TOKEN_MATCH_SCORES.START_WORD_PART
28980
29011
  )
28981
29012
  : (
28982
29013
  token.wordStart
28983
- ? 2.19
28984
- : 1
29014
+ ? TOKEN_MATCH_SCORES.WORD_START
29015
+ : TOKEN_MATCH_SCORES.WORD_PART
28985
29016
  )
28986
29017
  ) * modifier;
28987
29018
  }
28988
29019
 
28989
29020
  /**
28990
- * @param {string|string[]} [str='']
29021
+ * @param { string|string[] } [str='']
28991
29022
  *
28992
- * @return {string}
29023
+ * @return { string }
28993
29024
  */
28994
29025
  function stringJoin(str = '') {
28995
29026
  return isArray$2(str) ? str.join(', ') : str;
@@ -28998,10 +29029,10 @@
28998
29029
  /**
28999
29030
  * Compares two strings. also supports string arrays, which will be joined
29000
29031
  *
29001
- * @param {string|string[]} [a]
29002
- * @param {string|string[]} [b]
29032
+ * @param { string|string[] } [a]
29033
+ * @param { string|string[] } [b]
29003
29034
  *
29004
- * @returns {number}
29035
+ * @returns { number }
29005
29036
  */
29006
29037
  function compareStrings(a, b) {
29007
29038
  return stringJoin(a).localeCompare(stringJoin(b));
@@ -29011,11 +29042,11 @@
29011
29042
  * Match a given string against a set of words,
29012
29043
  * and return the result.
29013
29044
  *
29014
- * @param {string} string
29015
- * @param {string[]} words
29045
+ * @param { string } string
29046
+ * @param { string[] } words
29016
29047
  *
29017
29048
  * @return { {
29018
- * tokens: Token[],
29049
+ * tokens: BaseToken[],
29019
29050
  * matchedWords: Record<string, boolean>
29020
29051
  * } }
29021
29052
  */
@@ -29028,7 +29059,14 @@
29028
29059
  };
29029
29060
  }
29030
29061
 
29062
+ /**
29063
+ * @type { BaseToken[] }
29064
+ */
29031
29065
  const tokens = [];
29066
+
29067
+ /**
29068
+ * @type { Record<string, boolean> }
29069
+ */
29032
29070
  const matchedWords = {};
29033
29071
 
29034
29072
  const wordsEscaped = words.map(escapeRegexp);
@@ -29053,7 +29091,7 @@
29053
29091
  const start = startIndex === 0;
29054
29092
  const end = endIndex === string.length;
29055
29093
 
29056
- const all = !!match.groups.all;
29094
+ const all = !!match.groups?.all;
29057
29095
 
29058
29096
  const wordStart = start || /\s/.test(string.charAt(startIndex - 1));
29059
29097
  const wordEnd = end || /\s/.test(string.charAt(endIndex));
@@ -29102,6 +29140,13 @@
29102
29140
  };
29103
29141
  }
29104
29142
 
29143
+ /**
29144
+ * Escape string to not contain illegal regexp chars.
29145
+ *
29146
+ * @param { string } string
29147
+ *
29148
+ * @return { string }
29149
+ */
29105
29150
  function escapeRegexp(string) {
29106
29151
  return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
29107
29152
  }