@shijiu/jsview-vue 2.1.25 → 2.1.200
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.
- package/package.json +1 -1
- package/utils/JsViewEngineWidget/JsvFocusBlock.vue +1 -1
- package/utils/JsViewEngineWidget/JsvFocusHub.ts +123 -0
- package/utils/JsViewEngineWidget/JsvFocusManager.js +4 -3
- package/utils/JsViewEngineWidget/MetroWidget/AnimationManager.ts +145 -51
- package/utils/JsViewEngineWidget/MetroWidget/ListWidget.vue +51 -64
- package/utils/JsViewEngineWidget/MetroWidget/MetroWidget.vue +62 -71
- package/utils/JsViewEngineWidget/MetroWidget/MetroWidgetSetup.js +308 -613
- package/utils/JsViewEngineWidget/TemplateParser/CommonMetroTemplate.ts +127 -247
- package/utils/JsViewEngineWidget/TemplateParser/ListMetroTemplate.ts +1 -0
- package/utils/JsViewEngineWidget/TemplateParser/MetroTemplate.ts +36 -2
- package/utils/JsViewEngineWidget/WidgetCommon.ts +25 -6
- package/utils/JsViewPlugin/JsvAudio/{JsvAudioBrowser.vue → BrowserAudio/BrowserAudio.vue} +1 -1
- package/utils/JsViewPlugin/JsvAudio/index.js +1 -1
- package/utils/JsViewPlugin/JsvLatex/BrowserDomBuilder.js +37 -0
- package/utils/JsViewPlugin/JsvLatex/Color.ts +43 -0
- package/utils/JsViewPlugin/JsvLatex/JsvLatex.vue +159 -0
- package/utils/JsViewPlugin/JsvLatex/JsvLatexBridgeProxy.js +16 -0
- package/utils/JsViewPlugin/JsvLatex/JsvLatexBrowser.vue +59 -0
- package/utils/JsViewPlugin/JsvLatex/PluginLoader.js +171 -0
- package/utils/JsViewPlugin/JsvLatex/index.js +28 -0
- package/utils/JsViewPlugin/JsvLatex/mathjax-tex-svg.txt +1 -0
- package/utils/JsViewPlugin/JsvLatex/version.js +24 -0
- package/utils/JsViewPlugin/JsvLatex/version.mjs +24 -0
- package/utils/JsViewPlugin/index.js +2 -1
- package/utils/JsViewVueTools/JsvDynamicCssStyle.js +2 -52
- package/utils/JsViewVueTools/JsvPerformance.ts +11 -0
- package/utils/JsViewVueTools/JsvPreDownloader.ts +55 -11
- package/utils/JsViewVueTools/JsvStyleSheetsDeclarer.js +40 -0
- package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/CanvasTexture.ts +143 -0
- package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/CommandList.ts +24 -0
- package/utils/JsViewVueTools/JsvTextureStore/CanvasTexture/Path.ts +198 -0
- package/utils/JsViewVueTools/JsvTextureStore/JsvTextureStore.ts +31 -0
- package/utils/JsViewVueTools/JsvTextureStore/Store.ts +32 -0
- package/utils/JsViewVueTools/JsvTextureStore/Texture.ts +38 -0
- package/utils/JsViewVueTools/index.js +3 -0
- package/utils/JsViewVueWidget/JsvEnableRenderBreak.vue +17 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/ActionRefObject.ts +6 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorControl.ts +144 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorState.ts +6 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/{CallbackManager.js → CallbackManager.ts} +19 -10
- package/utils/JsViewVueWidget/JsvFreeMoveActor/ForgeTypeDefine.ts +45 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/FreeMoveActor.vue +1 -1
- package/utils/JsViewVueWidget/JsvFreeMoveActor/JsvEnvBlocker.vue +124 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/KeepFlags.ts +6 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/SetAction.ts +553 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/SetCondition.ts +138 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/SetState.ts +53 -0
- package/utils/JsViewVueWidget/JsvFreeMoveActor/index.js +11 -1
- package/utils/JsViewVueWidget/JsvHole.js +1 -1
- package/utils/JsViewVueWidget/JsvLine/JsvLine.vue +101 -0
- package/utils/JsViewVueWidget/JsvLine/LineManager.js +62 -0
- package/utils/JsViewVueWidget/JsvLine/index.js +3 -0
- package/utils/JsViewVueWidget/JsvMarquee.vue +316 -139
- package/utils/JsViewVueWidget/JsvMindMap/CommonType.ts +1 -0
- package/utils/JsViewVueWidget/JsvMindMap/Constant.ts +20 -0
- package/utils/JsViewVueWidget/JsvMindMap/DataTree.ts +394 -0
- package/utils/JsViewVueWidget/JsvMindMap/Geometry.ts +277 -0
- package/utils/JsViewVueWidget/JsvMindMap/JsvMindMap.vue +653 -0
- package/utils/JsViewVueWidget/JsvMindMap/index.js +1 -0
- package/utils/JsViewVueWidget/JsvMindMap/rtree.js +628 -0
- package/utils/JsViewVueWidget/JsvNinePatch.vue +2 -2
- package/utils/JsViewVueWidget/JsvPieChart.vue +124 -0
- package/utils/JsViewVueWidget/JsvPosterImage.vue +32 -9
- package/utils/JsViewVueWidget/JsvPreload/BrowserPreload.vue +135 -133
- package/utils/JsViewVueWidget/JsvPreload/JsvPreload.vue +273 -270
- package/utils/JsViewVueWidget/JsvSector.vue +107 -0
- package/utils/JsViewVueWidget/JsvTextBox.vue +14 -1
- package/utils/JsViewVueWidget/JsvTextureAnim/JsvTextureAnim.vue +28 -2
- package/utils/JsViewVueWidget/JsvVisibleSensor/JsvVisibleSensor.vue +122 -93
- package/utils/JsViewVueWidget/index.js +15 -7
- package/utils/JsViewVueWidget/JsvFreeMoveActor/ActorControl.js +0 -112
- package/utils/JsViewVueWidget/JsvFreeMoveActor/CommonTools.js +0 -18
- package/utils/JsViewVueWidget/JsvFreeMoveActor/SetAction.js +0 -216
- package/utils/JsViewVueWidget/JsvFreeMoveActor/SetCondition.js +0 -66
- package/utils/JsViewVueWidget/JsvFreeMoveActor/SetState.js +0 -38
- package/utils/JsViewVueWidget/JsvFreeMoveActor/TypeDefine.js +0 -12
- package/utils/JsViewVueWidget/JsvTouchContainer.vue +0 -183
- package/utils/JsViewVueWidget/JsvTransparentDiv.vue +0 -87
- /package/utils/{JsViewVueWidget → JsViewPlugin/JsvAudio/BrowserAudio}/JsvSystemAudio.vue +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: ChenChanghua
|
|
3
|
+
* @Date: 2023-02-22 18:22:26
|
|
4
|
+
* @Description: file content
|
|
5
|
+
*/
|
|
6
|
+
let PluginInfo = {
|
|
7
|
+
// downloadUrl: "http://192.168.2.1:8097/pluginpackapp.zip", //插件下载地址
|
|
8
|
+
packageName: "com.qcode.jsvlatex",
|
|
9
|
+
name: "数学公式插件",
|
|
10
|
+
version: "1.0.4", //插件需要的版本号
|
|
11
|
+
versionCodeMin: 4,
|
|
12
|
+
versionCodeMax: 4,
|
|
13
|
+
bridgeName: "jsvLatexBridge", //插件bridge注册到jsview的名称
|
|
14
|
+
className: "com.qcode.jsvlatex.JsvLatex", //插件初始化类名称
|
|
15
|
+
initMethod: "createInstance", //插件初始化方法
|
|
16
|
+
listener: "top.JsvLatexPluginLoadResult", //插件加载结果回调
|
|
17
|
+
listener2: "top.JsvLatexPluginStatus",
|
|
18
|
+
// debug:true,
|
|
19
|
+
// md5: "f8a12f63d450df862abc6dbf273e258d"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 不要用export default,update-env脚本不能解析
|
|
23
|
+
// 导出字段要含有 pluginVersionInfo 信息,作为npm时版本参考
|
|
24
|
+
module.exports = PluginInfo;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: ChenChanghua
|
|
3
|
+
* @Date: 2023-02-22 18:22:26
|
|
4
|
+
* @Description: file content
|
|
5
|
+
*/
|
|
6
|
+
let PluginInfo = {
|
|
7
|
+
// downloadUrl: "http://192.168.2.1:8097/pluginpackapp.zip", //插件下载地址
|
|
8
|
+
packageName: "com.qcode.jsvlatex",
|
|
9
|
+
name: "数学公式插件",
|
|
10
|
+
version: "1.0.4", //插件需要的版本号
|
|
11
|
+
versionCodeMin: 4,
|
|
12
|
+
versionCodeMax: 4,
|
|
13
|
+
bridgeName: "jsvLatexBridge", //插件bridge注册到jsview的名称
|
|
14
|
+
className: "com.qcode.jsvlatex.JsvLatex", //插件初始化类名称
|
|
15
|
+
initMethod: "createInstance", //插件初始化方法
|
|
16
|
+
listener: "top.JsvLatexPluginLoadResult", //插件加载结果回调
|
|
17
|
+
listener2: "top.JsvLatexPluginStatus",
|
|
18
|
+
// debug:true,
|
|
19
|
+
// md5: "f8a12f63d450df862abc6dbf273e258d"
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 不要用export default,update-env脚本不能解析
|
|
23
|
+
// 导出字段要含有 pluginVersionInfo 信息,作为npm时版本参考
|
|
24
|
+
export default PluginInfo;
|
|
@@ -13,59 +13,9 @@
|
|
|
13
13
|
* getCssStyleSheet: 函数,获取 _StyleSheet 实例的函数,可接受一个参数anchor_tag,用来定位CSS rule的群组
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
class CssStyleSheet {
|
|
17
|
-
constructor(style_sheet_ref) {
|
|
18
|
-
this._SS = style_sheet_ref;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
insertRule(rule_define_string) {
|
|
22
|
-
const index = this._SS.cssRules.length;
|
|
23
|
-
this._SS.insertRule(rule_define_string, index);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
hasRule(name) {
|
|
27
|
-
const css_rules_ref = this._SS.cssRules;
|
|
28
|
-
for (let i = css_rules_ref.length - 1; i >= 0; i--) {
|
|
29
|
-
if (css_rules_ref[i].selectorText === name) {
|
|
30
|
-
// Found
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
removeRule(name) {
|
|
39
|
-
this.removeMultiRules([name]);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
removeMultiRules(names_array) {
|
|
43
|
-
const style_sheet_ref = this._SS;
|
|
44
|
-
const css_rules_ref = this._SS.cssRules;
|
|
45
|
-
// 对CssRules进行删除操作,倒序轮询
|
|
46
|
-
for (let i = css_rules_ref.length - 1; i >= 0; i--) {
|
|
47
|
-
for (const j in names_array) {
|
|
48
|
-
if (css_rules_ref[i].selectorText === names_array[j]) {
|
|
49
|
-
names_array.splice(j, 1);
|
|
50
|
-
style_sheet_ref.deleteRule(i);
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
16
|
function getCssStyleGroup() {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!ss || ss.length === 0) {
|
|
62
|
-
console.error("Error: styleSheet empty");
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const style_sheets_ref = ss[0]; // 使用第0个作为动态css rule的加入点
|
|
67
|
-
|
|
68
|
-
return new CssStyleSheet(style_sheets_ref);
|
|
17
|
+
console.error("Error: expired api, use JsvStyleSheetsDeclarer instead");
|
|
18
|
+
return null;
|
|
69
19
|
}
|
|
70
20
|
|
|
71
21
|
export {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class JsvPerformance {
|
|
2
|
+
private static posterSingleThreadDecode: boolean = false;
|
|
3
|
+
|
|
4
|
+
static setPosterSingleThreadDecode(v: boolean) {
|
|
5
|
+
JsvPerformance.posterSingleThreadDecode = v;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static getPosterSingleThreadDecode() {
|
|
9
|
+
return JsvPerformance.posterSingleThreadDecode;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* JsvPreDownloader 通用下载器,可以在不同的环境中进行资源下载操作。
|
|
3
|
+
* JsvPreDownloader.download:实例方法,根据传入参数来下载资源。支持单个url或者url列表,返回Promise对象。
|
|
4
|
+
* 参数:
|
|
5
|
+
* url {string | Array}: (必填)图片url
|
|
6
|
+
* netSetting {string}: 网络设置
|
|
7
|
+
* isImage {boolean} : 是否为图片
|
|
8
|
+
*
|
|
9
|
+
* JsvPreDownloader.buildDownloadItem: 实例方法,创建预下载信息项。
|
|
10
|
+
* 参数:
|
|
11
|
+
* url {string}: (必填)图片url
|
|
12
|
+
* netSetting {string}: 网络设置
|
|
13
|
+
* isImage {boolean} : 是否为图片
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
|
|
1
17
|
interface CallbackInfo {
|
|
2
18
|
status: number,
|
|
3
19
|
info: string,
|
|
@@ -8,27 +24,33 @@ interface DownloadListItem {
|
|
|
8
24
|
netSetting?: string,
|
|
9
25
|
isImage?: boolean,
|
|
10
26
|
}
|
|
11
|
-
|
|
27
|
+
interface infoObject{
|
|
28
|
+
errorCode: number
|
|
29
|
+
errorInfo: string
|
|
30
|
+
url: null
|
|
31
|
+
}
|
|
12
32
|
|
|
33
|
+
const TAG = "JSvPreDownload";
|
|
34
|
+
let isNullNumber: number = 0;
|
|
35
|
+
let workNumber: number = 0;
|
|
13
36
|
abstract class JsvPreDownloaderBase {
|
|
14
37
|
public download(url: string | Array<DownloadListItem>, netSetting: string = "", isImage: boolean = false) {
|
|
15
38
|
return new Promise((resolve, reject) => {
|
|
16
39
|
if (typeof url === "string") {
|
|
17
40
|
this.downloadInner(url, netSetting, isImage).then(resolve, reject);
|
|
18
41
|
} else if (Array.isArray(url) && url.length > 0) {
|
|
19
|
-
const downloadResult = new Array(url.length);
|
|
42
|
+
const downloadResult = new Array(url.length);
|
|
20
43
|
const check = () => {
|
|
21
|
-
let allDone =
|
|
22
|
-
let allSuccess = true;
|
|
44
|
+
let allDone = false;
|
|
45
|
+
let allSuccess = true;
|
|
23
46
|
for (let i of downloadResult) {
|
|
24
|
-
|
|
25
|
-
allDone = false;
|
|
26
|
-
break;
|
|
27
|
-
} else {
|
|
28
|
-
if (!i.succeed) {
|
|
47
|
+
if (!i?.succeed) {
|
|
29
48
|
allSuccess = false;
|
|
30
49
|
}
|
|
31
|
-
|
|
50
|
+
}
|
|
51
|
+
if(isNullNumber + workNumber == url.length ){
|
|
52
|
+
|
|
53
|
+
allDone = true;
|
|
32
54
|
}
|
|
33
55
|
if (allDone) {
|
|
34
56
|
if (allSuccess) {
|
|
@@ -39,13 +61,25 @@ abstract class JsvPreDownloaderBase {
|
|
|
39
61
|
}
|
|
40
62
|
}
|
|
41
63
|
for (let i = 0; i < url.length; ++i) {
|
|
42
|
-
|
|
64
|
+
if(url[i]==null || url[i].url == null ){
|
|
65
|
+
downloadResult[i]={
|
|
66
|
+
succeed:false,
|
|
67
|
+
info:{
|
|
68
|
+
errorCode: 100,
|
|
69
|
+
errorInfo: "This item is null or url is null",
|
|
70
|
+
url: null
|
|
71
|
+
} as infoObject
|
|
72
|
+
}
|
|
73
|
+
isNullNumber += 1
|
|
74
|
+
} else {
|
|
75
|
+
this.downloadInner(url[i].url, url[i].netSetting, !!url[i].isImage)
|
|
43
76
|
.then(
|
|
44
77
|
(info) => {
|
|
45
78
|
downloadResult[i] = {
|
|
46
79
|
succeed: true,
|
|
47
80
|
info: info,
|
|
48
81
|
};
|
|
82
|
+
workNumber += 1
|
|
49
83
|
check();
|
|
50
84
|
},
|
|
51
85
|
(errorInfo) => {
|
|
@@ -53,8 +87,10 @@ abstract class JsvPreDownloaderBase {
|
|
|
53
87
|
succeed: false,
|
|
54
88
|
info: errorInfo,
|
|
55
89
|
};
|
|
90
|
+
workNumber += 1
|
|
56
91
|
check();
|
|
57
92
|
})
|
|
93
|
+
}
|
|
58
94
|
}
|
|
59
95
|
} else {
|
|
60
96
|
console.error(TAG, "download url invalid", url);
|
|
@@ -63,6 +99,14 @@ abstract class JsvPreDownloaderBase {
|
|
|
63
99
|
});
|
|
64
100
|
}
|
|
65
101
|
|
|
102
|
+
public buildDownloadItem(url: string, netSetting: string = "", isImage: boolean = false) : DownloadListItem {
|
|
103
|
+
const item: DownloadListItem = {
|
|
104
|
+
url: url,
|
|
105
|
+
netSetting: netSetting,
|
|
106
|
+
isImage: isImage,
|
|
107
|
+
}
|
|
108
|
+
return item
|
|
109
|
+
}
|
|
66
110
|
protected abstract downloadInner(url: string, netSetting: string | undefined, isImage: boolean): Promise<Object>;
|
|
67
111
|
}
|
|
68
112
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* 【模块 export 内容】
|
|
4
|
+
* JsvStyleSheetsDeclarer: 动态和删除全局的 CssStyle
|
|
5
|
+
* 接口:
|
|
6
|
+
* DeclareClass(className:string, styleProperties:object) 新加全局Class
|
|
7
|
+
* className: 定义的class的名称, 为了规避全局重名,建议用'-'进行区域区分,例如主界面叫 main-xxxx, 详情页用 detail-xxxx
|
|
8
|
+
* styleProperties: 具体的style定义的对象,内部的名字采用驼峰规范
|
|
9
|
+
*
|
|
10
|
+
* UndeclareClass(className:string) 删除全局Class
|
|
11
|
+
* className: 通过 DeclareClass 声明的出来的动态className
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
class JsvStyleSheetsDeclarer {
|
|
15
|
+
static DeclareClass(className, styleProperties) {
|
|
16
|
+
const scopedStyleSheets = {
|
|
17
|
+
0: {}
|
|
18
|
+
};
|
|
19
|
+
if (className.startsWith('.') == false) {
|
|
20
|
+
className = '.' + className;
|
|
21
|
+
}
|
|
22
|
+
scopedStyleSheets[0][className] = JSON.stringify(styleProperties);
|
|
23
|
+
|
|
24
|
+
window.JsvCode.Dom.DeclareStyleSheets(scopedStyleSheets);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static UndeclareClass(className) {
|
|
28
|
+
const scopedStyleSheets = {
|
|
29
|
+
0: {}
|
|
30
|
+
};
|
|
31
|
+
if (className.startsWith('.') == false) {
|
|
32
|
+
className = '.' + className;
|
|
33
|
+
}
|
|
34
|
+
scopedStyleSheets[0][className] = '{}';
|
|
35
|
+
|
|
36
|
+
window.JsvCode.Dom.UndeclareStyleSheets(scopedStyleSheets);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { JsvStyleSheetsDeclarer }
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import ForgeHandles from "../../../JsViewVueTools/ForgeHandles";
|
|
2
|
+
import { TextureBase } from "../Texture"
|
|
3
|
+
import * as Constants from "./CommandList"
|
|
4
|
+
import { RectPath, CirclePath, CustomPath } from "./Path"
|
|
5
|
+
|
|
6
|
+
class CanvasTexture extends TextureBase {
|
|
7
|
+
private drawCommands: Array<Object> | null = [];
|
|
8
|
+
private commited: boolean = false; // commit只能执行一次, 执行过后无法再更改texture内容
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* canvasTexture
|
|
12
|
+
*
|
|
13
|
+
* @param {int} width 此Canvas画布的宽度
|
|
14
|
+
* @param {int} height 此Canvas画布的高度
|
|
15
|
+
* @param {String|null} baseName 可选, 访问名的前缀信息
|
|
16
|
+
*/
|
|
17
|
+
constructor(width: Number, height: Number, baseName: String | null) {
|
|
18
|
+
super(baseName);
|
|
19
|
+
|
|
20
|
+
this.drawCommands?.push({
|
|
21
|
+
"cmd": Constants.CMD_ALLOC_CANVAS,
|
|
22
|
+
"w": width,
|
|
23
|
+
"h": height
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* clearCanvas
|
|
29
|
+
* 清空canvas
|
|
30
|
+
*/
|
|
31
|
+
clearCanvas() {
|
|
32
|
+
this.drawCommands?.push({
|
|
33
|
+
"cmd": Constants.CMD_CLEAR_CANVAS,
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* drawColor
|
|
39
|
+
* 以给定颜色
|
|
40
|
+
*
|
|
41
|
+
* @param {String} color 颜色设定,例如rgba(red:0~255, green:0~255, blue:0~255, alpla:0~1.0), 或则 #AARRGGBB
|
|
42
|
+
*/
|
|
43
|
+
drawColor(color: String) {
|
|
44
|
+
this.drawCommands?.push({
|
|
45
|
+
"cmd": Constants.CMD_DRAW_COLOR,
|
|
46
|
+
"clr": color
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* customPath
|
|
52
|
+
* 获得Path操作对象,
|
|
53
|
+
* 在自定义绘制指令后,通过 stroke 或者 fill 来完成绘制
|
|
54
|
+
*
|
|
55
|
+
* @return {CustomPath}
|
|
56
|
+
*/
|
|
57
|
+
customPath(): CustomPath | null {
|
|
58
|
+
if (this.drawCommands) {
|
|
59
|
+
return new CustomPath(this.drawCommands);
|
|
60
|
+
} else {
|
|
61
|
+
console.error("already commited");
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* rectPath
|
|
68
|
+
* 获得RectPath操作对象,通过 stroke 或者 fill 来完成绘制
|
|
69
|
+
*
|
|
70
|
+
* @param {Number} left 矩形左上角left
|
|
71
|
+
* @param {Number} top 矩形左上角top
|
|
72
|
+
* @param {Number} right 矩形右下角right
|
|
73
|
+
* @param {Number} bottom 矩形右下角bottom
|
|
74
|
+
* @return {RectPath}
|
|
75
|
+
*/
|
|
76
|
+
rectPath(left: Number, top: Number, right: Number, bottom: Number): RectPath | null {
|
|
77
|
+
if (this.drawCommands) {
|
|
78
|
+
return new RectPath(this.drawCommands, left, top, right, bottom);
|
|
79
|
+
} else {
|
|
80
|
+
console.error("already commited");
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* CirclePath
|
|
87
|
+
* 获得CirclePath操作对象,通过 stroke 或者 fill 来完成绘制
|
|
88
|
+
*
|
|
89
|
+
* @param {Number} centerX 圆心x
|
|
90
|
+
* @param {Number} centerY 圆心y
|
|
91
|
+
* @param {Number} radius 圆半径
|
|
92
|
+
* @return {CirclePath}
|
|
93
|
+
*/
|
|
94
|
+
circlePath(centerX: Number, centerY: Number, radius: Number): CirclePath | null {
|
|
95
|
+
if (this.drawCommands) {
|
|
96
|
+
return new CirclePath(this.drawCommands, centerX, centerY, radius);
|
|
97
|
+
} else {
|
|
98
|
+
console.error("already commited");
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* drawLine
|
|
105
|
+
* 绘制一条带有抗锯齿信息的直线
|
|
106
|
+
*
|
|
107
|
+
* @param {Number} fromX 绘制起点X
|
|
108
|
+
* @param {Number} fromY 绘制起点Y
|
|
109
|
+
* @param {Number} toX 绘制终点X
|
|
110
|
+
* @param {Number} toX 绘制终点Y
|
|
111
|
+
* @param {Number} lineWidth 线宽
|
|
112
|
+
* @param {String} color 颜色设定,例如rgba(red:0~255, green:0~255, blue:0~255, alpla:0~1.0), 或则 #AARRGGBB
|
|
113
|
+
*/
|
|
114
|
+
drawLine(fromX: Number, fromY: Number, toX: Number, toY: Number, lineWidth: Number, color: String) {
|
|
115
|
+
this.drawCommands?.push({
|
|
116
|
+
"cmd": Constants.CMD_DRAW_LINE,
|
|
117
|
+
"x0": fromX,
|
|
118
|
+
"y0": fromY,
|
|
119
|
+
"x1": toX,
|
|
120
|
+
"y1": toY,
|
|
121
|
+
"lineWidth": lineWidth,
|
|
122
|
+
"clr": color
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// override
|
|
127
|
+
commit(): String {
|
|
128
|
+
if (!this.commited) {
|
|
129
|
+
// 使用当前的指令列表创建CanvasTexture
|
|
130
|
+
this.textureRef = (ForgeHandles.TextureManager as any).GetCanvasTexture(JSON.stringify(this.drawCommands));
|
|
131
|
+
this.addToStore();
|
|
132
|
+
this.commited = true;
|
|
133
|
+
|
|
134
|
+
// 清理缓存,节省内存
|
|
135
|
+
this.drawCommands = null;
|
|
136
|
+
} else {
|
|
137
|
+
console.error("Error: should not commit twice");
|
|
138
|
+
}
|
|
139
|
+
return super.commit();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export default CanvasTexture;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const CMD_INVALID = 0;
|
|
2
|
+
|
|
3
|
+
// Canvas初始化
|
|
4
|
+
export const CMD_ALLOC_CANVAS = 1;
|
|
5
|
+
|
|
6
|
+
// Paint初始化
|
|
7
|
+
export const CMD_PREPARE_PAINT = 2;
|
|
8
|
+
|
|
9
|
+
// Path初始化
|
|
10
|
+
export const CMD_PREPARE_PATH = 3;
|
|
11
|
+
|
|
12
|
+
// 绘制指令
|
|
13
|
+
export const CMD_CLEAR_CANVAS = 10;
|
|
14
|
+
export const CMD_DRAW_COLOR = 11;
|
|
15
|
+
export const CMD_DRAW_CIRCLE_WITH_PAINT = 12;
|
|
16
|
+
export const CMD_DRAW_RECT_WITH_PAINT = 13;
|
|
17
|
+
export const CMD_DRAW_PATH_WITH_PAINT = 14;
|
|
18
|
+
export const CMD_DRAW_LINE = 15;
|
|
19
|
+
|
|
20
|
+
// Path的子命令
|
|
21
|
+
export const PATH_CMD_MOVE_TO = 30;
|
|
22
|
+
export const PATH_CMD_LINE_TO = 31;
|
|
23
|
+
export const PATH_CMD_ARC_TO = 32;
|
|
24
|
+
export const PATH_CMD_CLOSE = 33;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import * as Constants from "./CommandList"
|
|
2
|
+
|
|
3
|
+
class DrawingPath {
|
|
4
|
+
protected drawCommandsRefs: Array<Object> = [];
|
|
5
|
+
protected finishedDraw: boolean = false; // 控制stroke和fill只能调用一次
|
|
6
|
+
|
|
7
|
+
constructor(drawCmds: Array<Object>) {
|
|
8
|
+
this.drawCommandsRefs = drawCmds;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* stroke
|
|
13
|
+
* 绘制边框
|
|
14
|
+
*
|
|
15
|
+
* @param {Number} lineWidth 描边的线宽
|
|
16
|
+
* @param {String} color 颜色设定,例如rgba(red:0~255, green:0~255, blue:0~255, alpla:0~1.0), 或则 #AARRGGBB
|
|
17
|
+
*/
|
|
18
|
+
public stroke(lineWidth: Number, color: String) {
|
|
19
|
+
if (this.finishedDraw) {
|
|
20
|
+
console.error("Error: path can only draw once");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.drawCommandsRefs.push({
|
|
25
|
+
"cmd": Constants.CMD_PREPARE_PAINT,
|
|
26
|
+
"type": "stroke",
|
|
27
|
+
"lineWidth": lineWidth,
|
|
28
|
+
"clr": color
|
|
29
|
+
});
|
|
30
|
+
this.onFinishDraw(); // 调用继承类的完成处理执行绘制
|
|
31
|
+
this.finishedDraw = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* fill
|
|
36
|
+
* 绘制填充
|
|
37
|
+
*
|
|
38
|
+
* @param {String} color 颜色设定,例如rgba(red:0~255, green:0~255, blue:0~255, alpla:0~1.0), 或则 #AARRGGBB
|
|
39
|
+
*/
|
|
40
|
+
public fill(color: String) {
|
|
41
|
+
if (this.finishedDraw) {
|
|
42
|
+
console.error("Error: path can only draw once");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.drawCommandsRefs.push({
|
|
47
|
+
"cmd": Constants.CMD_PREPARE_PAINT,
|
|
48
|
+
"type": "fill",
|
|
49
|
+
"clr": color
|
|
50
|
+
});
|
|
51
|
+
this.onFinishDraw(); // 调用继承类的完成处理执行绘制
|
|
52
|
+
this.finishedDraw = true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected onFinishDraw(): void {
|
|
56
|
+
// should override be extends class
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 绘制矩形
|
|
61
|
+
export class RectPath extends DrawingPath {
|
|
62
|
+
private rectLeft: Number;
|
|
63
|
+
private rectTop: Number;
|
|
64
|
+
private rectRight: Number;
|
|
65
|
+
private rectBottom: Number;
|
|
66
|
+
|
|
67
|
+
constructor(drawCmds: Array<Object>, left: Number, top: Number, right: Number, bottom: Number) {
|
|
68
|
+
super(drawCmds);
|
|
69
|
+
|
|
70
|
+
this.rectLeft = left;
|
|
71
|
+
this.rectTop = top;
|
|
72
|
+
this.rectRight = right;
|
|
73
|
+
this.rectBottom = bottom;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// override
|
|
77
|
+
public onFinishDraw(): void {
|
|
78
|
+
this.drawCommandsRefs.push({
|
|
79
|
+
"cmd": Constants.CMD_DRAW_RECT_WITH_PAINT,
|
|
80
|
+
"left": this.rectLeft,
|
|
81
|
+
"top": this.rectTop,
|
|
82
|
+
"right": this.rectRight,
|
|
83
|
+
"bottom": this.rectBottom
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 绘制圆形
|
|
89
|
+
export class CirclePath extends DrawingPath {
|
|
90
|
+
private circleCenterX: Number;
|
|
91
|
+
private circleCenterY: Number;
|
|
92
|
+
private circleRadius: Number;
|
|
93
|
+
|
|
94
|
+
constructor(drawCmds: Array<Object>, centerX: Number, centerY: Number, radius: Number) {
|
|
95
|
+
super(drawCmds);
|
|
96
|
+
|
|
97
|
+
this.circleCenterX = centerX;
|
|
98
|
+
this.circleCenterY = centerY;
|
|
99
|
+
this.circleRadius = radius;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// override
|
|
103
|
+
public onFinishDraw(): void {
|
|
104
|
+
this.drawCommandsRefs.push({
|
|
105
|
+
"cmd": Constants.CMD_DRAW_CIRCLE_WITH_PAINT,
|
|
106
|
+
"x": this.circleCenterX,
|
|
107
|
+
"y": this.circleCenterY,
|
|
108
|
+
"radius": this.circleRadius,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 自定义绘制,比如扇形
|
|
114
|
+
export class CustomPath extends DrawingPath {
|
|
115
|
+
protected pathCommands: Array<Object> | null = [];
|
|
116
|
+
|
|
117
|
+
constructor(drawCmds: Array<Object>) {
|
|
118
|
+
super(drawCmds);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* moveTo
|
|
123
|
+
* 将画笔移动到目标位置
|
|
124
|
+
*
|
|
125
|
+
* @param {Number} targetX 目标位置x
|
|
126
|
+
* @param {Number} targetY 目标位置y
|
|
127
|
+
*/
|
|
128
|
+
moveTo(targetX: Number, targetY: Number) {
|
|
129
|
+
this.pathCommands?.push({
|
|
130
|
+
"cmd": Constants.PATH_CMD_MOVE_TO,
|
|
131
|
+
"x": targetX,
|
|
132
|
+
"y": targetY
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* lineTo
|
|
138
|
+
* 将画笔从当前位置到目标位置之间绘制一条直线
|
|
139
|
+
*
|
|
140
|
+
* @param {Number} targetX 目标位置x
|
|
141
|
+
* @param {Number} targetY 目标位置y
|
|
142
|
+
*/
|
|
143
|
+
lineTo(targetX: Number, targetY: Number) {
|
|
144
|
+
this.pathCommands?.push({
|
|
145
|
+
"cmd": Constants.PATH_CMD_LINE_TO,
|
|
146
|
+
"x": targetX,
|
|
147
|
+
"y": targetY
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* arcTo
|
|
153
|
+
* 绘制以(left, top, right, bottom)围城的矩形为横轴比的椭圆圆弧
|
|
154
|
+
*
|
|
155
|
+
* @param {Number} left 定义椭圆区域的left
|
|
156
|
+
* @param {Number} top 定义椭圆区域的top
|
|
157
|
+
* @param {Number} right 定义椭圆区域的right
|
|
158
|
+
* @param {Number} bottom 定义椭圆区域的bottom
|
|
159
|
+
* @param {Number} startAngle 起始角度(例如30 = 30度)
|
|
160
|
+
* @param {Number} sweepAngle 扫过的角度(例如要绘制半圆,则设置180)
|
|
161
|
+
*/
|
|
162
|
+
arcTo(left: Number, top: Number, right: Number, bottom: Number,
|
|
163
|
+
startAngle: Number, sweepAngle: Number) {
|
|
164
|
+
this.pathCommands?.push({
|
|
165
|
+
"cmd": Constants.PATH_CMD_ARC_TO,
|
|
166
|
+
"left": left,
|
|
167
|
+
"top": top,
|
|
168
|
+
"right": right,
|
|
169
|
+
"bottom": bottom,
|
|
170
|
+
"startAngle": startAngle,
|
|
171
|
+
"sweepAngle": sweepAngle
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* close
|
|
177
|
+
* 到此为止的路径进行闭环
|
|
178
|
+
*/
|
|
179
|
+
close() {
|
|
180
|
+
this.pathCommands?.push({
|
|
181
|
+
"cmd": Constants.PATH_CMD_CLOSE,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// override
|
|
186
|
+
public onFinishDraw(): void {
|
|
187
|
+
if (this.pathCommands) {
|
|
188
|
+
this.drawCommandsRefs.push({
|
|
189
|
+
"cmd": Constants.CMD_PREPARE_PATH
|
|
190
|
+
})
|
|
191
|
+
this.drawCommandsRefs.push(...this.pathCommands);
|
|
192
|
+
this.drawCommandsRefs.push({
|
|
193
|
+
"cmd": Constants.CMD_DRAW_PATH_WITH_PAINT
|
|
194
|
+
});
|
|
195
|
+
this.pathCommands = null; // 节省内存,清理掉缓存
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import CanvasTexture from "./CanvasTexture/CanvasTexture";
|
|
2
|
+
import sStore from "./Store";
|
|
3
|
+
|
|
4
|
+
let sTextureStoreApi: Object = {
|
|
5
|
+
/**
|
|
6
|
+
* canvasTexture
|
|
7
|
+
* 创建CanvasTexture句柄,执行commit()后, 获取访问名(访问名规则: 输入参数 baseName + 分配id)
|
|
8
|
+
* 可以在 img.src 或者 div.backgroundImage 通过 "texturestore://访问名"
|
|
9
|
+
*
|
|
10
|
+
* @param {int} width 此Canvas画布的宽度
|
|
11
|
+
* @param {int} height 此Canvas画布的高度
|
|
12
|
+
* @param {String|null} baseName 可选, 访问名的前缀信息
|
|
13
|
+
* @return {CanvasTexture}
|
|
14
|
+
*/
|
|
15
|
+
canvasTexture: (width: Number, height: Number, baseName: String | null) => {
|
|
16
|
+
return new CanvasTexture(width, height, baseName);
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
deleteTexture: (storeName: String) => {
|
|
20
|
+
let textureRef = sStore.getFromStore(storeName);
|
|
21
|
+
if (textureRef) {
|
|
22
|
+
// 释放native端的texture实体
|
|
23
|
+
textureRef.recycle();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
sTextureStoreApi as JsvTextureStoreApi,
|
|
31
|
+
}
|