@mybricks/plugin-ai 0.0.2 → 0.0.3

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 (249) hide show
  1. package/dist/_virtual/_rollupPluginBabelHelpers.js +164 -0
  2. package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/dist/agents/app.js +335 -0
  4. package/dist/agents/app.js.map +1 -0
  5. package/dist/agents/common.js +483 -0
  6. package/dist/agents/common.js.map +1 -0
  7. package/dist/agents/custom.js +16 -0
  8. package/dist/agents/custom.js.map +1 -0
  9. package/dist/agents/index.js +38 -0
  10. package/dist/agents/index.js.map +1 -0
  11. package/dist/agents/knowledges/knowledge-base.js +579 -0
  12. package/dist/agents/knowledges/knowledge-base.js.map +1 -0
  13. package/dist/agents/knowledges/knowledge-node.js +228 -0
  14. package/dist/agents/knowledges/knowledge-node.js.map +1 -0
  15. package/dist/agents/knowledges/types.js +105 -0
  16. package/dist/agents/knowledges/types.js.map +1 -0
  17. package/dist/agents/utils/config.js +229 -0
  18. package/dist/agents/utils/config.js.map +1 -0
  19. package/dist/agents/workspace/coding-manager.js +20 -0
  20. package/dist/agents/workspace/coding-manager.js.map +1 -0
  21. package/dist/agents/workspace/components-manager.js +113 -0
  22. package/dist/agents/workspace/components-manager.js.map +1 -0
  23. package/dist/agents/workspace/outline-focus.js +167 -0
  24. package/dist/agents/workspace/outline-focus.js.map +1 -0
  25. package/dist/agents/workspace/outline-info.js +430 -0
  26. package/dist/agents/workspace/outline-info.js.map +1 -0
  27. package/dist/agents/workspace/page-tree-generator.js +70 -0
  28. package/dist/agents/workspace/page-tree-generator.js.map +1 -0
  29. package/dist/agents/workspace/workspace.js +251 -0
  30. package/dist/agents/workspace/workspace.js.map +1 -0
  31. package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js +100 -0
  32. package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js.map +1 -0
  33. package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js +120 -0
  34. package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js.map +1 -0
  35. package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js +146 -0
  36. package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js.map +1 -0
  37. package/dist/agents/workspace-by-knowledges/test.js +242 -0
  38. package/dist/agents/workspace-by-knowledges/test.js.map +1 -0
  39. package/dist/agents/workspace-by-knowledges/utils/components-manager.js +132 -0
  40. package/dist/agents/workspace-by-knowledges/utils/components-manager.js.map +1 -0
  41. package/dist/agents/workspace-by-knowledges/utils/outline-focus.js +167 -0
  42. package/dist/agents/workspace-by-knowledges/utils/outline-focus.js.map +1 -0
  43. package/dist/agents/workspace-by-knowledges/utils/outline-info.js +430 -0
  44. package/dist/agents/workspace-by-knowledges/utils/outline-info.js.map +1 -0
  45. package/dist/agents/workspace-by-knowledges/workspace.js +169 -0
  46. package/dist/agents/workspace-by-knowledges/workspace.js.map +1 -0
  47. package/dist/api/cloud-components.js +85 -0
  48. package/dist/api/cloud-components.js.map +1 -0
  49. package/dist/api-record-replay/manager.js +168 -0
  50. package/dist/api-record-replay/manager.js.map +1 -0
  51. package/{src/api-record-replay/recorder.ts → dist/api-record-replay/recorder.js} +22 -32
  52. package/dist/api-record-replay/recorder.js.map +1 -0
  53. package/dist/api-record-replay/replayer.js +136 -0
  54. package/dist/api-record-replay/replayer.js.map +1 -0
  55. package/dist/components/attachments/index.js +124 -0
  56. package/dist/components/attachments/index.js.map +1 -0
  57. package/dist/components/attachments/index.less.js +8 -0
  58. package/dist/components/attachments/index.less.js.map +1 -0
  59. package/dist/components/icons/index.js +112 -0
  60. package/dist/components/icons/index.js.map +1 -0
  61. package/dist/components/icons/index.less.js +8 -0
  62. package/dist/components/icons/index.less.js.map +1 -0
  63. package/dist/components/mention/index.js +19 -0
  64. package/dist/components/mention/index.js.map +1 -0
  65. package/dist/components/mention/index.less.js +8 -0
  66. package/dist/components/mention/index.less.js.map +1 -0
  67. package/dist/components/messages/index.js +429 -0
  68. package/dist/components/messages/index.js.map +1 -0
  69. package/dist/components/messages/index.less.js +8 -0
  70. package/dist/components/messages/index.less.js.map +1 -0
  71. package/dist/components/sender/index.js +244 -0
  72. package/dist/components/sender/index.js.map +1 -0
  73. package/dist/components/sender/index.less.js +8 -0
  74. package/dist/components/sender/index.less.js.map +1 -0
  75. package/dist/context/RequestStatusTracker.js +44 -0
  76. package/dist/context/RequestStatusTracker.js.map +1 -0
  77. package/dist/context/index.js +45 -0
  78. package/dist/context/index.js.map +1 -0
  79. package/dist/data.js +4 -0
  80. package/dist/data.js.map +1 -0
  81. package/dist/index.js +306 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js +27 -0
  84. package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js.map +1 -0
  85. package/dist/plugin-ai/package.json.js +8 -0
  86. package/dist/plugin-ai/package.json.js.map +1 -0
  87. package/dist/plugin-ai/test/index.js +206 -0
  88. package/dist/plugin-ai/test/index.js.map +1 -0
  89. package/dist/preset/createTemplates.js +29 -0
  90. package/dist/preset/createTemplates.js.map +1 -0
  91. package/dist/preset/index.js +13 -0
  92. package/dist/preset/index.js.map +1 -0
  93. package/dist/preset/prompts.js +34 -0
  94. package/dist/preset/prompts.js.map +1 -0
  95. package/{src/preset/user.ts → dist/preset/user.js} +4 -3
  96. package/dist/preset/user.js.map +1 -0
  97. package/dist/requestAsStream.js +269 -0
  98. package/dist/requestAsStream.js.map +1 -0
  99. package/dist/rxai/node_modules/idb/build/index.js +277 -0
  100. package/dist/rxai/node_modules/idb/build/index.js.map +1 -0
  101. package/dist/rxai/src/agent/base.js +16 -0
  102. package/dist/rxai/src/agent/base.js.map +1 -0
  103. package/dist/rxai/src/agent/planning.js +1076 -0
  104. package/dist/rxai/src/agent/planning.js.map +1 -0
  105. package/dist/rxai/src/agent/rxai.js +254 -0
  106. package/dist/rxai/src/agent/rxai.js.map +1 -0
  107. package/dist/rxai/src/error/base.js +39 -0
  108. package/dist/rxai/src/error/base.js.map +1 -0
  109. package/dist/rxai/src/prompt/base.js +11 -0
  110. package/dist/rxai/src/prompt/base.js.map +1 -0
  111. package/dist/rxai/src/prompt/planning.js +23 -0
  112. package/dist/rxai/src/prompt/planning.js.map +1 -0
  113. package/dist/rxai/src/prompt/tool.js +14 -0
  114. package/dist/rxai/src/prompt/tool.js.map +1 -0
  115. package/dist/rxai/src/request/request.js +123 -0
  116. package/dist/rxai/src/request/request.js.map +1 -0
  117. package/dist/rxai/src/tool/getHistoryRecords.js +65 -0
  118. package/dist/rxai/src/tool/getHistoryRecords.js.map +1 -0
  119. package/dist/rxai/src/tool/util.js +424 -0
  120. package/dist/rxai/src/tool/util.js.map +1 -0
  121. package/dist/rxai/src/utils/events.js +43 -0
  122. package/dist/rxai/src/utils/events.js.map +1 -0
  123. package/dist/rxai/src/utils/idb.js +240 -0
  124. package/dist/rxai/src/utils/idb.js.map +1 -0
  125. package/dist/rxai/src/utils/retry.js +32 -0
  126. package/dist/rxai/src/utils/retry.js.map +1 -0
  127. package/dist/rxai/src/utils/uuid.js +7 -0
  128. package/dist/rxai/src/utils/uuid.js.map +1 -0
  129. package/dist/startView/components/header/header.js +12 -0
  130. package/dist/startView/components/header/header.js.map +1 -0
  131. package/dist/startView/components/header/header.less.js +8 -0
  132. package/dist/startView/components/header/header.less.js.map +1 -0
  133. package/dist/startView/index.js +62 -0
  134. package/dist/startView/index.js.map +1 -0
  135. package/dist/startView/index.less.js +8 -0
  136. package/dist/startView/index.less.js.map +1 -0
  137. package/dist/tools/analyze-and-expand-prd.js +116 -0
  138. package/dist/tools/analyze-and-expand-prd.js.map +1 -0
  139. package/dist/tools/analyze-requirement-and-components.js +208 -0
  140. package/dist/tools/analyze-requirement-and-components.js.map +1 -0
  141. package/dist/tools/answer.js +33 -0
  142. package/dist/tools/answer.js.map +1 -0
  143. package/dist/tools/build-process.js +550 -0
  144. package/dist/tools/build-process.js.map +1 -0
  145. package/dist/tools/coding-subagent-as-tool.js +101 -0
  146. package/dist/tools/coding-subagent-as-tool.js.map +1 -0
  147. package/dist/tools/generate-ui-content.js +528 -0
  148. package/dist/tools/generate-ui-content.js.map +1 -0
  149. package/dist/tools/index.js +31 -0
  150. package/dist/tools/index.js.map +1 -0
  151. package/dist/tools/open-dsl.js +49 -0
  152. package/dist/tools/open-dsl.js.map +1 -0
  153. package/dist/tools/refactor-ui-content.js +292 -0
  154. package/dist/tools/refactor-ui-content.js.map +1 -0
  155. package/dist/tools/utils.js +832 -0
  156. package/dist/tools/utils.js.map +1 -0
  157. package/dist/types/index.js +8 -0
  158. package/dist/types/index.js.map +1 -0
  159. package/dist/view/components/header/header.js +59 -0
  160. package/dist/view/components/header/header.js.map +1 -0
  161. package/dist/view/components/header/header.less.js +8 -0
  162. package/dist/view/components/header/header.less.js.map +1 -0
  163. package/dist/view/index.js +184 -0
  164. package/dist/view/index.js.map +1 -0
  165. package/dist/view/index.less.js +8 -0
  166. package/dist/view/index.less.js.map +1 -0
  167. package/package.json +28 -6
  168. package/src/agents/app.ts +0 -301
  169. package/src/agents/common.ts +0 -471
  170. package/src/agents/custom.ts +0 -14
  171. package/src/agents/index.ts +0 -37
  172. package/src/agents/knowledges/README.md +0 -614
  173. package/src/agents/knowledges/SUMMARY.md +0 -527
  174. package/src/agents/knowledges/index.ts +0 -8
  175. package/src/agents/knowledges/knowledge-base.ts +0 -565
  176. package/src/agents/knowledges/knowledge-node.ts +0 -266
  177. package/src/agents/knowledges/types.ts +0 -208
  178. package/src/agents/utils/config.ts +0 -427
  179. package/src/agents/workspace/coding-manager.ts +0 -31
  180. package/src/agents/workspace/components-manager.ts +0 -124
  181. package/src/agents/workspace/outline-focus.ts +0 -188
  182. package/src/agents/workspace/outline-info.ts +0 -520
  183. package/src/agents/workspace/page-tree-generator.ts +0 -83
  184. package/src/agents/workspace/workspace.ts +0 -319
  185. package/src/agents/workspace-by-knowledges/MIGRATION.md +0 -568
  186. package/src/agents/workspace-by-knowledges/README.md +0 -521
  187. package/src/agents/workspace-by-knowledges/index.ts +0 -11
  188. package/src/agents/workspace-by-knowledges/providers/component-docs-provider.ts +0 -92
  189. package/src/agents/workspace-by-knowledges/providers/focus-info-provider.ts +0 -131
  190. package/src/agents/workspace-by-knowledges/providers/index.ts +0 -8
  191. package/src/agents/workspace-by-knowledges/providers/project-info-provider.ts +0 -151
  192. package/src/agents/workspace-by-knowledges/test.ts +0 -240
  193. package/src/agents/workspace-by-knowledges/types.ts +0 -56
  194. package/src/agents/workspace-by-knowledges/utils/components-manager.ts +0 -145
  195. package/src/agents/workspace-by-knowledges/utils/index.ts +0 -8
  196. package/src/agents/workspace-by-knowledges/utils/outline-focus.ts +0 -178
  197. package/src/agents/workspace-by-knowledges/utils/outline-info.ts +0 -521
  198. package/src/agents/workspace-by-knowledges/workspace.ts +0 -166
  199. package/src/api/cloud-components.ts +0 -129
  200. package/src/api-record-replay/README.md +0 -187
  201. package/src/api-record-replay/index.ts +0 -11
  202. package/src/api-record-replay/manager.ts +0 -168
  203. package/src/api-record-replay/replayer.ts +0 -148
  204. package/src/components/attachments/index.less +0 -117
  205. package/src/components/attachments/index.tsx +0 -136
  206. package/src/components/icons/index.less +0 -8
  207. package/src/components/icons/index.tsx +0 -44
  208. package/src/components/index.less +0 -34
  209. package/src/components/mention/index.less +0 -23
  210. package/src/components/mention/index.tsx +0 -19
  211. package/src/components/messages/index.less +0 -1013
  212. package/src/components/messages/index.tsx +0 -519
  213. package/src/components/sender/index.less +0 -203
  214. package/src/components/sender/index.tsx +0 -298
  215. package/src/components/types.ts +0 -31
  216. package/src/constants/index.ts +0 -8
  217. package/src/context/RequestStatusTracker.ts +0 -50
  218. package/src/context/index.ts +0 -83
  219. package/src/data.ts +0 -5
  220. package/src/global.d.ts +0 -100
  221. package/src/index.tsx +0 -264
  222. package/src/mock.ts +0 -1267
  223. package/src/preset/agents.ts +0 -380
  224. package/src/preset/createTemplates.ts +0 -25
  225. package/src/preset/index.ts +0 -12
  226. package/src/preset/prompts.ts +0 -235
  227. package/src/preset/requestAsStream.ts +0 -246
  228. package/src/startView/components/header/header.less +0 -17
  229. package/src/startView/components/header/header.tsx +0 -15
  230. package/src/startView/components/index.ts +0 -1
  231. package/src/startView/index.less +0 -34
  232. package/src/startView/index.tsx +0 -61
  233. package/src/tools/analyze-and-expand-prd.ts +0 -272
  234. package/src/tools/analyze-requirement-and-components.ts +0 -589
  235. package/src/tools/answer.ts +0 -59
  236. package/src/tools/build-process.ts +0 -1174
  237. package/src/tools/coding-subagent-as-tool.ts +0 -119
  238. package/src/tools/generate-ui-content.ts +0 -1083
  239. package/src/tools/index.ts +0 -28
  240. package/src/tools/open-dsl.ts +0 -69
  241. package/src/tools/refactor-ui-content.ts +0 -801
  242. package/src/tools/type.d.ts +0 -12
  243. package/src/tools/utils.ts +0 -914
  244. package/src/types/index.ts +0 -4
  245. package/src/view/components/header/header.less +0 -51
  246. package/src/view/components/header/header.tsx +0 -60
  247. package/src/view/components/index.ts +0 -1
  248. package/src/view/index.less +0 -5
  249. package/src/view/index.tsx +0 -168
@@ -0,0 +1,832 @@
1
+ import { objectSpread2 as _objectSpread2, defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { jsonrepair } from 'jsonrepair';
3
+ import { ComponentsManager } from '../agents/workspace/components-manager.js';
4
+
5
+ function getFiles(files, _ref) {
6
+ var {
7
+ extName
8
+ } = _ref;
9
+ var result;
10
+ Object.keys(files).forEach(fileName => {
11
+ var file = files[fileName];
12
+ if (file.extension === extName) {
13
+ result = file;
14
+ }
15
+ });
16
+ return result;
17
+ }
18
+ function getComponentOperationSummary() {
19
+ var operations = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
20
+ var componentIdToTitleMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Map();
21
+ var componentActions = {};
22
+ var results = [];
23
+
24
+ // 收集组件title信息(补充传入映射中没有的新组件)
25
+ operations.forEach(operation => {
26
+ if (operation.type === 'addChild' && operation.params.title) {
27
+ componentIdToTitleMap.set(operation.params.comId, operation.params.title);
28
+ }
29
+ });
30
+ operations.forEach(operation => {
31
+ var _params$path, _params$path$split, _params$path$split$po, _params$to, _params$to2;
32
+ var {
33
+ comId,
34
+ type,
35
+ target,
36
+ params
37
+ } = operation;
38
+ switch (type) {
39
+ case 'doConfig':
40
+ var configTitle = componentIdToTitleMap.get(comId) || comId;
41
+ if (!componentActions[configTitle]) {
42
+ componentActions[configTitle] = {
43
+ configs: []
44
+ };
45
+ }
46
+ var simplifiedPath = (_params$path = params.path) === null || _params$path === void 0 || (_params$path$split = _params$path.split) === null || _params$path$split === void 0 || (_params$path$split = _params$path$split.call(_params$path, '/')) === null || _params$path$split === void 0 || (_params$path$split$po = _params$path$split.pop) === null || _params$path$split$po === void 0 ? void 0 : _params$path$split$po.call(_params$path$split);
47
+ componentActions[configTitle].configs.push(simplifiedPath);
48
+ break;
49
+ case 'addChild':
50
+ var parentTitle = componentIdToTitleMap.get(comId) || comId;
51
+
52
+ // 1. 先记录添加组件的操作
53
+ results.push("\u2022 \u5728\u3010".concat(parentTitle, "\u3011\u7684 ").concat(target, " \u63D2\u69FD\u4E2D\u65B0\u589E\u4E86\u300C").concat(params.title, "\u300D"));
54
+
55
+ // 2. 如果新组件有配置,单独记录配置操作
56
+ if (params.configs && params.configs.length > 0) {
57
+ var childConfigs = params.configs.map(config => {
58
+ var _config$path, _config$path$split, _config$path$split$po;
59
+ return (_config$path = config.path) === null || _config$path === void 0 || (_config$path$split = _config$path.split) === null || _config$path$split === void 0 || (_config$path$split = _config$path$split.call(_config$path, '/')) === null || _config$path$split === void 0 || (_config$path$split$po = _config$path$split.pop) === null || _config$path$split$po === void 0 ? void 0 : _config$path$split$po.call(_config$path$split);
60
+ });
61
+ results.push("\u2022 \u914D\u7F6E\u3010".concat(params.title, "\u3011\uFF1A\u8BBE\u7F6E\u4E86 ").concat(childConfigs.join('、'), " \u7B49\u5C5E\u6027"));
62
+ }
63
+ break;
64
+ case 'move':
65
+ var moveTitle = componentIdToTitleMap.get(comId);
66
+ var targetTitle = componentIdToTitleMap.get((_params$to = params.to) === null || _params$to === void 0 ? void 0 : _params$to.comId);
67
+ var slotId = (_params$to2 = params.to) === null || _params$to2 === void 0 ? void 0 : _params$to2.slotId;
68
+ if (moveTitle && targetTitle) {
69
+ results.push("\u2022 \u5C06\u3010".concat(moveTitle, "\u3011\u79FB\u52A8\u81F3\u3010").concat(targetTitle, "\u3011\u7684 ").concat(slotId, " \u63D2\u69FD\u4E2D"));
70
+ }
71
+ break;
72
+ case 'delete':
73
+ var deleteTitle = componentIdToTitleMap.get(comId);
74
+ if (deleteTitle) {
75
+ results.push("\u2022 \u5220\u9664\u4E86\u3010".concat(deleteTitle, "\u3011\u7EC4\u4EF6"));
76
+ } else {
77
+ // 如果没有title,可能是删除了一个没有被记录的组件
78
+ results.push("\u2022 \u5220\u9664\u4E86\u7EC4\u4EF6 ".concat(comId));
79
+ }
80
+ break;
81
+ }
82
+ });
83
+
84
+ // 处理独立的配置操作(doConfig类型)
85
+ Object.keys(componentActions).forEach(title => {
86
+ var actions = componentActions[title];
87
+ if (actions.configs.length > 0) {
88
+ results.push("\u2022 \u914D\u7F6E\u3010".concat(title, "\u3011\uFF1A\u8C03\u6574\u4E86 ").concat(actions.configs.join('、'), " \u7B49\u5C5E\u6027"));
89
+ }
90
+ });
91
+ return results.join('\n');
92
+ }
93
+ // 第二个参数用于透传当前解析器实例内的 comId -> params 映射,方便后续 O(1) 快查
94
+ var formatAction = (_action, comIdToParamsMap, options) => {
95
+ var _newAct$params4, _newAct$params5, _newAct$params6, _newAct$params1, _newAct$params11;
96
+ var {
97
+ enabledActionTags
98
+ } = options !== null && options !== void 0 ? options : {};
99
+ var action;
100
+ try {
101
+ // TODO,后面要提示词处理的,这样replace不合理
102
+ var fixActionString = _action.replaceAll('{":parent/', '{"path":":parent/');
103
+ action = JSON.parse(fixActionString);
104
+ } catch (error) {
105
+ try {
106
+ var repairedAction = jsonrepair(_action);
107
+ action = JSON.parse(repairedAction);
108
+ } catch (error) {
109
+ console.error("repair action error", error);
110
+ }
111
+ }
112
+ if (!Array.isArray(action)) {
113
+ return action;
114
+ }
115
+ var [comId, target, type, params] = action;
116
+ var newAct = {
117
+ comId,
118
+ type,
119
+ target,
120
+ params
121
+ };
122
+ if (newAct.type === "delete") {
123
+ if (!newAct.params) {
124
+ return _objectSpread2(_objectSpread2({}, newAct), {}, {
125
+ params: {}
126
+ });
127
+ }
128
+ }
129
+ if (newAct.type === 'move') {
130
+ if (newAct.params) {
131
+ return _objectSpread2(_objectSpread2({}, newAct), {}, {
132
+ params: {
133
+ to: newAct.params
134
+ }
135
+ });
136
+ }
137
+ }
138
+
139
+ // ns => namespace
140
+ if (newAct.type === "addChild") {
141
+ var _newAct$params;
142
+ if ((_newAct$params = newAct.params) !== null && _newAct$params !== void 0 && _newAct$params.ns) {
143
+ newAct.params.namespace = ComponentsManager.getFullNamespace(newAct.params.ns);
144
+ delete newAct.params.ns;
145
+ }
146
+ }
147
+
148
+ // 标记使用
149
+ if (newAct.type === 'addChild') {
150
+ if (enabledActionTags) {
151
+ var _newAct$params2;
152
+ if ((_newAct$params2 = newAct.params) !== null && _newAct$params2 !== void 0 && _newAct$params2.ignore) {
153
+ var _newAct$params3;
154
+ // TODO:标记的兼容,对于配置了ignore,但是有padding的组件,直接替换成enhance,因为直接去掉,底层的100%组件宽高会失效。
155
+ if (newAct !== null && newAct !== void 0 && (_newAct$params3 = newAct.params) !== null && _newAct$params3 !== void 0 && (_newAct$params3 = _newAct$params3.configs) !== null && _newAct$params3 !== void 0 && _newAct$params3.some(config => {
156
+ var _config$style;
157
+ return Object.keys((_config$style = config === null || config === void 0 ? void 0 : config.style) !== null && _config$style !== void 0 ? _config$style : {}).some(key => key.startsWith('padding'));
158
+ })) {
159
+ newAct.params.enhance = true;
160
+ delete newAct.params.ignore;
161
+ }
162
+
163
+ // TODO:标记的兼容,如果配置了enhance或者ignore的不是布局组件,需要删除该标记
164
+ if (!ComponentsManager.isLayoutComponent(newAct.params.namespace)) {
165
+ delete newAct.params.enhance;
166
+ delete newAct.params.ignore;
167
+ }
168
+
169
+ // TODO:标记的兼容,关注配置了ignore的父级元素是否为布局组件,如果不是,需要改成enhance而不是ignore,因为其他组件没有setLayout函数
170
+ if (comIdToParamsMap) {
171
+ var parentParams = comIdToParamsMap.get(newAct.comId);
172
+ if (!parentParams) {
173
+ // 没有父级组件,直接删除标记
174
+ delete newAct.params.enhance;
175
+ delete newAct.params.ignore;
176
+ } else {
177
+ // 有父级组件,判断父级组件是否为布局组件
178
+ var parentNamespace = parentParams === null || parentParams === void 0 ? void 0 : parentParams.namespace;
179
+ if (parentNamespace && !ComponentsManager.isLayoutComponent(parentNamespace)) {
180
+ newAct.params.enhance = true;
181
+ delete newAct.params.ignore;
182
+ }
183
+ }
184
+ }
185
+ }
186
+ } else {
187
+ if (newAct.params.enhance || newAct.params.ignore) {
188
+ delete newAct.params.enhance;
189
+ delete newAct.params.ignore;
190
+ }
191
+ }
192
+ }
193
+
194
+ // absolute 布局的转化
195
+ if (((_newAct$params4 = newAct.params) === null || _newAct$params4 === void 0 || (_newAct$params4 = _newAct$params4.value) === null || _newAct$params4 === void 0 ? void 0 : _newAct$params4.display) === "absolute") {
196
+ newAct.params.value.position = "smart";
197
+ delete newAct.params.value.display;
198
+ }
199
+
200
+ // flexDirection 的兼容
201
+ if ((_newAct$params5 = newAct.params) !== null && _newAct$params5 !== void 0 && _newAct$params5.value && newAct.params.value.display === "flex" && !newAct.params.value.flexDirection) {
202
+ newAct.params.value.flexDirection = "row";
203
+ }
204
+
205
+ // addChild兼容
206
+ if (newAct.type === "addChild" && Array.isArray((_newAct$params6 = newAct.params) === null || _newAct$params6 === void 0 ? void 0 : _newAct$params6.configs)) {
207
+ newAct.params.configs.forEach(config => {
208
+ var _config$value, _config$value2, _config$value3;
209
+ // path value幻觉,直接用key value的情况
210
+ if (!(config !== null && config !== void 0 && config.path) && Object.keys(config).length === 1) {
211
+ var firstKey = Object.keys(config)[0];
212
+ var value = config[firstKey];
213
+ delete config[firstKey];
214
+ config.path = firstKey;
215
+ config.value = value;
216
+ }
217
+ if (config.parent) {
218
+ config.path = ":parent/".concat(config.path);
219
+ delete config.parent;
220
+ }
221
+
222
+ // absolute 布局的转化
223
+ if ((config === null || config === void 0 || (_config$value = config.value) === null || _config$value === void 0 ? void 0 : _config$value.display) === "absolute") {
224
+ config.value.position = "smart";
225
+ delete config.value.display;
226
+ }
227
+
228
+ // flexDirection 的兼容
229
+ if (config.value && ((_config$value2 = config.value) === null || _config$value2 === void 0 ? void 0 : _config$value2.display) === "flex" && !((_config$value3 = config.value) !== null && _config$value3 !== void 0 && _config$value3.flexDirection)) {
230
+ config.value.flexDirection = "row";
231
+ }
232
+ if (config !== null && config !== void 0 && config.style) {
233
+ // 兼容background
234
+ transformToValidBackground(config === null || config === void 0 ? void 0 : config.style);
235
+ }
236
+ });
237
+ }
238
+
239
+ // flex布局幻觉的兼容
240
+ if (newAct.type === "doConfig") {
241
+ var _newAct$params7, _newAct$params8, _newAct$params9, _newAct$params0;
242
+ if (((_newAct$params7 = newAct.params) === null || _newAct$params7 === void 0 ? void 0 : _newAct$params7.display) === 'flex' && !((_newAct$params8 = newAct.params) !== null && _newAct$params8 !== void 0 && _newAct$params8.flexDirection)) {
243
+ newAct.params.flexDirection = 'column';
244
+ }
245
+ if ((_newAct$params9 = newAct.params) !== null && _newAct$params9 !== void 0 && _newAct$params9.flexDirection && !((_newAct$params0 = newAct.params) !== null && _newAct$params0 !== void 0 && _newAct$params0.display)) {
246
+ newAct.params.display = 'flex';
247
+ }
248
+ }
249
+
250
+ // 对样式幻觉的兼容
251
+ if (newAct.type === "doConfig" && (_newAct$params1 = newAct.params) !== null && _newAct$params1 !== void 0 && _newAct$params1.style) {
252
+ var _newAct$params10;
253
+ // 兼容background
254
+ transformToValidBackground((_newAct$params10 = newAct.params) === null || _newAct$params10 === void 0 ? void 0 : _newAct$params10.style);
255
+ }
256
+ if (newAct.type === "addChild" && (_newAct$params11 = newAct.params) !== null && _newAct$params11 !== void 0 && _newAct$params11.layout) {
257
+ var _newAct$params12, _newAct$params13;
258
+ // 兼容margin
259
+ transformToValidMargins((_newAct$params12 = newAct.params) === null || _newAct$params12 === void 0 ? void 0 : _newAct$params12.layout);
260
+
261
+ // 支持width=auto
262
+ if (((_newAct$params13 = newAct.params) === null || _newAct$params13 === void 0 || (_newAct$params13 = _newAct$params13.layout) === null || _newAct$params13 === void 0 ? void 0 : _newAct$params13.width) === 'auto') {
263
+ newAct.params.layout.width = '100%';
264
+ }
265
+ }
266
+
267
+ // 在所有兼容性处理之后,再记录 addChild 的配置,保证 namespace / layout 等信息已经就绪
268
+ if (comIdToParamsMap && newAct.type === "addChild") {
269
+ comIdToParamsMap.set(newAct.params.comId, JSON.parse(JSON.stringify(newAct.params)));
270
+ }
271
+ return newAct;
272
+ };
273
+
274
+ /**
275
+ * 将background转换为有效的backgroundColor和backgroundImage
276
+ * @param styles 需要转换的样式对象
277
+ */
278
+ function transformToValidBackground(styles) {
279
+ var _styles$backgroundCol;
280
+ // 兼容下把渐变色配置到backgroundColor的情况
281
+ if (styles !== null && styles !== void 0 && styles.backgroundColor && (styles === null || styles === void 0 || (_styles$backgroundCol = styles.backgroundColor) === null || _styles$backgroundCol === void 0 ? void 0 : _styles$backgroundCol.indexOf("gradient")) > -1) {
282
+ var imageRegex = /(url\([^)]+\)|linear-gradient\([^)]+\)|radial-gradient\([^)]+\)|conic-gradient\([^)]+\))/;
283
+ var imageMatch = styles.backgroundColor.match(imageRegex);
284
+ if (imageMatch && !styles.backgroundImage) {
285
+ styles.backgroundImage = imageMatch[0];
286
+ }
287
+ delete styles.backgroundColor;
288
+ }
289
+
290
+ // 兼容,配置backgroundColor的话记得去除渐变色
291
+ if (styles.backgroundColor && !styles.backgroundImage) {
292
+ styles.backgroundColor = styles.backgroundColor;
293
+ styles.backgroundImage = 'none';
294
+ }
295
+
296
+ // 如果没有background属性,直接返回
297
+ if (!styles.background) {
298
+ return;
299
+ }
300
+ var background = styles.background.toString().trim();
301
+
302
+ // 删除原有的background属性
303
+ delete styles.background;
304
+
305
+ // 处理特殊值
306
+ if (background === 'transparent' || background === 'none') {
307
+ styles.backgroundColor = 'transparent';
308
+ styles.backgroundImage = 'none';
309
+ return;
310
+ }
311
+
312
+ // 解析复合背景
313
+ var parsedBackground = parseComplexBackground(background);
314
+ if (parsedBackground.hasImages && !styles.backgroundImage) {
315
+ styles.backgroundColor = 'transparent';
316
+ styles.backgroundImage = parsedBackground.images.join(', ');
317
+
318
+ // 设置背景位置和尺寸
319
+ if (parsedBackground.position && !styles.backgroundPosition) {
320
+ styles.backgroundPosition = parsedBackground.position;
321
+ }
322
+ if (parsedBackground.size && !styles.backgroundSize) {
323
+ styles.backgroundSize = parsedBackground.size;
324
+ }
325
+ return;
326
+ }
327
+
328
+ // 如果只有颜色
329
+ if (parsedBackground.color && !styles.backgroundColor) {
330
+ styles.backgroundColor = parsedBackground.color;
331
+ if (!styles.backgroundImage) {
332
+ styles.backgroundImage = 'none';
333
+ }
334
+ return;
335
+ }
336
+
337
+ // 如果没有找到颜色,但有backgroundImage,设置透明背景色
338
+ if (styles.backgroundImage && !styles.backgroundColor) {
339
+ styles.backgroundColor = 'transparent';
340
+ }
341
+ }
342
+
343
+ /**
344
+ * 解析复杂的background值
345
+ * @param background 原始background字符串
346
+ * @returns 解析后的对象
347
+ */
348
+ function parseComplexBackground(background) {
349
+ var result = {
350
+ images: [],
351
+ color: '',
352
+ position: '',
353
+ size: '',
354
+ hasImages: false
355
+ };
356
+
357
+ // 使用更精确的方法来提取图片和渐变
358
+ var images = extractBackgroundImages(background);
359
+ if (images.length > 0) {
360
+ result.hasImages = true;
361
+ result.images = images;
362
+
363
+ // 提取位置和尺寸信息
364
+ var positionSizeInfo = extractPositionAndSize(background, images);
365
+ result.position = positionSizeInfo.position;
366
+ result.size = positionSizeInfo.size;
367
+ }
368
+
369
+ // 提取颜色值
370
+ var color = extractBackgroundColor(background, images);
371
+ if (color) {
372
+ result.color = color;
373
+ }
374
+ return result;
375
+ }
376
+
377
+ /**
378
+ * 提取背景图片和渐变
379
+ */
380
+ function extractBackgroundImages(background) {
381
+ var images = [];
382
+ var remaining = background;
383
+ while (remaining.length > 0) {
384
+ // 查找下一个函数的开始
385
+ var urlMatch = remaining.match(/url\s*\(/);
386
+ var gradientMatch = remaining.match(/(linear-gradient|radial-gradient|conic-gradient)\s*\(/);
387
+ var nextMatch = null;
388
+ if (urlMatch && gradientMatch) {
389
+ // 选择更早出现的匹配
390
+ if (urlMatch.index < gradientMatch.index) {
391
+ nextMatch = urlMatch;
392
+ } else {
393
+ nextMatch = gradientMatch;
394
+ }
395
+ } else if (urlMatch) {
396
+ nextMatch = urlMatch;
397
+ } else if (gradientMatch) {
398
+ nextMatch = gradientMatch;
399
+ }
400
+ if (!nextMatch) {
401
+ break;
402
+ }
403
+ var startIndex = nextMatch.index;
404
+ var functionStart = remaining.indexOf('(', startIndex) + 1;
405
+
406
+ // 找到匹配的右括号
407
+ var parenCount = 1;
408
+ var endIndex = functionStart;
409
+ while (endIndex < remaining.length && parenCount > 0) {
410
+ if (remaining[endIndex] === '(') {
411
+ parenCount++;
412
+ } else if (remaining[endIndex] === ')') {
413
+ parenCount--;
414
+ }
415
+ endIndex++;
416
+ }
417
+ if (parenCount === 0) {
418
+ // 提取完整的函数
419
+ var fullFunction = remaining.substring(startIndex, endIndex);
420
+ images.push(fullFunction);
421
+
422
+ // 移除已处理的部分
423
+ remaining = remaining.substring(endIndex);
424
+ } else {
425
+ // 如果括号不匹配,跳过这个匹配
426
+ remaining = remaining.substring(startIndex + 1);
427
+ }
428
+ }
429
+ return images;
430
+ }
431
+
432
+ /**
433
+ * 提取位置和尺寸信息
434
+ */
435
+ function extractPositionAndSize(background, images) {
436
+ var cleanBackground = background;
437
+
438
+ // 移除所有图片和渐变
439
+ images.forEach(image => {
440
+ cleanBackground = cleanBackground.replace(image, '');
441
+ });
442
+
443
+ // 清理多余的逗号和空格
444
+ cleanBackground = cleanBackground.replace(/,\s*,/g, ',').replace(/^\s*,\s*|\s*,\s*$/g, '').trim();
445
+
446
+ // 匹配位置/尺寸模式 (如: center/cover, top left/contain)
447
+ var positionSizeMatch = cleanBackground.match(/([^\/,]*?)\/([^\/,]*)/);
448
+ var position = '';
449
+ var size = '';
450
+ if (positionSizeMatch) {
451
+ var _positionSizeMatch$, _positionSizeMatch$2;
452
+ var positionPart = (_positionSizeMatch$ = positionSizeMatch[1]) === null || _positionSizeMatch$ === void 0 ? void 0 : _positionSizeMatch$.trim();
453
+ var sizePart = (_positionSizeMatch$2 = positionSizeMatch[2]) === null || _positionSizeMatch$2 === void 0 ? void 0 : _positionSizeMatch$2.trim();
454
+ if (positionPart && isValidBackgroundPosition(positionPart)) {
455
+ position = positionPart;
456
+ }
457
+ if (sizePart && isValidBackgroundSize(sizePart)) {
458
+ size = sizePart;
459
+ }
460
+ } else {
461
+ // 如果没有找到 / 分隔符,尝试单独匹配位置或尺寸
462
+ var parts = cleanBackground.split(/\s+/).filter(part => part.length > 0);
463
+ for (var part of parts) {
464
+ if (!position && isValidBackgroundPosition(part)) {
465
+ position = part;
466
+ } else if (!size && isValidBackgroundSize(part)) {
467
+ size = part;
468
+ }
469
+ }
470
+ }
471
+ return {
472
+ position,
473
+ size
474
+ };
475
+ }
476
+
477
+ /**
478
+ * 提取背景颜色
479
+ */
480
+ function extractBackgroundColor(background, images) {
481
+ var cleanBackground = background;
482
+
483
+ // 移除所有图片和渐变
484
+ images.forEach(image => {
485
+ cleanBackground = cleanBackground.replace(image, '');
486
+ });
487
+
488
+ // 移除位置和尺寸信息
489
+ cleanBackground = cleanBackground.replace(/\s*(center|top|bottom|left|right|\d+%|\d+px)\s*/g, ' ');
490
+ cleanBackground = cleanBackground.replace(/\s*\/\s*(cover|contain|auto|\d+%|\d+px)\s*/g, ' ');
491
+ cleanBackground = cleanBackground.replace(/,\s*,/g, ',').replace(/^\s*,\s*|\s*,\s*$/g, '').trim();
492
+
493
+ // 匹配颜色格式
494
+ var colorRegex = /(#[0-9A-Fa-f]{3,6}|rgb\([^)]+\)|rgba\([^)]+\)|hsl\([^)]+\)|hsla\([^)]+\)|[a-zA-Z]+)/;
495
+ var colorMatch = cleanBackground.match(colorRegex);
496
+ return colorMatch ? colorMatch[0] : '';
497
+ }
498
+
499
+ /**
500
+ * 检查是否是有效的背景位置值
501
+ */
502
+ function isValidBackgroundPosition(value) {
503
+ var positionKeywords = ['center', 'top', 'bottom', 'left', 'right'];
504
+ var parts = value.split(/\s+/);
505
+ return parts.every(part => positionKeywords.includes(part) || /^\d+%$/.test(part) || /^\d+px$/.test(part) || /^-?\d+(\.\d+)?(px|em|rem|%)$/.test(part));
506
+ }
507
+
508
+ /**
509
+ * 检查是否是有效的背景尺寸值
510
+ */
511
+ function isValidBackgroundSize(value) {
512
+ var sizeKeywords = ['cover', 'contain', 'auto'];
513
+ if (sizeKeywords.includes(value)) {
514
+ return true;
515
+ }
516
+ var parts = value.split(/\s+/);
517
+ return parts.every(part => part === 'auto' || /^\d+%$/.test(part) || /^\d+px$/.test(part) || /^-?\d+(\.\d+)?(px|em|rem|%)$/.test(part));
518
+ }
519
+
520
+ /**
521
+ * 将margin简写转换为marginTop/Right/Bottom/Left
522
+ * @param styles 需要转换的样式对象
523
+ */
524
+ function transformToValidMargins(styles) {
525
+ // 如果没有margin属性,直接返回
526
+ if (!styles.margin) {
527
+ return;
528
+ }
529
+ var margin = styles.margin.toString().trim();
530
+ var values = margin.split(/\s+/); // 按空格分割
531
+
532
+ // 根据值的数量设置不同方向的margin
533
+ switch (values.length) {
534
+ case 1:
535
+ // margin: 10px;
536
+ styles.marginTop = values[0];
537
+ styles.marginRight = values[0];
538
+ styles.marginBottom = values[0];
539
+ styles.marginLeft = values[0];
540
+ break;
541
+ case 2:
542
+ // margin: 10px 20px;
543
+ styles.marginTop = values[0];
544
+ styles.marginRight = values[1];
545
+ styles.marginBottom = values[0];
546
+ styles.marginLeft = values[1];
547
+ break;
548
+ case 3:
549
+ // margin: 10px 20px 30px;
550
+ styles.marginTop = values[0];
551
+ styles.marginRight = values[1];
552
+ styles.marginBottom = values[2];
553
+ styles.marginLeft = values[1];
554
+ break;
555
+ case 4:
556
+ // margin: 10px 20px 30px 40px;
557
+ styles.marginTop = values[0];
558
+ styles.marginRight = values[1];
559
+ styles.marginBottom = values[2];
560
+ styles.marginLeft = values[3];
561
+ break;
562
+ }
563
+
564
+ // 删除原有的margin属性
565
+ delete styles.margin;
566
+ }
567
+
568
+ /**
569
+ * 将解析出的一条 action 推入列表,若为 addChild 且带 index 则追加对应 move
570
+ */
571
+ function pushParsedAction(newActions, parsedAction, processedLines, trimmedLine) {
572
+ if (!parsedAction.comId) return;
573
+ newActions.push(parsedAction);
574
+ if (parsedAction.type === 'addChild' && parsedAction.params.index !== undefined) {
575
+ newActions.push({
576
+ comId: parsedAction.params.comId,
577
+ target: ':root',
578
+ type: 'move',
579
+ params: {
580
+ to: {
581
+ comId: parsedAction.comId,
582
+ slotId: parsedAction.target,
583
+ index: parsedAction.params.index
584
+ }
585
+ }
586
+ });
587
+ }
588
+ processedLines.add(trimmedLine);
589
+ }
590
+
591
+ /**
592
+ * 创建actions解析器
593
+ * @param options.enabledActionTags 是否启用 action tags
594
+ * @returns 解析函数 parseActions(text, isEnd?)
595
+ * - text: 待解析的 actions 文本(可流式追加)
596
+ * - isEnd: 是否为结束标记;为 true 时最后一行即使没有回车符也会被当作完整行解析
597
+ */
598
+ function createActionsParser(_ref2) {
599
+ var {
600
+ enabledActionTags
601
+ } = _ref2;
602
+ var processedLines = new Set();
603
+ var comIdToParamsMap = new Map();
604
+ return function parseActions(text, isEnd) {
605
+ var newActions = [];
606
+ var lines = text.split("\n").filter(line => line.trim() !== '');
607
+ var linesToProcess = lines.slice(0, -1);
608
+ var lastLine = lines[lines.length - 1];
609
+ var lastLineComplete = lines.length === 0 || text.endsWith("\n") || isEnd === true;
610
+ for (var line of linesToProcess) {
611
+ var trimmedLine = line.trim();
612
+ if (!trimmedLine || processedLines.has(trimmedLine)) continue;
613
+ try {
614
+ var parsedAction = formatAction(trimmedLine, comIdToParamsMap, {
615
+ enabledActionTags
616
+ });
617
+ pushParsedAction(newActions, parsedAction, processedLines, trimmedLine);
618
+ } catch (_unused) {
619
+ processedLines.add(trimmedLine);
620
+ }
621
+ }
622
+ if (lastLine && lastLine.trim() && lastLineComplete && !processedLines.has(lastLine.trim())) {
623
+ var trimmedLastLine = lastLine.trim();
624
+ try {
625
+ var _parsedAction = formatAction(trimmedLastLine, comIdToParamsMap, {
626
+ enabledActionTags
627
+ });
628
+ pushParsedAction(newActions, _parsedAction, processedLines, trimmedLastLine);
629
+ } catch (_unused2) {
630
+ processedLines.add(trimmedLastLine);
631
+ }
632
+ }
633
+ return newActions;
634
+ };
635
+ }
636
+ function stripFileBlocks(raw) {
637
+ if (typeof raw !== "string") {
638
+ return "";
639
+ }
640
+ var fileBlockRegex = /```[^\n]*title\s*=\s*"[^"\n]*"?[\s\S]*?```/g;
641
+ var cleaned = raw.replace(fileBlockRegex, '');
642
+
643
+ // 去掉多余空行:连续空白行压缩为单个换行,再首尾 trim
644
+ cleaned = cleaned.replace(/\n{2,}/g, '\n') // 多个换行压缩为一个
645
+ .trim();
646
+ return cleaned;
647
+ }
648
+ function jsonSafeParse(input) {
649
+ var finalError;
650
+ try {
651
+ return JSON.parse(input);
652
+ } catch (error) {
653
+ finalError = error;
654
+ try {
655
+ var repairedJson = jsonrepair(input);
656
+ return JSON.parse(repairedJson);
657
+ } catch (repairError) {
658
+ // 修复也失败了,抛出错误
659
+ throw finalError;
660
+ }
661
+ }
662
+ }
663
+
664
+ /** PC */
665
+
666
+ /** 鸿蒙 */
667
+
668
+ /** 获取pages,兼容spa和mpa */
669
+ var transformPageInfo = pageInfo => {
670
+ var pages = [];
671
+ pageInfo === null || pageInfo === void 0 || pageInfo.forEach(page => {
672
+ if ("pageAry" in page) {
673
+ pages.push(...page.pageAry);
674
+ } else {
675
+ pages.push(page);
676
+ }
677
+ });
678
+ return pages;
679
+ };
680
+ var formatVarAction = _action => {
681
+ var action;
682
+ try {
683
+ // TODO,后面要提示词处理的,这样replace不合理
684
+ var fixActionString = _action.replaceAll('{":parent/', '{"path":":parent/');
685
+ action = JSON.parse(fixActionString);
686
+ } catch (error) {
687
+ try {
688
+ var repairedAction = jsonrepair(_action);
689
+ action = JSON.parse(repairedAction);
690
+ console.log("[action]", action);
691
+ } catch (error) {
692
+ console.error("repair action error", error);
693
+ }
694
+ }
695
+ if (!Array.isArray(action)) {
696
+ return action;
697
+ }
698
+ return action;
699
+ };
700
+ function createVarActionsParser() {
701
+ var processedLines = new Set();
702
+ return function parseActions(text) {
703
+ var newActions = [];
704
+ var lines = text.split("\n").filter(line => line.trim() !== '');
705
+
706
+ // 只处理除了最后一行之外的所有行(最后一行可能不完整)
707
+ var linesToProcess = lines.slice(0, -1);
708
+ var lastLine = lines[lines.length - 1];
709
+
710
+ // 处理完整的行
711
+ for (var line of linesToProcess) {
712
+ var trimmedLine = line.trim();
713
+
714
+ // 跳过空行和已处理的行
715
+ if (!trimmedLine || processedLines.has(trimmedLine)) {
716
+ continue;
717
+ }
718
+ try {
719
+ var parsedAction = formatVarAction(trimmedLine);
720
+ newActions.push(parsedAction);
721
+ processedLines.add(trimmedLine);
722
+ } catch (error) {
723
+ // 这是真正的解析错误(完整的行但格式错误)
724
+ processedLines.add(trimmedLine); // 标记为已处理,避免重复尝试
725
+ }
726
+ }
727
+
728
+ // 处理最后一行
729
+ if (lastLine && lastLine.trim()) {
730
+ var trimmedLastLine = lastLine.trim();
731
+
732
+ // 如果文本以换行符结尾,说明最后一行是完整的
733
+ if (text.endsWith("\n") && !processedLines.has(trimmedLastLine)) {
734
+ try {
735
+ var _parsedAction2 = formatVarAction(trimmedLastLine);
736
+ newActions.push(_parsedAction2);
737
+ processedLines.add(trimmedLastLine);
738
+ } catch (error) {
739
+ processedLines.add(trimmedLastLine);
740
+ }
741
+ }
742
+ }
743
+
744
+ // processedLines.clear();
745
+
746
+ return newActions;
747
+ };
748
+ }
749
+ var UUID_SEED = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
750
+ var uuid = function uuid() {
751
+ var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
752
+ var maxPos = UUID_SEED.length;
753
+ var rtn = '';
754
+ for (var i = 0; i < len; i++) {
755
+ rtn += UUID_SEED.charAt(Math.floor(Math.random() * maxPos));
756
+ }
757
+ return 'u_' + rtn;
758
+ };
759
+ class ComIdTransform {
760
+ constructor(comIds) {
761
+ _defineProperty(this, "comIdMap", {});
762
+ var {
763
+ comIdMap
764
+ } = this;
765
+ comIds.forEach(comId => {
766
+ comIdMap[comId] = [comId];
767
+ });
768
+ }
769
+ getComId(comId) {
770
+ if (!this.comIdMap[comId] || this.comIdMap[comId].length === 0) {
771
+ var newComId = uuid();
772
+ this.comIdMap[comId] = [newComId];
773
+ return newComId;
774
+ }
775
+
776
+ // 返回最近添加的comId(数组的最后一个)
777
+ return this.comIdMap[comId][this.comIdMap[comId].length - 1];
778
+ }
779
+
780
+ // 添加新的comId映射,用于addChild操作
781
+ addComId(comId) {
782
+ var newComId = uuid();
783
+ if (!this.comIdMap[comId]) {
784
+ this.comIdMap[comId] = [];
785
+ }
786
+ this.comIdMap[comId].push(newComId);
787
+ return newComId;
788
+ }
789
+ }
790
+ class PromiseStack {
791
+ constructor() {
792
+ _defineProperty(this, "stack", []);
793
+ _defineProperty(this, "currentPromise", null);
794
+ }
795
+ add(promiseFn) {
796
+ this.stack.push(promiseFn);
797
+ this.run();
798
+ }
799
+ run() {
800
+ var _this = this;
801
+ return _asyncToGenerator(function* () {
802
+ var catchNext = false;
803
+ try {
804
+ if (_this.currentPromise) {
805
+ return;
806
+ }
807
+ var promiseFn = _this.stack.shift();
808
+ if (promiseFn) {
809
+ var promise = promiseFn();
810
+ if (Object.prototype.toString.call(promise) === "[object Promise]") {
811
+ _this.currentPromise = promise;
812
+ catchNext = true;
813
+ yield promise;
814
+ _this.currentPromise = null;
815
+ _this.run();
816
+ } else {
817
+ _this.run();
818
+ }
819
+ }
820
+ } catch (e) {
821
+ console.error(e);
822
+ if (catchNext) {
823
+ _this.currentPromise = null;
824
+ _this.run();
825
+ }
826
+ }
827
+ })();
828
+ }
829
+ }
830
+
831
+ export { ComIdTransform, PromiseStack, createActionsParser, createVarActionsParser, getComponentOperationSummary, getFiles, jsonSafeParse, stripFileBlocks, transformPageInfo, uuid };
832
+ //# sourceMappingURL=utils.js.map