kt.js 0.0.6 → 0.0.8
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/README.md +5 -3
- package/README.zh.md +5 -3
- package/dist/index.d.ts +44 -14
- package/dist/index.mjs +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# KT.js
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
[](https://github.com/baendlorel/kt.js/blob/main/LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[中文](README.zh.md) | [English](README.md) | [CHANGLOG](CHANGELOG.md)
|
|
6
6
|
|
|
7
|
-
> Note:
|
|
7
|
+
> Note: This framework is still under development. APIs, type declarations, and other parts may change. If you use it, please watch for updates in the near future.
|
|
8
8
|
|
|
9
9
|
KT.js is a tiny, high-performance DOM utility focused on minimal re-rendering and direct DOM manipulation. It favors not forcing re-renders and aims to keep DOM updates to the absolute minimum for maximum performance.
|
|
10
10
|
|
|
11
|
+
For more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)
|
|
12
|
+
|
|
11
13
|
## Philosophy
|
|
12
14
|
|
|
13
15
|
As a web framework, repeatedly creating a large number of variables and objects is unacceptable. This is a provocation against browsers and the V8 engine(or SpiderMonkey, or JSC). So I created KT.js.
|
package/README.zh.md
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
# KT.js
|
|
2
2
|
|
|
3
|
-
[
|
|
3
|
+
[](https://github.com/baendlorel/kt.js/blob/main/LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[中文](README.zh.md) | [English](README.md) | [更新日志](CHANGELOG.md)
|
|
6
6
|
|
|
7
|
-
> Note:
|
|
7
|
+
> Note: 本框架还在开发中,api、类型声明等可能会有变化,如果使用,近期请关注更新
|
|
8
8
|
|
|
9
9
|
KT.js 是一个微小的高性能 DOM 工具,专注于最小化重绘和直接操作 DOM。它的设计目标是尽量不强制重绘,只在必要时更新 DOM,从而获得极致性能。
|
|
10
10
|
|
|
11
|
+
For more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)
|
|
12
|
+
|
|
11
13
|
## 核心理念
|
|
12
14
|
|
|
13
15
|
作为一个web框架,反复创建大量对象、反复重绘是不可接受的,这是对浏览器和V8引擎(或者SpiderMonkey, 或者说JSC)的挑衅。所以我创建了 KT.js。
|
package/dist/index.d.ts
CHANGED
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
* @param attr attribute object or className
|
|
5
5
|
* @param content a string or an array of HTMLEnhancedElement as child nodes
|
|
6
6
|
*/
|
|
7
|
-
declare function h<
|
|
7
|
+
declare function h<T extends HTMLTag>(tag: T, attr?: KAttribute | string, content?: (HTMLKEnhancedElement | string)[] | HTMLKEnhancedElement | string): HTMLKEnhancedElement<T>;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* ## About
|
|
11
11
|
* @package Kt.js
|
|
12
12
|
* @author Kasukabe Tsumugi <futami16237@gmail.com>
|
|
13
|
-
* @version 0.0.
|
|
13
|
+
* @version 0.0.8 (Last Update: 2025.09.20 15:12:59.928)
|
|
14
14
|
* @license MIT
|
|
15
15
|
* @link https://github.com/baendlorel/kt.js
|
|
16
|
+
* @link https://baendlorel.github.io/ Welcome to my site!
|
|
16
17
|
* @description A simple and easy-to-use web framework, never re-render. Abbreviation of Kasukabe Tsumugi.
|
|
17
18
|
* @copyright Copyright (c) 2025 Kasukabe Tsumugi. All rights reserved.
|
|
18
19
|
*
|
|
@@ -27,11 +28,23 @@ export { createApp, h };
|
|
|
27
28
|
|
|
28
29
|
// # from: src/global.d.ts
|
|
29
30
|
|
|
31
|
+
// # from: src/types/core.d.ts
|
|
32
|
+
type HFunction = <T extends HTMLTag>(
|
|
33
|
+
tag: T,
|
|
34
|
+
attr?: KAttribute | string,
|
|
35
|
+
content?: (HTMLKEnhancedElement | string)[] | HTMLKEnhancedElement | string
|
|
36
|
+
) => HTMLKEnhancedElement<T>;
|
|
37
|
+
|
|
38
|
+
type HAlias<T extends HTMLTag> = (
|
|
39
|
+
attr?: KAttribute | string,
|
|
40
|
+
content?: (HTMLKEnhancedElement | string)[] | HTMLKEnhancedElement | string
|
|
41
|
+
) => HTMLKEnhancedElement<T>;
|
|
30
42
|
|
|
31
43
|
/**
|
|
32
44
|
* Used to create enhanced HTML elements
|
|
33
45
|
*/
|
|
34
46
|
export interface KAttribute {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
48
|
[k: string]: any;
|
|
36
49
|
|
|
37
50
|
id?: string;
|
|
@@ -62,6 +75,11 @@ export interface KAttribute {
|
|
|
62
75
|
| (string & {});
|
|
63
76
|
}
|
|
64
77
|
|
|
78
|
+
// # from: src/types/enhance.d.ts
|
|
79
|
+
export type HTMLTag = keyof HTMLElementTagNameMap;
|
|
80
|
+
|
|
81
|
+
export type KChildren = HTMLKEnhancedElement | Text;
|
|
82
|
+
|
|
65
83
|
interface KOnOptions extends AddEventListenerOptions {
|
|
66
84
|
/**
|
|
67
85
|
* This option's priority is higher than `once`.
|
|
@@ -75,23 +93,17 @@ type KListener<E extends HTMLElement, K extends keyof HTMLElementEventMap> = (
|
|
|
75
93
|
ev: HTMLElementEventMap[K]
|
|
76
94
|
) => unknown;
|
|
77
95
|
|
|
78
|
-
|
|
79
|
-
export type HTMLElementTag = keyof HTMLElementTagNameMap;
|
|
80
|
-
|
|
81
|
-
export type KChildren = HTMLKEnhancedElement | Text;
|
|
82
|
-
|
|
83
|
-
interface KEnhanced {
|
|
96
|
+
interface KEnhancedPrivates {
|
|
84
97
|
/**
|
|
85
98
|
* Unique numeric identifier for a KT.js enhanced element instance.
|
|
86
99
|
* Used internally to track and distinguish enhanced elements.
|
|
87
100
|
*/
|
|
88
|
-
|
|
101
|
+
id: number;
|
|
89
102
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*/
|
|
93
|
-
isKT: true;
|
|
103
|
+
text: Text;
|
|
104
|
+
}
|
|
94
105
|
|
|
106
|
+
interface KEnhanced {
|
|
95
107
|
/**
|
|
96
108
|
* The element's text content as maintained by KT.js.
|
|
97
109
|
* - it is not recommended to use `textContent` any more
|
|
@@ -169,6 +181,24 @@ type NonSpecialTags = {
|
|
|
169
181
|
* It combines the standard HTMLElement properties and methods
|
|
170
182
|
* with KT.js enhancements defined in KEnhanced.
|
|
171
183
|
*/
|
|
172
|
-
export type HTMLKEnhancedElement<T extends
|
|
184
|
+
export type HTMLKEnhancedElement<T extends HTMLTag = NonSpecialTags> =
|
|
173
185
|
(HTMLElement extends HTMLElementTagNameMap[T] ? HTMLElement : HTMLElementTagNameMap[T]) &
|
|
174
186
|
KEnhanced;
|
|
187
|
+
|
|
188
|
+
// # from: src/types/type-utils.d.ts
|
|
189
|
+
type IsSameType<A, B> =
|
|
190
|
+
(<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2
|
|
191
|
+
? (<T>() => T extends B ? 1 : 2) extends <T>() => T extends A ? 1 : 2
|
|
192
|
+
? true
|
|
193
|
+
: false
|
|
194
|
+
: false;
|
|
195
|
+
|
|
196
|
+
type PickProperty<T> = {
|
|
197
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
198
|
+
[K in keyof T as T[K] extends (...args: any[]) => any ? never : K]: T[K];
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
type PickMethod<T> = {
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
|
+
[K in keyof T as T[K] extends (...args: any[]) => any ? K : never]: T[K];
|
|
204
|
+
};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=Symbol("
|
|
1
|
+
const e=Symbol("NotProvided");class t extends(null){static kid=0;static index=0;static genIndex(){return"data-k-"+(++t.index).toString(36).padStart(6,"0")}static nextKid(){return++t.kid}}const n=e=>document.createTextNode(e),o=HTMLElement.prototype.addEventListener,i=HTMLElement.prototype.removeEventListener,r=HTMLElement.prototype.appendChild,s=HTMLElement.prototype.setAttribute,a=Array.isArray,l=Array.from,c=Object.keys,f=Object.assign,m=Object.defineProperties,u=Object.is,T=Number.isSafeInteger,h=e=>"object"==typeof e&&null!==e,E=new WeakMap,d=e=>E.get(e),p=e=>E.has(e),M={kon(t,n,r=e){if(u(r,e))return o.call(this,t,n),n;if(!h(r)||!("triggerLimit"in r))return o.call(this,t,n,r),n;const s=r.triggerLimit;if(delete r.triggerLimit,!T(s)||s<=0)throw new TypeError("[Kt.js:kon] options.triggerLimit must be a positive safe integer.");if(1===s)return r.once=!0,o.call(this,t,n,r),n;let a=s;const l=function(e){const o=n.call(this,e);return a--,a<=0&&i.call(this,t,l,r),o};return o.call(this,t,l,r),l},koff(t,n,o=e){u(e,o)?i.call(this,t,n):i.call(this,t,n,o)},kmount(e){if(!p(e))throw new TypeError("[Kt.js:kmount] target must be a KText element.");return r.call(e,this)}},L={ktext:{get(){return d(this).text.textContent},set(e){d(this).text.textContent=e}},kchildren:{get(){return l(this.children)},set(e){this.textContent="",r.call(this,d(this).text);const t=e.length;for(let o=0;o<t;o++){const t=e[o];if("string"!=typeof t){if(!(t instanceof Text||p(t)))throw new TypeError(`[Kt.js:kchildren] Invalid child element at index ${o}. Only string, Text nodes or KT.js enhanced elements are allowed.`);r.call(this,t)}else r.call(this,n(t))}}}};class H{t=null;o=null;add(e,t){if("function"!=typeof t)throw new TypeError("Branch must be a function");return e&&(this.t=t),this}nomatch(e){if("function"!=typeof e)throw new TypeError("Branch must be a function");return this.t||e(),this}deferedNomatch(e){if("function"!=typeof e)throw new TypeError("Branch must be a function");return this.o=e,this}run(...e){return this.t?this.t(...e):this.o?this.o(...e):void 0}}const y=()=>new H,w=(e,t)=>e.className=t,g=(e,t)=>{t.class&&(a(t.class)?e.classList.add(...t.class):e.className=t.class,delete t.class),t.style&&("string"==typeof t.style?e.setAttribute("style",t.style):f(e.style,t.style),delete t.style);const n=c(t),o=n.length;for(let i=0;i<o;i++){const o=n[i],r=t[o];"function"!=typeof r&&("checked"!==o?"value"!==o?"selected"!==o?"defaultValue"!==o?"defaultChecked"!==o?"defaultSelected"!==o?"disabled"!==o?"readOnly"!==o?"multiple"!==o?"autofocus"!==o?"required"!==o?"hidden"!==o?"open"===o&&e instanceof HTMLDetailsElement?e.open=Boolean(r):"controls"===o&&e instanceof HTMLMediaElement?e.controls=Boolean(r):"autoplay"===o&&e instanceof HTMLMediaElement?e.autoplay=Boolean(r):"loop"===o&&e instanceof HTMLMediaElement?e.loop=Boolean(r):"muted"===o&&e instanceof HTMLMediaElement?e.muted=Boolean(r):"defer"===o&&e instanceof HTMLScriptElement?e.defer=Boolean(r):"async"===o&&e instanceof HTMLScriptElement?e.async=Boolean(r):s.call(e,String(o),r):e.hidden=Boolean(r):e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?e.required=Boolean(r):s.call(e,o,r):e instanceof HTMLInputElement||e instanceof HTMLButtonElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement?e.autofocus=Boolean(r):s.call(e,o,r):e instanceof HTMLSelectElement?e.multiple=Boolean(r):s.call(e,o,r):e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?e.readOnly=Boolean(r):s.call(e,o,r):e instanceof HTMLInputElement||e instanceof HTMLButtonElement||e instanceof HTMLSelectElement||e instanceof HTMLOptGroupElement||e instanceof HTMLOptionElement||e instanceof HTMLFieldSetElement||e instanceof HTMLTextAreaElement?e.disabled=Boolean(r):s.call(e,o,r):e instanceof HTMLOptionElement?e.defaultSelected=Boolean(r):s.call(e,o,r):e instanceof HTMLInputElement?e.defaultChecked=Boolean(r):s.call(e,o,r):e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?e.defaultValue=String(r):s.call(e,o,r):e instanceof HTMLOptionElement?e.selected=Boolean(r):s.call(e,o,r):e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement?e.value=String(r):s.call(e,o,r):e instanceof HTMLInputElement?e.checked=Boolean(r):s.call(e,o,r))}},B=()=>{throw new TypeError("[Kt.js:h] attr must be an object.")},b=(e,t)=>{e.ktext=t},x=(e,t)=>{const o=t.length;for(let i=0;i<o;i++){const o=t[i];"string"!=typeof o?p(o)?r.call(e,o):k():r.call(e,n(o))}},j=(e,t)=>{p(t)||k(),r.call(e,t)},k=()=>{throw new TypeError("[Kt.js:h] content must be a string, HTMLEnhancedElement or an array of HTMLEnhancedElement.")};function S(e,o="",i=""){if("string"!=typeof e)throw new TypeError("[Kt.js:h] tagName must be a string.");const s=(e=>y().add("string"==typeof e,w).add(h(e),g).nomatch(B))(o),l=(e=>y().add("string"==typeof e,b).add(h(e),j).add(a(e),x).nomatch(k))(i),c=(f=e,document.createElement(f));var f;const u=n("");return r.call(c,u),((e,t)=>{E.set(e,t)})(c,{id:t.nextKid(),text:u}),function(e){m(e,L),e.kon=M.kon,e.koff=M.koff,e.kmount=M.kmount}(c),l.run(c,i),s.run(c,o),c}function I(t,n=e){if(!p(t))throw new TypeError("Root element must be a KText element.");const o=(i="app",document.getElementById(i)??document.body);var i;if(u(n,e))r.call(o,t);else if(!h(n))throw new TypeError("mountTo must be an HTMLElement or omitted.")}export{I as createApp,S as h};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kt.js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Kasukabe Tsumugi",
|
|
6
6
|
"email": "futami16237@gmail.com"
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"vitest": "^3.2.4"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
+
"bind-params": "^1.0.2",
|
|
68
69
|
"defered-branch": "^1.2.2"
|
|
69
70
|
}
|
|
70
71
|
}
|