@shijiu/jsview 1.9.719

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 (148) hide show
  1. package/dom/bin/jsview-browser-debug-dom.min.js +1 -0
  2. package/dom/bin/jsview-dom.min.js +1 -0
  3. package/dom/bin/jsview-engine-js-browser.min.js +1 -0
  4. package/dom/bin/jsview-forge-define.min.js +1 -0
  5. package/dom/browser-root-style.css +21 -0
  6. package/dom/jsv-browser-debug-dom.js +8 -0
  7. package/dom/jsv-dom.js +6 -0
  8. package/dom/jsv-engine-js-browser.js +6 -0
  9. package/dom/jsv-forge-define.js +6 -0
  10. package/dom/jsview-dom/README.md +5 -0
  11. package/dom/jsview-dom/package-lock.json-perfect +3898 -0
  12. package/dom/jsview-dom/package.json +23 -0
  13. package/dom/jsview-dom/rollup/browser-debug-dom.rollup.config.js +15 -0
  14. package/dom/jsview-dom/rollup/dom.rollup.config.js +14 -0
  15. package/dom/jsview-dom/rollup/engine-js-browser.rollup.config.js +14 -0
  16. package/dom/jsview-dom/rollup/forge-define.rollup.config.js +14 -0
  17. package/dom/jsview-dom/scripts/release_dist.sh +36 -0
  18. package/dom/jsview-dom/src/dom-browser-hook/HookDocument.js +118 -0
  19. package/dom/jsview-dom/src/dom-browser-hook/OriginDocument.js +19 -0
  20. package/dom/jsview-dom/src/dom-browser-hook/StyleFormatCheck.js +559 -0
  21. package/dom/jsview-dom/src/dom-browser-hook/index.js +6 -0
  22. package/dom/jsview-dom/src/dom-wrapper/ForgeExtension.js +226 -0
  23. package/dom/jsview-dom/src/dom-wrapper/JsViewForgeApp.js +85 -0
  24. package/dom/jsview-dom/src/dom-wrapper/JsViewProxy.js +51 -0
  25. package/dom/jsview-dom/src/dom-wrapper/event/AnimationEvent.js +7 -0
  26. package/dom/jsview-dom/src/dom-wrapper/event/Event.js +12 -0
  27. package/dom/jsview-dom/src/dom-wrapper/event/FocusEvent.js +9 -0
  28. package/dom/jsview-dom/src/dom-wrapper/event/KeyboardEvent.js +43 -0
  29. package/dom/jsview-dom/src/dom-wrapper/event/LoadEvent.js +8 -0
  30. package/dom/jsview-dom/src/dom-wrapper/index.js +16 -0
  31. package/dom/jsview-dom/src/dom-wrapper/node/AnchorElement.js +24 -0
  32. package/dom/jsview-dom/src/dom-wrapper/node/AudioElement.js +60 -0
  33. package/dom/jsview-dom/src/dom-wrapper/node/Comment.js +10 -0
  34. package/dom/jsview-dom/src/dom-wrapper/node/DivElement.js +498 -0
  35. package/dom/jsview-dom/src/dom-wrapper/node/Document.js +274 -0
  36. package/dom/jsview-dom/src/dom-wrapper/node/Element.js +852 -0
  37. package/dom/jsview-dom/src/dom-wrapper/node/FDivElement.js +48 -0
  38. package/dom/jsview-dom/src/dom-wrapper/node/HeadElement.js +47 -0
  39. package/dom/jsview-dom/src/dom-wrapper/node/ImageElement.js +203 -0
  40. package/dom/jsview-dom/src/dom-wrapper/node/JsvAudioTrackElement.js +22 -0
  41. package/dom/jsview-dom/src/dom-wrapper/node/JsvElement.js +40 -0
  42. package/dom/jsview-dom/src/dom-wrapper/node/LinkElement.js +48 -0
  43. package/dom/jsview-dom/src/dom-wrapper/node/MediaElement.js +230 -0
  44. package/dom/jsview-dom/src/dom-wrapper/node/Node.js +178 -0
  45. package/dom/jsview-dom/src/dom-wrapper/node/SVGElement.js +9 -0
  46. package/dom/jsview-dom/src/dom-wrapper/node/ScriptElement.js +45 -0
  47. package/dom/jsview-dom/src/dom-wrapper/node/StyleElement.js +33 -0
  48. package/dom/jsview-dom/src/dom-wrapper/node/StyleElementCache.js +41 -0
  49. package/dom/jsview-dom/src/dom-wrapper/node/Text.js +22 -0
  50. package/dom/jsview-dom/src/dom-wrapper/node/UnknownElement.js +4 -0
  51. package/dom/jsview-dom/src/dom-wrapper/node/VideoElement.js +237 -0
  52. package/dom/jsview-dom/src/dom-wrapper/style/BorderImage.js +25 -0
  53. package/dom/jsview-dom/src/dom-wrapper/style/Inset.js +26 -0
  54. package/dom/jsview-dom/src/dom-wrapper/style/JsvStyleVariable.js +65 -0
  55. package/dom/jsview-dom/src/dom-wrapper/style/KeyframeRule.js +11 -0
  56. package/dom/jsview-dom/src/dom-wrapper/style/StyleDeclaration.js +609 -0
  57. package/dom/jsview-dom/src/dom-wrapper/style/StyleSheet.js +51 -0
  58. package/dom/jsview-dom/src/dom-wrapper/style/StyleValue.js +385 -0
  59. package/dom/jsview-dom/src/dom-wrapper/style/TextStylePackMap.js +43 -0
  60. package/dom/jsview-dom/src/dom-wrapper/style/URL.js +144 -0
  61. package/dom/jsview-dom/src/dom-wrapper/utils/EventHandler.js +42 -0
  62. package/dom/jsview-dom/src/dom-wrapper/utils/FDivRoot.js +86 -0
  63. package/dom/jsview-dom/src/dom-wrapper/utils/JsvLazySyncCache.js +64 -0
  64. package/dom/jsview-dom/src/dom-wrapper/utils/Log.js +42 -0
  65. package/dom/jsview-dom/src/dom-wrapper/utils/MutationObserver.js +32 -0
  66. package/dom/jsview-dom/src/dom-wrapper/utils/focusableNode.js +715 -0
  67. package/dom/jsview-dom/src/engine-js/ForgeDefine.js +8 -0
  68. package/dom/jsview-dom/src/engine-js/ForgeExtensionDefine.js +14 -0
  69. package/dom/jsview-dom/src/engine-js/browser/PlatformUtils.js +100 -0
  70. package/dom/jsview-dom/src/engine-js/browser/animation_base.js +313 -0
  71. package/dom/jsview-dom/src/engine-js/browser/animation_keyframe.js +64 -0
  72. package/dom/jsview-dom/src/engine-js/browser/animation_progress.js +287 -0
  73. package/dom/jsview-dom/src/engine-js/browser/animation_proxy.js +906 -0
  74. package/dom/jsview-dom/src/engine-js/browser/apic_decoder/demux.js +143 -0
  75. package/dom/jsview-dom/src/engine-js/browser/apic_decoder/gifDecoder.js +12 -0
  76. package/dom/jsview-dom/src/engine-js/browser/apic_decoder/libwebp-0.6.0.min.js +160 -0
  77. package/dom/jsview-dom/src/engine-js/browser/console_log.js +25 -0
  78. package/dom/jsview-dom/src/engine-js/browser/dynamic_key_frames.js +95 -0
  79. package/dom/jsview-dom/src/engine-js/browser/easing.js +114 -0
  80. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/element_transform.js +122 -0
  81. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/gjk.js +450 -0
  82. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/mat.js +102 -0
  83. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/range_model.js +296 -0
  84. package/dom/jsview-dom/src/engine-js/browser/html_shared_tools/test_collide.js +10 -0
  85. package/dom/jsview-dom/src/engine-js/browser/index.js +38 -0
  86. package/dom/jsview-dom/src/engine-js/browser/latex_parse.js +336 -0
  87. package/dom/jsview-dom/src/engine-js/browser/layout_params.js +113 -0
  88. package/dom/jsview-dom/src/engine-js/browser/layout_view.js +3545 -0
  89. package/dom/jsview-dom/src/engine-js/browser/layout_view_debug.js +15 -0
  90. package/dom/jsview-dom/src/engine-js/browser/media.js +379 -0
  91. package/dom/jsview-dom/src/engine-js/browser/page_base.js +941 -0
  92. package/dom/jsview-dom/src/engine-js/browser/particle_view.js +526 -0
  93. package/dom/jsview-dom/src/engine-js/browser/platform_timer.js +61 -0
  94. package/dom/jsview-dom/src/engine-js/browser/react_utils.js +5 -0
  95. package/dom/jsview-dom/src/engine-js/browser/rect_utils.js +91 -0
  96. package/dom/jsview-dom/src/engine-js/browser/render_bridge.js +128 -0
  97. package/dom/jsview-dom/src/engine-js/browser/render_texture_proxy.js +155 -0
  98. package/dom/jsview-dom/src/engine-js/browser/renderer_deprecated.js +75 -0
  99. package/dom/jsview-dom/src/engine-js/browser/sound_pool.js +139 -0
  100. package/dom/jsview-dom/src/engine-js/browser/steps_animation.js +192 -0
  101. package/dom/jsview-dom/src/engine-js/browser/text_style_cache.js +454 -0
  102. package/dom/jsview-dom/src/engine-js/browser/text_utils.js +299 -0
  103. package/dom/jsview-dom/src/engine-js/browser/text_view.js +428 -0
  104. package/dom/jsview-dom/src/engine-js/browser/texture_manager.js +1060 -0
  105. package/dom/jsview-dom/src/engine-js/browser/url.js +69 -0
  106. package/dom/jsview-dom/src/engine-js/browser/velocity.js +40 -0
  107. package/dom/jsview-dom/src/engine-js/browser/view_sensor/autofroze_sensor.js +77 -0
  108. package/dom/jsview-dom/src/engine-js/browser/view_sensor/drag_impact_sensor.js +67 -0
  109. package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor.js +98 -0
  110. package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor_callback.js +21 -0
  111. package/dom/jsview-dom/src/engine-js/browser/view_sensor/impact_sensor_manager.js +24 -0
  112. package/dom/jsview-dom/src/engine-js/browser/view_sensor/index.js +9 -0
  113. package/dom/jsview-dom/src/engine-js/browser/view_sensor/view_sensor.js +268 -0
  114. package/dom/jsview-dom/src/engine-js/browser/view_sensor/view_sensor_manager.js +84 -0
  115. package/dom/jsview-dom/src/engine-js/browser/view_sensor/visible_sensor.js +213 -0
  116. package/dom/jsview-dom/src/engine-js/browser/view_store.js +41 -0
  117. package/dom/jsview-dom/src/engine-js/index.js +2 -0
  118. package/dom/jsview-dom/src/engine-js/native/README.md +1 -0
  119. package/dom/target_core_revision.mjs +15 -0
  120. package/index.js +0 -0
  121. package/loader/header_script_loader.js +134 -0
  122. package/loader/jsview-main.js +42 -0
  123. package/loader/jsview.config.default.js +37 -0
  124. package/loader/jsview.default.config.js +37 -0
  125. package/loader/loader.js +183 -0
  126. package/loader/loader_webkit.js +40 -0
  127. package/package.json +31 -0
  128. package/patches/node_modules/@vitejs/plugin-react/dist/index.cjs +520 -0
  129. package/patches/node_modules/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +17609 -0
  130. package/patches/node_modules/@vue/compiler-sfc/dist/jsview-css-to-js.js +335 -0
  131. package/patches/node_modules/@vue/compiler-sfc/dist/jsview-style-format.js +446 -0
  132. package/patches/node_modules/@vue/compiler-sfc/dist/jsview-style-types.js +91 -0
  133. package/patches/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js +8038 -0
  134. package/patches/node_modules/@vue/runtime-dom/dist/runtime-dom.esm-bundler.js +1700 -0
  135. package/patches/node_modules/postcss-js/objectifier.js +90 -0
  136. package/patches/node_modules/vite/dist/node/chunks/dep-0fc8e132.js +63175 -0
  137. package/patches/node_modules/vite/dist/node/jsview-react.vite.config.js +7 -0
  138. package/patches/node_modules/vite/dist/node/jsview-vue.vite.config.js +7 -0
  139. package/patches/node_modules/vite/dist/node/jsview.vite.config.js +56 -0
  140. package/patches/node_modules/vue-router/dist/vue-router.mjs +3595 -0
  141. package/tools/common.js +58 -0
  142. package/tools/jsview-jsmap-serve.js +105 -0
  143. package/tools/jsview-post-build.js +184 -0
  144. package/tools/jsview-post-install-react.js +13 -0
  145. package/tools/jsview-post-install-vue.js +16 -0
  146. package/tools/jsview-post-install.js +116 -0
  147. package/tools/jsview-run-android.js +67 -0
  148. package/tsconfig.json +34 -0
@@ -0,0 +1,446 @@
1
+ /*
2
+ * JsView Added
3
+ */
4
+ 'use strict';
5
+
6
+ const StyleName = require("./jsview-style-types").StyleName;
7
+
8
+ class StyleConverter {
9
+ static ToInteger(value) {
10
+ if (!value) {
11
+ return value;
12
+ }
13
+ if (typeof value == "number") {
14
+ return Math.floor(value);
15
+ }
16
+
17
+ if (typeof value == "string") {
18
+ const number = parseInt(value);
19
+ if (number != value && value.endsWith('px') == false) {
20
+ throw Error("Bad unit in value " + value);
21
+ }
22
+ return number;
23
+ }
24
+
25
+ return value;
26
+ }
27
+
28
+ static ToFloat(value) {
29
+ if (!value) {
30
+ return value;
31
+ }
32
+ if (typeof value !== "string") {
33
+ return value;
34
+ }
35
+
36
+ let ret = parseFloat(value);
37
+ return ret;
38
+ }
39
+
40
+ // static ToConst(value, defaultValue) {
41
+ // if (typeof (value) == "symbol") {
42
+ // return value;
43
+ // }
44
+
45
+ // if (!value) {
46
+ // value = "";
47
+ // }
48
+
49
+ // if (value.includes('contain')) {
50
+ // return StyleValue.ObjectFit.CONTAIN;
51
+ // } else if (value.includes('cover')) {
52
+ // return StyleValue.ObjectFit.COVER;
53
+ // } else if (value.includes('fill')) {
54
+ // return StyleValue.ObjectFit.FILL;
55
+ // } else if (value.includes('none')) {
56
+ // return StyleValue.ObjectFit.NONE;
57
+ // } else if (value.includes('scale-down')) {
58
+ // return StyleValue.ObjectFit.SCALEDOWN;
59
+ // } else if (value.includes('hidden')) {
60
+ // return StyleValue.Overflow.HIDDEN;
61
+ // } else if (value.includes('visible')) {
62
+ // return StyleValue.Overflow.VISIBLE;
63
+ // }
64
+
65
+ // return defaultValue; // default value
66
+ // }
67
+
68
+ static ToString(value, upperCase) {
69
+ if (!value) {
70
+ return "";
71
+ }
72
+
73
+ if (upperCase) {
74
+ value = value.toUpperCase();
75
+ }
76
+
77
+ return value;
78
+ }
79
+
80
+
81
+ static ToRect(str) {
82
+ let arrays = StyleConverter.SplitString(str, ' ');
83
+
84
+ let rect = {
85
+ top: arrays.length > 0 ? parseInt(arrays[0]) : 0,
86
+ right: arrays.length > 1 ? parseInt(arrays[1]) : null,
87
+ bottom: arrays.length > 2 ? parseInt(arrays[2]) : null,
88
+ left: arrays.length > 3 ? parseInt(arrays[3]) : null,
89
+ };
90
+ rect.right = (!!rect.right || rect.right === 0 ? rect.right : rect.top);
91
+ rect.bottom = (!!rect.bottom || rect.bottom === 0 ? rect.bottom : rect.top);
92
+ rect.left = (!!rect.left || rect.left === 0 ? rect.left : rect.right);
93
+ return rect;
94
+ }
95
+
96
+ static ToCorner(str) {
97
+ let arrays = StyleConverter.SplitString(str, ' ');
98
+
99
+ let rect = {
100
+ topLeft: arrays.length > 0 ? parseInt(arrays[0]) : 0,
101
+ topRight: arrays.length > 1 ? parseInt(arrays[1]) : null,
102
+ bottomRight: arrays.length > 2 ? parseInt(arrays[2]) : null,
103
+ bottomLeft: arrays.length > 3 ? parseInt(arrays[3]) : null,
104
+ };
105
+ rect.topRight = (!!rect.topRight || rect.topRight === 0 ? rect.topRight : rect.topLeft);
106
+ rect.bottomRight = (!!rect.bottomRight || rect.bottomRight === 0 ? rect.bottomRight : rect.topLeft);
107
+ rect.bottomLeft = (!!rect.bottomLeft || rect.bottomLeft === 0 ? rect.bottomLeft : rect.bottomRight);
108
+ return rect;
109
+ }
110
+
111
+ static ToAnimation(str) {
112
+ if (str === null || str.length === 0) {
113
+ return null;
114
+ }
115
+
116
+ let bezierStart = str.indexOf('cubic-bezier');
117
+ let arrays = [];
118
+ if (bezierStart >= 0) { // 防止贝塞尔里面的空格被拆分
119
+ let bezierEnd = str.indexOf(')');
120
+ let bezierStr = str.substring(bezierStart, bezierEnd + 1);
121
+ let bezierArray = StyleConverter.SplitString(str, bezierStr);
122
+ for (let item of bezierArray) {
123
+ let subArrays = StyleConverter.SplitString(item, ' ');
124
+ arrays = arrays.concat(subArrays);
125
+ }
126
+ arrays.push(bezierStr);
127
+ } else {
128
+ arrays = StyleConverter.SplitString(str, ' ');
129
+ }
130
+
131
+ // 下面四个属性在animation字符串中是无序的,所以需要单独判断。
132
+ let timingFunction = null;
133
+ let delay = 0;
134
+ let iterationCount = 1;
135
+ let direction = str.includes("alternate");
136
+ for (let idx = 2; idx < arrays.length; idx++) { // 前两个选项固定是name和duration
137
+ if (arrays[idx] === "infinite") {
138
+ iterationCount = -1; // -1表示无限循环
139
+ continue;
140
+ }
141
+
142
+ let num = StyleConverter.ToTimeMs(arrays[idx]);
143
+ if (isNaN(num) === false) { // 表示时间
144
+ delay = num;
145
+ } else {
146
+ num = parseFloat(arrays[idx]);
147
+ if (isNaN(num) === false) { // 表示次数
148
+ iterationCount = num;
149
+ } else { // 不是数字,直接赋给timingFunction,省略判断
150
+ timingFunction = arrays[idx];
151
+ }
152
+ }
153
+ }
154
+
155
+ let duration = arrays.length > 1 ? StyleConverter.ToTimeMs(arrays[1]) : 0;
156
+ let anim = {
157
+ name: arrays.length > 0 ? arrays[0] : "",
158
+ duration: duration,
159
+ timingFunction: timingFunction,
160
+ delay: delay,
161
+ iterationCount: iterationCount,
162
+ direction: direction,
163
+ };
164
+ // console.log("StyleConverter.ConvertAnimation() anim=", anim);
165
+
166
+ return anim;
167
+ }
168
+
169
+ static ToTransition(str) {
170
+ if (str == null || str.length == 0) {
171
+ return null;
172
+ }
173
+ let transition = {};
174
+ let arrays = new Array();
175
+ let splitStr = str.split(',');
176
+ for (let idx = 0; idx < splitStr.length; idx++) {
177
+ if (splitStr[idx].indexOf('(') >= 0) { // 如果包含"(", 则将直到")"为止的内容当作一个部分
178
+ let endIdx = idx;
179
+ while (endIdx < splitStr.length && splitStr[endIdx].indexOf(')') < 0) { // 没有包含")"
180
+ endIdx++;
181
+ }
182
+ let concatStr = "";
183
+ for (let subIdx = idx; subIdx <= endIdx; subIdx++) {
184
+ if (subIdx != idx) {
185
+ concatStr += ",";
186
+ }
187
+ concatStr += splitStr[subIdx];
188
+ }
189
+ idx = endIdx;
190
+ arrays = arrays.concat(concatStr);
191
+ } else {
192
+ arrays = arrays.concat(splitStr[idx]);
193
+ }
194
+ }
195
+ // console.warn("StyleConverter.ConvertTransition() arrays=" + JSON.stringify(arrays));
196
+ for (let item of arrays) {
197
+ let ret = StyleConverter.ConvertAnimation(item);
198
+ transition[ret.name] = ret;
199
+ if (ret.name == "all") {
200
+ let allProps = new Array("opacity", "left", "top", "width", "height", "transform");
201
+ for (let prop of allProps) {
202
+ transition[prop] = ret;
203
+ }
204
+ }
205
+ }
206
+ return transition;
207
+ }
208
+
209
+ // static ConvertEasing(str, duration) {
210
+ // let easing = Forge.Easing.Circular.InOut;
211
+ // if (!str) {
212
+ // return easing;
213
+ // }
214
+
215
+ // if (str.includes('ease')) { // 加速用
216
+ // if (str.includes('-in-out')) {
217
+ // easing = Forge.Easing.Circular.InOut;
218
+ // } else if (str.includes('-out')) {
219
+ // easing = Forge.Easing.Circular.Out;
220
+ // } else if (str.includes('-in')) {
221
+ // easing = Forge.Easing.Circular.In;
222
+ // } else {
223
+ // easing = Forge.Easing.Circular.InOut;
224
+ // }
225
+ // } else if (str.includes('linear')) {
226
+ // easing = null; // null是匀速动画
227
+ // } else if (str.includes('cubic-bezier')) {
228
+ // let bezier = StyleConverter.ConvertBezier(str);
229
+ // easing = new Forge.BezierEasing(bezier.x1, bezier.y1, bezier.x2, bezier.y2, duration);
230
+ // } else if (str.includes("steps")) {
231
+ // let steps = StyleConverter.ConvertSteps(str);
232
+ // easing = new Forge.StepsEasing(steps.steps, steps.type);
233
+ // }
234
+
235
+ // // console.log("StyleConverter.ConvertEasing() easing=" + JSON.stringify(easing.Package()));
236
+ // return easing;
237
+ // }
238
+
239
+ static ConvertBezier(str) {
240
+ let startIdx = str.indexOf('(');
241
+ if (startIdx >= 0) {
242
+ str = str.substring(startIdx + 1);
243
+ }
244
+
245
+ let arrays = StyleConverter.SplitString(str, ',');
246
+
247
+ let bezier = {
248
+ x1: arrays.length > 0 ? parseFloat(arrays[0]) : 0,
249
+ y1: arrays.length > 1 ? parseFloat(arrays[1]) : 0,
250
+ x2: arrays.length > 2 ? parseFloat(arrays[2]) : 0,
251
+ y2: arrays.length > 3 ? parseFloat(arrays[3]) : 0,
252
+ };
253
+ return bezier;
254
+ }
255
+
256
+ static ConvertSteps(str) {
257
+ let startIdx = str.indexOf('(');
258
+ if (startIdx >= 0) {
259
+ str = str.substring(startIdx + 1);
260
+ }
261
+ let arrays = StyleConverter.SplitString(str, ',');
262
+ return {
263
+ steps: arrays.length > 0 ? parseInt(arrays[0]) : 1,
264
+ type: arrays.length > 1 ? (arrays[1].includes("start") ? 0 : 1) : 0,
265
+ }
266
+ }
267
+
268
+ static SplitString(from, sep) {
269
+ if (!from) {
270
+ from = "";
271
+ }
272
+ let arrays = from.trim().split(sep);
273
+ if (sep !== ' ') {
274
+ return arrays;
275
+ }
276
+
277
+ //去除多个空格的条件下的影响
278
+ let ret = [];
279
+ for (let item of arrays) {
280
+ if (!item) {
281
+ continue;
282
+ }
283
+
284
+ ret.push(item);
285
+ }
286
+
287
+ return ret;
288
+ }
289
+
290
+ static ToTimeMs(str) {
291
+ if (!str) {
292
+ str = "";
293
+ }
294
+ str = str.trim();
295
+
296
+ let timing = NaN;
297
+ if (str.endsWith('ms')) {
298
+ timing = 1;
299
+ } else if (str.endsWith('s')) {
300
+ timing = 1000;
301
+ }
302
+ timing *= parseFloat(str);
303
+
304
+ return timing;
305
+ }
306
+
307
+ static ToInset(value) {
308
+ if (!value
309
+ || value.startsWith('inset') === false) {
310
+ console.error("JsView Error: Failed to convert inset, InvalidArgs: value=", value);
311
+ return null;
312
+ }
313
+
314
+ let idx = value.indexOf('(') + 1;
315
+ let edgeValue = value.substring(idx);
316
+ let rect = StyleConverter.ToRect(edgeValue);
317
+
318
+ return rect
319
+ }
320
+ }
321
+
322
+ class StyleFormatter {
323
+ static GetFormattedValue(propName, propValue) {
324
+ let formattedValue = propValue;
325
+
326
+ switch (propName) {
327
+ case StyleName.Height:
328
+ case StyleName.Left:
329
+ case StyleName.Top:
330
+ case StyleName.Width:
331
+ formattedValue = StyleFormatter.#GetLayoutValue(propName, propValue);
332
+ break;
333
+ case StyleName.BackgroundColor:
334
+ case StyleName.BackgroundImage:
335
+ case StyleName.BorderRadius:
336
+ formattedValue = StyleFormatter.#GetBackgroundValue(propName, propValue);
337
+ break;
338
+ case StyleName.BackfaceVisibility:
339
+ case StyleName.BorderImage:
340
+ case StyleName.BorderImageWidth:
341
+ case StyleName.BorderImageOutset:
342
+ case StyleName.ClipPath:
343
+ case StyleName.Display:
344
+ case StyleName.ObjectFit:
345
+ case StyleName.Opacity:
346
+ case StyleName.Overflow:
347
+ case StyleName.Perspective:
348
+ case StyleName.PerspectiveOrigin:
349
+ case StyleName.Visibility:
350
+ case StyleName.ZIndex:
351
+ formattedValue = StyleFormatter.#GetEffectValue(propName, propValue);
352
+ break;
353
+ case StyleName.Color:
354
+ case StyleName.FontFamily:
355
+ case StyleName.FontSize:
356
+ case StyleName.FontStyle:
357
+ case StyleName.FontWeight:
358
+ case StyleName.LineHeight:
359
+ case StyleName.TextAlign:
360
+ case StyleName.TextShadow:
361
+ case StyleName.TextOverflow:
362
+ case StyleName.WebkitTextStroke:
363
+ case StyleName.WhiteSpace:
364
+ case StyleName.WordWrap:
365
+ formattedValue = StyleFormatter.#GetTextValue(propName, propValue);
366
+ break;
367
+ case StyleName.Animation:
368
+ case StyleName.Transform:
369
+ case StyleName.TransformOrigin:
370
+ case StyleName.TransformStyle:
371
+ case StyleName.Transition:
372
+ formattedValue = StyleFormatter.#GetMotionValue(propName, propValue);
373
+ break;
374
+ default:
375
+ // 返回未处理的值
376
+ console.warn("JsView Warn: Unimplemented style property " + propName);
377
+ break;
378
+ }
379
+
380
+ return formattedValue;
381
+ }
382
+
383
+ static #GetLayoutValue(propName, propValue) {
384
+ const formattedValue = StyleConverter.ToInteger(propValue);
385
+
386
+ return formattedValue;
387
+ }
388
+
389
+ static #GetBackgroundValue(propName, propValue) {
390
+ let formattedValue = null;
391
+ switch (propName) {
392
+ case StyleName.BorderRadius:
393
+ formattedValue = StyleConverter.ToCorner(propValue);
394
+ break;
395
+ default:
396
+ formattedValue = StyleConverter.ToString(propValue);
397
+ break;
398
+ }
399
+
400
+ return formattedValue;
401
+ }
402
+
403
+ static #GetEffectValue(propName, propValue) {
404
+ let formattedValue = null;
405
+ switch (propName) {
406
+ case StyleName.Display:
407
+ case StyleName.Overflow:
408
+ case StyleName.Visibility:
409
+ formattedValue = StyleConverter.ToString(propValue);
410
+ break;
411
+ case StyleName.ClipPath:
412
+ formattedValue = StyleConverter.ToInset(propValue);
413
+ break;
414
+ default:
415
+ formattedValue = StyleConverter.ToInteger(propValue);
416
+ break;
417
+ }
418
+
419
+ return formattedValue;
420
+ }
421
+
422
+ static #GetTextValue(propName, propValue) {
423
+ let formattedValue = null;
424
+ switch (propName) {
425
+ case StyleName.FontSize:
426
+ case StyleName.LineHeight:
427
+ formattedValue = StyleConverter.ToInteger(propValue);
428
+ break;
429
+ default:
430
+ formattedValue = StyleConverter.ToString(propValue);
431
+ break;
432
+ }
433
+
434
+ return formattedValue;
435
+ }
436
+
437
+ static #GetMotionValue(propName, propValue) {
438
+ // 需要留到执行时处理
439
+ const formattedValue = StyleConverter.ToString(propValue);
440
+
441
+ return formattedValue;
442
+ }
443
+
444
+ }
445
+
446
+ exports.getFormattedValue = StyleFormatter.GetFormattedValue;
@@ -0,0 +1,91 @@
1
+ /*
2
+ * JsView Added
3
+ */
4
+ 'use strict';
5
+
6
+ // export const StyleGroup = {
7
+ // Layout: 'layout',
8
+ // Background: 'background',
9
+ // Effect: 'effect',
10
+ // Text: 'text',
11
+ // Motion: 'motion',
12
+ // }
13
+
14
+ const StyleName = {
15
+ // Layout
16
+ Height: 'height',
17
+ Left: 'left',
18
+ Top: 'top',
19
+ Width: 'width',
20
+ // Bottom : 'bottom',
21
+ // Right : 'right',
22
+
23
+ // Background
24
+ BackgroundColor: 'backgroundColor',
25
+ BackgroundImage: 'backgroundImage',
26
+ BorderRadius: 'borderRadius',
27
+
28
+ // Effect
29
+ BackfaceVisibility: 'backfaceVisibility',
30
+ BorderImage: 'borderImage',
31
+ BorderImageWidth: 'borderImageWidth',
32
+ BorderImageOutset: 'borderImageOutset',
33
+ ClipPath: 'clipPath',
34
+ Color: 'color',
35
+ Display: 'display',
36
+ ObjectFit: 'objectFit',
37
+ Opacity: 'opacity',
38
+ Overflow: 'overflow',
39
+ Perspective: 'perspective',
40
+ PerspectiveOrigin: 'perspectiveOrigin',
41
+ Visibility: 'visibility',
42
+ ZIndex: 'zIndex',
43
+
44
+ // Text
45
+ FontFamily: 'fontFamily',
46
+ FontSize: 'fontSize',
47
+ FontStyle: 'fontStyle',
48
+ FontWeight: 'fontWeight',
49
+ LineHeight: 'lineHeight',
50
+ TextAlign: 'textAlign',
51
+ TextShadow: 'textShadow',
52
+ TextOverflow: 'textOverflow',
53
+ WebkitTextStroke: 'WebkitTextStroke',
54
+ WhiteSpace: 'whiteSpace',
55
+ WordWrap: 'wordWrap',
56
+ JsvTextEmoji: 'JsvTextEmoji',
57
+
58
+ // Motion
59
+ Animation: 'animation',
60
+ Transform: 'transform',
61
+ TransformOrigin: 'transformOrigin',
62
+ TransformStyle: 'transformStyle',
63
+ Transition: 'transition',
64
+ }
65
+
66
+
67
+ // export const StyleValue = {
68
+ // Overflow: {
69
+ // Hidden: 'hidden',
70
+ // Visible: 'visible',
71
+ // },
72
+
73
+ // ObjectFit: {
74
+ // Fill: Symbol('fill'),
75
+ // Contain: Symbol('contain'),
76
+ // Cover: Symbol('cover'),
77
+ // None: Symbol('none'),
78
+ // Scaledown: Symbol('scale-down'),
79
+ // },
80
+ // }
81
+
82
+ // export class StyleType {
83
+ // static IsVariable(value) {
84
+ // const isVar = ( typeof (value) === "string"
85
+ // && (value.startsWith('--') || value.startsWith('var(--')));
86
+
87
+ // return isVar;
88
+ // }
89
+ // }
90
+
91
+ exports.StyleName = StyleName;