arche 0.3.10 → 0.3.11
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 +114 -19
- package/es.js +383 -162
- package/index.js +383 -162
- package/index.mjs +383 -162
- package/package.json +1 -1
- package/test.html +52 -10
- package/test.js +13 -6
package/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Arche v0.3.
|
|
2
|
+
* Arche v0.3.11
|
|
3
3
|
* https://github.com/richytong/arche
|
|
4
4
|
* (c) 2020-2023 Richard Tong
|
|
5
5
|
* Arche may be freely distributed under the MIT license.
|
|
@@ -86,27 +86,37 @@ const memoizeCappedWithResolver = function (func, cap, resolver) {
|
|
|
86
86
|
*
|
|
87
87
|
* @synopsis
|
|
88
88
|
* ```coffeescript [specscript]
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
89
|
+
* creator {
|
|
90
|
+
* createElement: (
|
|
91
|
+
* elementType string,
|
|
92
|
+
* props? object,
|
|
93
|
+
* children? Array<creator.Element>
|
|
94
|
+
* )=>creator.Element
|
|
95
|
+
* }
|
|
96
96
|
*
|
|
97
|
-
* creatorCreateElement(
|
|
97
|
+
* creatorCreateElement(
|
|
98
|
+
* creator,
|
|
99
|
+
* elementType string|function,
|
|
100
|
+
* propsOrTextOrChildren object|string|Array,
|
|
101
|
+
* textOrChildren string|Array,
|
|
102
|
+
* ) -> creator.Element
|
|
98
103
|
* ```
|
|
99
104
|
*/
|
|
100
|
-
|
|
105
|
+
function creatorCreateElement(
|
|
106
|
+
creator,
|
|
107
|
+
elementType,
|
|
108
|
+
propsOrTextOrChildren,
|
|
109
|
+
textOrChildren
|
|
110
|
+
) {
|
|
101
111
|
if (creator.createElement.length == 1) {
|
|
102
|
-
const element = creator.createElement(
|
|
103
|
-
for (const key in
|
|
104
|
-
elementSetAttribute(element, key,
|
|
112
|
+
const element = creator.createElement(elementType) // document.createElement
|
|
113
|
+
for (const key in propsOrTextOrChildren) {
|
|
114
|
+
elementSetAttribute(element, key, propsOrTextOrChildren[key])
|
|
105
115
|
}
|
|
106
|
-
const childrenLength =
|
|
116
|
+
const childrenLength = textOrChildren.length
|
|
107
117
|
let childrenIndex = -1
|
|
108
118
|
while (++childrenIndex < childrenLength) {
|
|
109
|
-
const child =
|
|
119
|
+
const child = textOrChildren[childrenIndex]
|
|
110
120
|
if (typeof child == 'string') {
|
|
111
121
|
element.appendChild(creator.createTextNode(child))
|
|
112
122
|
} else {
|
|
@@ -115,7 +125,312 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
115
125
|
}
|
|
116
126
|
return element
|
|
117
127
|
}
|
|
118
|
-
|
|
128
|
+
|
|
129
|
+
return creator.createElement(
|
|
130
|
+
elementType,
|
|
131
|
+
propsOrTextOrChildren,
|
|
132
|
+
...textOrChildren
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @name CreatorElement
|
|
138
|
+
*
|
|
139
|
+
* @synopsis
|
|
140
|
+
* ```coffeescript [specscript]
|
|
141
|
+
* CreatorElement(
|
|
142
|
+
* creator {
|
|
143
|
+
* createElement: (
|
|
144
|
+
* elementType string,
|
|
145
|
+
* props? object,
|
|
146
|
+
* children? Array<creator.Element>
|
|
147
|
+
* )=>creator.Element
|
|
148
|
+
* },
|
|
149
|
+
* elementType string,
|
|
150
|
+
* propsOrTextOrChildren object|string|Array,
|
|
151
|
+
* textOrChildren string|Array,
|
|
152
|
+
* )
|
|
153
|
+
* -> creator.Element
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
function CreatorElement(
|
|
157
|
+
creator,
|
|
158
|
+
elementType,
|
|
159
|
+
propsOrTextOrChildren,
|
|
160
|
+
textOrChildren
|
|
161
|
+
) {
|
|
162
|
+
if (isArray(propsOrTextOrChildren)) {
|
|
163
|
+
return creatorCreateElement(
|
|
164
|
+
creator,
|
|
165
|
+
elementType,
|
|
166
|
+
{},
|
|
167
|
+
propsOrTextOrChildren
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (typeof propsOrTextOrChildren == 'string') {
|
|
172
|
+
return creatorCreateElement(
|
|
173
|
+
creator,
|
|
174
|
+
elementType,
|
|
175
|
+
{},
|
|
176
|
+
[propsOrTextOrChildren]
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (isArray(textOrChildren)) {
|
|
181
|
+
return creatorCreateElement(
|
|
182
|
+
creator,
|
|
183
|
+
elementType,
|
|
184
|
+
propsOrTextOrChildren,
|
|
185
|
+
textOrChildren
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (textOrChildren == null) {
|
|
190
|
+
return creatorCreateElement(
|
|
191
|
+
creator,
|
|
192
|
+
elementType,
|
|
193
|
+
propsOrTextOrChildren,
|
|
194
|
+
[]
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return creatorCreateElement(
|
|
199
|
+
creator,
|
|
200
|
+
elementType,
|
|
201
|
+
propsOrTextOrChildren,
|
|
202
|
+
[textOrChildren]
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @name __CreatorElement
|
|
209
|
+
*
|
|
210
|
+
* @synopsis
|
|
211
|
+
* ```coffeescript [specscript]
|
|
212
|
+
* creator {
|
|
213
|
+
* createElement: (
|
|
214
|
+
* elementType string,
|
|
215
|
+
* props? object,
|
|
216
|
+
* children? Array<creator.Element>
|
|
217
|
+
* )=>creator.Element
|
|
218
|
+
* }
|
|
219
|
+
*
|
|
220
|
+
* __CreatorElement(creator elementType string) -> _Element function
|
|
221
|
+
*
|
|
222
|
+
* _Element(
|
|
223
|
+
* propsOrTextOrChildren object|string|Array,
|
|
224
|
+
* textOrChildren string|Array,
|
|
225
|
+
* ) -> creator.Element
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
function __CreatorElement(creator, elementType) {
|
|
229
|
+
return function _CreatorElement(propsOrTextOrChildren, textOrChildren) {
|
|
230
|
+
return CreatorElement(
|
|
231
|
+
creator,
|
|
232
|
+
elementType,
|
|
233
|
+
propsOrTextOrChildren,
|
|
234
|
+
textOrChildren
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @name _CreatorElement
|
|
241
|
+
*
|
|
242
|
+
* @synopsis
|
|
243
|
+
* ```coffeescript [specscript]
|
|
244
|
+
* args Array
|
|
245
|
+
*
|
|
246
|
+
* creator {
|
|
247
|
+
* createElement: (
|
|
248
|
+
* elementType string,
|
|
249
|
+
* props? object,
|
|
250
|
+
* children? Array<creator.Element>
|
|
251
|
+
* )=>creator.Element
|
|
252
|
+
* }
|
|
253
|
+
*
|
|
254
|
+
* _CreatorElement(creator) -> _Element (...args)=>creator.Element
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
function _CreatorElement(creator) {
|
|
258
|
+
return function _Element(...args) {
|
|
259
|
+
if (args.length == 1) {
|
|
260
|
+
return __CreatorElement(creator, args[0])
|
|
261
|
+
}
|
|
262
|
+
return CreatorElement(creator, ...args)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @name $__StyledCreatorElement
|
|
268
|
+
*
|
|
269
|
+
* @synopsis
|
|
270
|
+
* ```coffeescript [specscript]
|
|
271
|
+
* creator {
|
|
272
|
+
* createElement: (
|
|
273
|
+
* elementType string,
|
|
274
|
+
* props? object,
|
|
275
|
+
* children? Array<creator.Element>
|
|
276
|
+
* )=>creator.Element
|
|
277
|
+
* }
|
|
278
|
+
*
|
|
279
|
+
* $__StyledCreatorElement(
|
|
280
|
+
* creator,
|
|
281
|
+
* options {
|
|
282
|
+
* styled Styled,
|
|
283
|
+
* styledMemoizationCap number,
|
|
284
|
+
* }
|
|
285
|
+
* ) -> _StyledCreatorElement function
|
|
286
|
+
*
|
|
287
|
+
* _StyledCreatorElement(elementType string) -> _StyledElement function
|
|
288
|
+
*
|
|
289
|
+
* _StyledElement(
|
|
290
|
+
* propsOrTextOrChildren object|string|Array,
|
|
291
|
+
* textOrChildren string|Array,
|
|
292
|
+
* ) -> creator.Element
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
function $__StyledCreatorElement(creator, options) {
|
|
296
|
+
const { styled, styledMemoizationCap } = options
|
|
297
|
+
return function _StyledCreatorElement(elementType) {
|
|
298
|
+
const styledComponent = memoizeCappedWithResolver(
|
|
299
|
+
styled[elementType],
|
|
300
|
+
styledMemoizationCap,
|
|
301
|
+
array => array[0],
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
return function _StyledElement(propsOrTextOrChildren, textOrChildren) {
|
|
305
|
+
if (isArray(propsOrTextOrChildren)) {
|
|
306
|
+
return creatorCreateElement(
|
|
307
|
+
creator,
|
|
308
|
+
elementType,
|
|
309
|
+
{},
|
|
310
|
+
propsOrTextOrChildren
|
|
311
|
+
)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (typeof propsOrTextOrChildren == 'string') {
|
|
315
|
+
return creatorCreateElement(
|
|
316
|
+
creator,
|
|
317
|
+
elementType,
|
|
318
|
+
{},
|
|
319
|
+
[propsOrTextOrChildren]
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (isArray(textOrChildren)) {
|
|
324
|
+
if (propsOrTextOrChildren == null || propsOrTextOrChildren.css == null) {
|
|
325
|
+
return creatorCreateElement(
|
|
326
|
+
creator,
|
|
327
|
+
elementType,
|
|
328
|
+
propsOrTextOrChildren,
|
|
329
|
+
textOrChildren
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
const { css, ...props } = propsOrTextOrChildren
|
|
333
|
+
return creatorCreateElement(
|
|
334
|
+
creator,
|
|
335
|
+
styledComponent([css]),
|
|
336
|
+
props,
|
|
337
|
+
textOrChildren
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (textOrChildren == null) {
|
|
342
|
+
if (propsOrTextOrChildren == null || propsOrTextOrChildren.css == null) {
|
|
343
|
+
return creatorCreateElement(
|
|
344
|
+
creator,
|
|
345
|
+
elementType,
|
|
346
|
+
propsOrTextOrChildren,
|
|
347
|
+
[]
|
|
348
|
+
)
|
|
349
|
+
}
|
|
350
|
+
const { css, ...props } = propsOrTextOrChildren
|
|
351
|
+
return creatorCreateElement(creator, styledComponent([css]), props, [])
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (propsOrTextOrChildren == null || propsOrTextOrChildren.css == null) {
|
|
355
|
+
return creatorCreateElement(
|
|
356
|
+
creator,
|
|
357
|
+
elementType,
|
|
358
|
+
propsOrTextOrChildren,
|
|
359
|
+
[textOrChildren]
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const { css, ...props } = propsOrTextOrChildren
|
|
364
|
+
return creatorCreateElement(
|
|
365
|
+
creator,
|
|
366
|
+
styledComponent([css]),
|
|
367
|
+
props,
|
|
368
|
+
[textOrChildren]
|
|
369
|
+
)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* @name __assignElementNames
|
|
376
|
+
*
|
|
377
|
+
* @synopsis
|
|
378
|
+
* ```coffeescript [specscript]
|
|
379
|
+
* creator {
|
|
380
|
+
* createElement: (
|
|
381
|
+
* elementType string,
|
|
382
|
+
* props? object,
|
|
383
|
+
* children? Array<creator.Element>
|
|
384
|
+
* )=>creator.Element
|
|
385
|
+
* }
|
|
386
|
+
*
|
|
387
|
+
* __assignElementNames(CreatorElement creator.Element) -> ()
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
function __assignElementNames(CreatorElement) {
|
|
391
|
+
CreatorElement.A = CreatorElement('a')
|
|
392
|
+
CreatorElement.P = CreatorElement('p')
|
|
393
|
+
CreatorElement.B = CreatorElement('b')
|
|
394
|
+
CreatorElement.Q = CreatorElement('q')
|
|
395
|
+
CreatorElement.I = CreatorElement('i')
|
|
396
|
+
CreatorElement.Ul = CreatorElement('ul')
|
|
397
|
+
CreatorElement.Ol = CreatorElement('ol')
|
|
398
|
+
CreatorElement.Li = CreatorElement('li')
|
|
399
|
+
|
|
400
|
+
CreatorElement.H1 = CreatorElement('h1')
|
|
401
|
+
CreatorElement.H2 = CreatorElement('h2')
|
|
402
|
+
CreatorElement.H3 = CreatorElement('h3')
|
|
403
|
+
CreatorElement.H4 = CreatorElement('h4')
|
|
404
|
+
CreatorElement.H5 = CreatorElement('h5')
|
|
405
|
+
CreatorElement.H6 = CreatorElement('h6')
|
|
406
|
+
CreatorElement.Hr = CreatorElement('hr')
|
|
407
|
+
CreatorElement.Br = CreatorElement('br')
|
|
408
|
+
|
|
409
|
+
CreatorElement.Script = CreatorElement('script')
|
|
410
|
+
CreatorElement.Html = CreatorElement('html')
|
|
411
|
+
CreatorElement.Body = CreatorElement('body')
|
|
412
|
+
CreatorElement.Nav = CreatorElement('nav')
|
|
413
|
+
CreatorElement.Section = CreatorElement('section')
|
|
414
|
+
CreatorElement.Article = CreatorElement('article')
|
|
415
|
+
CreatorElement.Footer = CreatorElement('footer')
|
|
416
|
+
CreatorElement.Span = CreatorElement('span')
|
|
417
|
+
CreatorElement.Div = CreatorElement('div')
|
|
418
|
+
CreatorElement.Img = CreatorElement('img')
|
|
419
|
+
CreatorElement.Video = CreatorElement('video')
|
|
420
|
+
|
|
421
|
+
CreatorElement.Form = CreatorElement('form')
|
|
422
|
+
CreatorElement.Fieldset = CreatorElement('fieldset')
|
|
423
|
+
CreatorElement.Input = CreatorElement('input')
|
|
424
|
+
CreatorElement.Label = CreatorElement('label')
|
|
425
|
+
CreatorElement.Textarea = CreatorElement('textarea')
|
|
426
|
+
CreatorElement.Select = CreatorElement('select')
|
|
427
|
+
CreatorElement.Option = CreatorElement('option')
|
|
428
|
+
|
|
429
|
+
CreatorElement.Button = CreatorElement('button')
|
|
430
|
+
CreatorElement.Iframe = CreatorElement('iframe')
|
|
431
|
+
CreatorElement.Blockquote = CreatorElement('blockquote')
|
|
432
|
+
CreatorElement.Code = CreatorElement('code')
|
|
433
|
+
CreatorElement.Pre = CreatorElement('pre')
|
|
119
434
|
}
|
|
120
435
|
|
|
121
436
|
/**
|
|
@@ -125,43 +440,45 @@ const creatorCreateElement = function (creator, type, props, children) {
|
|
|
125
440
|
* ```coffeescript [specscript]
|
|
126
441
|
* Element = Object
|
|
127
442
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
443
|
+
* type string|function
|
|
444
|
+
* props Object
|
|
445
|
+
* children string|Object|Array<string|Object>
|
|
446
|
+
* element Element
|
|
447
|
+
* creator {
|
|
448
|
+
* createElement: (type, props?, children?)=>element,
|
|
449
|
+
* }
|
|
450
|
+
* rootElement type=>((props, children?)|children)=>element {
|
|
451
|
+
* Script: ((props, children?)|children)=>element,
|
|
452
|
+
* Html: ((props, children?)|children)=>element,
|
|
453
|
+
* Body: (props, children?)|children)=>element,
|
|
454
|
+
* Section: (props, children?)|children)=>element,
|
|
455
|
+
* Article: (props, children?)|children)=>element,
|
|
456
|
+
* Span: (props, children?)|children)=>element,
|
|
457
|
+
* Div: (props, children?)|children)=>element,
|
|
458
|
+
* Img: (props, children?)|children)=>element,
|
|
459
|
+
* H1: (props, children?)|children)=>element,
|
|
460
|
+
* H2: (props, children?)|children)=>element,
|
|
461
|
+
* H3: (props, children?)|children)=>element,
|
|
462
|
+
* H4: (props, children?)|children)=>element,
|
|
463
|
+
* H5: (props, children?)|children)=>element,
|
|
464
|
+
* H6: (props, children?)|children)=>element,
|
|
465
|
+
*
|
|
466
|
+
* A: (props, children?)|children)=>element,
|
|
467
|
+
* P: (props, children?)|children)=>element,
|
|
468
|
+
* B: (props, children?)|children)=>element,
|
|
469
|
+
* Q: (props, children?)|children)=>element,
|
|
470
|
+
* I: (props, children?)|children)=>element,
|
|
471
|
+
* Ul: (props, children?)|children)=>element,
|
|
472
|
+
* Ol: (props, children?)|children)=>element,
|
|
473
|
+
* Li: (props, children?)|children)=>element,
|
|
474
|
+
* Textarea: (props, children?)|children)=>element,
|
|
475
|
+
* Button: (props, children?)|children)=>element,
|
|
476
|
+
* Iframe: (props, children?)|children)=>element,
|
|
477
|
+
* Blockquote: (props, children?)|children)=>element,
|
|
478
|
+
* Br: (props, children?)|children)=>element,
|
|
479
|
+
* Code: (props, children?)|children)=>element,
|
|
480
|
+
* Pre: (props, children?)|children)=>element,
|
|
481
|
+
* }
|
|
165
482
|
*
|
|
166
483
|
* Arche(creator, options {
|
|
167
484
|
* styled?: Styled,
|
|
@@ -250,121 +567,25 @@ const Arche = function (creator, options = {}) {
|
|
|
250
567
|
styledMemoizationCap = 1000,
|
|
251
568
|
} = options
|
|
252
569
|
|
|
253
|
-
const
|
|
254
|
-
if (isArray(arg0)) {
|
|
255
|
-
return creatorCreateElement(creator, type, {}, arg0)
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (typeof arg0 == 'string') {
|
|
259
|
-
return creatorCreateElement(creator, type, {}, [arg0])
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (isArray(arg1)) {
|
|
263
|
-
return creatorCreateElement(creator, type, arg0, arg1)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (arg1 == null) {
|
|
267
|
-
return creatorCreateElement(creator, type, arg0, [])
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const styledRootElement = type => {
|
|
274
|
-
const styledComponent = memoizeCappedWithResolver(
|
|
275
|
-
styled[type],
|
|
276
|
-
styledMemoizationCap,
|
|
277
|
-
array => array[0],
|
|
278
|
-
)
|
|
570
|
+
const OriginalCreatorElement = _CreatorElement(creator)
|
|
279
571
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (typeof arg0 == 'string') {
|
|
286
|
-
return creatorCreateElement(creator, type, {}, [arg0])
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (isArray(arg1)) {
|
|
290
|
-
if (arg0 == null || arg0.css == null) {
|
|
291
|
-
return creatorCreateElement(creator, type, arg0, arg1)
|
|
292
|
-
}
|
|
293
|
-
const { css, ...props } = arg0
|
|
294
|
-
return creatorCreateElement(creator, styledComponent([css]), props, arg1)
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
if (arg1 == null) {
|
|
298
|
-
if (arg0 == null || arg0.css == null) {
|
|
299
|
-
return creatorCreateElement(creator, type, arg0, [])
|
|
300
|
-
}
|
|
301
|
-
const { css, ...props } = arg0
|
|
302
|
-
return creatorCreateElement(creator, styledComponent([css]), props, [])
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (arg0 == null || arg0.css == null) {
|
|
306
|
-
return creatorCreateElement(creator, type, arg0, [arg1])
|
|
307
|
-
}
|
|
308
|
-
const { css, ...props } = arg0
|
|
309
|
-
return creatorCreateElement(creator, styledComponent([css]), props, [arg1])
|
|
310
|
-
}
|
|
311
|
-
}
|
|
572
|
+
const StyledCreatorElement = $__StyledCreatorElement(creator, {
|
|
573
|
+
styled,
|
|
574
|
+
styledMemoizationCap,
|
|
575
|
+
})
|
|
312
576
|
|
|
313
|
-
const
|
|
577
|
+
const CreatorElement = (
|
|
314
578
|
styled == null
|
|
315
|
-
?
|
|
579
|
+
? OriginalCreatorElement
|
|
316
580
|
: type => typeof type == 'string'
|
|
317
|
-
?
|
|
318
|
-
:
|
|
581
|
+
? StyledCreatorElement(type)
|
|
582
|
+
: OriginalCreatorElement(type)
|
|
319
583
|
)
|
|
320
584
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
rootElement.B = rootElement('b')
|
|
326
|
-
rootElement.Q = rootElement('q')
|
|
327
|
-
rootElement.I = rootElement('i')
|
|
328
|
-
rootElement.Ul = rootElement('ul')
|
|
329
|
-
rootElement.Ol = rootElement('ol')
|
|
330
|
-
rootElement.Li = rootElement('li')
|
|
331
|
-
|
|
332
|
-
rootElement.H1 = rootElement('h1')
|
|
333
|
-
rootElement.H2 = rootElement('h2')
|
|
334
|
-
rootElement.H3 = rootElement('h3')
|
|
335
|
-
rootElement.H4 = rootElement('h4')
|
|
336
|
-
rootElement.H5 = rootElement('h5')
|
|
337
|
-
rootElement.H6 = rootElement('h6')
|
|
338
|
-
rootElement.Hr = rootElement('hr')
|
|
339
|
-
rootElement.Br = rootElement('br')
|
|
340
|
-
|
|
341
|
-
rootElement.Script = rootElement('script')
|
|
342
|
-
rootElement.Html = rootElement('html')
|
|
343
|
-
rootElement.Body = rootElement('body')
|
|
344
|
-
rootElement.Nav = rootElement('nav')
|
|
345
|
-
rootElement.Section = rootElement('section')
|
|
346
|
-
rootElement.Article = rootElement('article')
|
|
347
|
-
rootElement.Footer = rootElement('footer')
|
|
348
|
-
rootElement.Span = rootElement('span')
|
|
349
|
-
rootElement.Div = rootElement('div')
|
|
350
|
-
rootElement.Img = rootElement('img')
|
|
351
|
-
rootElement.Video = rootElement('video')
|
|
352
|
-
|
|
353
|
-
rootElement.Form = rootElement('form')
|
|
354
|
-
rootElement.Fieldset = rootElement('fieldset')
|
|
355
|
-
rootElement.Input = rootElement('input')
|
|
356
|
-
rootElement.Label = rootElement('label')
|
|
357
|
-
rootElement.Textarea = rootElement('textarea')
|
|
358
|
-
rootElement.Select = rootElement('select')
|
|
359
|
-
rootElement.Option = rootElement('option')
|
|
360
|
-
|
|
361
|
-
rootElement.Button = rootElement('button')
|
|
362
|
-
rootElement.Iframe = rootElement('iframe')
|
|
363
|
-
rootElement.Blockquote = rootElement('blockquote')
|
|
364
|
-
rootElement.Code = rootElement('code')
|
|
365
|
-
rootElement.Pre = rootElement('pre')
|
|
366
|
-
|
|
367
|
-
return rootElement
|
|
585
|
+
CreatorElement.creator = creator
|
|
586
|
+
__assignElementNames(CreatorElement)
|
|
587
|
+
|
|
588
|
+
return CreatorElement
|
|
368
589
|
}
|
|
369
590
|
|
|
370
591
|
export default Arche
|
package/package.json
CHANGED
package/test.html
CHANGED
|
@@ -5,22 +5,21 @@
|
|
|
5
5
|
<title>test</title>
|
|
6
6
|
<script src="https://unpkg.com/react@16.13.1/umd/react.production.min.js" crossorigin></script>
|
|
7
7
|
<script src="https://unpkg.com/react-dom@16.13.1/umd/react-dom.production.min.js" crossorigin></script>
|
|
8
|
+
<script src="https://unpkg.com/styled-components@6.1.19/dist/styled-components.min.js"></script>
|
|
8
9
|
<script src="/index.js"></script>
|
|
9
10
|
</head>
|
|
10
11
|
<body>
|
|
11
|
-
<div id="
|
|
12
|
-
|
|
13
|
-
<
|
|
14
|
-
</body>
|
|
15
|
-
<script>
|
|
12
|
+
<div id="react-counter"></div>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
16
15
|
const ReactElement = Arche(React)
|
|
17
16
|
const { Div, H1, P, Button, Img } = ReactElement
|
|
18
17
|
const { useState } = React
|
|
19
18
|
|
|
20
|
-
const
|
|
19
|
+
const ReactCounter = ReactElement(() => {
|
|
21
20
|
const [count, setCount] = useState(0)
|
|
22
21
|
return Div([
|
|
23
|
-
P('Success! - React'),
|
|
22
|
+
P('Success! - React Counter'),
|
|
24
23
|
P(`You clicked ${count} times`),
|
|
25
24
|
Button({
|
|
26
25
|
onClick() {
|
|
@@ -30,20 +29,30 @@ const Example = ReactElement(() => {
|
|
|
30
29
|
])
|
|
31
30
|
})
|
|
32
31
|
|
|
33
|
-
ReactDOM.render(
|
|
32
|
+
ReactDOM.render(ReactCounter(), document.getElementById('react-counter'))
|
|
33
|
+
</script>
|
|
34
34
|
|
|
35
|
+
<div id="user-card"></div>
|
|
36
|
+
|
|
37
|
+
<script>
|
|
35
38
|
const UserCard = ReactElement(({
|
|
36
39
|
firstName, lastName, age,
|
|
37
40
|
}) => Div({ style: { border: '1px solid lightgrey' } }, [
|
|
41
|
+
P('Success! - React User Card'),
|
|
38
42
|
H1(`${firstName} ${lastName}`),
|
|
39
|
-
Img({ src: 'https://
|
|
43
|
+
Img({ src: 'https://placehold.co/300', alt: 'placeholder' }),
|
|
40
44
|
P({ style: { color: 'lightgrey' } }, `age: ${age}`),
|
|
41
45
|
]))
|
|
42
46
|
|
|
43
47
|
ReactDOM.render(
|
|
44
48
|
UserCard({ firstName: 'George', lastName: 'Henry', age: 32 }),
|
|
45
|
-
document.getElementById('user-card')
|
|
49
|
+
document.getElementById('user-card')
|
|
50
|
+
)
|
|
51
|
+
</script>
|
|
46
52
|
|
|
53
|
+
<div id="dom-example"></div>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
47
56
|
const DOMElement = Arche(document)
|
|
48
57
|
|
|
49
58
|
const domExample = DOMElement.Div([
|
|
@@ -56,6 +65,39 @@ const domExample = DOMElement.Div([
|
|
|
56
65
|
])
|
|
57
66
|
|
|
58
67
|
document.getElementById('dom-example').appendChild(domExample)
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<div id="styled-react-user-card"></div>
|
|
59
71
|
|
|
72
|
+
<script>
|
|
73
|
+
const StyledReactElement = Arche(React, { styled })
|
|
74
|
+
|
|
75
|
+
const StyledUserCard = StyledReactElement(({
|
|
76
|
+
firstName, lastName, age,
|
|
77
|
+
}) => StyledReactElement.Div({
|
|
78
|
+
css: `
|
|
79
|
+
border: 1px solid lightgrey;
|
|
80
|
+
`,
|
|
81
|
+
}, [
|
|
82
|
+
StyledReactElement.P('Success! - Styled React User Card'),
|
|
83
|
+
StyledReactElement.H1(`${firstName} ${lastName}`),
|
|
84
|
+
StyledReactElement.Img({ src: 'https://placehold.co/300', alt: 'placeholder' }),
|
|
85
|
+
StyledReactElement.P({
|
|
86
|
+
css: `
|
|
87
|
+
color: lightgrey;
|
|
88
|
+
`,
|
|
89
|
+
}, `age: ${age}`),
|
|
90
|
+
]))
|
|
91
|
+
|
|
92
|
+
ReactDOM.render(
|
|
93
|
+
StyledUserCard({ firstName: 'George', lastName: 'Henry II', age: 32 }),
|
|
94
|
+
document.getElementById('styled-react-user-card')
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
console.log(styled)
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
</body>
|
|
101
|
+
<script>
|
|
60
102
|
</script>
|
|
61
103
|
</html>
|