@shijiu/jsview-vue 2.3.0 → 2.3.151-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/bin/browser/BrowserAudio.vue.mjs +4 -1
  2. package/bin/jsview-vue.mjs +2200 -466
  3. package/bin/types/utils/JsViewEngineWidget/JsvFocus/JsvFocusHub.d.ts +21 -1
  4. package/bin/types/utils/JsViewEngineWidget/MetroWidget/RenderItem.d.ts +5 -1
  5. package/bin/types/utils/JsViewEngineWidget/TemplateParser/CommonMetroTemplate.d.ts +2 -1
  6. package/bin/types/utils/JsViewEngineWidget/WidgetCommon.d.ts +10 -7
  7. package/bin/types/utils/JsViewVueTools/ForgeHandles.d.ts +1 -0
  8. package/bin/types/utils/JsViewVueTools/JsvRuntimeBridge.d.ts +37 -1
  9. package/bin/types/utils/JsViewVueTools/JsvTextureStore/CapturedTexture/CapturedTexture.d.ts +3 -3
  10. package/bin/types/utils/JsViewVueTools/JsvTextureStore/DominantColor/GetDominantColor.d.ts +7 -0
  11. package/bin/types/utils/JsViewVueTools/JsvTextureStore/JsvTextureStore.d.ts +14 -1
  12. package/bin/types/utils/JsViewVueTools/JsvTextureStore/Store.d.ts +2 -0
  13. package/bin/types/utils/JsViewVueTools/JsvTextureStore/Texture.d.ts +4 -0
  14. package/bin/types/utils/JsViewVueWidget/JsvDashPath.vue.d.ts +11 -0
  15. package/bin/types/utils/JsViewVueWidget/JsvFragShaderView/JsvFragShaderView.vue.d.ts +2 -1
  16. package/bin/types/utils/JsViewVueWidget/JsvSmoothSlideContainer.vue.d.ts +72 -0
  17. package/bin/types/utils/JsViewVueWidget/JsvSoundPool.d.ts +26 -0
  18. package/bin/types/utils/JsViewVueWidget/JsvSwiper/JsvSmoothSwiper.vue.d.ts +112 -0
  19. package/bin/types/utils/JsViewVueWidget/JsvSwiper/JsvSwiper2.vue.d.ts +142 -0
  20. package/bin/types/utils/JsViewVueWidget/JsvSwiper/index.d.ts +3 -1
  21. package/bin/types/utils/JsViewVueWidget/JsvTextureAnim/JsvTextureAnim.vue.d.ts +2 -2
  22. package/bin/types/utils/JsViewVueWidget/index.d.ts +2 -1
  23. package/package.json +1 -1
  24. package/utils/JsViewEngineWidget/JsvFocus/JsvFocusHub.ts +27 -1
  25. package/utils/JsViewEngineWidget/MetroWidget/MetroWidget.vue +35 -3
  26. package/utils/JsViewEngineWidget/MetroWidget/MetroWidgetSetup.js +736 -386
  27. package/utils/JsViewEngineWidget/MetroWidget/RenderItem.ts +13 -2
  28. package/utils/JsViewEngineWidget/MetroWidget/TaskManager.ts +38 -26
  29. package/utils/JsViewEngineWidget/TemplateParser/CommonMetroTemplate.ts +144 -73
  30. package/utils/JsViewEngineWidget/WidgetCommon.ts +12 -0
  31. package/utils/JsViewPlugin/JsvAudio/BrowserAudio/BrowserAudio.vue +4 -0
  32. package/utils/JsViewPlugin/JsvAudio/BrowserAudio/JsvSystemAudio.vue +13 -13
  33. package/utils/JsViewPlugin/JsvPlayer/BrowserJsvPlayer.vue +1 -1
  34. package/utils/JsViewVueTools/FeatureActive.ts +2 -1
  35. package/utils/JsViewVueTools/ForgeHandles.ts +5 -2
  36. package/utils/JsViewVueTools/JsvRuntimeBridge.js +97 -1
  37. package/utils/JsViewVueTools/JsvTextTools.ts +3 -1
  38. package/utils/JsViewVueTools/JsvTextureStore/CapturedTexture/CapturedTexture.ts +15 -12
  39. package/utils/JsViewVueTools/JsvTextureStore/DominantColor/GetDominantColor.ts +36 -0
  40. package/utils/JsViewVueTools/JsvTextureStore/JsvTextureStore.ts +23 -2
  41. package/utils/JsViewVueTools/JsvTextureStore/Store.ts +33 -21
  42. package/utils/JsViewVueTools/JsvTextureStore/Texture.ts +56 -41
  43. package/utils/JsViewVueWidget/JsvDashPath.vue +150 -0
  44. package/utils/JsViewVueWidget/JsvFlexCell/JsvFullScrAdjust.vue +3 -1
  45. package/utils/JsViewVueWidget/JsvFragShaderView/JsvFragShaderView.vue +26 -22
  46. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetAction.ts +1 -1
  47. package/utils/JsViewVueWidget/JsvInput/JsvInput.vue +1 -0
  48. package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +2 -2
  49. package/utils/JsViewVueWidget/JsvSmoothSlideContainer.vue +108 -0
  50. package/utils/JsViewVueWidget/JsvSoundPool.js +75 -12
  51. package/utils/JsViewVueWidget/JsvSwiper/JsvSmoothSwiper.vue +543 -0
  52. package/utils/JsViewVueWidget/JsvSwiper/JsvSwiper.vue +3 -3
  53. package/utils/JsViewVueWidget/JsvSwiper/JsvSwiper2.vue +644 -0
  54. package/utils/JsViewVueWidget/JsvSwiper/index.js +3 -1
  55. package/utils/JsViewVueWidget/JsvTextureAnim/JsvTextureAnim.vue +14 -8
  56. package/utils/JsViewVueWidget/index.js +2 -1
@@ -112,6 +112,31 @@ function openWindow(url, startup_image, startup_video, startup_duration, add_his
112
112
  return window.jJsvRuntimeBridge.openWindow(url, JSON.stringify(setting))
113
113
  }
114
114
 
115
+ /**
116
+ * 打开另外一个小程序
117
+ * @param {string} url 小程序url
118
+ * @param {string} startup_image 启动图url
119
+ * @param {string} startup_video 启动视频url
120
+ * @param {int} startup_duration 启动图时长,默认0
121
+ * @param {int} add_history 是否添加历史,0不添加,1添加
122
+ * @returns {Promise}
123
+ */
124
+ function openApp(url, startup_image, startup_video, startup_duration, add_history) {
125
+ let setting = {};
126
+ if (startup_image !== null && startup_image !== "")
127
+ setting.startupImage = startup_image;
128
+
129
+ if (startup_video !== null && startup_video !== "") {
130
+ setting.startupVideo = startup_video;
131
+ }
132
+
133
+ setting.startupDuration = startup_duration;
134
+ setting.addHistory = (add_history ? 1 : 0); // 兼容true/false传值
135
+
136
+ // direct_call("openWindow", url, JSON.stringify(setting));
137
+ return window.jJsvRuntimeBridge.openApp(url, JSON.stringify(setting))
138
+ }
139
+
115
140
  /**
116
141
  * 用新的进程打开另外一个小程序
117
142
  * @param {string} url 小程序url
@@ -136,6 +161,30 @@ function startUrlInNewTab(url, startup_image, startup_video, startup_duration, a
136
161
  return window.jJsvRuntimeBridge.startUrlInNewTab(url, JSON.stringify(setting))
137
162
  }
138
163
 
164
+ /**
165
+ * 用新的进程打开另外一个小程序
166
+ * @param {string} url 小程序url
167
+ * @param {string} startup_image 启动图url
168
+ * @param {string} startup_video 启动视频url
169
+ * @param {int} startup_duration 启动图时长,默认0
170
+ * @param {int} add_history 是否添加历史,0不添加,1添加
171
+ * @returns {Promise}
172
+ */
173
+ function openAppInNewTab(url, startup_image, startup_video, startup_duration, add_history) {
174
+ let setting = {};
175
+ if (startup_image !== null && startup_image !== "")
176
+ setting.startupImage = startup_image;
177
+
178
+ if (startup_video !== null && startup_video !== "") {
179
+ setting.startupVideo = startup_video;
180
+ }
181
+
182
+ setting.startupDuration = startup_duration;
183
+ setting.addHistory = (add_history ? 1 : 0); // 兼容true/false传值
184
+
185
+ return window.jJsvRuntimeBridge.openAppInNewTab(url, JSON.stringify(setting))
186
+ }
187
+
139
188
  /**
140
189
  * 用于给上一个小程序返回结果,通常与startUrlInNewTab和openWindow配合使用
141
190
  * @param {string} data 返回给上一个小程序的结果
@@ -202,9 +251,10 @@ function getInstalledApps() {
202
251
  * @param {string} uri Uri方式启动
203
252
  * @param {Array} flags 数组,用于intent.addFlags
204
253
  * @param {Array} param JSON格式数组,数组元素是 object ,object中的内容用于intent.putExtra
254
+ * @param {Array} category string数组,用于intent.addCategory
205
255
  *
206
256
  */
207
- function startNativeApp(package_name, activity, action, uri, flags, param) {
257
+ function startNativeApp(package_name, activity, action, uri, flags, param, category) {
208
258
  var obj = {};
209
259
  if (package_name !== null && package_name !== "")
210
260
  obj.packageName = package_name;
@@ -224,9 +274,52 @@ function startNativeApp(package_name, activity, action, uri, flags, param) {
224
274
  if (param !== null && param.length > 0)
225
275
  obj.param = param;
226
276
 
277
+ if (category!==null && category.length > 0)
278
+ obj.category = category
279
+
227
280
  direct_call("startNativeApp", JSON.stringify(obj));
228
281
  }
229
282
 
283
+ /**
284
+ * 启动安卓APP
285
+ * @param {string} package_name 包名
286
+ * @param {string} activity Activity方式启动
287
+ * @param {string} action Action方式启动
288
+ * @param {string} uri Uri方式启动
289
+ * @param {Array} flags 数组,用于intent.addFlags
290
+ * @param {Array} param JSON格式数组,数组元素是 object ,object中的内容用于intent.putExtra
291
+ * @param {Array} category string数组,用于intent.addCategory
292
+ *
293
+ */
294
+ function openNativeApp(package_name, activity, action, uri, flags, param, category) {
295
+ var obj = {};
296
+ if (package_name !== null && package_name !== "")
297
+ obj.packageName = package_name;
298
+
299
+ if (activity !== null && activity !== "")
300
+ obj.activity = activity;
301
+
302
+ if (action !== null && action !== "")
303
+ obj.action = action;
304
+
305
+ if (uri !== null && uri !== "")
306
+ obj.uri = uri;
307
+
308
+ if (flags !== null && flags.length > 0)
309
+ obj.flags = flags;
310
+
311
+ if (param !== null && param.length > 0)
312
+ obj.param = param;
313
+
314
+ if (category!==null && category.length > 0)
315
+ obj.category = category
316
+
317
+
318
+ // return window.jJsvRuntimeBridge.openNativeApp(JSON.stringify(obj));
319
+ return direct_call("openNativeApp", JSON.stringify(obj));
320
+ }
321
+
322
+
230
323
  /**
231
324
  * 发送安卓广播
232
325
  * @param {string} package_name 包名
@@ -617,7 +710,9 @@ const bridge = {
617
710
  getDeviceUUID,
618
711
  getAndroidId,
619
712
  openWindow,
713
+ openApp,
620
714
  startUrlInNewTab,
715
+ openAppInNewTab,
621
716
  onWindowResult,
622
717
  reloadWindow,
623
718
  closePage,
@@ -625,6 +720,7 @@ const bridge = {
625
720
  getSystemProperty,
626
721
  getInstalledApps,
627
722
  startNativeApp,
723
+ openNativeApp,
628
724
  sendNativeBroadcast,
629
725
  startService,
630
726
  getDeviceInfo,
@@ -24,7 +24,9 @@ declare interface FontStyleDefine {
24
24
  * @return {int} 文字宽度
25
25
  **/
26
26
  const getTextWidth = (text: string, style: FontStyleDefine) => {
27
- let forgeRef = Forge;
27
+ if (text && typeof text != "string") {
28
+ text = "" + text; // 规避text为非字符串导致接口调用错误的问题
29
+ }
28
30
  return Forge.TextUtils.GetTextWidth(text, style);
29
31
  };
30
32
 
@@ -6,18 +6,19 @@ export type CapturedCallback = (
6
6
  textureAccessName: string,
7
7
  autoRecycleSet: boolean,
8
8
  width: number,
9
- height: number) => void;
9
+ height: number,
10
+ isCannceled: boolean) => void;
10
11
 
11
12
  export class CapturedTexture extends TextureBase {
12
- private _AutoRecycle: boolean;
13
13
  private _Callback: CapturedCallback | null;
14
14
  private _CaptureDiv: any;
15
15
  private _Canceled: boolean = false;
16
-
16
+ private _PostProcessParams: any = null;
17
17
  constructor(
18
18
  captureDiv: any,
19
19
  callback: CapturedCallback,
20
- autoRecycle: boolean) {
20
+ autoRecycle: boolean,
21
+ postProcessParams: any = null) {
21
22
  super(null);
22
23
 
23
24
  // 激活引擎的功能支持
@@ -25,12 +26,14 @@ export class CapturedTexture extends TextureBase {
25
26
 
26
27
  this._CaptureDiv = captureDiv;
27
28
  this._Callback = callback;
28
- this._AutoRecycle = autoRecycle;
29
+ this.autoRecycle = autoRecycle;
30
+ this._PostProcessParams = postProcessParams;
29
31
  }
30
32
 
31
33
  // 清理对Callback和div的引用,防止泄露
32
34
  cancel() {
33
35
  if (!this._Canceled) {
36
+ this._Callback?.("", this.autoRecycle, 0, 0, true);
34
37
  this._Callback = null;
35
38
  this._CaptureDiv = null;
36
39
  this._Canceled = true;
@@ -47,18 +50,18 @@ export class CapturedTexture extends TextureBase {
47
50
  return;
48
51
  }
49
52
 
50
- // 处理自动回收
51
- if (!this._AutoRecycle) {
52
- this.addToStore(); // 用TextureStore来跟进引用状态
53
- }
53
+ //由于自动回收是三帧后回收, 所以需要先添加到store
54
+ this.addToStore();
54
55
 
55
56
  // 回调
56
57
  this._Callback?.(
57
58
  this.getStoreName(),
58
- this._AutoRecycle,
59
+ this.autoRecycle,
59
60
  resultObj.width as number,
60
- resultObj.height as number);
61
- }
61
+ resultObj.height as number,
62
+ false);
63
+ },
64
+ this._PostProcessParams
62
65
  );
63
66
  return '';
64
67
  }
@@ -0,0 +1,36 @@
1
+ import ForgeHandles from "../../../JsViewVueTools/ForgeHandles";
2
+ /**
3
+ * 使用ForgeTexture获取图片的dominant color, 注意, 此方法会hold住texture资源, 需要保证组件unmount时调用释放处理
4
+ * @param src 图片的src
5
+ * @param cbk 回调函数, 参数: info
6
+ * @returns 用于cancel的句柄,当cancel时,会清理对div和Callback的引用
7
+ */
8
+ export function getDominantColorByForgeTexture(
9
+ src: string,
10
+ cbk: (i: any) => void
11
+ ) {
12
+ if (!src) {
13
+ console.warn("getDominantColorByForgeTexture: src is empty");
14
+ return () => {};
15
+ }
16
+ const setting = { src };
17
+ let texture = (ForgeHandles.TextureManager as any).GetImageProcessTexture(
18
+ JSON.stringify(setting)
19
+ );
20
+ let canceled = false;
21
+ const callback = (info: any) => {
22
+ if (canceled) {
23
+ return;
24
+ }
25
+ cbk(info.extra);
26
+ texture?.RequestToUnload();
27
+ texture = null;
28
+ };
29
+ texture.DisableAutoRecycle();
30
+ texture.RegisterLoadImageCallback(src, callback, null);
31
+ return () => {
32
+ canceled = true;
33
+ texture?.RequestToUnload();
34
+ texture = null;
35
+ };
36
+ }
@@ -19,6 +19,7 @@
19
19
  import CanvasTexture from "./CanvasTexture/CanvasTexture";
20
20
  import { CapturedTexture, CapturedCallback } from "./CapturedTexture/CapturedTexture";
21
21
  import sStore from "./Store";
22
+ import { getDominantColorByForgeTexture } from "./DominantColor/GetDominantColor";
22
23
 
23
24
  let sJsvTextureConst = {
24
25
  LEFT: 1,
@@ -65,14 +66,16 @@ let sTextureStoreApi = {
65
66
  不需要主动调用deleteTexture释放.
66
67
  false: 此场景在callback收到资源名后, 需要使用完毕后调用 deleteTexture 手动释放
67
68
  在手动释放之前,可以赋给其他div/img来复用
69
+ * @param {any} postProcessParams 可选, 截图处理的参数
68
70
  * @return {CapturedTexture} 用于cancel的句柄,当cancel时,会清理对div和Callback的引用
69
71
  */
70
72
  capture2Texture: (
71
73
  captureDiv: any,
72
74
  callback: CapturedCallback,
73
- autoRecycle: boolean = true): CapturedTexture => {
75
+ autoRecycle: boolean = true,
76
+ postProcessParams: any = null): CapturedTexture => {
74
77
 
75
- let texture = new CapturedTexture(captureDiv, callback, autoRecycle);
78
+ let texture = new CapturedTexture(captureDiv, callback, autoRecycle, postProcessParams);
76
79
  texture.commit();
77
80
 
78
81
  return texture;
@@ -91,8 +94,26 @@ let sTextureStoreApi = {
91
94
  textureRef.recycle();
92
95
  }
93
96
  },
97
+
98
+ /**
99
+ * getDominantColor
100
+ * 获取图片的 dominant color
101
+ *
102
+ * @param src 图片的src
103
+ * @param callback 回调函数, 参数: info
104
+ * @return 用于cancel的句柄,当cancel时,会清理对div和Callback的引用
105
+ */
106
+ getDominantColor: (src: string, callback: (info: any) => void) => {
107
+ return getDominantColorByForgeTexture(src, (i: any) => {
108
+ callback(i);
109
+ });
110
+ }
94
111
  }
95
112
 
113
+ export enum CaptureProcessType {
114
+ Blur = 1,
115
+ }
116
+
96
117
  export {
97
118
  sTextureStoreApi as JsvTextureStoreApi,
98
119
  sJsvTextureConst as JsvTextureConst,
@@ -1,32 +1,44 @@
1
1
  import { TextureBase } from "./Texture";
2
+ import ForgeHandles from "../../JsViewVueTools/ForgeHandles";
2
3
 
3
4
  class JsvTextureStore {
4
- private textureMap: Map<String, TextureBase> = new Map();
5
+ private textureMap: Map<String, TextureBase> = new Map();
6
+ private hasAutoRecycle: boolean = false;
5
7
 
6
- constructor() {
8
+ constructor() { }
7
9
 
10
+ public addToStore(storeName: String, textureRef: TextureBase) {
11
+ if (!this.hasAutoRecycle && textureRef && textureRef.isAutoRecycle()) {
12
+ this.hasAutoRecycle = true;
13
+ ForgeHandles.sRenderBridge.AddWillSwapListener("jsv-texture-store", this.onWillSwap.bind(this));
8
14
  }
9
-
10
- public addToStore(storeName: String, textureRef: TextureBase) {
11
- this.textureMap.set(storeName, textureRef);
12
- }
13
-
14
- public getFromStore(storeName: String): TextureBase | undefined {
15
- return this.textureMap.get(storeName);
16
- }
17
-
18
- public removeFromStore(storeName: String): TextureBase | undefined {
19
- if (this.textureMap.has(storeName)) {
20
- let textureBaseRef = this.textureMap.get(storeName);
21
- this.textureMap.delete(storeName);
22
- return textureBaseRef;
23
- } else {
24
- console.error(`Error: name=${storeName} not in map`);
25
- return undefined;
26
- }
15
+ this.textureMap.set(storeName, textureRef);
16
+ }
17
+
18
+ public getFromStore(storeName: String): TextureBase | undefined {
19
+ return this.textureMap.get(storeName);
20
+ }
21
+
22
+ public removeFromStore(storeName: String): TextureBase | undefined {
23
+ if (this.textureMap.has(storeName)) {
24
+ let textureBaseRef = this.textureMap.get(storeName);
25
+ this.textureMap.delete(storeName);
26
+ return textureBaseRef;
27
+ } else {
28
+ console.error(`Error: name=${storeName} not in map`);
29
+ return undefined;
27
30
  }
31
+ }
32
+
33
+ private onWillSwap() {
34
+ this.textureMap.forEach((texture, key) => {
35
+ if (texture && texture.isAutoRecycle()) {
36
+ texture.tryRecycle();
37
+ }
38
+ });
39
+ }
28
40
  }
29
41
 
30
42
  let sStore: JsvTextureStore = new JsvTextureStore();
31
43
 
32
- export default sStore;
44
+ export default sStore;
@@ -1,53 +1,68 @@
1
1
  import sStore from "./Store";
2
2
 
3
+ const AUTO_RECYCLE_DELAY = 3;
3
4
  export class TextureBase {
4
- private baseName: String = 'T';
5
- protected textureRef: any = null; // Forge.ImageTexture
6
- public storeName: String = '';
7
-
8
- constructor(baseName: String | null) {
9
- if (baseName) {
10
- this.baseName = baseName;
11
- }
12
- }
5
+ private baseName: String = "T";
6
+ protected textureRef: any = null; // Forge.ImageTexture
7
+ public storeName: String = "";
8
+ protected autoRecycle: boolean = false;
9
+ private autoRecycleDelay: number = AUTO_RECYCLE_DELAY;
13
10
 
14
- protected addToStore() {
15
- this.storeName = this.getStoreName();
16
- this.textureRef.DisableAutoRecycle(); // 被store管理的,取消自动清理
17
- sStore.addToStore(this.storeName, this);
11
+ constructor(baseName: String | null) {
12
+ if (baseName) {
13
+ this.baseName = baseName;
18
14
  }
15
+ }
19
16
 
20
- protected getStoreName() {
21
- return `${this.baseName}-${this.textureRef?.GetTextureId()}`;
17
+ tryRecycle() {
18
+ if (!this.autoRecycle) return;
19
+ this.autoRecycleDelay--;
20
+ if (this.autoRecycleDelay < 0) {
21
+ this.recycle();
22
22
  }
23
+ }
23
24
 
24
- /**
25
- * commit
26
- * 完成绘制设置,出发制作目标texture
27
- *
28
- * @return {String} BaseName-textureId 格式的名字,用于 jsvtexturestore:// 的访问链接
29
- */
30
- public commit(): String {
31
- // Should override by extends to create Forge.ImageTexture -> textureRef
32
- return this.storeName;
33
- }
25
+ isAutoRecycle() {
26
+ return this.autoRecycle;
27
+ }
34
28
 
35
- /**
36
- * getTextureRef
37
- * 内部接口,获取内联的Forge.ImageTexture的句柄
38
- *
39
- * @return {String} BaseName-textureId 格式的名字,用于 jsvtexturestore:// 的访问链接
40
- */
41
- public getTextureRef(): any {
42
- return this.textureRef;
43
- }
29
+ protected addToStore() {
30
+ this.storeName = this.getStoreName();
31
+ this.textureRef.DisableAutoRecycle(); // 被store管理的,取消自动清理
32
+ sStore.addToStore(this.storeName, this);
33
+ }
34
+
35
+ protected getStoreName() {
36
+ return `${this.baseName}-${this.textureRef?.GetTextureId()}`;
37
+ }
38
+
39
+ /**
40
+ * commit
41
+ * 完成绘制设置,出发制作目标texture
42
+ *
43
+ * @return {String} BaseName-textureId 格式的名字,用于 jsvtexturestore:// 的访问链接
44
+ */
45
+ public commit(): String {
46
+ // Should override by extends to create Forge.ImageTexture -> textureRef
47
+ return this.storeName;
48
+ }
49
+
50
+ /**
51
+ * getTextureRef
52
+ * 内部接口,获取内联的Forge.ImageTexture的句柄
53
+ *
54
+ * @return {String} BaseName-textureId 格式的名字,用于 jsvtexturestore:// 的访问链接
55
+ */
56
+ public getTextureRef(): any {
57
+ return this.textureRef;
58
+ }
44
59
 
45
- public recycle() {
46
- // 释放native端的texture实体
47
- let textureRef = sStore.removeFromStore(this.storeName);
48
- if (textureRef) {
49
- // 释放native端的texture实体
50
- this.textureRef?.RequestToUnload();
51
- }
60
+ public recycle() {
61
+ // 释放native端的texture实体
62
+ let textureRef = sStore.removeFromStore(this.storeName);
63
+ if (textureRef) {
64
+ // 释放native端的texture实体
65
+ this.textureRef?.RequestToUnload();
52
66
  }
67
+ }
53
68
  }
@@ -0,0 +1,150 @@
1
+ <!--
2
+ * @file
3
+ *
4
+ * 【模块 export 内容】
5
+ * JsvDashPath:Vue组件,用于绘制虚线路径
6
+ * layout {Object}: (必填)组件位置,格式为 {left: number, top: number}
7
+ * points {Array}: (必填)点数组,每个点包含 x 和 y 坐标,坐标是相对于layout中指定的left和top
8
+ * 格式为 [{x: number, y: number}, ...]
9
+ * dash {Array}: 虚线配置数组,例如 [10, 5] 表示10px实线,5px空白,默认值 [10, 10]
10
+ * phase {Number}: 虚线起始位置偏移,默认值 0
11
+ * color {String}: 线条颜色,默认值 "#FFFFFF"
12
+ * lineWidth {Number}: 线条宽度,默认值 2
13
+ *
14
+ * 注意事项:
15
+ * 组件会根据传入的points自动计算所需画布大小
16
+ * 组件会在卸载时自动清理创建的纹理资源
17
+ -->
18
+
19
+ <template>
20
+ <div
21
+ :style="{
22
+ left: layout.left,
23
+ top: layout.top,
24
+ }"
25
+ >
26
+ <div
27
+ :style="{
28
+ left: canvasInfo.minX,
29
+ top: canvasInfo.minY,
30
+ width: canvasInfo.width,
31
+ height: canvasInfo.height,
32
+ backgroundImage: `url(jsvtexturestore://${sourceId})`,
33
+ }"
34
+ />
35
+ </div>
36
+ </template>
37
+
38
+ <script setup>
39
+ import { JsvTextureStoreApi } from "../JsViewVueTools";
40
+ import { onBeforeUnmount, computed } from "vue";
41
+
42
+ const props = defineProps({
43
+ // 组件位置 {left: number, top: number}
44
+ layout: {
45
+ type: Object,
46
+ required: true,
47
+ },
48
+ // 点数组,每个点包含 x 和 y 坐标, 坐标是相对与layout中指定的left和top
49
+ points: {
50
+ type: Array,
51
+ required: true,
52
+ validator: (value) => {
53
+ return value.every((point) => "x" in point && "y" in point);
54
+ },
55
+ },
56
+ // 虚线配置,例如 [10, 5] 表示10px实线,5px空白
57
+ dash: {
58
+ type: Array,
59
+ default: () => [10, 10],
60
+ },
61
+ // 虚线起始位置偏移
62
+ phase: {
63
+ type: Number,
64
+ default: 0,
65
+ },
66
+ // 线条颜色
67
+ color: {
68
+ type: String,
69
+ default: "#FFFFFF",
70
+ },
71
+ // 线条宽度
72
+ lineWidth: {
73
+ type: Number,
74
+ default: 2,
75
+ },
76
+ });
77
+
78
+ // 计算坐标系调整值和画布尺寸
79
+ const canvasInfo = computed(() => {
80
+ const xValues = props.points.map((p) => p.x);
81
+ const yValues = props.points.map((p) => p.y);
82
+
83
+ // 找出最小坐标值
84
+ const minX = Math.min(...xValues);
85
+ const minY = Math.min(...yValues);
86
+
87
+ // 计算偏移量(考虑线宽)
88
+ const lineOffset = Math.ceil(props.lineWidth / 2);
89
+
90
+ // 计算画布尺寸(考虑线宽)
91
+ const width = Math.max(...xValues) - minX + props.lineWidth * 2;
92
+ const height = Math.max(...yValues) - minY + props.lineWidth * 2;
93
+
94
+ return {
95
+ minX,
96
+ minY,
97
+ lineOffset,
98
+ width,
99
+ height,
100
+ };
101
+ });
102
+
103
+ // 创建画布纹理
104
+ let sourceId = "";
105
+ const canvasRef = JsvTextureStoreApi.canvasTexture(
106
+ canvasInfo.value.width,
107
+ canvasInfo.value.height
108
+ );
109
+
110
+ // 绘制透明背景
111
+ canvasRef.drawColor("rgba(0,0,0,0)");
112
+
113
+ // 创建自定义路径
114
+ const path = canvasRef.customPath();
115
+
116
+ // 移动到第一个调整后的点
117
+ if (props.points.length > 0) {
118
+ const firstPoint = props.points[0];
119
+ path.moveTo(
120
+ firstPoint.x - canvasInfo.value.minX + canvasInfo.value.lineOffset,
121
+ firstPoint.y - canvasInfo.value.minY + canvasInfo.value.lineOffset
122
+ );
123
+
124
+ // 连接后续的调整后的点
125
+ for (let i = 1; i < props.points.length; i++) {
126
+ const point = props.points[i];
127
+ path.lineTo(
128
+ point.x - canvasInfo.value.minX + canvasInfo.value.lineOffset,
129
+ point.y - canvasInfo.value.minY + canvasInfo.value.lineOffset
130
+ );
131
+ }
132
+ path.close();
133
+ }
134
+
135
+ // 使用虚线样式绘制路径
136
+ path.strokeWithSetting({
137
+ lineWidth: props.lineWidth,
138
+ color: props.color,
139
+ dash: props.dash,
140
+ phase: props.phase,
141
+ });
142
+
143
+ // 提交纹理并获取sourceId
144
+ sourceId = canvasRef.commit();
145
+
146
+ // 组件卸载时清理纹理
147
+ onBeforeUnmount(() => {
148
+ JsvTextureStoreApi.deleteTexture(sourceId);
149
+ });
150
+ </script>
@@ -145,7 +145,9 @@ defineExpose({
145
145
  transform: rScaleSet,
146
146
  }"
147
147
  >
148
- <slot />
148
+ <div data-jsv-vw-as-bound-anchor="true">
149
+ <slot />
150
+ </div>
149
151
  </div>
150
152
  </jsv-screen-flex>
151
153
  </template>