@ktjs/vite-plugin-ktjsx 0.1.3 → 0.2.2
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 +21 -0
- package/README.md +1 -1
- package/dist/index.d.ts +12 -15
- package/dist/index.mjs +55 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +10 -10
- package/dist/index.js +0 -69422
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`
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,I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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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ktjs/vite-plugin-ktjsx",
|
|
3
|
-
"
|
|
3
|
+
"description": "Vite plugin that applies KT.js JSX transforms.",
|
|
4
|
+
"description_zh": "用于应用 KT.js JSX 转换的 Vite 插件。",
|
|
5
|
+
"version": "0.2.2",
|
|
4
6
|
"type": "module",
|
|
5
|
-
"main": "dist/index.
|
|
6
|
-
"module": "dist/index.
|
|
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.
|
|
12
|
-
"default": "./dist/index.
|
|
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
|
-
"
|
|
28
|
-
|
|
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
|
+
}
|