@shijiu/jsview-vue 2.1.200 → 2.1.339-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 (120) hide show
  1. package/bin/browser/BrowserApic.vue.mjs +124 -0
  2. package/bin/browser/BrowserApic2.vue.mjs +118 -0
  3. package/bin/browser/BrowserApicLib.mjs +424 -0
  4. package/bin/browser/BrowserAudio.vue.mjs +263 -0
  5. package/bin/browser/BrowserJsvLatex.vue.mjs +110 -0
  6. package/bin/browser/BrowserJsvPlayer.vue.mjs +573 -0
  7. package/bin/browser/BrowserPreload.vue.mjs +154 -0
  8. package/bin/browser/BrowserQrcode.vue.mjs +178 -0
  9. package/bin/browser/BrowserSpray.vue.mjs +66 -0
  10. package/bin/browser/BrowserTextureAnim.vue.mjs +324 -0
  11. package/bin/export-sfc.mjs +12 -0
  12. package/bin/jsview-common.mjs +39 -0
  13. package/bin/jsview-vue.mjs +21106 -0
  14. package/index.js +3 -4
  15. package/package.json +1 -2
  16. package/tools/config/rollup.config.mjs +52 -0
  17. package/tools/config/tsconfig.json +18 -0
  18. package/tools/config/vite.config.ts +60 -0
  19. package/tools/jsview-vue-build.mjs +125 -0
  20. package/utils/JsViewEngineWidget/{JsvFocusBlock.vue → JsvFocus/JsvFocusBlock.vue} +11 -11
  21. package/utils/JsViewEngineWidget/{JsvFocusHub.ts → JsvFocus/JsvFocusHub.ts} +9 -3
  22. package/utils/JsViewEngineWidget/{JsvFocusManager.js → JsvFocus/JsvFocusManager.js} +6 -5
  23. package/utils/JsViewEngineWidget/MetroWidget/AnimationManager.ts +33 -10
  24. package/utils/JsViewEngineWidget/MetroWidget/ListWidget.vue +89 -57
  25. package/utils/JsViewEngineWidget/MetroWidget/MetroWidget.vue +118 -62
  26. package/utils/JsViewEngineWidget/MetroWidget/MetroWidgetSetup.js +504 -60
  27. package/utils/JsViewEngineWidget/MetroWidget/RenderItem.ts +11 -1
  28. package/utils/JsViewEngineWidget/MetroWidget/SlotComponent.vue +13 -0
  29. package/utils/JsViewEngineWidget/TemplateParser/CommonMetroTemplate.ts +1 -1
  30. package/utils/JsViewEngineWidget/TemplateParser/ListMetroTemplate.ts +1 -1
  31. package/utils/JsViewEngineWidget/TemplateParser/MetroTemplate.ts +34 -1
  32. package/utils/JsViewEngineWidget/TemplateParser/TemplateItemAdder.ts +52 -11
  33. package/utils/JsViewEngineWidget/index.js +3 -3
  34. package/utils/JsViewPlugin/JsvAudio/AudioProxy.js +9 -0
  35. package/utils/JsViewPlugin/JsvAudio/BrowserAudio/BrowserAudio.vue +11 -3
  36. package/utils/JsViewPlugin/JsvAudio/JsvAudio.vue +1 -0
  37. package/utils/JsViewPlugin/JsvAudio/JsvAudioBridgeProxy.js +8 -0
  38. package/utils/JsViewPlugin/JsvAudio/ScreenLockManager.js +16 -0
  39. package/utils/JsViewPlugin/JsvAudio/version.js +3 -3
  40. package/utils/JsViewPlugin/JsvAudio/version.mjs +3 -3
  41. package/utils/JsViewPlugin/JsvLatex/index.js +1 -1
  42. package/utils/JsViewPlugin/JsvPlayer/JsvPlayer.vue +1 -1
  43. package/utils/JsViewPlugin/JsvPlayer/index-0.9.js +3 -3
  44. package/utils/JsViewPlugin/JsvPlayer/index.js +2 -2
  45. package/utils/JsViewVueTools/DebugTool.js +2 -2
  46. package/utils/JsViewVueTools/DefaultKeyMap.js +1 -1
  47. package/utils/JsViewVueTools/JsvDynamicCssStyle.js +1 -1
  48. package/utils/JsViewVueTools/JsvDynamicKeyFrames.js +2 -2
  49. package/utils/JsViewVueTools/JsvImpactTracer.js +7 -7
  50. package/utils/JsViewVueTools/JsvPreDownloader.ts +1 -1
  51. package/utils/JsViewVueTools/JsvRefTaker.js +2 -1
  52. package/utils/JsViewVueTools/JsvRuntimeBridge.js +29 -29
  53. package/utils/JsViewVueTools/JsvStyleClass.js +3 -3
  54. package/utils/JsViewVueTools/JsvStyleSheetsDeclarer.js +1 -1
  55. package/utils/JsViewVueTools/JsvTextTools.js +4 -4
  56. package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/CanvasTexture.ts +29 -1
  57. package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/CommandList.ts +6 -5
  58. package/utils/JsViewVueTools/JsvTextureStore/JsvTextureStore.ts +60 -2
  59. package/utils/JsViewVueTools/NinePatchHelper.js +1 -1
  60. package/utils/JsViewVueWidget/JsvActorMove/ActorControlBase.js +1 -1
  61. package/utils/JsViewVueWidget/JsvActorMove/JsvActorMoveControl.js +1 -1
  62. package/utils/JsViewVueWidget/JsvApic/{BrowserApic → JsvApic}/BrowserApic.vue +20 -23
  63. package/utils/JsViewVueWidget/JsvApic/{JsvApic.vue → JsvApic/JsvApic.vue} +3 -14
  64. package/utils/JsViewVueWidget/JsvApic/{index.js → JsvApic/index.js} +2 -4
  65. package/utils/JsViewVueWidget/JsvApic/JsvApic2/BrowserApic2.vue +116 -0
  66. package/utils/JsViewVueWidget/JsvApic/JsvApic2/JsvApic2.vue +137 -0
  67. package/utils/JsViewVueWidget/JsvApic/JsvApic2/index.js +17 -0
  68. package/utils/JsViewVueWidget/JsvApic/JsvBrowserApicLib/BrowserApicLib.js +4 -0
  69. package/utils/JsViewVueWidget/JsvApic/{BrowserApic → JsvBrowserApicLib}/NormalLoopTool.js +16 -18
  70. package/utils/JsViewVueWidget/JsvApic/JsvBrowserApicLib/PartLoopTool.js +90 -0
  71. package/utils/JsViewVueWidget/JsvApic/JsvBrowserApicLib/SingleLoopTool.js +17 -0
  72. package/utils/JsViewVueWidget/JsvApic/JsvBrowserApicLib/Viewer.js +111 -0
  73. package/utils/JsViewVueWidget/JsvApic/JsvCommonLoopToolBase.js +48 -0
  74. package/utils/JsViewVueWidget/JsvConnectLine/ArcLineManager.js +71 -0
  75. package/utils/JsViewVueWidget/JsvConnectLine/JsvConnectLine.vue +354 -0
  76. package/utils/JsViewVueWidget/JsvConnectLine/index.js +2 -0
  77. package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorControl.ts +37 -18
  78. package/utils/JsViewVueWidget/JsvFreeMoveActor/ForgeTypeDefine.ts +7 -3
  79. package/utils/JsViewVueWidget/JsvFreeMoveActor/FreeMoveActor.vue +28 -2
  80. package/utils/JsViewVueWidget/JsvFreeMoveActor/JsvEnvBlocker.vue +12 -5
  81. package/utils/JsViewVueWidget/JsvFreeMoveActor/NexusNode.ts +21 -0
  82. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetAction.ts +47 -59
  83. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetCondition.ts +129 -12
  84. package/utils/JsViewVueWidget/JsvFreeMoveActor/SetState.ts +45 -0
  85. package/utils/JsViewVueWidget/JsvFreeMoveActor/index.js +10 -2
  86. package/utils/JsViewVueWidget/JsvGrid.vue +1 -1
  87. package/utils/JsViewVueWidget/JsvHole.js +1 -1
  88. package/utils/JsViewVueWidget/JsvInput/JsvInput.vue +1 -1
  89. package/utils/JsViewVueWidget/JsvLine/JsvLine.vue +2 -2
  90. package/utils/JsViewVueWidget/JsvLine/LineManager.js +6 -4
  91. package/utils/JsViewVueWidget/JsvMarquee.vue +7 -4
  92. package/utils/JsViewVueWidget/JsvPieChart.vue +1 -1
  93. package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +1 -1
  94. package/utils/JsViewVueWidget/JsvPreload/index.js +1 -1
  95. package/utils/JsViewVueWidget/JsvProgressBar.vue +172 -0
  96. package/utils/JsViewVueWidget/JsvQrcode/JsvQrcode.vue +0 -1
  97. package/utils/JsViewVueWidget/JsvQrcode/index.js +1 -1
  98. package/utils/JsViewVueWidget/JsvRadarChart.vue +1 -1
  99. package/utils/JsViewVueWidget/JsvScaleTextBox.vue +0 -2
  100. package/utils/JsViewVueWidget/JsvSector.vue +1 -1
  101. package/utils/JsViewVueWidget/JsvSoundPool.js +1 -1
  102. package/utils/JsViewVueWidget/JsvSpray/index.js +1 -1
  103. package/utils/JsViewVueWidget/JsvSpriteAnim/FrameBuidler.ts +235 -0
  104. package/utils/JsViewVueWidget/JsvSpriteAnim/JsvSpriteAnim.vue +433 -401
  105. package/utils/JsViewVueWidget/JsvSpriteAnim/JsvSpriteLoader.vue +120 -0
  106. package/utils/JsViewVueWidget/JsvSpriteAnim/index.js +2 -2
  107. package/utils/JsViewVueWidget/JsvSwiper/JsvSwiper.vue +5 -5
  108. package/utils/JsViewVueWidget/JsvSwiper3D/JsvSwiper.vue +425 -422
  109. package/utils/JsViewVueWidget/JsvVisibleSensor/index.js +1 -1
  110. package/utils/JsViewVueWidget/index.js +7 -3
  111. package/utils/index.js +4 -0
  112. package/utils/JsViewVueWidget/JsvApic/BrowserApic/LoopToolBase.js +0 -25
  113. package/utils/JsViewVueWidget/JsvApic/BrowserApic/PartLoopTool.js +0 -119
  114. package/utils/JsViewVueWidget/JsvApic/BrowserApic/Viewer.js +0 -106
  115. /package/utils/JsViewPlugin/JsvLatex/{JsvLatexBrowser.vue → BrowserJsvLatex.vue} +0 -0
  116. /package/utils/JsViewPlugin/JsvPlayer/{JsvPlayerBrowser-0.9.vue → BrowserJsvPlayer-0.9.vue} +0 -0
  117. /package/utils/JsViewPlugin/JsvPlayer/{JsvPlayerBrowser.vue → BrowserJsvPlayer.vue} +0 -0
  118. /package/utils/JsViewVueWidget/JsvApic/{BrowserApic → JsvBrowserApicLib}/ApicDataBase.js +0 -0
  119. /package/utils/JsViewVueWidget/JsvApic/{BrowserApic → JsvBrowserApicLib}/GifData.js +0 -0
  120. /package/utils/JsViewVueWidget/JsvApic/{BrowserApic → JsvBrowserApicLib}/WebpData.js +0 -0
@@ -0,0 +1,116 @@
1
+ <!--
2
+ * @Author: ChenChanghua
3
+ * @Date: 2021-10-13 13:14:49
4
+ * @LastEditors: ChenChanghua
5
+ * @LastEditTime: 2021-10-13 17:13:24
6
+ * @Description: file content
7
+ -->
8
+ <script setup>
9
+ import {
10
+ Viewer,
11
+ WebpData,
12
+ GifData
13
+ } from "../JsvBrowserApicLib/BrowserApicLib";
14
+ import { LoopType } from "../JsvCommonLoopToolBase.js";
15
+ import { onMounted, shallowRef } from "vue";
16
+
17
+ let waitForPlayInfo = null;
18
+
19
+ const loadImage = (url) => {
20
+ return new Promise((resolve, reject) => {
21
+ let xhr = new XMLHttpRequest();
22
+ xhr.open("GET", url);
23
+ xhr.responseType = "arraybuffer";
24
+ xhr.onreadystatechange = () => {
25
+ if (xhr.readyState === 4 && xhr.status === 200) {
26
+ if (xhr.status == 200) {
27
+ let apic_data;
28
+ if (url.indexOf(".webp") > 0) {
29
+ apic_data = new WebpData(xhr.response);
30
+ resolve(apic_data);
31
+ } else if (url.indexOf(".gif") > 0) {
32
+ apic_data = new GifData(xhr.response);
33
+ resolve(apic_data);
34
+ } else {
35
+ reject("unsupport file " + url);
36
+ }
37
+ } else {
38
+ reject("get image data failed. " + url + " " + xhr.status);
39
+ }
40
+ }
41
+ };
42
+ xhr.send();
43
+ });
44
+ };
45
+
46
+ const getUrl = (base_url) => {
47
+ let url_trim = base_url.trim();
48
+ if (url_trim.indexOf("http") === 0) {
49
+ return url_trim;
50
+ } else if (url_trim.indexOf("url") === 0) {
51
+ let index_1 = url_trim.indexOf("(");
52
+ let index_2 = url_trim.indexOf(")");
53
+ return url_trim.substring(index_1 + 1, index_2);
54
+ } else {
55
+ return url_trim;
56
+ }
57
+ };
58
+
59
+ const props = defineProps({
60
+ src: String,
61
+ style: Object,
62
+ onStart: Function,
63
+ onEnd: Function,
64
+ onLoad: Function,
65
+ });
66
+
67
+ let viewer = null;
68
+ let canvasProxyRef = shallowRef(null);
69
+
70
+ onMounted(() => {
71
+ let domLayoutView = canvasProxyRef.value.jsvGetProxyView();
72
+ domLayoutView.RegisterOnProxyReady(() => {
73
+ // 制作canvas
74
+ let canvas = window.originDocument.createElement("canvas");
75
+ canvas.style.width = props.style.width + "px";
76
+ canvas.style.height = props.style.height + "px";
77
+ domLayoutView.HtmlGetElement().appendChild(canvas);
78
+
79
+ loadImage(getUrl(props.src))
80
+ .then((data) => {
81
+ let listener = {
82
+ onstart: props.onStart,
83
+ onend: props.onEnd,
84
+ };
85
+ viewer = new Viewer(data, canvas, listener);
86
+ if (props.onLoad) {
87
+ props.onLoad();
88
+ }
89
+ if (waitForPlayInfo) {
90
+ viewer.play(...waitForPlayInfo);
91
+ waitForPlayInfo = null;
92
+ }
93
+ })
94
+ .catch((err) => console.error(err));
95
+ });
96
+ });
97
+
98
+ defineExpose({
99
+ show: (frameIndex = 0) => {
100
+ if (!isNaN(frameIndex)) {
101
+ viewer?.play(LoopType.LOOP_SINGLE, [[0, frameIndex, 0]]);
102
+ }
103
+ },
104
+ play: (...args) => {
105
+ waitForPlayInfo = args;
106
+ viewer?.play(...args);
107
+ },
108
+ stop: () => {
109
+ viewer?.stop();
110
+ },
111
+ });
112
+ </script>
113
+
114
+ <template>
115
+ <div ref="canvasProxyRef" :style="props.style" />
116
+ </template>
@@ -0,0 +1,137 @@
1
+ <!--
2
+ * @Author: ChenChanghua
3
+ * @Date: 2021-10-13 13:14:42
4
+ * @LastEditors: ChenChanghua
5
+ * @LastEditTime: 2022-08-02 13:35:10
6
+ * @Description: file content
7
+ -->
8
+
9
+ <!--
10
+ * 【模块 export 内容】
11
+ * JsvApic:Vue高阶组件,控制动图播放
12
+ * prop说明:
13
+ * src {string} 对应img标签的src, 传url时需要注意使用url([链接])
14
+ * style {object} 对应img标签的style
15
+ * 通过ref=拿到句柄后,可调用的方法:
16
+ * stop(): 停止播放
17
+ * show(): 显示某一帧
18
+ * play(loopType, loopInfo, endState): 开始播放
19
+ * loopType:
20
+ * 循环类型: LoopType.LOOP_DEFAULT 按图片配置循环
21
+ * LoopType.LOOP_INFINITE 无限循环
22
+ * LoopType.LOOP_FINITE 有限次循环
23
+ * LoopType.LOOP_PART 循环播放部分
24
+ * loopInfo:
25
+ * 循环参数, 为数字时表示循环次数, 为数组时[[循环次数1,循环开始帧1,循环结束帧1], [循环次数2,循环开始帧2,循环结束帧2], ...]
26
+ * endState:
27
+ * 播放结束后的状态: ApicEndState.HIDE 隐藏
28
+ * ApicEndState.LAST_FRAME 保持最后一帧
29
+ -->
30
+ <script>
31
+ import ForgeHandles from "../../../JsViewVueTools/ForgeHandles";
32
+ import { LoopType } from "../JsvCommonLoopToolBase";
33
+
34
+ export default {
35
+ props: {
36
+ src: String,
37
+ style: Object,
38
+ onStart: Function,
39
+ onEnd: Function,
40
+ onLoad: Function,
41
+ },
42
+ setup() {
43
+ return {
44
+ element: {},
45
+ };
46
+ },
47
+ data() {
48
+ return {
49
+ onStartId: -1,
50
+ onEndId: -1,
51
+ };
52
+ },
53
+ methods: {
54
+ show(frameIndex = 0) {
55
+ if (!isNaN(frameIndex)) {
56
+ this.play(LoopType.LOOP_SINGLE, [[0, frameIndex, 0]]);
57
+ }
58
+ },
59
+ play(loopType, loopInfo, endState) {
60
+ let params = {
61
+ LT: loopType,
62
+ ES: endState,
63
+ };
64
+ if (loopInfo instanceof Array) {
65
+ //[[循环次数1,循环开始帧1,循环结束帧1], [循环次数2,循环开始帧2,循环结束帧2], ...]
66
+ params.LI = loopInfo;
67
+ } else if (!isNaN(loopInfo)) {
68
+ params.LI = [[loopInfo, 0, 0]];
69
+ } else {
70
+ params.LI = [[0, 0, 0]];
71
+ }
72
+ if (this.$refs.element) {
73
+ let mainViewTexture = this.$refs.element.jsvGetProxyTexture(
74
+ ForgeHandles.TextureManager
75
+ );
76
+
77
+ mainViewTexture.DispatchCommand(
78
+ Forge.NativeConstant.APIC_PLAY,
79
+ JSON.stringify(params)
80
+ );
81
+ mainViewTexture.unregisterOnStart(this.onStartId);
82
+ if (this.onStart) {
83
+ this.onStartId = mainViewTexture.registerOnStart(this.onStart);
84
+ }
85
+ mainViewTexture.unregisterOnEnd(this.onEndId);
86
+ if (this.onEnd) {
87
+ this.onEndId = mainViewTexture.registerOnEnd(this.onEnd);
88
+ }
89
+ }
90
+ },
91
+ stop() {
92
+ if (this.$refs.element) {
93
+ let mainViewTexture = this.$refs.element.jsvGetProxyTexture(
94
+ ForgeHandles.TextureManager
95
+ );
96
+ mainViewTexture.DispatchCommand(Forge.NativeConstant.APIC_STOP, "");
97
+ }
98
+ },
99
+ },
100
+ mounted() {
101
+ if (this.onLoad) {
102
+ if (this.$refs.element) {
103
+ let mainViewTexture = this.$refs.element.jsvGetProxyTexture(
104
+ ForgeHandles.TextureManager
105
+ );
106
+ mainViewTexture.RegisterLoadImageCallback(null, this.onLoad, null);
107
+ }
108
+ }
109
+ },
110
+ beforeUnmount() {
111
+ this.stop();
112
+ if (this.$refs.element) {
113
+ let mainViewTexture = this.$refs.element.jsvGetProxyTexture(
114
+ ForgeHandles.TextureManager
115
+ );
116
+
117
+ if (this.onStart) {
118
+ mainViewTexture.unregisterOnStart(this.onStartId);
119
+ }
120
+
121
+ if (this.onEnd) {
122
+ mainViewTexture.unregisterOnEnd(this.onEndId);
123
+ }
124
+ }
125
+ },
126
+ };
127
+ </script>
128
+
129
+ <template>
130
+ <img
131
+ data-jsv-disable-apic-autoplay
132
+ alt=""
133
+ ref="element"
134
+ :src="src"
135
+ :style="style"
136
+ />
137
+ </template>
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @Author: ChenChanghua
3
+ * @Date: 2021-10-13 15:12:45
4
+ * @LastEditors: ChenChanghua
5
+ * @LastEditTime: 2021-10-13 17:41:08
6
+ * @Description: file content
7
+ */
8
+ //! 考虑到.vue文件除了export default的component外,还有可能export其他对象,因此使用import * as
9
+ import * as JsvApic2 from "./JsvApic2.vue";
10
+ let _JsvApic2;
11
+ if (window.JsView) {
12
+ _JsvApic2 = JsvApic2.default;
13
+ } else {
14
+ const BrowserApic2 = await import("./BrowserApic2.vue");
15
+ _JsvApic2 = BrowserApic2.default;
16
+ }
17
+ export default _JsvApic2;
@@ -0,0 +1,4 @@
1
+
2
+ export {default as Viewer} from "./Viewer";
3
+ export {default as WebpData} from "./WebpData";
4
+ export {default as GifData} from "./GifData";
@@ -5,57 +5,55 @@
5
5
  * @LastEditTime: 2021-10-13 14:13:17
6
6
  * @Description: file content
7
7
  */
8
- import LoopToolBase, { LoopType } from "./LoopToolBase";
8
+ import { LoopToolBase, LoopType } from "../JsvCommonLoopToolBase";
9
9
 
10
- class NormalLoopTool extends LoopToolBase {
11
- constructor(loop_type, loop_num, frame_num) {
10
+ export class NormalLoopTool extends LoopToolBase {
11
+ constructor(loop_type, loop_num) {
12
12
  super();
13
13
  this.mLoopType = loop_type;
14
14
  this.mLoopNum = loop_num;
15
- this.mFrameNum = frame_num;
16
15
  this.mLoopCount = 0;
17
- this.mFrameIndex = 0;
18
16
  }
19
17
 
20
- getNextIndex() {
18
+ getNextIndex(curFrame) {
19
+ if (!this.mValid) { return -1; }
21
20
  let next_index = -1;
22
21
  switch (this.mLoopType) {
23
22
  case LoopType.LOOP_DEFAULT:
24
23
  if (this.mLoopNum <= 0) {
25
24
  //默认无限循环
26
- next_index = (this.mFrameIndex + 1) % this.mFrameNum;
25
+ next_index = (curFrame + 1) % this.mTotalFrameNum;
27
26
  } else {
28
- if (this.mFrameIndex == this.mFrameNum - 1) {
27
+ if (curFrame == this.mTotalFrameNum - 1) {
29
28
  this.mLoopCount++;
30
29
  }
31
30
  next_index =
32
31
  this.mLoopCount >= this.mLoopNum
33
32
  ? -1
34
- : (this.mFrameIndex + 1) % this.mFrameNum;
33
+ : (curFrame + 1) % this.mTotalFrameNum;
35
34
  }
36
35
  break;
37
36
  case LoopType.LOOP_INFINITE:
38
- next_index = (this.mFrameIndex + 1) % this.mFrameNum;
37
+ next_index = (curFrame + 1) % this.mTotalFrameNum;
39
38
  break;
40
39
  case LoopType.LOOP_FINITE:
41
- if (this.mFrameIndex == this.mFrameNum - 1) {
40
+ if (curFrame == this.mTotalFrameNum - 1) {
42
41
  this.mLoopCount++;
43
42
  }
44
43
  next_index =
45
44
  this.mLoopCount >= this.mLoopNum
46
45
  ? -1
47
- : (this.mFrameIndex + 1) % this.mFrameNum;
46
+ : (curFrame + 1) % this.mTotalFrameNum;
48
47
  break;
49
48
  default:
50
49
  }
51
- this.mFrameIndex = next_index;
52
50
  return next_index;
53
51
  }
54
52
 
55
- reset() {
56
- this.mFrameIndex = 0;
57
- this.mLoopCount = 0;
53
+ setApicInfo(frameNum, loopNum) {
54
+ this.mTotalFrameNum = frameNum;
55
+ this.mLoopNum = this.mLoopType == LoopType.LOOP_DEFAULT ? loopNum : this.mLoopNum;
56
+ this.mNextFrameIndex = 0;
57
+ this.mValid = true;
58
58
  }
59
59
  }
60
-
61
- export default NormalLoopTool;
@@ -0,0 +1,90 @@
1
+ /*
2
+ * @Author: ChenChanghua
3
+ * @Date: 2021-10-13 14:01:36
4
+ * @LastEditors: ChenChanghua
5
+ * @LastEditTime: 2021-10-13 16:17:46
6
+ * @Description: file content
7
+ */
8
+ import { LoopToolBase } from "../JsvCommonLoopToolBase";
9
+
10
+ export class PartLoopTool extends LoopToolBase {
11
+ constructor(info_list) {
12
+ super();
13
+ this.mLoopPeriod = 0;
14
+ this.mCurLoopStartFrame = 0;
15
+ this.mCurLoopEndFrame = 0;
16
+ this.mCurLoopNum = 0;
17
+ this.mCurLoopCount = 0;
18
+
19
+ if (info_list == null) {
20
+ console.error("PartLoopTool info is null.");
21
+ return;
22
+ }
23
+ this.mLoopInfo = info_list;
24
+ }
25
+
26
+ getNextIndex(curIndex) {
27
+ //只播放指定范围内的动画
28
+ if (!this.mValid) { return -1; }
29
+ let next_index = -1;
30
+ let loop_period_num = this.mLoopInfo.length;
31
+ if (this.mLoopPeriod < loop_period_num) {
32
+ if (curIndex < this.mCurLoopEndFrame) {
33
+ next_index = curIndex + 1;
34
+ } else {
35
+ if (this.mCurLoopNum <= 0) {
36
+ //无限循环
37
+ next_index = this.mCurLoopStartFrame;
38
+ } else {
39
+ this.mCurLoopCount++;
40
+ if (this.mCurLoopCount >= this.mCurLoopNum) {
41
+ //当前片段完成
42
+ this.mLoopPeriod++;
43
+ if (this.mLoopPeriod < loop_period_num) {
44
+ this.mValid = this.updateLoop();
45
+ if (this.mValid) {
46
+ this.mCurLoopCount = 0;
47
+ next_index = this.mCurLoopStartFrame;
48
+ }
49
+ } else {
50
+ //所有片段已完成
51
+ }
52
+ } else {
53
+ next_index = this.mCurLoopStartFrame;
54
+ }
55
+ }
56
+ }
57
+ } else {
58
+ //所有循环已完成
59
+ }
60
+ return next_index;
61
+ }
62
+
63
+ updateLoop() {
64
+ let loop = this.mLoopInfo[this.mLoopPeriod];
65
+ this.mCurLoopNum = loop[0];
66
+ this.mCurLoopStartFrame = loop[1];
67
+ this.mCurLoopEndFrame = loop[2];
68
+ if (
69
+ isNaN(this.mCurLoopNum) || isNaN(this.mCurLoopStartFrame) || isNaN(this.mCurLoopEndFrame)
70
+ || this.mCurLoopStartFrame >= this.mTotalFrameNum
71
+ || this.mCurLoopEndFrame >= this.mTotalFrameNum
72
+ || this.mCurLoopStartFrame >= this.mCurLoopEndFrame
73
+ ) {
74
+ console.error("data error, frame number out of size.", this.mLoopInfo);
75
+ return false;
76
+ } else {
77
+ return true;
78
+ }
79
+ }
80
+
81
+ setApicInfo(frameNum, loopNum) {
82
+ this.mTotalFrameNum = frameNum;
83
+ this.mValid = this.updateLoop();
84
+ if (!this.mValid) {
85
+ Log.e(TAG, "PartLoopTool init loop info error." + this.mLoopInfo.toString());
86
+ } else {
87
+ this.mNextFrameIndex = this.mCurLoopStartFrame;
88
+ }
89
+ }
90
+ }
@@ -0,0 +1,17 @@
1
+ import { LoopToolBase } from "../JsvCommonLoopToolBase"
2
+
3
+ export class SingleLoopTool extends LoopToolBase {
4
+ constructor(index) {
5
+ super();
6
+ this.mTargetIndex = index;
7
+ }
8
+
9
+ getNextIndex(curIndex) {
10
+ return -1;
11
+ }
12
+
13
+ setApicInfo(frame_num, loop_num) {
14
+ this.mTotalFrameNum = frame_num;
15
+ this.mNextFrameIndex = this.mTargetIndex;
16
+ }
17
+ }
@@ -0,0 +1,111 @@
1
+ /*
2
+ * @Author: ChenChanghua
3
+ * @Date: 2021-10-13 14:01:45
4
+ * @LastEditors: ChenChanghua
5
+ * @LastEditTime: 2021-10-13 17:09:17
6
+ * @Description: file content
7
+ */
8
+
9
+ import { LoopType, ApicEndState } from "../JsvCommonLoopToolBase";
10
+ import { PartLoopTool } from "./PartLoopTool";
11
+ import { NormalLoopTool } from "./NormalLoopTool";
12
+ import { SingleLoopTool } from "./SingleLoopTool";
13
+
14
+ class Viewer {
15
+ constructor(
16
+ apic_data,
17
+ canvas,
18
+ listener,
19
+ ) {
20
+ this._ApicData = apic_data;
21
+ this._Canvas = canvas;
22
+ this._Context = this._Canvas.getContext("2d");
23
+ this._Listener = listener;
24
+ this._TimeoutId = -1;
25
+ this._EndState = ApicEndState.LAST_FRAME;
26
+ // this.renderFrame(0);
27
+ }
28
+
29
+ _createLoopTool(loop_type, loop_info) {
30
+ let loop_num = null;
31
+ switch (loop_type) {
32
+ case LoopType.LOOP_DEFAULT:
33
+ case LoopType.LOOP_INFINITE:
34
+ case LoopType.LOOP_FINITE:
35
+ loop_num =
36
+ loop_type == LoopType.LOOP_DEFAULT
37
+ ? this._ApicData.LoopCount
38
+ : loop_info[0][0];
39
+ this._LoopTool = new NormalLoopTool(
40
+ loop_type,
41
+ loop_num,
42
+ );
43
+ break;
44
+ case LoopType.LOOP_PART:
45
+ this._LoopTool = new PartLoopTool(
46
+ loop_info,
47
+ this._ApicData.FrameCount
48
+ );
49
+ break;
50
+ case LoopType.LOOP_SINGLE:
51
+ this._LoopTool = new SingleLoopTool(loop_info[0][1]);
52
+ break;
53
+ default:
54
+ this._LoopTool = new NormalLoopTool(
55
+ LoopType.LOOP_DEFAULT,
56
+ -1,
57
+ );
58
+ }
59
+ this._LoopTool.setApicInfo(this._ApicData.FrameCount, this._ApicData.LoopCount);
60
+ }
61
+
62
+ stop() {
63
+ clearTimeout(this._TimeoutId);
64
+ if (this._Listener?.onend) {
65
+ this._Listener.onend();
66
+ }
67
+ }
68
+
69
+ play(loopType, loopInfo, endState = ApicEndState.LAST_FRAME) {
70
+ this._EndState = endState;
71
+ let lInfo;
72
+ if (loopInfo instanceof Array) {
73
+ //[[循环次数1,循环开始帧1,循环结束帧1], [循环次数2,循环开始帧2,循环结束帧2], ...]
74
+ lInfo = loopInfo;
75
+ } else if (!isNaN(loopInfo)) {
76
+ lInfo = [[loopInfo, 0, 0]];
77
+ } else {
78
+ lInfo = [[0, 0, 0]];
79
+ }
80
+
81
+ this._createLoopTool(loopType, lInfo)
82
+ clearTimeout(this._TimeoutId);
83
+ this.renderLoop();
84
+ if (this._Listener?.onstart) {
85
+ this._Listener.onstart();
86
+ }
87
+ }
88
+
89
+ renderLoop() {
90
+ if (this._LoopTool.hasNext()) {
91
+ let duration = this.renderFrame(this._LoopTool.next());
92
+ this._TimeoutId = setTimeout(() => {
93
+ this.renderLoop();
94
+ }, duration);
95
+ } else {
96
+ console.log("loop finished");
97
+ if (this._EndState == ApicEndState.HIDE) {
98
+ this._Context.clearRect(0, 0, this._Canvas.width, this._Canvas.height);
99
+ }
100
+ if (this._Listener?.onend) {
101
+ this._Listener.onend();
102
+ }
103
+ }
104
+ }
105
+
106
+ renderFrame(frame_index) {
107
+ return this._ApicData.toImage(frame_index, this._Canvas, this._Context);
108
+ }
109
+ }
110
+
111
+ export default Viewer;
@@ -0,0 +1,48 @@
1
+ /*
2
+ * @Author: ChenChanghua
3
+ * @Date: 2021-10-13 14:01:14
4
+ * @LastEditors: ChenChanghua
5
+ * @LastEditTime: 2021-10-13 15:20:48
6
+ * @Description: file content
7
+ */
8
+
9
+ export class LoopToolBase {
10
+ constructor() {
11
+ this.mFrameIndex = -1;
12
+ this.mTotalFrameNum = -1;
13
+ this.mNextFrameIndex = -1;
14
+ this.mValide = false;
15
+ }
16
+
17
+ getNextIndex(curIndex) {
18
+ return -1;
19
+ }
20
+
21
+ hasNext() {
22
+ return this.mNextFrameIndex != -1;
23
+ }
24
+
25
+ next() {
26
+ this.mFrameIndex = this.mNextFrameIndex;
27
+ this.mNextFrameIndex = this.getNextIndex(this.mFrameIndex);
28
+ return this.mFrameIndex;
29
+ }
30
+
31
+ setApicInfo(frameNum, loopNum) {
32
+ this.mTotalFrameNum = frameNum;
33
+ this.mLoopNum = loopNum;
34
+ }
35
+ }
36
+
37
+ export const LoopType = {
38
+ LOOP_DEFAULT: 0,
39
+ LOOP_INFINITE: 1,
40
+ LOOP_FINITE: 2,
41
+ LOOP_PART: 3,
42
+ LOOP_SINGLE: 4,
43
+ };
44
+
45
+ export const ApicEndState = {
46
+ HIDE: 1,
47
+ LAST_FRAME: 2,
48
+ }
@@ -0,0 +1,71 @@
1
+ import { JsvTextureStoreApi } from "../../JsViewVueTools/JsvTextureStore/JsvTextureStore";
2
+
3
+ let sMap = new Map();
4
+
5
+ const createTexture = (lineWidth, color, radius) => {
6
+ let myKey = `${lineWidth}${color}${radius}`;
7
+ if (sMap.size == 0) {
8
+ let t = new ConnectLineTexture(lineWidth, color, radius)
9
+ t.DoRef();
10
+ sMap.set(myKey, t)
11
+ return t
12
+ } else {
13
+ let hasMatch = false;
14
+ for (let key of sMap.keys()) {
15
+ if (key == myKey) {
16
+ hasMatch = true
17
+ sMap.get(key).DoRef()
18
+ return sMap.get(myKey)
19
+ }
20
+ }
21
+ if (!hasMatch) {
22
+ let t = new ConnectLineTexture(lineWidth, color, radius)
23
+ t.DoRef();
24
+ sMap.set(myKey, t)
25
+ return t
26
+ }
27
+ }
28
+
29
+ }
30
+
31
+ class ConnectLineTexture {
32
+ constructor(lineWidth, color, radius) {
33
+ this.key = `${lineWidth}${color}${radius}`
34
+ this.bitmap = {
35
+ width: radius + lineWidth / 2 + 2,
36
+ height: radius + lineWidth / 2 + 2
37
+ }
38
+ this.centerX = 0;
39
+ this.centerY = 0;
40
+ this.count = 0;
41
+ //画布
42
+ this.canvasTexture = JsvTextureStoreApi.canvasTexture(this.bitmap.width, this.bitmap.height)
43
+ //绘画四分之一圆
44
+ this.customPath = this.canvasTexture.customPath()
45
+ this.customPath.arcTo(
46
+ this.centerX - radius,
47
+ this.centerY - radius,
48
+ this.centerX + radius,
49
+ this.centerY + radius,
50
+ 0,
51
+ 90
52
+ )
53
+ this.customPath.stroke(lineWidth + 2, color)
54
+ //sourceId赋值
55
+ this.sourceId = this.canvasTexture.commit();
56
+ }
57
+ getSourceId() {
58
+ return this.sourceId
59
+ }
60
+ DoRef() {
61
+ this.count++;
62
+ }
63
+ UnRef() {
64
+ this.count--;
65
+ if (this.count === 0) {
66
+ JsvTextureStoreApi.deleteTexture(this.sourceId);
67
+ sMap.delete(this.key)
68
+ }
69
+ }
70
+ }
71
+ export { createTexture };