jj 0.1.1 → 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.
- package/LICENSE +21 -0
- package/README.md +35 -7
- package/lib/ComponentFiles.d.ts +35 -0
- package/lib/ComponentFiles.js +116 -0
- package/lib/ComponentFiles.js.map +1 -0
- package/lib/WC.d.ts +33 -0
- package/lib/WC.js +160 -0
- package/lib/WC.js.map +1 -0
- package/lib/WDF.d.ts +11 -0
- package/lib/WDF.js +31 -0
- package/lib/WDF.js.map +1 -0
- package/lib/WE.d.ts +42 -0
- package/lib/WE.js +132 -0
- package/lib/WE.js.map +1 -0
- package/lib/WF.d.ts +14 -0
- package/lib/WF.js +44 -0
- package/lib/WF.js.map +1 -0
- package/lib/WHE.d.ts +21 -0
- package/lib/WHE.js +75 -0
- package/lib/WHE.js.map +1 -0
- package/lib/WN-mixin.d.ts +9 -0
- package/lib/WN-mixin.js +59 -0
- package/lib/WN-mixin.js.map +1 -0
- package/lib/WN.d.ts +34 -0
- package/lib/WN.js +145 -0
- package/lib/WN.js.map +1 -0
- package/lib/WS.d.ts +11 -0
- package/lib/WS.js +32 -0
- package/lib/WS.js.map +1 -0
- package/lib/WSH.d.ts +11 -0
- package/lib/WSH.js +29 -0
- package/lib/WSH.js.map +1 -0
- package/lib/WT.d.ts +12 -0
- package/lib/WT.js +39 -0
- package/lib/WT.js.map +1 -0
- package/lib/Welem.d.ts +49 -0
- package/lib/Welem.js +173 -0
- package/lib/Welem.js.map +1 -0
- package/lib/Wfrag.d.ts +15 -0
- package/lib/Wfrag.js +56 -0
- package/lib/Wfrag.js.map +1 -0
- package/lib/Whelem.d.ts +17 -0
- package/lib/Whelem.js +69 -0
- package/lib/Whelem.js.map +1 -0
- package/lib/Wnode.d.ts +6 -0
- package/lib/Wnode.js +33 -0
- package/lib/Wnode.js.map +1 -0
- package/lib/Wshad.d.ts +9 -0
- package/lib/Wshad.js +31 -0
- package/lib/Wshad.js.map +1 -0
- package/lib/bundle.js +737 -0
- package/lib/bundle.js.map +7 -0
- package/lib/bundle.min.js +3 -0
- package/lib/case.d.ts +3 -0
- package/lib/case.js +34 -0
- package/lib/case.js.map +1 -0
- package/lib/case.test.d.ts +1 -0
- package/lib/case.test.js +79 -0
- package/lib/case.test.js.map +1 -0
- package/lib/h.d.ts +3 -0
- package/lib/h.js +9 -0
- package/lib/h.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -0
- package/lib/util.d.ts +5 -0
- package/lib/util.js +19 -0
- package/lib/util.js.map +1 -0
- package/lib/wrap-unwrap.d.ts +22 -0
- package/lib/wrap-unwrap.js +68 -0
- package/lib/wrap-unwrap.js.map +1 -0
- package/package.json +56 -26
- package/CSS.js +0 -145
- package/Router.js +0 -89
- package/Selector.js +0 -175
- package/Tag.js +0 -827
- package/control.js +0 -74
- package/dist/jj.js +0 -1580
- package/dist/jj.js.gz +0 -0
- package/dist/jj.min.js +0 -1
- package/dist/jj.min.js.gz +0 -0
- package/dist/jj.min.js.map +0 -1
- package/events.js +0 -16
- package/index.js +0 -26
- package/observer.js +0 -27
- package/rollup.config.js +0 -25
- package/unit.js +0 -78
- package/util.js +0 -153
- package/win.js +0 -11
package/CSS.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { mapKeyVal, camel2kebab, nl, ind, isObj, isNum, isStr, isArr, qut } from './util.js'
|
|
2
|
-
import { isDim } from './unit.js'
|
|
3
|
-
|
|
4
|
-
function isAtRule(selectorTxt) {
|
|
5
|
-
return selectorTxt.trimLeft().startsWith('@')
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function toValue(val) {
|
|
9
|
-
if (isStr(val)) {
|
|
10
|
-
if (val.trim() === '') {
|
|
11
|
-
return qut(val)
|
|
12
|
-
}
|
|
13
|
-
return val
|
|
14
|
-
}
|
|
15
|
-
if (isNum(val)) {
|
|
16
|
-
return String(val)
|
|
17
|
-
}
|
|
18
|
-
if (isDim(val)) {
|
|
19
|
-
return String(val)
|
|
20
|
-
} else if (isArr(val)) {
|
|
21
|
-
return val.join(' ')
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function extractRules(selectorTxt, bodyObj) {
|
|
26
|
-
const baseRule = new SimpleRule(selectorTxt)
|
|
27
|
-
const ownProps = baseRule.bodyObj
|
|
28
|
-
const nestedRules = [baseRule]
|
|
29
|
-
mapKeyVal(bodyObj, (key, val) => {
|
|
30
|
-
const v = toValue(val)
|
|
31
|
-
if (v !== undefined) {
|
|
32
|
-
ownProps[key] = v
|
|
33
|
-
} else if (isAtRule(key)) {
|
|
34
|
-
nestedRules.push(new WrapperRule(key, { [selectorTxt]: val }))
|
|
35
|
-
} else {
|
|
36
|
-
let nestedSelectorTxt = key.replace(/&/g, selectorTxt)
|
|
37
|
-
if (nestedSelectorTxt === key) {
|
|
38
|
-
// No & was present, so the replacement didn't do anything. Nest the selectors
|
|
39
|
-
nestedSelectorTxt = selectorTxt + ' ' + key
|
|
40
|
-
}
|
|
41
|
-
nestedRules.push(new NestedRule(nestedSelectorTxt, val))
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
return nestedRules
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function propVal(indentation, prop, val) {
|
|
48
|
-
const colon = indentation < 0 ? ':' : ': '
|
|
49
|
-
return camel2kebab(prop)
|
|
50
|
-
+ colon
|
|
51
|
-
+ toValue(val)
|
|
52
|
-
+ ';'
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
class SimpleRule {
|
|
56
|
-
constructor(selectorTxt, bodyObj = {}) {
|
|
57
|
-
this.selectorTxt = selectorTxt
|
|
58
|
-
this.bodyObj = bodyObj
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get isEmpty() {
|
|
62
|
-
return Object.keys(this.bodyObj).length === 0
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
toString(indentation = 0) {
|
|
66
|
-
if (this.isEmpty) {
|
|
67
|
-
return indentation >= 0 ? ind(indentation) + `/* ${this.selectorTxt} {} */`: ''
|
|
68
|
-
}
|
|
69
|
-
let ret = ind(indentation) + this.selectorTxt
|
|
70
|
-
if (indentation >= 0) {
|
|
71
|
-
ret += ' '
|
|
72
|
-
}
|
|
73
|
-
ret += '{' + nl(indentation)
|
|
74
|
-
const space = ind(indentation, 1)
|
|
75
|
-
ret += mapKeyVal(this.bodyObj, (key, val) => space + propVal(indentation, key, val))
|
|
76
|
-
.join(nl(indentation))
|
|
77
|
-
if (indentation >= 0) {
|
|
78
|
-
ret += nl(indentation) + ind(indentation)
|
|
79
|
-
}
|
|
80
|
-
ret += '}'
|
|
81
|
-
return ret
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
class NestedRule {
|
|
86
|
-
constructor(selectorTxt, bodyObj) {
|
|
87
|
-
this.selectorTxt = selectorTxt
|
|
88
|
-
this.bodyObj = bodyObj
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
toString(indentation = 0) {
|
|
92
|
-
if (isObj(this.bodyObj)) {
|
|
93
|
-
return extractRules(this.selectorTxt, this.bodyObj)
|
|
94
|
-
.map(rule => rule.toString(indentation))
|
|
95
|
-
.join(nl(indentation))
|
|
96
|
-
}
|
|
97
|
-
const v = toValue(this.bodyObj)
|
|
98
|
-
if (v !== undefined) {
|
|
99
|
-
return ind(indentation) + propVal(indentation, this.selectorTxt, v)
|
|
100
|
-
}
|
|
101
|
-
return ind(indentation) + this.selectorTxt
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
class WrapperRule {
|
|
106
|
-
constructor(selectorTxt, ruleSet) {
|
|
107
|
-
this.selectorTxt = selectorTxt
|
|
108
|
-
this.ruleSet = ruleSet
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
toString(indentation = 0) {
|
|
112
|
-
let ret = ind(indentation) + this.selectorTxt
|
|
113
|
-
if (isObj(this.ruleSet)) {
|
|
114
|
-
const childIndentation = indentation >= 0 ? indentation + 1 : -1
|
|
115
|
-
if (indentation >= 0) {
|
|
116
|
-
ret += ' '
|
|
117
|
-
}
|
|
118
|
-
ret += '{' + nl(indentation)
|
|
119
|
-
ret += objToRulesArr(this.ruleSet)
|
|
120
|
-
.map(rule => rule.toString(childIndentation))
|
|
121
|
-
.join(nl(indentation))
|
|
122
|
-
ret += nl(indentation)
|
|
123
|
-
ret += ind(indentation) + '}'
|
|
124
|
-
} else {
|
|
125
|
-
ret += ';'
|
|
126
|
-
}
|
|
127
|
-
return ret
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function objToRulesArr(obj) {
|
|
132
|
-
if (!isObj(obj)){
|
|
133
|
-
if (isStr(obj)) {
|
|
134
|
-
obj = { [obj]: null }
|
|
135
|
-
} else {
|
|
136
|
-
throw new TypeError(`Invalid style descriptor: ${obj}`)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return mapKeyVal(obj, (selectorTxt, bodyObj) => {
|
|
140
|
-
if (isAtRule(selectorTxt)) {
|
|
141
|
-
return new WrapperRule(selectorTxt, bodyObj)
|
|
142
|
-
}
|
|
143
|
-
return new NestedRule(selectorTxt, bodyObj)
|
|
144
|
-
})
|
|
145
|
-
}
|
package/Router.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { win } from './win.js'
|
|
2
|
-
import { isFn, isStr, isObj } from './util.js'
|
|
3
|
-
|
|
4
|
-
function match(regexp, pathname) {
|
|
5
|
-
if(isStr(regexp)) {
|
|
6
|
-
console.log('boo', regexp, pathname)
|
|
7
|
-
return regexp === pathname
|
|
8
|
-
}
|
|
9
|
-
if (regexp instanceof RegExp) {
|
|
10
|
-
const parseResult = pathname.match(regexp)
|
|
11
|
-
return parseResult || false
|
|
12
|
-
}
|
|
13
|
-
throw new TypeError(`Invalid route regexp: ${regexp}`)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const rootRouterMap = new WeakMap()
|
|
17
|
-
|
|
18
|
-
class Router {
|
|
19
|
-
constructor(root) {
|
|
20
|
-
if (!isObj(root) || !isFn(root.run)) {
|
|
21
|
-
throw new Error(`Root must have a run method but got ${root}`)
|
|
22
|
-
}
|
|
23
|
-
this.routes = []
|
|
24
|
-
this.root = root
|
|
25
|
-
this.isMatched = false
|
|
26
|
-
rootRouterMap.set(root, this)
|
|
27
|
-
|
|
28
|
-
const matchThis = (state) => this.runMatches(state)
|
|
29
|
-
win.on('popstate', matchThis).on('hashchange', matchThis)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
addRoute(regexp, handler) {
|
|
33
|
-
if (isFn(this.defRouteHandler)) {
|
|
34
|
-
throw new Error(`Cannot add a route after the default route is set`)
|
|
35
|
-
}
|
|
36
|
-
if (!isFn(handler)) {
|
|
37
|
-
throw new TypeError(`Expected a route handler function but got ${handler}`)
|
|
38
|
-
}
|
|
39
|
-
const newRoute = { regexp, handler }
|
|
40
|
-
this.routes.push(newRoute)
|
|
41
|
-
if (!this.isMatched) {
|
|
42
|
-
this._runRoute(undefined, newRoute)
|
|
43
|
-
}
|
|
44
|
-
return this
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
addDefRoute(handler) {
|
|
48
|
-
if (isFn(this.defRouteHandler)) {
|
|
49
|
-
throw new Error(`There is already a default route handler`)
|
|
50
|
-
}
|
|
51
|
-
if (!isFn(handler)) {
|
|
52
|
-
throw new TypeError(`Expected a default route handler function but got ${handler}`)
|
|
53
|
-
}
|
|
54
|
-
this.defRouteHandler = handler
|
|
55
|
-
if (!this.isMatched) {
|
|
56
|
-
this._runDefRoute()
|
|
57
|
-
}
|
|
58
|
-
return this
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
_runRoute(state, { regexp, handler}, pathname = window.location.pathname) {
|
|
62
|
-
const matchResult = match(regexp, pathname)
|
|
63
|
-
if (matchResult) {
|
|
64
|
-
this.isMatched = true
|
|
65
|
-
this.root.run(handler, state, matchResult)
|
|
66
|
-
}
|
|
67
|
-
return !!matchResult
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
_runDefRoute() {
|
|
71
|
-
this.root.run(this.defRouteHandler)
|
|
72
|
-
return this
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
runMatches(state, pathname = window.location.pathname) {
|
|
76
|
-
const someRouteMatched = this.routes.some(route => this._runRoute(state, route, pathname))
|
|
77
|
-
if (!someRouteMatched) {
|
|
78
|
-
return this._runDefRoute()
|
|
79
|
-
}
|
|
80
|
-
return this
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function router(root) {
|
|
85
|
-
if (!isObj(root) || !isFn(root.run)) {
|
|
86
|
-
throw new TypeError(`root should be a Tag instance. Got ${root}`)
|
|
87
|
-
}
|
|
88
|
-
return rootRouterMap.get(root) || new Router(root)
|
|
89
|
-
}
|
package/Selector.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { sqBra, qut, alias, rnd, mapKeyVal } from './util.js'
|
|
2
|
-
|
|
3
|
-
class Selector {
|
|
4
|
-
constructor(selector = '') {
|
|
5
|
-
this.selector = selector
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
toString() {
|
|
9
|
-
return this.selector
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
css(ruleObj) {
|
|
13
|
-
return { [this.selector]: ruleObj }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
clone() {
|
|
17
|
-
return new Selector(this.selector)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
append(...str) {
|
|
21
|
-
if (str.length) {
|
|
22
|
-
this.selector += str.map(s => isSel(s) ? s.selector : s).join('')
|
|
23
|
-
}
|
|
24
|
-
return this
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
at(str) {
|
|
28
|
-
return this.append('@', str)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get _() {
|
|
32
|
-
return this.append(' ')
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// [attribute] [target] Selects all elements with a target attribute
|
|
36
|
-
// [attribute=value] [target=_blank] Selects all elements with target="_blank"
|
|
37
|
-
attr(attrName, attrValue) {
|
|
38
|
-
return attrValue === undefined ?
|
|
39
|
-
this.append(sqBra(attrName)) :
|
|
40
|
-
this.append(sqBra(attrName, '=', qut(attrValue)))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// [attribute~=value] [title~=flower] Selects all elements with a title attribute containing the word "flower"
|
|
44
|
-
attrValArrContains(attrName, attrValue) {
|
|
45
|
-
return this.append(sqBra(attrName, '~=', qut(attrValue)))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// [attribute^=value] a[href^="https"] Selects every <a> element whose href attribute value begins with "https"
|
|
49
|
-
attrValStartsWith(attrName, attrValue) {
|
|
50
|
-
return this.append(sqBra(attrName, '^=', qut(attrValue)))
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// [attribute$=value] a[href$=".pdf"] Selects every <a> element whose href attribute value ends with ".pdf"
|
|
54
|
-
attrValEndsWith(attrName, attrValue) {
|
|
55
|
-
return this.append(sqBra(attrName, '$=', qut(attrValue)))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// [attribute*=value] a[href*="w3schools"] Selects every <a> element whose href attribute value contains the substring "w3schools"
|
|
59
|
-
attrValContains(attrName, attrValue) {
|
|
60
|
-
return this.append(sqBra(attrName, '*=', qut(attrValue)))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
class(...classNames) {
|
|
64
|
-
classNames.forEach(c => this.append('.', c))
|
|
65
|
-
return this
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
BEM(block, element, modifier) {
|
|
69
|
-
this.B(block)
|
|
70
|
-
if (element !== undefined) {
|
|
71
|
-
this.E(element)
|
|
72
|
-
}
|
|
73
|
-
if (modifier !== undefined) {
|
|
74
|
-
this.M(modifier)
|
|
75
|
-
}
|
|
76
|
-
return this
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
E(element) {
|
|
80
|
-
return this.append('__', element)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
M(modifier) {
|
|
84
|
-
return this.append('--', modifier)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
id(idString) {
|
|
88
|
-
return this.append('#', idString)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
pClass(pseudo) {
|
|
92
|
-
return this.append(':', pseudo)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
pEl(pseudo) {
|
|
96
|
-
return this.append('::', pseudo)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
par(...str) {
|
|
100
|
-
return this.append('(', ...str, ')')
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
prop(prop, val) {
|
|
104
|
-
return this.par(prop, ':', val)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
nthChild(str) {
|
|
108
|
-
return this.pClass(`nth-child(${str})`)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
firstChild() {
|
|
112
|
-
return this.pClass(`first-child`)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
rnd(prefix = '') {
|
|
116
|
-
return this.append(rnd(prefix))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
[Symbol.toPrimitive](hint) {
|
|
120
|
-
if (hint === 'string') {
|
|
121
|
-
return this.toString()
|
|
122
|
-
}
|
|
123
|
-
return this.value
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// B, E, M are for Block Element Modifier: http://getbem.com/introduction/
|
|
128
|
-
alias(Selector, {
|
|
129
|
-
class: 'B',
|
|
130
|
-
append: ['add', 'el', 'tag', 'com', 'cond', 'star', 'all', 'sel', 'concat'],
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const shortHands = {
|
|
134
|
-
[Symbol.toPrimitive]: 'toString',
|
|
135
|
-
'>': ['gt', 'parentOf'],
|
|
136
|
-
'*': ['star', 'all'],
|
|
137
|
-
'~': ['tilde', 'precedes'],
|
|
138
|
-
'+': ['plus', 'followedBy'],
|
|
139
|
-
',': ['comma', 'or'],
|
|
140
|
-
// TODO: there's :not() pseudo-class as well and that one takes a selector
|
|
141
|
-
'not': ['not'],
|
|
142
|
-
'only': ['only'],
|
|
143
|
-
'and': ['and'],
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
mapKeyVal(shortHands, (str, vals) => {
|
|
147
|
-
vals.forEach(v => {
|
|
148
|
-
Selector.prototype[v] = function () {
|
|
149
|
-
return this.append(str)
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
export function isSel(v) {
|
|
155
|
-
return v instanceof Selector
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function _sel(param) {
|
|
159
|
-
if (isSel(param)) {
|
|
160
|
-
return param
|
|
161
|
-
}
|
|
162
|
-
return new Selector(param)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export const sel = new Proxy(_sel, {
|
|
166
|
-
get(_sel, prop) {
|
|
167
|
-
const selector = new Selector()
|
|
168
|
-
if (prop in selector) {
|
|
169
|
-
return selector[prop]
|
|
170
|
-
} else {
|
|
171
|
-
selector.append(prop)
|
|
172
|
-
return selector
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
})
|