Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement โ†’
Sign In

@tko/provider.component

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tko/provider.component - npm Package Compare versions

Comparing version
4.0.1
to
4.1.0
+5
README.md
# @tko/provider.component
Binding provider for custom web components
Part of [TKO](https://tko.io) โ€” modern Knockout.js. [Docs](https://tko.io) ยท [Source](https://github.com/knockout/tko/tree/main/packages/provider.component)
+2
-2

@@ -1,2 +0,2 @@

// @tko/provider.component ๐ŸฅŠ 4.0.1 ESM
// @tko/provider.component ๐ŸฅŠ 4.1.0 ESM
"use strict";

@@ -51,3 +51,3 @@ import { tagNameLower, objectMap } from "@tko/utils";

const hasDash = tagName.includes("-");
const isUnknownEntity = "" + node === "[object HTMLUnknownElement]";
const isUnknownEntity = Object.prototype.toString.call(node) === "[object HTMLUnknownElement]";
if (hasDash || isUnknownEntity) {

@@ -54,0 +54,0 @@ return tagName;

{
"version": 3,
"sources": ["../src/ComponentProvider.ts"],
"sourcesContent": ["import { tagNameLower, objectMap } from '@tko/utils'\n\nimport registry from '@tko/utils.component'\n\nimport { unwrap, isWriteableObservable } from '@tko/observable'\n\nimport { computed } from '@tko/computed'\n\nimport { Provider } from '@tko/provider'\n\nimport { Parser } from '@tko/utils.parser'\n\nexport default class ComponentProvider extends Provider {\n override get FOR_NODE_TYPES() {\n return [Node.ELEMENT_NODE]\n }\n\n /**\n * Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->\n * @param {Node} node\n */\n override preprocessNode(node: Node): Node[] | null {\n if (node instanceof Element && node.tagName === 'SLOT') {\n const parent = node.parentNode\n const slotName = node.getAttribute('name') || ''\n const openNode = document.createComment(`ko slot: \"${slotName}\"`)\n const closeNode = document.createComment('/ko')\n\n if (!parent) {\n throw Error('Missing parent node')\n }\n\n parent.insertBefore(openNode, node)\n parent.insertBefore(closeNode, node)\n parent.removeChild(node)\n\n return [openNode, closeNode]\n }\n return null\n }\n\n override nodeHasBindings(node: Node): boolean {\n return Boolean(this.getComponentNameForNode(node))\n }\n\n override getBindingAccessors(node: Node, context) {\n const componentName = this.getComponentNameForNode(node)\n if (!componentName) {\n return Object.create(null)\n }\n const component = () => ({ name: componentName, params: this.getComponentParams(node, context) })\n return { component }\n }\n\n getComponentNameForNode(node: Node): string | null {\n if (!(node instanceof Element) || node.nodeType !== Node.ELEMENT_NODE) {\n return null\n }\n const tagName = tagNameLower(node)\n if (registry.isRegistered(tagName)) {\n const hasDash = tagName.includes('-')\n const isUnknownEntity = '' + node === '[object HTMLUnknownElement]'\n if (hasDash || isUnknownEntity) {\n return tagName\n }\n }\n return null\n }\n\n getComponentParams(node: Node, context) {\n if (!(node instanceof Element)) {\n return { $raw: {} }\n }\n\n const parser = new (Parser as any)(node, context, this.globals) as Parser\n const paramsString = (node.getAttribute('params') || '').trim()\n const accessors = parser.parse(paramsString, context, undefined, node)\n if (!accessors || Object.keys(accessors).length === 0) {\n return { $raw: {} }\n }\n const $raw = objectMap(accessors, value => computed(value, null, { disposeWhenNodeIsRemoved: node }))\n const params = objectMap($raw, v => this.makeParamValue(node, v))\n return Object.assign({ $raw }, params)\n }\n\n makeParamValue(node: Element, paramValueComputed) {\n const paramValue = paramValueComputed.peek()\n // Does the evaluation of the parameter value unwrap any observables?\n if (!paramValueComputed.isActive()) {\n // No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.\n // Example: \"someVal: firstName, age: 123\" (whether or not firstName is an observable/computed)\n return paramValue\n }\n // Yes it does. Supply a computed property that unwraps both the outer (binding expression)\n // level of observability, and any inner (resulting model value) level of observability.\n // This means the component doesn't have to worry about multiple unwrapping. If the value is a\n // writable observable, the computed will also be writable and pass the value on to the observable.\n const isWriteable = isWriteableObservable(paramValue)\n\n return computed({\n read: () => unwrap(paramValueComputed()),\n write: isWriteable ? v => paramValueComputed()(v) : undefined,\n disposeWhenNodeIsRemoved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AAO,GAAG;AAClC,YAAM,UAAU,QAAQ,SAAS,GAAG;AACpC,YAAM,kBAAkB,KAAK,SAAS;AACtC,UAAI,WAAW,iBAAiB;AAC9B,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,mBAAmB,MAAY,SAAS;AACtC,QAAI,EAAE,gBAAgB,UAAU;AAC9B,aAAO,EAAE,MAAM,CAAC,EAAE;AAAA,IACpB;AAEA,UAAM,SAAS,IAAK,OAAe,MAAM,SAAS,KAAK,OAAO;AAC9D,UAAM,gBAAgB,KAAK,aAAa,QAAQ,KAAK,IAAI,KAAK;AAC9D,UAAM,YAAY,OAAO,MAAM,cAAc,SAAS,QAAW,IAAI;AACrE,QAAI,CAAC,aAAa,OAAO,KAAK,SAAS,EAAE,WAAW,GAAG;AACrD,aAAO,EAAE,MAAM,CAAC,EAAE;AAAA,IACpB;AACA,UAAM,OAAO,UAAU,WAAW,WAAS,SAAS,OAAO,MAAM,EAAE,0BAA0B,KAAK,CAAC,CAAC;AACpG,UAAM,SAAS,UAAU,MAAM,OAAK,KAAK,eAAe,MAAM,CAAC,CAAC;AAChE,WAAO,OAAO,OAAO,EAAE,KAAK,GAAG,MAAM;AAAA,EACvC;AAAA,EAEA,eAAe,MAAe,oBAAoB;AAChD,UAAM,aAAa,mBAAmB,KAAK;AAE3C,QAAI,CAAC,mBAAmB,SAAS,GAAG;AAGlC,aAAO;AAAA,IACT;AAKA,UAAM,cAAc,sBAAsB,UAAU;AAEpD,WAAO,SAAS;AAAA,MACd,MAAM,MAAM,OAAO,mBAAmB,CAAC;AAAA,MACvC,OAAO,cAAc,OAAK,mBAAmB,EAAE,CAAC,IAAI;AAAA,MACpD,0BAA0B;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;",
"sourcesContent": ["import { tagNameLower, objectMap } from '@tko/utils'\n\nimport registry from '@tko/utils.component'\n\nimport { unwrap, isWriteableObservable } from '@tko/observable'\n\nimport { computed } from '@tko/computed'\n\nimport { Provider } from '@tko/provider'\n\nimport { Parser } from '@tko/utils.parser'\n\nexport default class ComponentProvider extends Provider {\n override get FOR_NODE_TYPES() {\n return [Node.ELEMENT_NODE]\n }\n\n /**\n * Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->\n * @param {Node} node\n */\n override preprocessNode(node: Node): Node[] | null {\n if (node instanceof Element && node.tagName === 'SLOT') {\n const parent = node.parentNode\n const slotName = node.getAttribute('name') || ''\n const openNode = document.createComment(`ko slot: \"${slotName}\"`)\n const closeNode = document.createComment('/ko')\n\n if (!parent) {\n throw Error('Missing parent node')\n }\n\n parent.insertBefore(openNode, node)\n parent.insertBefore(closeNode, node)\n parent.removeChild(node)\n\n return [openNode, closeNode]\n }\n return null\n }\n\n override nodeHasBindings(node: Node): boolean {\n return Boolean(this.getComponentNameForNode(node))\n }\n\n override getBindingAccessors(node: Node, context) {\n const componentName = this.getComponentNameForNode(node)\n if (!componentName) {\n return Object.create(null)\n }\n const component = () => ({ name: componentName, params: this.getComponentParams(node, context) })\n return { component }\n }\n\n getComponentNameForNode(node: Node): string | null {\n if (!(node instanceof Element) || node.nodeType !== Node.ELEMENT_NODE) {\n return null\n }\n const tagName = tagNameLower(node)\n if (registry.isRegistered(tagName)) {\n const hasDash = tagName.includes('-')\n const isUnknownEntity = Object.prototype.toString.call(node) === '[object HTMLUnknownElement]'\n if (hasDash || isUnknownEntity) {\n return tagName\n }\n }\n return null\n }\n\n getComponentParams(node: Node, context) {\n if (!(node instanceof Element)) {\n return { $raw: {} }\n }\n\n const parser = new (Parser as any)(node, context, this.globals) as Parser\n const paramsString = (node.getAttribute('params') || '').trim()\n const accessors = parser.parse(paramsString, context, undefined, node)\n if (!accessors || Object.keys(accessors).length === 0) {\n return { $raw: {} }\n }\n const $raw = objectMap(accessors, value => computed(value, null, { disposeWhenNodeIsRemoved: node }))\n const params = objectMap($raw, v => this.makeParamValue(node, v))\n return Object.assign({ $raw }, params)\n }\n\n makeParamValue(node: Element, paramValueComputed) {\n const paramValue = paramValueComputed.peek()\n // Does the evaluation of the parameter value unwrap any observables?\n if (!paramValueComputed.isActive()) {\n // No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.\n // Example: \"someVal: firstName, age: 123\" (whether or not firstName is an observable/computed)\n return paramValue\n }\n // Yes it does. Supply a computed property that unwraps both the outer (binding expression)\n // level of observability, and any inner (resulting model value) level of observability.\n // This means the component doesn't have to worry about multiple unwrapping. If the value is a\n // writable observable, the computed will also be writable and pass the value on to the observable.\n const isWriteable = isWriteableObservable(paramValue)\n\n return computed({\n read: () => unwrap(paramValueComputed()),\n write: isWriteable ? v => paramValueComputed()(v) : undefined,\n disposeWhenNodeIsRemoved: node\n })\n }\n}\n"],
"mappings": ";;AAAA,SAAS,cAAc,iBAAiB;AAExC,OAAO,cAAc;AAErB,SAAS,QAAQ,6BAA6B;AAE9C,SAAS,gBAAgB;AAEzB,SAAS,gBAAgB;AAEzB,SAAS,cAAc;AAEvB,qBAAqB,0BAA0B,SAAS;AAAA,EACtD,IAAa,iBAAiB;AAC5B,WAAO,CAAC,KAAK,YAAY;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,eAAe,MAA2B;AACjD,QAAI,gBAAgB,WAAW,KAAK,YAAY,QAAQ;AACtD,YAAM,SAAS,KAAK;AACpB,YAAM,WAAW,KAAK,aAAa,MAAM,KAAK;AAC9C,YAAM,WAAW,SAAS,cAAc,aAAa,QAAQ,GAAG;AAChE,YAAM,YAAY,SAAS,cAAc,KAAK;AAE9C,UAAI,CAAC,QAAQ;AACX,cAAM,MAAM,qBAAqB;AAAA,MACnC;AAEA,aAAO,aAAa,UAAU,IAAI;AAClC,aAAO,aAAa,WAAW,IAAI;AACnC,aAAO,YAAY,IAAI;AAEvB,aAAO,CAAC,UAAU,SAAS;AAAA,IAC7B;AACA,WAAO;AAAA,EACT;AAAA,EAES,gBAAgB,MAAqB;AAC5C,WAAO,QAAQ,KAAK,wBAAwB,IAAI,CAAC;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A,eAAe,MAAe,oBAAoB;AAChD,UAAM,aAAa,mBAAmB,KAAK;AAE3C,QAAI,CAAC,mBAAmB,SAAS,GAAG;AAGlC,aAAO;AAAA,IACT;AAKA,UAAM,cAAc,sBAAsB,UAAU;AAEpD,WAAO,SAAS;AAAA,MACd,MAAM,MAAM,OAAO,mBAAmB,CAAC;AAAA,MACvC,OAAO,cAAc,OAAK,mBAAmB,EAAE,CAAC,IAAI;AAAA,MACpD,0BAA0B;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;",
"names": []
}

@@ -1,2 +0,2 @@

// @tko/provider.component ๐ŸฅŠ 4.0.1 CommonJS
// @tko/provider.component ๐ŸฅŠ 4.1.0 CommonJS
"use strict";

@@ -87,3 +87,3 @@ var __create = Object.create;

const hasDash = tagName.includes("-");
const isUnknownEntity = "" + node === "[object HTMLUnknownElement]";
const isUnknownEntity = Object.prototype.toString.call(node) === "[object HTMLUnknownElement]";
if (hasDash || isUnknownEntity) {

@@ -90,0 +90,0 @@ return tagName;

{
"version": 3,
"sources": ["../index.ts", "../src/ComponentProvider.ts"],
"sourcesContent": ["export * from './src'\n", "import { tagNameLower, objectMap } from '@tko/utils'\n\nimport registry from '@tko/utils.component'\n\nimport { unwrap, isWriteableObservable } from '@tko/observable'\n\nimport { computed } from '@tko/computed'\n\nimport { Provider } from '@tko/provider'\n\nimport { Parser } from '@tko/utils.parser'\n\nexport default class ComponentProvider extends Provider {\n override get FOR_NODE_TYPES() {\n return [Node.ELEMENT_NODE]\n }\n\n /**\n * Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->\n * @param {Node} node\n */\n override preprocessNode(node: Node): Node[] | null {\n if (node instanceof Element && node.tagName === 'SLOT') {\n const parent = node.parentNode\n const slotName = node.getAttribute('name') || ''\n const openNode = document.createComment(`ko slot: \"${slotName}\"`)\n const closeNode = document.createComment('/ko')\n\n if (!parent) {\n throw Error('Missing parent node')\n }\n\n parent.insertBefore(openNode, node)\n parent.insertBefore(closeNode, node)\n parent.removeChild(node)\n\n return [openNode, closeNode]\n }\n return null\n }\n\n override nodeHasBindings(node: Node): boolean {\n return Boolean(this.getComponentNameForNode(node))\n }\n\n override getBindingAccessors(node: Node, context) {\n const componentName = this.getComponentNameForNode(node)\n if (!componentName) {\n return Object.create(null)\n }\n const component = () => ({ name: componentName, params: this.getComponentParams(node, context) })\n return { component }\n }\n\n getComponentNameForNode(node: Node): string | null {\n if (!(node instanceof Element) || node.nodeType !== Node.ELEMENT_NODE) {\n return null\n }\n const tagName = tagNameLower(node)\n if (registry.isRegistered(tagName)) {\n const hasDash = tagName.includes('-')\n const isUnknownEntity = '' + node === '[object HTMLUnknownElement]'\n if (hasDash || isUnknownEntity) {\n return tagName\n }\n }\n return null\n }\n\n getComponentParams(node: Node, context) {\n if (!(node instanceof Element)) {\n return { $raw: {} }\n }\n\n const parser = new (Parser as any)(node, context, this.globals) as Parser\n const paramsString = (node.getAttribute('params') || '').trim()\n const accessors = parser.parse(paramsString, context, undefined, node)\n if (!accessors || Object.keys(accessors).length === 0) {\n return { $raw: {} }\n }\n const $raw = objectMap(accessors, value => computed(value, null, { disposeWhenNodeIsRemoved: node }))\n const params = objectMap($raw, v => this.makeParamValue(node, v))\n return Object.assign({ $raw }, params)\n }\n\n makeParamValue(node: Element, paramValueComputed) {\n const paramValue = paramValueComputed.peek()\n // Does the evaluation of the parameter value unwrap any observables?\n if (!paramValueComputed.isActive()) {\n // No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.\n // Example: \"someVal: firstName, age: 123\" (whether or not firstName is an observable/computed)\n return paramValue\n }\n // Yes it does. Supply a computed property that unwraps both the outer (binding expression)\n // level of observability, and any inner (resulting model value) level of observability.\n // This means the component doesn't have to worry about multiple unwrapping. If the value is a\n // writable observable, the computed will also be writable and pass the value on to the observable.\n const isWriteable = isWriteableObservable(paramValue)\n\n return computed({\n read: () => unwrap(paramValueComputed()),\n write: isWriteable ? v => paramValueComputed()(v) : undefined,\n disposeWhenNodeIsRemo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ko/utils.component'\n\nimport { unwrap, isWriteableObservable } from '@tko/observable'\n\nimport { computed } from '@tko/computed'\n\nimport { Provider } from '@tko/provider'\n\nimport { Parser } from '@tko/utils.parser'\n\nexport default class ComponentProvider extends Provider {\n override get FOR_NODE_TYPES() {\n return [Node.ELEMENT_NODE]\n }\n\n /**\n * Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->\n * @param {Node} node\n */\n override preprocessNode(node: Node): Node[] | null {\n if (node instanceof Element && node.tagName === 'SLOT') {\n const parent = node.parentNode\n const slotName = node.getAttribute('name') || ''\n const openNode = document.createComment(`ko slot: \"${slotName}\"`)\n const closeNode = document.createComment('/ko')\n\n if (!parent) {\n throw Error('Missing parent node')\n }\n\n parent.insertBefore(openNode, node)\n parent.insertBefore(closeNode, node)\n parent.removeChild(node)\n\n return [openNode, closeNode]\n }\n return null\n }\n\n override nodeHasBindings(node: Node): boolean {\n return Boolean(this.getComponentNameForNode(node))\n }\n\n override getBindingAccessors(node: Node, context) {\n const componentName = this.getComponentNameForNode(node)\n if (!componentName) {\n return Object.create(null)\n }\n const component = () => ({ name: componentName, params: this.getComponentParams(node, context) })\n return { component }\n }\n\n getComponentNameForNode(node: Node): string | null {\n if (!(node instanceof Element) || node.nodeType !== Node.ELEMENT_NODE) {\n return null\n }\n const tagName = tagNameLower(node)\n if (registry.isRegistered(tagName)) {\n const hasDash = tagName.includes('-')\n const isUnknownEntity = Object.prototype.toString.call(node) === '[object HTMLUnknownElement]'\n if (hasDash || isUnknownEntity) {\n return tagName\n }\n }\n return null\n }\n\n getComponentParams(node: Node, context) {\n if (!(node instanceof Element)) {\n return { $raw: {} }\n }\n\n const parser = new (Parser as any)(node, context, this.globals) as Parser\n const paramsString = (node.getAttribute('params') || '').trim()\n const accessors = parser.parse(paramsString, context, undefined, node)\n if (!accessors || Object.keys(accessors).length === 0) {\n return { $raw: {} }\n }\n const $raw = objectMap(accessors, value => computed(value, null, { disposeWhenNodeIsRemoved: node }))\n const params = objectMap($raw, v => this.makeParamValue(node, v))\n return Object.assign({ $raw }, params)\n }\n\n makeParamValue(node: Element, paramValueComputed) {\n const paramValue = paramValueComputed.peek()\n // Does the evaluation of the parameter value unwrap any observables?\n if (!paramValueComputed.isActive()) {\n // No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.\n // Example: \"someVal: firstName, age: 123\" (whether or not firstName is an observable/computed)\n return paramValue\n }\n // Yes it does. Supply a computed property that unwraps both the outer (binding expression)\n // level of observability, and any inner (resulting model value) level of observability.\n // This means the component doesn't have to worry about multiple unwrapping. If the value is a\n // writable observable, the computed will also be writable and pass the value on to the observable.\n const isWriteable = isWriteableObservable(paramValue)\n\n return computed({\n read: () => unwrap(paramValueComputed()),\n write: isWriteable ? v => paramValueComputed()(v) : undefined,\n disposeWhenNodeIsRemoved: node\n })\n }\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAwC;AAExC,IAAAA,gBAAqB;AAErB,wBAA8C;AAE9C,sBAAyB;AAEzB,sBAAyB;AAEzB,IAAAA,gBAAuB;AAEvB,IAAqB,oBAArB,cAA+C,yBAAS;AAAA,EACtD,IAAa,iBAAiB;AAC5B,WAAO,CAAC,KAAK,YAAY;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,eAAe,MAA2B;AACjD,QAAI,gBAAgB,WAAW,KAAK,YAAY,QAAQ;AACtD,YAAM,SAAS,KAAK;AACpB,YAAM,WAAW,KAAK,aAAa,MAAM,KAAK;AAC9C,YAAM,WAAW,SAAS,cAAc,aAAa,QAAQ,GAAG;AAChE,YAAM,YAAY,SAAS,cAAc,KAAK;AAE9C,UAAI,CAAC,QAAQ;AACX,cAAM,MAAM,qBAAqB;AAAA,MACnC;AAEA,aAAO,aAAa,UAAU,IAAI;AAClC,aAAO,aAAa,WAAW,IAAI;AACnC,aAAO,YAAY,IAAI;AAEvB,aAAO,CAAC,UAA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AAM,aAAS,wBAAU,MAAM,OAAK,KAAK,eAAe,MAAM,CAAC,CAAC;AAChE,WAAO,OAAO,OAAO,EAAE,KAAK,GAAG,MAAM;AAAA,EACvC;AAAA,EAEA,eAAe,MAAe,oBAAoB;AAChD,UAAM,aAAa,mBAAmB,KAAK;AAE3C,QAAI,CAAC,mBAAmB,SAAS,GAAG;AAGlC,aAAO;AAAA,IACT;AAKA,UAAM,kBAAc,yCAAsB,UAAU;AAEpD,eAAO,0BAAS;AAAA,MACd,MAAM,UAAM,0BAAO,mBAAmB,CAAC;AAAA,MACvC,OAAO,cAAc,OAAK,mBAAmB,EAAE,CAAC,IAAI;AAAA,MACpD,0BAA0B;AAAA,IAC5B,CAAC;AAAA,EACH;AACF;",
"names": ["import_utils", "registry"]
}

@@ -1,3 +0,3 @@

// @tko/provider.component ๐ŸฅŠ 4.0.1 ESM
// @tko/provider.component ๐ŸฅŠ 4.1.0 ESM
"use strict";
export { default as ComponentProvider } from "./ComponentProvider.js";

@@ -1,3 +0,3 @@

// @tko/provider.component ๐ŸฅŠ 4.0.1 MJS
// @tko/provider.component ๐ŸฅŠ 4.1.0 MJS
"use strict";
export { default as ComponentProvider } from "./ComponentProvider.js";
{
"version": "4.0.1",
"version": "4.1.0",
"name": "@tko/provider.component",

@@ -11,9 +11,8 @@ "description": "Bind custom web components e.g. <custom-binding>",

"dependencies": {
"@tko/computed": "^4.0.1",
"@tko/observable": "^4.0.1",
"@tko/provider": "^4.0.1",
"@tko/utils": "^4.0.1",
"@tko/utils.component": "^4.0.1",
"@tko/utils.parser": "^4.0.1",
"tslib": "^2.2.0"
"@tko/computed": "^4.1.0",
"@tko/observable": "^4.1.0",
"@tko/provider": "^4.1.0",
"@tko/utils": "^4.1.0",
"@tko/utils.component": "^4.1.0",
"@tko/utils.parser": "^4.1.0"
},

@@ -43,3 +42,10 @@ "homepage": "https://tko.io",

"build": "bun ../../tools/build.ts"
}
},
"keywords": [
"knockout",
"tko",
"provider",
"web-components",
"custom-elements"
]
}