jj 0.1.1 → 2.1.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 +36 -7
- package/lib/WC.d.ts +45 -0
- package/lib/WC.js +118 -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 +43 -0
- package/lib/WE.js +133 -0
- package/lib/WE.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/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/bundle.js +706 -0
- package/lib/bundle.js.map +7 -0
- package/lib/bundle.min.js +2 -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 +4 -0
- package/lib/util.js +11 -0
- package/lib/util.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/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
|
-
})
|