@ktjs/shared 0.23.4 → 0.23.7

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
@@ -1,3 +1,13 @@
1
+ declare global {
2
+ /**
3
+ * Extend Comment interface to include properties for fragment handling.
4
+ */
5
+ interface Comment {
6
+ kisFragmentAnchor: boolean;
7
+ kFragmentList: Node[];
8
+ }
9
+ }
10
+
1
11
  /**
2
12
  * Mark the attribute as SVG to handle special cases during rendering.
3
13
  */
@@ -114,12 +124,12 @@ declare const originAppend: (...nodes: (Node | string)[]) => void;
114
124
  declare const $append: typeof originAppend;
115
125
  declare const $buttonDisabledGetter: () => any;
116
126
  declare const $buttonDisabledSetter: (v: any) => void;
117
- declare const parseStyle: (style: unknown) => string;
127
+ declare const $parseStyle: (style: unknown) => string;
118
128
  type ChangeHandler<T = string> = (value: T, ...args: any[]) => void;
119
129
  /**
120
130
  * Used for `k-model`
121
131
  */
122
- declare const applyModel: (element: HTMLElementTagNameMap[InputElementTag], valueRef: {
132
+ declare const $applyModel: (element: HTMLElementTagNameMap[InputElementTag], valueRef: {
123
133
  value: unknown;
124
134
  addOnChange: (fn: (newValue: unknown) => void) => void;
125
135
  }, propName: "value" | "checked", eventName: "change" | "input") => void;
@@ -129,6 +139,14 @@ declare const applyModel: (element: HTMLElementTagNameMap[InputElementTag], valu
129
139
  */
130
140
  declare const $emptyFn: (...args: any[]) => any;
131
141
  declare const $isSame: (a: unknown, b: unknown) => boolean;
142
+ /**
143
+ * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
144
+ */
145
+ declare const $forEach: (array: unknown[], callback: (item: unknown, index: number, array: unknown[]) => void) => void;
146
+ /**
147
+ * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
148
+ */
149
+ declare const $forEachAsync: (array: unknown[], callback: (item: unknown, index: number, array: unknown[]) => void) => Promise<void>;
132
150
 
133
151
  /**
134
152
  * Normalize path by joining parts and ensuring leading slash
@@ -165,5 +183,5 @@ declare global {
165
183
  const $debug: typeof console.debug;
166
184
  }
167
185
 
168
- export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $random, $replaceNode, $toString, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, applyModel, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery, parseStyle };
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 };
169
187
  export type { ChangeHandler, ChangeTriggerField, HTMLTag, InputElementTag, MathMLTag, NoTextNodeTag, NonSpecialTags, SVGTag, otherstring };
@@ -1,6 +1,31 @@
1
1
  var __ktjs_shared__ = (function (exports) {
2
2
  'use strict';
3
3
 
4
+ // Cached native methods for performance optimization
5
+ const $isArray = Array.isArray;
6
+ const $ArrayFrom = Array.from;
7
+ const $is = Object.is;
8
+ const $assign = Object.assign;
9
+ const $hasOwn = Object.prototype.hasOwnProperty;
10
+ const $toString = Object.prototype.toString;
11
+ const $keys = Object.keys;
12
+ const $defines = Object.defineProperties;
13
+ const $define = Object.defineProperty;
14
+ const $entries = Object.entries;
15
+ const $random = Math.random;
16
+ const $isThenable = (o) => typeof o?.then === 'function';
17
+
18
+ if (typeof Symbol === 'undefined') {
19
+ window.Symbol = function Symbol(description) {
20
+ return `@@SYMBOL_${description || ''}_${$random().toString(36).slice(2)}`;
21
+ };
22
+ }
23
+
24
+ // each instance shares the same empty array, but it will be replaced when used
25
+ const emptyArray = [];
26
+ Comment.prototype.kisFragmentAnchor = false;
27
+ Comment.prototype.kFragmentList = emptyArray;
28
+
4
29
  // Shared constants
5
30
  // Empty for now - can be extended with framework-wide constants
6
31
  /**
@@ -16,20 +41,6 @@ var __ktjs_shared__ = (function (exports) {
16
41
  */
17
42
  const DIRV_TYPE = Symbol('kt-directive-type');
18
43
 
19
- // Cached native methods for performance optimization
20
- const $isArray = Array.isArray;
21
- const $ArrayFrom = Array.from;
22
- const $is = Object.is;
23
- const $assign = Object.assign;
24
- const $hasOwn = Object.prototype.hasOwnProperty;
25
- const $toString = Object.prototype.toString;
26
- const $keys = Object.keys;
27
- const $defines = Object.defineProperties;
28
- const $define = Object.defineProperty;
29
- const $entries = Object.entries;
30
- const $random = Math.random;
31
- const $isThenable = (o) => typeof o?.then === 'function';
32
-
33
44
  // DOM manipulation utilities
34
45
  // # dom natives
35
46
  const $isNode = (x) => x?.nodeType > 0;
@@ -80,7 +91,7 @@ var __ktjs_shared__ = (function (exports) {
80
91
  }
81
92
  };
82
93
  const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
83
- const parseStyle = (style) => {
94
+ const $parseStyle = (style) => {
84
95
  if (!style) {
85
96
  return '';
86
97
  }
@@ -89,7 +100,7 @@ var __ktjs_shared__ = (function (exports) {
89
100
  }
90
101
  if (style && typeof style === 'object') {
91
102
  if (style.isKT) {
92
- return parseStyle(style.value);
103
+ return $parseStyle(style.value);
93
104
  }
94
105
  return $entries(style)
95
106
  .map((entry) => {
@@ -103,7 +114,7 @@ var __ktjs_shared__ = (function (exports) {
103
114
  /**
104
115
  * Used for `k-model`
105
116
  */
106
- const applyModel = (element, valueRef, propName, eventName) => {
117
+ const $applyModel = (element, valueRef, propName, eventName) => {
107
118
  element[propName] = valueRef.value; // initialize
108
119
  valueRef.addOnChange((newValue) => (element[propName] = newValue));
109
120
  element.addEventListener(eventName, () => (valueRef.value = element[propName]));
@@ -120,6 +131,24 @@ var __ktjs_shared__ = (function (exports) {
120
131
  }
121
132
  return $is(a, b);
122
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
+ };
123
152
 
124
153
  /**
125
154
  * Normalize path by joining parts and ensuring leading slash
@@ -194,18 +223,13 @@ var __ktjs_shared__ = (function (exports) {
194
223
  return params;
195
224
  };
196
225
 
197
- if (typeof Symbol === 'undefined') {
198
- window.Symbol = function Symbol(description) {
199
- return `@@SYMBOL_${description || ''}_${$random().toString(36).slice(2)}`;
200
- };
201
- }
202
-
203
- // Shared utilities and cached native methods for kt.js framework
204
- Object.defineProperty(window, '__ktjs__', { value: '0.23.4' });
226
+ // incase that symbol is not supported
227
+ Object.defineProperty(window, '__ktjs__', { value: '0.23.7' });
205
228
 
206
229
  exports.$ArrayFrom = $ArrayFrom;
207
230
  exports.$append = $append;
208
231
  exports.$appendChild = $appendChild;
232
+ exports.$applyModel = $applyModel;
209
233
  exports.$assign = $assign;
210
234
  exports.$buttonDisabledGetter = $buttonDisabledGetter;
211
235
  exports.$buttonDisabledSetter = $buttonDisabledSetter;
@@ -213,6 +237,8 @@ var __ktjs_shared__ = (function (exports) {
213
237
  exports.$defines = $defines;
214
238
  exports.$emptyFn = $emptyFn;
215
239
  exports.$entries = $entries;
240
+ exports.$forEach = $forEach;
241
+ exports.$forEachAsync = $forEachAsync;
216
242
  exports.$hasOwn = $hasOwn;
217
243
  exports.$is = $is;
218
244
  exports.$isArray = $isArray;
@@ -220,19 +246,18 @@ var __ktjs_shared__ = (function (exports) {
220
246
  exports.$isSame = $isSame;
221
247
  exports.$isThenable = $isThenable;
222
248
  exports.$keys = $keys;
249
+ exports.$parseStyle = $parseStyle;
223
250
  exports.$random = $random;
224
251
  exports.$replaceNode = $replaceNode;
225
252
  exports.$toString = $toString;
226
253
  exports.DIRV_TYPE = DIRV_TYPE;
227
254
  exports.MATHML_ATTR_FLAG = MATHML_ATTR_FLAG;
228
255
  exports.SVG_ATTR_FLAG = SVG_ATTR_FLAG;
229
- exports.applyModel = applyModel;
230
256
  exports.buildQuery = buildQuery;
231
257
  exports.emplaceParams = emplaceParams;
232
258
  exports.extractParams = extractParams;
233
259
  exports.normalizePath = normalizePath;
234
260
  exports.parseQuery = parseQuery;
235
- exports.parseStyle = parseStyle;
236
261
 
237
262
  return exports;
238
263
 
@@ -1,6 +1,31 @@
1
1
  var __ktjs_shared__ = (function (exports) {
2
2
  'use strict';
3
3
 
4
+ // Cached native methods for performance optimization
5
+ var $isArray = Array.isArray;
6
+ var $ArrayFrom = Array.from;
7
+ var $is = Object.is;
8
+ var $assign = Object.assign;
9
+ var $hasOwn = Object.prototype.hasOwnProperty;
10
+ var $toString = Object.prototype.toString;
11
+ var $keys = Object.keys;
12
+ var $defines = Object.defineProperties;
13
+ var $define = Object.defineProperty;
14
+ var $entries = Object.entries;
15
+ var $random = Math.random;
16
+ var $isThenable = function (o) { return typeof (o === null || o === void 0 ? void 0 : o.then) === 'function'; };
17
+
18
+ if (typeof Symbol === 'undefined') {
19
+ window.Symbol = function Symbol(description) {
20
+ return "@@SYMBOL_".concat(description || '', "_").concat($random().toString(36).slice(2));
21
+ };
22
+ }
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
+
4
29
  // Shared constants
5
30
  // Empty for now - can be extended with framework-wide constants
6
31
  /**
@@ -16,20 +41,6 @@ var __ktjs_shared__ = (function (exports) {
16
41
  */
17
42
  var DIRV_TYPE = Symbol('kt-directive-type');
18
43
 
19
- // Cached native methods for performance optimization
20
- var $isArray = Array.isArray;
21
- var $ArrayFrom = Array.from;
22
- var $is = Object.is;
23
- var $assign = Object.assign;
24
- var $hasOwn = Object.prototype.hasOwnProperty;
25
- var $toString = Object.prototype.toString;
26
- var $keys = Object.keys;
27
- var $defines = Object.defineProperties;
28
- var $define = Object.defineProperty;
29
- var $entries = Object.entries;
30
- var $random = Math.random;
31
- var $isThenable = function (o) { return typeof (o === null || o === void 0 ? void 0 : o.then) === 'function'; };
32
-
33
44
  // DOM manipulation utilities
34
45
  var _a;
35
46
  // # dom natives
@@ -85,7 +96,7 @@ var __ktjs_shared__ = (function (exports) {
85
96
  }
86
97
  };
87
98
  var $buttonDisabledGetter = (_a = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled'), _a.get), $buttonDisabledSetter = _a.set;
88
- var parseStyle = function (style) {
99
+ var $parseStyle = function (style) {
89
100
  if (!style) {
90
101
  return '';
91
102
  }
@@ -94,7 +105,7 @@ var __ktjs_shared__ = (function (exports) {
94
105
  }
95
106
  if (style && typeof style === 'object') {
96
107
  if (style.isKT) {
97
- return parseStyle(style.value);
108
+ return $parseStyle(style.value);
98
109
  }
99
110
  return $entries(style)
100
111
  .map(function (entry) {
@@ -108,12 +119,72 @@ var __ktjs_shared__ = (function (exports) {
108
119
  /**
109
120
  * Used for `k-model`
110
121
  */
111
- var applyModel = function (element, valueRef, propName, eventName) {
122
+ var $applyModel = function (element, valueRef, propName, eventName) {
112
123
  element[propName] = valueRef.value; // initialize
113
124
  valueRef.addOnChange(function (newValue) { return (element[propName] = newValue); });
114
125
  element.addEventListener(eventName, function () { return (valueRef.value = element[propName]); });
115
126
  };
116
127
 
128
+ /******************************************************************************
129
+ Copyright (c) Microsoft Corporation.
130
+
131
+ Permission to use, copy, modify, and/or distribute this software for any
132
+ purpose with or without fee is hereby granted.
133
+
134
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
135
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
136
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
137
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
138
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
139
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
140
+ PERFORMANCE OF THIS SOFTWARE.
141
+ ***************************************************************************** */
142
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
143
+
144
+
145
+ function __awaiter(thisArg, _arguments, P, generator) {
146
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
147
+ return new (P || (P = Promise))(function (resolve, reject) {
148
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
149
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
150
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
151
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
152
+ });
153
+ }
154
+
155
+ function __generator(thisArg, body) {
156
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
157
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
158
+ function verb(n) { return function (v) { return step([n, v]); }; }
159
+ function step(op) {
160
+ if (f) throw new TypeError("Generator is already executing.");
161
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
162
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
163
+ if (y = 0, t) op = [op[0] & 2, t.value];
164
+ switch (op[0]) {
165
+ case 0: case 1: t = op; break;
166
+ case 4: _.label++; return { value: op[1], done: false };
167
+ case 5: _.label++; y = op[1]; op = [0]; continue;
168
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
169
+ default:
170
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
171
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
172
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
173
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
174
+ if (t[2]) _.ops.pop();
175
+ _.trys.pop(); continue;
176
+ }
177
+ op = body.call(thisArg, _);
178
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
179
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
180
+ }
181
+ }
182
+
183
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
184
+ var e = new Error(message);
185
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
186
+ };
187
+
117
188
  // String manipulation utilities
118
189
  /**
119
190
  * Default empty function
@@ -125,6 +196,39 @@ var __ktjs_shared__ = (function (exports) {
125
196
  }
126
197
  return $is(a, b);
127
198
  };
199
+ /**
200
+ * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
201
+ */
202
+ var $forEach = function (array, callback) {
203
+ var len = array.length;
204
+ for (var i = 0; i < len; i++) {
205
+ callback(array[i], i, array);
206
+ }
207
+ };
208
+ /**
209
+ * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
210
+ */
211
+ var $forEachAsync = function (array, callback) { return __awaiter(void 0, void 0, void 0, function () {
212
+ var len, i;
213
+ return __generator(this, function (_a) {
214
+ switch (_a.label) {
215
+ case 0:
216
+ len = array.length;
217
+ i = 0;
218
+ _a.label = 1;
219
+ case 1:
220
+ if (!(i < len)) return [3 /*break*/, 4];
221
+ return [4 /*yield*/, callback(array[i], i, array)];
222
+ case 2:
223
+ _a.sent();
224
+ _a.label = 3;
225
+ case 3:
226
+ i++;
227
+ return [3 /*break*/, 1];
228
+ case 4: return [2 /*return*/];
229
+ }
230
+ });
231
+ }); };
128
232
 
129
233
  /**
130
234
  * Normalize path by joining parts and ensuring leading slash
@@ -204,18 +308,13 @@ var __ktjs_shared__ = (function (exports) {
204
308
  return params;
205
309
  };
206
310
 
207
- if (typeof Symbol === 'undefined') {
208
- window.Symbol = function Symbol(description) {
209
- return "@@SYMBOL_".concat(description || '', "_").concat($random().toString(36).slice(2));
210
- };
211
- }
212
-
213
- // Shared utilities and cached native methods for kt.js framework
214
- Object.defineProperty(window, '__ktjs__', { value: '0.23.4' });
311
+ // incase that symbol is not supported
312
+ Object.defineProperty(window, '__ktjs__', { value: '0.23.7' });
215
313
 
216
314
  exports.$ArrayFrom = $ArrayFrom;
217
315
  exports.$append = $append;
218
316
  exports.$appendChild = $appendChild;
317
+ exports.$applyModel = $applyModel;
219
318
  exports.$assign = $assign;
220
319
  exports.$buttonDisabledGetter = $buttonDisabledGetter;
221
320
  exports.$buttonDisabledSetter = $buttonDisabledSetter;
@@ -223,6 +322,8 @@ var __ktjs_shared__ = (function (exports) {
223
322
  exports.$defines = $defines;
224
323
  exports.$emptyFn = $emptyFn;
225
324
  exports.$entries = $entries;
325
+ exports.$forEach = $forEach;
326
+ exports.$forEachAsync = $forEachAsync;
226
327
  exports.$hasOwn = $hasOwn;
227
328
  exports.$is = $is;
228
329
  exports.$isArray = $isArray;
@@ -230,19 +331,18 @@ var __ktjs_shared__ = (function (exports) {
230
331
  exports.$isSame = $isSame;
231
332
  exports.$isThenable = $isThenable;
232
333
  exports.$keys = $keys;
334
+ exports.$parseStyle = $parseStyle;
233
335
  exports.$random = $random;
234
336
  exports.$replaceNode = $replaceNode;
235
337
  exports.$toString = $toString;
236
338
  exports.DIRV_TYPE = DIRV_TYPE;
237
339
  exports.MATHML_ATTR_FLAG = MATHML_ATTR_FLAG;
238
340
  exports.SVG_ATTR_FLAG = SVG_ATTR_FLAG;
239
- exports.applyModel = applyModel;
240
341
  exports.buildQuery = buildQuery;
241
342
  exports.emplaceParams = emplaceParams;
242
343
  exports.extractParams = extractParams;
243
344
  exports.normalizePath = normalizePath;
244
345
  exports.parseQuery = parseQuery;
245
- exports.parseStyle = parseStyle;
246
346
 
247
347
  return exports;
248
348
 
package/dist/index.mjs CHANGED
@@ -1,3 +1,28 @@
1
+ // Cached native methods for performance optimization
2
+ const $isArray = Array.isArray;
3
+ const $ArrayFrom = Array.from;
4
+ const $is = Object.is;
5
+ const $assign = Object.assign;
6
+ const $hasOwn = Object.prototype.hasOwnProperty;
7
+ const $toString = Object.prototype.toString;
8
+ const $keys = Object.keys;
9
+ const $defines = Object.defineProperties;
10
+ const $define = Object.defineProperty;
11
+ const $entries = Object.entries;
12
+ const $random = Math.random;
13
+ const $isThenable = (o) => typeof o?.then === 'function';
14
+
15
+ if (typeof Symbol === 'undefined') {
16
+ window.Symbol = function Symbol(description) {
17
+ return `@@SYMBOL_${description || ''}_${$random().toString(36).slice(2)}`;
18
+ };
19
+ }
20
+
21
+ // each instance shares the same empty array, but it will be replaced when used
22
+ const emptyArray = [];
23
+ Comment.prototype.kisFragmentAnchor = false;
24
+ Comment.prototype.kFragmentList = emptyArray;
25
+
1
26
  // Shared constants
2
27
  // Empty for now - can be extended with framework-wide constants
3
28
  /**
@@ -13,20 +38,6 @@ const MATHML_ATTR_FLAG = '__kt_mathml__';
13
38
  */
14
39
  const DIRV_TYPE = Symbol('kt-directive-type');
15
40
 
16
- // Cached native methods for performance optimization
17
- const $isArray = Array.isArray;
18
- const $ArrayFrom = Array.from;
19
- const $is = Object.is;
20
- const $assign = Object.assign;
21
- const $hasOwn = Object.prototype.hasOwnProperty;
22
- const $toString = Object.prototype.toString;
23
- const $keys = Object.keys;
24
- const $defines = Object.defineProperties;
25
- const $define = Object.defineProperty;
26
- const $entries = Object.entries;
27
- const $random = Math.random;
28
- const $isThenable = (o) => typeof o?.then === 'function';
29
-
30
41
  // DOM manipulation utilities
31
42
  // # dom natives
32
43
  const $isNode = (x) => x?.nodeType > 0;
@@ -77,7 +88,7 @@ const $append = // for ie 9/10/11
77
88
  }
78
89
  };
79
90
  const { get: $buttonDisabledGetter, set: $buttonDisabledSetter } = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled');
80
- const parseStyle = (style) => {
91
+ const $parseStyle = (style) => {
81
92
  if (!style) {
82
93
  return '';
83
94
  }
@@ -86,7 +97,7 @@ const parseStyle = (style) => {
86
97
  }
87
98
  if (style && typeof style === 'object') {
88
99
  if (style.isKT) {
89
- return parseStyle(style.value);
100
+ return $parseStyle(style.value);
90
101
  }
91
102
  return $entries(style)
92
103
  .map((entry) => {
@@ -100,7 +111,7 @@ const parseStyle = (style) => {
100
111
  /**
101
112
  * Used for `k-model`
102
113
  */
103
- const applyModel = (element, valueRef, propName, eventName) => {
114
+ const $applyModel = (element, valueRef, propName, eventName) => {
104
115
  element[propName] = valueRef.value; // initialize
105
116
  valueRef.addOnChange((newValue) => (element[propName] = newValue));
106
117
  element.addEventListener(eventName, () => (valueRef.value = element[propName]));
@@ -117,6 +128,24 @@ const $isSame = (a, b) => {
117
128
  }
118
129
  return $is(a, b);
119
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
+ };
120
149
 
121
150
  /**
122
151
  * Normalize path by joining parts and ensuring leading slash
@@ -191,13 +220,7 @@ const extractParams = (pattern, path) => {
191
220
  return params;
192
221
  };
193
222
 
194
- if (typeof Symbol === 'undefined') {
195
- window.Symbol = function Symbol(description) {
196
- return `@@SYMBOL_${description || ''}_${$random().toString(36).slice(2)}`;
197
- };
198
- }
199
-
200
- // Shared utilities and cached native methods for kt.js framework
201
- Object.defineProperty(window, '__ktjs__', { value: '0.23.4' });
223
+ // incase that symbol is not supported
224
+ Object.defineProperty(window, '__ktjs__', { value: '0.23.7' });
202
225
 
203
- export { $ArrayFrom, $append, $appendChild, $assign, $buttonDisabledGetter, $buttonDisabledSetter, $define, $defines, $emptyFn, $entries, $hasOwn, $is, $isArray, $isNode, $isSame, $isThenable, $keys, $random, $replaceNode, $toString, DIRV_TYPE, MATHML_ATTR_FLAG, SVG_ATTR_FLAG, applyModel, buildQuery, emplaceParams, extractParams, normalizePath, parseQuery, parseStyle };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/shared",
3
- "version": "0.23.4",
3
+ "version": "0.23.7",
4
4
  "description": "Shared utilities and cached native methods for kt.js framework",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
@@ -34,6 +34,7 @@
34
34
  },
35
35
  "scripts": {
36
36
  "build": "rollup -c rollup.config.mjs",
37
- "dev": "rollup -c rollup.config.mjs -w"
37
+ "dev": "rollup -c rollup.config.mjs -w",
38
+ "test": "vitest run"
38
39
  }
39
40
  }