kt.js 0.3.2 → 0.4.1

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
@@ -19,12 +19,13 @@ KT.js follows one rule: full controll of dom and avoid unless repainting.
19
19
 
20
20
  ## Current Core Features
21
21
 
22
- - `h` function and its aliases
23
- - Router
24
- - Automatically adapts 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
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
26
  - Transpiled to ES5 with no modern syntax
27
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.
28
29
 
29
30
  ## Getting started
30
31
 
@@ -147,6 +148,33 @@ console.log(current?.path, current?.params, current?.query);
147
148
  - Error handling (`onError`)
148
149
  - Minimal footprint
149
150
 
151
+ ## `ktnull`
152
+
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:
155
+
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.
157
+
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:
169
+
170
+ ```html
171
+ <div>
172
+ <div>Item 1</div>
173
+ <div>Item 2</div>
174
+ undefined
175
+ </div>
176
+ ```
177
+
150
178
  ## Browser Compatibility
151
179
 
152
180
  KT.js is transpiled to ES5 and works in all modern browsers as well as legacy browsers including IE9+.
@@ -156,15 +184,13 @@ KT.js is transpiled to ES5 and works in all modern browsers as well as legacy br
156
184
  For environments without native `Promise` support (like IE11 and below), KT.js provides a minimal Promise polyfill:
157
185
 
158
186
  ```html
159
- <!-- Load the Promise polyfill before KT.js -->
160
- <script src="https://unpkg.com/kt.js@0.3.0/dist/promise-polyfill.js"></script>
161
187
  <script src="https://unpkg.com/kt.js@0.3.0/dist/index.iife.js"></script>
162
188
  ```
163
189
 
164
190
  Or when using module bundlers:
165
191
 
166
192
  ```js
167
- import 'kt.js/dist/promise-polyfill';
193
+ import 'some promise polyfill'; // Will fallback to sync version if Promise is not available
168
194
  import { h, div, createRouter } from 'kt.js';
169
195
  ```
170
196
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
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
+
1
7
  type otherstring = string & {};
2
8
 
3
9
  /**
@@ -102,4 +108,4 @@ declare function createRouter(config: RouterConfig): {
102
108
  current: () => RouteContext | null;
103
109
  };
104
110
 
105
- export { a, btn, createRouter, div, form, h, h1, h2, h3, h4, h5, h6, img, input, label, li, ol, option, p, select, span, table, tbody, td, th, thead, tr, ul };
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 +1 @@
1
- var kt=function(n){"use strict";var t=document.createElement,e=document.createTextNode,r=document.createDocumentFragment,o=function(n){return void 0===n&&(n=""),e.call(document,n)},u=HTMLElement.prototype.addEventListener,i=HTMLElement.prototype.setAttribute,a=HTMLElement.prototype.appendChild,f="function"==typeof HTMLElement.prototype.append?HTMLElement.prototype.append:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(n.length<50)for(var e=0;e<n.length;e++){"string"==typeof(i=n[e])?a.call(this,o(i)):a.call(this,i)}else{var u=r.call(document);for(e=0;e<n.length;e++){var i;"string"==typeof(i=n[e])?a.call(u,o(i)):a.call(u,i)}a.call(this,u)}},c=Array.isArray,d=Object.keys,l=function(){return{}},s="undefined"==typeof Promise?l:Promise.resolve,v="undefined"==typeof Promise?l:Promise.reject,p=function(n){throw new Error("Kt.js:".concat(n))};function m(n,t,e){t in n?n[t]=!!e:i.call(n,t,e)}function h(n,t,e){t in n?n[t]=e:i.call(n,t,e)}var y={checked:m,selected:m,value:h,valueAsDate:h,valueAsNumber:h,defaultValue:h,defaultChecked:m,defaultSelected:m,disabled:m,readOnly:m,multiple:m,required:m,autofocus:m,open:m,controls:m,autoplay:m,loop:m,muted:m,defer:m,async:m,hidden:function(n,t,e){n.hidden=!!e}},w=function(n,t,e){return i.call(n,t,e)};function g(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),void 0!==r){if("string"==typeof r)i.call(n,"style",r);else for(var o in n.style)n.style[o]=r[o];delete t.style}for(var a=d(t),f=a.length-1;f>=0;f--){var c=t[o=a[f]];"function"!=typeof c?(y[o]||w)(n,o,c):u.call(n,o,c)}void 0!==e&&(t.style=e),void 0!==r&&(t.style=r)}(n,t):p("applyAttr attr must be an object.")}function b(n,e,r){void 0===e&&(e=""),void 0===r&&(r=""),"string"!=typeof n&&p("h tagName must be a string.");var o,u=(o=n,t.call(document,o));return g(u,e),function(n,t){c(t)?f.apply(n,t):f.call(n,t)}(u,r),u}var E=function(n){return function(t,e){return b(n,t,e)}},H=E("div"),L=E("span"),M=E("label"),P=E("p"),R=E("h1"),T=E("h2"),j=E("h3"),k=E("h4"),A=E("h5"),q=E("h6"),C=E("ul"),N=E("ol"),I=E("li"),O=E("button"),U=E("form"),x=E("input"),D=E("select"),K=E("option"),S=E("table"),V=E("thead"),$=E("tbody"),z=E("tr"),B=E("th"),F=E("td"),G=E("a"),J=E("img"),Q=function(){return!0};return n.a=G,n.btn=O,n.createRouter=function(n){var t=n.routes,e=n.container,r=n.beforeEach,o=void 0===r?Q:r,u=n.afterEach,i=void 0===u?Q:u,a=n.onError,f=void 0===a?console.error:a,c=null,d=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}}),l=function(n){for(var t=0;t<d.length;t++){var e=d[t],r=e.route,o=e.pattern,u=e.names,i=n.match(o);if(i){for(var a={},f=0;f<u.length;f++)a[u[f]]=i[f+1];return{route:r,params:a}}}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],a=p(u||""),d=l(r);if(!d){var m=new Error("Route not found: ".concat(r));return f(m),v(m)}var h={params:d.params,query:a,path:r,meta:d.route.meta};return s(o(h,c)).then(function(n){return n?(window.location.hash=u?"".concat(r,"?").concat(u):r,d.route.handler(h)):v(new Error("Navigation blocked by guard"))}).then(function(n){e&&n&&(e.innerHTML="",e.appendChild(n)),i(c=h)}).catch(function(n){return f(n),v(n)})}:function(n){var t=n.split("?"),r=t[0],u=t[1],a=p(u||""),d=l(r);if(d){var s={params:d.params,query:a,path:r,meta:d.route.meta};try{if(!o(s,c))return;window.location.hash=u?"".concat(r,"?").concat(u):r;var v=d.route.handler(s);e&&v&&"function"!=typeof v.then&&(e.innerHTML="",e.appendChild(v)),i(c=s)}catch(n){f(n)}}else f(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 c}}},n.div=H,n.form=U,n.h=b,n.h1=R,n.h2=T,n.h3=j,n.h4=k,n.h5=A,n.h6=q,n.img=J,n.input=x,n.label=M,n.li=I,n.ol=N,n.option=K,n.p=P,n.select=D,n.span=L,n.table=S,n.tbody=$,n.td=F,n.th=B,n.thead=V,n.tr=z,n.ul=C,n}({});
1
+ var kt=function(n){"use strict";var t=Object.freeze(Object.create(null)),e=Array.isArray,r=Array.prototype.filter,o=Object.keys,u=function(){return{}},i="undefined"==typeof Promise?u:Promise.resolve,a="undefined"==typeof Promise?u:Promise.reject,f=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 n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return m.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])?p.call(this,l(u)):u!==t&&p.call(this,u)}else{var o=d.call(document);for(r=0;r<n.length;r++){var u;"string"==typeof(u=n[r])?p.call(o,l(u)):u!==t&&p.call(o,u)}p.call(this,o)}},y=function(n){throw new Error("Kt.js:".concat(n))};function w(n,t,e){t in n?n[t]=!!e:v.call(n,t,e)}function b(n,t,e){t in n?n[t]=e:v.call(n,t,e)}var g={checked:w,selected:w,value:b,valueAsDate:b,valueAsNumber:b,defaultValue:b,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}},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,r=t.style;if(void 0!==e&&(n.className=e,delete t.class),void 0!==r){if("string"==typeof r)v.call(n,"style",r);else for(var u in n.style)n.style[u]=r[u];delete t.style}for(var i=o(t),a=i.length-1;a>=0;a--){var f=t[u=i[a]];"function"!=typeof f?(g[u]||E)(n,u,f):s.call(n,u,f)}void 0!==e&&(t.style=e),void 0!==r&&(t.style=r)}(n,t):y("applyAttr attr must be an object.")}function A(n,t,r){void 0===t&&(t=""),void 0===r&&(r=""),"string"!=typeof n&&y("h tagName must be a string.");var o,u=(o=n,f.call(document,o));return j(u,t),function(n,t){e(t)?h.apply(n,t):h.call(n,t)}(u,r),u}var P=function(n){return function(t,e){return A(n,t,e)}},R=P("div"),k=P("span"),H=P("label"),L=P("p"),M=P("h1"),O=P("h2"),T=P("h3"),q=P("h4"),C=P("h5"),N=P("h6"),I=P("ul"),U=P("ol"),x=P("li"),D=P("button"),K=P("form"),S=P("input"),V=P("select"),$=P("option"),z=P("table"),B=P("thead"),F=P("tbody"),G=P("tr"),J=P("th"),Q=P("td"),W=P("a"),X=P("img"),Y=function(){return!0};return n.a=W,n.btn=D,n.createRouter=function(n){var t=n.routes,e=n.container,r=n.beforeEach,o=void 0===r?Y:r,u=n.afterEach,f=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 a={},f=0;f<u.length;f++)a[u[f]]=i[f+1];return{route:r,params:a}}}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 i(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)),f(l=h)}).catch(function(n){return d(n),a(n)})}:function(n){var t=n.split("?"),r=t[0],u=t[1],i=p(u||""),a=v(r);if(a){var c={params:a.params,query:i,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)),f(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=K,n.h=A,n.h1=M,n.h2=O,n.h3=T,n.h4=q,n.h5=C,n.h6=N,n.img=X,n.input=S,n.ktnull=t,n.label=H,n.li=x,n.ol=U,n.option=$,n.p=L,n.select=V,n.span=k,n.table=z,n.tbody=F,n.td=Q,n.th=J,n.thead=B,n.tr=G,n.ul=I,n}({});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var n=document.createElement,t=document.createTextNode,e=document.createDocumentFragment,r=function(n){return void 0===n&&(n=""),t.call(document,n)},o=HTMLElement.prototype.addEventListener,u=HTMLElement.prototype.setAttribute,i=HTMLElement.prototype.appendChild,a="function"==typeof HTMLElement.prototype.append?HTMLElement.prototype.append:function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];if(n.length<50)for(var o=0;o<n.length;o++){"string"==typeof(a=n[o])?i.call(this,r(a)):i.call(this,a)}else{var u=e.call(document);for(o=0;o<n.length;o++){var a;"string"==typeof(a=n[o])?i.call(u,r(a)):i.call(u,a)}i.call(this,u)}},f=Array.isArray,c=Object.keys,d=function(){return{}},l="undefined"==typeof Promise?d:Promise.resolve,v="undefined"==typeof Promise?d:Promise.reject,s=function(n){throw new Error("Kt.js:".concat(n))};function p(n,t,e){t in n?n[t]=!!e:u.call(n,t,e)}function m(n,t,e){t in n?n[t]=e:u.call(n,t,e)}var h={checked:p,selected:p,value:m,valueAsDate:m,valueAsNumber:m,defaultValue:m,defaultChecked:p,defaultSelected:p,disabled:p,readOnly:p,multiple:p,required:p,autofocus:p,open:p,controls:p,autoplay:p,loop:p,muted:p,defer:p,async:p,hidden:function(n,t,e){n.hidden=!!e}},y=function(n,t,e){return u.call(n,t,e)};function w(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),void 0!==r){if("string"==typeof r)u.call(n,"style",r);else for(var i in n.style)n.style[i]=r[i];delete t.style}for(var a=c(t),f=a.length-1;f>=0;f--){var d=t[i=a[f]];"function"!=typeof d?(h[i]||y)(n,i,d):o.call(n,i,d)}void 0!==e&&(t.style=e),void 0!==r&&(t.style=r)}(n,t):s("applyAttr attr must be an object.")}function g(t,e,r){void 0===e&&(e=""),void 0===r&&(r=""),"string"!=typeof t&&s("h tagName must be a string.");var o,u=(o=t,n.call(document,o));return w(u,e),function(n,t){f(t)?a.apply(n,t):a.call(n,t)}(u,r),u}var b=function(n){return function(t,e){return g(n,t,e)}},E=b("div"),H=b("span"),L=b("label"),M=b("p"),P=b("h1"),R=b("h2"),T=b("h3"),j=b("h4"),A=b("h5"),k=b("h6"),q=b("ul"),C=b("ol"),N=b("li"),x=b("button"),I=b("form"),O=b("input"),U=b("select"),D=b("option"),K=b("table"),S=b("thead"),V=b("tbody"),$=b("tr"),z=b("th"),B=b("td"),F=b("a"),G=b("img"),J=function(){return!0};function Q(n){var t=n.routes,e=n.container,r=n.beforeEach,o=void 0===r?J:r,u=n.afterEach,i=void 0===u?J:u,a=n.onError,f=void 0===a?console.error:a,c=null,d=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}}),s=function(n){for(var t=0;t<d.length;t++){var e=d[t],r=e.route,o=e.pattern,u=e.names,i=n.match(o);if(i){for(var a={},f=0;f<u.length;f++)a[u[f]]=i[f+1];return{route:r,params:a}}}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],a=p(u||""),d=s(r);if(!d){var m=new Error("Route not found: ".concat(r));return f(m),v(m)}var h={params:d.params,query:a,path:r,meta:d.route.meta};return l(o(h,c)).then(function(n){return n?(window.location.hash=u?"".concat(r,"?").concat(u):r,d.route.handler(h)):v(new Error("Navigation blocked by guard"))}).then(function(n){e&&n&&(e.innerHTML="",e.appendChild(n)),i(c=h)}).catch(function(n){return f(n),v(n)})}:function(n){var t=n.split("?"),r=t[0],u=t[1],a=p(u||""),d=s(r);if(d){var l={params:d.params,query:a,path:r,meta:d.route.meta};try{if(!o(l,c))return;window.location.hash=u?"".concat(r,"?").concat(u):r;var v=d.route.handler(l);e&&v&&"function"!=typeof v.then&&(e.innerHTML="",e.appendChild(v)),i(c=l)}catch(n){f(n)}}else f(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 c}}}export{F as a,x as btn,Q as createRouter,E as div,I as form,g as h,P as h1,R as h2,T as h3,j as h4,A as h5,k as h6,G as img,O as input,L as label,N as li,C as ol,D as option,M as p,U as select,H as span,K as table,V as tbody,B as td,z as th,S as thead,$ as tr,q as ul};
1
+ var n=Object.freeze(Object.create(null)),t=Array.isArray,e=Array.prototype.filter,r=Object.keys,o=function(){return{}},u="undefined"==typeof Promise?o:Promise.resolve,i="undefined"==typeof Promise?o:Promise.reject,a=document.createElement,f=document.createTextNode,c=document.createDocumentFragment,d=function(n){return void 0===n&&(n=""),f.call(document,n)},l=HTMLElement.prototype.addEventListener,v=HTMLElement.prototype.setAttribute,s=HTMLElement.prototype.appendChild,p=HTMLElement.prototype.append,m="function"==typeof p?function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return p.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])?s.call(this,d(u)):u!==n&&s.call(this,u)}else{var o=c.call(document);for(r=0;r<t.length;r++){var u;"string"==typeof(u=t[r])?s.call(o,d(u)):u!==n&&s.call(o,u)}s.call(this,o)}},h=function(n){throw new Error("Kt.js:".concat(n))};function y(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 b={checked:y,selected:y,value:w,valueAsDate:w,valueAsNumber:w,defaultValue:w,defaultChecked:y,defaultSelected:y,disabled:y,readOnly:y,multiple:y,required:y,autofocus:y,open:y,controls:y,autoplay:y,loop:y,muted:y,defer:y,async:y,hidden:function(n,t,e){n.hidden=!!e}},g=function(n,t,e){return v.call(n,t,e)};function E(n,t){"string"==typeof t?n.className=t:"object"==typeof t&&null!==t?function(n,t){var e=t.class,o=t.style;if(void 0!==e&&(n.className=e,delete t.class),void 0!==o){if("string"==typeof o)v.call(n,"style",o);else for(var u in n.style)n.style[u]=o[u];delete t.style}for(var i=r(t),a=i.length-1;a>=0;a--){var f=t[u=i[a]];"function"!=typeof f?(b[u]||g)(n,u,f):l.call(n,u,f)}void 0!==e&&(t.style=e),void 0!==o&&(t.style=o)}(n,t):h("applyAttr attr must be an object.")}function j(n,e,r){void 0===e&&(e=""),void 0===r&&(r=""),"string"!=typeof n&&h("h tagName must be a string.");var o,u=(o=n,a.call(document,o));return E(u,e),function(n,e){t(e)?m.apply(n,e):m.call(n,e)}(u,r),u}var A=function(n){return function(t,e){return j(n,t,e)}},P=A("div"),R=A("span"),H=A("label"),L=A("p"),M=A("h1"),O=A("h2"),T=A("h3"),k=A("h4"),q=A("h5"),C=A("h6"),N=A("ul"),x=A("ol"),I=A("li"),U=A("button"),D=A("form"),K=A("input"),S=A("select"),V=A("option"),$=A("table"),z=A("thead"),B=A("tbody"),F=A("tr"),G=A("th"),J=A("td"),Q=A("a"),W=A("img"),X=function(){return!0};function Y(n){var t=n.routes,e=n.container,r=n.beforeEach,o=void 0===r?X:r,a=n.afterEach,f=void 0===a?X:a,c=n.onError,d=void 0===c?console.error:c,l=null,v=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}}),s=function(n){for(var t=0;t<v.length;t++){var e=v[t],r=e.route,o=e.pattern,u=e.names,i=n.match(o);if(i){for(var a={},f=0;f<u.length;f++)a[u[f]]=i[f+1];return{route:r,params:a}}}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],a=t[1],c=p(a||""),v=s(r);if(!v){var m=new Error("Route not found: ".concat(r));return d(m),i(m)}var h={params:v.params,query:c,path:r,meta:v.route.meta};return u(o(h,l)).then(function(n){return n?(window.location.hash=a?"".concat(r,"?").concat(a):r,v.route.handler(h)):i(new Error("Navigation blocked by guard"))}).then(function(n){e&&n&&(e.innerHTML="",e.appendChild(n)),f(l=h)}).catch(function(n){return d(n),i(n)})}:function(n){var t=n.split("?"),r=t[0],u=t[1],i=p(u||""),a=s(r);if(a){var c={params:a.params,query:i,path:r,meta:a.route.meta};try{if(!o(c,l))return;window.location.hash=u?"".concat(r,"?").concat(u):r;var v=a.route.handler(c);e&&v&&"function"!=typeof v.then&&(e.innerHTML="",e.appendChild(v)),f(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{Q as a,U as btn,Y as createRouter,P as div,D as form,j as h,M as h1,O as h2,T as h3,k as h4,q as h5,C as h6,W as img,K as input,n as ktnull,H as label,I as li,x as ol,V as option,L as p,S as select,R as span,$ as table,B as tbody,J as td,G as th,z as thead,F as tr,N as ul};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kt.js",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"