@ktjs/vite-plugin-ktjsx 0.1.2 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 kasukabe tsumugi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,7 +8,7 @@ light, manual‑control web framework that creates real DOM elements with built
8
8
 
9
9
  `@ktjs/vite-plugin-ktjsx` applies KT.js JSX transforms in Vite.
10
10
 
11
- It reuses `@ktjs/babel-plugin-ktjsx` internally, so behavior is the same:
11
+ It reuses the shared `@ktjs/transformer` core (also used by `@ktjs/babel-plugin-ktjsx`), so behavior is the same:
12
12
 
13
13
  - mark SVG / MathML subtrees with KT.js namespace flags
14
14
  - (TODO) transform `k-if` / `k-else-if` / `k-else` chains
package/dist/index.d.ts CHANGED
@@ -1,15 +1,12 @@
1
- import { Plugin as Plugin_2 } from 'vite';
2
-
3
- declare type Filter = RegExp | ((id: string) => boolean);
4
-
5
- declare function viteKTjsx(options?: ViteKTjsxOptions): Plugin_2;
6
- export default viteKTjsx;
7
- export { viteKTjsx }
8
-
9
- export declare interface ViteKTjsxOptions {
10
- include?: Filter;
11
- exclude?: Filter;
12
- babelConfig?: Record<string, unknown>;
13
- }
14
-
15
- export { }
1
+ import { Plugin } from 'vite';
2
+
3
+ type Filter = RegExp | ((id: string) => boolean);
4
+ interface ViteKTjsxOptions {
5
+ include?: Filter;
6
+ exclude?: Filter;
7
+ babelConfig?: Record<string, unknown>;
8
+ }
9
+ declare function viteKTjsx(options?: ViteKTjsxOptions): Plugin;
10
+
11
+ export { viteKTjsx as default, viteKTjsx };
12
+ export type { ViteKTjsxOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,55 @@
1
+ import { transformWithKTjsx } from '@ktjs/transformer';
2
+
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
+ function viteKTjsx(options = {}) {
30
+ return {
31
+ name: 'ktjs:vite-plugin-ktjsx',
32
+ enforce: 'pre',
33
+ async transform(code, id) {
34
+ const cleanId = stripQuery(id);
35
+ if (!shouldTransform(cleanId, options.include, options.exclude)) {
36
+ return null;
37
+ }
38
+ const result = await transformWithKTjsx(code, {
39
+ filename: cleanId,
40
+ sourceFileName: cleanId,
41
+ ...options.babelConfig,
42
+ });
43
+ if (!result?.code) {
44
+ return null;
45
+ }
46
+ return {
47
+ code: result.code,
48
+ map: result.map ?? null,
49
+ };
50
+ },
51
+ };
52
+ }
53
+
54
+ export { viteKTjsx as default, viteKTjsx };
55
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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;;;;"}
@@ -0,0 +1,4 @@
1
+ import type { NodePath } from '@babel/core';
2
+ import * as t from '@babel/types';
3
+ export declare function transformConditionalChains(path: NodePath<t.JSXElement>): void;
4
+ //# sourceMappingURL=if-else.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"if-else.d.ts","sourceRoot":"","sources":["../../../../transformer/src/if-else.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAiFlC,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QA8DtE"}
@@ -0,0 +1,4 @@
1
+ export { default, transformerKTjsx } from './plugin.js';
2
+ export type { KTjsxTransformOptions } from './transform.js';
3
+ export { transformWithKTjsx } from './transform.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../transformer/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type NodePath } from '@babel/core';
2
+ import * as t from '@babel/types';
3
+ export declare function validateDirectiveCombinations(path: NodePath<t.JSXElement>): void;
4
+ export declare function transformKFor(path: NodePath<t.JSXElement>): boolean;
5
+ //# sourceMappingURL=k-for.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"k-for.d.ts","sourceRoot":"","sources":["../../../../transformer/src/k-for.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAWlC,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAkBzE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,OAAO,CAqCnE"}
@@ -0,0 +1,4 @@
1
+ import type { PluginObj } from '@babel/core';
2
+ export declare function transformerKTjsx(): PluginObj;
3
+ export default transformerKTjsx;
4
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../transformer/src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAK7C,wBAAgB,gBAAgB,IAAI,SAAS,CAgB5C;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { NodePath } from '@babel/core';
2
+ import * as t from '@babel/types';
3
+ export declare function addFlagToSvgMathMLElement(path: NodePath<t.JSXElement>): void;
4
+ //# sourceMappingURL=svg-mathml-flag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg-mathml-flag.d.ts","sourceRoot":"","sources":["../../../../transformer/src/svg-mathml-flag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAUlC,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAiFrE"}
@@ -0,0 +1,8 @@
1
+ import { type TransformOptions } from '@babel/core';
2
+ type ReservedTransformOptions = 'ast' | 'babelrc' | 'configFile' | 'parserOpts' | 'plugins' | 'sourceMaps';
3
+ export type KTjsxTransformOptions = Omit<TransformOptions, ReservedTransformOptions> & {
4
+ parserPlugins?: NonNullable<TransformOptions['parserOpts']>['plugins'];
5
+ };
6
+ export declare function transformWithKTjsx(code: string, options?: KTjsxTransformOptions): Promise<import("@babel/core").BabelFileResult>;
7
+ export {};
8
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../transformer/src/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAKpE,KAAK,wBAAwB,GACzB,KAAK,GACL,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,YAAY,CAAC;AAEjB,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,EAAE,wBAAwB,CAAC,GAAG;IACrF,aAAa,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;CACxE,CAAC;AAEF,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,kDAezF"}
@@ -0,0 +1,10 @@
1
+ import type { Plugin } from 'vite';
2
+ type Filter = RegExp | ((id: string) => boolean);
3
+ export interface ViteKTjsxOptions {
4
+ include?: Filter;
5
+ exclude?: Filter;
6
+ babelConfig?: Record<string, unknown>;
7
+ }
8
+ export declare function viteKTjsx(options?: ViteKTjsxOptions): Plugin;
9
+ export default viteKTjsx;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,KAAK,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;AAEjD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAsCD,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,CA0BhE;AAED,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "@ktjs/vite-plugin-ktjsx",
3
- "version": "0.1.2",
3
+ "description": "Vite plugin that applies KT.js JSX transforms.",
4
+ "description_zh": "用于应用 KT.js JSX 转换的 Vite 插件。",
5
+ "version": "0.2.1",
4
6
  "type": "module",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
+ "main": "dist/index.mjs",
8
+ "module": "dist/index.mjs",
7
9
  "types": "dist/index.d.ts",
8
10
  "exports": {
9
11
  ".": {
10
12
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js",
12
- "default": "./dist/index.js"
13
+ "import": "./dist/index.mjs",
14
+ "default": "./dist/index.mjs"
13
15
  }
14
16
  },
15
17
  "files": [
@@ -24,10 +26,8 @@
24
26
  "url": "https://github.com/ktjs/kt.js"
25
27
  },
26
28
  "license": "MIT",
27
- "description": "Vite plugin that applies KT.js JSX transforms.",
28
- "scripts": {
29
- "build": "node build.js",
30
- "test": "vitest run"
29
+ "dependencies": {
30
+ "@ktjs/transformer": "^*"
31
31
  },
32
32
  "devDependencies": {
33
33
  "typescript": "^5.9.3",
@@ -36,4 +36,4 @@
36
36
  "peerDependencies": {
37
37
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
38
38
  }
39
- }
39
+ }