arche 1.0.0 → 1.0.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.
Files changed (6) hide show
  1. package/LICENSE +5 -17
  2. package/README.md +52 -299
  3. package/es.js +271 -130
  4. package/index.js +20 -15
  5. package/index.mjs +271 -130
  6. package/package.json +1 -1
package/LICENSE CHANGED
@@ -1,21 +1,9 @@
1
- The MIT License (MIT)
1
+ The CLOUT Free and Open Source Software License (CFOSS)
2
2
 
3
- Copyright (c) 2025 Richard Tong
3
+ © Richard Yufei Tong, King of Software
4
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:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
6
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
7
+ 1. This permission notice is included in all copies or substantial portions of the Software.
14
8
 
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
21
- THE SOFTWARE.
9
+ THE SOFTWARE IS PROVIDED AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE, OR IN THE USE OF OR OTHER DEALINGS OF THE SOFTWARE.
package/README.md CHANGED
@@ -1,46 +1,44 @@
1
1
  # Arche
2
2
  ![arche-logo](https://raw.githubusercontent.com/a-synchronous/assets/master/arche-logo-226x226.png)
3
- > Arche (/ˈɑːrki/; Ancient Greek: ἀρχή) is a Greek word with primary senses "beginning", "origin" or "source of action" (ἐξ' ἀρχῆς: from the beginning, οr ἐξ' ἀρχῆς λόγος: the original argument), and later "first principle" or "element". ([wikipedia](https://en.wikipedia.org/wiki/Arche))
3
+ > Arche (/ˈɑːrki/; Ancient Greek: ἀρχή) is a Greek word with primary senses "beginning", "origin" or "source of action" (ἐξ' ἀρχῆς: from the beginning, οr ἐξ' ἀρχῆς λόγος: the original argument), and later "first principle" or "element".
4
4
 
5
5
  ![Node.js CI](https://github.com/richytong/arche/actions/workflows/nodejs.yml/badge.svg)
6
6
  [![codecov](https://codecov.io/gh/richytong/arche/branch/master/graph/badge.svg)](https://codecov.io/gh/richytong/arche)
7
+ [![npm version](https://img.shields.io/npm/v/arche.svg?style=flat)](https://www.npmjs.com/package/arche)
7
8
 
8
9
  Simplified DOM interface / React in pure JavaScript.
9
10
 
10
- ```javascript
11
- const DocumentElement = Arche(document)
12
- const { Div, H1, P } = DocumentElement
13
-
14
- const myElement = Div({ id: 'my-element' }, [
15
- H1('I am a heading'),
16
- P('paragraph'),
17
- P('lorem ipsum'),
18
- ])
19
-
20
- document.getElementById('#my-container').appendChild(myElement)
21
- // <div id="my-container">
22
- // <div id="my-element">
23
- // <h1>I am a heading</h1>
24
- // <p>paragraph</p>
25
- // <p>lorem ipsum</p>
26
- // </div>
27
- // </div>
11
+ ```javascript [playground]
12
+ {
13
+ const DocumentElement = Arche(document)
14
+ const { Div, H1, P } = DocumentElement
28
15
 
29
- const ReactElement = Arche(React)
30
- const { Div, H1, P, Button, Img } = ReactElement
16
+ const myElement = Div({ id: 'my-element' }, [
17
+ H1('DOM Example'),
18
+ P('paragraph'),
19
+ P('lorem ipsum'),
20
+ ])
31
21
 
32
- const UserCard = ReactElement(({
33
- firstName, lastName, age,
34
- }) => Div([
35
- H1(`${firstName} ${lastName}`),
36
- Img({ src: 'https://via.placeholder.com/150x150', alt: 'placeholder' }),
37
- P({ style: { color: 'lightgrey' } }, `age: ${age}`),
38
- ]))
22
+ document.getElementById('dom-container').appendChild(myElement)
23
+ }
39
24
 
40
- ReactDOM.render(
41
- UserCard({ firstName: 'Example', lastName: 'Name', age: 32 }),
42
- document.getElementById('react-root')
43
- )
25
+ {
26
+ const ReactElement = Arche(React)
27
+ const { Div, H1, P, Button, Img } = ReactElement
28
+
29
+ const UserCard = ReactElement(({
30
+ firstName, lastName, age,
31
+ }) => Div([
32
+ H1(`${firstName} ${lastName}`),
33
+ Img({ src: 'https://placehold.co/300x300', alt: 'placeholder' }),
34
+ P({ style: { color: 'lightgrey' } }, `age: ${age}`),
35
+ ]))
36
+
37
+ ReactDOM.render(
38
+ UserCard({ firstName: 'React', lastName: 'ExampleUser', age: 32 }),
39
+ document.getElementById('react-root')
40
+ )
41
+ }
44
42
  ```
45
43
 
46
44
  ## Installation
@@ -79,70 +77,6 @@ window.Svg = DocumentElement('svg')
79
77
  window.Path = DocumentElement('path')
80
78
  ```
81
79
 
82
- ## Syntax
83
- ```coffeescript [specscript]
84
- Arche() -> DocumentElement
85
- Arche(document Document) -> DocumentElement
86
-
87
- DocumentElement(
88
- elementType string,
89
- props object,
90
- text string
91
- ) -> element Element
92
-
93
- DocumentElement(
94
- elementType string,
95
- props object,
96
- children Array<Element|string>
97
- ) -> element Element
98
-
99
- DocumentElement(elementType string) -> TypedDocumentElement
100
- DocumentElement.A -> TypedDocumentElement
101
- DocumentElement.P -> TypedDocumentElement
102
- DocumentElement.B -> TypedDocumentElement
103
- DocumentElement.Q -> TypedDocumentElement
104
- DocumentElement.I -> TypedDocumentElement
105
- DocumentElement.Ul -> TypedDocumentElement
106
- DocumentElement.Ol -> TypedDocumentElement
107
- DocumentElement.Li -> TypedDocumentElement
108
- DocumentElement.H1 -> TypedDocumentElement
109
- DocumentElement.H2 -> TypedDocumentElement
110
- DocumentElement.H3 -> TypedDocumentElement
111
- DocumentElement.H4 -> TypedDocumentElement
112
- DocumentElement.H5 -> TypedDocumentElement
113
- DocumentElement.H6 -> TypedDocumentElement
114
- DocumentElement.Hr -> TypedDocumentElement
115
- DocumentElement.Br -> TypedDocumentElement
116
- DocumentElement.Script -> TypedDocumentElement
117
- DocumentElement.Html -> TypedDocumentElement
118
- DocumentElement.Body -> TypedDocumentElement
119
- DocumentElement.Nav -> TypedDocumentElement
120
- DocumentElement.Section -> TypedDocumentElement
121
- DocumentElement.Article -> TypedDocumentElement
122
- DocumentElement.Footer -> TypedDocumentElement
123
- DocumentElement.Span -> TypedDocumentElement
124
- DocumentElement.Div -> TypedDocumentElement
125
- DocumentElement.Img -> TypedDocumentElement
126
- DocumentElement.Video -> TypedDocumentElement
127
- DocumentElement.Form -> TypedDocumentElement
128
- DocumentElement.Fieldset -> TypedDocumentElement
129
- DocumentElement.Input -> TypedDocumentElement
130
- DocumentElement.Label -> TypedDocumentElement
131
- DocumentElement.Textarea -> TypedDocumentElement
132
- DocumentElement.Select -> TypedDocumentElement
133
- DocumentElement.Option -> TypedDocumentElement
134
- DocumentElement.Button -> TypedDocumentElement
135
- DocumentElement.Iframe -> TypedDocumentElement
136
- DocumentElement.Blockquote -> TypedDocumentElement
137
- DocumentElement.Code -> TypedDocumentElement
138
- DocumentElement.Pre -> TypedDocumentElement
139
-
140
- TypedDocumentElement(props object, text string) -> element Element
141
- TypedDocumentElement(text string) -> element Element
142
- TypedDocumentElement(props object, children Array<Element|string>) -> element Element
143
- TypedDocumentElement(children Array<Element|string>) -> element Element
144
- ```
145
-
146
80
  ## Using React
147
81
  To use Arche with [React](https://react.dev/), simply provide the React library.
148
82
 
@@ -152,7 +86,7 @@ const ReactElement = Arche(React)
152
86
 
153
87
  Create dynamic components with props.
154
88
 
155
- ```javascript
89
+ ```javascript [playground]
156
90
  const ReactElement = Arche(React)
157
91
 
158
92
  const { Div, H1, P, Button, Img } = ReactElement
@@ -161,21 +95,19 @@ const UserCard = ReactElement(({
161
95
  firstName, lastName, age,
162
96
  }) => Div([
163
97
  H1(`${firstName} ${lastName}`),
164
- Img({ src: 'https://via.placeholder.com/150x150', alt: 'placeholder' }),
98
+ Img({ src: 'https://placehold.co/300x300', alt: 'placeholder' }),
165
99
  P({ style: { color: 'lightgrey' } }, `age: ${age}`),
166
100
  ]))
167
101
 
168
- render(UserCard({ firstName: 'Example', lastName: 'Name', age: 32 }))
169
- // <div>
170
- // <h1>Example Name</h1>
171
- // <img src="https://via.placeholder.com/150x150" alt="placeholder">
172
- // <p style="color: lightgrey">age: 32</p>
173
- // </div>
102
+ ReactDOM.render(
103
+ UserCard({ firstName: 'Example', lastName: 'Name', age: 32 }),
104
+ document.getElementById('react-root')
105
+ )
174
106
  ```
175
107
 
176
108
  Complete interoperability with React hooks (converted from [this example](https://reactjs.org/docs/hooks-intro.html)).
177
109
 
178
- ```javascript
110
+ ```javascript [playground]
179
111
  const ReactElement = Arche(React)
180
112
  const { Div, P, Button } = ReactElement
181
113
  const { useState } = React
@@ -193,11 +125,7 @@ const Example = ReactElement(() => {
193
125
  ])
194
126
  })
195
127
 
196
- render(Example())
197
- // <div>
198
- // <p>You clicked {count} times</p>
199
- // <button onclick="setCount(count + 1)">Click me</button>
200
- // </div>
128
+ ReactDOM.render(Example(), document.getElementById('react-root'))
201
129
  ```
202
130
 
203
131
  Set `ReactElement` globally for a better developer experience.
@@ -218,83 +146,6 @@ window.Svg = ReactElement('svg')
218
146
  window.Path = ReactElement('path')
219
147
  ```
220
148
 
221
- ## Syntax with React
222
-
223
- ```coffeescript [specscript]
224
- type React = {
225
- createElement: (
226
- elementType string,
227
- props object,
228
- children string|Array<React.Element|string>
229
- )=>(reactElement React.Element)
230
- }
231
-
232
- Arche(React) -> ReactElement
233
-
234
- ReactElement(
235
- elementType string,
236
- props object,
237
- text string
238
- ) -> reactElement React.Element
239
-
240
- ReactElement(
241
- elementType string,
242
- props object,
243
- children Array<React.Element|string>
244
- ) -> reactElement React.Element
245
-
246
- ReactElement(elementType string) -> TypedReactElement
247
- ReactElement.A -> TypedReactElement
248
- ReactElement.P -> TypedReactElement
249
- ReactElement.B -> TypedReactElement
250
- ReactElement.Q -> TypedReactElement
251
- ReactElement.I -> TypedReactElement
252
- ReactElement.Ul -> TypedReactElement
253
- ReactElement.Ol -> TypedReactElement
254
- ReactElement.Li -> TypedReactElement
255
- ReactElement.H1 -> TypedReactElement
256
- ReactElement.H2 -> TypedReactElement
257
- ReactElement.H3 -> TypedReactElement
258
- ReactElement.H4 -> TypedReactElement
259
- ReactElement.H5 -> TypedReactElement
260
- ReactElement.H6 -> TypedReactElement
261
- ReactElement.Hr -> TypedReactElement
262
- ReactElement.Br -> TypedReactElement
263
- ReactElement.Script -> TypedReactElement
264
- ReactElement.Html -> TypedReactElement
265
- ReactElement.Body -> TypedReactElement
266
- ReactElement.Nav -> TypedReactElement
267
- ReactElement.Section -> TypedReactElement
268
- ReactElement.Article -> TypedReactElement
269
- ReactElement.Footer -> TypedReactElement
270
- ReactElement.Span -> TypedReactElement
271
- ReactElement.Div -> TypedReactElement
272
- ReactElement.Img -> TypedReactElement
273
- ReactElement.Video -> TypedReactElement
274
- ReactElement.Form -> TypedReactElement
275
- ReactElement.Fieldset -> TypedReactElement
276
- ReactElement.Input -> TypedReactElement
277
- ReactElement.Label -> TypedReactElement
278
- ReactElement.Textarea -> TypedReactElement
279
- ReactElement.Select -> TypedReactElement
280
- ReactElement.Option -> TypedReactElement
281
- ReactElement.Button -> TypedReactElement
282
- ReactElement.Iframe -> TypedReactElement
283
- ReactElement.Blockquote -> TypedReactElement
284
- ReactElement.Code -> TypedReactElement
285
- ReactElement.Pre -> TypedReactElement
286
-
287
- TypedReactElement(props object, text string) -> reactElement React.Element
288
- TypedReactElement(text string) -> reactElement React.Element
289
-
290
- TypedReactElement(
291
- props object,
292
- children Array<React.Element|string>
293
- ) -> reactElement React.Element
294
-
295
- TypedReactElement(children Array<React.Element|string>) -> reactElement React.Element
296
- ```
297
-
298
149
  ## Using React Context
299
150
  To use React Context with Arche, wrap `YourContext.Provider` with `ReactElement` and supply `value` as a prop, specifying children in the next argument.
300
151
 
@@ -330,135 +181,37 @@ const ArticleWrapper = ReactElement(() => {
330
181
  Arche accepts a `styled` option from css-in-js libraries like [Styled Components](https://styled-components.com/) to enable a `css` prop on `ReactElement` and `TypedReactElement`.
331
182
 
332
183
  ```javascript
333
- // global.js
334
184
  const ReactElement = Arche(React, { styled })
335
185
  ```
336
186
 
337
187
  Elements can now specify a `css` prop to use css-in-js.
338
188
 
339
- ```javascript
340
- // MyComponent.js
341
- const MyComponent = ReactElement(props => {
189
+ ```javascript [playground]
190
+ const ReactElement = Arche(React, { styled })
191
+ const { Div, H1, P } = ReactElement
192
+
193
+ const MyComponent = ReactElement(() => {
342
194
  return Div({
343
195
  css: `
344
- width: 500px;
196
+ height: 500px;
197
+ width: 100%;
345
198
  background-color: pink;
346
199
  `,
347
- })
200
+ }, [
201
+ H1('Styled Example'),
202
+ P('Text'),
203
+ ])
348
204
  })
349
- ```
350
-
351
- ## Syntax with styled
352
- ```coffeescript [specscript]
353
- ([css string])=>(reactElement React.Element) -> StyledComponent
354
-
355
- type Styled = {
356
- h1: StyledComponent,
357
- h2: StyledComponent,
358
- h3: StyledComponent,
359
- h4: StyledComponent,
360
- h5: StyledComponent,
361
- div: StyledComponent,
362
- button: StyledComponent,
363
- a: StyledComponent,
364
- p: StyledComponent,
365
- span: StyledComponent,
366
- img: StyledComponent,
367
- ul: StyledComponent,
368
- ol: StyledComponent,
369
- li: StyledComponent,
370
- form: StyledComponent,
371
- article: StyledComponent,
372
- main: StyledComponent,
373
- section: StyledComponent,
374
- nav: StyledComponent,
375
- }
376
205
 
377
- Arche(React {
378
- createElement: (
379
- elementType string,
380
- props object,
381
- textOrChildren string|Array<React.Element|string>
382
- )=>(reactElement React.Element)
383
- }, options {
384
- styled: Styled,
385
- styledMemoizationCap?: number
386
- }) -> reactElement ReactElement
387
-
388
- ReactElement(
389
- elementType string,
390
- propsWithCss { css: string, ...props object },
391
- text string
392
- ) -> reactElement React.Element
393
-
394
- ReactElement(
395
- elementType string,
396
- propsWithCss { css: string, ...props object },
397
- children Array<React.Element|string>
398
- ) -> reactElement React.Element
399
-
400
- ReactElement(elementType string) -> TypedReactElement
401
- ReactElement.A -> TypedReactElement
402
- ReactElement.P -> TypedReactElement
403
- ReactElement.B -> TypedReactElement
404
- ReactElement.Q -> TypedReactElement
405
- ReactElement.I -> TypedReactElement
406
- ReactElement.Ul -> TypedReactElement
407
- ReactElement.Ol -> TypedReactElement
408
- ReactElement.Li -> TypedReactElement
409
- ReactElement.H1 -> TypedReactElement
410
- ReactElement.H2 -> TypedReactElement
411
- ReactElement.H3 -> TypedReactElement
412
- ReactElement.H4 -> TypedReactElement
413
- ReactElement.H5 -> TypedReactElement
414
- ReactElement.H6 -> TypedReactElement
415
- ReactElement.Hr -> TypedReactElement
416
- ReactElement.Br -> TypedReactElement
417
- ReactElement.Script -> TypedReactElement
418
- ReactElement.Html -> TypedReactElement
419
- ReactElement.Body -> TypedReactElement
420
- ReactElement.Nav -> TypedReactElement
421
- ReactElement.Section -> TypedReactElement
422
- ReactElement.Article -> TypedReactElement
423
- ReactElement.Footer -> TypedReactElement
424
- ReactElement.Span -> TypedReactElement
425
- ReactElement.Div -> TypedReactElement
426
- ReactElement.Img -> TypedReactElement
427
- ReactElement.Video -> TypedReactElement
428
- ReactElement.Form -> TypedReactElement
429
- ReactElement.Fieldset -> TypedReactElement
430
- ReactElement.Input -> TypedReactElement
431
- ReactElement.Label -> TypedReactElement
432
- ReactElement.Textarea -> TypedReactElement
433
- ReactElement.Select -> TypedReactElement
434
- ReactElement.Option -> TypedReactElement
435
- ReactElement.Button -> TypedReactElement
436
- ReactElement.Iframe -> TypedReactElement
437
- ReactElement.Blockquote -> TypedReactElement
438
- ReactElement.Code -> TypedReactElement
439
- ReactElement.Pre -> TypedReactElement
440
-
441
- TypedReactElement(
442
- propsWithCss { css: string, ...props object },
443
- text string
444
- ) -> reactElement React.Element
445
-
446
- TypedReactElement(text string) -> reactElement React.Element
447
-
448
- TypedReactElement(
449
- propsWithCss { css: string, ...props object },
450
- children Array<React.Element|string>
451
- ) -> reactElement React.Element
452
-
453
- TypedReactElement(children Array<React.Element|string>) -> reactElement React.Element
206
+ ReactDOM.render(MyComponent(), document.getElementById('react-root'))
454
207
  ```
455
208
 
456
209
  # Contributing
457
210
  Your feedback and contributions are welcome. If you have a suggestion, please raise an issue. Prior to that, please search through the issues first in case your suggestion has been made already. If you decide to work on an issue, please create a pull request.
458
211
 
459
- Pull requests should provide some basic context and link the relevant issue. Here is an [example pull request](https://github.com/a-synchronous/rubico/pull/12). If you are interested in contributing, the [help wanted](https://github.com/richytong/arche/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) tag is a good place to start.
212
+ Pull requests should provide some basic context and link the relevant issue. If you are interested in contributing, the [help wanted](https://github.com/richytong/arche/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) tag is a good place to start.
460
213
 
461
- For more information please see [CONTRIBUTING.md](/CONTRIBUTING.md)
214
+ For more information please see [CONTRIBUTING.md](https://github.com/richytong/arche/blob/master/CONTRIBUTING.md)
462
215
 
463
216
  # License
464
217
  Arche is [MIT Licensed](https://github.com/a-synchronous/rubico/blob/master/LICENSE).