@ktjs/shared 0.23.7 → 0.23.10

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/dist/index.d.ts CHANGED
@@ -5,6 +5,10 @@ declare global {
5
5
  interface Comment {
6
6
  kisFragmentAnchor: boolean;
7
7
  kFragmentList: Node[];
8
+ kredraw: () => void;
9
+ kchildrenRef: {
10
+ value: any[];
11
+ };
8
12
  }
9
13
  }
10
14
 
@@ -138,6 +142,8 @@ declare const $applyModel: (element: HTMLElementTagNameMap[InputElementTag], val
138
142
  * Default empty function
139
143
  */
140
144
  declare const $emptyFn: (...args: any[]) => any;
145
+ declare const $emptyArray: any[];
146
+ declare const $emptyObject: any;
141
147
  declare const $isSame: (a: unknown, b: unknown) => boolean;
142
148
  /**
143
149
  * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
@@ -183,5 +189,5 @@ declare global {
183
189
  const $debug: typeof console.debug;
184
190
  }
185
191
 
186
- export { $ArrayFrom, $append, $appendChild, $applyModel, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $forEach, $forEachAsync, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $parseStyle, $random, $replaceNode, $toString, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery };
192
+ export { $ArrayFrom, $append, $appendChild, $applyModel, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyArray, $emptyFn, $emptyObject, $entries, $forEach, $forEachAsync, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $parseStyle, $random, $replaceNode, $toString, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery };
187
193
  export type { ChangeHandler, ChangeTriggerField, HTMLTag, InputElementTag, MathMLTag, NoTextNodeTag, NonSpecialTags, SVGTag, otherstring };
@@ -21,10 +21,44 @@ var __ktjs_shared__ = (function (exports) {
21
21
  };
22
22
  }
23
23
 
24
+ // String manipulation utilities
25
+ /**
26
+ * Default empty function
27
+ */
28
+ const $emptyFn = (() => true);
29
+ const $emptyArray = [];
30
+ const $emptyObject = Object.create(null);
31
+ const $isSame = (a, b) => {
32
+ if ($isArray(a)) {
33
+ return true; // always trigger an array
34
+ }
35
+ return $is(a, b);
36
+ };
37
+ /**
38
+ * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
39
+ */
40
+ const $forEach = (array, callback) => {
41
+ const len = array.length;
42
+ for (let i = 0; i < len; i++) {
43
+ callback(array[i], i, array);
44
+ }
45
+ };
46
+ /**
47
+ * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
48
+ */
49
+ const $forEachAsync = async (array, callback) => {
50
+ const len = array.length;
51
+ for (let i = 0; i < len; i++) {
52
+ await callback(array[i], i, array);
53
+ }
54
+ };
55
+
56
+ const $emptyChildrenRef = { value: $emptyArray };
24
57
  // each instance shares the same empty array, but it will be replaced when used
25
- const emptyArray = [];
26
58
  Comment.prototype.kisFragmentAnchor = false;
27
- Comment.prototype.kFragmentList = emptyArray;
59
+ Comment.prototype.kFragmentList = $emptyArray;
60
+ Comment.prototype.kredraw = $emptyFn;
61
+ Comment.prototype.kchildrenRef = $emptyChildrenRef;
28
62
 
29
63
  // Shared constants
30
64
  // Empty for now - can be extended with framework-wide constants
@@ -120,36 +154,6 @@ var __ktjs_shared__ = (function (exports) {
120
154
  element.addEventListener(eventName, () => (valueRef.value = element[propName]));
121
155
  };
122
156
 
123
- // String manipulation utilities
124
- /**
125
- * Default empty function
126
- */
127
- const $emptyFn = (() => true);
128
- const $isSame = (a, b) => {
129
- if ($isArray(a)) {
130
- return true; // always trigger an array
131
- }
132
- return $is(a, b);
133
- };
134
- /**
135
- * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
136
- */
137
- const $forEach = (array, callback) => {
138
- const len = array.length;
139
- for (let i = 0; i < len; i++) {
140
- callback(array[i], i, array);
141
- }
142
- };
143
- /**
144
- * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
145
- */
146
- const $forEachAsync = async (array, callback) => {
147
- const len = array.length;
148
- for (let i = 0; i < len; i++) {
149
- await callback(array[i], i, array);
150
- }
151
- };
152
-
153
157
  /**
154
158
  * Normalize path by joining parts and ensuring leading slash
155
159
  */
@@ -224,7 +228,7 @@ var __ktjs_shared__ = (function (exports) {
224
228
  };
225
229
 
226
230
  // incase that symbol is not supported
227
- Object.defineProperty(window, '__ktjs__', { value: '0.23.7' });
231
+ Object.defineProperty(window, '__ktjs__', { value: '0.23.10' });
228
232
 
229
233
  exports.$ArrayFrom = $ArrayFrom;
230
234
  exports.$append = $append;
@@ -235,7 +239,9 @@ var __ktjs_shared__ = (function (exports) {
235
239
  exports.$buttonDisabledSetter = $buttonDisabledSetter;
236
240
  exports.$define = $define;
237
241
  exports.$defines = $defines;
242
+ exports.$emptyArray = $emptyArray;
238
243
  exports.$emptyFn = $emptyFn;
244
+ exports.$emptyObject = $emptyObject;
239
245
  exports.$entries = $entries;
240
246
  exports.$forEach = $forEach;
241
247
  exports.$forEachAsync = $forEachAsync;
@@ -21,110 +21,6 @@ var __ktjs_shared__ = (function (exports) {
21
21
  };
22
22
  }
23
23
 
24
- // each instance shares the same empty array, but it will be replaced when used
25
- var emptyArray = [];
26
- Comment.prototype.kisFragmentAnchor = false;
27
- Comment.prototype.kFragmentList = emptyArray;
28
-
29
- // Shared constants
30
- // Empty for now - can be extended with framework-wide constants
31
- /**
32
- * Mark the attribute as SVG to handle special cases during rendering.
33
- */
34
- var SVG_ATTR_FLAG = '__kt_svg__';
35
- /**
36
- * Mark the attribute as MathML to handle special cases during rendering.
37
- */
38
- var MATHML_ATTR_FLAG = '__kt_mathml__';
39
- /**
40
- * Can be if, else, else-if.
41
- */
42
- var DIRV_TYPE = Symbol('kt-directive-type');
43
-
44
- // DOM manipulation utilities
45
- var _a;
46
- // # dom natives
47
- var $isNode = function (x) { return (x === null || x === void 0 ? void 0 : x.nodeType) > 0; };
48
- /**
49
- * Safe replace `oldNode` With `newNode`
50
- */
51
- var $replaceNode = function (oldNode, newNode) {
52
- if ($isNode(oldNode) && $isNode(newNode)) {
53
- if (newNode.contains(oldNode)) {
54
- newNode.remove();
55
- }
56
- oldNode.replaceWith(newNode);
57
- }
58
- };
59
- /**
60
- * & Remove `bind` because it is shockingly slower than wrapper
61
- * & `window.document` is safe because it is not configurable and its setter is undefined
62
- */
63
- var $appendChild = HTMLElement.prototype.appendChild;
64
- var originAppend = HTMLElement.prototype.append;
65
- var $append = // for ie 9/10/11
66
- typeof originAppend === 'function'
67
- ? originAppend
68
- : function () {
69
- var nodes = [];
70
- for (var _i = 0; _i < arguments.length; _i++) {
71
- nodes[_i] = arguments[_i];
72
- }
73
- if (nodes.length < 50) {
74
- for (var i = 0; i < nodes.length; i++) {
75
- var node = nodes[i];
76
- if (typeof node === 'string') {
77
- $appendChild.call(this, document.createTextNode(node));
78
- }
79
- else {
80
- $appendChild.call(this, node);
81
- }
82
- }
83
- }
84
- else {
85
- var fragment = document.createDocumentFragment();
86
- for (var i = 0; i < nodes.length; i++) {
87
- var node = nodes[i];
88
- if (typeof node === 'string') {
89
- $appendChild.call(fragment, document.createTextNode(node));
90
- }
91
- else {
92
- $appendChild.call(fragment, node);
93
- }
94
- }
95
- $appendChild.call(this, fragment);
96
- }
97
- };
98
- var $buttonDisabledGetter = (_a = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled'), _a.get), $buttonDisabledSetter = _a.set;
99
- var $parseStyle = function (style) {
100
- if (!style) {
101
- return '';
102
- }
103
- if (typeof style === 'string') {
104
- return style;
105
- }
106
- if (style && typeof style === 'object') {
107
- if (style.isKT) {
108
- return $parseStyle(style.value);
109
- }
110
- return $entries(style)
111
- .map(function (entry) {
112
- var cssKey = entry[0].replace(/[A-Z]/g, function (m) { return "-".concat(m.toLowerCase()); });
113
- return "".concat(cssKey, ":").concat(entry[1]);
114
- })
115
- .join(';');
116
- }
117
- return '';
118
- };
119
- /**
120
- * Used for `k-model`
121
- */
122
- var $applyModel = function (element, valueRef, propName, eventName) {
123
- element[propName] = valueRef.value; // initialize
124
- valueRef.addOnChange(function (newValue) { return (element[propName] = newValue); });
125
- element.addEventListener(eventName, function () { return (valueRef.value = element[propName]); });
126
- };
127
-
128
24
  /******************************************************************************
129
25
  Copyright (c) Microsoft Corporation.
130
26
 
@@ -190,6 +86,8 @@ var __ktjs_shared__ = (function (exports) {
190
86
  * Default empty function
191
87
  */
192
88
  var $emptyFn = (function () { return true; });
89
+ var $emptyArray = [];
90
+ var $emptyObject = Object.create(null);
193
91
  var $isSame = function (a, b) {
194
92
  if ($isArray(a)) {
195
93
  return true; // always trigger an array
@@ -230,6 +128,112 @@ var __ktjs_shared__ = (function (exports) {
230
128
  });
231
129
  }); };
232
130
 
131
+ var $emptyChildrenRef = { value: $emptyArray };
132
+ // each instance shares the same empty array, but it will be replaced when used
133
+ Comment.prototype.kisFragmentAnchor = false;
134
+ Comment.prototype.kFragmentList = $emptyArray;
135
+ Comment.prototype.kredraw = $emptyFn;
136
+ Comment.prototype.kchildrenRef = $emptyChildrenRef;
137
+
138
+ // Shared constants
139
+ // Empty for now - can be extended with framework-wide constants
140
+ /**
141
+ * Mark the attribute as SVG to handle special cases during rendering.
142
+ */
143
+ var SVG_ATTR_FLAG = '__kt_svg__';
144
+ /**
145
+ * Mark the attribute as MathML to handle special cases during rendering.
146
+ */
147
+ var MATHML_ATTR_FLAG = '__kt_mathml__';
148
+ /**
149
+ * Can be if, else, else-if.
150
+ */
151
+ var DIRV_TYPE = Symbol('kt-directive-type');
152
+
153
+ // DOM manipulation utilities
154
+ var _a;
155
+ // # dom natives
156
+ var $isNode = function (x) { return (x === null || x === void 0 ? void 0 : x.nodeType) > 0; };
157
+ /**
158
+ * Safe replace `oldNode` With `newNode`
159
+ */
160
+ var $replaceNode = function (oldNode, newNode) {
161
+ if ($isNode(oldNode) && $isNode(newNode)) {
162
+ if (newNode.contains(oldNode)) {
163
+ newNode.remove();
164
+ }
165
+ oldNode.replaceWith(newNode);
166
+ }
167
+ };
168
+ /**
169
+ * & Remove `bind` because it is shockingly slower than wrapper
170
+ * & `window.document` is safe because it is not configurable and its setter is undefined
171
+ */
172
+ var $appendChild = HTMLElement.prototype.appendChild;
173
+ var originAppend = HTMLElement.prototype.append;
174
+ var $append = // for ie 9/10/11
175
+ typeof originAppend === 'function'
176
+ ? originAppend
177
+ : function () {
178
+ var nodes = [];
179
+ for (var _i = 0; _i < arguments.length; _i++) {
180
+ nodes[_i] = arguments[_i];
181
+ }
182
+ if (nodes.length < 50) {
183
+ for (var i = 0; i < nodes.length; i++) {
184
+ var node = nodes[i];
185
+ if (typeof node === 'string') {
186
+ $appendChild.call(this, document.createTextNode(node));
187
+ }
188
+ else {
189
+ $appendChild.call(this, node);
190
+ }
191
+ }
192
+ }
193
+ else {
194
+ var fragment = document.createDocumentFragment();
195
+ for (var i = 0; i < nodes.length; i++) {
196
+ var node = nodes[i];
197
+ if (typeof node === 'string') {
198
+ $appendChild.call(fragment, document.createTextNode(node));
199
+ }
200
+ else {
201
+ $appendChild.call(fragment, node);
202
+ }
203
+ }
204
+ $appendChild.call(this, fragment);
205
+ }
206
+ };
207
+ var $buttonDisabledGetter = (_a = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled'), _a.get), $buttonDisabledSetter = _a.set;
208
+ var $parseStyle = function (style) {
209
+ if (!style) {
210
+ return '';
211
+ }
212
+ if (typeof style === 'string') {
213
+ return style;
214
+ }
215
+ if (style && typeof style === 'object') {
216
+ if (style.isKT) {
217
+ return $parseStyle(style.value);
218
+ }
219
+ return $entries(style)
220
+ .map(function (entry) {
221
+ var cssKey = entry[0].replace(/[A-Z]/g, function (m) { return "-".concat(m.toLowerCase()); });
222
+ return "".concat(cssKey, ":").concat(entry[1]);
223
+ })
224
+ .join(';');
225
+ }
226
+ return '';
227
+ };
228
+ /**
229
+ * Used for `k-model`
230
+ */
231
+ var $applyModel = function (element, valueRef, propName, eventName) {
232
+ element[propName] = valueRef.value; // initialize
233
+ valueRef.addOnChange(function (newValue) { return (element[propName] = newValue); });
234
+ element.addEventListener(eventName, function () { return (valueRef.value = element[propName]); });
235
+ };
236
+
233
237
  /**
234
238
  * Normalize path by joining parts and ensuring leading slash
235
239
  */
@@ -309,7 +313,7 @@ var __ktjs_shared__ = (function (exports) {
309
313
  };
310
314
 
311
315
  // incase that symbol is not supported
312
- Object.defineProperty(window, '__ktjs__', { value: '0.23.7' });
316
+ Object.defineProperty(window, '__ktjs__', { value: '0.23.10' });
313
317
 
314
318
  exports.$ArrayFrom = $ArrayFrom;
315
319
  exports.$append = $append;
@@ -320,7 +324,9 @@ var __ktjs_shared__ = (function (exports) {
320
324
  exports.$buttonDisabledSetter = $buttonDisabledSetter;
321
325
  exports.$define = $define;
322
326
  exports.$defines = $defines;
327
+ exports.$emptyArray = $emptyArray;
323
328
  exports.$emptyFn = $emptyFn;
329
+ exports.$emptyObject = $emptyObject;
324
330
  exports.$entries = $entries;
325
331
  exports.$forEach = $forEach;
326
332
  exports.$forEachAsync = $forEachAsync;
package/dist/index.mjs CHANGED
@@ -18,10 +18,44 @@ if (typeof Symbol === 'undefined') {
18
18
  };
19
19
  }
20
20
 
21
+ // String manipulation utilities
22
+ /**
23
+ * Default empty function
24
+ */
25
+ const $emptyFn = (() => true);
26
+ const $emptyArray = [];
27
+ const $emptyObject = Object.create(null);
28
+ const $isSame = (a, b) => {
29
+ if ($isArray(a)) {
30
+ return true; // always trigger an array
31
+ }
32
+ return $is(a, b);
33
+ };
34
+ /**
35
+ * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
36
+ */
37
+ const $forEach = (array, callback) => {
38
+ const len = array.length;
39
+ for (let i = 0; i < len; i++) {
40
+ callback(array[i], i, array);
41
+ }
42
+ };
43
+ /**
44
+ * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
45
+ */
46
+ const $forEachAsync = async (array, callback) => {
47
+ const len = array.length;
48
+ for (let i = 0; i < len; i++) {
49
+ await callback(array[i], i, array);
50
+ }
51
+ };
52
+
53
+ const $emptyChildrenRef = { value: $emptyArray };
21
54
  // each instance shares the same empty array, but it will be replaced when used
22
- const emptyArray = [];
23
55
  Comment.prototype.kisFragmentAnchor = false;
24
- Comment.prototype.kFragmentList = emptyArray;
56
+ Comment.prototype.kFragmentList = $emptyArray;
57
+ Comment.prototype.kredraw = $emptyFn;
58
+ Comment.prototype.kchildrenRef = $emptyChildrenRef;
25
59
 
26
60
  // Shared constants
27
61
  // Empty for now - can be extended with framework-wide constants
@@ -117,36 +151,6 @@ const $applyModel = (element, valueRef, propName, eventName) => {
117
151
  element.addEventListener(eventName, () => (valueRef.value = element[propName]));
118
152
  };
119
153
 
120
- // String manipulation utilities
121
- /**
122
- * Default empty function
123
- */
124
- const $emptyFn = (() => true);
125
- const $isSame = (a, b) => {
126
- if ($isArray(a)) {
127
- return true; // always trigger an array
128
- }
129
- return $is(a, b);
130
- };
131
- /**
132
- * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
133
- */
134
- const $forEach = (array, callback) => {
135
- const len = array.length;
136
- for (let i = 0; i < len; i++) {
137
- callback(array[i], i, array);
138
- }
139
- };
140
- /**
141
- * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
142
- */
143
- const $forEachAsync = async (array, callback) => {
144
- const len = array.length;
145
- for (let i = 0; i < len; i++) {
146
- await callback(array[i], i, array);
147
- }
148
- };
149
-
150
154
  /**
151
155
  * Normalize path by joining parts and ensuring leading slash
152
156
  */
@@ -221,6 +225,6 @@ const extractParams = (pattern, path) => {
221
225
  };
222
226
 
223
227
  // incase that symbol is not supported
224
- Object.defineProperty(window, '__ktjs__', { value: '0.23.7' });
228
+ Object.defineProperty(window, '__ktjs__', { value: '0.23.10' });
225
229
 
226
- export { $ArrayFrom, $append, $appendChild, $applyModel, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $forEach, $forEachAsync, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $parseStyle, $random, $replaceNode, $toString, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery };
230
+ export { $ArrayFrom, $append, $appendChild, $applyModel, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyArray, $emptyFn, $emptyObject, $entries, $forEach, $forEachAsync, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $parseStyle, $random, $replaceNode, $toString, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/shared",
3
- "version": "0.23.7",
3
+ "version": "0.23.10",
4
4
  "description": "Shared utilities and cached native methods for kt.js framework",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",