@ktjs/vite-plugin-ktjsx 0.4.5 → 0.4.6

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,32 +1,71 @@
1
- # vite-plugin-ktjsx
1
+ # KT.js
2
2
 
3
- light, manual‑control web framework that creates real DOM elements with built‑in reactive state management.
4
-
5
- [![npm version](https://img.shields.io/npm/v/vite-plugin-ktjsx.svg)](https://www.npmjs.com/package/vite-plugin-ktjsx)
6
- [![npm downloads](https://img.shields.io/npm/dm/vite-plugin-ktjsx.svg)](https://www.npmjs.com/package/vite-plugin-ktjsx)
3
+ [![npm version](https://img.shields.io/npm/v/kt.js.svg)](https://www.npmjs.com/package/kt.js)
4
+ [![npm downloads](https://img.shields.io/npm/dm/kt.js.svg)](https://www.npmjs.com/package/kt.js)
7
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
6
 
9
- `@ktjs/vite-plugin-ktjsx` applies KT.js JSX transforms in Vite.
7
+ <p align="center">
8
+ <a href="https://baendlorel.github.io/kt.js/">
9
+ <img src="https://raw.githubusercontent.com/baendlorel/kt.js/refs/heads/main/assets/ktjs-0.0.1.svg" width="240px" alt="KT.js logo" />
10
+ </a>
11
+ </p>
12
+
13
+ <p align="center"><strong>Visit KT.js: <a href="https://baendlorel.github.io/kt.js/">https://baendlorel.github.io/kt.js/</a></strong></p>
14
+
15
+ > kt.js is still under development, so there might be some breaking changes. Note the Update Log below
16
+
17
+ ## Recent Updates
18
+
19
+ 1. `ref.value` remains the standard read API, and it can also replace the whole outer value with `ref.value = nextValue`.
20
+ 2. `ref.draft` is the deep-mutation entry for nested objects, arrays, `Map` / `Set`, and custom mutable objects.
21
+ 3. `ref.draft` itself is not assignable; mutate nested fields or call mutating methods on the returned object instead.
22
+ 4. `addOnChange((newValue, oldValue) => ...)` keeps `oldValue` as the previous reference, not a deep snapshot.
23
+
24
+ ## Community
25
+
26
+ - QQ Group: `1070434849`
27
+ - Telegram: https://t.me/kt_js
10
28
 
11
- It reuses the shared `@ktjs/transformer` core (also used by `@ktjs/babel-plugin-ktjsx`), so behavior is the same:
29
+ ## Introduction
12
30
 
13
- - mark SVG / MathML subtrees with KT.js namespace flags
14
- - compile adjacent `k-if` + `k-else` siblings into `KTConditional(...)`
15
- - warn and leave `k-else-if` unchanged (currently unsupported)
31
+ kt.js is a simple framework with a tiny runtime that renders real DOM directly (no virtual DOM), uses explicit reactivity variables and gives you manual control over refs, bindings, and redraw timing.
16
32
 
17
- Basic usage:
33
+ KT.js focuses on one principle: keep direct control of the DOM and avoid unnecessary repainting.
34
+
35
+ ## Reactive Contract
18
36
 
19
37
  ```ts
20
- import { defineConfig } from 'vite';
21
- import ktjsx from '@ktjs/vite-plugin-ktjsx';
38
+ const user = ref({ profile: { name: 'John' }, tags: ['new'] });
39
+
40
+ console.log(user.value.profile.name); // read
22
41
 
23
- export default defineConfig({
24
- plugins: [ktjsx()],
25
- });
42
+ user.value = {
43
+ ...user.value,
44
+ profile: { ...user.value.profile, name: 'Jane' },
45
+ tags: [...user.value.tags],
46
+ }; // replace the whole outer value
47
+
48
+ user.draft.profile.name = 'Jane'; // deep write
49
+ user.draft.tags.push('active'); // array / map / set / custom-object style mutation
26
50
  ```
27
51
 
28
- Options:
52
+ Rules:
53
+
54
+ - Read with `.value`.
55
+ - Replace the whole outer value with `.value = nextValue`.
56
+ - Use `.draft` for deep mutations on nested objects, arrays, `Map` / `Set`, or other mutable instances.
57
+ - Do not assign to `.draft` itself; mutate inside it.
58
+ - `computed` stays read-only and is consumed through `.value`.
59
+ - `oldValue` in change listeners is the previous reference only, not a deep-cloned snapshot.
60
+ - Correctness is expected to come from the transformer and TypeScript checks; runtime hot paths stay minimal on purpose.
29
61
 
30
- - `include` - custom file matcher (`RegExp` or predicate function)
31
- - `exclude` - files to skip (`RegExp` or predicate function)
32
- - `babelConfig` - additional Babel transform options
62
+ This is an explicit contract, closer to a Rust-style model than permissive runtime magic: unclear code should fail early.
63
+
64
+ ## Quick Start
65
+
66
+ ```bash
67
+ pnpm create kt.js my-app
68
+ cd my-app
69
+ pnpm install
70
+ pnpm dev
71
+ ```
package/dist/index.mjs CHANGED
@@ -1,53 +1,25 @@
1
- import { transformWithKTjsx } from '@ktjs/transformer';
1
+ import { transformWithKTjsx } from "@ktjs/transformer";
2
+
3
+ const DEFAULT_INCLUDE_RE = /\.[cm]?[jt]sx$/, NODE_MODULES_RE = /\/node_modules\//, QUERY_RE = /\?.*$/, matchFilter = (filter, id) => !!filter && ("function" == typeof filter ? filter(id) : (filter.lastIndex = 0,
4
+ filter.test(id)));
2
5
 
3
- const DEFAULT_INCLUDE_RE = /\.[cm]?[jt]sx$/;
4
- const NODE_MODULES_RE = /\/node_modules\//;
5
- const QUERY_RE = /\?.*$/;
6
- const stripQuery = (id) => id.replace(QUERY_RE, '');
7
- const matchFilter = (filter, id) => {
8
- if (!filter) {
9
- return false;
10
- }
11
- if (typeof filter === 'function') {
12
- return filter(id);
13
- }
14
- filter.lastIndex = 0;
15
- return filter.test(id);
16
- };
17
- const shouldTransform = (id, include, exclude) => {
18
- if (id.startsWith('\0') || NODE_MODULES_RE.test(id)) {
19
- return false;
20
- }
21
- if (exclude && matchFilter(exclude, id)) {
22
- return false;
23
- }
24
- if (include) {
25
- return matchFilter(include, id);
26
- }
27
- return DEFAULT_INCLUDE_RE.test(id);
28
- };
29
6
  function viteKTjsx(options = {}) {
30
7
  return {
31
- name: 'ktjs:vite-plugin-ktjsx',
32
- enforce: 'pre',
8
+ name: "ktjs:vite-plugin-ktjsx",
9
+ enforce: "pre",
33
10
  async transform(code, id) {
34
- const cleanId = stripQuery(id);
35
- if (!shouldTransform(cleanId, options.include, options.exclude)) {
36
- return null;
37
- }
11
+ const cleanId = (id => id.replace(QUERY_RE, ""))(id);
12
+ if (!((id, include, exclude) => !id.startsWith("\0") && !NODE_MODULES_RE.test(id) && (!exclude || !matchFilter(exclude, id)) && (include ? matchFilter(include, id) : DEFAULT_INCLUDE_RE.test(id)))(cleanId, options.include, options.exclude)) return null;
38
13
  const result = await transformWithKTjsx(code, {
39
14
  filename: cleanId,
40
15
  sourceFileName: cleanId,
41
- ...options.babelConfig,
16
+ ...options.babelConfig
42
17
  });
43
- if (!result?.code) {
44
- return null;
45
- }
46
- return {
18
+ return result?.code ? {
47
19
  code: result.code,
48
- map: result.map ?? null,
49
- };
50
- },
20
+ map: result.map ?? null
21
+ } : null;
22
+ }
51
23
  };
52
24
  }
53
25
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { transformWithKTjsx, type KTjsxTransformOptions } from '@ktjs/transformer';\n\ntype Filter = RegExp | ((id: string) => boolean);\n\nexport interface ViteKTjsxOptions {\n include?: Filter;\n exclude?: Filter;\n babelConfig?: Record<string, unknown>;\n}\n\nconst DEFAULT_INCLUDE_RE = /\\.[cm]?[jt]sx$/;\nconst NODE_MODULES_RE = /\\/node_modules\\//;\nconst QUERY_RE = /\\?.*$/;\ntype InternalTransformOptions = Omit<KTjsxTransformOptions, 'filename' | 'sourceFileName'>;\n\nconst stripQuery = (id: string) => id.replace(QUERY_RE, '');\n\nconst matchFilter = (filter: Filter | undefined, id: string): boolean => {\n if (!filter) {\n return false;\n }\n\n if (typeof filter === 'function') {\n return filter(id);\n }\n\n filter.lastIndex = 0;\n return filter.test(id);\n};\n\nconst shouldTransform = (id: string, include?: Filter, exclude?: Filter): boolean => {\n if (id.startsWith('\\0') || NODE_MODULES_RE.test(id)) {\n return false;\n }\n\n if (exclude && matchFilter(exclude, id)) {\n return false;\n }\n\n if (include) {\n return matchFilter(include, id);\n }\n\n return DEFAULT_INCLUDE_RE.test(id);\n};\n\nexport function viteKTjsx(options: ViteKTjsxOptions = {}): Plugin {\n return {\n name: 'ktjs:vite-plugin-ktjsx',\n enforce: 'pre',\n async transform(code, id) {\n const cleanId = stripQuery(id);\n if (!shouldTransform(cleanId, options.include, options.exclude)) {\n return null;\n }\n\n const result = await transformWithKTjsx(code, {\n filename: cleanId,\n sourceFileName: cleanId,\n ...(options.babelConfig as InternalTransformOptions),\n });\n\n if (!result?.code) {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n\nexport default viteKTjsx;\n"],"names":[],"mappings":";;AAWA,MAAM,kBAAkB,GAAG,gBAAgB;AAC3C,MAAM,eAAe,GAAG,kBAAkB;AAC1C,MAAM,QAAQ,GAAG,OAAO;AAGxB,MAAM,UAAU,GAAG,CAAC,EAAU,KAAK,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;AAE3D,MAAM,WAAW,GAAG,CAAC,MAA0B,EAAE,EAAU,KAAa;IACtE,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,OAAO,KAAK;IACd;AAEA,IAAA,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;AAChC,QAAA,OAAO,MAAM,CAAC,EAAE,CAAC;IACnB;AAEA,IAAA,MAAM,CAAC,SAAS,GAAG,CAAC;AACpB,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;AACxB,CAAC;AAED,MAAM,eAAe,GAAG,CAAC,EAAU,EAAE,OAAgB,EAAE,OAAgB,KAAa;AAClF,IAAA,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;AACnD,QAAA,OAAO,KAAK;IACd;IAEA,IAAI,OAAO,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,EAAE;AACvC,QAAA,OAAO,KAAK;IACd;IAEA,IAAI,OAAO,EAAE;AACX,QAAA,OAAO,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;IACjC;AAEA,IAAA,OAAO,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;AACpC,CAAC;AAEK,SAAU,SAAS,CAAC,OAAA,GAA4B,EAAE,EAAA;IACtD,OAAO;AACL,QAAA,IAAI,EAAE,wBAAwB;AAC9B,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,MAAM,SAAS,CAAC,IAAI,EAAE,EAAE,EAAA;AACtB,YAAA,MAAM,OAAO,GAAG,UAAU,CAAC,EAAE,CAAC;AAC9B,YAAA,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE;AAC/D,gBAAA,OAAO,IAAI;YACb;AAEA,YAAA,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,IAAI,EAAE;AAC5C,gBAAA,QAAQ,EAAE,OAAO;AACjB,gBAAA,cAAc,EAAE,OAAO;gBACvB,GAAI,OAAO,CAAC,WAAwC;AACrD,aAAA,CAAC;AAEF,YAAA,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE;AACjB,gBAAA,OAAO,IAAI;YACb;YAEA,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;AACjB,gBAAA,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,IAAI;aACxB;QACH,CAAC;KACF;AACH;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { transformWithKTjsx, type KTjsxTransformOptions } from '@ktjs/transformer';\n\ntype Filter = RegExp | ((id: string) => boolean);\n\nexport interface ViteKTjsxOptions {\n include?: Filter;\n exclude?: Filter;\n babelConfig?: Record<string, unknown>;\n}\n\nconst DEFAULT_INCLUDE_RE = /\\.[cm]?[jt]sx$/;\nconst NODE_MODULES_RE = /\\/node_modules\\//;\nconst QUERY_RE = /\\?.*$/;\ntype InternalTransformOptions = Omit<KTjsxTransformOptions, 'filename' | 'sourceFileName'>;\n\nconst stripQuery = (id: string) => id.replace(QUERY_RE, '');\n\nconst matchFilter = (filter: Filter | undefined, id: string): boolean => {\n if (!filter) {\n return false;\n }\n\n if (typeof filter === 'function') {\n return filter(id);\n }\n\n filter.lastIndex = 0;\n return filter.test(id);\n};\n\nconst shouldTransform = (id: string, include?: Filter, exclude?: Filter): boolean => {\n if (id.startsWith('\\0') || NODE_MODULES_RE.test(id)) {\n return false;\n }\n\n if (exclude && matchFilter(exclude, id)) {\n return false;\n }\n\n if (include) {\n return matchFilter(include, id);\n }\n\n return DEFAULT_INCLUDE_RE.test(id);\n};\n\nexport function viteKTjsx(options: ViteKTjsxOptions = {}): Plugin {\n return {\n name: 'ktjs:vite-plugin-ktjsx',\n enforce: 'pre',\n async transform(code, id) {\n const cleanId = stripQuery(id);\n if (!shouldTransform(cleanId, options.include, options.exclude)) {\n return null;\n }\n\n const result = await transformWithKTjsx(code, {\n filename: cleanId,\n sourceFileName: cleanId,\n ...(options.babelConfig as InternalTransformOptions),\n });\n\n if (!result?.code) {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n },\n };\n}\n\nexport default viteKTjsx;\n"],"names":["DEFAULT_INCLUDE_RE","NODE_MODULES_RE","QUERY_RE","matchFilter","filter","id","lastIndex","test","viteKTjsx","options","name","enforce","transform","code","cleanId","replace","stripQuery","include","exclude","startsWith","shouldTransform","result","transformWithKTjsx","filename","sourceFileName","babelConfig","map"],"mappings":";;AAWA,MAAMA,qBAAqB,kBACrBC,kBAAkB,oBAClBC,WAAW,SAKXC,cAAc,CAACC,QAA4BC,SAC1CD,WAIiB,qBAAXA,SACFA,OAAOC,OAGhBD,OAAOE,YAAY;AACZF,OAAOG,KAAKF;;AAmBf,SAAUG,UAAUC,UAA4B;IACpD,OAAO;QACLC,MAAM;QACNC,SAAS;QACT,eAAMC,CAAUC,MAAMR;YACpB,MAAMS,UApCO,CAACT,MAAeA,GAAGU,QAAQb,UAAU,IAoClCc,CAAWX;YAC3B,KAtBkB,EAACA,IAAYY,SAAkBC,aACjDb,GAAGc,WAAW,UAASlB,gBAAgBM,KAAKF,SAI5Ca,YAAWf,YAAYe,SAASb,SAIhCY,UACKd,YAAYc,SAASZ,MAGvBL,mBAAmBO,KAAKF,KAStBe,CAAgBN,SAASL,QAAQQ,SAASR,QAAQS,UACrD,OAAO;YAGT,MAAMG,eAAeC,mBAAmBT,MAAM;gBAC5CU,UAAUT;gBACVU,gBAAgBV;mBACZL,QAAQgB;;YAGd,OAAKJ,QAAQR,OAIN;gBACLA,MAAMQ,OAAOR;gBACba,KAAKL,OAAOK,OAAO;gBALZ;AAOX;;AAEJ;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ktjs/vite-plugin-ktjsx",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Vite plugin that applies KT.js JSX transforms.",
5
5
  "description_zh": "用于应用 KT.js JSX 转换的 Vite 插件。",
6
6
  "type": "module",