Skip to content

Commit c3b9772

Browse files
committed
chore: updates
fixes: svg crash
1 parent 559537b commit c3b9772

File tree

128 files changed

+7444
-9607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+7444
-9607
lines changed

apps/demo/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@nativescript/canvas-polyfill": "file:../../packages/canvas-polyfill",
1515
"@nativescript/canvas-three": "file:../../packages/canvas-three",
1616
"@nativescript/core": "file:../../node_modules/@nativescript/core",
17+
"@pixi-essentials/svg": "file:../../node_modules/@pixi-essentials/svg",
1718
"babylonjs": "file:../../node_modules/babylonjs",
1819
"babylonjs-materials": "file:../../node_modules/babylonjs-materials",
1920
"chart.js": "file:../../node_modules/chart.js",

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
"@nativescript/types": "~8.5.0",
4141
"@nativescript/webpack": "~5.0.5",
4242
"@ngtools/webpack": "^15.0.0",
43+
"@pixi-essentials/svg": "^2.0.1",
4344
"@types/three": "^0.157.0",
45+
"@xmldom/xmldom": "0.8.10",
4446
"babylonjs": "^6.0.0",
4547
"babylonjs-materials": "^6.0.0",
4648
"canvg": "^4.0.1",
@@ -60,6 +62,7 @@
6062
"pixi-filters": "~5.3.0",
6163
"pixi.js": "~7.3.1",
6264
"pixi.js-legacy": "~7.3.1",
65+
"pixi-viewport": "^5.0.2",
6366
"playcanvas": "^1.66.1",
6467
"query-selector": "2.0.0",
6568
"react-nativescript": "^4.0.0",
@@ -70,16 +73,12 @@
7073
"typescript": "~4.8.0",
7174
"util": "~0.12.5",
7275
"vexflow": "^4.2.3",
73-
"@xmldom/xmldom": "0.8.10",
7476
"zen-3d": "0.0.3",
7577
"zone.js": "~0.13.0"
7678
},
7779
"lint-staged": {
7880
"**/*.{js,ts,scss,json,html}": [
7981
"npx prettier --write"
8082
]
81-
},
82-
"dependencies": {
83-
"pixi-viewport": "^5.0.2"
8483
}
8584
}

packages/canvas-babylon/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-babylon",
3-
"version": "2.0.0-beta.17",
3+
"version": "2.0.0-beta.18",
44
"description": "",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-media/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-media",
3-
"version": "2.0.0-beta.17",
3+
"version": "2.0.0-beta.18",
44
"description": "Canvas media",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-phaser-ce/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-phaser-ce",
3-
"version": "2.0.0-beta.17",
3+
"version": "2.0.0-beta.18",
44
"description": "Tools for using Phaser-ce to build native 2D games in NativeScript 👾",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-phaser/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-phaser",
3-
"version": "2.0.0-beta.17",
3+
"version": "2.0.0-beta.18",
44
"description": "Build awesome 2D games with Phaser.js and NativeScript",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-pixi/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/canvas-pixi",
3-
"version": "2.0.0-beta.17",
3+
"version": "2.0.0-beta.18",
44
"description": "Plugin for using pixi.js in NativeScript",
55
"main": "index",
66
"typings": "index.d.ts",

packages/canvas-polyfill/DOM/Document.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import { Canvas } from '@nativescript/canvas';
88
import { Frame, StackLayout } from '@nativescript/core';
99
import { Node } from './Node';
1010
import { Element } from './Element';
11-
11+
import { SVGSVGElement } from './svg/SVGSVGElement';
1212
export class Document extends Node {
1313
readonly body: Element;
1414
private _documentElement: Element;
1515
private readyState: string;
1616
readonly head: Element;
17-
17+
__instance: Document;
1818
get defaultView() {
1919
return global.window;
20-
};
20+
}
2121

2222
constructor() {
2323
super('#document');
@@ -41,7 +41,7 @@ export class Document extends Node {
4141
// Return nothing to keep firebase working.
4242
return null;
4343
case 'svg':
44-
return new SVGElement();
44+
return new SVGSVGElement('svg');
4545
case 'rect':
4646
return new SVGRectElement();
4747
case 'circle':
@@ -69,6 +69,9 @@ export class Document extends Node {
6969
}
7070

7171
getElementById(id: string) {
72+
if (this.__instance) {
73+
return this.__instance.getElementById(id);
74+
}
7275
const topmost = Frame.topmost();
7376
if (topmost) {
7477
const nativeElement = topmost.getViewById(id);
@@ -91,24 +94,34 @@ export class Document extends Node {
9194
}
9295

9396
getElementsByTagName(tagname: string) {
97+
if (this.__instance) {
98+
return this.__instance.getElementsByTagName(tagname);
99+
}
94100
return [];
95101
}
96102

97103
get documentElement() {
98-
return this._documentElement;
104+
if (this._documentElement) {
105+
return this._documentElement;
106+
}
107+
if (this.__instance) {
108+
return this.__instance?.documentElement;
109+
}
110+
return null;
99111
}
100112

101113
//@ts-ignore
102-
set documentElement(value) {
103-
}
114+
set documentElement(value) {}
104115

105116
querySelectorAll(selector) {
117+
if (this.__instance) {
118+
return this.__instance.querySelectorAll?.(selector) ?? [];
119+
}
106120
return [];
107-
//return (this as any)._instance?.querySelectorAll?.(selector) ?? [];
108121
}
109122

110123
querySelector(selector) {
111-
// const ret = (this as any)._instance?.querySelectorAll?.(selector);
124+
const ret = this.__instance?.querySelectorAll?.(selector);
112125
// let element = ret?.[0] ?? null;
113126
// if (ret === undefined) {
114127
// const items = (this as any)._instance.getElementsByTagName(selector);

packages/canvas-polyfill/DOM/Element.ts

+60-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class DOMRect extends DOMRectReadOnly {
3333
}
3434
}
3535

36-
3736
export class Element extends Node {
3837
private _classList = new Set();
3938
_nativeElement: ViewBase;
@@ -43,7 +42,6 @@ export class Element extends Node {
4342
private _attributeOriginalValue: Map<string, unknown> = new Map();
4443
private _jsBuffer: Float32Array;
4544

46-
4745
set nativeElement(value) {
4846
this._nativeElement = value;
4947
if (value) {
@@ -76,6 +74,61 @@ export class Element extends Node {
7674
return this.nodeName;
7775
}
7876

77+
get children() {
78+
const element = (<any>this)._xmlDom?.documentElement ?? (<any>this)._xmlDom;
79+
if (element) {
80+
const ret = [];
81+
const length = element?.childNodes?.length ?? 0;
82+
83+
for (let i = 0; i < length; i++) {
84+
const node = element.childNodes.item(i);
85+
if (node) {
86+
switch (node.nodeName) {
87+
case 'line':
88+
{
89+
const line = new SVGLineElement() as any;
90+
line.__instance = node;
91+
ret.push(line);
92+
}
93+
break;
94+
case 'polyline':
95+
{
96+
const polyline = new SVGPolylineElement() as any;
97+
polyline.__instance = node;
98+
ret.push(polyline);
99+
}
100+
break;
101+
case 'g':
102+
{
103+
const g = new SVGGElement() as any;
104+
g.__instance = node;
105+
ret.push(g);
106+
}
107+
break;
108+
case 'path':
109+
{
110+
const path = new SVGPathElement() as any;
111+
path.__instance = node;
112+
ret.push(path);
113+
}
114+
break;
115+
case 'rect':
116+
{
117+
const rect = new SVGRectElement() as any;
118+
rect.__instance = node;
119+
ret.push(rect);
120+
}
121+
break;
122+
}
123+
}
124+
}
125+
126+
return ret;
127+
}
128+
129+
return [];
130+
}
131+
79132
getAttribute(key: string): unknown {
80133
if (this.nativeElement) {
81134
return this.nativeElement[key];
@@ -108,11 +161,9 @@ export class Element extends Node {
108161
}
109162
}
110163

111-
setAttributeNS() {
112-
}
164+
setAttributeNS() {}
113165

114-
removeAttributeNS() {
115-
}
166+
removeAttributeNS() {}
116167

117168
querySelector(selector: string) {
118169
const selection = querySelector(selector, this);
@@ -126,7 +177,6 @@ export class Element extends Node {
126177
return querySelector(selector, this);
127178
}
128179

129-
130180
getBoundingClientRect() {
131181
const nativeElement = this['nativeElement'];
132182
if (this.nodeName === 'CANVAS') {
@@ -152,7 +202,7 @@ export class Element extends Node {
152202
x: 0,
153203
y: 0,
154204
width: this.innerWidth,
155-
height: this.innerHeight
205+
height: this.innerHeight,
156206
};
157207
}
158208

@@ -216,9 +266,7 @@ export class Element extends Node {
216266
return {};
217267
}
218268

219-
setPointerCapture(id: string) {
220-
}
269+
setPointerCapture(id: string) {}
221270

222-
releasePointerCapture(id: string) {
223-
}
271+
releasePointerCapture(id: string) {}
224272
}

packages/canvas-polyfill/DOM/XMLDocument.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { Document as Doc} from './Document';
1+
import { Document as Doc } from './Document';
22

33
import querySelector from 'query-selector';
44

55
import { DOMParser } from '@xmldom/xmldom';
66

7+
import { SVGSVGElement } from './svg/SVGSVGElement';
8+
79
export class XMLDocument extends Doc {
8-
private __instance: Document;
10+
//@ts-ignore
11+
__instance: Document;
912
static fromParser(instance) {
1013
if (instance) {
1114
const documentPrototype = Object.getPrototypeOf(instance);
@@ -15,6 +18,12 @@ export class XMLDocument extends Doc {
1518

1619
const doc = new XMLDocument();
1720
doc.__instance = instance;
21+
const documentElement = instance?.documentElement;
22+
if (documentElement?.nodeName === 'svg' && documentElement?.namespaceURI === 'http://www.w3.org/2000/svg') {
23+
const svg = new SVGSVGElement('svg') as any;
24+
svg.__instance = instance.documentElement;
25+
(<any>doc)._documentElement = svg;
26+
}
1827
return doc;
1928
}
2029
return null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const SVG_LENGTHTYPE_UNKNOWN = 0;
2+
const SVG_LENGTHTYPE_NUMBER = 1;
3+
const SVG_LENGTHTYPE_PERCENTAGE = 2;
4+
const SVG_LENGTHTYPE_EMS = 3;
5+
const SVG_LENGTHTYPE_EXS = 4;
6+
const SVG_LENGTHTYPE_PX = 5;
7+
const SVG_LENGTHTYPE_CM = 6;
8+
const SVG_LENGTHTYPE_MM = 7;
9+
const SVG_LENGTHTYPE_IN = 8;
10+
const SVG_LENGTHTYPE_PT = 9;
11+
const SVG_LENGTHTYPE_PC = 10;
12+
13+
// @ts-ignore
14+
export class SVGLength {
15+
_unitType: number = SVG_LENGTHTYPE_UNKNOWN;
16+
17+
_value: number = 0;
18+
_valueInSpecifiedUnits: number = 0;
19+
_valueAsString: number = 0;
20+
21+
newValueSpecifiedUnits(unitType: number, valueInSpecifiedUnits: number) {}
22+
23+
convertToSpecifiedUnits(unitType: number) {}
24+
25+
static SVG_LENGTHTYPE_UNKNOWN = SVG_LENGTHTYPE_UNKNOWN;
26+
27+
static SVG_LENGTHTYPE_NUMBER = SVG_LENGTHTYPE_NUMBER;
28+
29+
static SVG_LENGTHTYPE_PERCENTAGE = SVG_LENGTHTYPE_PERCENTAGE;
30+
31+
static SVG_LENGTHTYPE_EMS = SVG_LENGTHTYPE_EMS;
32+
33+
static SVG_LENGTHTYPE_EXS = SVG_LENGTHTYPE_EXS;
34+
35+
static SVG_LENGTHTYPE_PX = SVG_LENGTHTYPE_PX;
36+
37+
static SVG_LENGTHTYPE_CM = SVG_LENGTHTYPE_CM;
38+
39+
static SVG_LENGTHTYPE_MM = SVG_LENGTHTYPE_MM;
40+
41+
static SVG_LENGTHTYPE_IN = SVG_LENGTHTYPE_IN;
42+
43+
static SVG_LENGTHTYPE_PT = SVG_LENGTHTYPE_PT;
44+
45+
static SVG_LENGTHTYPE_PC = SVG_LENGTHTYPE_PC;
46+
}
47+
48+
// @ts-ignore
49+
export class SVGAnimatedLength {
50+
_baseVal: SVGLength;
51+
_animVal: SVGLength;
52+
53+
constructor() {
54+
this._baseVal = new SVGLength();
55+
this._animVal = new SVGLength();
56+
}
57+
58+
get baseVal() {
59+
return this._baseVal;
60+
}
61+
62+
get animVal() {
63+
return this._animVal;
64+
}
65+
}
66+
67+
export const SVGAnimatedLengthEmpty = new SVGAnimatedLength();
68+
Object.freeze(SVGAnimatedLengthEmpty);

packages/canvas-polyfill/DOM/svg/SVGCircleElement.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { SVGElement } from './SVGElement';
1+
import { SVGGeometryElement } from './SVGGeometryElement';
22
import { Circle } from '@nativescript/canvas-svg';
33

4-
export class SVGCircleElement extends SVGElement {
4+
export class SVGCircleElement extends SVGGeometryElement {
55
//__internalElement: Circle;
66
constructor() {
77
super('circle');

0 commit comments

Comments
 (0)