@shijiu/jsview-vue 0.9.280 → 0.9.286-alpha.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/package.json
CHANGED
|
@@ -16,8 +16,6 @@ var postCssImport = _interopDefaultLegacy(require('postcss-import-sync'));
|
|
|
16
16
|
|
|
17
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
|
|
18
18
|
|
|
19
|
-
const adaptPath = (path.posix || path);
|
|
20
|
-
|
|
21
19
|
var nodeModulesDir = path.resolve(process.cwd(), 'node_modules')
|
|
22
20
|
var cachedCssStyles = {}
|
|
23
21
|
|
|
@@ -109,7 +107,7 @@ function compileCssToJs(sfc, options) {
|
|
|
109
107
|
checkSelectors(node, styleInfo.styleFilePath, styleInfo.styleSelectors); // 检测selector是否已经处理过
|
|
110
108
|
let styleJsFilePath = path.relative(nodeModulesDir, styleInfo.styleJsFilePath);
|
|
111
109
|
styleJsFilePath = styleJsFilePath.replace(/\\/g, '/');
|
|
112
|
-
styleImportContainer += `\nimport "${
|
|
110
|
+
styleImportContainer += `\nimport "${styleJsFilePath}";`
|
|
113
111
|
} else if(node.name === "keyframes") {
|
|
114
112
|
const styleFilePath = node.source.input.file;
|
|
115
113
|
const styleSelectors = new Set([node.params]);
|
|
@@ -201,9 +199,9 @@ function compileImportNode(node) {
|
|
|
201
199
|
throw e;
|
|
202
200
|
}
|
|
203
201
|
|
|
204
|
-
const sourceDir =
|
|
202
|
+
const sourceDir = path.dirname(node.source.input.file);
|
|
205
203
|
let styleFileName = node.params.replace(/^["'](.+(?=["']$))["']$/, '$1')
|
|
206
|
-
const styleFilePath =
|
|
204
|
+
const styleFilePath = path.resolve(sourceDir, styleFileName);
|
|
207
205
|
return compileAndSaveImportedNode(styleFilePath, result.root.nodes);
|
|
208
206
|
}
|
|
209
207
|
|
|
@@ -212,7 +210,9 @@ function compileAndSaveImportedNode(styleFilePath, styleNodes) {
|
|
|
212
210
|
let styleContent = "";
|
|
213
211
|
|
|
214
212
|
styleNodes.forEach(node => {
|
|
215
|
-
if(
|
|
213
|
+
if(node.name === "keyframes") {
|
|
214
|
+
styleContent += compileKeyframesNode(node);
|
|
215
|
+
} else if(!!node.selector) {
|
|
216
216
|
styleContent += compileSelectorNode(node);
|
|
217
217
|
styleSelectors.add(node.selector);
|
|
218
218
|
} else {
|
|
@@ -225,8 +225,8 @@ function compileAndSaveImportedNode(styleFilePath, styleNodes) {
|
|
|
225
225
|
if (!fs.existsSync(cacheDir)) {
|
|
226
226
|
fs.mkdirSync(cacheDir);
|
|
227
227
|
}
|
|
228
|
-
const styleJsFileName =
|
|
229
|
-
const styleJsFilePath =
|
|
228
|
+
const styleJsFileName = path.basename(styleFilePath) + `.${hash(styleFilePath)}.js`;
|
|
229
|
+
const styleJsFilePath = path.join(cacheDir, styleJsFileName);
|
|
230
230
|
|
|
231
231
|
styleContent = "\nObject.assign(window.JsvCode.Dom.StyleSheets, {" + styleContent;
|
|
232
232
|
styleContent += "});\n";
|
|
@@ -239,13 +239,39 @@ function compileAndSaveImportedNode(styleFilePath, styleNodes) {
|
|
|
239
239
|
};
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
+
function getStringOffset(source, line, column) {
|
|
243
|
+
check(!isNaN(line), source, "JsView Error: Failed to get string offset, line is NaN.");
|
|
244
|
+
check(!isNaN(column), source, "JsView Error: Failed to get string offset, column is NaN.");
|
|
245
|
+
|
|
246
|
+
line -= 1;
|
|
247
|
+
column -= 1;
|
|
248
|
+
|
|
249
|
+
var offset = 0;
|
|
250
|
+
for (var idx = 0; idx < line; idx++) {
|
|
251
|
+
offset = source.indexOf('\n', offset + 1);
|
|
252
|
+
check(offset >= 0, source, "JsView Error: Failed to get string offset, line=" + line + ", column=" + column);
|
|
253
|
+
}
|
|
254
|
+
offset += column;
|
|
255
|
+
|
|
256
|
+
return offset;
|
|
257
|
+
}
|
|
258
|
+
|
|
242
259
|
function compileKeyframesNode(node) {
|
|
243
260
|
const name = node.name;
|
|
244
261
|
check(name, node.source.input.css, "JsView Error: name is not found!");
|
|
245
262
|
|
|
246
263
|
check(name === "keyframes", node.source.input.css, "JsView Error: @keyframes name is not found!");
|
|
247
264
|
|
|
248
|
-
|
|
265
|
+
let startOffset = node.source.start.offset;
|
|
266
|
+
let endOffset = node.source.end.offset;
|
|
267
|
+
if (typeof (startOffset) == 'undefined') {
|
|
268
|
+
startOffset = getStringOffset(node.source.input.css, node.source.start.line, node.source.start.column);
|
|
269
|
+
}
|
|
270
|
+
if (typeof (endOffset) == 'undefined') {
|
|
271
|
+
endOffset = getStringOffset(node.source.input.css, node.source.end.line, node.source.end.column);
|
|
272
|
+
}
|
|
273
|
+
const content = node.source.input.css.slice(startOffset, endOffset + 1);
|
|
274
|
+
// console.log('jsview-css-to-js.compileKeyframesNode() \n', startOffset, endOffset, content);
|
|
249
275
|
|
|
250
276
|
let styleContent = "'" + node.params + "':'";
|
|
251
277
|
styleContent += content.replace(/\n/g, " ");
|