@ktjs/babel-plugin-ktjsx 0.1.0 → 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
@@ -1,25 +1,52 @@
1
- # babel-plugin-ktjsx
1
+ # @ktjs/babel-plugin-ktjsx
2
2
 
3
- `@ktjs/babel-plugin-ktjsx` is a Babel plugin that enhances compiled JSX output to better support SVG and namespace-aware element creation.
3
+ `@ktjs/babel-plugin-ktjsx` is the Babel entry for KT.js JSX transforms, re-exported from `@ktjs/transformer`.
4
4
 
5
- Basic usage (Babel):
5
+ Current behavior:
6
+
7
+ - add KT.js internal SVG / MathML flags on JSX elements in SVG / MathML context
8
+ - validate directive combinations (`k-if` + `k-else`, and `k-for` mixed with conditional directives)
9
+ - transform `k-for` into `source.map(...)` and remove `k-for` / `k-key` attributes
10
+ - normalize sibling `k-if` / `k-else-if` / `k-else` chains into explicit `k-if` conditions
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pnpm add -D @ktjs/babel-plugin-ktjsx @babel/core
16
+ ```
17
+
18
+ ## Usage (ESM Babel config)
6
19
 
7
20
  ```js
8
- // babel.config.js
21
+ // babel.config.mjs
22
+ import ktjsx from '@ktjs/babel-plugin-ktjsx';
23
+
24
+ export default {
25
+ plugins: [ktjsx],
26
+ };
27
+ ```
28
+
29
+ ## Usage (CommonJS Babel config)
30
+
31
+ ```js
32
+ // babel.config.cjs
33
+ const { default: ktjsx } = require('@ktjs/babel-plugin-ktjsx');
34
+
9
35
  module.exports = {
10
- plugins: [['@ktjs/babel-plugin-ktjsx', { svgTags: ['svg', 'g', 'path'] }]],
36
+ plugins: [ktjsx],
11
37
  };
12
38
  ```
13
39
 
14
- This plugin will transform calls like `createElement('svg', ...)` (or `h('svg', ...)`) into `createElementNS('http://www.w3.org/2000/svg', 'svg', ...)` so that SVG elements are created in the correct namespace.
40
+ ## Named exports
15
41
 
16
- Options:
42
+ ```ts
43
+ import { transformerKTjsx, transformWithKTjsx } from '@ktjs/babel-plugin-ktjsx';
44
+ ```
17
45
 
18
- - `svgTags` - array of tag names to treat as SVG (default includes common SVG tags)
19
- - `namespaceURI` - SVG namespace (default `http://www.w3.org/2000/svg`)
20
- - `createElementNames` - functions to consider as element factories (default `['createElement','h']`)
46
+ - `transformerKTjsx`: Babel plugin factory (same as default export)
47
+ - `transformWithKTjsx`: programmatic transform helper
21
48
 
22
- Notes:
49
+ ## Notes
23
50
 
24
- - The plugin is intended to run after JSX has been transformed to `createElement`/`h` calls. If you use a custom JSX pragma, include that name in `createElementNames`.
25
- - A Rollup wrapper can be created to run this plugin during bundling; prefer using Babel for precise AST-level transforms.
51
+ - This plugin works on JSX AST directly (not on `createElement(...)` output).
52
+ - There are no custom plugin options yet.
@@ -0,0 +1,4 @@
1
+ export { default, transformerKTjsx } from '@ktjs/transformer';
2
+ export type { KTjsxTransformOptions } from '@ktjs/transformer';
3
+ export { transformWithKTjsx } from '@ktjs/transformer';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { KTjsxTransformOptions } from '@ktjs/transformer';
2
+ export { transformWithKTjsx } from '@ktjs/transformer';
3
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/transform.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1 @@
1
- import { PluginObj } from '@babel/core';
2
-
3
- declare function babelKTjsx(): PluginObj;
4
- export default babelKTjsx;
5
-
6
- export { }
1
+ export { KTjsxTransformOptions, default, transformWithKTjsx, transformerKTjsx } from '@ktjs/transformer';