arche 0.3.8 → 0.3.10

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
@@ -94,6 +94,8 @@ import Arche from 'https://unpkg.com/arche/es.js'
94
94
 
95
95
  # Syntax
96
96
  ```coffeescript [specscript]
97
+ Arche() -> DocumentElement
98
+ Arche(document Document) -> DocumentElement
97
99
  Arche(React {
98
100
  createElement: (type, props?, children?)=>ReactElement,
99
101
  }, options? {
package/es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Arche v0.3.8
2
+ * Arche v0.3.10
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.
@@ -25,6 +25,13 @@ const elementSetAttribute = function (element, key, value) {
25
25
  if (value == null) { // boolean
26
26
  element.setAttribute(key, value)
27
27
  }
28
+ else if (typeof value == 'boolean') {
29
+ if (value) {
30
+ element.setAttribute(key, key)
31
+ } else {
32
+ element.removeAttribute(key)
33
+ }
34
+ }
28
35
  else if (value.constructor == Object) { // style
29
36
  for (const subKey in value) {
30
37
  element[key][subKey] = value[subKey]
@@ -230,6 +237,14 @@ const creatorCreateElement = function (creator, type, props, children) {
230
237
  */
231
238
 
232
239
  const Arche = function (creator, options = {}) {
240
+ if (creator == null && typeof document != 'undefined') {
241
+ creator = document
242
+ }
243
+
244
+ if (creator == null) {
245
+ throw new TypeError('creator not defined')
246
+ }
247
+
233
248
  const {
234
249
  styled,
235
250
  styledMemoizationCap = 1000,
@@ -303,6 +318,8 @@ const Arche = function (creator, options = {}) {
303
318
  : originalRootElement(type)
304
319
  )
305
320
 
321
+ rootElement.creator = creator
322
+
306
323
  rootElement.A = rootElement('a')
307
324
  rootElement.P = rootElement('p')
308
325
  rootElement.B = rootElement('b')
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Arche v0.3.8
2
+ * Arche v0.3.10
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.
@@ -31,6 +31,13 @@ const elementSetAttribute = function (element, key, value) {
31
31
  if (value == null) { // boolean
32
32
  element.setAttribute(key, value)
33
33
  }
34
+ else if (typeof value == 'boolean') {
35
+ if (value) {
36
+ element.setAttribute(key, key)
37
+ } else {
38
+ element.removeAttribute(key)
39
+ }
40
+ }
34
41
  else if (value.constructor == Object) { // style
35
42
  for (const subKey in value) {
36
43
  element[key][subKey] = value[subKey]
@@ -236,6 +243,14 @@ const creatorCreateElement = function (creator, type, props, children) {
236
243
  */
237
244
 
238
245
  const Arche = function (creator, options = {}) {
246
+ if (creator == null && typeof document != 'undefined') {
247
+ creator = document
248
+ }
249
+
250
+ if (creator == null) {
251
+ throw new TypeError('creator not defined')
252
+ }
253
+
239
254
  const {
240
255
  styled,
241
256
  styledMemoizationCap = 1000,
@@ -309,6 +324,8 @@ const Arche = function (creator, options = {}) {
309
324
  : originalRootElement(type)
310
325
  )
311
326
 
327
+ rootElement.creator = creator
328
+
312
329
  rootElement.A = rootElement('a')
313
330
  rootElement.P = rootElement('p')
314
331
  rootElement.B = rootElement('b')
package/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Arche v0.3.8
2
+ * Arche v0.3.10
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.
@@ -25,6 +25,13 @@ const elementSetAttribute = function (element, key, value) {
25
25
  if (value == null) { // boolean
26
26
  element.setAttribute(key, value)
27
27
  }
28
+ else if (typeof value == 'boolean') {
29
+ if (value) {
30
+ element.setAttribute(key, key)
31
+ } else {
32
+ element.removeAttribute(key)
33
+ }
34
+ }
28
35
  else if (value.constructor == Object) { // style
29
36
  for (const subKey in value) {
30
37
  element[key][subKey] = value[subKey]
@@ -230,6 +237,14 @@ const creatorCreateElement = function (creator, type, props, children) {
230
237
  */
231
238
 
232
239
  const Arche = function (creator, options = {}) {
240
+ if (creator == null && typeof document != 'undefined') {
241
+ creator = document
242
+ }
243
+
244
+ if (creator == null) {
245
+ throw new TypeError('creator not defined')
246
+ }
247
+
233
248
  const {
234
249
  styled,
235
250
  styledMemoizationCap = 1000,
@@ -303,6 +318,8 @@ const Arche = function (creator, options = {}) {
303
318
  : originalRootElement(type)
304
319
  )
305
320
 
321
+ rootElement.creator = creator
322
+
306
323
  rootElement.A = rootElement('a')
307
324
  rootElement.P = rootElement('p')
308
325
  rootElement.B = rootElement('b')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arche",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "HTML as JavaScript",
5
5
  "author": "Richard Tong",
6
6
  "license": "MIT",
package/test.js CHANGED
@@ -3,6 +3,21 @@ const Arche = require('.')
3
3
 
4
4
  describe('Arche', () => {
5
5
  describe('unary creator.createElement - document', () => {
6
+ it('init', async () => {
7
+ assert.throws(
8
+ () => {
9
+ const E1 = Arche()
10
+ console.log(E1)
11
+ },
12
+ new TypeError('creator not defined'),
13
+ )
14
+
15
+ globalThis.document = { createElement() {} }
16
+
17
+ const E1 = Arche()
18
+ assert.equal(E1.creator, globalThis.document)
19
+ })
20
+
6
21
  const mockEventListeners = new Map()
7
22
  const mockDocument = {
8
23
  createElement(type) {
@@ -46,6 +61,7 @@ describe('Arche', () => {
46
61
  Article('yo'),
47
62
  ]),
48
63
  Button({
64
+ disabled: true,
49
65
  onClick: listener,
50
66
  onMouseOver(event) {
51
67
  console.log('onmouseover')
@@ -62,7 +78,7 @@ describe('Arche', () => {
62
78
 
63
79
  assert.strictEqual(
64
80
  JSON.stringify(el),
65
- '{"type":"div","children":[{"type":"h1","children":[{"type":"text","text":"header"}],"style":{}},{"type":"p","children":[{"type":"text","text":"description"}],"style":{"color":"grey"}},{"type":"span","children":[],"style":{},"id":"hey","excluded":null},{"type":"div","children":[{"type":"article","children":[{"type":"text","text":"yo"}],"style":{}}],"style":{},"id":"nested"},{"type":"button","children":[],"style":{}}],"style":{}}')
81
+ '{"type":"div","children":[{"type":"h1","children":[{"type":"text","text":"header"}],"style":{}},{"type":"p","children":[{"type":"text","text":"description"}],"style":{"color":"grey"}},{"type":"span","children":[],"style":{},"id":"hey","excluded":null},{"type":"div","children":[{"type":"article","children":[{"type":"text","text":"yo"}],"style":{}}],"style":{},"id":"nested"},{"type":"button","children":[],"style":{},"disabled":"disabled"}],"style":{}}')
66
82
  })
67
83
  })
68
84