@shapediver/viewer.data-engine.html-element-anchor-engine 1.15.7 → 2.0.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.
- package/dist/HTMLElementAnchorEngine.d.ts +2 -2
- package/dist/HTMLElementAnchorEngine.d.ts.map +1 -1
- package/dist/HTMLElementAnchorEngine.js +9 -9
- package/dist/HTMLElementAnchorEngine.js.map +1 -1
- package/package.json +15 -12
- package/src/HTMLElementAnchorEngine.ts +123 -0
- package/src/index.ts +5 -0
- package/tsconfig.json +17 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ITreeNode } from '@shapediver/viewer.shared.node-tree';
|
|
2
2
|
import { ShapeDiverResponseOutputContent } from '@shapediver/sdk.geometry-api-sdk-v2';
|
|
3
3
|
export declare class HTMLElementAnchorEngine {
|
|
4
4
|
private readonly _converter;
|
|
@@ -10,6 +10,6 @@ export declare class HTMLElementAnchorEngine {
|
|
|
10
10
|
* @param content the material content
|
|
11
11
|
* @returns the scene graph node
|
|
12
12
|
*/
|
|
13
|
-
loadContent(content: ShapeDiverResponseOutputContent): Promise<
|
|
13
|
+
loadContent(content: ShapeDiverResponseOutputContent): Promise<ITreeNode>;
|
|
14
14
|
}
|
|
15
15
|
//# sourceMappingURL=HTMLElementAnchorEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLElementAnchorEngine.d.ts","sourceRoot":"","sources":["../src/HTMLElementAnchorEngine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"HTMLElementAnchorEngine.d.ts","sourceRoot":"","sources":["../src/HTMLElementAnchorEngine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAY,MAAM,qCAAqC,CAAA;AAIzE,OAAO,EAAE,+BAA+B,EAAE,MAAM,qCAAqC,CAAA;AAGrF,qBACa,uBAAuB;IAGhC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsD;IACjF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqE;IACrG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6C;IAMrE;;;;;OAKG;IACU,WAAW,CAAC,OAAO,EAAE,+BAA+B,GAAG,OAAO,CAAC,SAAS,CAAC;CA+FzF"}
|
|
@@ -46,7 +46,7 @@ let HTMLElementAnchorEngine = class HTMLElementAnchorEngine {
|
|
|
46
46
|
data.forEach((element) => {
|
|
47
47
|
// we need a location and a text, otherwise this doesn't make sense
|
|
48
48
|
if (!element.location || !element.text) {
|
|
49
|
-
this._logger.warn(viewer_shared_services_1.
|
|
49
|
+
this._logger.warn(viewer_shared_services_1.LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: One of the specified Tag2D elements did not have all necessary properties.');
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
const cleanedText = this._inputValidator.sanitize(element.text);
|
|
@@ -60,7 +60,7 @@ let HTMLElementAnchorEngine = class HTMLElementAnchorEngine {
|
|
|
60
60
|
const data = content.data;
|
|
61
61
|
data.forEach((element) => {
|
|
62
62
|
if (!element.location || !element.data) {
|
|
63
|
-
this._logger.warn(viewer_shared_services_1.
|
|
63
|
+
this._logger.warn(viewer_shared_services_1.LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: One of the specified Anchor elements did not have all necessary properties.');
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
let position;
|
|
@@ -80,7 +80,7 @@ let HTMLElementAnchorEngine = class HTMLElementAnchorEngine {
|
|
|
80
80
|
}
|
|
81
81
|
if (!element.format || (element.format === 'text')) {
|
|
82
82
|
if (!element.data.text) {
|
|
83
|
-
this._logger.warn(viewer_shared_services_1.
|
|
83
|
+
this._logger.warn(viewer_shared_services_1.LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: The text property for an Anchor element is missing.');
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
const textData = element.data;
|
|
@@ -95,13 +95,13 @@ let HTMLElementAnchorEngine = class HTMLElementAnchorEngine {
|
|
|
95
95
|
position
|
|
96
96
|
},
|
|
97
97
|
hideable: element.hideable,
|
|
98
|
-
|
|
98
|
+
viewports: element.viewports,
|
|
99
99
|
intersectionTarget
|
|
100
100
|
}));
|
|
101
101
|
}
|
|
102
102
|
else if (element.format === 'image') {
|
|
103
103
|
if (!element.data.src || !element.data.width || !element.data.height || !element.data.alt) {
|
|
104
|
-
this._logger.warn(viewer_shared_services_1.
|
|
104
|
+
this._logger.warn(viewer_shared_services_1.LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: One of the specified Anchor elements did not have all necessary properties.');
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
const imageData = element.data;
|
|
@@ -116,24 +116,24 @@ let HTMLElementAnchorEngine = class HTMLElementAnchorEngine {
|
|
|
116
116
|
position
|
|
117
117
|
},
|
|
118
118
|
hideable: element.hideable,
|
|
119
|
-
|
|
119
|
+
viewports: element.viewports,
|
|
120
120
|
intersectionTarget
|
|
121
121
|
}));
|
|
122
122
|
}
|
|
123
|
-
this._logger.warn(viewer_shared_services_1.
|
|
123
|
+
this._logger.warn(viewer_shared_services_1.LOGGING_TOPIC.DATA_PROCESSING, `HTMLElementAnchorEngine.load: The Anchor does not have a recognized format: ${element.format}`);
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
return node;
|
|
127
127
|
}
|
|
128
128
|
catch (e) {
|
|
129
129
|
const error = new viewer_shared_services_1.ShapeDiverViewerDataProcessingError('HTMLElementAnchorEngine.load: Loading of anchors failed.');
|
|
130
|
-
throw this._logger.handleError(viewer_shared_services_1.
|
|
130
|
+
throw this._logger.handleError(viewer_shared_services_1.LOGGING_TOPIC.DATA_PROCESSING, `HTMLElementAnchorEngine.load`, error);
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
HTMLElementAnchorEngine = __decorate([
|
|
136
|
-
tsyringe_1.singleton()
|
|
136
|
+
(0, tsyringe_1.singleton)()
|
|
137
137
|
], HTMLElementAnchorEngine);
|
|
138
138
|
exports.HTMLElementAnchorEngine = HTMLElementAnchorEngine;
|
|
139
139
|
//# sourceMappingURL=HTMLElementAnchorEngine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLElementAnchorEngine.js","sourceRoot":"","sources":["../src/HTMLElementAnchorEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"HTMLElementAnchorEngine.js","sourceRoot":"","sources":["../src/HTMLElementAnchorEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,uCAA+C;AAC/C,yEAAiK;AACjK,iFAAyE;AACzE,+EAA0I;AAE1I,uEAAoD;AAKpD,IAAa,uBAAuB,GAApC,MAAa,uBAAuB;IAApC;QACI,yBAAyB;QAER,eAAU,GAAyB,oBAAS,CAAC,OAAO,CAAC,kCAAS,CAAC,CAAC;QAChE,oBAAe,GAAmC,oBAAS,CAAC,OAAO,CAAC,uCAAc,CAAC,CAAC;QACpF,YAAO,GAAmB,oBAAS,CAAC,OAAO,CAAC,+BAAM,CAAC,CAAC;QA0GrE,gCAAgC;IACpC,CAAC;IAzGG,4BAA4B;IAE5B,6BAA6B;IAE7B;;;;;OAKG;IACU,WAAW,CAAC,OAAwC;;YAC7D,IAAI;gBACA,MAAM,IAAI,GAAG,IAAI,kCAAQ,CAAC,oBAAoB,CAAC,CAAC;gBAChD,IAAI,OAAO,CAAC,MAAM,KAAK,OAAO,EAAE;oBAC5B,MAAM,IAAI,GAAa,OAAO,CAAC,IAAI,CAAC;oBACpC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAe,EAAE,EAAE;wBAC7B,mEAAmE;wBACnE,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,CAAC,OAAO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CAAC,OAAO,CAAC,IAAI,CAAC,sCAAa,CAAC,eAAe,EAAE,+EAA+E,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;oBACtJ,CAAC,CAAC,CAAC;iBACN;gBACD,OAAO,IAAI,CAAC;aACf;YAAC,OAAO,CAAC,EAAE;gBACR,MAAM,KAAK,GAAG,IAAI,4DAAmC,CAAC,0DAA0D,CAAC,CAAC;gBAClH,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,sCAAa,CAAC,eAAe,EAAE,8BAA8B,EAAE,KAAK,CAAC,CAAC;aACxG;QACL,CAAC;KAAA;CAGJ,CAAA;AAhHY,uBAAuB;IADnC,IAAA,oBAAS,GAAE;GACC,uBAAuB,CAgHnC;AAhHY,0DAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.data-engine.html-element-anchor-engine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
"test": "__tests__"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"dist"
|
|
13
|
+
"dist",
|
|
14
|
+
"src",
|
|
15
|
+
"package.json",
|
|
16
|
+
"README.md",
|
|
17
|
+
"tsconfig.json"
|
|
14
18
|
],
|
|
15
19
|
"publishConfig": {
|
|
16
20
|
"access": "public"
|
|
@@ -20,11 +24,10 @@
|
|
|
20
24
|
"url": "git+https://github.com/shapediver/Viewer.git"
|
|
21
25
|
},
|
|
22
26
|
"scripts": {
|
|
23
|
-
"test": "bash ../../scripts/test.sh",
|
|
24
27
|
"check": "tsc --noEmit",
|
|
25
|
-
"build": "bash ../../scripts/build.sh",
|
|
26
|
-
"build-watch": "bash ../../scripts/build-watch.sh",
|
|
27
|
-
"build-dep": "bash ../../scripts/build-dep.sh"
|
|
28
|
+
"build": "bash ../../scripts/building/build.sh",
|
|
29
|
+
"build-watch": "bash ../../scripts/building/build-watch.sh",
|
|
30
|
+
"build-dep": "bash ../../scripts/building/build-dep.sh"
|
|
28
31
|
},
|
|
29
32
|
"bugs": {
|
|
30
33
|
"url": "https://github.com/shapediver/Viewer/issues"
|
|
@@ -37,14 +40,14 @@
|
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|
|
39
42
|
"@shapediver/sdk.geometry-api-sdk-v2": "^1.0.24",
|
|
40
|
-
"@shapediver/viewer.data-engine.shared-types": "
|
|
41
|
-
"@shapediver/viewer.shared.math": "
|
|
42
|
-
"@shapediver/viewer.shared.node-tree": "
|
|
43
|
-
"@shapediver/viewer.shared.services": "
|
|
44
|
-
"@shapediver/viewer.shared.types": "
|
|
43
|
+
"@shapediver/viewer.data-engine.shared-types": "2.0.0",
|
|
44
|
+
"@shapediver/viewer.shared.math": "2.0.0",
|
|
45
|
+
"@shapediver/viewer.shared.node-tree": "2.0.0",
|
|
46
|
+
"@shapediver/viewer.shared.services": "2.0.0",
|
|
47
|
+
"@shapediver/viewer.shared.types": "2.0.0",
|
|
45
48
|
"axios": "^0.21.1",
|
|
46
49
|
"gl-matrix": "3.3.0",
|
|
47
50
|
"tsyringe": "^4.5.0"
|
|
48
51
|
},
|
|
49
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "bb53f1f23dcf3b1d76e786bdc8eb20e485c029f2"
|
|
50
53
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { container, singleton } from 'tsyringe'
|
|
2
|
+
import { HTMLElementAnchorData, HTMLElementAnchorTextData, HTMLElementAnchorImageData, IAnchorDataText, IAnchorDataImage } from '@shapediver/viewer.shared.types'
|
|
3
|
+
import { ITreeNode, TreeNode } from '@shapediver/viewer.shared.node-tree'
|
|
4
|
+
import { Logger, LOGGING_TOPIC, Converter, ShapeDiverViewerDataProcessingError, InputValidator } from '@shapediver/viewer.shared.services'
|
|
5
|
+
import { vec3, vec4 } from 'gl-matrix'
|
|
6
|
+
import { Box } from '@shapediver/viewer.shared.math'
|
|
7
|
+
import { ShapeDiverResponseOutputContent } from '@shapediver/sdk.geometry-api-sdk-v2'
|
|
8
|
+
import { IAnchor, ITag2D } from '@shapediver/viewer.data-engine.shared-types'
|
|
9
|
+
|
|
10
|
+
@singleton()
|
|
11
|
+
export class HTMLElementAnchorEngine {
|
|
12
|
+
// #region Properties (2)
|
|
13
|
+
|
|
14
|
+
private readonly _converter: Converter = <Converter>container.resolve(Converter);
|
|
15
|
+
private readonly _inputValidator: InputValidator = <InputValidator>container.resolve(InputValidator);
|
|
16
|
+
private readonly _logger: Logger = <Logger>container.resolve(Logger);
|
|
17
|
+
|
|
18
|
+
// #endregion Properties (2)
|
|
19
|
+
|
|
20
|
+
// #region Public Methods (1)
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Load the material content into a scene graph node.
|
|
24
|
+
*
|
|
25
|
+
* @param content the material content
|
|
26
|
+
* @returns the scene graph node
|
|
27
|
+
*/
|
|
28
|
+
public async loadContent(content: ShapeDiverResponseOutputContent): Promise<ITreeNode> {
|
|
29
|
+
try {
|
|
30
|
+
const node = new TreeNode('htmlElementAnchors');
|
|
31
|
+
if (content.format === 'tag2d') {
|
|
32
|
+
const data: ITag2D[] = content.data;
|
|
33
|
+
data.forEach((element: ITag2D) => {
|
|
34
|
+
// we need a location and a text, otherwise this doesn't make sense
|
|
35
|
+
if (!element.location || !element.text) {
|
|
36
|
+
this._logger.warn(LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: One of the specified Tag2D elements did not have all necessary properties.');
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const cleanedText = this._inputValidator.sanitize(element.text);
|
|
40
|
+
node.data.push(new HTMLElementAnchorTextData({
|
|
41
|
+
location: this._converter.toVec3(element.location),
|
|
42
|
+
data: { color: this._converter.toColor(element.color, '#000000'), text: cleanedText }
|
|
43
|
+
}))
|
|
44
|
+
});
|
|
45
|
+
} else if (content.format === 'anchor') {
|
|
46
|
+
const data: IAnchor[] = content.data;
|
|
47
|
+
data.forEach((element: IAnchor) => {
|
|
48
|
+
if (!element.location || !element.data) {
|
|
49
|
+
this._logger.warn(LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: One of the specified Anchor elements did not have all necessary properties.');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let position
|
|
54
|
+
if (element.data.position)
|
|
55
|
+
position = {
|
|
56
|
+
vertical: element.data.position.vertical,
|
|
57
|
+
horizontal: element.data.position.horizontal
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let intersectionTarget;
|
|
61
|
+
if (element.intersectionTarget) {
|
|
62
|
+
if (typeof element.intersectionTarget === 'string' || Array.isArray(element.intersectionTarget)) {
|
|
63
|
+
intersectionTarget = element.intersectionTarget;
|
|
64
|
+
} else if (element.intersectionTarget.min && element.intersectionTarget.max) {
|
|
65
|
+
intersectionTarget = new Box(this._converter.toVec3(element.intersectionTarget.min), this._converter.toVec3(element.intersectionTarget.max))
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!element.format || (element.format === 'text')) {
|
|
70
|
+
if (!(<IAnchorDataText>element.data).text) {
|
|
71
|
+
this._logger.warn(LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: The text property for an Anchor element is missing.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const textData = <IAnchorDataText>element.data;
|
|
75
|
+
const cleanedText = this._inputValidator.sanitize(textData.text);
|
|
76
|
+
|
|
77
|
+
node.data.push(new HTMLElementAnchorTextData({
|
|
78
|
+
location: this._converter.toVec3(element.location),
|
|
79
|
+
data: {
|
|
80
|
+
color: this._converter.toColor(textData.color, '#000000'),
|
|
81
|
+
text: cleanedText,
|
|
82
|
+
hidden: textData.hidden,
|
|
83
|
+
textAlign: textData.textAlign,
|
|
84
|
+
position
|
|
85
|
+
},
|
|
86
|
+
hideable: element.hideable,
|
|
87
|
+
viewports: element.viewports,
|
|
88
|
+
intersectionTarget
|
|
89
|
+
}));
|
|
90
|
+
|
|
91
|
+
} else if (element.format === 'image') {
|
|
92
|
+
if (!(<IAnchorDataImage>element.data).src || !(<IAnchorDataImage>element.data).width || !(<IAnchorDataImage>element.data).height || !(<IAnchorDataImage>element.data).alt) {
|
|
93
|
+
this._logger.warn(LOGGING_TOPIC.DATA_PROCESSING, 'HTMLElementAnchorEngine.load: One of the specified Anchor elements did not have all necessary properties.');
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const imageData = <IAnchorDataImage>element.data;
|
|
97
|
+
node.data.push(new HTMLElementAnchorImageData({
|
|
98
|
+
location: this._converter.toVec3(element.location),
|
|
99
|
+
data: {
|
|
100
|
+
alt: imageData.alt,
|
|
101
|
+
height: typeof imageData.height === 'string' ? +imageData.height : imageData.height,
|
|
102
|
+
width: typeof imageData.width === 'string' ? +imageData.width : imageData.width,
|
|
103
|
+
src: imageData.src,
|
|
104
|
+
hidden: imageData.hidden,
|
|
105
|
+
position
|
|
106
|
+
},
|
|
107
|
+
hideable: element.hideable,
|
|
108
|
+
viewports: element.viewports,
|
|
109
|
+
intersectionTarget
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
this._logger.warn(LOGGING_TOPIC.DATA_PROCESSING, `HTMLElementAnchorEngine.load: The Anchor does not have a recognized format: ${element.format}`);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return node;
|
|
116
|
+
} catch (e) {
|
|
117
|
+
const error = new ShapeDiverViewerDataProcessingError('HTMLElementAnchorEngine.load: Loading of anchors failed.');
|
|
118
|
+
throw this._logger.handleError(LOGGING_TOPIC.DATA_PROCESSING, `HTMLElementAnchorEngine.load`, error);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// #endregion Public Methods (1)
|
|
123
|
+
}
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED