kt.js 0.0.2 → 0.0.3

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,6 +1,96 @@
1
+ # kt.js
2
+
3
+ [中文](./README.zh.md) [English](./README.md)
4
+
5
+ For more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)
6
+
7
+ > Note: this library is under active development.
8
+
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
+
11
+ Key philosophy
12
+
13
+ - No forced re-rendering. Changes are applied only when needed.
14
+ - Nearly zero unnecessary reflows/repaints.
15
+ - Minimal overhead and extremely small runtime cost.
16
+ - Direct DOM operations for predictable, fast updates.
17
+
18
+ ## Getting started
19
+
20
+ Install via npm or your preferred package manager and import the functions you need from `src/index.ts`.
21
+
22
+ Primary exports (from `src/index.ts`)
23
+
24
+ - `h` — hyperscript helper
25
+ - Creates a KText-enhanced DOM element representation.
26
+ - Typical usage: h('div', { id: 'root' }, 'Hello') or using JSX-like helpers from the project.
27
+ - Returns an `HTMLKEnhancedElement` (an HTMLElement with extra `enhance` properties described below).
28
+
29
+ - `css` — global CSS collector
30
+ - Tagged template helper that collects provided CSS text into an internal list.
31
+ - Usage: css`.foo { color: red; }`
32
+ - The collected CSS is applied by `applyCss()` (invoked automatically by `createApp` if appropriate).
33
+
34
+ - `useScope` — scoped CSS helper
35
+ - Provides a mechanism to scope CSS rules to a specific name/namespace. Works with the `css` helper and the library's scoped utilities.
36
+
37
+ - `createApp` — mount helper
38
+ - Mounts a root `HTMLKEnhancedElement` to the document.
39
+ - Signature: `createApp(rootElement: HTMLKEnhancedElement, mountTo?: HTMLElement)`
40
+ - If `mountTo` is omitted, it tries `#app` and falls back to `document.body`.
41
+ - Will call `applyCss()` to flush collected CSS to the document.
42
+
43
+ ## Enhance-added properties and methods
44
+
45
+ After calling `enhance(element)` (done internally by `h` when appropriate), an HTMLElement becomes an `HTMLKEnhancedElement` with the following additions:
46
+
47
+ - Properties
48
+ - `kid` (number): a per-element unique index generated by an internal `Indexer.nextKid()`.
49
+ - `isKT` (true): boolean marker that identifies the element as a KText element.
50
+ - `ktext` (string): getter/setter that proxies to an internal Text node stored on the element (reads/writes element text content).
51
+
52
+ - Methods
53
+ - `kon(type, listener, options?)` — enhanced addEventListener
54
+ - Normalizes options. Supports a `triggerLimit` option which will remove the listener after N triggers (if `triggerLimit === 1` it becomes `once`).
55
+ - Returns the listener (or a wrapped listener used for limited triggers).
56
+ - `koff(type, listener, options?)` — enhanced removeEventListener
57
+ - Removes event listeners respecting provided options.
58
+ - `kmount(element)` — append/mount helper
59
+ - Equivalent to `element.appendChild(this)` and returns `this` for chaining.
60
+
61
+ ## Examples
62
+
63
+ Create and mount an app:
64
+
65
+ ```ts
66
+ import { h, css, createApp } from './src/index';
67
+
68
+ const root = h('div', { id: 'root' }, 'Hello world');
69
+ css`
70
+ .root {
71
+ color: hotpink;
72
+ }
73
+ `;
74
+ createApp(root);
75
+ ```
76
+
77
+ ## Notes and caveats
78
+
79
+ - This library manipulates the DOM directly and intentionally keeps re-rendering minimal.
80
+ - `enhance` augments elements with non-enumerable descriptors for `ktext`, `isKT`, and `kid`, and assigns `kon`, `koff`, and `kmount` methods directly.
81
+ - The API is small and low-level by design — it's intended as a performance-focused building block rather than a full component framework.
82
+
83
+ ## Contributing
84
+
85
+ PRs and issues are welcome. If you add features that affect the public API, update README and tests accordingly.
86
+
87
+ ## License
88
+
89
+ See the repository `LICENSE` file.
90
+
1
91
  # KT.js
2
92
 
3
- (still developing)
93
+ For more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)
4
94
 
5
95
  (image wait to be placed here)
6
96
 
package/README.zh.md ADDED
@@ -0,0 +1,87 @@
1
+ # kt.js
2
+
3
+ [中文](./README.zh.md) [English](./README.md)
4
+
5
+ For more awesome packages, check out [my homepage💛](https://baendlorel.github.io/?repoType=npm)
6
+
7
+ > 注意:这个库仍在开发中。
8
+
9
+ kt.js 是一个微小的高性能 DOM 工具,专注于最小化重绘和直接操作 DOM。它的设计目标是尽量不强制重绘,只在必要时更新 DOM,从而获得极致性能。
10
+
11
+ 核心理念
12
+
13
+ - 不强制重绘。只有在需要时才更新。
14
+ - 极少无谓的重排/重绘。
15
+ - 最小开销,极低运行时成本。
16
+ - 直接操作 DOM,获得可预测且快速的更新。
17
+
18
+ ## 快速开始
19
+
20
+ 通过 npm 或你喜欢的包管理器安装,然后从 `src/index.ts` 中导入所需函数。
21
+
22
+ 主要导出(来自 `src/index.ts`)
23
+
24
+ - `h` — hyperscript 辅助函数
25
+ - 创建带有 KText 增强属性的 DOM 元素。
26
+ - 用法示例:h('div', { id: 'root' }, 'Hello')。
27
+ - 返回 `HTMLKEnhancedElement`(一个带有额外 `enhance` 属性的 HTMLElement)。
28
+
29
+ - `css` — 全局 CSS 收集器
30
+ - 模板字符串标签函数,把传入的 CSS 文本收集到内部数组中。
31
+ - 用法: css`.foo { color: red; }`
32
+ - 收集到的 CSS 会通过 `applyCss()` 注入到文档中(`createApp` 在合适时会调用它)。
33
+
34
+ - `useScope` — 作用域 CSS 助手
35
+ - 提供将 CSS 作用域化到特定名称/命名空间的能力,配合 `css` 使用。
36
+
37
+ - `createApp` — 挂载助手
38
+ - 将根 `HTMLKEnhancedElement` 挂载到文档。
39
+ - 签名:`createApp(rootElement: HTMLKEnhancedElement, mountTo?: HTMLElement)`
40
+ - 若省略 `mountTo`,会尝试 `#app`,找不到则回退到 `document.body`。
41
+ - 会调用 `applyCss()` 来刷新已收集的 CSS。
42
+
43
+ ## enhance 增添的属性和方法
44
+
45
+ 当调用 `enhance(element)`(在需要时 `h` 会内部调用)后,HTMLElement 会被增强为 `HTMLKEnhancedElement`,包含以下新增项:
46
+
47
+ - 属性
48
+ - `kid`(number):由内部 `Indexer.nextKid()` 生成的每个元素唯一索引。
49
+ - `isKT`(true):标记元素是 KText 元素的布尔值。
50
+ - `ktext`(string):代理内部 Text 节点的 getter/setter(读写元素文本内容)。
51
+
52
+ - 方法
53
+ - `kon(type, listener, options?)` — 增强的 addEventListener
54
+ - 规范化 options,支持 `triggerLimit`(监听器在触发 N 次后移除;若 `triggerLimit === 1` 则等同于 `once`)。
55
+ - 返回 listener(或用于限制触发次数的包装监听器)。
56
+ - `koff(type, listener, options?)` — 增强的 removeEventListener
57
+ - 移除事件监听,遵循提供的 options。
58
+ - `kmount(element)` — 挂载/追加辅助方法
59
+ - 等价于 `element.appendChild(this)`,并返回 `this` 以方便链式调用。
60
+
61
+ ## 示例
62
+
63
+ ```ts
64
+ import { h, css, createApp } from './src/index';
65
+
66
+ const root = h('div', { id: 'root' }, 'Hello world');
67
+ css`
68
+ .root {
69
+ color: hotpink;
70
+ }
71
+ `;
72
+ createApp(root);
73
+ ```
74
+
75
+ ## 注意
76
+
77
+ - 本库直接操作 DOM,故意将重绘控制在最低。
78
+ - `enhance` 为元素添加了非枚举描述符的属性 `ktext`、`isKT` 和 `kid`,并直接赋值 `kon`、`koff`、`kmount` 方法。
79
+ - 该 API 小且低级,旨在作为性能优先的构建块,而非完整的组件框架。
80
+
81
+ ## 贡献
82
+
83
+ 欢迎 PR 和 issue。如果你修改了公共 API,请同步更新 README 和测试。
84
+
85
+ ## 许可证
86
+
87
+ 参见仓库中的 `LICENSE` 文件。
package/dist/index.d.ts CHANGED
@@ -20,18 +20,21 @@ declare function css(strings: TemplateStringsArray, ...values: any[]): string;
20
20
  * @param attr attribute object or className
21
21
  * @param content a string or an array of HTMLEnhancedElement as child nodes
22
22
  */
23
- declare function h<Tag extends HTMLElementTag>(
24
- tag: Tag,
25
- attr?: KAttribute | string,
26
- content?: (HTMLKEnhancedElement | string)[] | HTMLKEnhancedElement | string
27
- ): HTMLKEnhancedElement<Tag>;
23
+ declare function h<Tag extends HTMLElementTag>(tag: Tag, attr?: KAttribute | string, content?: (HTMLKEnhancedElement | string)[] | HTMLKEnhancedElement | string): HTMLKEnhancedElement<Tag>;
28
24
 
29
25
  declare function useScope(scopeName?: string): {
30
- h: typeof h;
31
- css: typeof css;
26
+ h: typeof h;
27
+ css: typeof css;
32
28
  };
33
29
 
34
- export { css, h, useScope };
30
+ /**
31
+ * Mount root element to `#app`(`body` if not found) or to the given element.
32
+ * @param rootElement an instance of `HTMLKEnhancedElement`, created by `h` function.
33
+ * @param mountTo any `HTMLElement` to mount to, if omitted, will mount to `#app` or `body`.
34
+ */
35
+ declare function createApp(rootElement: HTMLKEnhancedElement, mountTo?: HTMLElement): void;
36
+
37
+ export { createApp, css, h, useScope };
35
38
 
36
39
  // # from: src/global.d.ts
37
40
  declare const __IS_DEV__: boolean;
@@ -70,7 +73,6 @@ type KListener<E extends HTMLElement, K extends keyof HTMLElementEventMap> = (
70
73
  ) => unknown;
71
74
 
72
75
  // # from: src/types/enhance.d.ts
73
-
74
76
  type HTMLElementTag = keyof HTMLElementTagNameMap;
75
77
 
76
78
  interface KEnhanced {
@@ -81,6 +83,9 @@ interface KEnhanced {
81
83
 
82
84
  isKT: true;
83
85
 
86
+ // getter/setter
87
+ ktext: string;
88
+
84
89
  kon: <El extends HTMLElement, K extends keyof HTMLElementEventMap>(
85
90
  this: El,
86
91
  type: K,
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- class t extends Error{reason;filename;line;column;source;constructor(t,n,e,s,i){super(`${t}:${e}:${s}: ${n}`),this.reason=n,this.filename=t,this.line=e,this.column=s,this.source=i}}class n{start;end;source;constructor(t,n,e){this.start=t,this.end=n,this.source=e}}var e;!function(t){t.stylesheet="stylesheet",t.rule="rule",t.declaration="declaration",t.comment="comment",t.container="container",t.charset="charset",t.document="document",t.customMedia="custom-media",t.fontFace="font-face",t.host="host",t.import="import",t.keyframes="keyframes",t.keyframe="keyframe",t.layer="layer",t.media="media",t.namespace="namespace",t.page="page",t.startingStyle="starting-style",t.supports="supports"}(e||(e={}));const s=(t,n,e)=>{let s=e,i=1e4;do{const e=n.map(n=>t.indexOf(n,s));e.push(t.indexOf("\\",s));const r=e.filter(t=>-1!==t);if(0===r.length)return-1;const o=Math.min(...r);if("\\"!==t[o])return o;s=o+2,i--}while(i>0);throw new Error("Too many escaping")},i=(t,n,e)=>{let r=e,o=1e4;do{const e=n.map(n=>t.indexOf(n,r));e.push(t.indexOf("(",r)),e.push(t.indexOf('"',r)),e.push(t.indexOf("'",r)),e.push(t.indexOf("\\",r));const c=e.filter(t=>-1!==t);if(0===c.length)return-1;const h=Math.min(...c);switch(t[h]){case"\\":r=h+2;break;case"(":{const n=i(t,[")"],h+1);if(-1===n)return-1;r=n+1}break;case'"':{const n=s(t,['"'],h+1);if(-1===n)return-1;r=n+1}break;case"'":{const n=s(t,["'"],h+1);if(-1===n)return-1;r=n+1}break;default:return h}o--}while(o>0);throw new Error("Too many escaping")},r=/\/\*[^]*?(?:\*\/|$)/g;function o(t){return t?t.trim():""}function c(t,n){const e=t&&"string"==typeof t.type,s=e?t:n;for(const n in t){const e=t[n];Array.isArray(e)?e.forEach(t=>{c(t,s)}):e&&"object"==typeof e&&c(e,s)}return e&&Object.defineProperty(t,"parent",{configurable:!0,writable:!0,enumerable:!1,value:n||null}),t}class h{level=0;indentation=" ";compress=!1;constructor(t){"string"==typeof t?.indent&&(this.indentation=t?.indent),t?.compress&&(this.compress=!0)}emit(t,n){return t}indent(t){return this.level=this.level||1,t?(this.level+=t,""):Array(this.level).join(this.indentation)}visit(t){switch(t.type){case e.stylesheet:return this.stylesheet(t);case e.rule:return this.rule(t);case e.declaration:return this.declaration(t);case e.comment:return this.comment(t);case e.container:return this.container(t);case e.charset:return this.charset(t);case e.document:return this.document(t);case e.customMedia:return this.customMedia(t);case e.fontFace:return this.fontFace(t);case e.host:return this.host(t);case e.import:return this.import(t);case e.keyframes:return this.keyframes(t);case e.keyframe:return this.keyframe(t);case e.layer:return this.layer(t);case e.media:return this.media(t);case e.namespace:return this.namespace(t);case e.page:return this.page(t);case e.startingStyle:return this.startingStyle(t);case e.supports:return this.supports(t)}}mapVisit(t,n){let e="";n=n||"";for(let s=0,i=t.length;s<i;s++)e+=this.visit(t[s]),n&&s<i-1&&(e+=this.emit(n));return e}compile(t){return this.compress?t.stylesheet.rules.map(this.visit,this).join(""):this.stylesheet(t)}stylesheet(t){return this.mapVisit(t.stylesheet.rules,"\n\n")}comment(t){return this.compress?this.emit("",t.position):this.emit(`${this.indent()}/*${t.comment}*/`,t.position)}container(t){return this.compress?this.emit(`@container ${t.container}`,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@container ${t.container}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}layer(t){return this.compress?this.emit(`@layer ${t.layer}`,t.position)+(t.rules?this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):";"):this.emit(`${this.indent()}@layer ${t.layer}`,t.position)+(t.rules?this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`):";")}import(t){return this.emit(`@import ${t.import};`,t.position)}media(t){return this.compress?this.emit(`@media ${t.media}`,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@media ${t.media}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}document(t){const n=`@${t.vendor||""}document ${t.document}`;return this.compress?this.emit(n,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(n,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`${this.indent(-1)}\n}`)}charset(t){return this.emit(`@charset ${t.charset};`,t.position)}namespace(t){return this.emit(`@namespace ${t.namespace};`,t.position)}startingStyle(t){return this.compress?this.emit("@starting-style",t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@starting-style`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}supports(t){return this.compress?this.emit(`@supports ${t.supports}`,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@supports ${t.supports}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}keyframes(t){return this.compress?this.emit(`@${t.vendor||""}keyframes ${t.name}`,t.position)+this.emit("{")+this.mapVisit(t.keyframes)+this.emit("}"):this.emit(`@${t.vendor||""}keyframes ${t.name}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.keyframes,"\n")+this.emit(`${this.indent(-1)}}`)}keyframe(t){const n=t.declarations;return this.compress?this.emit(t.values.join(","),t.position)+this.emit("{")+this.mapVisit(n)+this.emit("}"):this.emit(this.indent())+this.emit(t.values.join(", "),t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(n,"\n")+this.emit(`${this.indent(-1)}\n${this.indent()}}\n`)}page(t){if(this.compress){const n=t.selectors.length?t.selectors.join(", "):"";return this.emit(`@page ${n}`,t.position)+this.emit("{")+this.mapVisit(t.declarations)+this.emit("}")}const n=t.selectors.length?`${t.selectors.join(", ")} `:"";return this.emit(`@page ${n}`,t.position)+this.emit("{\n")+this.emit(this.indent(1))+this.mapVisit(t.declarations,"\n")+this.emit(this.indent(-1))+this.emit("\n}")}fontFace(t){return this.compress?this.emit("@font-face",t.position)+this.emit("{")+this.mapVisit(t.declarations)+this.emit("}"):this.emit("@font-face ",t.position)+this.emit("{\n")+this.emit(this.indent(1))+this.mapVisit(t.declarations,"\n")+this.emit(this.indent(-1))+this.emit("\n}")}host(t){return this.compress?this.emit("@host",t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit("@host",t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`${this.indent(-1)}\n}`)}customMedia(t){return this.emit(`@custom-media ${t.name} ${t.media};`,t.position)}rule(t){const n=t.declarations;if(!n.length)return"";if(this.compress)return this.emit(t.selectors.join(","),t.position)+this.emit("{")+this.mapVisit(n)+this.emit("}");const e=this.indent();return this.emit(t.selectors.map(t=>e+t).join(",\n"),t.position)+this.emit(" {\n")+this.emit(this.indent(1))+this.mapVisit(n,"\n")+this.emit(this.indent(-1))+this.emit(`\n${this.indent()}}`)}declaration(t){return this.compress?this.emit(`${t.property}:${t.value}`,t.position)+this.emit(";"):"grid-template-areas"===t.property?this.emit(this.indent())+this.emit(t.property+": "+t.value.split("\n").join("\n".padEnd(22)+this.indent()),t.position)+this.emit(";"):this.emit(this.indent())+this.emit(`${t.property}: ${t.value}`,t.position)+this.emit(";")}}const u=(s,h)=>{h=h||{};let u=1,a=1;function f(){const t={line:u,column:a};return e=>(e.position=new n(t,{line:u,column:a},h?.source||""),$(),e)}const l=[];function m(n){const e=new t(h?.source||"",n,u,a,s);if(!h?.silent)throw e;l.push(e)}function p(){const t=/^{\s*/.exec(s);return!!t&&(g(t),!0)}function d(){const t=/^}/.exec(s);return!!t&&(g(t),!0)}function y(){let t;const n=[];for($(),E(n);s.length&&"}"!==s.charAt(0)&&(t=S()||j(),t);)n.push(t),E(n);return n}function g(t){const n=t[0];return function(t){const n=t.match(/\n/g);n&&(u+=n.length);const e=t.lastIndexOf("\n");a=~e?t.length-e:a+t.length}(n),s=s.slice(n.length),t}function $(){const t=/^\s*/.exec(s);t&&g(t)}function E(t){t=t||[];let n=T();for(;n;)t.push(n),n=T();return t}function T(){const t=f();if("/"!==s.charAt(0)||"*"!==s.charAt(1))return;const n=/^\/\*[^]*?\*\//.exec(s);return n?(g(n),t({type:e.comment,comment:n[0].slice(2,-2)})):m("End of comment missing")}function L(){const t=/^([^{]+)/.exec(s);if(t)return g(t),((t,n)=>{const e=[];let s=0;for(;s<t.length;){const r=i(t,n,s);if(-1===r)return e.push(t.substring(s)),e;e.push(t.substring(s,r)),s=r+1}return e})(o(t[0]).replace(r,""),[","]).map(t=>o(t))}function M(){const t=f(),n=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/.exec(s);if(!n)return;g(n);const c=o(n[0]),h=/^:\s*/.exec(s);if(!h)return m("property missing ':'");g(h);let u="";const a=i(s,[";","}"]);-1!==a&&(u=s.substring(0,a),g([u]),u=o(u).replace(r,""));const l=t({type:e.declaration,property:c.replace(r,""),value:u}),p=/^[;\s]*/.exec(s);return p&&g(p),l}function H(){const t=[];if(!p())return m("missing '{'");E(t);let n=M();for(;n;)t.push(n),E(t),n=M();return d()?t:m("missing '}'")}function w(){const t=[],n=f();let i=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(s);for(;i;){const n=g(i);t.push(n[1]);const e=/^,\s*/.exec(s);e&&g(e),i=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(s)}if(t.length)return n({type:e.keyframe,values:t,declarations:H()||[]})}const b=B("import"),v=B("charset"),k=B("namespace");function B(t){const n=new RegExp("^@"+t+"\\s*((?::?[^;'\"]|\"(?:\\\\\"|[^\"])*?\"|'(?:\\\\'|[^'])*?')+)(?:;|$)");return()=>{const e=f(),i=n.exec(s);if(!i)return;const r=g(i),o={type:t};return o[t]=r[1].trim(),e(o)}}function S(){if("@"===s[0])return function(){const t=f(),n=/^@([-\w]+)?keyframes\s*/.exec(s);if(!n)return;const i=g(n)[1],r=/^([-\w]+)\s*/.exec(s);if(!r)return m("@keyframes missing name");const o=g(r)[1];if(!p())return m("@keyframes missing '{'");let c=E(),h=w();for(;h;)c.push(h),c=c.concat(E()),h=w();return d()?t({type:e.keyframes,name:o,vendor:i,keyframes:c}):m("@keyframes missing '}'")}()||function(){const t=f(),n=/^@media *([^{]+)/.exec(s);if(!n)return;const i=o(g(n)[1]);if(!p())return m("@media missing '{'");const r=E().concat(y());return d()?t({type:e.media,media:i,rules:r}):m("@media missing '}'")}()||function(){const t=f(),n=/^@custom-media\s+(--\S+)\s+([^{;\s][^{;]*);/.exec(s);if(!n)return;const i=g(n);return t({type:e.customMedia,name:o(i[1]),media:o(i[2])})}()||function(){const t=f(),n=/^@supports *([^{]+)/.exec(s);if(!n)return;const i=o(g(n)[1]);if(!p())return m("@supports missing '{'");const r=E().concat(y());return d()?t({type:e.supports,supports:i,rules:r}):m("@supports missing '}'")}()||b()||v()||k()||function(){const t=f(),n=/^@([-\w]+)?document *([^{]+)/.exec(s);if(!n)return;const i=g(n),r=o(i[1]),c=o(i[2]);if(!p())return m("@document missing '{'");const h=E().concat(y());return d()?t({type:e.document,document:c,vendor:r,rules:h}):m("@document missing '}'")}()||function(){const t=f(),n=/^@page */.exec(s);if(!n)return;g(n);const i=L()||[];if(!p())return m("@page missing '{'");let r=E(),o=M();for(;o;)r.push(o),r=r.concat(E()),o=M();return d()?t({type:e.page,selectors:i,declarations:r}):m("@page missing '}'")}()||function(){const t=f(),n=/^@host\s*/.exec(s);if(!n)return;if(g(n),!p())return m("@host missing '{'");const i=E().concat(y());return d()?t({type:e.host,rules:i}):m("@host missing '}'")}()||function(){const t=f(),n=/^@font-face\s*/.exec(s);if(!n)return;if(g(n),!p())return m("@font-face missing '{'");let i=E(),r=M();for(;r;)i.push(r),i=i.concat(E()),r=M();return d()?t({type:e.fontFace,declarations:i}):m("@font-face missing '}'")}()||function(){const t=f(),n=/^@container *([^{]+)/.exec(s);if(!n)return;const i=o(g(n)[1]);if(!p())return m("@container missing '{'");const r=E().concat(y());return d()?t({type:e.container,container:i,rules:r}):m("@container missing '}'")}()||function(){const t=f(),n=/^@starting-style\s*/.exec(s);if(!n)return;if(g(n),!p())return m("@starting-style missing '{'");const i=E().concat(y());return d()?t({type:e.startingStyle,rules:i}):m("@starting-style missing '}'")}()||function(){const t=f(),n=/^@layer *([^{;@]+)/.exec(s);if(!n)return;const i=o(g(n)[1]);if(!p()){const n=/^[;\s]*/.exec(s);return n&&g(n),t({type:e.layer,layer:i})}const r=E().concat(y());return d()?t({type:e.layer,layer:i,rules:r}):m("@layer missing '}'")}()}function j(){const t=f(),n=L();return n?(E(),t({type:e.rule,selectors:n,declarations:H()||[]})):m("selector missing")}return c(function(){const t=y();return{type:e.stylesheet,stylesheet:{source:h?.source,rules:t,parsingErrors:l}}}())},a=Reflect.apply,f=Reflect.get,l=Reflect.defineProperty,m=Array.isArray,p=Object.keys,d=Object.assign,y=Object.is,g=Number.isSafeInteger,$=t=>"object"==typeof t&&null!==t,E=document.createElement.bind(document),T=document.createTextNode.bind(document);function L(t,n){const e=[];for(let s=0;s<t.length;s++)e.push(t[s]),s<n.length&&e.push(String(n[s]));return e.join("").replace(/\r\n/g,"\n").trim()}function M(t,...n){return L(t,n)}function H(t){return function(n,...s){const i=L(n,s),r=u(i),o=n=>{if(!$(n))return;n.type===e.rule&&(n.selectors=n.selectors.map(n=>`[${t}]${n}`));const s=p(n),i=s.length;for(let t=0;t<i;t++){const e=f(n,s[t]);if(m(e)){const t=e.length;for(let n=0;n<t;n++)o(e[n]);continue}$(e)&&o(e)}};o(r);const c=((t,n)=>new h(n||{}).compile(t))(r);return c}}class w extends(null){static kid=0;static scopeIndex=0;static genScopeName(){return"data-k-"+(++w.scopeIndex).toString(36).padStart(6,"0")}static nextKid(){return++w.kid}}const b=Symbol();function v(t,n,e=b){if(y(e,b))return a(addEventListener,this,[t,n]),n;if(!$(e)||!("triggerLimit"in e))return a(addEventListener,this,[t,n,e]),n;const s=e.triggerLimit;if(delete e.triggerLimit,!g(s)||s<=0)throw new TypeError("[Kt.js:kon] options.triggerLimit must be a positive safe integer.");if(1===s)return e.once=!0,a(addEventListener,this,[t,n,e]),n;let i=s;const r=function(s){const o=a(n,this,[s]);return i--,i<=0&&a(removeEventListener,this,[t,r,e]),o};return a(addEventListener,this,[t,r,e]),r}function k(t,n,e=b){y(b,e)?a(removeEventListener,this,[t,n]):a(removeEventListener,this,[t,n,e])}function B(t){return t.appendChild(this)}function S(t,n="",e=""){if("string"!=typeof t)throw new TypeError("[Kt.js:h] tagName must be a string.");if("string"!=typeof n&&!$(n))throw new TypeError("[Kt.js:h] attr must be an object.");if("string"!=typeof e&&!$(e)&&!m(e))throw new TypeError("[Kt.js:h] content must be a string or an array of html elements.");const s=E(t);if(l(s,"kid",{value:w.nextKid(),enumerable:!0}),l(s,"isKT",{value:!0}),s.kon=v,s.koff=k,s.kmount=B,"string"==typeof e){const t=T(e);s.appendChild(t)}else if(m(e)){const t=e.length;for(let n=0;n<t;n++){const t=e[n];if("string"!=typeof t){if(!t.isKT)throw new TypeError("[Kt.js:h] content must be a string or an array of HTMLEnhancedElement.");s.appendChild(t)}else s.appendChild(T(t))}}else e.isKT&&s.appendChild(e);if(!n)return s;if("string"==typeof n)return s.className=n,s;n.class&&(m(n.class)?s.classList.add(...n.class):s.className=n.class,delete n.class),n.style&&("string"==typeof n.style?s.setAttribute("style",n.style):d(s.style,n.style),delete n.style);const i=p(n),r=i.length;for(let t=0;t<r;t++){const e=i[t],r=n[e];"function"!=typeof r&&("checked"!==e?"value"!==e?"selected"!==e?"defaultValue"!==e?"defaultChecked"!==e?"defaultSelected"!==e?"disabled"!==e?"readOnly"!==e?"multiple"!==e?"autofocus"!==e?"required"!==e?"hidden"!==e?"open"===e&&s instanceof HTMLDetailsElement?s.open=Boolean(r):"controls"===e&&s instanceof HTMLMediaElement?s.controls=Boolean(r):"autoplay"===e&&s instanceof HTMLMediaElement?s.autoplay=Boolean(r):"loop"===e&&s instanceof HTMLMediaElement?s.loop=Boolean(r):"muted"===e&&s instanceof HTMLMediaElement?s.muted=Boolean(r):"defer"===e&&s instanceof HTMLScriptElement?s.defer=Boolean(r):"async"===e&&s instanceof HTMLScriptElement?s.async=Boolean(r):s.setAttribute(e,r):s.hidden=Boolean(r):s instanceof HTMLInputElement||s instanceof HTMLSelectElement||s instanceof HTMLTextAreaElement?s.required=Boolean(r):s.setAttribute(e,r):s instanceof HTMLInputElement||s instanceof HTMLButtonElement||s instanceof HTMLSelectElement||s instanceof HTMLTextAreaElement?s.autofocus=Boolean(r):s.setAttribute(e,r):s instanceof HTMLSelectElement?s.multiple=Boolean(r):s.setAttribute(e,r):s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement?s.readOnly=Boolean(r):s.setAttribute(e,r):s instanceof HTMLInputElement||s instanceof HTMLButtonElement||s instanceof HTMLSelectElement||s instanceof HTMLOptGroupElement||s instanceof HTMLOptionElement||s instanceof HTMLFieldSetElement||s instanceof HTMLTextAreaElement?s.disabled=Boolean(r):s.setAttribute(e,r):s instanceof HTMLOptionElement?s.defaultSelected=Boolean(r):s.setAttribute(e,r):s instanceof HTMLInputElement?s.defaultChecked=Boolean(r):s.setAttribute(e,r):s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement?s.defaultValue=String(r):s.setAttribute(e,r):s instanceof HTMLOptionElement?s.selected=Boolean(r):s.setAttribute(e,r):s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement?s.value=String(r):s.setAttribute(e,r):s instanceof HTMLInputElement?s.checked=Boolean(r):s.setAttribute(e,r))}return s}function j(t){return function(...n){const e=S(...n);return e.setAttribute(t,""),e}}function x(t=w.genScopeName()){return{h:j(t),css:H(t)}}export{M as css,S as h,x as useScope};
1
+ const t=Symbol("KText"),n=Symbol("NotProvided");let e=class extends Error{reason;filename;line;column;source;constructor(t,n,e,s,i){super(`${t}:${e}:${s}: ${n}`),this.reason=n,this.filename=t,this.line=e,this.column=s,this.source=i}};class s{start;end;source;constructor(t,n,e){this.start=t,this.end=n,this.source=e}}var i;!function(t){t.stylesheet="stylesheet",t.rule="rule",t.declaration="declaration",t.comment="comment",t.container="container",t.charset="charset",t.document="document",t.customMedia="custom-media",t.fontFace="font-face",t.host="host",t.import="import",t.keyframes="keyframes",t.keyframe="keyframe",t.layer="layer",t.media="media",t.namespace="namespace",t.page="page",t.startingStyle="starting-style",t.supports="supports"}(i||(i={}));const r=(t,n,e)=>{let s=e,i=1e4;do{const e=n.map(n=>t.indexOf(n,s));e.push(t.indexOf("\\",s));const r=e.filter(t=>-1!==t);if(0===r.length)return-1;const o=Math.min(...r);if("\\"!==t[o])return o;s=o+2,i--}while(i>0);throw new Error("Too many escaping")},o=(t,n,e)=>{let s=e,i=1e4;do{const e=n.map(n=>t.indexOf(n,s));e.push(t.indexOf("(",s)),e.push(t.indexOf('"',s)),e.push(t.indexOf("'",s)),e.push(t.indexOf("\\",s));const c=e.filter(t=>-1!==t);if(0===c.length)return-1;const u=Math.min(...c);switch(t[u]){case"\\":s=u+2;break;case"(":{const n=o(t,[")"],u+1);if(-1===n)return-1;s=n+1}break;case'"':{const n=r(t,['"'],u+1);if(-1===n)return-1;s=n+1}break;case"'":{const n=r(t,["'"],u+1);if(-1===n)return-1;s=n+1}break;default:return u}i--}while(i>0);throw new Error("Too many escaping")},c=/\/\*[^]*?(?:\*\/|$)/g;function u(t){return t?t.trim():""}function h(t,n){const e=t&&"string"==typeof t.type,s=e?t:n;for(const n in t){const e=t[n];Array.isArray(e)?e.forEach(t=>{h(t,s)}):e&&"object"==typeof e&&h(e,s)}return e&&Object.defineProperty(t,"parent",{configurable:!0,writable:!0,enumerable:!1,value:n||null}),t}class a{level=0;indentation=" ";compress=!1;constructor(t){"string"==typeof t?.indent&&(this.indentation=t?.indent),t?.compress&&(this.compress=!0)}emit(t,n){return t}indent(t){return this.level=this.level||1,t?(this.level+=t,""):Array(this.level).join(this.indentation)}visit(t){switch(t.type){case i.stylesheet:return this.stylesheet(t);case i.rule:return this.rule(t);case i.declaration:return this.declaration(t);case i.comment:return this.comment(t);case i.container:return this.container(t);case i.charset:return this.charset(t);case i.document:return this.document(t);case i.customMedia:return this.customMedia(t);case i.fontFace:return this.fontFace(t);case i.host:return this.host(t);case i.import:return this.import(t);case i.keyframes:return this.keyframes(t);case i.keyframe:return this.keyframe(t);case i.layer:return this.layer(t);case i.media:return this.media(t);case i.namespace:return this.namespace(t);case i.page:return this.page(t);case i.startingStyle:return this.startingStyle(t);case i.supports:return this.supports(t)}}mapVisit(t,n){let e="";n=n||"";for(let s=0,i=t.length;s<i;s++)e+=this.visit(t[s]),n&&s<i-1&&(e+=this.emit(n));return e}compile(t){return this.compress?t.stylesheet.rules.map(this.visit,this).join(""):this.stylesheet(t)}stylesheet(t){return this.mapVisit(t.stylesheet.rules,"\n\n")}comment(t){return this.compress?this.emit("",t.position):this.emit(`${this.indent()}/*${t.comment}*/`,t.position)}container(t){return this.compress?this.emit(`@container ${t.container}`,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@container ${t.container}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}layer(t){return this.compress?this.emit(`@layer ${t.layer}`,t.position)+(t.rules?this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):";"):this.emit(`${this.indent()}@layer ${t.layer}`,t.position)+(t.rules?this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`):";")}import(t){return this.emit(`@import ${t.import};`,t.position)}media(t){return this.compress?this.emit(`@media ${t.media}`,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@media ${t.media}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}document(t){const n=`@${t.vendor||""}document ${t.document}`;return this.compress?this.emit(n,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(n,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`${this.indent(-1)}\n}`)}charset(t){return this.emit(`@charset ${t.charset};`,t.position)}namespace(t){return this.emit(`@namespace ${t.namespace};`,t.position)}startingStyle(t){return this.compress?this.emit("@starting-style",t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@starting-style`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}supports(t){return this.compress?this.emit(`@supports ${t.supports}`,t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit(`${this.indent()}@supports ${t.supports}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`\n${this.indent(-1)}${this.indent()}}`)}keyframes(t){return this.compress?this.emit(`@${t.vendor||""}keyframes ${t.name}`,t.position)+this.emit("{")+this.mapVisit(t.keyframes)+this.emit("}"):this.emit(`@${t.vendor||""}keyframes ${t.name}`,t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.keyframes,"\n")+this.emit(`${this.indent(-1)}}`)}keyframe(t){const n=t.declarations;return this.compress?this.emit(t.values.join(","),t.position)+this.emit("{")+this.mapVisit(n)+this.emit("}"):this.emit(this.indent())+this.emit(t.values.join(", "),t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(n,"\n")+this.emit(`${this.indent(-1)}\n${this.indent()}}\n`)}page(t){if(this.compress){const n=t.selectors.length?t.selectors.join(", "):"";return this.emit(`@page ${n}`,t.position)+this.emit("{")+this.mapVisit(t.declarations)+this.emit("}")}const n=t.selectors.length?`${t.selectors.join(", ")} `:"";return this.emit(`@page ${n}`,t.position)+this.emit("{\n")+this.emit(this.indent(1))+this.mapVisit(t.declarations,"\n")+this.emit(this.indent(-1))+this.emit("\n}")}fontFace(t){return this.compress?this.emit("@font-face",t.position)+this.emit("{")+this.mapVisit(t.declarations)+this.emit("}"):this.emit("@font-face ",t.position)+this.emit("{\n")+this.emit(this.indent(1))+this.mapVisit(t.declarations,"\n")+this.emit(this.indent(-1))+this.emit("\n}")}host(t){return this.compress?this.emit("@host",t.position)+this.emit("{")+this.mapVisit(t.rules)+this.emit("}"):this.emit("@host",t.position)+this.emit(` {\n${this.indent(1)}`)+this.mapVisit(t.rules,"\n\n")+this.emit(`${this.indent(-1)}\n}`)}customMedia(t){return this.emit(`@custom-media ${t.name} ${t.media};`,t.position)}rule(t){const n=t.declarations;if(!n.length)return"";if(this.compress)return this.emit(t.selectors.join(","),t.position)+this.emit("{")+this.mapVisit(n)+this.emit("}");const e=this.indent();return this.emit(t.selectors.map(t=>e+t).join(",\n"),t.position)+this.emit(" {\n")+this.emit(this.indent(1))+this.mapVisit(n,"\n")+this.emit(this.indent(-1))+this.emit(`\n${this.indent()}}`)}declaration(t){return this.compress?this.emit(`${t.property}:${t.value}`,t.position)+this.emit(";"):"grid-template-areas"===t.property?this.emit(this.indent())+this.emit(t.property+": "+t.value.split("\n").join("\n".padEnd(22)+this.indent()),t.position)+this.emit(";"):this.emit(this.indent())+this.emit(`${t.property}: ${t.value}`,t.position)+this.emit(";")}}const f=(t,n)=>{n=n||{};let r=1,a=1;function f(){const t={line:r,column:a};return e=>(e.position=new s(t,{line:r,column:a},n?.source||""),$(),e)}const l=[];function m(s){const i=new e(n?.source||"",s,r,a,t);if(!n?.silent)throw i;l.push(i)}function p(){const n=/^{\s*/.exec(t);return!!n&&(g(n),!0)}function d(){const n=/^}/.exec(t);return!!n&&(g(n),!0)}function y(){let n;const e=[];for($(),T(e);t.length&&"}"!==t.charAt(0)&&(n=x()||v(),n);)e.push(n),T(e);return e}function g(n){const e=n[0];return function(t){const n=t.match(/\n/g);n&&(r+=n.length);const e=t.lastIndexOf("\n");a=~e?t.length-e:a+t.length}(e),t=t.slice(e.length),n}function $(){const n=/^\s*/.exec(t);n&&g(n)}function T(t){t=t||[];let n=E();for(;n;)t.push(n),n=E();return t}function E(){const n=f();if("/"!==t.charAt(0)||"*"!==t.charAt(1))return;const e=/^\/\*[^]*?\*\//.exec(t);return e?(g(e),n({type:i.comment,comment:e[0].slice(2,-2)})):m("End of comment missing")}function M(){const n=/^([^{]+)/.exec(t);if(n)return g(n),((t,n)=>{const e=[];let s=0;for(;s<t.length;){const i=o(t,n,s);if(-1===i)return e.push(t.substring(s)),e;e.push(t.substring(s,i)),s=i+1}return e})(u(n[0]).replace(c,""),[","]).map(t=>u(t))}function L(){const n=f(),e=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/.exec(t);if(!e)return;g(e);const s=u(e[0]),r=/^:\s*/.exec(t);if(!r)return m("property missing ':'");g(r);let h="";const a=o(t,[";","}"]);-1!==a&&(h=t.substring(0,a),g([h]),h=u(h).replace(c,""));const l=n({type:i.declaration,property:s.replace(c,""),value:h}),p=/^[;\s]*/.exec(t);return p&&g(p),l}function H(){const t=[];if(!p())return m("missing '{'");T(t);let n=L();for(;n;)t.push(n),T(t),n=L();return d()?t:m("missing '}'")}function w(){const n=[],e=f();let s=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t);for(;s;){const e=g(s);n.push(e[1]);const i=/^,\s*/.exec(t);i&&g(i),s=/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t)}if(n.length)return e({type:i.keyframe,values:n,declarations:H()||[]})}const b=S("import"),k=S("charset"),B=S("namespace");function S(n){const e=new RegExp("^@"+n+"\\s*((?::?[^;'\"]|\"(?:\\\\\"|[^\"])*?\"|'(?:\\\\'|[^'])*?')+)(?:;|$)");return()=>{const s=f(),i=e.exec(t);if(!i)return;const r=g(i),o={type:n};return o[n]=r[1].trim(),s(o)}}function x(){if("@"===t[0])return function(){const n=f(),e=/^@([-\w]+)?keyframes\s*/.exec(t);if(!e)return;const s=g(e)[1],r=/^([-\w]+)\s*/.exec(t);if(!r)return m("@keyframes missing name");const o=g(r)[1];if(!p())return m("@keyframes missing '{'");let c=T(),u=w();for(;u;)c.push(u),c=c.concat(T()),u=w();return d()?n({type:i.keyframes,name:o,vendor:s,keyframes:c}):m("@keyframes missing '}'")}()||function(){const n=f(),e=/^@media *([^{]+)/.exec(t);if(!e)return;const s=u(g(e)[1]);if(!p())return m("@media missing '{'");const r=T().concat(y());return d()?n({type:i.media,media:s,rules:r}):m("@media missing '}'")}()||function(){const n=f(),e=/^@custom-media\s+(--\S+)\s+([^{;\s][^{;]*);/.exec(t);if(!e)return;const s=g(e);return n({type:i.customMedia,name:u(s[1]),media:u(s[2])})}()||function(){const n=f(),e=/^@supports *([^{]+)/.exec(t);if(!e)return;const s=u(g(e)[1]);if(!p())return m("@supports missing '{'");const r=T().concat(y());return d()?n({type:i.supports,supports:s,rules:r}):m("@supports missing '}'")}()||b()||k()||B()||function(){const n=f(),e=/^@([-\w]+)?document *([^{]+)/.exec(t);if(!e)return;const s=g(e),r=u(s[1]),o=u(s[2]);if(!p())return m("@document missing '{'");const c=T().concat(y());return d()?n({type:i.document,document:o,vendor:r,rules:c}):m("@document missing '}'")}()||function(){const n=f(),e=/^@page */.exec(t);if(!e)return;g(e);const s=M()||[];if(!p())return m("@page missing '{'");let r=T(),o=L();for(;o;)r.push(o),r=r.concat(T()),o=L();return d()?n({type:i.page,selectors:s,declarations:r}):m("@page missing '}'")}()||function(){const n=f(),e=/^@host\s*/.exec(t);if(!e)return;if(g(e),!p())return m("@host missing '{'");const s=T().concat(y());return d()?n({type:i.host,rules:s}):m("@host missing '}'")}()||function(){const n=f(),e=/^@font-face\s*/.exec(t);if(!e)return;if(g(e),!p())return m("@font-face missing '{'");let s=T(),r=L();for(;r;)s.push(r),s=s.concat(T()),r=L();return d()?n({type:i.fontFace,declarations:s}):m("@font-face missing '}'")}()||function(){const n=f(),e=/^@container *([^{]+)/.exec(t);if(!e)return;const s=u(g(e)[1]);if(!p())return m("@container missing '{'");const r=T().concat(y());return d()?n({type:i.container,container:s,rules:r}):m("@container missing '}'")}()||function(){const n=f(),e=/^@starting-style\s*/.exec(t);if(!e)return;if(g(e),!p())return m("@starting-style missing '{'");const s=T().concat(y());return d()?n({type:i.startingStyle,rules:s}):m("@starting-style missing '}'")}()||function(){const n=f(),e=/^@layer *([^{;@]+)/.exec(t);if(!e)return;const s=u(g(e)[1]);if(!p()){const e=/^[;\s]*/.exec(t);return e&&g(e),n({type:i.layer,layer:s})}const r=T().concat(y());return d()?n({type:i.layer,layer:s,rules:r}):m("@layer missing '}'")}()}function v(){const t=f(),n=M();return n?(T(),t({type:i.rule,selectors:n,declarations:H()||[]})):m("selector missing")}return h(function(){const t=y();return{type:i.stylesheet,stylesheet:{source:n?.source,rules:t,parsingErrors:l}}}())},l=Reflect.apply,m=Reflect.set,p=Reflect.get,d=Reflect.defineProperty,y=Array.isArray,g=Object.keys,$=Object.assign,T=Object.is,E=Number.isSafeInteger,M=t=>"object"==typeof t&&null!==t,L=document.getElementById.bind(document),H=document.createElement.bind(document),w=document.createTextNode.bind(document),b=HTMLElement.prototype.addEventListener,k=HTMLElement.prototype.removeEventListener,B=[];function S(t,n){const e=[];for(let s=0;s<t.length;s++)e.push(t[s]),s<n.length&&e.push(String(n[s]));return e.join("").replace(/\r\n/g,"\n").trim()}function x(t,...n){const e=S(t,n);return B.push(e),e}function v(t){return function(n,...e){const s=S(n,e),r=f(s),o=n=>{if(!M(n))return;n.type===i.rule&&(n.selectors=n.selectors.map(n=>`[${t}]${n}`));const e=g(n),s=e.length;for(let t=0;t<s;t++){const s=p(n,e[t]);if(y(s)){const t=s.length;for(let n=0;n<t;n++)o(s[n]);continue}M(s)&&o(s)}};o(r);const c=((t,n)=>new a(n||{}).compile(t))(r);return B.push(c),c}}class j extends(null){static kid=0;static scopeIndex=0;static genScopeName(){return"data-k-"+(++j.scopeIndex).toString(36).padStart(6,"0")}static nextKid(){return++j.kid}}const A={get:function(){return p(this,t).textContent},set:function(n){p(this,t).textContent=n}},I={value:!0};function O(t,e,s=n){if(T(s,n))return l(b,this,[t,e]),e;if(!M(s)||!("triggerLimit"in s))return l(b,this,[t,e,s]),e;const i=s.triggerLimit;if(delete s.triggerLimit,!E(i)||i<=0)throw new TypeError("[Kt.js:kon] options.triggerLimit must be a positive safe integer.");if(1===i)return s.once=!0,l(b,this,[t,e,s]),e;let r=i;const o=function(n){const i=l(e,this,[n]);return r--,r<=0&&l(k,this,[t,o,s]),i};return l(b,this,[t,o,s]),o}function K(t,e,s=n){T(n,s)?l(k,this,[t,e]):l(k,this,[t,e,s])}function R(t){return t.appendChild(this)}function N(t){d(t,"kid",{value:j.nextKid(),enumerable:!0}),d(t,"isKT",I),d(t,"ktext",A),t.kon=O,t.koff=K,t.kmount=R}class z{t=null;o=null;add(t,n){if("function"!=typeof n)throw new TypeError("Branch must be a function");return t&&(this.t=n),this}nomatch(t){if("function"!=typeof t)throw new TypeError("Branch must be a function");return this.t||t(),this}deferedNomatch(t){if("function"!=typeof t)throw new TypeError("Branch must be a function");return this.o=t,this}run(...t){return this.t?this.t(...t):this.o?this.o(...t):void 0}}const F=()=>new z,V=(t,n)=>t.className=n,q=(t,n)=>{n.class&&(y(n.class)?t.classList.add(...n.class):t.className=n.class,delete n.class),n.style&&("string"==typeof n.style?t.setAttribute("style",n.style):$(t.style,n.style),delete n.style);const e=g(n),s=e.length;for(let i=0;i<s;i++){const s=e[i],r=n[s];"function"!=typeof r&&("checked"!==s?"value"!==s?"selected"!==s?"defaultValue"!==s?"defaultChecked"!==s?"defaultSelected"!==s?"disabled"!==s?"readOnly"!==s?"multiple"!==s?"autofocus"!==s?"required"!==s?"hidden"!==s?"open"===s&&t instanceof HTMLDetailsElement?t.open=Boolean(r):"controls"===s&&t instanceof HTMLMediaElement?t.controls=Boolean(r):"autoplay"===s&&t instanceof HTMLMediaElement?t.autoplay=Boolean(r):"loop"===s&&t instanceof HTMLMediaElement?t.loop=Boolean(r):"muted"===s&&t instanceof HTMLMediaElement?t.muted=Boolean(r):"defer"===s&&t instanceof HTMLScriptElement?t.defer=Boolean(r):"async"===s&&t instanceof HTMLScriptElement?t.async=Boolean(r):t.setAttribute(s,r):t.hidden=Boolean(r):t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?t.required=Boolean(r):t.setAttribute(s,r):t instanceof HTMLInputElement||t instanceof HTMLButtonElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?t.autofocus=Boolean(r):t.setAttribute(s,r):t instanceof HTMLSelectElement?t.multiple=Boolean(r):t.setAttribute(s,r):t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?t.readOnly=Boolean(r):t.setAttribute(s,r):t instanceof HTMLInputElement||t instanceof HTMLButtonElement||t instanceof HTMLSelectElement||t instanceof HTMLOptGroupElement||t instanceof HTMLOptionElement||t instanceof HTMLFieldSetElement||t instanceof HTMLTextAreaElement?t.disabled=Boolean(r):t.setAttribute(s,r):t instanceof HTMLOptionElement?t.defaultSelected=Boolean(r):t.setAttribute(s,r):t instanceof HTMLInputElement?t.defaultChecked=Boolean(r):t.setAttribute(s,r):t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?t.defaultValue=String(r):t.setAttribute(s,r):t instanceof HTMLOptionElement?t.selected=Boolean(r):t.setAttribute(s,r):t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement?t.value=String(r):t.setAttribute(s,r):t instanceof HTMLInputElement?t.checked=Boolean(r):t.setAttribute(s,r))}},C=()=>{throw new TypeError("[Kt.js:h] attr must be an object.")},D=(t,n)=>{t.ktext=n},G=(t,n)=>{const e=n.length;for(let s=0;s<e;s++){const e=n[s];"string"!=typeof e?e.isKT?t.appendChild(e):_():t.appendChild(w(e))}},P=(t,n)=>{n.isKT||_(),t.appendChild(n)},_=()=>{throw new TypeError("[Kt.js:h] content must be a string, HTMLEnhancedElement or an array of HTMLEnhancedElement.")};function J(n,e="",s=""){if("string"!=typeof n)throw new TypeError("[Kt.js:h] tagName must be a string.");const i=(t=>F().add("string"==typeof t,V).add(M(t),q).nomatch(C))(e),r=(t=>F().add("string"==typeof t,D).add(M(t),P).add(y(t),G).nomatch(_))(s),o=H(n),c=w("");return o.appendChild(c),m(o,t,c),N(o),r.run(o,s),i.run(o,e),o}function Q(t){return function(...n){const e=J(...n);return e.setAttribute(t,""),e}}function U(t=j.genScopeName()){return{h:Q(t),css:v(t)}}function W(t,e=n){if(!t.isKT)throw new TypeError("Root element must be a KText element.");const s=L("app")??document.body;if(T(e,n)&&t.kmount(s),!M(e))throw new TypeError("mountTo must be an HTMLElement or omitted.");!function(){const t=H("style");t.id="kt.js-style",t.innerHTML=B.join("\n"),B.splice(0),t.innerHTML}()}export{W as createApp,x as css,J as h,U as useScope};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kt.js",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "author": {
5
5
  "name": "Kasukabe Tsumugi",
6
6
  "email": "futami16237@gmail.com"
@@ -64,6 +64,7 @@
64
64
  "vitest": "^3.2.4"
65
65
  },
66
66
  "dependencies": {
67
- "@adobe/css-tools": "^4.4.4"
67
+ "@adobe/css-tools": "^4.4.4",
68
+ "defered-branch": "^1.2.2"
68
69
  }
69
70
  }