jj 0.1.0 → 2.0.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.
Files changed (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -7
  3. package/lib/ComponentFiles.d.ts +35 -0
  4. package/lib/ComponentFiles.js +116 -0
  5. package/lib/ComponentFiles.js.map +1 -0
  6. package/lib/WC.d.ts +33 -0
  7. package/lib/WC.js +160 -0
  8. package/lib/WC.js.map +1 -0
  9. package/lib/WDF.d.ts +11 -0
  10. package/lib/WDF.js +31 -0
  11. package/lib/WDF.js.map +1 -0
  12. package/lib/WE.d.ts +42 -0
  13. package/lib/WE.js +132 -0
  14. package/lib/WE.js.map +1 -0
  15. package/lib/WF.d.ts +14 -0
  16. package/lib/WF.js +44 -0
  17. package/lib/WF.js.map +1 -0
  18. package/lib/WHE.d.ts +21 -0
  19. package/lib/WHE.js +75 -0
  20. package/lib/WHE.js.map +1 -0
  21. package/lib/WN-mixin.d.ts +9 -0
  22. package/lib/WN-mixin.js +59 -0
  23. package/lib/WN-mixin.js.map +1 -0
  24. package/lib/WN.d.ts +34 -0
  25. package/lib/WN.js +145 -0
  26. package/lib/WN.js.map +1 -0
  27. package/lib/WS.d.ts +11 -0
  28. package/lib/WS.js +32 -0
  29. package/lib/WS.js.map +1 -0
  30. package/lib/WSH.d.ts +11 -0
  31. package/lib/WSH.js +29 -0
  32. package/lib/WSH.js.map +1 -0
  33. package/lib/WT.d.ts +12 -0
  34. package/lib/WT.js +39 -0
  35. package/lib/WT.js.map +1 -0
  36. package/lib/Welem.d.ts +49 -0
  37. package/lib/Welem.js +173 -0
  38. package/lib/Welem.js.map +1 -0
  39. package/lib/Wfrag.d.ts +15 -0
  40. package/lib/Wfrag.js +56 -0
  41. package/lib/Wfrag.js.map +1 -0
  42. package/lib/Whelem.d.ts +17 -0
  43. package/lib/Whelem.js +69 -0
  44. package/lib/Whelem.js.map +1 -0
  45. package/lib/Wnode.d.ts +6 -0
  46. package/lib/Wnode.js +33 -0
  47. package/lib/Wnode.js.map +1 -0
  48. package/lib/Wshad.d.ts +9 -0
  49. package/lib/Wshad.js +31 -0
  50. package/lib/Wshad.js.map +1 -0
  51. package/lib/bundle.js +737 -0
  52. package/lib/bundle.js.map +7 -0
  53. package/lib/bundle.min.js +3 -0
  54. package/lib/case.d.ts +3 -0
  55. package/lib/case.js +34 -0
  56. package/lib/case.js.map +1 -0
  57. package/lib/case.test.d.ts +1 -0
  58. package/lib/case.test.js +79 -0
  59. package/lib/case.test.js.map +1 -0
  60. package/lib/h.d.ts +3 -0
  61. package/lib/h.js +9 -0
  62. package/lib/h.js.map +1 -0
  63. package/lib/index.d.ts +11 -0
  64. package/lib/index.js +12 -0
  65. package/lib/index.js.map +1 -0
  66. package/lib/util.d.ts +5 -0
  67. package/lib/util.js +19 -0
  68. package/lib/util.js.map +1 -0
  69. package/lib/wrap-unwrap.d.ts +22 -0
  70. package/lib/wrap-unwrap.js +68 -0
  71. package/lib/wrap-unwrap.js.map +1 -0
  72. package/package.json +56 -26
  73. package/CSS.js +0 -145
  74. package/Router.js +0 -89
  75. package/Selector.js +0 -175
  76. package/Tag.js +0 -827
  77. package/control.js +0 -74
  78. package/events.js +0 -16
  79. package/index.js +0 -26
  80. package/observer.js +0 -27
  81. package/rollup.config.js +0 -25
  82. package/unit.js +0 -78
  83. package/util.js +0 -153
  84. package/win.js +0 -11
package/control.js DELETED
@@ -1,74 +0,0 @@
1
- import { isFn, isNum } from './util.js'
2
-
3
- function parseRangeArguments(arr) {
4
- if (arr.length < 2) {
5
- throw new TypeError(`Expected at least 2 arguments but got ${arr}`)
6
- }
7
- if (!isNum(arr[0])) {
8
- throw new TypeError(`The first argument must be a number but got ${arr[0]}`)
9
- }
10
- if (isFn(arr[1])) {
11
- // range(end, fn, ...extraParams)
12
- const [ end, fn, ...extraParams ] = arr
13
- return { start: 0, end, step: 1, fn, extraParams }
14
- } else if (isFn(arr[2])) {
15
- // range(start, end, fn, ...extraParams)
16
- const [ start, end, fn, ...extraParams ] = arr
17
- return { start, end, step: 1, fn, extraParams }
18
- } else if (isFn(arr[3])) {
19
- // // range(start, end, step, fn, ...extraParams)
20
- const [ start, end, step, fn, ...extraParams ] = arr
21
- return { start, end, step, fn, extraParams }
22
- }
23
- throw new TypeError(`Which function do you want to run? Got ${arr}`)
24
- }
25
-
26
- export const control = {
27
- /**
28
- * @remark if inside the function you need to refer to the tag (exposed as `this`), just remember
29
- * to use a classic function instead of an arrow function
30
- */
31
- if(condition, fn, ...extraParams) {
32
- if (condition) {
33
- return this.run(fn, ...extraParams)
34
- }
35
- return this
36
- },
37
-
38
- forEach(arr, fn, ...extraParams) {
39
- arr.forEach(item => {
40
- this.run(fn, item, ...extraParams)
41
- })
42
-
43
- return this
44
- },
45
-
46
- times(n, fn, ...extraParams) {
47
- return this.range(1, n + 1, 1, fn, ...extraParams)
48
- },
49
-
50
- // range(start, end, step, fn, ...extraParams)
51
- // range(start, end, fn, ...extraParams) // step = 1
52
- // range(end, fn, ...extraParams) // start = 0, step = 1
53
- range() {
54
- const { start, end, step, fn, extraParams } = parseRangeArguments(Array.from(arguments))
55
- if (!isNum(start) || !isNum(end) || !isNum(step)) {
56
- throw new TypeError(`Expected numbers but got: start=${start}, end=${end}, step=${step}`)
57
- }
58
- if (step === 0) {
59
- throw new Error(`The step cannot be zero`)
60
- }
61
- if ((start < end && step < 0) || (start > end && step > 0)) {
62
- throw new Error(`This loop will never end: start=${start}, end=${end}, step=${step}`)
63
- }
64
- for (let i = start; i < end; i += step) {
65
- this.run(fn, i, ...extraParams)
66
- }
67
- return this
68
- },
69
-
70
- run(fn, ...extraParams) {
71
- fn.call(this, this, ...extraParams)
72
- return this
73
- },
74
- }
package/events.js DELETED
@@ -1,16 +0,0 @@
1
- export const events = {
2
- on(eventName, handler) {
3
- this.el.addEventListener(eventName, handler)
4
- return this
5
- },
6
-
7
- once(eventName, handler) {
8
- this.el.addEventListener(eventName, handler, { once: true })
9
- return this
10
- },
11
-
12
- off(eventName, handler) {
13
- this.el.removeEventListener(eventName, handler)
14
- return this
15
- }
16
- }
package/index.js DELETED
@@ -1,26 +0,0 @@
1
- export { rnd, qut, runOnce, ent, doc } from './util.js'
2
- export * from './unit.js'
3
- export * from './Selector.js'
4
- export * from './Tag.js'
5
- export * from './Router.js'
6
- import { win } from './win.js'
7
- import { startObserving, stopObserving } from './observer.js'
8
-
9
- const DOMContentLoaded = 'DOMContentLoaded'
10
-
11
- export function ready(fn) {
12
- const { document: { readyState } } = window
13
- if (readyState === 'complete' || readyState === 'loaded' || readyState === 'interactive') {
14
- fn()
15
- } else {
16
- function onReady() {
17
- win.off(DOMContentLoaded, onReady)
18
- fn()
19
- }
20
- win.on(DOMContentLoaded, onReady)
21
- }
22
- }
23
-
24
- win.on('unload', () => stopObserving())
25
-
26
- ready(() => startObserving())
package/observer.js DELETED
@@ -1,27 +0,0 @@
1
- // https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events
2
- export const attachedEvent = new Event('attached')
3
- export const detachedEvent = new Event('detached')
4
-
5
- export function mutationObservationCb(mutationsList, observer) {
6
- for (var mutation of mutationsList) {
7
- if (mutation.type == 'childList') {
8
- mutation.addedNodes.forEach(n => n.dispatchEvent(attachedEvent))
9
- mutation.removedNodes.forEach(n => n.dispatchEvent(detachedEvent))
10
- }
11
- }
12
- };
13
-
14
- var mo
15
-
16
- export function startObserving(observationRoot = document.documentElement) {
17
- // https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
18
- mo = new MutationObserver(mutationObservationCb)
19
- const config = { childList: true, subtree: true };
20
- mo.observe(observationRoot, config);
21
- }
22
-
23
- export function stopObserving() {
24
- if (mo) {
25
- mo.disconnect()
26
- }
27
- }
package/rollup.config.js DELETED
@@ -1,25 +0,0 @@
1
- import { terser } from 'rollup-plugin-terser'
2
- import gzipPlugin from 'rollup-plugin-gzip'
3
-
4
- module.exports = {
5
- input: 'index.js',
6
- plugins: [
7
- terser({ include: ['jj.min.js', 'esm'] }),
8
- gzipPlugin()
9
- ],
10
- output: [
11
- {
12
- compact: false,
13
- indent: false,
14
- file: 'dist/jj.js',
15
- format: 'esm'
16
- },
17
- {
18
- compact: true,
19
- indent: false,
20
- sourcemap: true,
21
- file: 'dist/jj.min.js',
22
- format: 'esm'
23
- },
24
- ]
25
- };
package/unit.js DELETED
@@ -1,78 +0,0 @@
1
- import { isStr, alias } from './util.js'
2
-
3
- class Dim {
4
- constructor(value, unit) {
5
- if (isStr(value)) {
6
- this.parse(value)
7
- } else {
8
- this.value = value
9
- this.unit = unit
10
- }
11
- }
12
-
13
- clone() {
14
- return new Dim(this.value, this.unit)
15
- }
16
-
17
- parse(str) {
18
- const parts = str.match(/([-+]?[0-9.]+)([%\w]*)/)
19
- if (parts) {
20
- const [, value, unit] = parts
21
- this.value = value
22
- this.unit = unit
23
- }
24
- throw new SyntaxError(`Could not parse ${str} as a CSS Dimention`)
25
- }
26
-
27
- toString() {
28
- return `${this.value}${this.unit}`
29
- }
30
-
31
- [Symbol.toPrimitive](hint) {
32
- if (hint === 'string') {
33
- return this.toString()
34
- }
35
- return this.value
36
- }
37
- }
38
-
39
- alias(Dim, {
40
- toString: 'toJSON'
41
- })
42
-
43
- export function isDim(val) {
44
- return val instanceof Dim
45
- }
46
-
47
- export function perc(num) {
48
- return new Dim(num, '%')
49
- }
50
-
51
- export function em(num) {
52
- return new Dim(num, 'em')
53
- }
54
-
55
- export function rem(num) {
56
- return new Dim(num, 'rem')
57
- }
58
-
59
- export function px(num) {
60
- return new Dim(num, 'px')
61
- }
62
-
63
- export function vh(num) {
64
- return new Dim(num, 'vh')
65
- }
66
-
67
- export function vw(num) {
68
- return new Dim(num, 'vw')
69
- }
70
-
71
- export function col(r, g, b, a) {
72
- if (g === undefined && b === undefined && a === undefined) {
73
- if (isStr(r, 1)) {
74
- return `#${r}`
75
- }
76
- }
77
- throw new Error('TODO: Use case not implemented yet')
78
- }
package/util.js DELETED
@@ -1,153 +0,0 @@
1
- export const INDENT = ' '
2
- export const NEWLINE = '\n'
3
-
4
- export function isArr(x) {
5
- return Array.isArray(x)
6
- }
7
-
8
- export function arrFrom(x) {
9
- return Array.from(x)
10
- }
11
-
12
- export function toArray(a) {
13
- return isArr(a) ? a : [a]
14
- }
15
-
16
- export function ind(indentation, addition = 0) {
17
- if (indentation < 0) {
18
- return ''
19
- }
20
- indentation += addition
21
- if (ind.cache[indentation] === undefined) {
22
- ind.cache[indentation] = INDENT.repeat(indentation)
23
- }
24
- return ind.cache[indentation]
25
- }
26
- ind.cache = ['', INDENT]
27
-
28
- export function nl(indentation) {
29
- return indentation < 0 ? '' : NEWLINE
30
- }
31
-
32
- export function mapKeyVal(obj, fn) {
33
- return Object.entries(obj).map(([k, v]) => fn(k, v, obj))
34
- }
35
-
36
- export function isObj(a) {
37
- return a && typeof a === 'object'
38
- }
39
-
40
- export function isStr(a, minLength = 0) {
41
- return typeof a === 'string' && a.length >= minLength
42
- }
43
-
44
- export function isNum(a) {
45
- return typeof a === 'number' && Number.isFinite(a)
46
- }
47
-
48
- export function isFn(a) {
49
- return typeof a === 'function'
50
- }
51
-
52
- export function isBool(a) {
53
- return typeof a === 'boolean'
54
- }
55
-
56
- export function isDef(a) {
57
- return a !== undefined
58
- }
59
-
60
- export function camel2kebab(str) {
61
- return str.replace(/([A-Z])/g, ch => '-' + ch.toLowerCase())
62
- }
63
-
64
- export function cssValue(v) {
65
- if (isArr(v)) {
66
- return v.join(' ')
67
- }
68
- return v
69
- }
70
-
71
- function embed(start, end, ...contents) {
72
- return start + contents.join('') + end
73
- }
74
-
75
- export function par(...strArr) {
76
- return embed('(', ')', ...strArr)
77
- }
78
-
79
- export function qut(...strArr) {
80
- const str = strArr.join('').replace('"', '\\"')
81
- return embed('"', '"', str)
82
- }
83
-
84
- export function ent(entity) {
85
- if (isStr(entity)) {
86
- return '&' + entity + ';'
87
- } else if (isNum(entity) && Number.isInteger(entity)) {
88
- return `&#${entity};`
89
- }
90
- throw new TypeError(`Cannot make HTML entity from ${entity}`)
91
- }
92
-
93
- export function sqBra(...strArr) {
94
- return embed('[', ']', ...strArr)
95
- }
96
-
97
- export function rnd(prefix) {
98
- const randomStr = Math.random().toString(36).substr(2)
99
- // the resulting string should always start with a letter, otherwise it won't work as class or id
100
- return isStr(prefix) ? `${prefix}-${randomStr}` : randomStr
101
- }
102
-
103
- export function alias(obj, aliasDic) {
104
- const prt = obj.prototype
105
-
106
- function assignTarget(dst, src) {
107
- if (prt[dst] !== undefined) {
108
- throw new Error(`${obj.name} already has a method called ${dst}`)
109
- }
110
- prt[dst] = prt[src]
111
- }
112
-
113
- mapKeyVal(aliasDic, (src, dst) => {
114
- if (isArr(dst)) {
115
- dst.forEach(d => assignTarget(d, src))
116
- } else {
117
- assignTarget(dst, src)
118
- }
119
- })
120
- }
121
-
122
- const ranOnce = Symbol('ran once flag')
123
- export function runOnce(fn, ...args) {
124
- if (isFn(fn) && !fn[ranOnce]) {
125
- fn.apply(undefined, args)
126
- fn[ranOnce] = true
127
- }
128
- }
129
-
130
- export const doc = {
131
- el(tagName, ns) {
132
- return isStr(ns) ? document.createElementNS(ns, tagName) : document.createElement(tagName)
133
- },
134
- frag() {
135
- return document.createDocumentFragment()
136
- },
137
- text(...strArr) {
138
- return document.createTextNode(String(strArr.flat().join('')))
139
- },
140
- comm(...strArr) {
141
- return document.createComment(String(strArr.flat().join('')))
142
- },
143
- get body() {
144
- return document.body
145
- },
146
- get head() {
147
- return document.body.head
148
- },
149
- }
150
-
151
- export function isComponent(obj) {
152
- return isObj(obj) && isObj(obj.root)
153
- }
package/win.js DELETED
@@ -1,11 +0,0 @@
1
- import { events } from './events.js'
2
-
3
- class Window {
4
- constructor(windowRef) {
5
- this.el = windowRef
6
- }
7
- }
8
-
9
- Object.assign(Window.prototype, events)
10
-
11
- export const win = new Window(window)