catchword 0.0.0-stage → 1.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 +314 -2
- package/bin/catchword.js +8 -0
- package/bin/falcon.js +5 -0
- package/dist/cli/adb.d.ts +6 -0
- package/dist/cli/adb.js +52 -0
- package/dist/cli/audit.d.ts +4 -0
- package/dist/cli/audit.js +91 -0
- package/dist/cli/build.d.ts +13 -0
- package/dist/cli/build.js +139 -0
- package/dist/cli/clean.d.ts +1 -0
- package/dist/cli/clean.js +15 -0
- package/dist/cli/create.d.ts +4 -0
- package/dist/cli/create.js +60 -0
- package/dist/cli/dev.d.ts +10 -0
- package/dist/cli/dev.js +23 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.js +243 -0
- package/dist/cli/native.d.ts +18 -0
- package/dist/cli/native.js +232 -0
- package/dist/cli/simulator.d.ts +8 -0
- package/dist/cli/simulator.js +77 -0
- package/dist/cli/upload.d.ts +9 -0
- package/dist/cli/upload.js +135 -0
- package/dist/cli/util.d.ts +8 -0
- package/dist/cli/util.js +43 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +90 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +51 -0
- package/dist/native/api.d.ts +46 -0
- package/dist/native/api.js +185 -0
- package/dist/native/build.d.ts +47 -0
- package/dist/native/build.js +407 -0
- package/dist/native/elf.d.ts +15 -0
- package/dist/native/elf.js +200 -0
- package/dist/native/types.d.ts +9 -0
- package/dist/native/types.js +91 -0
- package/dist/native/wsl.d.ts +7 -0
- package/dist/native/wsl.js +29 -0
- package/dist/plugin/app-entry.d.ts +6 -0
- package/dist/plugin/app-entry.js +115 -0
- package/dist/plugin/assets.d.ts +4 -0
- package/dist/plugin/assets.js +84 -0
- package/dist/plugin/config.d.ts +14 -0
- package/dist/plugin/config.js +80 -0
- package/dist/plugin/context.d.ts +58 -0
- package/dist/plugin/context.js +255 -0
- package/dist/plugin/fallback.d.ts +4 -0
- package/dist/plugin/fallback.js +81 -0
- package/dist/plugin/image-service.d.ts +17 -0
- package/dist/plugin/image-service.js +138 -0
- package/dist/plugin/jsapi.d.ts +6 -0
- package/dist/plugin/jsapi.js +82 -0
- package/dist/plugin/output.d.ts +4 -0
- package/dist/plugin/output.js +75 -0
- package/dist/plugin/preview.d.ts +34 -0
- package/dist/plugin/preview.js +459 -0
- package/dist/plugin/sanitize.d.ts +5 -0
- package/dist/plugin/sanitize.js +48 -0
- package/dist/plugin/security.d.ts +4 -0
- package/dist/plugin/security.js +18 -0
- package/dist/plugin/sfc.d.ts +6 -0
- package/dist/plugin/sfc.js +181 -0
- package/dist/plugin/shim.d.ts +4 -0
- package/dist/plugin/shim.js +68 -0
- package/dist/plugin/state.d.ts +31 -0
- package/dist/plugin/state.js +61 -0
- package/dist/plugin/string-table.d.ts +7 -0
- package/dist/plugin/string-table.js +324 -0
- package/dist/plugin/style.d.ts +15 -0
- package/dist/plugin/style.js +114 -0
- package/dist/plugin/template.d.ts +7 -0
- package/dist/plugin/template.js +39 -0
- package/dist/steps/manifest.d.ts +9 -0
- package/dist/steps/manifest.js +60 -0
- package/dist/steps/pack.d.ts +3 -0
- package/dist/steps/pack.js +46 -0
- package/dist/steps/qjsc.d.ts +9 -0
- package/dist/steps/qjsc.js +186 -0
- package/dist/steps/report.d.ts +2 -0
- package/dist/steps/report.js +50 -0
- package/dist/steps/security.d.ts +17 -0
- package/dist/steps/security.js +310 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.js +1 -0
- package/dist/util/class-tokenize.d.ts +2 -0
- package/dist/util/class-tokenize.js +56 -0
- package/dist/util/component-name.d.ts +6 -0
- package/dist/util/component-name.js +120 -0
- package/dist/util/fs.d.ts +14 -0
- package/dist/util/fs.js +70 -0
- package/dist/util/imports.d.ts +2 -0
- package/dist/util/imports.js +173 -0
- package/dist/util/log.d.ts +8 -0
- package/dist/util/log.js +24 -0
- package/package.json +61 -4
- package/template/README.md +38 -0
- package/template/catchword.config.ts +18 -0
- package/template/native/CMakeLists.txt +33 -0
- package/template/native/README.md +34 -0
- package/template/native/api.override.json +7 -0
- package/template/native/include/jsapi_demo.h +10 -0
- package/template/native/lib/README.md +10 -0
- package/template/native/sdk/README.md +6 -0
- package/template/native/src/bridge.cpp +9 -0
- package/template/native/src/jsapi_demo.cpp +11 -0
- package/template/package.json +38 -0
- package/template/src/app.js +45 -0
- package/template/src/app.json +11 -0
- package/template/src/base-page.js +150 -0
- package/template/src/components/HelloWorld.vue +20 -0
- package/template/src/mocks/$jsapi.test.js +5 -0
- package/template/src/mocks/test-module.js +5 -0
- package/template/src/pages/index/index.vue +41 -0
- package/template/src/pages/page/page.vue +63 -0
- package/template/src/shims.d.ts +21 -0
- package/template/src/styles/base.less +23 -0
- package/template/src/styles/mixin.less +32 -0
- package/template/src/styles/var.less +15 -0
- package/template/tsconfig.json +14 -0
- package/vendor/README.md +16 -0
- package/vendor/falcon-styler/.jscsrc +31 -0
- package/vendor/falcon-styler/LICENSE +21 -0
- package/vendor/falcon-styler/README.md +124 -0
- package/vendor/falcon-styler/index.js +273 -0
- package/vendor/falcon-styler/lib/shorthand-parser.js +78 -0
- package/vendor/falcon-styler/lib/util.js +30 -0
- package/vendor/falcon-styler/lib/validator.js +846 -0
- package/vendor/falcon-styler/package.json +32 -0
- package/vendor/licenses/falcon-styler.LICENSE +21 -0
- package/vendor/licenses/weex-template-compiler.README.md +3 -0
- package/vendor/package.json +5 -0
- package/vendor/qjsc/SHA256SUMS +11 -0
- package/vendor/qjsc/bin/darwin/arm64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjsc20200906 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200412 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200705 +0 -0
- package/vendor/qjsc/bin/darwin/x64/qjscbn20200906 +0 -0
- package/vendor/qjsc/bin/linux/qjsc20200705 +0 -0
- package/vendor/qjsc/bin/win32/libgcc_s_dw2-1.dll +0 -0
- package/vendor/qjsc/bin/win32/pthreadGC-3.dll +0 -0
- package/vendor/qjsc/bin/win32/qjsc20200705.exe +0 -0
- package/vendor/web/falcon-js-web.js +863 -0
- package/vendor/web/falcon-jsapi-web.js +479 -0
- package/vendor/web/falcon-vue-render.js +11323 -0
- package/vendor/web/falcon-web-boot.js +4 -0
- package/vendor/web/falcon-web-hud.js +119 -0
- package/vendor/web/falcon-web-style.js +235 -0
- package/vendor/web/vue.runtime.common.dev.js +8467 -0
- package/vendor/web/vue.runtime.common.js +5 -0
- package/vendor/weex-template-compiler/README.md +3 -0
- package/vendor/weex-template-compiler/build.js +4824 -0
- package/vendor/weex-template-compiler/index.js +17 -0
- package/vendor/weex-template-compiler/package.json +25 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var css = require('css')
|
|
4
|
+
var util = require('./lib/util')
|
|
5
|
+
var validateItem = require('./lib/validator').validate
|
|
6
|
+
var shorthandParser = require('./lib/shorthand-parser')
|
|
7
|
+
|
|
8
|
+
// padding & margin shorthand parsing
|
|
9
|
+
function convertLengthShorthand(rule, prop) {
|
|
10
|
+
for (var i = 0; i < rule.declarations.length; i++) {
|
|
11
|
+
var declaration = rule.declarations[i]
|
|
12
|
+
if (declaration.property === prop) {
|
|
13
|
+
var values = declaration.value.split(/\s+/)
|
|
14
|
+
// values[0] = values[0] || 0
|
|
15
|
+
values[1] = values[1] || values[0]
|
|
16
|
+
values[2] = values[2] || values[0]
|
|
17
|
+
values[3] = values[3] || values[1]
|
|
18
|
+
rule.declarations.splice(i, 1)
|
|
19
|
+
rule.declarations.splice(i, 0, { type: 'declaration', property: prop + '-left', value: values[3], position: declaration.position })
|
|
20
|
+
rule.declarations.splice(i, 0, { type: 'declaration', property: prop + '-bottom', value: values[2], position: declaration.position })
|
|
21
|
+
rule.declarations.splice(i, 0, { type: 'declaration', property: prop + '-right', value: values[1], position: declaration.position })
|
|
22
|
+
rule.declarations.splice(i, 0, { type: 'declaration', property: prop + '-top', value: values[0], position: declaration.position })
|
|
23
|
+
// break
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parse `<style>` code to a JSON Object and log errors & warnings
|
|
30
|
+
*
|
|
31
|
+
* @param {string} code
|
|
32
|
+
* @param {function} done which will be called with
|
|
33
|
+
* - err:Error
|
|
34
|
+
* - data.jsonStyle{}: `classname.propname.value`-like object
|
|
35
|
+
* - data.log[{line, column, reason}]
|
|
36
|
+
*/
|
|
37
|
+
function parse(code, done) {
|
|
38
|
+
var ast, err, jsonStyle = {}, log = []
|
|
39
|
+
|
|
40
|
+
// css parse
|
|
41
|
+
ast = css.parse(code, { silent: true })
|
|
42
|
+
|
|
43
|
+
// catch syntax error
|
|
44
|
+
if (ast.stylesheet.parsingErrors && ast.stylesheet.parsingErrors.length) {
|
|
45
|
+
err = ast.stylesheet.parsingErrors
|
|
46
|
+
err.forEach(function (error) {
|
|
47
|
+
log.push({ line: error.line, column: error.column, reason: error.toString().replace('Error', 'ERROR') })
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// walk all
|
|
52
|
+
/* istanbul ignore else */
|
|
53
|
+
if (ast && ast.type === 'stylesheet' && ast.stylesheet &&
|
|
54
|
+
ast.stylesheet.rules && ast.stylesheet.rules.length) {
|
|
55
|
+
ast.stylesheet.rules.forEach(function (rule) {
|
|
56
|
+
var type = rule.type
|
|
57
|
+
var ruleResult = {}
|
|
58
|
+
var ruleLog = []
|
|
59
|
+
|
|
60
|
+
if (type === 'rule') {
|
|
61
|
+
if (rule.declarations && rule.declarations.length) {
|
|
62
|
+
rule.declarations = shorthandParser(rule.declarations)
|
|
63
|
+
// padding & margin shorthand parsing
|
|
64
|
+
convertLengthShorthand(rule, 'padding')
|
|
65
|
+
convertLengthShorthand(rule, 'margin')
|
|
66
|
+
|
|
67
|
+
rule.declarations.forEach(function (declaration) {
|
|
68
|
+
var subType = declaration.type
|
|
69
|
+
var name, value, line, column, subResult, camelCasedName
|
|
70
|
+
|
|
71
|
+
/* istanbul ignore if */
|
|
72
|
+
if (subType !== 'declaration') {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
name = declaration.property
|
|
77
|
+
value = declaration.value
|
|
78
|
+
|
|
79
|
+
// validate declarations and collect them to result
|
|
80
|
+
camelCasedName = util.hyphenedToCamelCase(name)
|
|
81
|
+
subResult = validateItem(camelCasedName, value)
|
|
82
|
+
|
|
83
|
+
/* istanbul ignore else */
|
|
84
|
+
if (typeof subResult.value === 'number' || typeof subResult.value === 'string') {
|
|
85
|
+
ruleResult[camelCasedName] = subResult.value
|
|
86
|
+
}
|
|
87
|
+
if (subResult.log) {
|
|
88
|
+
subResult.log.line = declaration.position.start.line
|
|
89
|
+
subResult.log.column = declaration.position.start.column
|
|
90
|
+
ruleLog.push(subResult.log)
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
rule.selectors.forEach(function (selector) {
|
|
95
|
+
if (selector.match(/^\.[A-Za-z0-9_\-:]+$/)) {
|
|
96
|
+
var className = selector.slice(1)
|
|
97
|
+
|
|
98
|
+
// handle pseudo class
|
|
99
|
+
var pseudoIndex = className.indexOf(':')
|
|
100
|
+
if (pseudoIndex > -1) {
|
|
101
|
+
var pseudoCls = className.slice(pseudoIndex)
|
|
102
|
+
className = className.slice(0, pseudoIndex)
|
|
103
|
+
var pseudoRuleResult = {}
|
|
104
|
+
Object.keys(ruleResult).forEach(function (prop) {
|
|
105
|
+
pseudoRuleResult[prop + pseudoCls] = ruleResult[prop]
|
|
106
|
+
})
|
|
107
|
+
ruleResult = pseudoRuleResult
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// merge style
|
|
111
|
+
Object.keys(ruleResult).forEach(function (prop) {
|
|
112
|
+
// handle transition
|
|
113
|
+
if (prop.indexOf('transition') === 0 && prop !== 'transition') {
|
|
114
|
+
var realProp = prop.replace('transition', '')
|
|
115
|
+
realProp = realProp[0].toLowerCase() + realProp.slice(1)
|
|
116
|
+
jsonStyle['@TRANSITION'] = jsonStyle['@TRANSITION'] || {}
|
|
117
|
+
jsonStyle['@TRANSITION'][className] = jsonStyle['@TRANSITION'][className] || {}
|
|
118
|
+
jsonStyle['@TRANSITION'][className][realProp] = ruleResult[prop]
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
jsonStyle[className] = jsonStyle[className] || {}
|
|
122
|
+
jsonStyle[className][prop] = ruleResult[prop]
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
log.push({
|
|
127
|
+
line: rule.position.start.line,
|
|
128
|
+
column: rule.position.start.column,
|
|
129
|
+
reason: 'ERROR: Selector `' + selector + '` is not supported. Weex only support single-classname selector'
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
log = log.concat(ruleLog)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/* istanbul ignore else */
|
|
137
|
+
else if (type === 'font-face') {
|
|
138
|
+
/* istanbul ignore else */
|
|
139
|
+
if (rule.declarations && rule.declarations.length) {
|
|
140
|
+
rule.declarations.forEach(function (declaration) {
|
|
141
|
+
/* istanbul ignore if */
|
|
142
|
+
if (declaration.type !== 'declaration') {
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
var name = util.hyphenedToCamelCase(declaration.property)
|
|
146
|
+
var value = declaration.value
|
|
147
|
+
if (name === 'fontFamily' && '\"\''.indexOf(value[0]) > -1) { // FIXME: delete leading and trailing quotes
|
|
148
|
+
value = value.slice(1, value.length - 1)
|
|
149
|
+
}
|
|
150
|
+
ruleResult[name] = value
|
|
151
|
+
})
|
|
152
|
+
if (!jsonStyle['@FONT-FACE']) {
|
|
153
|
+
jsonStyle['@FONT-FACE'] = []
|
|
154
|
+
}
|
|
155
|
+
jsonStyle['@FONT-FACE'].push(ruleResult)
|
|
156
|
+
}
|
|
157
|
+
} else if (type === 'keyframes') {
|
|
158
|
+
//将内容转成格式:
|
|
159
|
+
/*
|
|
160
|
+
{
|
|
161
|
+
"keyframmove": {
|
|
162
|
+
"left": [
|
|
163
|
+
{ "p": 0, "v": "0" },
|
|
164
|
+
{ "p": 0.2, "v": "100px" },
|
|
165
|
+
{ "p": 1, "v": "200px" }
|
|
166
|
+
],
|
|
167
|
+
"opacity": [
|
|
168
|
+
{ "p": 0, "v": "0.1" },
|
|
169
|
+
{ "p": 0.2, "v": "0.6" },
|
|
170
|
+
{ "p": 1, "v": "1" }
|
|
171
|
+
],
|
|
172
|
+
"top": [
|
|
173
|
+
{ "p": 0, "v": "0px" },
|
|
174
|
+
{ "p": 0.2, "v": "200px" },
|
|
175
|
+
{ "p": 1, "v": "300px" }
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
*/
|
|
180
|
+
if (rule.name && rule.keyframes && rule.keyframes.length) {
|
|
181
|
+
const name = rule.name;
|
|
182
|
+
jsonStyle["@KEYFRAME"] = jsonStyle["@KEYFRAME"] || {};
|
|
183
|
+
const result = jsonStyle["@KEYFRAME"][name] = {};
|
|
184
|
+
rule.keyframes.forEach((keyframe) => {
|
|
185
|
+
if (keyframe.type == "keyframe") {
|
|
186
|
+
const values = keyframe.values.map(v => {
|
|
187
|
+
if (v === 'from') { return 0; }
|
|
188
|
+
if (v === 'to') { return 1; }
|
|
189
|
+
return (parseInt(v) || 0) / 100;
|
|
190
|
+
});
|
|
191
|
+
if (keyframe.declarations && keyframe.declarations.length) {
|
|
192
|
+
keyframe.declarations.forEach((declaration) => {
|
|
193
|
+
const camelCasedName = util.hyphenedToCamelCase(declaration.property);
|
|
194
|
+
const subResult = validateItem(camelCasedName, declaration.value);
|
|
195
|
+
const value = subResult.value;
|
|
196
|
+
|
|
197
|
+
if (subResult.log) {
|
|
198
|
+
subResult.log.line = declaration.position.start.line
|
|
199
|
+
subResult.log.column = declaration.position.start.column
|
|
200
|
+
ruleLog.push(subResult.log)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (camelCasedName && typeof value === 'number' || typeof value === 'string') {
|
|
204
|
+
result[camelCasedName] = result[camelCasedName] || [];
|
|
205
|
+
values.forEach((p) => {
|
|
206
|
+
result[camelCasedName].push({ p: p, v: value })
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
done(err, { jsonStyle: jsonStyle, log: log })
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Validate a JSON Object and log errors & warnings
|
|
223
|
+
*
|
|
224
|
+
* @param {object} json
|
|
225
|
+
* @param {function} done which will be called with
|
|
226
|
+
* - err:Error
|
|
227
|
+
* - data.jsonStyle{}: `classname.propname.value`-like object
|
|
228
|
+
* - data.log[{reason}]
|
|
229
|
+
*/
|
|
230
|
+
function validate(json, done) {
|
|
231
|
+
var log = []
|
|
232
|
+
var err
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
json = JSON.parse(JSON.stringify(json))
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
err = e
|
|
239
|
+
json = {}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
Object.keys(json).forEach(function (selector) {
|
|
243
|
+
var declarations = json[selector]
|
|
244
|
+
|
|
245
|
+
Object.keys(declarations).forEach(function (name) {
|
|
246
|
+
var value = declarations[name]
|
|
247
|
+
var result = validateItem(name, value)
|
|
248
|
+
|
|
249
|
+
if (typeof result.value === 'number' || typeof result.value === 'string') {
|
|
250
|
+
declarations[name] = result.value
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
delete declarations[name]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (result.log) {
|
|
257
|
+
log.push(result.log)
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
done(err, {
|
|
263
|
+
jsonStyle: json,
|
|
264
|
+
log: log
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
module.exports = {
|
|
269
|
+
parse: parse,
|
|
270
|
+
validate: validate,
|
|
271
|
+
validateItem: validateItem,
|
|
272
|
+
util: util
|
|
273
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
function generateDeclaration(property, value, position) {
|
|
2
|
+
return {
|
|
3
|
+
type: 'declaration',
|
|
4
|
+
property,
|
|
5
|
+
value,
|
|
6
|
+
position
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function transition(declaration) {
|
|
10
|
+
var CHUNK_REGEXP = /^(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?\s*(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?$/
|
|
11
|
+
var match = declaration.value.match(CHUNK_REGEXP)
|
|
12
|
+
var result = []
|
|
13
|
+
var position = declaration.position
|
|
14
|
+
match[1] && result.push(generateDeclaration('transition-property', match[1], position))
|
|
15
|
+
match[2] && result.push(generateDeclaration('transition-duration', match[2], position))
|
|
16
|
+
match[3] && result.push(generateDeclaration('transition-timing-function', match[3], position))
|
|
17
|
+
match[4] && result.push(generateDeclaration('transition-delay', match[4], position))
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function margin(declaration) {
|
|
22
|
+
var position = declaration.position
|
|
23
|
+
var splitResult = declaration.value.split(/\s+/)
|
|
24
|
+
var result = []
|
|
25
|
+
switch (splitResult.length) {
|
|
26
|
+
case 1:
|
|
27
|
+
splitResult.push(splitResult[0], splitResult[0], splitResult[0])
|
|
28
|
+
break
|
|
29
|
+
case 2:
|
|
30
|
+
splitResult.push(splitResult[0], splitResult[1])
|
|
31
|
+
break
|
|
32
|
+
case 3:
|
|
33
|
+
splitResult.push(splitResult[1])
|
|
34
|
+
break
|
|
35
|
+
}
|
|
36
|
+
result.push(
|
|
37
|
+
generateDeclaration('margin-top', splitResult[0], position),
|
|
38
|
+
generateDeclaration('margin-right', splitResult[1], position),
|
|
39
|
+
generateDeclaration('margin-bottom', splitResult[2], position),
|
|
40
|
+
generateDeclaration('margin-left', splitResult[3], position)
|
|
41
|
+
)
|
|
42
|
+
return result
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// animation: name duration timing-function delay iteration-count direction;
|
|
46
|
+
// animation:theanimation 4s linear 10s infinite alternate;
|
|
47
|
+
function animation(declaration) {
|
|
48
|
+
const CHUNK_REGEXP = /^(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?\s*(\S*)?\s*(\d*\.?\d+(?:ms|s)?)?\s*(\S*)?\s*(\S*)?$/
|
|
49
|
+
const match = declaration.value.match(CHUNK_REGEXP);
|
|
50
|
+
|
|
51
|
+
var result = []
|
|
52
|
+
var position = declaration.position
|
|
53
|
+
match[1] && result.push(generateDeclaration('animation-name', match[1], position))
|
|
54
|
+
match[2] && result.push(generateDeclaration('animation-duration', match[2], position))
|
|
55
|
+
match[3] && result.push(generateDeclaration('animation-timing-function', match[3], position))
|
|
56
|
+
match[4] && result.push(generateDeclaration('animation-delay', match[4], position))
|
|
57
|
+
match[5] && result.push(generateDeclaration('animation-iteration-count', match[5], position))
|
|
58
|
+
match[6] && result.push(generateDeclaration('animation-direction', match[6], position))
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var parserCollection = {
|
|
63
|
+
transition,
|
|
64
|
+
margin,
|
|
65
|
+
animation
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = function (declarations) {
|
|
69
|
+
return declarations.reduce((result, declaration) => {
|
|
70
|
+
var parser = parserCollection[declaration.property]
|
|
71
|
+
if (parser) {
|
|
72
|
+
return result.concat(parser(declaration))
|
|
73
|
+
} else {
|
|
74
|
+
result.push(declaration)
|
|
75
|
+
return result
|
|
76
|
+
}
|
|
77
|
+
}, [])
|
|
78
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rules:
|
|
3
|
+
* - abc-def -> abcDef
|
|
4
|
+
* - -abc-def -> AbcDef
|
|
5
|
+
*
|
|
6
|
+
* @param {string} value
|
|
7
|
+
* @return {string}
|
|
8
|
+
*/
|
|
9
|
+
exports.hyphenedToCamelCase = function hyphenedToCamelCase(value) {
|
|
10
|
+
return value.replace(/-([a-z])/g, function(s, m) {
|
|
11
|
+
return m.toUpperCase()
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* rules:
|
|
17
|
+
* - abcDef -> abc-def
|
|
18
|
+
* - AbcDef -> -abc-def
|
|
19
|
+
*
|
|
20
|
+
* @param {string} value
|
|
21
|
+
* @return {string}
|
|
22
|
+
*/
|
|
23
|
+
exports.camelCaseToHyphened = function camelCaseToHyphened(value) {
|
|
24
|
+
return value.replace(/([A-Z])/g, function(s, m) {
|
|
25
|
+
if (typeof m === 'string') {
|
|
26
|
+
return '-' + m.toLowerCase()
|
|
27
|
+
}
|
|
28
|
+
return m
|
|
29
|
+
})
|
|
30
|
+
}
|