kt.js 0.4.2 → 0.5.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/README.md CHANGED
@@ -1,204 +1,133 @@
1
- # KT.js
1
+ # kt.js
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/kt.js.svg)](https://www.npmjs.com/package/kt.js)
4
- [![license](https://img.shields.io/github/license/baendlorel/kt.js.svg)](https://github.com/baendlorel/kt.js/blob/main/LICENSE)
3
+ <img src="https://raw.githubusercontent.com/baendlorel/kt.js/dev/.assets/ktjs-0.0.1.svg" alt="KT.js Logo" width="150"/>
5
4
 
6
- [CHANGLOG✨](CHANGELOG.md)
5
+ > 📦 Main entry package - For full documentation, see [KT.js](https://raw.githubusercontent.com/baendlorel/kt.js/dev/README.md).
7
6
 
8
- > Note: This framework is still under development. APIs, type declarations, and other parts **may change frequently**. If you use it, please watch for updates in the near future. Feel free to mail me if you have any questions!
7
+ Main entry package for KT.js framework - a simple and easy-to-use web framework that never re-renders.
9
8
 
10
- KT.js is a tiny DOM utility focused on direct DOM manipulation. It favors not forcing re-renders and aims to keep DOM updates to the absolute minimum for maximum performance.
9
+ ## Overview
11
10
 
12
- For more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)
11
+ `kt.js` is the all-in-one package that re-exports everything from the KT.js ecosystem. Install this single package to get access to all features including core DOM utilities, routing, and shortcuts.
13
12
 
14
- ## Philosophy
15
-
16
- As a web framework, repeatedly creating a large number of variables and objects is unacceptable. So I created KT.js.
17
-
18
- KT.js follows one rule: full controll of dom and avoid unless repainting.
19
-
20
- ## Current Core Features
21
-
22
- - **`h` function**: and its aliases
23
- - **Router**:
24
- - Auto-adapt to environment: uses async navigation guards when `Promise` is available, falls back to synchronous mode otherwise
25
- - **Full ES5 compatibility**: works in IE9+ and other legacy browsers
26
- - Transpiled to ES5 with no modern syntax
27
- - Optional minimal Promise polyfill included for older environments
28
- - **ktnull**: a special value representing "null", used for filtering. Since native DOM APIs do not ignore `undefined` or `null`, this feature is provided to maintain native behavior while enhancing usability.
29
-
30
- ## Getting started
31
-
32
- ### Using IIFE (direct browser usage)
33
-
34
- KT.js provides an IIFE build that can be included directly in HTML:
35
-
36
- ```html
37
- <script src="https://unpkg.com/kt.js@0.3.0/dist/index.iife.js"></script>
38
- <script>
39
- // kt is available globally
40
- const { h, div } = kt;
41
- const app = div('container', 'Hello World');
42
- document.body.appendChild(app);
43
- </script>
44
- ```
45
-
46
- ### Using ES Modules
47
-
48
- Install via package managers:
13
+ ## Installation
49
14
 
50
15
  ```bash
51
- npm install kt.js
52
- # or
53
16
  pnpm add kt.js
54
17
  ```
55
18
 
56
- ```ts
57
- import { h, div } from 'kt.js';
58
-
59
- const container = div('container', [div('header'), div('body', 'something'), div('footer')]);
60
- const app = h('section', { id: 'app' }, container);
61
- ```
19
+ ## What's Included
62
20
 
63
- This will create the following DOM structure:
21
+ This package re-exports everything from:
64
22
 
65
- ```html
66
- <section id="app">
67
- <div class="container">
68
- <div class="header"></div>
69
- <div class="body">something</div>
70
- <div class="footer"></div>
71
- </div>
72
- </section>
73
- ```
23
+ - **`@ktjs/core`** - Core DOM manipulation utilities
24
+ - `h` function for creating elements
25
+ - `ktnull` for conditional rendering
26
+ - Runtime utilities and helpers
27
+ - **`@ktjs/shortcuts`** - Convenient shortcuts
28
+ - Element creation shortcuts (div, span, button, etc.)
29
+ - `withDefaults` for creating element factories
30
+ - Form helpers and layout utilities
74
31
 
75
- If you give a function in the attributes, it will be treated as an event listener, and the key will be considered as the event name:
32
+ **Note:** The router (`@ktjs/router`) is a separate package and needs to be installed independently.
76
33
 
77
- ```ts
78
- const button = btn({ click: () => alert('Clicked!') }, 'Click me');
79
- // this equals
80
- const button = btn(undefined, 'Click me');
81
- button.addEventListener('click', () => alert('Clicked!'));
82
- ```
34
+ ## Quick Start
83
35
 
84
- Work with `@emotion/css`
36
+ ```typescript
37
+ import { h, div, button, withDefaults } from 'kt.js';
85
38
 
86
- ```ts
87
- import { css } from '@emotion/css';
39
+ // Create elements
40
+ const app = div('app', [h('h1', {}, 'Welcome to KT.js'), button({ '@click': () => alert('Hello!') }, 'Click me')]);
88
41
 
89
- const className = css`
90
- color: red;
91
- font-size: 20px;
92
- `;
42
+ // Use shortcuts with defaults
43
+ const card = withDefaults(div, { class: 'card' });
44
+ const myCard = card('card-body', 'Card content');
93
45
 
94
- h('div', { class: className }, 'Styled text');
46
+ document.body.appendChild(app);
95
47
  ```
96
48
 
97
- ## Router
49
+ ### Using with Router
98
50
 
99
- KT.js includes a lightweight client-side router (hash-based):
51
+ If you need routing, install `@ktjs/router` separately:
100
52
 
101
- ```ts
102
- import { createRouter, div, h1 } from 'kt.js';
53
+ ```bash
54
+ pnpm add @ktjs/router
55
+ ```
56
+
57
+ ```typescript
58
+ import { div } from 'kt.js';
59
+ import { createRouter } from '@ktjs/router';
103
60
 
104
61
  const router = createRouter({
105
62
  routes: [
106
63
  {
107
64
  path: '/',
108
- handler: () => div({}, [h1({}, 'Home Page')]),
65
+ name: 'home',
66
+ beforeEnter: (to) => {
67
+ const app = document.getElementById('app')!;
68
+ app.innerHTML = '';
69
+ app.appendChild(div({}, 'Home Page'));
70
+ },
109
71
  },
110
72
  {
111
- path: '/user/:id',
112
- handler: (ctx) => div({}, [h1({}, `User ${ctx.params.id}`)]),
73
+ path: '/about',
74
+ name: 'about',
75
+ beforeEnter: (to) => {
76
+ const app = document.getElementById('app')!;
77
+ app.innerHTML = '';
78
+ app.appendChild(div({}, 'About Page'));
79
+ },
113
80
  },
114
81
  ],
115
- container: document.getElementById('app'),
116
- beforeEach: async (to, from) => {
117
- // Navigation guard - return false to block navigation
118
- console.log('navigating to:', to.path);
119
- return true;
120
- },
121
- afterEach: (to) => {
122
- // Called after successful navigation
123
- document.title = to.path;
124
- },
125
- onError: (error) => {
126
- console.error('Router error:', error);
127
- },
128
82
  });
129
83
 
130
- router.start();
131
-
132
- // Navigate programmatically
133
- router.push('/user/123');
134
- router.push('/user/456?page=2');
135
-
136
- // Get current route
137
- const current = router.current();
138
- console.log(current?.path, current?.params, current?.query);
84
+ router.push('/');
139
85
  ```
140
86
 
141
- **Features:**
87
+ ## Why Use the Main Package?
142
88
 
143
- - Hash-based routing (`#/path`)
144
- - Dynamic route parameters (`/user/:id`)
145
- - Query string parsing (`?key=value`)
146
- - Async navigation guards (`beforeEach`) - automatically disabled in non-Promise environments
147
- - Lifecycle hooks (`afterEach`)
148
- - Error handling (`onError`)
149
- - Minimal footprint
89
+ - **Convenience**: Single import for all KT.js functionality
90
+ - **Simplicity**: No need to manage multiple package versions
91
+ - **Complete**: Get all features out of the box
92
+ - **Optimized**: Proper tree-shaking ensures you only bundle what you use
150
93
 
151
- ## `ktnull`
94
+ ## When to Use Individual Packages
152
95
 
153
- `ktnull` is an internal falsy value. It is assigned by `Object.freeze(Object.create(null))`.
154
- It is used for filtering, you can do like this:
96
+ If you only need specific functionality, you can install individual packages:
155
97
 
156
- > Since `ktnull` is an empty object, it can be used on the 2nd argument position of `h` or the 1st position of `div`, representing attributes.
98
+ - Need only DOM utilities? `pnpm add @ktjs/core`
99
+ - Need only routing? → `pnpm add @ktjs/router`
100
+ - Need only shortcuts? → `pnpm add @ktjs/shortcuts @ktjs/core`
101
+ - Need everything except router? → `pnpm add kt.js` (this package)
102
+ - Need everything including router? → `pnpm add kt.js @ktjs/router`
157
103
 
158
- ```ts
159
- import { div, ktnull } from 'kt.js';
160
- const list = div(ktnull, [
161
- div(ktnull, 'Item 1'),
162
- someCondition ? div(ktnull, 'item 1.5') : ktnull,
163
- div(ktnull, 'Item 2'),
164
- undefined,
165
- ]);
166
- ```
167
-
168
- Then it will create:
104
+ This can result in slightly smaller dependency trees in your `node_modules`.
169
105
 
170
- ```html
171
- <div>
172
- <div>Item 1</div>
173
- <div>Item 2</div>
174
- undefined
175
- </div>
176
- ```
106
+ ## Documentation
177
107
 
178
- ## Browser Compatibility
108
+ For complete documentation, examples, and guides, see:
179
109
 
180
- KT.js is transpiled to ES5 and works in all modern browsers as well as legacy browsers including IE9+.
110
+ - [Main Documentation](../../README.md) - Complete framework guide
111
+ - [Core Package](../core/README.md) - Core DOM utilities
112
+ - [Router Package](../router/README.md) - Routing documentation
113
+ - [Shortcuts Package](../shortcuts/README.md) - Shortcuts and utilities
114
+ - [Changelog](../../CHANGELOG.md) - Version history and updates
181
115
 
182
- ### Promise Polyfill
116
+ ## Features
183
117
 
184
- For environments without native `Promise` support (like IE11 and below), KT.js provides a minimal Promise polyfill:
118
+ - Direct DOM manipulation with zero virtual DOM overhead
119
+ - ✅ Full TypeScript support with intelligent type inference
120
+ - ✅ ES5 compatible (works in IE9+)
121
+ - ✅ Zero dependencies (self-contained)
122
+ - ✅ Tiny bundle size with excellent tree-shaking
123
+ - ✅ Conditional rendering with `ktnull`
124
+ - ✅ Event handler shortcuts with `@<eventName>` syntax
125
+ - ✅ Element factories with `withDefaults`
126
+ - ✅ Router available as separate package (`@ktjs/router`)
185
127
 
186
- ```html
187
- <script src="https://unpkg.com/kt.js@0.3.0/dist/index.iife.js"></script>
188
- ```
189
-
190
- Or when using module bundlers:
191
-
192
- ```js
193
- import 'some promise polyfill'; // Will fallback to sync version if Promise is not available
194
- import { h, div, createRouter } from 'kt.js';
195
- ```
196
-
197
- **Note:** The Router will work without Promise support, but navigation guards (`beforeEach`) will run synchronously and cannot use async/await patterns.
198
-
199
- ## Notes
128
+ ## Browser Compatibility
200
129
 
201
- - `call`, `apply` on `Function.prototype` is trusted.
130
+ KT.js works in all modern browsers and legacy browsers including IE9+. For older browsers without Promise support, navigation guards will run synchronously.
202
131
 
203
132
  ## License
204
133
 
package/dist/index.d.ts CHANGED
@@ -1,111 +1,2 @@
1
- /**
2
- * This is a `falsy` value used to indicate "no node" in `h` function.
3
- * - We use `Object.create(null)` because it is guaranteed to be unique and no need for polyfill of `symbol`.
4
- */
5
- declare const ktnull: any;
6
-
7
- type otherstring = string & {};
8
-
9
- /**
10
- * Normal HTML tags like `div`, `span`, `a`, etc.
11
- */
12
- type HTMLTag = keyof HTMLElementTagNameMap;
13
-
14
- type RawContent = (HTMLElement | string | undefined)[] | HTMLElement | string;
15
- type RawAttr = KAttribute | string;
16
-
17
- /**
18
- * Used to create enhanced HTML elements
19
- */
20
- interface KAttribute {
21
- [k: string]: any;
22
-
23
- id?: string;
24
-
25
- type?: string;
26
- for?: string;
27
- name?: string;
28
- value?: string;
29
- valueAsDate?: Date;
30
- valueAsNumber?: number;
31
- label?: string;
32
- disabled?: string;
33
- min?: string;
34
- max?: string;
35
- selected?: boolean;
36
- checked?: boolean;
37
- class?: string;
38
- style?: string | Partial<CSSStyleDeclaration>;
39
- action?: string;
40
- method?: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE' | otherstring;
41
- }
42
-
43
- declare const div: (attr?: RawAttr, content?: RawContent) => HTMLDivElement;
44
- declare const span: (attr?: RawAttr, content?: RawContent) => HTMLSpanElement;
45
- declare const label: (attr?: RawAttr, content?: RawContent) => HTMLLabelElement;
46
- declare const p: (attr?: RawAttr, content?: RawContent) => HTMLParagraphElement;
47
- declare const h1: (attr?: RawAttr, content?: RawContent) => HTMLHeadingElement;
48
- declare const h2: (attr?: RawAttr, content?: RawContent) => HTMLHeadingElement;
49
- declare const h3: (attr?: RawAttr, content?: RawContent) => HTMLHeadingElement;
50
- declare const h4: (attr?: RawAttr, content?: RawContent) => HTMLHeadingElement;
51
- declare const h5: (attr?: RawAttr, content?: RawContent) => HTMLHeadingElement;
52
- declare const h6: (attr?: RawAttr, content?: RawContent) => HTMLHeadingElement;
53
- declare const ul: (attr?: RawAttr, content?: RawContent) => HTMLUListElement;
54
- declare const ol: (attr?: RawAttr, content?: RawContent) => HTMLOListElement;
55
- declare const li: (attr?: RawAttr, content?: RawContent) => HTMLLIElement;
56
- declare const btn: (attr?: RawAttr, content?: RawContent) => HTMLButtonElement;
57
- declare const form: (attr?: RawAttr, content?: RawContent) => HTMLFormElement;
58
- declare const input: (attr?: RawAttr, content?: RawContent) => HTMLInputElement;
59
- declare const select: (attr?: RawAttr, content?: RawContent) => HTMLSelectElement;
60
- declare const option: (attr?: RawAttr, content?: RawContent) => HTMLOptionElement;
61
- declare const table: (attr?: RawAttr, content?: RawContent) => HTMLTableElement;
62
- declare const thead: (attr?: RawAttr, content?: RawContent) => HTMLTableSectionElement;
63
- declare const tbody: (attr?: RawAttr, content?: RawContent) => HTMLTableSectionElement;
64
- declare const tr: (attr?: RawAttr, content?: RawContent) => HTMLTableRowElement;
65
- declare const th: (attr?: RawAttr, content?: RawContent) => HTMLTableCellElement;
66
- declare const td: (attr?: RawAttr, content?: RawContent) => HTMLTableCellElement;
67
- declare const a: (attr?: RawAttr, content?: RawContent) => HTMLAnchorElement;
68
- declare const img: (attr?: RawAttr, content?: RawContent) => HTMLImageElement;
69
-
70
- /**
71
- * Create an enhanced HTMLElement.
72
- * - Only supports HTMLElements, **NOT** SVGElements or other Elements.
73
- * @param tag tag of an `HTMLElement`
74
- * @param attr attribute object or className
75
- * @param content a string or an array of HTMLEnhancedElement as child nodes
76
- */
77
- declare function h<T extends HTMLTag>(tag: T, attr?: RawAttr, content?: RawContent): HTMLElementTagNameMap[T];
78
-
79
- // Minimal router types
80
-
81
- interface RouteContext {
82
- params: Record<string, string>;
83
- query: Record<string, string>;
84
- path: string;
85
- meta?: Record<string, any>;
86
- }
87
-
88
- type RouteHandler = (ctx: RouteContext) => HTMLElement | void | Promise<HTMLElement | void>;
89
-
90
- interface RouteConfig {
91
- path: string;
92
- handler: RouteHandler;
93
- meta?: Record<string, any>;
94
- }
95
-
96
- interface RouterConfig {
97
- routes: RouteConfig[];
98
- container?: HTMLElement;
99
- beforeEach?: (to: RouteContext, from: RouteContext | null) => boolean | Promise<boolean>;
100
- afterEach?: (to: RouteContext) => void;
101
- onError?: (error: Error) => void;
102
- }
103
-
104
- declare function createRouter(config: RouterConfig): {
105
- start: () => void;
106
- stop: () => void;
107
- push: (path: string) => void;
108
- current: () => RouteContext | null;
109
- };
110
-
111
- export { a, btn, createRouter, div, form, h, h1, h2, h3, h4, h5, h6, img, input, ktnull, label, li, ol, option, p, select, span, table, tbody, td, th, thead, tr, ul };
1
+ export * from '@ktjs/core';
2
+ export * from '@ktjs/shortcuts';
@@ -1 +1 @@
1
- var kt=function(n){"use strict";var t=Object.freeze(Object.create(null)),e=Array.isArray,r=Array.prototype.filter,o=Object.prototype.hasOwnProperty,u=Object.keys,i=function(){return{}},f="undefined"==typeof Promise?i:Promise.resolve,a="undefined"==typeof Promise?i:Promise.reject,c=document.createElement,d=document.createTextNode,l=document.createDocumentFragment,s=function(n){return void 0===n&&(n=""),d.call(document,n)},v=HTMLElement.prototype.addEventListener,p=HTMLElement.prototype.setAttribute,m=HTMLElement.prototype.appendChild,h=HTMLElement.prototype.append,y="function"==typeof h?function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return h.apply(this,r.call(n,function(n){return n!==t}))}:function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];if(n.length<50)for(var r=0;r<n.length;r++){"string"==typeof(u=n[r])?m.call(this,s(u)):u!==t&&m.call(this,u)}else{var o=l.call(document);for(r=0;r<n.length;r++){var u;"string"==typeof(u=n[r])?m.call(o,s(u)):u!==t&&m.call(o,u)}m.call(this,o)}},b=function(n){throw new Error("Kt.js:".concat(n))};function w(n,t,e){t in n?n[t]=!!e:p.call(n,t,e)}function g(n,t,e){t in n?n[t]=e:p.call(n,t,e)}var E={checked:w,selected:w,value:g,valueAsDate:g,valueAsNumber:g,defaultValue:g,defaultChecked:w,defaultSelected:w,disabled:w,readOnly:w,multiple:w,required:w,autofocus:w,open:w,controls:w,autoplay:w,loop:w,muted:w,defer:w,async:w,hidden:function(n,t,e){n.hidden=!!e}},j=function(n,t,e){return p.call(n,t,e)};function A(n,t){"string"==typeof t?n.className=t:"object"==typeof t&&null!==t?function(n,t){var e=t.class,r=t.style;if(void 0!==e&&(n.className=e,delete t.class),r){if("string"==typeof r)p.call(n,"style",r);else if("object"==typeof r)for(var i in r)o.call(n.style,i)&&(n.style[i]=r[i]);delete t.style}for(var f=u(t),a=f.length-1;a>=0;a--){var c=t[i=f[a]];"function"!=typeof c?(E[i]||j)(n,i,c):v.call(n,i,c)}void 0!==e&&(t.style=e),void 0!==r&&(t.style=r)}(n,t):b("applyAttr attr must be an object.")}function O(n,t,r){void 0===t&&(t=""),void 0===r&&(r=""),"string"!=typeof n&&b("h tagName must be a string.");var o,u=(o=n,c.call(document,o));return A(u,t),function(n,t){e(t)?y.apply(n,t):y.call(n,t)}(u,r),u}var P=function(n){return function(t,e){return O(n,t,e)}},R=P("div"),k=P("span"),H=P("label"),L=P("p"),M=P("h1"),T=P("h2"),q=P("h3"),C=P("h4"),N=P("h5"),I=P("h6"),U=P("ul"),x=P("ol"),D=P("li"),K=P("button"),S=P("form"),V=P("input"),$=P("select"),z=P("option"),B=P("table"),F=P("thead"),G=P("tbody"),J=P("tr"),Q=P("th"),W=P("td"),X=P("a"),Y=P("img"),Z=function(){return!0};return n.a=X,n.btn=K,n.createRouter=function(n){var t=n.routes,e=n.container,r=n.beforeEach,o=void 0===r?Z:r,u=n.afterEach,i=void 0===u?Z:u,c=n.onError,d=void 0===c?console.error:c,l=null,s=t.map(function(n){var t=[],e=n.path.replace(/\/:([^/]+)/g,function(n,e){return t.push(e),"/([^/]+)"});return{route:n,pattern:new RegExp("^".concat(e,"$")),names:t}}),v=function(n){for(var t=0;t<s.length;t++){var e=s[t],r=e.route,o=e.pattern,u=e.names,i=n.match(o);if(i){for(var f={},a=0;a<u.length;a++)f[u[a]]=i[a+1];return{route:r,params:f}}}return null},p=function(n){var t={};if(!n)return t;for(var e=(0===n.indexOf("?")?n.slice(1):n).split("&"),r=0;r<e.length;r++){var o=e[r].split("="),u=o[0];u&&(t[decodeURIComponent(u)]=decodeURIComponent(o[1]||""))}return t},m="undefined"!=typeof Promise?function(n){var t=n.split("?"),r=t[0],u=t[1],c=p(u||""),s=v(r);if(!s){var m=new Error("Route not found: ".concat(r));return d(m),a(m)}var h={params:s.params,query:c,path:r,meta:s.route.meta};return f(o(h,l)).then(function(n){return n?(window.location.hash=u?"".concat(r,"?").concat(u):r,s.route.handler(h)):a(new Error("Navigation blocked by guard"))}).then(function(n){e&&n&&(e.innerHTML="",e.appendChild(n)),i(l=h)}).catch(function(n){return d(n),a(n)})}:function(n){var t=n.split("?"),r=t[0],u=t[1],f=p(u||""),a=v(r);if(a){var c={params:a.params,query:f,path:r,meta:a.route.meta};try{if(!o(c,l))return;window.location.hash=u?"".concat(r,"?").concat(u):r;var s=a.route.handler(c);e&&s&&"function"!=typeof s.then&&(e.innerHTML="",e.appendChild(s)),i(l=c)}catch(n){d(n)}}else d(new Error("Route not found: ".concat(r)))},h=function(){return m(window.location.hash.slice(1)||"/")};return{start:function(){window.addEventListener("hashchange",h),h()},stop:function(){return window.removeEventListener("hashchange",h)},push:function(n){return m(n)},current:function(){return l}}},n.div=R,n.form=S,n.h=O,n.h1=M,n.h2=T,n.h3=q,n.h4=C,n.h5=N,n.h6=I,n.img=Y,n.input=V,n.ktnull=t,n.label=H,n.li=D,n.ol=x,n.option=z,n.p=L,n.select=$,n.span=k,n.table=B,n.tbody=G,n.td=W,n.th=Q,n.thead=F,n.tr=J,n.ul=U,n}({});
1
+ var kt=function(t,e,n){"use strict";return Object.keys(e).forEach(function(n){"default"===n||Object.prototype.hasOwnProperty.call(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})}),Object.keys(n).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:function(){return n[e]}})}),t}({},__ktjs_core__,__ktjs_shortcuts__);
@@ -0,0 +1 @@
1
+ var kt=function(t,e,n){"use strict";return Object.keys(e).forEach(function(n){"default"===n||Object.prototype.hasOwnProperty.call(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})}),Object.keys(n).forEach(function(e){"default"===e||Object.prototype.hasOwnProperty.call(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:function(){return n[e]}})}),t}({},__ktjs_core__,__ktjs_shortcuts__);
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var n=Object.freeze(Object.create(null)),t=Array.isArray,e=Array.prototype.filter,r=Object.prototype.hasOwnProperty,o=Object.keys,u=function(){return{}},i="undefined"==typeof Promise?u:Promise.resolve,f="undefined"==typeof Promise?u:Promise.reject,a=document.createElement,c=document.createTextNode,d=document.createDocumentFragment,l=function(n){return void 0===n&&(n=""),c.call(document,n)},s=HTMLElement.prototype.addEventListener,v=HTMLElement.prototype.setAttribute,p=HTMLElement.prototype.appendChild,m=HTMLElement.prototype.append,h="function"==typeof m?function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return m.apply(this,e.call(t,function(t){return t!==n}))}:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(t.length<50)for(var r=0;r<t.length;r++){"string"==typeof(u=t[r])?p.call(this,l(u)):u!==n&&p.call(this,u)}else{var o=d.call(document);for(r=0;r<t.length;r++){var u;"string"==typeof(u=t[r])?p.call(o,l(u)):u!==n&&p.call(o,u)}p.call(this,o)}},y=function(n){throw new Error("Kt.js:".concat(n))};function b(n,t,e){t in n?n[t]=!!e:v.call(n,t,e)}function w(n,t,e){t in n?n[t]=e:v.call(n,t,e)}var g={checked:b,selected:b,value:w,valueAsDate:w,valueAsNumber:w,defaultValue:w,defaultChecked:b,defaultSelected:b,disabled:b,readOnly:b,multiple:b,required:b,autofocus:b,open:b,controls:b,autoplay:b,loop:b,muted:b,defer:b,async:b,hidden:function(n,t,e){n.hidden=!!e}},E=function(n,t,e){return v.call(n,t,e)};function j(n,t){"string"==typeof t?n.className=t:"object"==typeof t&&null!==t?function(n,t){var e=t.class,u=t.style;if(void 0!==e&&(n.className=e,delete t.class),u){if("string"==typeof u)v.call(n,"style",u);else if("object"==typeof u)for(var i in u)r.call(n.style,i)&&(n.style[i]=u[i]);delete t.style}for(var f=o(t),a=f.length-1;a>=0;a--){var c=t[i=f[a]];"function"!=typeof c?(g[i]||E)(n,i,c):s.call(n,i,c)}void 0!==e&&(t.style=e),void 0!==u&&(t.style=u)}(n,t):y("applyAttr attr must be an object.")}function A(n,e,r){void 0===e&&(e=""),void 0===r&&(r=""),"string"!=typeof n&&y("h tagName must be a string.");var o,u=(o=n,a.call(document,o));return j(u,e),function(n,e){t(e)?h.apply(n,e):h.call(n,e)}(u,r),u}var O=function(n){return function(t,e){return A(n,t,e)}},P=O("div"),R=O("span"),H=O("label"),L=O("p"),M=O("h1"),T=O("h2"),k=O("h3"),q=O("h4"),C=O("h5"),N=O("h6"),x=O("ul"),I=O("ol"),U=O("li"),D=O("button"),K=O("form"),S=O("input"),V=O("select"),$=O("option"),z=O("table"),B=O("thead"),F=O("tbody"),G=O("tr"),J=O("th"),Q=O("td"),W=O("a"),X=O("img"),Y=function(){return!0};function Z(n){var t=n.routes,e=n.container,r=n.beforeEach,o=void 0===r?Y:r,u=n.afterEach,a=void 0===u?Y:u,c=n.onError,d=void 0===c?console.error:c,l=null,s=t.map(function(n){var t=[],e=n.path.replace(/\/:([^/]+)/g,function(n,e){return t.push(e),"/([^/]+)"});return{route:n,pattern:new RegExp("^".concat(e,"$")),names:t}}),v=function(n){for(var t=0;t<s.length;t++){var e=s[t],r=e.route,o=e.pattern,u=e.names,i=n.match(o);if(i){for(var f={},a=0;a<u.length;a++)f[u[a]]=i[a+1];return{route:r,params:f}}}return null},p=function(n){var t={};if(!n)return t;for(var e=(0===n.indexOf("?")?n.slice(1):n).split("&"),r=0;r<e.length;r++){var o=e[r].split("="),u=o[0];u&&(t[decodeURIComponent(u)]=decodeURIComponent(o[1]||""))}return t},m="undefined"!=typeof Promise?function(n){var t=n.split("?"),r=t[0],u=t[1],c=p(u||""),s=v(r);if(!s){var m=new Error("Route not found: ".concat(r));return d(m),f(m)}var h={params:s.params,query:c,path:r,meta:s.route.meta};return i(o(h,l)).then(function(n){return n?(window.location.hash=u?"".concat(r,"?").concat(u):r,s.route.handler(h)):f(new Error("Navigation blocked by guard"))}).then(function(n){e&&n&&(e.innerHTML="",e.appendChild(n)),a(l=h)}).catch(function(n){return d(n),f(n)})}:function(n){var t=n.split("?"),r=t[0],u=t[1],i=p(u||""),f=v(r);if(f){var c={params:f.params,query:i,path:r,meta:f.route.meta};try{if(!o(c,l))return;window.location.hash=u?"".concat(r,"?").concat(u):r;var s=f.route.handler(c);e&&s&&"function"!=typeof s.then&&(e.innerHTML="",e.appendChild(s)),a(l=c)}catch(n){d(n)}}else d(new Error("Route not found: ".concat(r)))},h=function(){return m(window.location.hash.slice(1)||"/")};return{start:function(){window.addEventListener("hashchange",h),h()},stop:function(){return window.removeEventListener("hashchange",h)},push:function(n){return m(n)},current:function(){return l}}}export{W as a,D as btn,Z as createRouter,P as div,K as form,A as h,M as h1,T as h2,k as h3,q as h4,C as h5,N as h6,X as img,S as input,n as ktnull,H as label,U as li,I as ol,$ as option,L as p,V as select,R as span,z as table,F as tbody,Q as td,J as th,B as thead,G as tr,x as ul};
1
+ export*from"@ktjs/core";export*from"@ktjs/shortcuts";
package/package.json CHANGED
@@ -1,66 +1,41 @@
1
1
  {
2
- "name": "kt.js",
3
- "version": "0.4.2",
4
- "author": {
5
- "name": "Kasukabe Tsumugi",
6
- "email": "futami16237@gmail.com"
7
- },
8
- "purpose": "npm",
9
- "description": "A simple and easy-to-use web framework, never re-render. Abbreviation of Kasukabe Tsumugi.",
10
- "description_zh": "KT.js,简单易用,never重绘。取自Kasukabe Tsumugi的首字母。",
11
- "type": "module",
12
- "main": "./dist/index.cjs",
13
- "module": "./dist/index.mjs",
14
- "types": "./dist/index.d.ts",
15
- "exports": {
16
- "types": "./dist/index.d.ts",
17
- "import": "./dist/index.mjs",
18
- "require": "./dist/index.cjs",
19
- "default": "./dist/index.mjs"
20
- },
21
- "files": [
22
- "dist"
23
- ],
24
- "homepage": "https://github.com/baendlorel/kt.js#readme",
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/baendlorel/kt.js"
28
- },
29
- "keywords": [
30
- "framework",
31
- "web",
32
- "typescript",
33
- "javascript"
34
- ],
35
- "scripts": {
36
- "gsize": "cat dist/index.mjs | wc -c && gzip -c dist/index.mjs | wc -c",
37
- "lines": "clear && find ./src -type f \\( -name \"*.ts\" -o -name \"*.tsx\" -o -name \"*.js\" -o -name \"*.mjs\" -o -name \"*.cjs\" -o -name \"*.cpp\" -o -name \"*.h\" -o -name \"*.py\" -o -name \"*.css\" -o -name \"*.rs\" -o -name \"*.rc\" \\) | xargs wc -l",
38
- "test": "clear & vitest",
39
- "lint": "oxlint .",
40
- "cover": "clear & vitest --coverage",
41
- "build": "tsx ./.scripts/rollup.ts"
42
- },
43
- "license": "MIT",
44
- "devDependencies": {
45
- "@rollup/plugin-alias": "^5.1.1",
46
- "@rollup/plugin-commonjs": "^28.0.6",
47
- "@rollup/plugin-node-resolve": "^16.0.1",
48
- "@rollup/plugin-replace": "^6.0.2",
49
- "@rollup/plugin-terser": "^0.4.4",
50
- "@rollup/plugin-typescript": "^12.1.4",
51
- "@types/node": "^24.5.1",
52
- "@vitest/coverage-v8": "^3.2.4",
53
- "jsdom": "^27.0.0",
54
- "oxlint": "^1.16.0",
55
- "prettier": "^3.6.2",
56
- "rimraf": "^6.0.1",
57
- "rollup": "^4.50.2",
58
- "rollup-plugin-conditional-compilation": "^1.0.6",
59
- "rollup-plugin-const-enum": "^1.1.4",
60
- "rollup-plugin-dts": "^6.2.3",
61
- "rollup-plugin-func-macro": "^1.1.1",
62
- "tslib": "^2.8.1",
63
- "typescript": "^5.9.2",
64
- "vitest": "^3.2.4"
65
- }
2
+ "name": "kt.js",
3
+ "version": "0.5.0",
4
+ "author": {
5
+ "name": "Kasukabe Tsumugi",
6
+ "email": "futami16237@gmail.com"
7
+ },
8
+ "description": "A simple and easy-to-use web framework, never re-render. Abbreviation of Kasukabe Tsumugi.",
9
+ "type": "module",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "default": "./dist/index.mjs"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "homepage": "https://github.com/baendlorel/kt.js#readme",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/baendlorel/kt.js",
24
+ "directory": "packages/kt.js"
25
+ },
26
+ "keywords": [
27
+ "framework",
28
+ "web",
29
+ "typescript",
30
+ "javascript"
31
+ ],
32
+ "license": "MIT",
33
+ "dependencies": {
34
+ "@ktjs/core": "0.5.0",
35
+ "@ktjs/shortcuts": "0.5.0"
36
+ },
37
+ "scripts": {
38
+ "build": "rollup -c rollup.config.mjs",
39
+ "dev": "rollup -c rollup.config.mjs -w"
40
+ }
66
41
  }