@shijiu/jsview 2.0.1021 → 2.0.1073

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.
@@ -1 +1 @@
1
- /* eslint-disable */ void 0===window.Forge?(window.Forge={},console.log("Define forge browser")):console.log("Define using JsView forge engine-js");var e=window.Forge;class t{constructor(e,t){if(!e)return;if(!0===e.startsWith("url")){let t=e.indexOf("(")+1,i=e.lastIndexOf(")");if("undefined"===(e=e.substring(t,i).trim())||"null"===e||0===e.length)return}if(!0===e.startsWith("data:"))return void(this.href=e);let i=e.indexOf("://");if(!(i<0||i>10)||e.startsWith("./")||e.startsWith("/")||(e="./"+e),!0===e.startsWith("/"))e=document.location.origin+e;else if(!0===e.startsWith("./")&&void 0!==window.JsView&&void 0!==window.JsView.Dom.JsSubPath){if(void 0===window.JsView.Dom.MainPath||"undefined"===window.JsView.Dom.MainPathRef||window.JsView.Dom.MainPathRef!==document.location.href){window.JsView.Dom.JsSubPath.startsWith("/")||(window.JsView.Dom.JsSubPath="/"+window.JsView.Dom.JsSubPath),window.JsView.Dom.JsSubPath.endsWith("/")||(window.JsView.Dom.JsSubPath=window.JsView.Dom.JsSubPath+"/"),window.JsView.Dom.MainPathRef=document.location.href;let e=document.location.pathname.lastIndexOf(window.JsView.Dom.JsSubPath);window.JsView.Dom.MainPath=document.location.origin+document.location.pathname.substring(0,e)}e=window.JsView.Dom.MainPath+e.substring(1)}if(this.href=e,!t)return;let o=this.href,n=o.indexOf("#");n>0&&(this.hash=o.substring(n),o=o.substring(0,n));let r=o.indexOf("?");r>1&&(this.search=o.substring(r),o=o.substring(0,r));let s=o,a=s.indexOf("://");this.protocol=a>0?s.substring(0,a+1):"";let d=a>1?s.substring(a+3):"";a=d.indexOf("/"),this.host=a>0?d.substring(0,a):"",this.pathname=a>=1?d.substring(a):"",this.origin=this.protocol+"//"+this.host,a=this.host.indexOf(":"),this.hostname=a>0?this.host.substring(0,a):this.host,this.port=a>1?this.host.substring(a+1):""}replace(e){this.href=e}href="";origin="";protocol="";host="";hostname="";port="";pathname="";search="";hash=""}class i{static SetBackgroundColor(t,i,o){const n=window.JsvCode.ForgeHandles.TextureManager.GetColorTextureCached(i);let r;o&&(r=new e.ViewRoundCornerMask(o.topLeft,o.topRight,o.bottomLeft,o.bottomRight));const s=new e.ExternalTextureSetting(n,r);t.ResetTexture(s)}static SetBackgroundImage(i,o,n,r,s,a,d){let l,g={};if("string"==typeof o){const e=new t(o);if(e instanceof t==!1)throw Error("Bad Argument.",e);g.url=e.href}else"linear-gradient"==o?.type&&(g.gradient=o);if(g.gradient)if(g.gradient.colors?.length>2){const e=g.gradient.colors,t=[e[0],e[e.length-1]],i=e.slice(1,e.length-1);l=window.JsvCode.ForgeHandles.TextureManager.CreateLinearGradientTexture(t,i)}else 2==g.gradient.colors?.length?l=window.JsvCode.ForgeHandles.TextureManager.CreateMiniGradientTexture(!0,g.gradient.colors[0],g.gradient.colors[1],g.gradient.rawValue):console.warn("Failed to create backgroundImage gradient, bad colors.",g.gradient.colors);else g.url&&(l=g.url.includes(".gif")||g.url.includes(".webp")?window.JsvCode.ForgeHandles.TextureManager.GetGifImage(g.url,!1,null,d):window.JsvCode.ForgeHandles.TextureManager.GetImage2(g.url,!1,s,a||e.ColorSpace.RGBA_8888));if(l){let t;n&&(t=new e.ViewRoundCornerMask(n.topLeft,n.topRight,n.bottomLeft,n.bottomRight));const o=new e.ExternalTextureSetting(l,t);if(i.ResetTexture(o),r){let e=l.RegisterLoadImageCallback(null,(function(){r({width:l.Width,height:l.Height})}));i.RegisterDetachCallback((()=>{l.UnregisterLoadImageCallback(e)}))}}}static SetMaskedBackgroundImage(i,o,n,r){if("string"==typeof o&&(o=new t(o)),o instanceof t==!1)throw Error("Bad Argument.",o);if("string"==typeof n&&(n=new t(n)),n instanceof t==!1)throw Error("Bad Argument(MaskURL).",n);const s=window.JsvCode.ForgeHandles.TextureManager.GetImage2(o.href,!1,null,r||e.ColorSpace.RGBA_8888);if(s){const t=window.JsvCode.ForgeHandles.TextureManager.GetImage2(n.href,!1,null,e.ColorSpace.RGBA_8888),o=new e.ExternalTextureSetting(s,new e.ViewTextureMask(t));i.ResetTexture(o)}}}export{e as Forge,i as ForgeExtension};
1
+ /* eslint-disable */ void 0===window.Forge?(window.Forge={},console.log("Define forge browser")):console.log("Define using JsView forge engine-js");var e=window.Forge;class t{constructor(e,t){if(!e)return;if(!0===e.startsWith("url")){let t=e.indexOf("(")+1,i=e.lastIndexOf(")");if("undefined"===(e=e.substring(t,i).trim())||"null"===e||0===e.length)return}if(!0===e.startsWith("data:"))return void(this.href=e);let i=e.indexOf("://");if(!(i<0||i>10)||e.startsWith("./")||e.startsWith("/")||(e="./"+e),!0===e.startsWith("/"))e=document.location.origin+e;else if(!0===e.startsWith("./")&&void 0!==window.JsView&&void 0!==window.JsView.Dom.JsSubPath){if(void 0===window.JsView.Dom.MainPath||"undefined"===window.JsView.Dom.MainPathRef||window.JsView.Dom.MainPathRef!==document.location.href){window.JsView.Dom.JsSubPath.startsWith("/")||(window.JsView.Dom.JsSubPath="/"+window.JsView.Dom.JsSubPath),window.JsView.Dom.JsSubPath.endsWith("/")||(window.JsView.Dom.JsSubPath=window.JsView.Dom.JsSubPath+"/"),window.JsView.Dom.MainPathRef=document.location.href;let e=document.location.pathname.lastIndexOf(window.JsView.Dom.JsSubPath);window.JsView.Dom.MainPath=document.location.origin+document.location.pathname.substring(0,e)}e=window.JsView.Dom.MainPath+e.substring(1)}if(this.href=e,!t)return;let o=this.href,n=o.indexOf("#");n>0&&(this.hash=o.substring(n),o=o.substring(0,n));let s=o.indexOf("?");s>1&&(this.search=o.substring(s),o=o.substring(0,s));let r=o,a=r.indexOf("://");this.protocol=a>0?r.substring(0,a+1):"";let d=a>1?r.substring(a+3):"";a=d.indexOf("/"),this.host=a>0?d.substring(0,a):"",this.pathname=a>=1?d.substring(a):"","file:"==this.protocol&&(this.host="",this.pathname=d),this.origin=this.protocol+"//"+this.host,a=this.host.indexOf(":"),this.hostname=a>0?this.host.substring(0,a):this.host,this.port=a>1?this.host.substring(a+1):""}replace(e){this.href=e}href="";origin="";protocol="";host="";hostname="";port="";pathname="";search="";hash=""}class i{static SetBackgroundColor(t,i,o){const n=window.JsvCode.ForgeHandles.TextureManager.GetColorTextureCached(i);let s;o&&(s=new e.ViewRoundCornerMask(o.topLeft,o.topRight,o.bottomLeft,o.bottomRight));const r=new e.ExternalTextureSetting(n,s);t.ResetTexture(r)}static SetBackgroundImage(i,o,n,s,r,a,d){let h,l={};if("string"==typeof o){const e=new t(o);if(e instanceof t==!1)throw Error("Bad Argument.",e);l.url=e.href}else"linear-gradient"==o?.type&&(l.gradient=o);if(l.gradient)if(l.gradient.colors?.length>2){const e=l.gradient.colors,t=[e[0],e[e.length-1]],i=e.slice(1,e.length-1);h=window.JsvCode.ForgeHandles.TextureManager.CreateLinearGradientTexture(t,i)}else 2==l.gradient.colors?.length?h=window.JsvCode.ForgeHandles.TextureManager.CreateMiniGradientTexture(!0,l.gradient.colors[0],l.gradient.colors[1],l.gradient.rawValue):console.warn("Failed to create backgroundImage gradient, bad colors.",l.gradient.colors);else l.url&&(h=l.url.includes(".gif")||l.url.includes(".webp")?window.JsvCode.ForgeHandles.TextureManager.GetGifImage(l.url,!1,null,d):window.JsvCode.ForgeHandles.TextureManager.GetImage2(l.url,!1,r,a||e.ColorSpace.RGBA_8888));if(h){let t;n&&(t=new e.ViewRoundCornerMask(n.topLeft,n.topRight,n.bottomLeft,n.bottomRight));const o=new e.ExternalTextureSetting(h,t);if(i.ResetTexture(o),s){let e=h.RegisterLoadImageCallback(null,(function(){s({width:h.Width,height:h.Height})}));i.RegisterDetachCallback((()=>{h.UnregisterLoadImageCallback(e)}))}}}static SetMaskedBackgroundImage(i,o,n,s){if("string"==typeof o&&(o=new t(o)),o instanceof t==!1)throw Error("Bad Argument.",o);if("string"==typeof n&&(n=new t(n)),n instanceof t==!1)throw Error("Bad Argument(MaskURL).",n);const r=window.JsvCode.ForgeHandles.TextureManager.GetImage2(o.href,!1,null,s||e.ColorSpace.RGBA_8888);if(r){const t=window.JsvCode.ForgeHandles.TextureManager.GetImage2(n.href,!1,null,e.ColorSpace.RGBA_8888),o=new e.ExternalTextureSetting(r,new e.ViewTextureMask(t));i.ResetTexture(o)}}}export{e as Forge,i as ForgeExtension};
@@ -3,11 +3,11 @@
3
3
  */
4
4
 
5
5
  const TargetRevision = {
6
- "CoreRevision": 1021336,
7
- "CoreRevisionAndBranch": "1021336",
8
- "JseRevision": "1.0.882",
6
+ "CoreRevision": 1021367,
7
+ "CoreRevisionAndBranch": "1021367",
8
+ "JseRevision": "1.0.885",
9
9
  "JseUrl":
10
- "http://cdn.release.qcast.cn/forge_js/master/JsViewES6_js2c_r882.jsv.1f7c4fd1.js"
10
+ "http://cdn.release.qcast.cn/forge_js/master/JsViewES6_js2c_r885.jsv.fa4a843c.js"
11
11
  };
12
12
 
13
13
  // 版本是否存在测试方法
@@ -147,16 +147,6 @@ export default class JsViewLoader {
147
147
  console.error("JsView Error: Load designed map failed");
148
148
  }
149
149
 
150
- // 设置播放器的屏幕坐标尺寸
151
- if (window.JsView) {
152
- window.JsView.setVideoDesignMapWidth?.(designMap.width);
153
- } else {
154
- // 借助Audio标签设置基类BaseMedia的屏幕尺寸配置,绕开react的unref语法检测
155
- if (Audio.setDesignMapWidth) {
156
- Audio.setDesignMapWidth(designMap.width);
157
- }
158
- }
159
-
160
150
  return designMap;
161
151
  }
162
152
 
@@ -1,10 +1,10 @@
1
- import AppData from '/src/appConfig/app.config.mjs'
2
- import JsViewVendorConfig from "/src/appConfig/jsview.config.mjs"
3
-
4
1
  async function main() {
2
+ const { default: appConfig } = await import("/src/appConfig/app.config.mjs");
3
+ const { default: jsviewVendorConfig } = await import("/src/appConfig/jsview.config.mjs");
4
+
5
5
  let JsViewLoader = null;
6
6
  // 根据JsViewConfig, 判断厂商是否设置了使用远程loader启动
7
- const remoteLoader = JsViewVendorConfig.jsviewConfig.remoteLoader;
7
+ const remoteLoader = jsviewVendorConfig.jsviewConfig.remoteLoader;
8
8
  if (remoteLoader) {
9
9
  JsViewLoader = (await import(remoteLoader)).default;
10
10
  } else {
@@ -13,7 +13,7 @@ async function main() {
13
13
  const jsviewLoader = new JsViewLoader();
14
14
 
15
15
  // 使用vendor配置值覆盖默认配置。
16
- const config = jsviewLoader.mergeConfig(JsViewVendorConfig);
16
+ const config = jsviewLoader.mergeConfig(jsviewVendorConfig);
17
17
  console.log("JsView config: " + JSON.stringify(config));
18
18
 
19
19
  jsviewLoader.initForgeEnv();
@@ -23,7 +23,7 @@ async function main() {
23
23
  // JsView环境加载完毕后,加载vue/react的main.js文件。
24
24
  import('/src/main.tsx');
25
25
  };
26
- jsviewLoader.initJsViewEnv(AppData.AppName, onInitJsViewEnv);
26
+ jsviewLoader.initJsViewEnv(appConfig.AppName, onInitJsViewEnv);
27
27
  }
28
28
 
29
29
  // webpack/vite运行入口
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shijiu/jsview",
3
- "version": "2.0.1021",
3
+ "version": "2.0.1073",
4
4
  "bin": {
5
5
  "jsview-post-build": "./tools/jsview-post-build.js",
6
6
  "jsview-post-install": "./tools/jsview-post-install.js"
@@ -260,7 +260,19 @@ function resolveScript(descriptor, options, ssr) {
260
260
  return null;
261
261
  }
262
262
  const cacheToUse = ssr ? ssrCache : clientCache;
263
- const cached = cacheToUse.get(descriptor);
263
+ // JsView Added >>>
264
+ // 解决@import的css文件没有被热更新问题。
265
+ // const cached = cacheToUse.get(descriptor);
266
+ let cached = cacheToUse.get(descriptor);
267
+ if (descriptor.filename?.endsWith('.vue') && descriptor.styles) {
268
+ for (const style of descriptor.styles) {
269
+ if (style.content?.includes('@import')) {
270
+ cached = null;
271
+ break;
272
+ }
273
+ }
274
+ }
275
+ // JsView Added <<<
264
276
  if (cached) {
265
277
  return cached;
266
278
  }
@@ -10,9 +10,10 @@ const fs = require('fs');
10
10
  const path = require('path');
11
11
  const postCss = require('postcss');
12
12
  const postCssJs = require('postcss-js');
13
- const styleChecker = require("./jsview-style-checker");
13
+ const styleChecker = require('./jsview-style-checker');
14
+ const Logger = require('@shijiu/jsview/tools/jsview-logger');
14
15
 
15
- const compilerSfc = require("./compiler-sfc.cjs");
16
+ const compilerSfc = require('./compiler-sfc.cjs');
16
17
  const processorLangList = [
17
18
  'less',
18
19
  'sass',
@@ -26,9 +27,8 @@ const cachedCssStyles = {};
26
27
  function ensureSfcDescriptor(descriptor) {
27
28
  try {
28
29
  ensureSfcDescriptorImpl(descriptor)
29
-
30
30
  } catch (exception) {
31
- console.error("JsView Error: Failed to call ensureSfcDescriptor()! Exception:\n", exception);
31
+ Logger.ErrorAndThrow(Logger.GetFileTag(descriptor.filename), 'Failed to call ensureSfcDescriptor()!');
32
32
  }
33
33
  }
34
34
 
@@ -36,12 +36,12 @@ function compileCssToJs(sfc, options) {
36
36
  try {
37
37
  // 必须在此处parse css,否则npm run build时进入不到js代码中。
38
38
  // const styleJsFilePath = getStyleJsFilePath(sfc.filename);
39
- // return `\nimport "${styleJsFilePath}";`
39
+ // return `\nimport '${styleJsFilePath}';`
40
40
 
41
41
  const compiledJsContent = compileCssToJsImpl(sfc, options)
42
42
  return compiledJsContent;
43
43
  } catch (exception) {
44
- console.error("JsView Error: Failed to call compileCssToJs()! Exception:\n", exception);
44
+ Logger.ErrorAndThrow(Logger.GetFileTag(sfc.filename), 'Failed to call compileCssToJs()!');
45
45
  }
46
46
  }
47
47
 
@@ -50,10 +50,9 @@ function compileCssToJsImpl(sfc, options) {
50
50
  let cachedStyleSheets = {};
51
51
  for (const style of sfc.styles) {
52
52
  if(!!style.module) {
53
- let errMsg = "JsView Error: style module is not released by Vue3!\n";
53
+ let errMsg = 'style module is not released by Vue3!\n';
54
54
  errMsg += style;
55
- console.error(errMsg + " errors =", errors);
56
- throw new Error(errMsg)
55
+ Logger.ErrorAndThrow(Logger.GetFileTag(sfc.filename), errMsg + ' errors =', errors);
57
56
  }
58
57
 
59
58
  const compileStyleOptions = {
@@ -70,17 +69,16 @@ function compileCssToJsImpl(sfc, options) {
70
69
  preprocessLang: style.attrs.lang,
71
70
  };
72
71
 
73
- if(!!style.attrs.src) { // 处理<style [scoped] src="xxx">
72
+ if(!!style.attrs.src) { // 处理<style [scoped] src='xxx'>
74
73
  const baseDir = path.dirname(sfc.filename);
75
74
  const cssSrcPath = path.resolve(baseDir, style.attrs.src);
76
- compileStyleOptions.source = fs.readFileSync(cssSrcPath, "utf8");
75
+ compileStyleOptions.source = fs.readFileSync(cssSrcPath, 'utf8');
77
76
  }
78
77
 
79
78
  const { rawResult, errors } = compilerSfc.compileStyle(compileStyleOptions)
80
79
  if(errors.length) {
81
- const errMsg = "JsView Error: Failed to compile style when convert css to js!";
82
- console.error(errMsg + " errors =", errors);
83
- throw new Error(errMsg)
80
+ const errMsg = 'Failed to compile style when convert css to js!';
81
+ Logger.ErrorAndThrow(Logger.GetFileTag(sfc.filename), errMsg + ' errors =', errors);
84
82
  }
85
83
 
86
84
  const {styleImports, styleSheets } = compileAndSaveImportedNode(rawResult.result.root.nodes);
@@ -90,7 +88,7 @@ function compileCssToJsImpl(sfc, options) {
90
88
 
91
89
  const styleJsContents = serializeStyleJsFile(cachedStyleImports, cachedStyleSheets);
92
90
 
93
- // console.log("jsview-css-to-js.compileCssToJsImpl() styleJsContents=", styleJsContents);
91
+ // Logger.Debug(Logger.GetFileTag(sfc.filename), 'styleJsContents=', styleJsContents);
94
92
 
95
93
  return styleJsContents;
96
94
  }
@@ -109,12 +107,12 @@ function ensureSfcDescriptorImpl(descriptor) {
109
107
 
110
108
  // 为了触发compiler-sfc.cjs.compileScript()
111
109
  // 如果script和scriptSetup都不存在,就做一个空的
112
- // console.log("JsView: insert a empty script.");
110
+ // Logger.Debug('insert a empty script.');
113
111
  descriptor.script = {
114
112
  type: 'script',
115
- content: "export default {}\n",
113
+ content: 'export default {}\n',
116
114
  loc: {
117
- source: "",
115
+ source: '',
118
116
  start: { column: 0, line: 0, offset: 0 },
119
117
  end: { column: 0, line: 0, offset: 0}
120
118
  },
@@ -141,9 +139,9 @@ function checkSelectors(node, styleFilePath, styleSelectors) {
141
139
  for(let selector of cachedSelectors) {
142
140
  if(styleSelectors.has(selector)) { // 发现重复的selector
143
141
  if (selector.includes['['] && selector.includes[']']) { // scoped style
144
- let errMsg = "JsView Warn: Multi defined CSS selector '" + selector + "' from " + node.source.input.file + ".\n";
145
- errMsg += "It has been defined in " + cachedFilePath + ".\n";
146
- console.warn(errMsg);
142
+ let errMsg = 'Multi defined CSS selector "' + selector + '" from ' + node.source.input.file + '.\n';
143
+ errMsg += 'It has been defined in ' + cachedFilePath + '.\n';
144
+ Logger.Warn(Logger.GetFileTag(node.source.input.file), errMsg);
147
145
  }
148
146
  return false;
149
147
  }
@@ -161,11 +159,10 @@ function checkSelectors(node, styleFilePath, styleSelectors) {
161
159
  return true;
162
160
  }
163
161
 
164
- function check(expr, source, errMsg) {
162
+ function check(expr, node, source, errMsg) {
165
163
  if(!expr) {
166
- errMsg += ("\n source is: \n" + source);
167
- console.error(errMsg);
168
- throw new Error(errMsg);
164
+ errMsg += ('\n source is: \n' + source);
165
+ Logger.ErrorAndThrow(Logger.GetFileTag(node.source.input.file), errMsg);
169
166
  }
170
167
  }
171
168
 
@@ -174,22 +171,21 @@ function compileAndSaveImportedNode(styleNodes) {
174
171
  let styleSheets = {};
175
172
 
176
173
  for(const node of styleNodes) {
177
- if (node.type === "comment"
178
- || node.name === "-webkit-keyframes"
179
- || node.name === "charset") {
174
+ if (node.type === 'comment'
175
+ || node.name === '-webkit-keyframes'
176
+ || node.name === 'charset') {
180
177
  // DO NOTHING
181
- } else if(node.name === "import") {
178
+ } else if(node.name === 'import') {
182
179
  const importContent = compileImportNodeRecursive(node);
183
180
  if (importContent && styleImports.includes(importContent) == false) {
184
181
  styleImports.push(importContent);
185
182
  }
186
- } else if(node.name === "keyframes") {
183
+ } else if(node.name === 'keyframes') {
187
184
  const styleFilePath = node.source.input.file;
188
185
  const styleSelectors = new Set([node.params]);
189
186
  const checked = checkSelectors(node, styleFilePath, styleSelectors); // 检测selector是否已经处理过
190
187
  if (checked == false) {
191
- let errMsg = "JsView Warn: Multi defined CSS keyframes '" + node.params + "'.\n";
192
- console.warn(errMsg);
188
+ Logger.Warn(Logger.GetFileTag(node.source.input.file), 'Multi defined CSS keyframes "' + node.params + '".\n');
193
189
  }
194
190
 
195
191
  const subStyleSheets = compileKeyframesNode(node);
@@ -201,8 +197,7 @@ function compileAndSaveImportedNode(styleNodes) {
201
197
  const styleSelectors = new Set([node.selector]);
202
198
  const checked = checkSelectors(node, styleFilePath, styleSelectors); // 检测selector是否已经处理过
203
199
  if (checked == false) {
204
- let errMsg = "JsView Warn: Multi defined CSS selector '" + node.selector + "'.\n";
205
- console.warn(errMsg);
200
+ Logger.Warn(Logger.GetFileTag(node.source.input.file), 'Multi defined CSS selector "' + node.selector + '".\n');
206
201
  }
207
202
 
208
203
  const subStyleSheets = compileSelectorNode(node);
@@ -216,17 +211,17 @@ function compileAndSaveImportedNode(styleNodes) {
216
211
  styleSheets[scopedId] = mergedStyleRules;
217
212
  }
218
213
  styleSelectors.add(node.selector);
219
- } else if (node.name === "-moz-keyframes"
220
- || node.name === "-o-keyframes"
221
- || node.name === "-webkit-keyframes") {
214
+ } else if (node.name === '-moz-keyframes'
215
+ || node.name === '-o-keyframes'
216
+ || node.name === '-webkit-keyframes') {
222
217
  // Stylus 添加的keyframes,忽略,只处理@keyframes
223
218
  } else {
224
- console.log("Unsupported css node: ", node);
225
- check(false, node.source.input.css, "JsView Error: Unsupported css node from import css file.");
219
+ Logger.Info(Logger.GetFileTag(node.source.input.file), 'Unsupported css node: ', node);
220
+ check(false, node, node.source.input.css, 'Unsupported css node from import css file.');
226
221
  }
227
222
  }
228
223
 
229
- // console.log('jsview-css-to-js.compileAndSaveImportedNode() styleSheets=', styleImports, styleSheets);
224
+ // Logger.Debug(Logger.GetFileTag(node.source.input.file), 'jsview-css-to-js.compileAndSaveImportedNode() styleSheets=', styleImports, styleSheets);
230
225
  return {
231
226
  styleImports,
232
227
  styleSheets,
@@ -234,7 +229,7 @@ function compileAndSaveImportedNode(styleNodes) {
234
229
  }
235
230
 
236
231
  function serializeStyleJsFile(styleImports, styleSheets) {
237
- let styleJsContent = "\n";
232
+ let styleJsContent = '\n';
238
233
 
239
234
  if (styleImports.length > 0) {
240
235
  const styleImportsContent = styleImports.join('\n');
@@ -243,9 +238,9 @@ function serializeStyleJsFile(styleImports, styleSheets) {
243
238
 
244
239
  if (Object.keys(styleSheets).length > 0) {
245
240
  const styleSheetsContent = JSON.stringify(styleSheets);
246
- styleJsContent += "\nconst styleSheetsContent = ";
241
+ styleJsContent += '\nconst styleSheetsContent = ';
247
242
  styleJsContent += styleSheetsContent;
248
- styleJsContent += ";\nwindow.JsvCode.Dom.DeclareStyleSheets(styleSheetsContent);";
243
+ styleJsContent += ';\nwindow.JsvCode.Dom.DeclareStyleSheets(styleSheetsContent);';
249
244
  }
250
245
 
251
246
  return styleJsContent;
@@ -275,9 +270,9 @@ function getStyleJsFilePath(styleFilePath) {
275
270
  return styleJsFilePath;
276
271
  }
277
272
 
278
- function getStringOffset(source, line, column) {
279
- check(!isNaN(line), source, "JsView Error: Failed to get string offset, line is NaN.");
280
- check(!isNaN(column), source, "JsView Error: Failed to get string offset, column is NaN.");
273
+ function getStringOffset(node, source, line, column) {
274
+ check(!isNaN(line), node, source, 'Failed to get string offset, line is NaN.');
275
+ check(!isNaN(column), node, source, 'Failed to get string offset, column is NaN.');
281
276
 
282
277
  line -= 1;
283
278
  column -= 1;
@@ -285,7 +280,7 @@ function getStringOffset(source, line, column) {
285
280
  var offset = 0;
286
281
  for (var idx = 0; idx < line; idx++) {
287
282
  offset = source.indexOf('\n', offset + 1);
288
- check(offset >= 0, source, "JsView Error: Failed to get string offset, line=" + line + ", column=" + column);
283
+ check(offset >= 0, node, source, 'Failed to get string offset, line=' + line + ', column=' + column);
289
284
  }
290
285
  offset += column;
291
286
 
@@ -294,7 +289,7 @@ function getStringOffset(source, line, column) {
294
289
 
295
290
  function compileImportNodeRecursive(node, parsedImports = []) {
296
291
  const name = node.name;
297
- check(name === "import", node.source.input.css, "JsView Error: @import name is not found!");
292
+ check(name === 'import', node, node.source.input.css, '@import name is not found!');
298
293
 
299
294
  let cssFilePath = node.params.replaceAll('"', '');
300
295
  cssFilePath = cssFilePath.replaceAll("'", '');
@@ -304,13 +299,13 @@ function compileImportNodeRecursive(node, parsedImports = []) {
304
299
 
305
300
  // 解死循环
306
301
  if (parsedImports.includes(cssFileFullPath)) {
307
- console.log('JsView Info: Ignore to parse file in dead loop: ' + cssFileFullPath);
302
+ Logger.Info(Logger.GetFileTag(node.source.input.file), 'Ignore to parse file in dead loop: ' + cssFileFullPath);
308
303
  return null;
309
304
  }
310
305
  parsedImports.push(cssFileFullPath);
311
306
 
312
307
  try {
313
- const content = fs.readFileSync(cssFileFullPath, "utf8");;
308
+ const content = fs.readFileSync(cssFileFullPath, 'utf8');;
314
309
  const options = {
315
310
  from: cssFileFullPath
316
311
  };
@@ -321,7 +316,7 @@ function compileImportNodeRecursive(node, parsedImports = []) {
321
316
  const importNodeIndexs = [];
322
317
  for (let idx = 0; idx < styleNodes.length; idx++) {
323
318
  const node = styleNodes[idx];
324
- if (node.name !== "import") {
319
+ if (node.name !== 'import') {
325
320
  continue;
326
321
  }
327
322
 
@@ -346,63 +341,73 @@ function compileImportNodeRecursive(node, parsedImports = []) {
346
341
  const { _, styleSheets } = compileAndSaveImportedNode(styleNodes);
347
342
  const styleJsContents = serializeStyleJsFile(styleImports, styleSheets);
348
343
 
349
- fs.writeFileSync(styleJsFilePath, styleJsContents, "utf8");;
344
+ fs.writeFileSync(styleJsFilePath, styleJsContents, 'utf8');;
350
345
  } catch (e) {
351
- console.log('JsView Error: Failed to compile css import node.', e);
352
- throw e;
346
+ Logger.ErrorAndThrow(Logger.GetFileTag(node.source.input.file), 'Failed to compile css import node.', e);
353
347
  }
354
348
 
355
349
  let styleJsFileRelativePath = path.relative(baseDir, styleJsFilePath);
356
350
  styleJsFileRelativePath = styleJsFileRelativePath.replaceAll('\\', '/');
357
- const styleImportContent = `\nimport "${styleJsFileRelativePath}";`;
351
+ const styleImportContent = `\nimport '${styleJsFileRelativePath}';`;
358
352
 
359
- // console.log('jsview-css-to-js.compileImportNodeRecursive() return ', styleImportContent);
353
+ // Logger.Debug(Logger.GetFileTag(node.source.input.file), 'return ', styleImportContent);
360
354
  return styleImportContent;
361
355
  }
362
356
 
363
357
  function compileKeyframesNode(node) {
364
358
  const name = node.name;
365
- check(name, node.source.input.css, "JsView Error: name is not found!");
366
-
367
- check(name === "keyframes", node.source.input.css, "JsView Error: @keyframes name is not found!");
368
-
369
- let startOffset = node.source.start.offset;
370
- let endOffset = node.source.end.offset;
371
- if (typeof (startOffset) == 'undefined') {
372
- startOffset = getStringOffset(node.source.input.css, node.source.start.line, node.source.start.column);
373
- }
374
- if (typeof (endOffset) == 'undefined') {
375
- endOffset = getStringOffset(node.source.input.css, node.source.end.line, node.source.end.column);
359
+ check(name, node, node.source.input.css, 'name is not found!');
360
+
361
+ check(name === 'keyframes', node, node.source.input.css, '@keyframes name is not found!');
362
+
363
+ // let startOffset = node.source.start.offset;
364
+ // let endOffset = node.source.end.offset;
365
+ // if (typeof (startOffset) == 'undefined') {
366
+ // startOffset = getStringOffset(node.source.input.css, node.source.start.line, node.source.start.column);
367
+ // }
368
+ // if (typeof (endOffset) == 'undefined') {
369
+ // endOffset = getStringOffset(node.source.input.css, node.source.end.line, node.source.end.column);
370
+ // }
371
+ // const content = node.source.input.css.slice(startOffset, endOffset + 1);
372
+ // Logger.Debug(Logger.GetFileTag(node.source.input.file), startOffset, endOffset, content);
373
+
374
+ let content = '{';
375
+ for (const ident of node.nodes) {
376
+ content += ident.selector;
377
+ content += '{';
378
+ for (const declaration of ident.nodes) {
379
+ content += declaration.prop + ':' + declaration.value + ';';
380
+ }
381
+ content += '}';
376
382
  }
377
- const content = node.source.input.css.slice(startOffset, endOffset + 1);
378
- // console.log('jsview-css-to-js.compileKeyframesNode() \n', startOffset, endOffset, content);
383
+ content += '}';
384
+ content = content.replaceAll('\\', ''); // 去掉var()里面的 \\
379
385
 
380
386
  const kfName = node.params;
381
- let kfValue = content.replace(/(\r|\n|\r\n)/g, " ");
382
- kfValue = kfValue.replace(/@keyframes .*? {/g, "@keyframes " + kfName + " {");
383
- kfValue = styleChecker.GetFormattedKeyframe(kfName, kfValue);
387
+ let kfValue = '@keyframes ' + kfName + ' ' + content;
388
+ kfValue = styleChecker.GetFormattedKeyframe(node.source.input.file, kfName, kfValue);
384
389
 
385
390
  const scopedId = '0'; // CSS规范中,keyframes没有继承, 放在glabol中
386
391
  const kfRule = { [kfName]: kfValue };
387
392
 
388
393
  const styleSheets = { [scopedId]: kfRule };
389
394
 
390
- // console.log('jsview-css-to-js.compileKeyframesNode() return ', styleSheets);
395
+ // Logger.Debug(Logger.GetFileTag(node.source.input.file), 'return ', styleSheets);
391
396
  return styleSheets;
392
397
  }
393
398
 
394
399
  function compileSelectorNode(node) {
395
400
  const selector = node.selector;
396
- check(selector, node.source.input.css, "JsView Error: Selector is not found!");
401
+ check(selector, node, node.source.input.css, 'Selector is not found!');
397
402
 
398
- let errMsg = "JsView Error: Only class selector is supported!\n";
399
- errMsg += "JsView Error: Please use css like `.classname { property: value; }`";
400
- check(selector.startsWith('.'), node.source.input.css, errMsg);
403
+ let errMsg = 'Only class selector is supported!\n';
404
+ errMsg += 'Please use css like `.classname { property: value; }`';
405
+ check(selector.startsWith('.'), node, node.source.input.css, errMsg);
401
406
 
402
407
  const declarations = postCssJs.objectify(node);
403
408
  const styleSheets = parsePostCssJs(node, selector, declarations);
404
409
 
405
- // console.log('jsview-css-to-js.compileSelectorNode() return ', styleSheets);
410
+ // Logger.Debug(Logger.GetFileTag(node.source.input.file), 'return ', styleSheets);
406
411
  return styleSheets;
407
412
  }
408
413
 
@@ -414,9 +419,9 @@ function parsePostCssJs(node, selector, declarations) {
414
419
  for (let selector of selectorArray) {
415
420
  selector = selector.trim();
416
421
 
417
- let scopedId = selector.substring(selector.indexOf("[") + 1, selector.lastIndexOf("]"));
422
+ let scopedId = selector.substring(selector.indexOf('[') + 1, selector.lastIndexOf(']'));
418
423
  if (scopedId) {
419
- selector = selector.substring(0, selector.indexOf("["));
424
+ selector = selector.substring(0, selector.indexOf('['));
420
425
  scopedId = scopedId.replace('data-v-', '');
421
426
  } else {
422
427
  scopedId = '0';
@@ -437,8 +442,7 @@ function parseUnscopedStyleSheets(node, selector, declarations, scopedId) {
437
442
 
438
443
  for (let [name, value] of Object.entries(declarations)) {
439
444
  if (value instanceof Array) { // 同一个name定义了多次
440
- let errMsg = "JsView Warn: Multi defined CSS name '" + name + "' from " + selector + ".\n";
441
- console.warn(errMsg);
445
+ Logger.Warn(Logger.GetFileTag(node.source.input.file), 'Multi defined CSS name "' + name + '" from ' + selector + '.\n');
442
446
  value = value[value.length - 1];
443
447
  }
444
448
 
@@ -448,7 +452,7 @@ function parseUnscopedStyleSheets(node, selector, declarations, scopedId) {
448
452
  }
449
453
 
450
454
  if (name.startsWith('@keyframes')) { // keyframes解嵌套处理
451
- check(false, node.source.input.css, "JsView Error: Nested keyframes is not supported!");
455
+ check(false, node, node.source.input.css, 'Nested keyframes is not supported!');
452
456
  delete declarations[name];
453
457
  continue;
454
458
  } else if (value instanceof Object) { // css class解嵌套处理
@@ -459,13 +463,13 @@ function parseUnscopedStyleSheets(node, selector, declarations, scopedId) {
459
463
  continue;
460
464
  }
461
465
 
462
- const formattedValue = styleChecker.GetFormattedValue(name, value);
466
+ const formattedValue = styleChecker.GetFormattedValue(node.source.input.file, name, value);
463
467
  declarations[name] = formattedValue;
464
468
  }
465
469
 
466
470
  styleRules[selector] = JSON.stringify(declarations);
467
471
 
468
- // console.log('jsview-css-to-js.parseUnscopedStyleSheets() return ', styleRules);
472
+ // Logger.Debug(Logger.GetFileTag(node.source.input.file), 'return ', styleRules);
469
473
  return styleRules;
470
474
  }
471
475