1 | import { __decorate } from "tslib";
|
2 | import { singleton, Syringe } from 'mana-syringe';
|
3 | export var SceneGraphSelectorFactory = Syringe.defineToken('SceneGraphSelectorFactory');
|
4 | export var SceneGraphSelector = Syringe.defineToken('SceneGraphSelector', {
|
5 | multiple: false
|
6 | });
|
7 | var NAME_REGEXP = /\[\s*name=(.*)\s*\]/;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var DefaultSceneGraphSelector =
|
19 |
|
20 | function () {
|
21 | function DefaultSceneGraphSelector() {}
|
22 |
|
23 | DefaultSceneGraphSelector.prototype.selectOne = function (query, root) {
|
24 | if (query.startsWith('.')) {
|
25 | return root.find(function (node) {
|
26 |
|
27 | return node.className === query.substring(1);
|
28 | });
|
29 | } else if (query.startsWith('#')) {
|
30 |
|
31 | return root.find(function (node) {
|
32 |
|
33 | return node.id === query.substring(1);
|
34 | });
|
35 | } else if (query.startsWith('[name=')) {
|
36 | var matches = query.match(NAME_REGEXP);
|
37 |
|
38 | if (matches && matches.length > 1) {
|
39 | var targetName_1 = matches[1].replace(/"/g, '');
|
40 |
|
41 | return root.find(function (node) {
|
42 | return root !== node && node.name === targetName_1;
|
43 | });
|
44 | } else {
|
45 | return null;
|
46 | }
|
47 | } else {
|
48 |
|
49 | return root.find(function (node) {
|
50 | return root !== node && node.nodeName === query;
|
51 | });
|
52 | }
|
53 | };
|
54 |
|
55 | DefaultSceneGraphSelector.prototype.selectAll = function (query, root) {
|
56 |
|
57 | if (query.startsWith('.')) {
|
58 |
|
59 |
|
60 | return root.findAll(function (node) {
|
61 | return root !== node && node.className === query.substring(1);
|
62 | });
|
63 | } else if (query.startsWith('#')) {
|
64 | return root.findAll(function (node) {
|
65 | return root !== node && node.id === query.substring(1);
|
66 | });
|
67 | } else if (query.startsWith('[name=')) {
|
68 |
|
69 | var matches = query.match(NAME_REGEXP);
|
70 |
|
71 | if (matches && matches.length > 1) {
|
72 | var targetName_2 = matches[1].replace(/"/g, '');
|
73 |
|
74 | return root.findAll(function (node) {
|
75 | return root !== node && node.name === targetName_2;
|
76 | });
|
77 | } else {
|
78 | return [];
|
79 | }
|
80 | } else {
|
81 |
|
82 | return root.findAll(function (node) {
|
83 | return root !== node && node.nodeName === query;
|
84 | });
|
85 | }
|
86 | };
|
87 |
|
88 |
|
89 | DefaultSceneGraphSelector.prototype.is = function () {
|
90 |
|
91 | return true;
|
92 | };
|
93 |
|
94 | DefaultSceneGraphSelector = __decorate([singleton({
|
95 | token: SceneGraphSelector
|
96 | })], DefaultSceneGraphSelector);
|
97 | return DefaultSceneGraphSelector;
|
98 | }();
|
99 |
|
100 | export { DefaultSceneGraphSelector }; |
\ | No newline at end of file |