webgal-parser 4.4.9-fix1 → 4.4.14-1

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.
Files changed (48) hide show
  1. package/.prettierrc +19 -0
  2. package/build/cjs/config/scriptConfig.d.ts +6 -1
  3. package/build/cjs/index.cjs +232 -182
  4. package/build/cjs/index.d.ts +15 -6
  5. package/build/cjs/interface/sceneInterface.d.ts +4 -3
  6. package/build/cjs/sceneParser.d.ts +5 -4
  7. package/build/cjs/scriptParser/argsParser.d.ts +2 -2
  8. package/build/cjs/scriptParser/commandParser.d.ts +4 -3
  9. package/build/cjs/scriptParser/contentParser.d.ts +1 -1
  10. package/build/cjs/scriptParser/scriptParser.d.ts +4 -3
  11. package/build/cjs/scriptParser/subSceneScanner.d.ts +1 -1
  12. package/build/cjs/styleParser/index.d.ts +5 -0
  13. package/build/es/config/scriptConfig.d.ts +6 -1
  14. package/build/es/index.d.ts +15 -6
  15. package/build/es/index.js +232 -182
  16. package/build/es/interface/sceneInterface.d.ts +4 -3
  17. package/build/es/sceneParser.d.ts +5 -4
  18. package/build/es/scriptParser/argsParser.d.ts +2 -2
  19. package/build/es/scriptParser/commandParser.d.ts +4 -3
  20. package/build/es/scriptParser/contentParser.d.ts +1 -1
  21. package/build/es/scriptParser/scriptParser.d.ts +4 -3
  22. package/build/es/scriptParser/subSceneScanner.d.ts +1 -1
  23. package/build/es/styleParser/index.d.ts +5 -0
  24. package/build/types/config/scriptConfig.d.ts +6 -1
  25. package/build/types/index.d.ts +15 -6
  26. package/build/types/interface/sceneInterface.d.ts +4 -3
  27. package/build/types/sceneParser.d.ts +5 -4
  28. package/build/types/scriptParser/argsParser.d.ts +2 -2
  29. package/build/types/scriptParser/commandParser.d.ts +4 -3
  30. package/build/types/scriptParser/contentParser.d.ts +1 -1
  31. package/build/types/scriptParser/scriptParser.d.ts +4 -3
  32. package/build/types/scriptParser/subSceneScanner.d.ts +1 -1
  33. package/build/types/styleParser/index.d.ts +5 -0
  34. package/build/umd/index.global.js +232 -182
  35. package/package.json +1 -1
  36. package/src/config/scriptConfig.ts +9 -5
  37. package/src/configParser/configParser.ts +37 -25
  38. package/src/index.ts +66 -30
  39. package/src/interface/sceneInterface.ts +4 -3
  40. package/src/parser4/index.ts +1 -1
  41. package/src/sceneParser.ts +36 -17
  42. package/src/scriptParser/argsParser.ts +17 -14
  43. package/src/scriptParser/assetsScanner.ts +5 -1
  44. package/src/scriptParser/commandParser.ts +31 -23
  45. package/src/scriptParser/contentParser.ts +14 -10
  46. package/src/scriptParser/scriptParser.ts +38 -20
  47. package/src/scriptParser/subSceneScanner.ts +11 -5
  48. package/src/styleParser/index.ts +39 -0
@@ -3,16 +3,22 @@
3
3
  * @param content 语句内容
4
4
  * @return {Array<string>} 子场景列表
5
5
  */
6
- import { commandType } from "../interface/sceneInterface";
6
+ import { commandType } from '../interface/sceneInterface';
7
7
 
8
- export const subSceneScanner = (command: commandType, content: string): Array<string> => {
8
+ export const subSceneScanner = (
9
+ command: commandType,
10
+ content: string,
11
+ ): Array<string> => {
9
12
  const subSceneList: Array<string> = [];
10
- if (command === commandType.changeScene || command === commandType.callScene) {
13
+ if (
14
+ command === commandType.changeScene ||
15
+ command === commandType.callScene
16
+ ) {
11
17
  subSceneList.push(content);
12
18
  }
13
19
  if (command === commandType.choose) {
14
- const chooseList = content.split("|");
15
- const chooseValue = chooseList.map((e) => e.split(":")[1] ?? "");
20
+ const chooseList = content.split('|');
21
+ const chooseValue = chooseList.map((e) => e.split(':')[1] ?? '');
16
22
  chooseValue.forEach((e) => {
17
23
  if (e.match(/\./)) {
18
24
  subSceneList.push(e);
@@ -0,0 +1,39 @@
1
+ export interface IWebGALStyleObj {
2
+ classNameStyles: Record<string, string>;
3
+ others: string;
4
+ }
5
+
6
+ export function scss2cssinjsParser(scssString: string): IWebGALStyleObj {
7
+ const [classNameStyles, others] = parseCSS(scssString);
8
+ return {
9
+ classNameStyles,
10
+ others,
11
+ };
12
+ }
13
+
14
+ /**
15
+ * GPT 4 写的,临时用,以后要重构!!!
16
+ * TODO:用人类智能重构,要是用着一直没问题,也不是不可以 trust AI
17
+ * @param css
18
+ */
19
+ function parseCSS(css: string): [Record<string, string>, string] {
20
+ const result: Record<string, string> = {};
21
+ let specialRules = '';
22
+ let matches;
23
+ // 匹配类选择器和其内容,包括一层嵌套
24
+ const classRegex = /\.([^{\s]+)\s*{([^}]*?(?:\{[^}]*?\}[^}]*?)?)}/g;
25
+ // 更新特殊规则正则表达式以正确处理一层嵌套,并确保大括号成对出现
26
+ const specialRegex = /(@[^{]+{\s*(?:[^{}]*{[^}]*}[^{}]*)+\s*})/g;
27
+
28
+ // 提取类和样式
29
+ while ((matches = classRegex.exec(css)) !== null) {
30
+ result[matches[1]] = matches[2].trim().replace(/\s*;\s*/g, ';\n');
31
+ }
32
+
33
+ // 提取特殊规则,并确保包含所有的大括号
34
+ while ((matches = specialRegex.exec(css)) !== null) {
35
+ specialRules += matches[1].trim() + '\n';
36
+ }
37
+
38
+ return [result, specialRules.trim()];
39
+ }