@ktjs/shared 0.23.11 → 0.23.12

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,348 +0,0 @@
1
- var __ktjs_shared__ = (function (exports) {
2
- 'use strict';
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
- // Shared constants
25
- // Empty for now - can be extended with framework-wide constants
26
- /**
27
- * Mark the attribute as SVG to handle special cases during rendering.
28
- */
29
- var SVG_ATTR_FLAG = '__kt_svg__';
30
- /**
31
- * Mark the attribute as MathML to handle special cases during rendering.
32
- */
33
- var MATHML_ATTR_FLAG = '__kt_mathml__';
34
- /**
35
- * Can be if, else, else-if.
36
- */
37
- var DIRV_TYPE = Symbol('kt-directive-type');
38
-
39
- // DOM manipulation utilities
40
- var _a;
41
- // # dom natives
42
- var $isNode = function (x) { return (x === null || x === void 0 ? void 0 : x.nodeType) > 0; };
43
- /**
44
- * Safe replace `oldNode` With `newNode`
45
- */
46
- var $replaceNode = function (oldNode, newNode) {
47
- if ($isNode(oldNode) && $isNode(newNode)) {
48
- if (newNode.contains(oldNode)) {
49
- newNode.remove();
50
- }
51
- oldNode.replaceWith(newNode);
52
- }
53
- };
54
- /**
55
- * & Remove `bind` because it is shockingly slower than wrapper
56
- * & `window.document` is safe because it is not configurable and its setter is undefined
57
- */
58
- var $appendChild = HTMLElement.prototype.appendChild;
59
- var originAppend = HTMLElement.prototype.append;
60
- var $append = // for ie 9/10/11
61
- typeof originAppend === 'function'
62
- ? originAppend
63
- : function () {
64
- var nodes = [];
65
- for (var _i = 0; _i < arguments.length; _i++) {
66
- nodes[_i] = arguments[_i];
67
- }
68
- if (nodes.length < 50) {
69
- for (var i = 0; i < nodes.length; i++) {
70
- var node = nodes[i];
71
- if (typeof node === 'string') {
72
- $appendChild.call(this, document.createTextNode(node));
73
- }
74
- else {
75
- $appendChild.call(this, node);
76
- }
77
- }
78
- }
79
- else {
80
- var fragment = document.createDocumentFragment();
81
- for (var i = 0; i < nodes.length; i++) {
82
- var node = nodes[i];
83
- if (typeof node === 'string') {
84
- $appendChild.call(fragment, document.createTextNode(node));
85
- }
86
- else {
87
- $appendChild.call(fragment, node);
88
- }
89
- }
90
- $appendChild.call(this, fragment);
91
- }
92
- };
93
- var $buttonDisabledGetter = (_a = Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype, 'disabled'), _a.get), $buttonDisabledSetter = _a.set;
94
- var $parseStyle = function (style) {
95
- if (!style) {
96
- return '';
97
- }
98
- if (typeof style === 'string') {
99
- return style;
100
- }
101
- if (style && typeof style === 'object') {
102
- if (style.isKT) {
103
- return $parseStyle(style.value);
104
- }
105
- return $entries(style)
106
- .map(function (entry) {
107
- var cssKey = entry[0].replace(/[A-Z]/g, function (m) { return "-".concat(m.toLowerCase()); });
108
- return "".concat(cssKey, ":").concat(entry[1]);
109
- })
110
- .join(';');
111
- }
112
- return '';
113
- };
114
- /**
115
- * Used for `k-model`
116
- */
117
- var $applyModel = function (element, valueRef, propName, eventName) {
118
- element[propName] = valueRef.value; // initialize
119
- valueRef.addOnChange(function (newValue) { return (element[propName] = newValue); });
120
- element.addEventListener(eventName, function () { return (valueRef.value = element[propName]); });
121
- };
122
-
123
- /******************************************************************************
124
- Copyright (c) Microsoft Corporation.
125
-
126
- Permission to use, copy, modify, and/or distribute this software for any
127
- purpose with or without fee is hereby granted.
128
-
129
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
130
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
131
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
132
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
133
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
134
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
135
- PERFORMANCE OF THIS SOFTWARE.
136
- ***************************************************************************** */
137
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
138
-
139
-
140
- function __awaiter(thisArg, _arguments, P, generator) {
141
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
142
- return new (P || (P = Promise))(function (resolve, reject) {
143
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
144
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
145
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
146
- step((generator = generator.apply(thisArg, _arguments || [])).next());
147
- });
148
- }
149
-
150
- function __generator(thisArg, body) {
151
- 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);
152
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
153
- function verb(n) { return function (v) { return step([n, v]); }; }
154
- function step(op) {
155
- if (f) throw new TypeError("Generator is already executing.");
156
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
157
- 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;
158
- if (y = 0, t) op = [op[0] & 2, t.value];
159
- switch (op[0]) {
160
- case 0: case 1: t = op; break;
161
- case 4: _.label++; return { value: op[1], done: false };
162
- case 5: _.label++; y = op[1]; op = [0]; continue;
163
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
164
- default:
165
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
166
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
167
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
168
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
169
- if (t[2]) _.ops.pop();
170
- _.trys.pop(); continue;
171
- }
172
- op = body.call(thisArg, _);
173
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
174
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
175
- }
176
- }
177
-
178
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
179
- var e = new Error(message);
180
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
181
- };
182
-
183
- // String manipulation utilities
184
- /**
185
- * Default empty function
186
- */
187
- var $emptyFn = (function () { return true; });
188
- var $emptyArray = [];
189
- var $emptyObject = Object.create(null);
190
- var $isSame = function (a, b) {
191
- if ($isArray(a)) {
192
- return true; // always trigger an array
193
- }
194
- return $is(a, b);
195
- };
196
- /**
197
- * Safe and quick forEach implementation that works with array-like objects and handles sparse arrays.
198
- */
199
- var $forEach = function (array, callback) {
200
- var len = array.length;
201
- for (var i = 0; i < len; i++) {
202
- callback(array[i], i, array);
203
- }
204
- };
205
- /**
206
- * Async version of $forEach that allows for asynchronous callbacks. It processes items sequentially, awaiting each callback before moving to the next.
207
- */
208
- var $forEachAsync = function (array, callback) { return __awaiter(void 0, void 0, void 0, function () {
209
- var len, i;
210
- return __generator(this, function (_a) {
211
- switch (_a.label) {
212
- case 0:
213
- len = array.length;
214
- i = 0;
215
- _a.label = 1;
216
- case 1:
217
- if (!(i < len)) return [3 /*break*/, 4];
218
- return [4 /*yield*/, callback(array[i], i, array)];
219
- case 2:
220
- _a.sent();
221
- _a.label = 3;
222
- case 3:
223
- i++;
224
- return [3 /*break*/, 1];
225
- case 4: return [2 /*return*/];
226
- }
227
- });
228
- }); };
229
-
230
- /**
231
- * Normalize path by joining parts and ensuring leading slash
232
- */
233
- var normalizePath = function () {
234
- var paths = [];
235
- for (var _i = 0; _i < arguments.length; _i++) {
236
- paths[_i] = arguments[_i];
237
- }
238
- var p = paths
239
- .map(function (p) { return p.split('/'); })
240
- .flat()
241
- .filter(Boolean);
242
- return '/' + p.join('/');
243
- };
244
- /**
245
- * Parse query string into object
246
- */
247
- var parseQuery = function (queryString) {
248
- var query = {};
249
- if (!queryString || queryString === '?') {
250
- return query;
251
- }
252
- var params = queryString.replace(/^\?/, '').split('&');
253
- for (var _i = 0, params_1 = params; _i < params_1.length; _i++) {
254
- var param = params_1[_i];
255
- var _a = param.split('='), key = _a[0], value = _a[1];
256
- if (key) {
257
- query[decodeURIComponent(key)] = value ? decodeURIComponent(value) : '';
258
- }
259
- }
260
- return query;
261
- };
262
- /**
263
- * Build query string from object
264
- */
265
- var buildQuery = function (query) {
266
- var keys = Object.keys(query);
267
- if (keys.length === 0)
268
- return '';
269
- var params = keys.map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(query[key])); }).join('&');
270
- return "?".concat(params);
271
- };
272
- /**
273
- * Substitute params into path pattern
274
- * @example '/user/:id' + {id: '123'} => '/user/123'
275
- */
276
- var emplaceParams = function (path, params) {
277
- var result = path;
278
- for (var key in params) {
279
- result = result.replace(":".concat(key), params[key]);
280
- }
281
- return result;
282
- };
283
- /**
284
- * Extract dynamic params from path using pattern
285
- * @example pattern: '/user/:id', path: '/user/123' => {id: '123'}
286
- */
287
- var extractParams = function (pattern, path) {
288
- var params = {};
289
- var patternParts = pattern.split('/');
290
- var pathParts = path.split('/');
291
- if (patternParts.length !== pathParts.length) {
292
- return null;
293
- }
294
- for (var i = 0; i < patternParts.length; i++) {
295
- var patternPart = patternParts[i];
296
- var pathPart = pathParts[i];
297
- if (patternPart.startsWith(':')) {
298
- var paramName = patternPart.slice(1);
299
- params[paramName] = pathPart;
300
- }
301
- else if (patternPart !== pathPart) {
302
- return null;
303
- }
304
- }
305
- return params;
306
- };
307
-
308
- // incase that symbol is not supported
309
- Object.defineProperty(window, '__ktjs__', { value: '0.23.11' });
310
-
311
- exports.$ArrayFrom = $ArrayFrom;
312
- exports.$append = $append;
313
- exports.$appendChild = $appendChild;
314
- exports.$applyModel = $applyModel;
315
- exports.$assign = $assign;
316
- exports.$buttonDisabledGetter = $buttonDisabledGetter;
317
- exports.$buttonDisabledSetter = $buttonDisabledSetter;
318
- exports.$define = $define;
319
- exports.$defines = $defines;
320
- exports.$emptyArray = $emptyArray;
321
- exports.$emptyFn = $emptyFn;
322
- exports.$emptyObject = $emptyObject;
323
- exports.$entries = $entries;
324
- exports.$forEach = $forEach;
325
- exports.$forEachAsync = $forEachAsync;
326
- exports.$hasOwn = $hasOwn;
327
- exports.$is = $is;
328
- exports.$isArray = $isArray;
329
- exports.$isNode = $isNode;
330
- exports.$isSame = $isSame;
331
- exports.$isThenable = $isThenable;
332
- exports.$keys = $keys;
333
- exports.$parseStyle = $parseStyle;
334
- exports.$random = $random;
335
- exports.$replaceNode = $replaceNode;
336
- exports.$toString = $toString;
337
- exports.DIRV_TYPE = DIRV_TYPE;
338
- exports.MATHML_ATTR_FLAG = MATHML_ATTR_FLAG;
339
- exports.SVG_ATTR_FLAG = SVG_ATTR_FLAG;
340
- exports.buildQuery = buildQuery;
341
- exports.emplaceParams = emplaceParams;
342
- exports.extractParams = extractParams;
343
- exports.normalizePath = normalizePath;
344
- exports.parseQuery = parseQuery;
345
-
346
- return exports;
347
-
348
- })({});