@tko/utils 4.0.0-beta1.3 → 4.0.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.
- package/dist/array.js +39 -35
- package/dist/array.js.map +2 -2
- package/dist/async.js +4 -3
- package/dist/async.js.map +2 -2
- package/dist/css.js +5 -4
- package/dist/css.js.map +2 -2
- package/dist/dom/data.js +36 -46
- package/dist/dom/data.js.map +2 -2
- package/dist/dom/disposal.js +23 -16
- package/dist/dom/disposal.js.map +2 -2
- package/dist/dom/event.js +39 -41
- package/dist/dom/event.js.map +2 -2
- package/dist/dom/fixes.js +5 -24
- package/dist/dom/fixes.js.map +2 -2
- package/dist/dom/html.js +46 -61
- package/dist/dom/html.js.map +2 -2
- package/dist/dom/info.js +10 -8
- package/dist/dom/info.js.map +2 -2
- package/dist/dom/manipulation.js +16 -24
- package/dist/dom/manipulation.js.map +2 -2
- package/dist/dom/selectExtensions.js +33 -23
- package/dist/dom/selectExtensions.js.map +2 -2
- package/dist/dom/virtualElements.js +40 -32
- package/dist/dom/virtualElements.js.map +3 -3
- package/dist/error.js +2 -1
- package/dist/error.js.map +2 -2
- package/dist/function.js +2 -1
- package/dist/function.js.map +2 -2
- package/dist/index.cjs +446 -449
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +2 -3
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +2 -3
- package/dist/index.mjs.map +2 -2
- package/dist/memoization.js +18 -13
- package/dist/memoization.js.map +3 -3
- package/dist/object.js +10 -8
- package/dist/object.js.map +2 -2
- package/dist/options.js +97 -35
- package/dist/options.js.map +2 -2
- package/dist/string.js +3 -5
- package/dist/string.js.map +2 -2
- package/dist/symbol.js +3 -2
- package/dist/symbol.js.map +2 -2
- package/dist/tasks.js +10 -20
- package/dist/tasks.js.map +2 -2
- package/helpers/jasmine-13-helper.ts +198 -147
- package/package.json +2 -3
- package/LICENSE +0 -22
- package/dist/bind-shim.js +0 -18
- package/dist/bind-shim.js.map +0 -7
- package/dist/ie.js +0 -15
- package/dist/ie.js.map +0 -7
- package/dist/jquery.js +0 -6
- package/dist/jquery.js.map +0 -7
package/dist/memoization.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/memoization.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Memoization\n//\nimport { arrayPushAll } from './array'\n\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["//\n// Memoization\n//\nimport { arrayPushAll } from './array'\n\nconst memos = {}\n\nfunction randomMax8HexChars() {\n return (((1 + Math.random()) * 0x100000000) | 0).toString(16).substring(1)\n}\n\nfunction generateRandomId() {\n return randomMax8HexChars() + randomMax8HexChars()\n}\n\nfunction findMemoNodes(rootNode: Node, appendToArray: any[]) {\n if (!rootNode) {\n return\n }\n if (rootNode.nodeType === Node.COMMENT_NODE) {\n const comment = rootNode as Comment\n const memoId = parseMemoText(comment.nodeValue)\n if (memoId != null) {\n appendToArray.push({ domNode: rootNode, memoId: memoId })\n }\n } else if (rootNode.nodeType === Node.ELEMENT_NODE) {\n for (let i = 0, childNodes = rootNode.childNodes, j = childNodes.length; i < j; i++) {\n findMemoNodes(childNodes[i], appendToArray)\n }\n }\n}\n\nexport function memoize(callback: (val: any) => void): string {\n if (typeof callback !== 'function') {\n throw new Error('You can only pass a function to memoization.memoize()')\n }\n const memoId = generateRandomId()\n memos[memoId] = callback\n return '<!--[ko_memo:' + memoId + ']-->'\n}\n\nexport function unmemoize(memoId: string, callbackParams: any[]) {\n const callback = memos[memoId]\n if (callback === undefined) {\n throw new Error(\"Couldn't find any memo with ID \" + memoId + \". Perhaps it's already been unmemoized.\")\n }\n try {\n callback.apply(null, callbackParams || [])\n return true\n } finally {\n delete memos[memoId]\n }\n}\n\nexport function unmemoizeDomNodeAndDescendants(domNode: Node, extraCallbackParamsArray: any[]) {\n const memos = new Array()\n findMemoNodes(domNode, memos)\n for (let i = 0, j = memos.length; i < j; i++) {\n const node = memos[i].domNode\n const combinedParams = [node]\n if (extraCallbackParamsArray) {\n arrayPushAll(combinedParams, extraCallbackParamsArray)\n }\n unmemoize(memos[i].memoId, combinedParams)\n node.nodeValue = '' // Neuter this node so we don't try to unmemoize it again\n if (node.parentNode) {\n node.parentNode.removeChild(node)\n } // If possible, erase it totally (not always possible - someone else might just hold a reference to it then call unmemoizeDomNodeAndDescendants again)\n }\n}\n\nexport function parseMemoText(memoText: string | null): string | null {\n if (!memoText) {\n return null\n }\n\n const match = memoText.match(/^\\[ko_memo\\:(.*?)\\]$/)\n return match ? match[1] : null\n}\n"],
|
|
5
|
+
"mappings": ";;AAGA,SAAS,oBAAoB;AAE7B,MAAM,QAAQ,CAAC;AAEf,SAAS,qBAAqB;AAC5B,WAAU,IAAI,KAAK,OAAO,KAAK,aAAe,GAAG,SAAS,EAAE,EAAE,UAAU,CAAC;AAC3E;AAEA,SAAS,mBAAmB;AAC1B,SAAO,mBAAmB,IAAI,mBAAmB;AACnD;AAEA,SAAS,cAAc,UAAgB,eAAsB;AAC3D,MAAI,CAAC,UAAU;AACb;AAAA,EACF;AACA,MAAI,SAAS,aAAa,KAAK,cAAc;AAC3C,UAAM,UAAU;AAChB,UAAM,SAAS,cAAc,QAAQ,SAAS;AAC9C,QAAI,UAAU,MAAM;AAClB,oBAAc,KAAK,EAAE,SAAS,UAAU,OAAe,CAAC;AAAA,IAC1D;AAAA,EACF,WAAW,SAAS,aAAa,KAAK,cAAc;AAClD,aAAS,IAAI,GAAG,aAAa,SAAS,YAAY,IAAI,WAAW,QAAQ,IAAI,GAAG,KAAK;AACnF,oBAAc,WAAW,CAAC,GAAG,aAAa;AAAA,IAC5C;AAAA,EACF;AACF;AAEO,gBAAS,QAAQ,UAAsC;AAC5D,MAAI,OAAO,aAAa,YAAY;AAClC,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,QAAM,SAAS,iBAAiB;AAChC,QAAM,MAAM,IAAI;AAChB,SAAO,kBAAkB,SAAS;AACpC;AAEO,gBAAS,UAAU,QAAgB,gBAAuB;AAC/D,QAAM,WAAW,MAAM,MAAM;AAC7B,MAAI,aAAa,QAAW;AAC1B,UAAM,IAAI,MAAM,oCAAoC,SAAS,yCAAyC;AAAA,EACxG;AACA,MAAI;AACF,aAAS,MAAM,MAAM,kBAAkB,CAAC,CAAC;AACzC,WAAO;AAAA,EACT,UAAE;AACA,WAAO,MAAM,MAAM;AAAA,EACrB;AACF;AAEO,gBAAS,+BAA+B,SAAe,0BAAiC;AAC7F,QAAMA,SAAQ,IAAI,MAAM;AACxB,gBAAc,SAASA,MAAK;AAC5B,WAAS,IAAI,GAAG,IAAIA,OAAM,QAAQ,IAAI,GAAG,KAAK;AAC5C,UAAM,OAAOA,OAAM,CAAC,EAAE;AACtB,UAAM,iBAAiB,CAAC,IAAI;AAC5B,QAAI,0BAA0B;AAC5B,mBAAa,gBAAgB,wBAAwB;AAAA,IACvD;AACA,cAAUA,OAAM,CAAC,EAAE,QAAQ,cAAc;AACzC,SAAK,YAAY;AACjB,QAAI,KAAK,YAAY;AACnB,WAAK,WAAW,YAAY,IAAI;AAAA,IAClC;AAAA,EACF;AACF;AAEO,gBAAS,cAAc,UAAwC;AACpE,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,SAAS,MAAM,sBAAsB;AACnD,SAAO,QAAQ,MAAM,CAAC,IAAI;AAC5B;",
|
|
6
|
+
"names": ["memos"]
|
|
7
7
|
}
|
package/dist/object.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
2
3
|
export function hasOwnProperty(obj, propName) {
|
|
3
4
|
return Object.prototype.hasOwnProperty.call(obj, propName);
|
|
4
5
|
}
|
|
@@ -10,8 +11,9 @@ export function isObjectLike(obj) {
|
|
|
10
11
|
}
|
|
11
12
|
export function extend(target, source) {
|
|
12
13
|
if (source) {
|
|
13
|
-
for (
|
|
14
|
+
for (const prop of Object.keys(source)) {
|
|
14
15
|
if (hasOwnProperty(source, prop)) {
|
|
16
|
+
;
|
|
15
17
|
target[prop] = source[prop];
|
|
16
18
|
}
|
|
17
19
|
}
|
|
@@ -19,7 +21,7 @@ export function extend(target, source) {
|
|
|
19
21
|
return target;
|
|
20
22
|
}
|
|
21
23
|
export function objectForEach(obj, action) {
|
|
22
|
-
for (
|
|
24
|
+
for (const prop in obj) {
|
|
23
25
|
if (hasOwnProperty(obj, prop)) {
|
|
24
26
|
action(prop, obj[prop]);
|
|
25
27
|
}
|
|
@@ -32,8 +34,8 @@ export function objectMap(source, mapping, thisArg) {
|
|
|
32
34
|
if (arguments.length > 2) {
|
|
33
35
|
mapping = mapping.bind(thisArg);
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
for (
|
|
37
|
+
const target = {};
|
|
38
|
+
for (const prop in source) {
|
|
37
39
|
if (hasOwnProperty(source, prop)) {
|
|
38
40
|
target[prop] = mapping(source[prop], prop, source);
|
|
39
41
|
}
|
|
@@ -45,14 +47,14 @@ export function getObjectOwnProperty(obj, propName) {
|
|
|
45
47
|
}
|
|
46
48
|
export function clonePlainObjectDeep(obj, seen) {
|
|
47
49
|
if (!seen) {
|
|
48
|
-
seen =
|
|
50
|
+
seen = new Array();
|
|
49
51
|
}
|
|
50
52
|
if (!obj || typeof obj !== "object" || obj.constructor !== Object || seen.indexOf(obj) !== -1) {
|
|
51
53
|
return obj;
|
|
52
54
|
}
|
|
53
55
|
seen.push(obj);
|
|
54
|
-
|
|
55
|
-
for (
|
|
56
|
+
const result = {};
|
|
57
|
+
for (const prop in obj) {
|
|
56
58
|
if (hasOwnProperty(obj, prop)) {
|
|
57
59
|
result[prop] = clonePlainObjectDeep(obj[prop], seen);
|
|
58
60
|
}
|
package/dist/object.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/object.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Object functions\n//\n\nexport function hasOwnProperty(obj, propName) {\n return Object.prototype.hasOwnProperty.call(obj, propName)\n}\n\n/**\n * True when obj is a non-null object, or a function.\n * @param obj
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// Object functions\n//\n\nexport function hasOwnProperty<T = any>(obj: T, propName: keyof T | any): boolean {\n return Object.prototype.hasOwnProperty.call(obj, propName)\n}\n\n/**\n * True when obj is a non-null object, or a function.\n * @param obj\n * @returns\n */\nexport function isObjectLike(obj) {\n if (obj === null) {\n return false\n }\n return typeof obj === 'object' || typeof obj === 'function'\n}\n\nexport function extend<T, U>(target: T, source: U): T & U {\n if (source) {\n for (const prop of Object.keys(source) as Array<keyof U>) {\n if (hasOwnProperty(source, prop)) {\n ;(target as T & U)[prop] = source[prop] as any\n }\n }\n }\n return target as T & U\n}\n\nexport function objectForEach<T = any>(obj: { [key: string]: T }, action: (key: string, value: T) => void): void {\n for (const prop in obj) {\n if (hasOwnProperty(obj, prop)) {\n action(prop, obj[prop])\n }\n }\n}\n\nexport function objectMap(source, mapping, thisArg?: any) {\n if (!source) {\n return source\n }\n if (arguments.length > 2) {\n mapping = mapping.bind(thisArg)\n }\n const target = {}\n for (const prop in source) {\n if (hasOwnProperty(source, prop)) {\n target[prop] = mapping(source[prop], prop, source)\n }\n }\n return target\n}\nexport function getObjectOwnProperty(obj, propName: string) {\n return hasOwnProperty(obj, propName) ? obj[propName] : undefined\n}\n\n/**\n * @deprecated Function is unused\n * */\nexport function clonePlainObjectDeep(obj, seen?: any[]) {\n if (!seen) {\n seen = new Array()\n }\n\n if (!obj || typeof obj !== 'object' || obj.constructor !== Object || seen.indexOf(obj) !== -1) {\n return obj\n }\n\n // Anything that makes it below is a plain object that has not yet\n // been seen/cloned.\n seen.push(obj)\n\n const result = {}\n for (const prop in obj) {\n if (hasOwnProperty(obj, prop)) {\n result[prop] = clonePlainObjectDeep(obj[prop], seen)\n }\n }\n return result\n}\n\n/**\n * JSON.stringify, but inserts `...` for objects that are referenced\n * multiple times, preventing infinite recursion.\n */\nexport function safeStringify(value) {\n const seen = new Set()\n return JSON.stringify(value, (k, v) => {\n if (seen.has(v)) {\n return '...'\n }\n if (typeof v === 'object') {\n seen.add(v)\n }\n return v\n })\n}\n\n/**\n * Promises/A+ compliant isThenable (per section 1.2)\n */\nexport function isThenable(object: any) {\n return isObjectLike(object) && typeof object.then === 'function'\n}\n"],
|
|
5
|
+
"mappings": ";;AAIO,gBAAS,eAAwB,KAAQ,UAAkC;AAChF,SAAO,OAAO,UAAU,eAAe,KAAK,KAAK,QAAQ;AAC3D;AAOO,gBAAS,aAAa,KAAK;AAChC,MAAI,QAAQ,MAAM;AAChB,WAAO;AAAA,EACT;AACA,SAAO,OAAO,QAAQ,YAAY,OAAO,QAAQ;AACnD;AAEO,gBAAS,OAAa,QAAW,QAAkB;AACxD,MAAI,QAAQ;AACV,eAAW,QAAQ,OAAO,KAAK,MAAM,GAAqB;AACxD,UAAI,eAAe,QAAQ,IAAI,GAAG;AAChC;AAAC,QAAC,OAAiB,IAAI,IAAI,OAAO,IAAI;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,gBAAS,cAAuB,KAA2B,QAA+C;AAC/G,aAAW,QAAQ,KAAK;AACtB,QAAI,eAAe,KAAK,IAAI,GAAG;AAC7B,aAAO,MAAM,IAAI,IAAI,CAAC;AAAA,IACxB;AAAA,EACF;AACF;AAEO,gBAAS,UAAU,QAAQ,SAAS,SAAe;AACxD,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AACA,MAAI,UAAU,SAAS,GAAG;AACxB,cAAU,QAAQ,KAAK,OAAO;AAAA,EAChC;AACA,QAAM,SAAS,CAAC;AAChB,aAAW,QAAQ,QAAQ;AACzB,QAAI,eAAe,QAAQ,IAAI,GAAG;AAChC,aAAO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|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
3
|
+
export class Options {
|
|
4
|
+
constructor() {
|
|
5
|
+
// The following options can be set on ko.options to make a function rewriting or something similar.
|
|
6
|
+
this.bindingStringPreparsers = [];
|
|
7
|
+
// Reference to the own knockout instance
|
|
8
|
+
this.knockoutInstance = null;
|
|
9
|
+
this.deferUpdates = false;
|
|
10
|
+
// Don't set this false, with jquery 3.7+
|
|
11
|
+
this.useOnlyNativeEvents = true;
|
|
12
|
+
// Use HTML5 <template> tags if is supported
|
|
13
|
+
this.useTemplateTag = true;
|
|
14
|
+
this.protoProperty = "__ko_proto__";
|
|
15
|
+
// Modify the default attribute from `data-bind`.
|
|
16
|
+
this.defaultBindingAttribute = "data-bind";
|
|
17
|
+
// Enable/disable <!-- ko binding: ... -> style bindings
|
|
18
|
+
this.allowVirtualElements = true;
|
|
19
|
+
// Global variables that can be accessed from bindings.
|
|
20
|
+
this.bindingGlobals = /* @__PURE__ */ Object.create(null);
|
|
21
|
+
// Whether the `with` binding creates a child context when used with `as`.
|
|
22
|
+
this.createChildContextWithAs = false;
|
|
23
|
+
// jQuery will be automatically set to globalThis.jQuery in applyBindings
|
|
24
|
+
// if it is (strictly equal to) undefined. Set it to true to
|
|
25
|
+
// disable automatically setting jQuery.
|
|
26
|
+
this.disableJQueryUsage = false;
|
|
27
|
+
this.Promise = globalThis.Promise;
|
|
28
|
+
this.taskScheduler = null;
|
|
29
|
+
this.debug = false;
|
|
30
|
+
/**
|
|
31
|
+
* The maximum size of template to parse.
|
|
32
|
+
* Set to 0 to disable the limit.
|
|
33
|
+
*/
|
|
34
|
+
this.templateSizeLimit = 4096;
|
|
35
|
+
/**
|
|
36
|
+
* Whether or not to allow script tags in templates.
|
|
37
|
+
* If false, an error will be thrown if a script tag is detected in the template.
|
|
38
|
+
* It is not recommended to set this to true.
|
|
39
|
+
*/
|
|
40
|
+
this.allowScriptTagsInTemplates = false;
|
|
41
|
+
this._sanitizeWarningLogged = false;
|
|
42
|
+
this.global = globalThis;
|
|
43
|
+
this.document = globalThis.document;
|
|
44
|
+
// Filters for bindings
|
|
45
|
+
// data-bind="expression | filter_1 | filter_2"
|
|
46
|
+
this.filters = {};
|
|
47
|
+
// Used by the template binding.
|
|
48
|
+
this.includeDestroyed = false;
|
|
49
|
+
this.foreachHidesDestroyed = false;
|
|
50
|
+
}
|
|
51
|
+
get jQuery() {
|
|
52
|
+
if (this.disableJQueryUsage) return;
|
|
53
|
+
return this._jQuery ?? globalThis.jQuery;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Set jQuery manuall to be used by TKO.
|
|
57
|
+
* @param jQuery If jQuery set to undefined, TKO will not use jQuery and this.disableJQueryUsage to true.
|
|
58
|
+
*/
|
|
59
|
+
set jQuery(jQuery) {
|
|
60
|
+
if (!jQuery) {
|
|
61
|
+
this.disableJQueryUsage = true;
|
|
62
|
+
this._jQuery = void 0;
|
|
63
|
+
} else {
|
|
64
|
+
this._jQuery = jQuery;
|
|
65
|
+
this.disableJQueryUsage = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sanitize HTML templates before parsing them. Default is a no-op.
|
|
70
|
+
* Please configure something like DOMPurify or validator.js for your environment.
|
|
71
|
+
* @param html HTML string to be sanitized
|
|
72
|
+
* @returns Sanitized HTML string
|
|
73
|
+
*/
|
|
74
|
+
sanitizeHtmlTemplate(html) {
|
|
75
|
+
if (!this._sanitizeWarningLogged) {
|
|
76
|
+
console.warn(
|
|
77
|
+
"WARNING -- You don't have a HTML sanitizer configured. Please configure options.sanitizeHtmlTemplate to avoid XSS vulnerabilities."
|
|
78
|
+
);
|
|
79
|
+
this._sanitizeWarningLogged = true;
|
|
80
|
+
}
|
|
81
|
+
return html;
|
|
82
|
+
}
|
|
83
|
+
onError(e, throws = true) {
|
|
84
|
+
if (throws) throw e;
|
|
85
|
+
return e;
|
|
86
|
+
}
|
|
87
|
+
set(name, value) {
|
|
88
|
+
this[name] = value;
|
|
89
|
+
}
|
|
90
|
+
// Overload getBindingHandler to have a custom lookup function.
|
|
91
|
+
getBindingHandler(key) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
cleanExternalData(node, callback) {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const options = new Options();
|
|
36
98
|
export default options;
|
package/dist/options.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/options.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// This becomes ko.options\n// --\n//\n// This is the root 'options', which must be extended by others.\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { Provider } from '@tko/provider'\nimport type { KnockoutInstance } from '@tko/builder'\n\nexport interface CustomBindingGlobalProperties {\n [customBindingName: string]: any\n}\n\nexport type BindingStringPreparsersFunction = (bindingString: string) => string\n\n//\n// This becomes ko.options\n// --\n//\n// This is the root 'options', which must be extended by others.\nexport class Options {\n // The following options can be set on ko.options to make a function rewriting or something similar.\n bindingStringPreparsers: BindingStringPreparsersFunction[] = []\n\n // Reference to the own knockout instance\n knockoutInstance: KnockoutInstance | null = null\n\n deferUpdates: boolean = false\n\n // Don't set this false, with jquery 3.7+\n useOnlyNativeEvents: boolean = true\n\n // Use HTML5 <template> tags if is supported\n useTemplateTag: boolean = true\n\n protoProperty: string = '__ko_proto__'\n\n // Modify the default attribute from `data-bind`.\n defaultBindingAttribute: string = 'data-bind'\n\n // Enable/disable <!-- ko binding: ... -> style bindings\n allowVirtualElements: boolean = true\n\n // Global variables that can be accessed from bindings.\n bindingGlobals: object & CustomBindingGlobalProperties = Object.create(null)\n\n // An instance of the binding provider.\n bindingProviderInstance: Provider\n\n // Whether the `with` binding creates a child context when used with `as`.\n createChildContextWithAs: boolean = false\n\n // jQuery will be automatically set to globalThis.jQuery in applyBindings\n // if it is (strictly equal to) undefined. Set it to true to\n // disable automatically setting jQuery.\n disableJQueryUsage: boolean = false\n\n get jQuery(): JQueryStatic | undefined {\n if (this.disableJQueryUsage) return\n return this._jQuery ?? (globalThis as any).jQuery\n }\n\n private _jQuery: JQueryStatic | undefined\n /**\n * Set jQuery manuall to be used by TKO.\n * @param jQuery If jQuery set to undefined, TKO will not use jQuery and this.disableJQueryUsage to true.\n */\n set jQuery(jQuery: JQueryStatic | undefined) {\n if (!jQuery) {\n this.disableJQueryUsage = true\n this._jQuery = undefined\n } else {\n this._jQuery = jQuery\n this.disableJQueryUsage = false\n }\n }\n\n Promise: PromiseConstructor = globalThis.Promise\n\n taskScheduler: any = null\n\n debug: boolean = false\n /**\n * The maximum size of template to parse.\n * Set to 0 to disable the limit.\n */\n templateSizeLimit: number = 4096\n\n /**\n * Whether or not to allow script tags in templates.\n * If false, an error will be thrown if a script tag is detected in the template.\n * It is not recommended to set this to true.\n */\n allowScriptTagsInTemplates: boolean = false\n\n private _sanitizeWarningLogged: boolean = false\n /**\n * Sanitize HTML templates before parsing them. Default is a no-op.\n * Please configure something like DOMPurify or validator.js for your environment.\n * @param html HTML string to be sanitized\n * @returns Sanitized HTML string\n */\n sanitizeHtmlTemplate(html: string): string {\n if (!this._sanitizeWarningLogged) {\n console.warn(\n \"WARNING -- You don't have a HTML sanitizer configured. Please configure options.sanitizeHtmlTemplate to avoid XSS vulnerabilities.\"\n )\n this._sanitizeWarningLogged = true\n }\n return html\n }\n\n global: any = globalThis\n\n document: Document = globalThis.document\n\n // Filters for bindings\n // data-bind=\"expression | filter_1 | filter_2\"\n filters: any = {}\n\n // Used by the template binding.\n includeDestroyed: boolean = false\n\n foreachHidesDestroyed: boolean = false\n\n onError(e: any, throws: boolean = true): typeof e {\n if (throws) throw e\n return e\n }\n\n set(name: string, value: any): void {\n this[name] = value\n }\n\n // Overload getBindingHandler to have a custom lookup function.\n getBindingHandler(key: string): any {\n return null\n }\n cleanExternalData(node: Node, callback?: Function) {}\n}\n\nconst options = new Options()\n\nexport default options\n"],
|
|
5
|
+
"mappings": ";;AAcO,aAAM,QAAQ;AAAA,EAAd;AAEL;AAAA,mCAA6D,CAAC;AAG9D;AAAA,4BAA4C;AAE5C,wBAAwB;AAGxB;AAAA,+BAA+B;AAG/B;AAAA,0BAA0B;AAE1B,yBAAwB;AAGxB;AAAA,mCAAkC;AAGlC;AAAA,gCAAgC;AAGhC;AAAA,0BAAyD,uBAAO,OAAO,IAAI;AAM3E;AAAA,oCAAoC;AAKpC;AAAA;AAAA;AAAA,8BAA8B;AAsB9B,mBAA8B,WAAW;AAEzC,yBAAqB;AAErB,iBAAiB;AAKjB;AAAA;AAAA;AAAA;AAAA,6BAA4B;AAO5B;AAAA;AAAA;AAAA;AAAA;AAAA,sCAAsC;AAEtC,SAAQ,yBAAkC;AAiB1C,kBAAc;AAEd,oBAAqB,WAAW;AAIhC;AAAA;AAAA,mBAAe,CAAC;AAGhB;AAAA,4BAA4B;AAE5B,iCAAiC;AAAA;AAAA,EAlEjC,IAAI,SAAmC;AACrC,QAAI,KAAK,mBAAoB;AAC7B,WAAO,KAAK,WAAY,WAAmB;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAO,QAAkC;AAC3C,QAAI,CAAC,QAAQ;AACX,WAAK,qBAAqB;AAC1B,WAAK,UAAU;AAAA,IACjB,OAAO;AACL,WAAK,UAAU;AACf,WAAK,qBAAqB;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BA,qBAAqB,MAAsB;AACzC,QAAI,CAAC,KAAK,wBAAwB;AAChC,cAAQ;AAAA,QACN;AAAA,MACF;AACA,WAAK,yBAAyB;AAAA,IAChC;AACA,WAAO;AAAA,EACT;AAAA,EAeA,QAAQ,GAAQ,SAAkB,MAAgB;AAChD,QAAI,OAAQ,OAAM;AAClB,WAAO;AAAA,EACT;AAAA,EAEA,IAAI,MAAc,OAAkB;AAClC,SAAK,IAAI,IAAI;AAAA,EACf;AAAA;AAAA,EAGA,kBAAkB,KAAkB;AAClC,WAAO;AAAA,EACT;AAAA,EACA,kBAAkB,MAAY,UAAqB;AAAA,EAAC;AACtD;AAEA,MAAM,UAAU,IAAI,QAAQ;AAE5B,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/string.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
2
3
|
export function stringTrim(string) {
|
|
3
4
|
return string === null || string === void 0 ? "" : string.trim ? string.trim() : string.toString().replace(/^[\s\xa0]+|[\s\xa0]+$/g, "");
|
|
4
5
|
}
|
|
@@ -13,10 +14,7 @@ export function parseJson(jsonString) {
|
|
|
13
14
|
if (typeof jsonString === "string") {
|
|
14
15
|
jsonString = stringTrim(jsonString);
|
|
15
16
|
if (jsonString) {
|
|
16
|
-
|
|
17
|
-
return JSON.parse(jsonString);
|
|
18
|
-
}
|
|
19
|
-
return new Function("return " + jsonString)();
|
|
17
|
+
return JSON.parse(jsonString);
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
return null;
|
package/dist/string.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/string.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// String (and JSON)\n//\n\nexport function stringTrim
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// String (and JSON)\n//\n\nexport function stringTrim(string) {\n return string === null || string === undefined\n ? ''\n : string.trim\n ? string.trim()\n : string.toString().replace(/^[\\s\\xa0]+|[\\s\\xa0]+$/g, '')\n}\n\nexport function stringStartsWith(string, startsWith) {\n string = string || ''\n if (startsWith.length > string.length) {\n return false\n }\n return string.substring(0, startsWith.length) === startsWith\n}\n\nexport function parseJson<T = any>(jsonString: string): T | null {\n if (typeof jsonString === 'string') {\n jsonString = stringTrim(jsonString)\n if (jsonString) {\n return JSON.parse(jsonString) as T\n }\n }\n return null\n}\n"],
|
|
5
|
+
"mappings": ";;AAIO,gBAAS,WAAW,QAAQ;AACjC,SAAO,WAAW,QAAQ,WAAW,SACjC,KACA,OAAO,OACL,OAAO,KAAK,IACZ,OAAO,SAAS,EAAE,QAAQ,0BAA0B,EAAE;AAC9D;AAEO,gBAAS,iBAAiB,QAAQ,YAAY;AACnD,WAAS,UAAU;AACnB,MAAI,WAAW,SAAS,OAAO,QAAQ;AACrC,WAAO;AAAA,EACT;AACA,SAAO,OAAO,UAAU,GAAG,WAAW,MAAM,MAAM;AACpD;AAEO,gBAAS,UAAmB,YAA8B;AAC/D,MAAI,OAAO,eAAe,UAAU;AAClC,iBAAa,WAAW,UAAU;AAClC,QAAI,YAAY;AACd,aAAO,KAAK,MAAM,UAAU;AAAA,IAC9B;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/symbol.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
2
|
-
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
3
|
+
export const useSymbols = typeof Symbol === "function";
|
|
3
4
|
export function createSymbolOrString(identifier) {
|
|
4
5
|
return useSymbols ? Symbol(identifier) : identifier;
|
|
5
6
|
}
|
package/dist/symbol.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/symbol.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// ES6 Symbols\n//\n\nexport
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// ES6 Symbols\n//\n\nexport const useSymbols = typeof Symbol === 'function'\n\nexport function createSymbolOrString(identifier) {\n return useSymbols ? Symbol(identifier) : identifier\n}\n"],
|
|
5
|
+
"mappings": ";;AAIO,aAAM,aAAa,OAAO,WAAW;AAErC,gBAAS,qBAAqB,YAAY;AAC/C,SAAO,aAAa,OAAO,UAAU,IAAI;AAC3C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/tasks.js
CHANGED
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
// @tko/utils 🥊 4.0.0
|
|
1
|
+
// @tko/utils 🥊 4.0.0 ESM
|
|
2
|
+
"use strict";
|
|
2
3
|
import options from "./options";
|
|
3
4
|
import { deferError } from "./error";
|
|
4
|
-
|
|
5
|
+
let taskQueue = new Array(), taskQueueLength = 0, nextHandle = 1, nextIndexToProcess = 0, w = options.global;
|
|
5
6
|
if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {
|
|
6
|
-
options.taskScheduler = function(callback) {
|
|
7
|
-
|
|
7
|
+
options.taskScheduler = (function(callback) {
|
|
8
|
+
const div = w.document.createElement("div");
|
|
8
9
|
new w.MutationObserver(callback).observe(div, { attributes: true });
|
|
9
10
|
return function() {
|
|
10
11
|
div.classList.toggle("foo");
|
|
11
12
|
};
|
|
12
|
-
}(scheduledProcess);
|
|
13
|
-
} else if (w && w.document && "onreadystatechange" in w.document.createElement("script")) {
|
|
14
|
-
options.taskScheduler = function(callback) {
|
|
15
|
-
var script = document.createElement("script");
|
|
16
|
-
script.onreadystatechange = function() {
|
|
17
|
-
script.onreadystatechange = null;
|
|
18
|
-
document.documentElement.removeChild(script);
|
|
19
|
-
script = null;
|
|
20
|
-
callback();
|
|
21
|
-
};
|
|
22
|
-
document.documentElement.appendChild(script);
|
|
23
|
-
};
|
|
13
|
+
})(scheduledProcess);
|
|
24
14
|
} else {
|
|
25
15
|
options.taskScheduler = function(callback) {
|
|
26
16
|
setTimeout(callback, 0);
|
|
@@ -28,8 +18,8 @@ if (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {
|
|
|
28
18
|
}
|
|
29
19
|
function processTasks() {
|
|
30
20
|
if (taskQueueLength) {
|
|
31
|
-
|
|
32
|
-
for (
|
|
21
|
+
let mark = taskQueueLength, countMarks = 0;
|
|
22
|
+
for (let task; nextIndexToProcess < taskQueueLength; ) {
|
|
33
23
|
if (task = taskQueue[nextIndexToProcess++]) {
|
|
34
24
|
if (nextIndexToProcess > mark) {
|
|
35
25
|
if (++countMarks >= 5e3) {
|
|
@@ -63,13 +53,13 @@ export function schedule(func) {
|
|
|
63
53
|
return nextHandle++;
|
|
64
54
|
}
|
|
65
55
|
export function cancel(handle) {
|
|
66
|
-
|
|
56
|
+
const index = handle - (nextHandle - taskQueueLength);
|
|
67
57
|
if (index >= nextIndexToProcess && index < taskQueueLength) {
|
|
68
58
|
taskQueue[index] = null;
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
61
|
export function resetForTesting() {
|
|
72
|
-
|
|
62
|
+
const length = taskQueueLength - nextIndexToProcess;
|
|
73
63
|
nextIndexToProcess = taskQueueLength = taskQueue.length = 0;
|
|
74
64
|
return length;
|
|
75
65
|
}
|
package/dist/tasks.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/tasks.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Tasks Micro-scheduler\n// ===\n//\n/* eslint no-cond-assign: 0 */\nimport options from './options'\nimport { deferError } from './error'\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// Tasks Micro-scheduler\n// ===\n//\n/* eslint no-cond-assign: 0 */\nimport options from './options'\nimport { deferError } from './error'\n\nlet taskQueue = new Array(),\n taskQueueLength = 0,\n nextHandle = 1,\n nextIndexToProcess = 0,\n w = options.global\n\nif (w && w.MutationObserver && !(w.navigator && w.navigator.standalone)) {\n // Chrome 27+, Firefox 14+, IE 11+, Opera 15+, Safari 6.1+, node\n // From https://github.com/petkaantonov/bluebird * Copyright (c) 2014 Petka Antonov * License: MIT\n options.taskScheduler = (function (callback) {\n const div = w.document.createElement('div')\n new w.MutationObserver(callback).observe(div, { attributes: true })\n return function () {\n div.classList.toggle('foo')\n }\n })(scheduledProcess)\n} else {\n options.taskScheduler = function (callback) {\n setTimeout(callback, 0)\n }\n}\n\nfunction processTasks() {\n if (taskQueueLength) {\n // Each mark represents the end of a logical group of tasks and the number of these groups is\n // limited to prevent unchecked recursion.\n let mark = taskQueueLength,\n countMarks = 0\n\n // nextIndexToProcess keeps track of where we are in the queue; processTasks can be called recursively without issue\n for (let task; nextIndexToProcess < taskQueueLength; ) {\n if ((task = taskQueue[nextIndexToProcess++])) {\n if (nextIndexToProcess > mark) {\n if (++countMarks >= 5000) {\n nextIndexToProcess = taskQueueLength // skip all tasks remaining in the queue since any of them could be causing the recursion\n deferError(Error(\"'Too much recursion' after processing \" + countMarks + ' task groups.'))\n break\n }\n mark = taskQueueLength\n }\n try {\n task()\n } catch (ex) {\n deferError(ex)\n }\n }\n }\n }\n}\n\nfunction scheduledProcess() {\n processTasks()\n\n // Reset the queue\n nextIndexToProcess = taskQueueLength = taskQueue.length = 0\n}\n\nfunction scheduleTaskProcessing() {\n options.taskScheduler(scheduledProcess)\n}\n\nexport function schedule(func: () => any): number {\n if (!taskQueueLength) {\n scheduleTaskProcessing()\n }\n\n taskQueue[taskQueueLength++] = func\n return nextHandle++\n}\n\nexport function cancel(handle: number) {\n const index = handle - (nextHandle - taskQueueLength)\n if (index >= nextIndexToProcess && index < taskQueueLength) {\n taskQueue[index] = null\n }\n}\n\n// For testing only: reset the queue and return the previous queue length\nexport function resetForTesting() {\n const length = taskQueueLength - nextIndexToProcess\n nextIndexToProcess = taskQueueLength = taskQueue.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