@ktjs/jsx 0.6.0
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 +442 -0
- package/babel-preset.cjs +38 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.mjs +1 -0
- package/dist/jsx-runtime.cjs +1 -0
- package/dist/jsx-runtime.d.ts +23 -0
- package/dist/jsx-runtime.mjs +1 -0
- package/package.json +65 -0
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
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
# @ktjs/jsx
|
|
2
|
+
|
|
3
|
+
<img src="https://raw.githubusercontent.com/baendlorel/kt.js/dev/.assets/ktjs-0.0.1.svg" alt="KT.js Logo" width="150"/>
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@ktjs/jsx)
|
|
6
|
+
|
|
7
|
+
> 📦 Part of [KT.js](https://github.com/baendlorel/kt.js) - JSX/TSX support for the KT.js framework
|
|
8
|
+
|
|
9
|
+
Write UI code with JSX syntax while maintaining KT.js's philosophy of direct DOM manipulation and zero unnecessary re-renders.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- ✨ **JSX/TSX Support**: Write declarative UI code with familiar JSX syntax
|
|
14
|
+
- 🎯 **Direct DOM Manipulation**: JSX compiles to direct `h()` calls, no virtual DOM
|
|
15
|
+
- 🔧 **Full TypeScript Support**: Complete type safety with IntelliSense
|
|
16
|
+
- ⚡ **Zero Runtime Overhead**: JSX is pure syntax sugar over KT.js's `h` function
|
|
17
|
+
- 🎨 **Event Handler Syntax**: Support for both function props and `@eventName` syntax
|
|
18
|
+
- 📦 **Multiple Runtime Modes**: Support both automatic and classic JSX transforms
|
|
19
|
+
- 🔌 **Easy Integration**: Works with Babel, TypeScript, and modern build tools
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @ktjs/jsx @ktjs/core
|
|
25
|
+
# or
|
|
26
|
+
npm install @ktjs/jsx @ktjs/core
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
### TypeScript Configuration
|
|
32
|
+
|
|
33
|
+
For **automatic runtime** (recommended, React 17+ style):
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
// tsconfig.json
|
|
37
|
+
{
|
|
38
|
+
"compilerOptions": {
|
|
39
|
+
"jsx": "react-jsx",
|
|
40
|
+
"jsxImportSource": "@ktjs/jsx"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
For **classic runtime** (React 16 style):
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
// tsconfig.json
|
|
49
|
+
{
|
|
50
|
+
"compilerOptions": {
|
|
51
|
+
"jsx": "react",
|
|
52
|
+
"jsxFactory": "h",
|
|
53
|
+
"jsxFragmentFactory": "Fragment"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Basic Usage
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { h } from '@ktjs/jsx';
|
|
62
|
+
|
|
63
|
+
// Simple element
|
|
64
|
+
const greeting = <div class="greeting">Hello, KT.js!</div>;
|
|
65
|
+
|
|
66
|
+
// With attributes and event handlers
|
|
67
|
+
const button = (
|
|
68
|
+
<button
|
|
69
|
+
class="btn primary"
|
|
70
|
+
@click={() => alert('Clicked!')}
|
|
71
|
+
>
|
|
72
|
+
Click me
|
|
73
|
+
</button>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// Nested elements
|
|
77
|
+
const app = (
|
|
78
|
+
<div id="app">
|
|
79
|
+
<header class="header">
|
|
80
|
+
<h1>My App</h1>
|
|
81
|
+
</header>
|
|
82
|
+
<main class="content">
|
|
83
|
+
<p>Welcome to KT.js with JSX!</p>
|
|
84
|
+
{button}
|
|
85
|
+
</main>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
document.body.appendChild(app);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Event Handlers
|
|
93
|
+
|
|
94
|
+
You can use event handlers in two ways:
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
// 1. Function props (automatically converted to event listeners)
|
|
98
|
+
<button click={() => console.log('clicked')}>Button 1</button>
|
|
99
|
+
|
|
100
|
+
// 2. @-prefixed attributes (explicit event handlers)
|
|
101
|
+
<button @click={(e) => console.log('clicked', e)}>Button 2</button>
|
|
102
|
+
|
|
103
|
+
// 3. Mix both (regular attribute + event listener)
|
|
104
|
+
<input
|
|
105
|
+
change="change-value" // Regular attribute
|
|
106
|
+
@change={(e) => console.log(e)} // Event listener
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Conditional Rendering
|
|
111
|
+
|
|
112
|
+
Use JavaScript expressions for conditional rendering:
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { ktnull } from '@ktjs/jsx';
|
|
116
|
+
|
|
117
|
+
const isLoggedIn = true;
|
|
118
|
+
|
|
119
|
+
const app = (
|
|
120
|
+
<div>
|
|
121
|
+
{isLoggedIn ? <p>Welcome back!</p> : <p>Please log in</p>}
|
|
122
|
+
|
|
123
|
+
{/* Use ktnull to render nothing */}
|
|
124
|
+
{isLoggedIn ? <button>Logout</button> : ktnull}
|
|
125
|
+
</div>
|
|
126
|
+
);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Lists
|
|
130
|
+
|
|
131
|
+
Map arrays to JSX elements:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
const items = ['Apple', 'Banana', 'Orange'];
|
|
135
|
+
|
|
136
|
+
const list = (
|
|
137
|
+
<ul>
|
|
138
|
+
{items.map((item, index) => (
|
|
139
|
+
<li key={index}>{item}</li>
|
|
140
|
+
))}
|
|
141
|
+
</ul>
|
|
142
|
+
);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Dynamic Attributes
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
const className = 'card primary';
|
|
149
|
+
const isDisabled = false;
|
|
150
|
+
|
|
151
|
+
const element = (
|
|
152
|
+
<div class={className} style="padding: 20px; background: #f0f0f0" data-disabled={isDisabled ? 'true' : 'false'}>
|
|
153
|
+
Dynamic attributes
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Advanced Usage
|
|
159
|
+
|
|
160
|
+
### Using with Babel
|
|
161
|
+
|
|
162
|
+
If you're using Babel instead of TypeScript:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
pnpm add -D @babel/plugin-transform-react-jsx
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
```javascript
|
|
169
|
+
// babel.config.js
|
|
170
|
+
module.exports = {
|
|
171
|
+
presets: [
|
|
172
|
+
[
|
|
173
|
+
'@ktjs/jsx/babel-preset',
|
|
174
|
+
{
|
|
175
|
+
runtime: 'automatic', // or 'classic'
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Classic Runtime (Manual Import)
|
|
183
|
+
|
|
184
|
+
If you prefer the classic JSX transform:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
// You need to import h in every file using JSX
|
|
188
|
+
import { h, Fragment } from '@ktjs/jsx';
|
|
189
|
+
|
|
190
|
+
const app = (
|
|
191
|
+
<div>
|
|
192
|
+
<h1>Classic Runtime</h1>
|
|
193
|
+
</div>
|
|
194
|
+
);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Fragments
|
|
198
|
+
|
|
199
|
+
**Note**: KT.js doesn't have a native Fragment concept. Fragments are wrapped in a `div` with `data-kt-fragment="true"`:
|
|
200
|
+
|
|
201
|
+
```tsx
|
|
202
|
+
import { Fragment } from '@ktjs/jsx';
|
|
203
|
+
|
|
204
|
+
const list = (
|
|
205
|
+
<>
|
|
206
|
+
<li>Item 1</li>
|
|
207
|
+
<li>Item 2</li>
|
|
208
|
+
<li>Item 3</li>
|
|
209
|
+
</>
|
|
210
|
+
);
|
|
211
|
+
// Results in: <div data-kt-fragment="true"><li>Item 1</li>...</div>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
If you want truly unwrapped children, use arrays instead:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
const items = [<li key="1">Item 1</li>, <li key="2">Item 2</li>, <li key="3">Item 3</li>];
|
|
218
|
+
|
|
219
|
+
const list = <ul>{items}</ul>;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Integration with CSS-in-JS
|
|
223
|
+
|
|
224
|
+
Works seamlessly with CSS-in-JS libraries:
|
|
225
|
+
|
|
226
|
+
```tsx
|
|
227
|
+
import { css } from '@emotion/css';
|
|
228
|
+
|
|
229
|
+
const buttonStyle = css`
|
|
230
|
+
background: blue;
|
|
231
|
+
color: white;
|
|
232
|
+
padding: 10px 20px;
|
|
233
|
+
border: none;
|
|
234
|
+
border-radius: 4px;
|
|
235
|
+
cursor: pointer;
|
|
236
|
+
|
|
237
|
+
&:hover {
|
|
238
|
+
background: darkblue;
|
|
239
|
+
}
|
|
240
|
+
`;
|
|
241
|
+
|
|
242
|
+
const button = (
|
|
243
|
+
<button class={buttonStyle} @click={() => alert('Styled!')}>
|
|
244
|
+
Styled Button
|
|
245
|
+
</button>
|
|
246
|
+
);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Creating Reusable Components
|
|
250
|
+
|
|
251
|
+
While KT.js doesn't have a component system, you can create factory functions:
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
interface CardProps {
|
|
255
|
+
title: string;
|
|
256
|
+
content: string;
|
|
257
|
+
onClose?: () => void;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function Card({ title, content, onClose }: CardProps) {
|
|
261
|
+
return (
|
|
262
|
+
<div class="card">
|
|
263
|
+
<div class="card-header">
|
|
264
|
+
<h3>{title}</h3>
|
|
265
|
+
{onClose && (
|
|
266
|
+
<button class="close" @click={onClose}>×</button>
|
|
267
|
+
)}
|
|
268
|
+
</div>
|
|
269
|
+
<div class="card-body">
|
|
270
|
+
{content}
|
|
271
|
+
</div>
|
|
272
|
+
</div>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Usage
|
|
277
|
+
const myCard = Card({
|
|
278
|
+
title: 'Hello',
|
|
279
|
+
content: 'This is a card',
|
|
280
|
+
onClose: () => console.log('Closing...')
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
document.body.appendChild(myCard);
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## API Reference
|
|
287
|
+
|
|
288
|
+
### JSX Runtime Functions
|
|
289
|
+
|
|
290
|
+
#### `jsx(tag, props, ...children)`
|
|
291
|
+
|
|
292
|
+
The main JSX transformation function. Called automatically by the JSX compiler.
|
|
293
|
+
|
|
294
|
+
**Parameters:**
|
|
295
|
+
|
|
296
|
+
- `tag` (string): HTML tag name
|
|
297
|
+
- `props` (object): Element attributes and event handlers
|
|
298
|
+
- `children` (...): Child elements
|
|
299
|
+
|
|
300
|
+
**Returns:** `HTMLElement`
|
|
301
|
+
|
|
302
|
+
#### `Fragment(props)`
|
|
303
|
+
|
|
304
|
+
Fragment component for grouping elements without a wrapper (wraps in a div with `data-kt-fragment`).
|
|
305
|
+
|
|
306
|
+
#### `h(tag, props, children)`
|
|
307
|
+
|
|
308
|
+
Classic JSX factory function, equivalent to `jsx`.
|
|
309
|
+
|
|
310
|
+
### Re-exported from @ktjs/core
|
|
311
|
+
|
|
312
|
+
- `ktnull`: Special value for conditional rendering (renders nothing)
|
|
313
|
+
|
|
314
|
+
## Type Definitions
|
|
315
|
+
|
|
316
|
+
Full TypeScript support with comprehensive JSX type definitions:
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
declare global {
|
|
320
|
+
namespace JSX {
|
|
321
|
+
type Element = HTMLElement;
|
|
322
|
+
|
|
323
|
+
interface IntrinsicElements {
|
|
324
|
+
div: KTAttribute & { children?: KTRawContent };
|
|
325
|
+
span: KTAttribute & { children?: KTRawContent };
|
|
326
|
+
// ... all HTML elements
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Comparison: JSX vs Function Calls
|
|
333
|
+
|
|
334
|
+
```tsx
|
|
335
|
+
// JSX syntax
|
|
336
|
+
const app = (
|
|
337
|
+
<div class="container">
|
|
338
|
+
<h1>Hello</h1>
|
|
339
|
+
<button @click={() => alert('Hi')}>Click</button>
|
|
340
|
+
</div>
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
// Equivalent function calls
|
|
344
|
+
import { h, div, button } from '@ktjs/core';
|
|
345
|
+
|
|
346
|
+
const app = div({ class: 'container' }, [
|
|
347
|
+
h('h1', {}, 'Hello'),
|
|
348
|
+
button({ '@click': () => alert('Hi') }, 'Click')
|
|
349
|
+
]);
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Both produce **exactly the same DOM** with **zero performance difference**. Choose the style you prefer!
|
|
353
|
+
|
|
354
|
+
## Build Tool Integration
|
|
355
|
+
|
|
356
|
+
### Vite
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
// vite.config.ts
|
|
360
|
+
import { defineConfig } from 'vite';
|
|
361
|
+
|
|
362
|
+
export default defineConfig({
|
|
363
|
+
esbuild: {
|
|
364
|
+
jsxImportSource: '@ktjs/jsx',
|
|
365
|
+
jsx: 'automatic',
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Webpack
|
|
371
|
+
|
|
372
|
+
```javascript
|
|
373
|
+
// webpack.config.js
|
|
374
|
+
module.exports = {
|
|
375
|
+
module: {
|
|
376
|
+
rules: [
|
|
377
|
+
{
|
|
378
|
+
test: /\.[jt]sx?$/,
|
|
379
|
+
exclude: /node_modules/,
|
|
380
|
+
use: {
|
|
381
|
+
loader: 'babel-loader',
|
|
382
|
+
options: {
|
|
383
|
+
presets: ['@ktjs/jsx/babel-preset'],
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### esbuild
|
|
393
|
+
|
|
394
|
+
```javascript
|
|
395
|
+
// build.js
|
|
396
|
+
import esbuild from 'esbuild';
|
|
397
|
+
|
|
398
|
+
esbuild.build({
|
|
399
|
+
entryPoints: ['src/index.tsx'],
|
|
400
|
+
bundle: true,
|
|
401
|
+
jsxImportSource: '@ktjs/jsx',
|
|
402
|
+
jsx: 'automatic',
|
|
403
|
+
outfile: 'dist/bundle.js',
|
|
404
|
+
});
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## Browser Compatibility
|
|
408
|
+
|
|
409
|
+
Same as @ktjs/core - works in all modern browsers and IE9+ (with transpilation).
|
|
410
|
+
|
|
411
|
+
## Why Use JSX with KT.js?
|
|
412
|
+
|
|
413
|
+
✅ **Familiar Syntax**: If you're coming from React, JSX feels natural
|
|
414
|
+
✅ **Better IDE Support**: Enhanced autocomplete and error checking
|
|
415
|
+
✅ **Readability**: Complex nested structures are easier to read
|
|
416
|
+
✅ **Zero Cost**: Pure compile-time transformation, no runtime overhead
|
|
417
|
+
✅ **Optional**: You can mix JSX with regular function calls
|
|
418
|
+
|
|
419
|
+
## Philosophy
|
|
420
|
+
|
|
421
|
+
`@ktjs/jsx` is purely syntactic sugar. It transforms JSX to direct `h()` function calls at compile time:
|
|
422
|
+
|
|
423
|
+
```
|
|
424
|
+
<div>Hello</div> → h('div', {}, 'Hello')
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
This means:
|
|
428
|
+
|
|
429
|
+
- **No virtual DOM** - direct DOM manipulation
|
|
430
|
+
- **No reconciliation** - you control when and what updates
|
|
431
|
+
- **No framework magic** - just JavaScript and the DOM API
|
|
432
|
+
|
|
433
|
+
## License
|
|
434
|
+
|
|
435
|
+
MIT
|
|
436
|
+
|
|
437
|
+
## Links
|
|
438
|
+
|
|
439
|
+
- [KT.js Main Repository](https://github.com/baendlorel/kt.js)
|
|
440
|
+
- [@ktjs/core](../core)
|
|
441
|
+
- [@ktjs/router](../router)
|
|
442
|
+
- [@ktjs/shortcuts](../shortcuts)
|
package/babel-preset.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Babel preset for @ktjs/jsx
|
|
3
|
+
*
|
|
4
|
+
* This preset configures Babel to transform JSX/TSX syntax
|
|
5
|
+
* to use the KT.js JSX runtime.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // babel.config.js
|
|
9
|
+
* module.exports = {
|
|
10
|
+
* presets: ['@ktjs/jsx/babel-preset']
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* @param {import('@babel/core').ConfigAPI} api
|
|
14
|
+
* @param {Object} options
|
|
15
|
+
* @param {boolean} [options.runtime='automatic'] - JSX runtime mode: 'automatic' or 'classic'
|
|
16
|
+
* @param {string} [options.importSource='@ktjs/jsx'] - Import source for automatic runtime
|
|
17
|
+
* @param {string} [options.pragma='h'] - JSX pragma for classic runtime
|
|
18
|
+
* @param {string} [options.pragmaFrag='Fragment'] - JSX fragment pragma for classic runtime
|
|
19
|
+
*/
|
|
20
|
+
module.exports = function (api, options = {}) {
|
|
21
|
+
const { runtime = 'automatic', importSource = '@ktjs/jsx', pragma = 'h', pragmaFrag = 'Fragment' } = options;
|
|
22
|
+
|
|
23
|
+
api.assertVersion(7);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
plugins: [
|
|
27
|
+
[
|
|
28
|
+
'@babel/plugin-transform-react-jsx',
|
|
29
|
+
{
|
|
30
|
+
runtime,
|
|
31
|
+
importSource: runtime === 'automatic' ? importSource : undefined,
|
|
32
|
+
pragma: runtime === 'classic' ? pragma : undefined,
|
|
33
|
+
pragmaFrag: runtime === 'classic' ? pragmaFrag : undefined,
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("@ktjs/core");function e(e,r,...n){const o="string"==typeof r?{class:r}:r;return t.h(e,o,n)}const r=e,n=e;Object.defineProperty(exports,"createElement",{enumerable:!0,get:function(){return t.h}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return t.h}}),exports.Fragment=function(e){const{children:r}=e||{};if(!r)return t.ktnull;if(!Array.isArray(r))return r;const n=document.createElement("div");return n.setAttribute("data-kt-fragment","true"),r.forEach(e=>{e&&e!==t.ktnull&&("string"==typeof e?n.appendChild(document.createTextNode(e)):e instanceof HTMLElement&&n.appendChild(e))}),n},exports.jsx=e,exports.jsxDEV=r,exports.jsxs=n;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { HTMLTag, KTRawAttr, KTRawContents, KTRawContent, ktnull, KTAttribute } from '@ktjs/core';
|
|
2
|
+
export { h as createElement, h } from '@ktjs/core';
|
|
3
|
+
|
|
4
|
+
declare function jsx<T extends HTMLTag>(tag: T, props: KTRawAttr, ...children: KTRawContents): HTMLElementTagNameMap[T];
|
|
5
|
+
/**
|
|
6
|
+
* Fragment support - returns an array of children
|
|
7
|
+
* Note: kt.js doesn't have a real Fragment concept,
|
|
8
|
+
* so we return ktnull for empty fragments or flatten children
|
|
9
|
+
*/
|
|
10
|
+
declare function Fragment(props: {
|
|
11
|
+
children?: KTRawContent;
|
|
12
|
+
}): HTMLElement | typeof ktnull;
|
|
13
|
+
/**
|
|
14
|
+
* JSX Development runtime - same as jsx but with additional dev checks
|
|
15
|
+
*/
|
|
16
|
+
declare const jsxDEV: typeof jsx;
|
|
17
|
+
/**
|
|
18
|
+
* JSX runtime for React 17+ automatic runtime
|
|
19
|
+
* This is called when using jsx: "react-jsx" or "react-jsxdev"
|
|
20
|
+
*/
|
|
21
|
+
declare const jsxs: typeof jsx;
|
|
22
|
+
|
|
23
|
+
declare global {
|
|
24
|
+
namespace JSX {
|
|
25
|
+
type Element = HTMLElementTagNameMap[keyof HTMLElementTagNameMap];
|
|
26
|
+
|
|
27
|
+
// 为常用元素提供更精确的类型
|
|
28
|
+
interface IntrinsicElements {
|
|
29
|
+
[tag: string]: KTAttribute & { children?: KTRawContent };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface IntrinsicAttributes {
|
|
33
|
+
key?: string | number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ElementChildrenAttribute {
|
|
37
|
+
children: {};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { Fragment, jsx, jsxDEV, jsxs };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as t,ktnull as r}from"@ktjs/core";export{h as createElement,h}from"@ktjs/core";function e(r,e,...n){return t(r,"string"==typeof e?{class:e}:e,n)}function n(t){const{children:e}=t||{};if(!e)return r;if(!Array.isArray(e))return e;const n=document.createElement("div");return n.setAttribute("data-kt-fragment","true"),e.forEach(t=>{t&&t!==r&&("string"==typeof t?n.appendChild(document.createTextNode(t)):t instanceof HTMLElement&&n.appendChild(t))}),n}const o=e,c=e;export{n as Fragment,e as jsx,o as jsxDEV,c as jsxs};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("@ktjs/core");function e(e,r,...n){const o="string"==typeof r?{class:r}:r;return t.h(e,o,n)}const r=e,n=e;Object.defineProperty(exports,"createElement",{enumerable:!0,get:function(){return t.h}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return t.h}}),exports.Fragment=function(e){const{children:r}=e||{};if(!r)return t.ktnull;if(!Array.isArray(r))return r;const n=document.createElement("div");return n.setAttribute("data-kt-fragment","true"),r.forEach(e=>{e&&e!==t.ktnull&&("string"==typeof e?n.appendChild(document.createTextNode(e)):e instanceof HTMLElement&&n.appendChild(e))}),n},exports.jsx=e,exports.jsxDEV=r,exports.jsxs=n;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HTMLTag, KTRawAttr, KTRawContents, KTRawContent, ktnull } from '@ktjs/core';
|
|
2
|
+
export { h as createElement, h } from '@ktjs/core';
|
|
3
|
+
|
|
4
|
+
declare function jsx<T extends HTMLTag>(tag: T, props: KTRawAttr, ...children: KTRawContents): HTMLElementTagNameMap[T];
|
|
5
|
+
/**
|
|
6
|
+
* Fragment support - returns an array of children
|
|
7
|
+
* Note: kt.js doesn't have a real Fragment concept,
|
|
8
|
+
* so we return ktnull for empty fragments or flatten children
|
|
9
|
+
*/
|
|
10
|
+
declare function Fragment(props: {
|
|
11
|
+
children?: KTRawContent;
|
|
12
|
+
}): HTMLElement | typeof ktnull;
|
|
13
|
+
/**
|
|
14
|
+
* JSX Development runtime - same as jsx but with additional dev checks
|
|
15
|
+
*/
|
|
16
|
+
declare const jsxDEV: typeof jsx;
|
|
17
|
+
/**
|
|
18
|
+
* JSX runtime for React 17+ automatic runtime
|
|
19
|
+
* This is called when using jsx: "react-jsx" or "react-jsxdev"
|
|
20
|
+
*/
|
|
21
|
+
declare const jsxs: typeof jsx;
|
|
22
|
+
|
|
23
|
+
export { Fragment, jsx, jsxDEV, jsxs };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as t,ktnull as r}from"@ktjs/core";export{h as createElement,h}from"@ktjs/core";function e(r,e,...n){return t(r,"string"==typeof e?{class:e}:e,n)}function n(t){const{children:e}=t||{};if(!e)return r;if(!Array.isArray(e))return e;const n=document.createElement("div");return n.setAttribute("data-kt-fragment","true"),e.forEach(t=>{t&&t!==r&&("string"==typeof t?n.appendChild(document.createTextNode(t)):t instanceof HTMLElement&&n.appendChild(t))}),n}const o=e,c=e;export{n as Fragment,e as jsx,o as jsxDEV,c as jsxs};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ktjs/jsx",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "JSX/TSX support for KT.js - Build UIs with JSX syntax while keeping direct DOM control",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Kasukabe Tsumugi",
|
|
7
|
+
"email": "futami16237@gmail.com"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.mjs",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./jsx-runtime": {
|
|
21
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
22
|
+
"import": "./dist/jsx-runtime.mjs",
|
|
23
|
+
"require": "./dist/jsx-runtime.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./jsx-dev-runtime": {
|
|
26
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
27
|
+
"import": "./dist/jsx-runtime.mjs",
|
|
28
|
+
"require": "./dist/jsx-runtime.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./babel-preset": {
|
|
31
|
+
"require": "./babel-preset.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"babel-preset.cjs",
|
|
37
|
+
"README.md",
|
|
38
|
+
"LICENSE"
|
|
39
|
+
],
|
|
40
|
+
"keywords": [
|
|
41
|
+
"ktjs",
|
|
42
|
+
"jsx",
|
|
43
|
+
"tsx",
|
|
44
|
+
"react-jsx",
|
|
45
|
+
"dom",
|
|
46
|
+
"typescript"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/baendlorel/kt.js",
|
|
51
|
+
"directory": "packages/jsx"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@ktjs/core": "^0.5.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@ktjs/core": "0.6.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "rollup -c rollup.config.mjs",
|
|
61
|
+
"dev": "rollup -c rollup.config.mjs -w",
|
|
62
|
+
"check": "tsc --noEmit",
|
|
63
|
+
"test": "vitest"
|
|
64
|
+
}
|
|
65
|
+
}
|