sygnal 4.1.1 → 4.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/README.md CHANGED
@@ -186,13 +186,23 @@ For Vite:
186
186
  // vite.config.js
187
187
  export default defineConfig({
188
188
  esbuild: {
189
- jsxInject: `import { jsx, Fragment } from 'sygnal/jsx'`,
190
- jsxFactory: 'jsx',
191
- jsxFragment: 'Fragment'
189
+ jsx: 'automatic',
190
+ jsxImportSource: 'sygnal',
192
191
  }
193
192
  })
194
193
  ```
195
194
 
195
+ For TypeScript projects, also add to `tsconfig.json`:
196
+
197
+ ```json
198
+ {
199
+ "compilerOptions": {
200
+ "jsx": "react-jsx",
201
+ "jsxImportSource": "sygnal"
202
+ }
203
+ }
204
+ ```
205
+
196
206
  Without JSX, use `h()`:
197
207
 
198
208
  ```javascript
@@ -16,8 +16,8 @@ function sygnalAstroIntegration() {
16
16
  updateConfig({
17
17
  vite: {
18
18
  esbuild: {
19
- jsxFactory: 'jsx',
20
- jsxInject: `import { jsx } from 'sygnal/jsx'`,
19
+ jsx: 'automatic',
20
+ jsxImportSource: 'sygnal',
21
21
  },
22
22
  },
23
23
  });
@@ -14,8 +14,8 @@ function sygnalAstroIntegration() {
14
14
  updateConfig({
15
15
  vite: {
16
16
  esbuild: {
17
- jsxFactory: 'jsx',
18
- jsxInject: `import { jsx } from 'sygnal/jsx'`,
17
+ jsx: 'automatic',
18
+ jsxImportSource: 'sygnal',
19
19
  },
20
20
  },
21
21
  });
@@ -0,0 +1,308 @@
1
+ 'use strict';
2
+
3
+ var _extend = require('extend');
4
+
5
+ const undefinedv = (v) => v === undefined;
6
+
7
+ const number = (v) => typeof v === 'number';
8
+
9
+ const string = (v) => typeof v === 'string';
10
+
11
+ const text = (v) => string(v) || number(v);
12
+
13
+ const array = (v) => Array.isArray(v);
14
+
15
+ const object = (v) => typeof v === 'object' && v !== null;
16
+
17
+ const fun = (v) => typeof v === 'function';
18
+
19
+ const vnode$1 = (v) => object(v) && 'sel' in v && 'data' in v && 'children' in v && 'text' in v;
20
+
21
+ const svgPropsMap = {
22
+ // Container / structural
23
+ svg: 1, g: 1, defs: 1, symbol: 1, use: 1,
24
+ // Shape
25
+ circle: 1, ellipse: 1, line: 1, path: 1, polygon: 1, polyline: 1, rect: 1,
26
+ // Text (no HTML collision: HTML has no <text>, <tspan>, or <textPath>)
27
+ text: 1, tspan: 1, textPath: 1,
28
+ // Gradient / paint
29
+ linearGradient: 1, radialGradient: 1, stop: 1, pattern: 1,
30
+ // Clipping / masking
31
+ clipPath: 1, mask: 1,
32
+ // Marker
33
+ marker: 1,
34
+ // Filter primitives
35
+ filter: 1, feBlend: 1, feColorMatrix: 1, feComponentTransfer: 1,
36
+ feComposite: 1, feConvolveMatrix: 1, feDiffuseLighting: 1,
37
+ feDisplacementMap: 1, feDropShadow: 1, feFlood: 1, feGaussianBlur: 1,
38
+ feImage: 1, feMerge: 1, feMergeNode: 1, feMorphology: 1, feOffset: 1,
39
+ fePointLight: 1, feSpecularLighting: 1, feSpotLight: 1, feTile: 1,
40
+ feTurbulence: 1, feFuncR: 1, feFuncG: 1, feFuncB: 1, feFuncA: 1,
41
+ // Descriptive (excluding 'title' — collides with HTML <title>)
42
+ desc: 1, metadata: 1,
43
+ // Other (excluding 'a', 'image', 'style', 'script' — collide with HTML)
44
+ foreignObject: 1, switch: 1,
45
+ // Animation
46
+ animate: 1, animateMotion: 1, animateTransform: 1, set: 1, mpath: 1,
47
+ };
48
+
49
+ const svg = (v) => v.sel in svgPropsMap;
50
+
51
+ // TODO: stop using extend here
52
+
53
+ const extend = (...objs) => _extend(true, ...objs);
54
+
55
+ const assign = (...objs) => _extend(false, ...objs);
56
+
57
+ const reduceDeep = (arr, fn, initial) => {
58
+ let result = initial;
59
+ for (let i = 0; i < arr.length; i++) {
60
+ const value = arr[i];
61
+ if (array(value)) {
62
+ result = reduceDeep(value, fn, result);
63
+ } else {
64
+ result = fn(result, value);
65
+ }
66
+ }
67
+ return result
68
+ };
69
+
70
+ const mapObject = (obj, fn) => Object.keys(obj).map(
71
+ (key) => fn(key, obj[key])
72
+ ).reduce(
73
+ (acc, curr) => extend(acc, curr),
74
+ {}
75
+ );
76
+
77
+ const deepifyKeys = (obj, modules) => mapObject(obj,
78
+ (key, val) => {
79
+ const dashIndex = key.indexOf('-');
80
+ if (dashIndex > -1 && modules[key.slice(0, dashIndex)] !== undefined) {
81
+ const moduleData = {
82
+ [key.slice(dashIndex + 1)]: val
83
+ };
84
+ return {
85
+ [key.slice(0, dashIndex)]: moduleData
86
+ }
87
+ }
88
+ return { [key]: val }
89
+ }
90
+ );
91
+
92
+ const omit = (key, obj) => mapObject(obj,
93
+ (mod, data) => mod !== key ? ({ [mod]: data }) : {}
94
+ );
95
+
96
+ // Const fnName = (...params) => guard ? default : ...
97
+
98
+ const createTextElement = (text$1) => !text(text$1) ? undefined : {
99
+ text: text$1,
100
+ sel: undefined,
101
+ data: undefined,
102
+ children: undefined,
103
+ elm: undefined,
104
+ key: undefined
105
+ };
106
+
107
+ const applySvg = (vnode) => {
108
+ // Skip text vnodes (sel is undefined) and nullish values
109
+ if (!vnode || undefinedv(vnode.sel)) return vnode
110
+
111
+ const data = vnode.data || {};
112
+ const props = data.props || {};
113
+ const propsWithoutClassName = omit('className', props);
114
+ const classAttr = props.className !== undefined ? { class: props.className } : {};
115
+ const mergedAttrs = assign({}, propsWithoutClassName, classAttr, data.attrs || {});
116
+
117
+ return assign(vnode,
118
+ { data: omit('props', assign({}, data,
119
+ { ns: 'http://www.w3.org/2000/svg', attrs: mergedAttrs }
120
+ )) },
121
+ // foreignObject contains HTML, not SVG — do not recurse into its children
122
+ { children: (!Array.isArray(vnode.children) || vnode.sel === 'foreignObject')
123
+ ? vnode.children
124
+ : vnode.children.map((child) => applySvg(child))
125
+ }
126
+ )
127
+ };
128
+
129
+ const considerSvg = (vnode) => !svg(vnode) ? vnode : applySvg(vnode);
130
+
131
+ const rewrites = {
132
+ for: 'attrs',
133
+ role: 'attrs',
134
+ tabindex: 'attrs',
135
+ 'aria-*': 'attrs',
136
+ key: null
137
+ };
138
+
139
+ const rewriteModules = (data, modules) => mapObject(data, (key, val) => {
140
+ const inner = { [key]: val };
141
+ if (rewrites[key] && modules[rewrites[key]] !== undefined) {
142
+ return { [rewrites[key]]: inner }
143
+ }
144
+ if (rewrites[key] === null) {
145
+ return {}
146
+ }
147
+ const keys = Object.keys(rewrites);
148
+ for (let i = 0; i < keys.length; i++) {
149
+ const k = keys[i];
150
+ if (k.charAt(k.length - 1) === '*' && key.indexOf(k.slice(0, -1)) === 0 && modules[rewrites[k]] !== undefined) {
151
+ return { [rewrites[k]]: inner }
152
+ }
153
+ }
154
+ if (modules[key] !== undefined) {
155
+ return { [modules[key] ? modules[key] : key]: val }
156
+ }
157
+ if (modules.props !== undefined) {
158
+ return { props: inner }
159
+ }
160
+ return inner
161
+ });
162
+
163
+ const applyFocusProps = (data) => {
164
+ if (!data.props) return data
165
+ const { autoFocus, autoSelect, ...rest } = data.props;
166
+ if (!autoFocus && !autoSelect) return data
167
+
168
+ data.props = rest;
169
+ const existingInsert = data.hook?.insert;
170
+ data.hook = {
171
+ ...data.hook,
172
+ insert: (vnode) => {
173
+ if (existingInsert) existingInsert(vnode);
174
+ if (vnode.elm && typeof vnode.elm.focus === 'function') {
175
+ vnode.elm.focus();
176
+ if (autoSelect && typeof vnode.elm.select === 'function') {
177
+ vnode.elm.select();
178
+ }
179
+ }
180
+ },
181
+ };
182
+ return data
183
+ };
184
+
185
+ const sanitizeData = (data, modules) => applyFocusProps(rewriteModules(deepifyKeys(data, modules), modules));
186
+
187
+ const sanitizeText = (children) => children.length > 1 || !text(children[0]) ? undefined : children[0].toString();
188
+
189
+ const sanitizeChildren = (children) => reduceDeep(children, (acc, child) => {
190
+ const vnode = vnode$1(child) ? child : createTextElement(child);
191
+ acc.push(vnode);
192
+ return acc
193
+ }
194
+ , []);
195
+
196
+ const defaultModules = {
197
+ attrs: '',
198
+ props: '',
199
+ class: '',
200
+ data: 'dataset',
201
+ style: '',
202
+ hook: '',
203
+ on: ''
204
+ };
205
+
206
+ const createElementWithModules = (modules) => {
207
+ return (sel, data, ...children) => {
208
+ if (typeof sel === 'undefined') {
209
+ sel = 'UNDEFINED';
210
+ console.error('JSX Error: Capitalized HTML element without corresponding factory function. Components with names where the first letter is capital MUST be defined or included at the parent component\'s file scope.');
211
+ }
212
+ if (fun(sel)) {
213
+ if (sel.name === 'Fragment') {
214
+ return sel(data || {}, children)
215
+ }
216
+ data ||= {};
217
+ if (!sel.isSygnalComponent) {
218
+ const name = sel.componentName || sel.label || sel.name || 'FUNCTION_COMPONENT';
219
+ const view = sel;
220
+ const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug, preventInstantiation } = sel;
221
+ if (preventInstantiation) {
222
+ const text = sanitizeText(children);
223
+ return considerSvg({
224
+ sel: name,
225
+ data: data ? sanitizeData(data, modules) : {},
226
+ children: typeof text !== 'undefined' ? createTextElement(text) : sanitizeChildren(children),
227
+ text,
228
+ elm: undefined,
229
+ key: data ? data.key : undefined
230
+ })
231
+ }
232
+ const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug };
233
+ data.sygnalOptions = options;
234
+ sel = name;
235
+ } else {
236
+ const factory = sel;
237
+ sel = sel.componentName || sel.label || sel.name || 'sygnal-factory';
238
+ data.sygnalFactory = factory;
239
+ }
240
+ }
241
+ const text = sanitizeText(children);
242
+ return considerSvg({
243
+ sel,
244
+ data: data ? sanitizeData(data, modules) : {},
245
+ children: typeof text !== 'undefined' ? createTextElement(text) : sanitizeChildren(children),
246
+ text,
247
+ elm: undefined,
248
+ key: data ? data.key : undefined
249
+ })
250
+ }
251
+ };
252
+
253
+ const createElement = createElementWithModules(defaultModules);
254
+
255
+ function vnode(sel, data, children, text, elm) {
256
+ const key = data === undefined ? undefined : data.key;
257
+ return { sel, data, children, text, elm, key };
258
+ }
259
+
260
+ /* eslint-disable @typescript-eslint/no-namespace, import/export */
261
+ function Fragment(data, ...children) {
262
+ const flatChildren = flattenAndFilter(children, []);
263
+ if (flatChildren.length === 1 &&
264
+ !flatChildren[0].sel &&
265
+ flatChildren[0].text) {
266
+ // only child is a simple text node, pass as text for a simpler vtree
267
+ return vnode(undefined, undefined, undefined, flatChildren[0].text, undefined);
268
+ }
269
+ else {
270
+ return vnode(undefined, data !== null && data !== void 0 ? data : {}, flatChildren, undefined, undefined);
271
+ }
272
+ }
273
+ function flattenAndFilter(children, flattened) {
274
+ for (const child of children) {
275
+ // filter out falsey children, except 0 since zero can be a valid value e.g inside a chart
276
+ if (child !== undefined &&
277
+ child !== null &&
278
+ child !== false &&
279
+ child !== "") {
280
+ if (Array.isArray(child)) {
281
+ flattenAndFilter(child, flattened);
282
+ }
283
+ else if (typeof child === "string" ||
284
+ typeof child === "number" ||
285
+ typeof child === "boolean") {
286
+ flattened.push(vnode(undefined, undefined, undefined, String(child), undefined));
287
+ }
288
+ else {
289
+ flattened.push(child);
290
+ }
291
+ }
292
+ }
293
+ return flattened;
294
+ }
295
+
296
+ function jsx(type, props, key) {
297
+ if (props == null) return createElement(type, null)
298
+ const { children, ...rest } = props;
299
+ if (key !== undefined) rest.key = key;
300
+ if (children === undefined) return createElement(type, rest)
301
+ if (Array.isArray(children)) return createElement(type, rest, ...children)
302
+ return createElement(type, rest, children)
303
+ }
304
+
305
+ exports.Fragment = Fragment;
306
+ exports.jsx = jsx;
307
+ exports.jsxDEV = jsx;
308
+ exports.jsxs = jsx;
@@ -0,0 +1,303 @@
1
+ import _extend from 'extend';
2
+
3
+ const undefinedv = (v) => v === undefined;
4
+
5
+ const number = (v) => typeof v === 'number';
6
+
7
+ const string = (v) => typeof v === 'string';
8
+
9
+ const text = (v) => string(v) || number(v);
10
+
11
+ const array = (v) => Array.isArray(v);
12
+
13
+ const object = (v) => typeof v === 'object' && v !== null;
14
+
15
+ const fun = (v) => typeof v === 'function';
16
+
17
+ const vnode$1 = (v) => object(v) && 'sel' in v && 'data' in v && 'children' in v && 'text' in v;
18
+
19
+ const svgPropsMap = {
20
+ // Container / structural
21
+ svg: 1, g: 1, defs: 1, symbol: 1, use: 1,
22
+ // Shape
23
+ circle: 1, ellipse: 1, line: 1, path: 1, polygon: 1, polyline: 1, rect: 1,
24
+ // Text (no HTML collision: HTML has no <text>, <tspan>, or <textPath>)
25
+ text: 1, tspan: 1, textPath: 1,
26
+ // Gradient / paint
27
+ linearGradient: 1, radialGradient: 1, stop: 1, pattern: 1,
28
+ // Clipping / masking
29
+ clipPath: 1, mask: 1,
30
+ // Marker
31
+ marker: 1,
32
+ // Filter primitives
33
+ filter: 1, feBlend: 1, feColorMatrix: 1, feComponentTransfer: 1,
34
+ feComposite: 1, feConvolveMatrix: 1, feDiffuseLighting: 1,
35
+ feDisplacementMap: 1, feDropShadow: 1, feFlood: 1, feGaussianBlur: 1,
36
+ feImage: 1, feMerge: 1, feMergeNode: 1, feMorphology: 1, feOffset: 1,
37
+ fePointLight: 1, feSpecularLighting: 1, feSpotLight: 1, feTile: 1,
38
+ feTurbulence: 1, feFuncR: 1, feFuncG: 1, feFuncB: 1, feFuncA: 1,
39
+ // Descriptive (excluding 'title' — collides with HTML <title>)
40
+ desc: 1, metadata: 1,
41
+ // Other (excluding 'a', 'image', 'style', 'script' — collide with HTML)
42
+ foreignObject: 1, switch: 1,
43
+ // Animation
44
+ animate: 1, animateMotion: 1, animateTransform: 1, set: 1, mpath: 1,
45
+ };
46
+
47
+ const svg = (v) => v.sel in svgPropsMap;
48
+
49
+ // TODO: stop using extend here
50
+
51
+ const extend = (...objs) => _extend(true, ...objs);
52
+
53
+ const assign = (...objs) => _extend(false, ...objs);
54
+
55
+ const reduceDeep = (arr, fn, initial) => {
56
+ let result = initial;
57
+ for (let i = 0; i < arr.length; i++) {
58
+ const value = arr[i];
59
+ if (array(value)) {
60
+ result = reduceDeep(value, fn, result);
61
+ } else {
62
+ result = fn(result, value);
63
+ }
64
+ }
65
+ return result
66
+ };
67
+
68
+ const mapObject = (obj, fn) => Object.keys(obj).map(
69
+ (key) => fn(key, obj[key])
70
+ ).reduce(
71
+ (acc, curr) => extend(acc, curr),
72
+ {}
73
+ );
74
+
75
+ const deepifyKeys = (obj, modules) => mapObject(obj,
76
+ (key, val) => {
77
+ const dashIndex = key.indexOf('-');
78
+ if (dashIndex > -1 && modules[key.slice(0, dashIndex)] !== undefined) {
79
+ const moduleData = {
80
+ [key.slice(dashIndex + 1)]: val
81
+ };
82
+ return {
83
+ [key.slice(0, dashIndex)]: moduleData
84
+ }
85
+ }
86
+ return { [key]: val }
87
+ }
88
+ );
89
+
90
+ const omit = (key, obj) => mapObject(obj,
91
+ (mod, data) => mod !== key ? ({ [mod]: data }) : {}
92
+ );
93
+
94
+ // Const fnName = (...params) => guard ? default : ...
95
+
96
+ const createTextElement = (text$1) => !text(text$1) ? undefined : {
97
+ text: text$1,
98
+ sel: undefined,
99
+ data: undefined,
100
+ children: undefined,
101
+ elm: undefined,
102
+ key: undefined
103
+ };
104
+
105
+ const applySvg = (vnode) => {
106
+ // Skip text vnodes (sel is undefined) and nullish values
107
+ if (!vnode || undefinedv(vnode.sel)) return vnode
108
+
109
+ const data = vnode.data || {};
110
+ const props = data.props || {};
111
+ const propsWithoutClassName = omit('className', props);
112
+ const classAttr = props.className !== undefined ? { class: props.className } : {};
113
+ const mergedAttrs = assign({}, propsWithoutClassName, classAttr, data.attrs || {});
114
+
115
+ return assign(vnode,
116
+ { data: omit('props', assign({}, data,
117
+ { ns: 'http://www.w3.org/2000/svg', attrs: mergedAttrs }
118
+ )) },
119
+ // foreignObject contains HTML, not SVG — do not recurse into its children
120
+ { children: (!Array.isArray(vnode.children) || vnode.sel === 'foreignObject')
121
+ ? vnode.children
122
+ : vnode.children.map((child) => applySvg(child))
123
+ }
124
+ )
125
+ };
126
+
127
+ const considerSvg = (vnode) => !svg(vnode) ? vnode : applySvg(vnode);
128
+
129
+ const rewrites = {
130
+ for: 'attrs',
131
+ role: 'attrs',
132
+ tabindex: 'attrs',
133
+ 'aria-*': 'attrs',
134
+ key: null
135
+ };
136
+
137
+ const rewriteModules = (data, modules) => mapObject(data, (key, val) => {
138
+ const inner = { [key]: val };
139
+ if (rewrites[key] && modules[rewrites[key]] !== undefined) {
140
+ return { [rewrites[key]]: inner }
141
+ }
142
+ if (rewrites[key] === null) {
143
+ return {}
144
+ }
145
+ const keys = Object.keys(rewrites);
146
+ for (let i = 0; i < keys.length; i++) {
147
+ const k = keys[i];
148
+ if (k.charAt(k.length - 1) === '*' && key.indexOf(k.slice(0, -1)) === 0 && modules[rewrites[k]] !== undefined) {
149
+ return { [rewrites[k]]: inner }
150
+ }
151
+ }
152
+ if (modules[key] !== undefined) {
153
+ return { [modules[key] ? modules[key] : key]: val }
154
+ }
155
+ if (modules.props !== undefined) {
156
+ return { props: inner }
157
+ }
158
+ return inner
159
+ });
160
+
161
+ const applyFocusProps = (data) => {
162
+ if (!data.props) return data
163
+ const { autoFocus, autoSelect, ...rest } = data.props;
164
+ if (!autoFocus && !autoSelect) return data
165
+
166
+ data.props = rest;
167
+ const existingInsert = data.hook?.insert;
168
+ data.hook = {
169
+ ...data.hook,
170
+ insert: (vnode) => {
171
+ if (existingInsert) existingInsert(vnode);
172
+ if (vnode.elm && typeof vnode.elm.focus === 'function') {
173
+ vnode.elm.focus();
174
+ if (autoSelect && typeof vnode.elm.select === 'function') {
175
+ vnode.elm.select();
176
+ }
177
+ }
178
+ },
179
+ };
180
+ return data
181
+ };
182
+
183
+ const sanitizeData = (data, modules) => applyFocusProps(rewriteModules(deepifyKeys(data, modules), modules));
184
+
185
+ const sanitizeText = (children) => children.length > 1 || !text(children[0]) ? undefined : children[0].toString();
186
+
187
+ const sanitizeChildren = (children) => reduceDeep(children, (acc, child) => {
188
+ const vnode = vnode$1(child) ? child : createTextElement(child);
189
+ acc.push(vnode);
190
+ return acc
191
+ }
192
+ , []);
193
+
194
+ const defaultModules = {
195
+ attrs: '',
196
+ props: '',
197
+ class: '',
198
+ data: 'dataset',
199
+ style: '',
200
+ hook: '',
201
+ on: ''
202
+ };
203
+
204
+ const createElementWithModules = (modules) => {
205
+ return (sel, data, ...children) => {
206
+ if (typeof sel === 'undefined') {
207
+ sel = 'UNDEFINED';
208
+ console.error('JSX Error: Capitalized HTML element without corresponding factory function. Components with names where the first letter is capital MUST be defined or included at the parent component\'s file scope.');
209
+ }
210
+ if (fun(sel)) {
211
+ if (sel.name === 'Fragment') {
212
+ return sel(data || {}, children)
213
+ }
214
+ data ||= {};
215
+ if (!sel.isSygnalComponent) {
216
+ const name = sel.componentName || sel.label || sel.name || 'FUNCTION_COMPONENT';
217
+ const view = sel;
218
+ const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug, preventInstantiation } = sel;
219
+ if (preventInstantiation) {
220
+ const text = sanitizeText(children);
221
+ return considerSvg({
222
+ sel: name,
223
+ data: data ? sanitizeData(data, modules) : {},
224
+ children: typeof text !== 'undefined' ? createTextElement(text) : sanitizeChildren(children),
225
+ text,
226
+ elm: undefined,
227
+ key: data ? data.key : undefined
228
+ })
229
+ }
230
+ const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug };
231
+ data.sygnalOptions = options;
232
+ sel = name;
233
+ } else {
234
+ const factory = sel;
235
+ sel = sel.componentName || sel.label || sel.name || 'sygnal-factory';
236
+ data.sygnalFactory = factory;
237
+ }
238
+ }
239
+ const text = sanitizeText(children);
240
+ return considerSvg({
241
+ sel,
242
+ data: data ? sanitizeData(data, modules) : {},
243
+ children: typeof text !== 'undefined' ? createTextElement(text) : sanitizeChildren(children),
244
+ text,
245
+ elm: undefined,
246
+ key: data ? data.key : undefined
247
+ })
248
+ }
249
+ };
250
+
251
+ const createElement = createElementWithModules(defaultModules);
252
+
253
+ function vnode(sel, data, children, text, elm) {
254
+ const key = data === undefined ? undefined : data.key;
255
+ return { sel, data, children, text, elm, key };
256
+ }
257
+
258
+ /* eslint-disable @typescript-eslint/no-namespace, import/export */
259
+ function Fragment(data, ...children) {
260
+ const flatChildren = flattenAndFilter(children, []);
261
+ if (flatChildren.length === 1 &&
262
+ !flatChildren[0].sel &&
263
+ flatChildren[0].text) {
264
+ // only child is a simple text node, pass as text for a simpler vtree
265
+ return vnode(undefined, undefined, undefined, flatChildren[0].text, undefined);
266
+ }
267
+ else {
268
+ return vnode(undefined, data !== null && data !== void 0 ? data : {}, flatChildren, undefined, undefined);
269
+ }
270
+ }
271
+ function flattenAndFilter(children, flattened) {
272
+ for (const child of children) {
273
+ // filter out falsey children, except 0 since zero can be a valid value e.g inside a chart
274
+ if (child !== undefined &&
275
+ child !== null &&
276
+ child !== false &&
277
+ child !== "") {
278
+ if (Array.isArray(child)) {
279
+ flattenAndFilter(child, flattened);
280
+ }
281
+ else if (typeof child === "string" ||
282
+ typeof child === "number" ||
283
+ typeof child === "boolean") {
284
+ flattened.push(vnode(undefined, undefined, undefined, String(child), undefined));
285
+ }
286
+ else {
287
+ flattened.push(child);
288
+ }
289
+ }
290
+ }
291
+ return flattened;
292
+ }
293
+
294
+ function jsx(type, props, key) {
295
+ if (props == null) return createElement(type, null)
296
+ const { children, ...rest } = props;
297
+ if (key !== undefined) rest.key = key;
298
+ if (children === undefined) return createElement(type, rest)
299
+ if (Array.isArray(children)) return createElement(type, rest, ...children)
300
+ return createElement(type, rest, children)
301
+ }
302
+
303
+ export { Fragment, jsx, jsx as jsxDEV, jsx as jsxs };