@ckeditor/ckeditor5-utils 40.0.0 → 40.2.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.
Files changed (135) hide show
  1. package/CHANGELOG.md +26 -26
  2. package/LICENSE.md +3 -3
  3. package/package.json +1 -1
  4. package/src/abortabledebounce.d.ts +17 -0
  5. package/src/abortabledebounce.js +22 -0
  6. package/src/areconnectedthroughproperties.d.ts +11 -11
  7. package/src/areconnectedthroughproperties.js +73 -73
  8. package/src/ckeditorerror.d.ts +123 -123
  9. package/src/ckeditorerror.js +176 -176
  10. package/src/collection.d.ts +433 -427
  11. package/src/collection.js +583 -575
  12. package/src/comparearrays.d.ts +30 -30
  13. package/src/comparearrays.js +47 -47
  14. package/src/config.d.ts +163 -163
  15. package/src/config.js +163 -162
  16. package/src/count.d.ts +18 -18
  17. package/src/count.js +24 -24
  18. package/src/delay.d.ts +19 -19
  19. package/src/delay.js +26 -26
  20. package/src/diff.d.ts +31 -31
  21. package/src/diff.js +115 -115
  22. package/src/difftochanges.d.ts +59 -59
  23. package/src/difftochanges.js +79 -79
  24. package/src/dom/createelement.d.ts +57 -57
  25. package/src/dom/createelement.js +40 -40
  26. package/src/dom/emittermixin.d.ts +142 -142
  27. package/src/dom/emittermixin.js +239 -239
  28. package/src/dom/findclosestscrollableancestor.d.ts +11 -11
  29. package/src/dom/findclosestscrollableancestor.js +31 -31
  30. package/src/dom/getancestors.d.ts +17 -17
  31. package/src/dom/getancestors.js +27 -27
  32. package/src/dom/getborderwidths.d.ts +24 -24
  33. package/src/dom/getborderwidths.js +24 -24
  34. package/src/dom/getcommonancestor.d.ts +12 -12
  35. package/src/dom/getcommonancestor.js +25 -25
  36. package/src/dom/getdatafromelement.d.ts +14 -14
  37. package/src/dom/getdatafromelement.js +20 -20
  38. package/src/dom/getpositionedancestor.d.ts +10 -10
  39. package/src/dom/getpositionedancestor.js +22 -22
  40. package/src/dom/global.d.ts +32 -32
  41. package/src/dom/global.js +35 -35
  42. package/src/dom/indexof.d.ts +14 -14
  43. package/src/dom/indexof.js +21 -21
  44. package/src/dom/insertat.d.ts +15 -15
  45. package/src/dom/insertat.js +17 -17
  46. package/src/dom/iscomment.d.ts +11 -11
  47. package/src/dom/iscomment.js +14 -14
  48. package/src/dom/isnode.d.ts +11 -11
  49. package/src/dom/isnode.js +21 -21
  50. package/src/dom/isrange.d.ts +11 -11
  51. package/src/dom/isrange.js +13 -13
  52. package/src/dom/istext.d.ts +11 -11
  53. package/src/dom/istext.js +13 -13
  54. package/src/dom/isvalidattributename.d.ts +10 -10
  55. package/src/dom/isvalidattributename.js +22 -22
  56. package/src/dom/isvisible.d.ts +18 -18
  57. package/src/dom/isvisible.js +20 -20
  58. package/src/dom/iswindow.d.ts +11 -11
  59. package/src/dom/iswindow.js +22 -22
  60. package/src/dom/position.d.ts +211 -211
  61. package/src/dom/position.js +313 -313
  62. package/src/dom/rect.d.ts +195 -195
  63. package/src/dom/rect.js +474 -474
  64. package/src/dom/remove.d.ts +13 -13
  65. package/src/dom/remove.js +18 -18
  66. package/src/dom/resizeobserver.d.ts +74 -74
  67. package/src/dom/resizeobserver.js +126 -126
  68. package/src/dom/scroll.d.ts +73 -73
  69. package/src/dom/scroll.js +383 -383
  70. package/src/dom/setdatainelement.d.ts +14 -14
  71. package/src/dom/setdatainelement.js +20 -20
  72. package/src/dom/tounit.d.ts +22 -22
  73. package/src/dom/tounit.js +16 -16
  74. package/src/elementreplacer.d.ts +31 -31
  75. package/src/elementreplacer.js +43 -43
  76. package/src/emittermixin.d.ts +312 -312
  77. package/src/emittermixin.js +453 -453
  78. package/src/env.d.ts +117 -117
  79. package/src/env.js +122 -122
  80. package/src/eventinfo.d.ts +58 -58
  81. package/src/eventinfo.js +26 -26
  82. package/src/fastdiff.d.ts +112 -112
  83. package/src/fastdiff.js +248 -248
  84. package/src/first.d.ts +11 -11
  85. package/src/first.js +17 -17
  86. package/src/focustracker.d.ts +75 -75
  87. package/src/focustracker.js +95 -95
  88. package/src/index.d.ts +64 -61
  89. package/src/index.js +63 -60
  90. package/src/inserttopriorityarray.d.ts +30 -30
  91. package/src/inserttopriorityarray.js +21 -21
  92. package/src/isiterable.d.ts +14 -14
  93. package/src/isiterable.js +16 -16
  94. package/src/keyboard.d.ts +126 -126
  95. package/src/keyboard.js +221 -221
  96. package/src/keystrokehandler.d.ts +87 -87
  97. package/src/keystrokehandler.js +122 -122
  98. package/src/language.d.ts +17 -17
  99. package/src/language.js +19 -19
  100. package/src/locale.d.ts +120 -120
  101. package/src/locale.js +76 -76
  102. package/src/mapsequal.d.ts +15 -15
  103. package/src/mapsequal.js +27 -27
  104. package/src/mix.d.ts +85 -85
  105. package/src/mix.js +50 -50
  106. package/src/nth.d.ts +16 -16
  107. package/src/nth.js +24 -24
  108. package/src/objecttomap.d.ts +23 -23
  109. package/src/objecttomap.js +27 -27
  110. package/src/observablemixin.d.ts +560 -560
  111. package/src/observablemixin.js +580 -580
  112. package/src/priorities.d.ts +33 -33
  113. package/src/priorities.js +23 -23
  114. package/src/retry.d.ts +33 -0
  115. package/src/retry.js +47 -0
  116. package/src/splicearray.d.ts +26 -26
  117. package/src/splicearray.js +40 -40
  118. package/src/spy.d.ts +21 -21
  119. package/src/spy.js +22 -22
  120. package/src/toarray.d.ts +25 -25
  121. package/src/toarray.js +7 -7
  122. package/src/tomap.d.ts +19 -19
  123. package/src/tomap.js +29 -29
  124. package/src/translation-service.d.ts +168 -168
  125. package/src/translation-service.js +198 -198
  126. package/src/uid.d.ts +15 -15
  127. package/src/uid.js +57 -57
  128. package/src/unicode.d.ts +54 -54
  129. package/src/unicode.js +85 -85
  130. package/src/verifylicense.d.ts +15 -15
  131. package/src/verifylicense.js +87 -87
  132. package/src/version.d.ts +10 -10
  133. package/src/version.js +153 -153
  134. package/src/wait.d.ts +16 -0
  135. package/src/wait.js +29 -0
package/src/diff.js CHANGED
@@ -1,115 +1,115 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module utils/diff
7
- */
8
- import fastDiff from './fastdiff';
9
- // The following code is based on the "O(NP) Sequence Comparison Algorithm"
10
- // by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
11
- /**
12
- * Calculates the difference between two arrays or strings producing an array containing a list of changes
13
- * necessary to transform input into output.
14
- *
15
- * ```ts
16
- * diff( 'aba', 'acca' ); // [ 'equal', 'insert', 'insert', 'delete', 'equal' ]
17
- * ```
18
- *
19
- * This function is based on the "O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
20
- * Unfortunately, while it gives the most precise results, its to complex for longer strings/arrow (above 200 items).
21
- * Therefore, `diff()` automatically switches to {@link module:utils/fastdiff~fastDiff `fastDiff()`} when detecting
22
- * such a scenario. The return formats of both functions are identical.
23
- *
24
- * @param a Input array or string.
25
- * @param b Output array or string.
26
- * @param cmp Optional function used to compare array values, by default === is used.
27
- * @returns Array of changes.
28
- */
29
- export default function diff(a, b, cmp) {
30
- // Set the comparator function.
31
- cmp = cmp || function (a, b) {
32
- return a === b;
33
- };
34
- const aLength = a.length;
35
- const bLength = b.length;
36
- // Perform `fastDiff` for longer strings/arrays (see #269).
37
- if (aLength > 200 || bLength > 200 || aLength + bLength > 300) {
38
- return diff.fastDiff(a, b, cmp, true);
39
- }
40
- // Temporary action type statics.
41
- let _insert, _delete;
42
- // Swapped the arrays to use the shorter one as the first one.
43
- if (bLength < aLength) {
44
- const tmp = a;
45
- a = b;
46
- b = tmp;
47
- // We swap the action types as well.
48
- _insert = 'delete';
49
- _delete = 'insert';
50
- }
51
- else {
52
- _insert = 'insert';
53
- _delete = 'delete';
54
- }
55
- const m = a.length;
56
- const n = b.length;
57
- const delta = n - m;
58
- // Edit scripts, for each diagonal.
59
- const es = {};
60
- // Furthest points, the furthest y we can get on each diagonal.
61
- const fp = {};
62
- function snake(k) {
63
- // We use -1 as an alternative below to handle initial values ( instead of filling the fp with -1 first ).
64
- // Furthest points (y) on the diagonal below k.
65
- const y1 = (fp[k - 1] !== undefined ? fp[k - 1] : -1) + 1;
66
- // Furthest points (y) on the diagonal above k.
67
- const y2 = fp[k + 1] !== undefined ? fp[k + 1] : -1;
68
- // The way we should go to get further.
69
- const dir = y1 > y2 ? -1 : 1;
70
- // Clone previous changes array (if any).
71
- if (es[k + dir]) {
72
- es[k] = es[k + dir].slice(0);
73
- }
74
- // Create changes array.
75
- if (!es[k]) {
76
- es[k] = [];
77
- }
78
- // Push the action.
79
- es[k].push(y1 > y2 ? _insert : _delete);
80
- // Set the beginning coordinates.
81
- let y = Math.max(y1, y2);
82
- let x = y - k;
83
- // Traverse the diagonal as long as the values match.
84
- while (x < m && y < n && cmp(a[x], b[y])) {
85
- x++;
86
- y++;
87
- // Push no change action.
88
- es[k].push('equal');
89
- }
90
- return y;
91
- }
92
- let p = 0;
93
- let k;
94
- // Traverse the graph until we reach the end of the longer string.
95
- do {
96
- // Updates furthest points and edit scripts for diagonals below delta.
97
- for (k = -p; k < delta; k++) {
98
- fp[k] = snake(k);
99
- }
100
- // Updates furthest points and edit scripts for diagonals above delta.
101
- for (k = delta + p; k > delta; k--) {
102
- fp[k] = snake(k);
103
- }
104
- // Updates furthest point and edit script for the delta diagonal.
105
- // note that the delta diagonal is the one which goes through the sink (m, n).
106
- fp[delta] = snake(delta);
107
- p++;
108
- } while (fp[delta] !== n);
109
- // Return the final list of edit changes.
110
- // We remove the first item that represents the action for the injected nulls.
111
- return es[delta].slice(1);
112
- }
113
- // Store the API in static property to easily overwrite it in tests.
114
- // Too bad dependency injection does not work in Webpack + ES 6 (const) + Babel.
115
- diff.fastDiff = fastDiff;
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module utils/diff
7
+ */
8
+ import fastDiff from './fastdiff';
9
+ // The following code is based on the "O(NP) Sequence Comparison Algorithm"
10
+ // by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
11
+ /**
12
+ * Calculates the difference between two arrays or strings producing an array containing a list of changes
13
+ * necessary to transform input into output.
14
+ *
15
+ * ```ts
16
+ * diff( 'aba', 'acca' ); // [ 'equal', 'insert', 'insert', 'delete', 'equal' ]
17
+ * ```
18
+ *
19
+ * This function is based on the "O(NP) Sequence Comparison Algorithm" by Sun Wu, Udi Manber, Gene Myers, Webb Miller.
20
+ * Unfortunately, while it gives the most precise results, its to complex for longer strings/arrow (above 200 items).
21
+ * Therefore, `diff()` automatically switches to {@link module:utils/fastdiff~fastDiff `fastDiff()`} when detecting
22
+ * such a scenario. The return formats of both functions are identical.
23
+ *
24
+ * @param a Input array or string.
25
+ * @param b Output array or string.
26
+ * @param cmp Optional function used to compare array values, by default === is used.
27
+ * @returns Array of changes.
28
+ */
29
+ export default function diff(a, b, cmp) {
30
+ // Set the comparator function.
31
+ cmp = cmp || function (a, b) {
32
+ return a === b;
33
+ };
34
+ const aLength = a.length;
35
+ const bLength = b.length;
36
+ // Perform `fastDiff` for longer strings/arrays (see #269).
37
+ if (aLength > 200 || bLength > 200 || aLength + bLength > 300) {
38
+ return diff.fastDiff(a, b, cmp, true);
39
+ }
40
+ // Temporary action type statics.
41
+ let _insert, _delete;
42
+ // Swapped the arrays to use the shorter one as the first one.
43
+ if (bLength < aLength) {
44
+ const tmp = a;
45
+ a = b;
46
+ b = tmp;
47
+ // We swap the action types as well.
48
+ _insert = 'delete';
49
+ _delete = 'insert';
50
+ }
51
+ else {
52
+ _insert = 'insert';
53
+ _delete = 'delete';
54
+ }
55
+ const m = a.length;
56
+ const n = b.length;
57
+ const delta = n - m;
58
+ // Edit scripts, for each diagonal.
59
+ const es = {};
60
+ // Furthest points, the furthest y we can get on each diagonal.
61
+ const fp = {};
62
+ function snake(k) {
63
+ // We use -1 as an alternative below to handle initial values ( instead of filling the fp with -1 first ).
64
+ // Furthest points (y) on the diagonal below k.
65
+ const y1 = (fp[k - 1] !== undefined ? fp[k - 1] : -1) + 1;
66
+ // Furthest points (y) on the diagonal above k.
67
+ const y2 = fp[k + 1] !== undefined ? fp[k + 1] : -1;
68
+ // The way we should go to get further.
69
+ const dir = y1 > y2 ? -1 : 1;
70
+ // Clone previous changes array (if any).
71
+ if (es[k + dir]) {
72
+ es[k] = es[k + dir].slice(0);
73
+ }
74
+ // Create changes array.
75
+ if (!es[k]) {
76
+ es[k] = [];
77
+ }
78
+ // Push the action.
79
+ es[k].push(y1 > y2 ? _insert : _delete);
80
+ // Set the beginning coordinates.
81
+ let y = Math.max(y1, y2);
82
+ let x = y - k;
83
+ // Traverse the diagonal as long as the values match.
84
+ while (x < m && y < n && cmp(a[x], b[y])) {
85
+ x++;
86
+ y++;
87
+ // Push no change action.
88
+ es[k].push('equal');
89
+ }
90
+ return y;
91
+ }
92
+ let p = 0;
93
+ let k;
94
+ // Traverse the graph until we reach the end of the longer string.
95
+ do {
96
+ // Updates furthest points and edit scripts for diagonals below delta.
97
+ for (k = -p; k < delta; k++) {
98
+ fp[k] = snake(k);
99
+ }
100
+ // Updates furthest points and edit scripts for diagonals above delta.
101
+ for (k = delta + p; k > delta; k--) {
102
+ fp[k] = snake(k);
103
+ }
104
+ // Updates furthest point and edit script for the delta diagonal.
105
+ // note that the delta diagonal is the one which goes through the sink (m, n).
106
+ fp[delta] = snake(delta);
107
+ p++;
108
+ } while (fp[delta] !== n);
109
+ // Return the final list of edit changes.
110
+ // We remove the first item that represents the action for the injected nulls.
111
+ return es[delta].slice(1);
112
+ }
113
+ // Store the API in static property to easily overwrite it in tests.
114
+ // Too bad dependency injection does not work in Webpack + ES 6 (const) + Babel.
115
+ diff.fastDiff = fastDiff;
@@ -1,59 +1,59 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- import type { DiffResult } from './diff';
6
- /**
7
- * @module utils/difftochanges
8
- */
9
- /**
10
- * Creates a set of changes which need to be applied to the input in order to transform
11
- * it into the output. This function can be used with strings or arrays.
12
- *
13
- * ```ts
14
- * const input = Array.from( 'abc' );
15
- * const output = Array.from( 'xaby' );
16
- * const changes = diffToChanges( diff( input, output ), output );
17
- *
18
- * changes.forEach( change => {
19
- * if ( change.type == 'insert' ) {
20
- * input.splice( change.index, 0, ...change.values );
21
- * } else if ( change.type == 'delete' ) {
22
- * input.splice( change.index, change.howMany );
23
- * }
24
- * } );
25
- *
26
- * input.join( '' ) == output.join( '' ); // -> true
27
- * ```
28
- *
29
- * @typeParam T The type of output array element.
30
- * @param diff Result of {@link module:utils/diff~diff}.
31
- * @param output The string or array which was passed as diff's output.
32
- * @returns Set of changes (insert or delete) which need to be applied to the input
33
- * in order to transform it into the output.
34
- */
35
- export default function diffToChanges<T>(diff: ReadonlyArray<DiffResult>, output: ArrayLike<T>): Array<Change<T>>;
36
- /**
37
- * An object describing insertion change.
38
- *
39
- * @typeParam T The type of output array element.
40
- */
41
- export interface InsertChange<T> {
42
- type: 'insert';
43
- index: number;
44
- values: Array<T>;
45
- }
46
- /**
47
- * An object describing deletion change.
48
- */
49
- export interface DeleteChange {
50
- type: 'delete';
51
- index: number;
52
- howMany: number;
53
- }
54
- /**
55
- * The element of the result of {@link module:utils/difftochanges~diffToChanges} function.
56
- *
57
- * @typeParam T The type of output array element.
58
- */
59
- export type Change<T> = InsertChange<T> | DeleteChange;
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import type { DiffResult } from './diff';
6
+ /**
7
+ * @module utils/difftochanges
8
+ */
9
+ /**
10
+ * Creates a set of changes which need to be applied to the input in order to transform
11
+ * it into the output. This function can be used with strings or arrays.
12
+ *
13
+ * ```ts
14
+ * const input = Array.from( 'abc' );
15
+ * const output = Array.from( 'xaby' );
16
+ * const changes = diffToChanges( diff( input, output ), output );
17
+ *
18
+ * changes.forEach( change => {
19
+ * if ( change.type == 'insert' ) {
20
+ * input.splice( change.index, 0, ...change.values );
21
+ * } else if ( change.type == 'delete' ) {
22
+ * input.splice( change.index, change.howMany );
23
+ * }
24
+ * } );
25
+ *
26
+ * input.join( '' ) == output.join( '' ); // -> true
27
+ * ```
28
+ *
29
+ * @typeParam T The type of output array element.
30
+ * @param diff Result of {@link module:utils/diff~diff}.
31
+ * @param output The string or array which was passed as diff's output.
32
+ * @returns Set of changes (insert or delete) which need to be applied to the input
33
+ * in order to transform it into the output.
34
+ */
35
+ export default function diffToChanges<T>(diff: ReadonlyArray<DiffResult>, output: ArrayLike<T>): Array<Change<T>>;
36
+ /**
37
+ * An object describing insertion change.
38
+ *
39
+ * @typeParam T The type of output array element.
40
+ */
41
+ export interface InsertChange<T> {
42
+ type: 'insert';
43
+ index: number;
44
+ values: Array<T>;
45
+ }
46
+ /**
47
+ * An object describing deletion change.
48
+ */
49
+ export interface DeleteChange {
50
+ type: 'delete';
51
+ index: number;
52
+ howMany: number;
53
+ }
54
+ /**
55
+ * The element of the result of {@link module:utils/difftochanges~diffToChanges} function.
56
+ *
57
+ * @typeParam T The type of output array element.
58
+ */
59
+ export type Change<T> = InsertChange<T> | DeleteChange;
@@ -1,79 +1,79 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * @module utils/difftochanges
7
- */
8
- /**
9
- * Creates a set of changes which need to be applied to the input in order to transform
10
- * it into the output. This function can be used with strings or arrays.
11
- *
12
- * ```ts
13
- * const input = Array.from( 'abc' );
14
- * const output = Array.from( 'xaby' );
15
- * const changes = diffToChanges( diff( input, output ), output );
16
- *
17
- * changes.forEach( change => {
18
- * if ( change.type == 'insert' ) {
19
- * input.splice( change.index, 0, ...change.values );
20
- * } else if ( change.type == 'delete' ) {
21
- * input.splice( change.index, change.howMany );
22
- * }
23
- * } );
24
- *
25
- * input.join( '' ) == output.join( '' ); // -> true
26
- * ```
27
- *
28
- * @typeParam T The type of output array element.
29
- * @param diff Result of {@link module:utils/diff~diff}.
30
- * @param output The string or array which was passed as diff's output.
31
- * @returns Set of changes (insert or delete) which need to be applied to the input
32
- * in order to transform it into the output.
33
- */
34
- export default function diffToChanges(diff, output) {
35
- const changes = [];
36
- let index = 0;
37
- let lastOperation = null;
38
- diff.forEach(change => {
39
- if (change == 'equal') {
40
- pushLast();
41
- index++;
42
- }
43
- else if (change == 'insert') {
44
- if (lastOperation && lastOperation.type == 'insert') {
45
- lastOperation.values.push(output[index]);
46
- }
47
- else {
48
- pushLast();
49
- lastOperation = {
50
- type: 'insert',
51
- index,
52
- values: [output[index]]
53
- };
54
- }
55
- index++;
56
- }
57
- else /* if ( change == 'delete' ) */ {
58
- if (lastOperation && lastOperation.type == 'delete') {
59
- lastOperation.howMany++;
60
- }
61
- else {
62
- pushLast();
63
- lastOperation = {
64
- type: 'delete',
65
- index,
66
- howMany: 1
67
- };
68
- }
69
- }
70
- });
71
- pushLast();
72
- return changes;
73
- function pushLast() {
74
- if (lastOperation) {
75
- changes.push(lastOperation);
76
- lastOperation = null;
77
- }
78
- }
79
- }
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module utils/difftochanges
7
+ */
8
+ /**
9
+ * Creates a set of changes which need to be applied to the input in order to transform
10
+ * it into the output. This function can be used with strings or arrays.
11
+ *
12
+ * ```ts
13
+ * const input = Array.from( 'abc' );
14
+ * const output = Array.from( 'xaby' );
15
+ * const changes = diffToChanges( diff( input, output ), output );
16
+ *
17
+ * changes.forEach( change => {
18
+ * if ( change.type == 'insert' ) {
19
+ * input.splice( change.index, 0, ...change.values );
20
+ * } else if ( change.type == 'delete' ) {
21
+ * input.splice( change.index, change.howMany );
22
+ * }
23
+ * } );
24
+ *
25
+ * input.join( '' ) == output.join( '' ); // -> true
26
+ * ```
27
+ *
28
+ * @typeParam T The type of output array element.
29
+ * @param diff Result of {@link module:utils/diff~diff}.
30
+ * @param output The string or array which was passed as diff's output.
31
+ * @returns Set of changes (insert or delete) which need to be applied to the input
32
+ * in order to transform it into the output.
33
+ */
34
+ export default function diffToChanges(diff, output) {
35
+ const changes = [];
36
+ let index = 0;
37
+ let lastOperation = null;
38
+ diff.forEach(change => {
39
+ if (change == 'equal') {
40
+ pushLast();
41
+ index++;
42
+ }
43
+ else if (change == 'insert') {
44
+ if (lastOperation && lastOperation.type == 'insert') {
45
+ lastOperation.values.push(output[index]);
46
+ }
47
+ else {
48
+ pushLast();
49
+ lastOperation = {
50
+ type: 'insert',
51
+ index,
52
+ values: [output[index]]
53
+ };
54
+ }
55
+ index++;
56
+ }
57
+ else /* if ( change == 'delete' ) */ {
58
+ if (lastOperation && lastOperation.type == 'delete') {
59
+ lastOperation.howMany++;
60
+ }
61
+ else {
62
+ pushLast();
63
+ lastOperation = {
64
+ type: 'delete',
65
+ index,
66
+ howMany: 1
67
+ };
68
+ }
69
+ }
70
+ });
71
+ pushLast();
72
+ return changes;
73
+ function pushLast() {
74
+ if (lastOperation) {
75
+ changes.push(lastOperation);
76
+ lastOperation = null;
77
+ }
78
+ }
79
+ }
@@ -1,57 +1,57 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
- */
5
- /**
6
- * Attributes to be applied to the HTML element.
7
- */
8
- type HTMLElementAttributes = {
9
- readonly [key: string]: string;
10
- };
11
- /**
12
- * Attributes to be applied to the SVG element.
13
- */
14
- type SVGElementAttributes = HTMLElementAttributes & {
15
- xmlns: string;
16
- };
17
- /**
18
- * Element or elements that will be added to the created element as children. Strings will be automatically turned into Text nodes.
19
- */
20
- type ChildrenElements = Node | string | Iterable<Node | string>;
21
- /**
22
- * Creates an HTML element with attributes and children elements.
23
- *
24
- * ```ts
25
- * createElement( document, 'p' ); // <p>
26
- * createElement( document, 'p', { class: 'foo' } ); // <p class="foo">
27
- * createElement( document, 'p', null, 'foo' ); // <p>foo</p>
28
- * createElement( document, 'p', null, [ createElement(...) ] ); // <p><...></p>
29
- * ```
30
- *
31
- * @label HTML_ELEMENT
32
- * @param doc Document used to create the element.
33
- * @param name Name of the HTML element.
34
- * @param attributes Object where keys represent attribute keys and values represent attribute values.
35
- * @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
36
- * @returns HTML element.
37
- */
38
- export default function createElement<T extends keyof HTMLElementTagNameMap>(doc: Document, name: T, attributes?: HTMLElementAttributes, children?: ChildrenElements): HTMLElementTagNameMap[T];
39
- /**
40
- * Creates an SVG element with attributes and children elements.
41
- *
42
- * ```ts
43
- * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' } ); // <mask>
44
- * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg', id: 'foo' } ); // <mask id="foo">
45
- * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, 'foo' ); // <mask>foo</mask>
46
- * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, [ createElement(...) ] ); // <mask><...></mask>
47
- * ```
48
- *
49
- * @label SVG_ELEMENT
50
- * @param doc Document used to create the element.
51
- * @param name Name of the SVG element.
52
- * @param attributes Object where keys represent attribute keys and values represent attribute values.
53
- * @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
54
- * @returns SVG element.
55
- */
56
- export default function createElement<T extends keyof SVGElementTagNameMap>(doc: Document, name: T, attributes: SVGElementAttributes, children?: ChildrenElements): SVGElementTagNameMap[T];
57
- export {};
1
+ /**
2
+ * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * Attributes to be applied to the HTML element.
7
+ */
8
+ type HTMLElementAttributes = {
9
+ readonly [key: string]: string;
10
+ };
11
+ /**
12
+ * Attributes to be applied to the SVG element.
13
+ */
14
+ type SVGElementAttributes = HTMLElementAttributes & {
15
+ xmlns: string;
16
+ };
17
+ /**
18
+ * Element or elements that will be added to the created element as children. Strings will be automatically turned into Text nodes.
19
+ */
20
+ type ChildrenElements = Node | string | Iterable<Node | string>;
21
+ /**
22
+ * Creates an SVG element with attributes and children elements.
23
+ *
24
+ * ```ts
25
+ * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' } ); // <mask>
26
+ * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg', id: 'foo' } ); // <mask id="foo">
27
+ * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, 'foo' ); // <mask>foo</mask>
28
+ * createElement( document, 'mask', { xmlns: 'http://www.w3.org/2000/svg' }, [ createElement(...) ] ); // <mask><...></mask>
29
+ * ```
30
+ *
31
+ * @label SVG_ELEMENT
32
+ * @param doc Document used to create the element.
33
+ * @param name Name of the SVG element.
34
+ * @param attributes Object where keys represent attribute keys and values represent attribute values.
35
+ * @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
36
+ * @returns SVG element.
37
+ */
38
+ export default function createElement<T extends keyof SVGElementTagNameMap>(doc: Document, name: T, attributes: SVGElementAttributes, children?: ChildrenElements): SVGElementTagNameMap[T];
39
+ /**
40
+ * Creates an HTML element with attributes and children elements.
41
+ *
42
+ * ```ts
43
+ * createElement( document, 'p' ); // <p>
44
+ * createElement( document, 'p', { class: 'foo' } ); // <p class="foo">
45
+ * createElement( document, 'p', null, 'foo' ); // <p>foo</p>
46
+ * createElement( document, 'p', null, [ createElement(...) ] ); // <p><...></p>
47
+ * ```
48
+ *
49
+ * @label HTML_ELEMENT
50
+ * @param doc Document used to create the element.
51
+ * @param name Name of the HTML element.
52
+ * @param attributes Object where keys represent attribute keys and values represent attribute values.
53
+ * @param children Child or any iterable of children. Strings will be automatically turned into Text nodes.
54
+ * @returns HTML element.
55
+ */
56
+ export default function createElement<T extends keyof HTMLElementTagNameMap>(doc: Document, name: T, attributes?: HTMLElementAttributes, children?: ChildrenElements): HTMLElementTagNameMap[T];
57
+ export {};