@sswroom/sswr 1.5.0 → 1.5.2
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/Changelog +37 -0
- package/cesium.d.ts +9 -2
- package/cesium.js +263 -44
- package/data.d.ts +6 -0
- package/data.js +216 -204
- package/geometry.d.ts +5 -0
- package/geometry.js +62 -50
- package/hkoapi.js +10 -10
- package/kml.d.ts +4 -1
- package/kml.js +53 -24
- package/leaflet.js +154 -34
- package/map.js +22 -22
- package/math.js +134 -134
- package/net.d.ts +2 -0
- package/net.js +76 -0
- package/olayer2.d.ts +11 -0
- package/olayer2.js +328 -76
- package/osm.js +21 -22
- package/package.json +1 -1
- package/parser.js +339 -93
- package/text.d.ts +127 -1
- package/text.js +1142 -21
- package/web.d.ts +9 -0
- package/web.js +222 -58
package/geometry.d.ts
CHANGED
package/geometry.js
CHANGED
|
@@ -65,22 +65,22 @@ export class LineString extends Vector2D
|
|
|
65
65
|
|
|
66
66
|
calBoundaryPoint(coord)
|
|
67
67
|
{
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
let l;
|
|
69
|
+
let points;
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
let calBase;
|
|
72
|
+
let calDiffX;
|
|
73
|
+
let calDiffY;
|
|
74
|
+
let calSqDiffX;
|
|
75
|
+
let calSqDiffY;
|
|
76
|
+
let calPtX;
|
|
77
|
+
let calPtY;
|
|
78
|
+
let calPtOutX = 0;
|
|
79
|
+
let calPtOutY = 0;
|
|
80
|
+
let calD;
|
|
81
|
+
let dist = 0x7fffffff;
|
|
82
|
+
let x = coord.x;
|
|
83
|
+
let y = coord.y;
|
|
84
84
|
|
|
85
85
|
points = this.coordinates;
|
|
86
86
|
l = points.length - 1;
|
|
@@ -171,7 +171,7 @@ export class LineString extends Vector2D
|
|
|
171
171
|
calPtOutY = points[l][1];
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
|
|
174
|
+
let ret = new Object();
|
|
175
175
|
ret.x = calPtOutX;
|
|
176
176
|
ret.y = calPtOutY;
|
|
177
177
|
ret.dist = Math.sqrt(dist);
|
|
@@ -180,13 +180,13 @@ export class LineString extends Vector2D
|
|
|
180
180
|
|
|
181
181
|
insideOrTouch(coord)
|
|
182
182
|
{
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
183
|
+
let thisX;
|
|
184
|
+
let thisY;
|
|
185
|
+
let lastX;
|
|
186
|
+
let lastY;
|
|
187
|
+
let j;
|
|
188
|
+
let l;
|
|
189
|
+
let tmpX;
|
|
190
190
|
|
|
191
191
|
l = this.coordinates.length;
|
|
192
192
|
lastX = this.coordinates[0][0];
|
|
@@ -238,17 +238,17 @@ export class LinearRing extends LineString
|
|
|
238
238
|
|
|
239
239
|
insideOrTouch(coord)
|
|
240
240
|
{
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
241
|
+
let thisX;
|
|
242
|
+
let thisY;
|
|
243
|
+
let lastX;
|
|
244
|
+
let lastY;
|
|
245
|
+
let j;
|
|
246
|
+
let l;
|
|
247
|
+
let leftCnt = 0;
|
|
248
|
+
let tmpX;
|
|
249
|
+
let points;
|
|
250
|
+
let x = coord.x;
|
|
251
|
+
let y = coord.y;
|
|
252
252
|
|
|
253
253
|
points = this.coordinates;
|
|
254
254
|
|
|
@@ -301,8 +301,8 @@ export class LinearRing extends LineString
|
|
|
301
301
|
|
|
302
302
|
isClose()
|
|
303
303
|
{
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
let firstPoint = this.coordinates[0];
|
|
305
|
+
let lastPoint = this.coordinates[this.coordinates.length - 1];
|
|
306
306
|
return firstPoint[0] == lastPoint[0] && firstPoint[1] == lastPoint[1];
|
|
307
307
|
}
|
|
308
308
|
|
|
@@ -313,10 +313,10 @@ export class LinearRing extends LineString
|
|
|
313
313
|
|
|
314
314
|
static createFromCircle(srid, center, radiusX, radiusY, nPoints)
|
|
315
315
|
{
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
let pos = [];
|
|
317
|
+
let ratio = 2 * Math.PI / nPoints;
|
|
318
|
+
let i = 0;
|
|
319
|
+
let angle;
|
|
320
320
|
i = 0;
|
|
321
321
|
while (i <= nPoints)
|
|
322
322
|
{
|
|
@@ -338,9 +338,9 @@ export class MultiGeometry extends Vector2D
|
|
|
338
338
|
|
|
339
339
|
calBoundaryPoint(coord)
|
|
340
340
|
{
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
341
|
+
let minObj = null;
|
|
342
|
+
let thisObj;
|
|
343
|
+
let i = this.coordinates.length;
|
|
344
344
|
while (i-- > 0)
|
|
345
345
|
{
|
|
346
346
|
thisObj = this.coordinates[i].calBoundaryPoint(coord);
|
|
@@ -354,7 +354,7 @@ export class MultiGeometry extends Vector2D
|
|
|
354
354
|
|
|
355
355
|
insideOrTouch(coord)
|
|
356
356
|
{
|
|
357
|
-
|
|
357
|
+
let i = this.coordinates.length;
|
|
358
358
|
while (i-- > 0)
|
|
359
359
|
{
|
|
360
360
|
if (this.coordinates[i].insideOrTouch(coord))
|
|
@@ -372,7 +372,7 @@ export class Polygon extends MultiGeometry
|
|
|
372
372
|
{
|
|
373
373
|
super(srid);
|
|
374
374
|
this.type = VectorType.Polygon;
|
|
375
|
-
|
|
375
|
+
let i;
|
|
376
376
|
for (i in coordinates)
|
|
377
377
|
{
|
|
378
378
|
this.geometries.push(new LinearRing(srid, coordinates[i]));
|
|
@@ -381,8 +381,8 @@ export class Polygon extends MultiGeometry
|
|
|
381
381
|
|
|
382
382
|
insideOrTouch(coord)
|
|
383
383
|
{
|
|
384
|
-
|
|
385
|
-
|
|
384
|
+
let i = this.coordinates.length;
|
|
385
|
+
let inside = false;
|
|
386
386
|
while (i-- > 0)
|
|
387
387
|
{
|
|
388
388
|
if (this.coordinates[i].insideOrTouch(coord))
|
|
@@ -400,10 +400,22 @@ export class MultiPolygon extends MultiGeometry
|
|
|
400
400
|
{
|
|
401
401
|
super(srid);
|
|
402
402
|
this.type = VectorType.MultiPolygon;
|
|
403
|
-
|
|
404
|
-
|
|
403
|
+
let i;
|
|
404
|
+
if (coordinates)
|
|
405
405
|
{
|
|
406
|
-
|
|
406
|
+
for (i in coordinates)
|
|
407
|
+
{
|
|
408
|
+
this.geometries.push(new Polygon(srid, coordinates[i]));
|
|
409
|
+
}
|
|
407
410
|
}
|
|
408
411
|
}
|
|
409
412
|
}
|
|
413
|
+
|
|
414
|
+
export class GeometryCollection extends MultiGeometry
|
|
415
|
+
{
|
|
416
|
+
constructor(srid)
|
|
417
|
+
{
|
|
418
|
+
super(srid);
|
|
419
|
+
this.type = VectorType.GeometryCollection;
|
|
420
|
+
}
|
|
421
|
+
}
|
package/hkoapi.js
CHANGED
|
@@ -17,7 +17,7 @@ export function getLayers()
|
|
|
17
17
|
|
|
18
18
|
export async function getLocalWeatherForecast(lang)
|
|
19
19
|
{
|
|
20
|
-
|
|
20
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=flw&lang="+lang);
|
|
21
21
|
if (resp.ok)
|
|
22
22
|
{
|
|
23
23
|
return await resp.json();
|
|
@@ -27,7 +27,7 @@ export async function getLocalWeatherForecast(lang)
|
|
|
27
27
|
|
|
28
28
|
export async function get9DayWeatherForecast(lang)
|
|
29
29
|
{
|
|
30
|
-
|
|
30
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=fnd&lang="+lang);
|
|
31
31
|
if (resp.ok)
|
|
32
32
|
{
|
|
33
33
|
return await resp.json();
|
|
@@ -37,7 +37,7 @@ export async function get9DayWeatherForecast(lang)
|
|
|
37
37
|
|
|
38
38
|
export async function getCurrentWeatherReport(lang)
|
|
39
39
|
{
|
|
40
|
-
|
|
40
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread&lang="+lang);
|
|
41
41
|
if (resp.ok)
|
|
42
42
|
{
|
|
43
43
|
return await resp.json();
|
|
@@ -47,7 +47,7 @@ export async function getCurrentWeatherReport(lang)
|
|
|
47
47
|
|
|
48
48
|
export async function getWeatherWarningSummary(lang)
|
|
49
49
|
{
|
|
50
|
-
|
|
50
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=warnsum&lang="+lang);
|
|
51
51
|
if (resp.ok)
|
|
52
52
|
{
|
|
53
53
|
return await resp.json();
|
|
@@ -57,7 +57,7 @@ export async function getWeatherWarningSummary(lang)
|
|
|
57
57
|
|
|
58
58
|
export async function getWeatherWarningInfo(lang)
|
|
59
59
|
{
|
|
60
|
-
|
|
60
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=warningInfo&lang="+lang);
|
|
61
61
|
if (resp.ok)
|
|
62
62
|
{
|
|
63
63
|
return await resp.json();
|
|
@@ -67,7 +67,7 @@ export async function getWeatherWarningInfo(lang)
|
|
|
67
67
|
|
|
68
68
|
export async function getSpecialWeatherTips(lang)
|
|
69
69
|
{
|
|
70
|
-
|
|
70
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=swt&lang="+lang);
|
|
71
71
|
if (resp.ok)
|
|
72
72
|
{
|
|
73
73
|
return await resp.json();
|
|
@@ -77,7 +77,7 @@ export async function getSpecialWeatherTips(lang)
|
|
|
77
77
|
|
|
78
78
|
export async function getQuickEarthquakeMessages(lang)
|
|
79
79
|
{
|
|
80
|
-
|
|
80
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/earthquake.php?dataType=qem&lang="+lang);
|
|
81
81
|
if (resp.ok)
|
|
82
82
|
{
|
|
83
83
|
return await resp.json();
|
|
@@ -87,7 +87,7 @@ export async function getQuickEarthquakeMessages(lang)
|
|
|
87
87
|
|
|
88
88
|
export async function getLocallyFeltEarthTremorReport(lang)
|
|
89
89
|
{
|
|
90
|
-
|
|
90
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/earthquake.php?dataType=feltearthquake&lang="+lang);
|
|
91
91
|
if (resp.ok)
|
|
92
92
|
{
|
|
93
93
|
return await resp.json();
|
|
@@ -97,7 +97,7 @@ export async function getLocallyFeltEarthTremorReport(lang)
|
|
|
97
97
|
|
|
98
98
|
export async function getLunarDate(date)
|
|
99
99
|
{
|
|
100
|
-
|
|
100
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/lunardate.php?date="+date.toString("yyyy-MM-dd"));
|
|
101
101
|
if (resp.ok)
|
|
102
102
|
{
|
|
103
103
|
return await resp.json();
|
|
@@ -107,7 +107,7 @@ export async function getLunarDate(date)
|
|
|
107
107
|
|
|
108
108
|
export async function getHourlyRainfall(lang)
|
|
109
109
|
{
|
|
110
|
-
|
|
110
|
+
let resp = await fetch("https://data.weather.gov.hk/weatherAPI/opendata/hourlyRainfall.php?lang="+lang);
|
|
111
111
|
if (resp.ok)
|
|
112
112
|
{
|
|
113
113
|
return await resp.json();
|
package/kml.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as data from "./data";
|
|
2
2
|
import * as geometry from "./geometry";
|
|
3
|
+
import * as web from "./web";
|
|
3
4
|
|
|
4
5
|
export enum AltitudeMode
|
|
5
6
|
{
|
|
@@ -139,8 +140,9 @@ export class LineStyle extends ColorStyle
|
|
|
139
140
|
|
|
140
141
|
export class PolyStyle extends ColorStyle
|
|
141
142
|
{
|
|
142
|
-
|
|
143
|
+
outline: boolean;
|
|
143
144
|
constructor();
|
|
145
|
+
setOutline(outline: boolean): void;
|
|
144
146
|
getUsedNS(ns: object): void;
|
|
145
147
|
appendOuterXML(strs: string[], level: number): void;
|
|
146
148
|
equals(o: PolyStyle): boolean;
|
|
@@ -307,4 +309,5 @@ export class ScreenOverlay extends Feature
|
|
|
307
309
|
}
|
|
308
310
|
|
|
309
311
|
export function toString(item: Feature | NetworkLinkControl): string;
|
|
312
|
+
export function toColor(color: string): web.Color;
|
|
310
313
|
export function toCSSColor(color: string): string;
|
package/kml.js
CHANGED
|
@@ -123,7 +123,7 @@ export class ColorStyle extends Element
|
|
|
123
123
|
|
|
124
124
|
fromCSSColor(color)
|
|
125
125
|
{
|
|
126
|
-
|
|
126
|
+
let c = web.parseCSSColor(color);
|
|
127
127
|
this.fromARGB(c.a, c.r, c.g, c.b);
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -212,7 +212,7 @@ export class IconStyle extends ColorStyle
|
|
|
212
212
|
|
|
213
213
|
equals(o)
|
|
214
214
|
{
|
|
215
|
-
if (!o instanceof IconStyle)
|
|
215
|
+
if (!(o instanceof IconStyle))
|
|
216
216
|
return false;
|
|
217
217
|
if (!this.sameColor(o))
|
|
218
218
|
return false;
|
|
@@ -261,7 +261,7 @@ export class LabelStyle extends ColorStyle
|
|
|
261
261
|
|
|
262
262
|
equals(o)
|
|
263
263
|
{
|
|
264
|
-
if (!o instanceof LabelStyle)
|
|
264
|
+
if (!(o instanceof LabelStyle))
|
|
265
265
|
return false;
|
|
266
266
|
if (!this.sameColor(o))
|
|
267
267
|
return false;
|
|
@@ -307,7 +307,7 @@ export class LineStyle extends ColorStyle
|
|
|
307
307
|
|
|
308
308
|
equals(o)
|
|
309
309
|
{
|
|
310
|
-
if (!o instanceof LineStyle)
|
|
310
|
+
if (!(o instanceof LineStyle))
|
|
311
311
|
return false;
|
|
312
312
|
if (!this.sameColor(o))
|
|
313
313
|
return false;
|
|
@@ -324,6 +324,11 @@ export class PolyStyle extends ColorStyle
|
|
|
324
324
|
super();
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
+
setOutline(outline)
|
|
328
|
+
{
|
|
329
|
+
this.outline = outline;
|
|
330
|
+
}
|
|
331
|
+
|
|
327
332
|
getUsedNS(ns)
|
|
328
333
|
{
|
|
329
334
|
}
|
|
@@ -332,15 +337,19 @@ export class PolyStyle extends ColorStyle
|
|
|
332
337
|
{
|
|
333
338
|
strs.push("\t".repeat(level)+"<PolyStyle>");
|
|
334
339
|
this.appendInnerXML(strs, level + 1);
|
|
340
|
+
if (this.outline != null)
|
|
341
|
+
strs.push("\t".repeat(level + 1)+"<outline>"+(this.labelVisibility?"1":"0")+"</outline>");
|
|
335
342
|
strs.push("\t".repeat(level)+"</PolyStyle>");
|
|
336
343
|
}
|
|
337
344
|
|
|
338
345
|
equals(o)
|
|
339
346
|
{
|
|
340
|
-
if (!o instanceof PolyStyle)
|
|
347
|
+
if (!(o instanceof PolyStyle))
|
|
341
348
|
return false;
|
|
342
349
|
if (!this.sameColor(o))
|
|
343
350
|
return false;
|
|
351
|
+
if (this.outline != o.outline)
|
|
352
|
+
return false;
|
|
344
353
|
return true;
|
|
345
354
|
}
|
|
346
355
|
};
|
|
@@ -373,7 +382,7 @@ export class BalloonStyle extends Element
|
|
|
373
382
|
|
|
374
383
|
equals(o)
|
|
375
384
|
{
|
|
376
|
-
if (!o instanceof BalloonStyle)
|
|
385
|
+
if (!(o instanceof BalloonStyle))
|
|
377
386
|
return false;
|
|
378
387
|
if (this.bgColor != o.bgColor)
|
|
379
388
|
return false;
|
|
@@ -411,7 +420,7 @@ export class ListStyle extends Element
|
|
|
411
420
|
|
|
412
421
|
equals(o)
|
|
413
422
|
{
|
|
414
|
-
if (!o instanceof ListStyle)
|
|
423
|
+
if (!(o instanceof ListStyle))
|
|
415
424
|
return false;
|
|
416
425
|
if (this.listItemType != o.listItemType)
|
|
417
426
|
return false;
|
|
@@ -742,13 +751,13 @@ export class Container extends Feature
|
|
|
742
751
|
{
|
|
743
752
|
if (this.styleList == null)
|
|
744
753
|
this.styleList = [];
|
|
745
|
-
|
|
754
|
+
let i;
|
|
746
755
|
for (i in this.styleList)
|
|
747
756
|
{
|
|
748
757
|
if (this.styleList[i].isStyle(iconStyle, labelStyle, lineStyle, polyStyle, balloonStyle, listStyle))
|
|
749
758
|
return this.styleList[i];
|
|
750
759
|
}
|
|
751
|
-
|
|
760
|
+
let style = new Style("style"+(this.styleList.length + 1));
|
|
752
761
|
style.iconStyle = iconStyle;
|
|
753
762
|
style.labelStyle = labelStyle;
|
|
754
763
|
style.lineStyle = lineStyle;
|
|
@@ -761,7 +770,7 @@ export class Container extends Feature
|
|
|
761
770
|
|
|
762
771
|
getStyleById(id)
|
|
763
772
|
{
|
|
764
|
-
|
|
773
|
+
let i;
|
|
765
774
|
if (this.styleList)
|
|
766
775
|
{
|
|
767
776
|
for (i in this.styleList)
|
|
@@ -785,7 +794,7 @@ export class Container extends Feature
|
|
|
785
794
|
{
|
|
786
795
|
if (this.styleList)
|
|
787
796
|
{
|
|
788
|
-
|
|
797
|
+
let i;
|
|
789
798
|
for (i in this.styleList)
|
|
790
799
|
{
|
|
791
800
|
this.styleList[i].getUsedNS(ns);
|
|
@@ -795,7 +804,7 @@ export class Container extends Feature
|
|
|
795
804
|
|
|
796
805
|
appendOuterXML(strs, level)
|
|
797
806
|
{
|
|
798
|
-
|
|
807
|
+
let i;
|
|
799
808
|
strs.push("\t".repeat(level)+"<"+this.eleName+">");
|
|
800
809
|
this.appendInnerXML(strs, level + 1);
|
|
801
810
|
if (this.styleList)
|
|
@@ -865,7 +874,7 @@ export class Placemark extends Feature
|
|
|
865
874
|
{
|
|
866
875
|
if (subGeom)
|
|
867
876
|
{
|
|
868
|
-
|
|
877
|
+
let i;
|
|
869
878
|
strs.push("\t".repeat(level)+"<LinearRing>");
|
|
870
879
|
if (vec.coordinates[0].length >= 3)
|
|
871
880
|
{
|
|
@@ -893,13 +902,13 @@ export class Placemark extends Feature
|
|
|
893
902
|
}
|
|
894
903
|
else
|
|
895
904
|
{
|
|
896
|
-
|
|
905
|
+
let pg = vec.toPolygon();
|
|
897
906
|
this.appendGeometry(strs, level, pg, subGeom);
|
|
898
907
|
}
|
|
899
908
|
}
|
|
900
909
|
else if (vec instanceof geometry.LineString)
|
|
901
910
|
{
|
|
902
|
-
|
|
911
|
+
let i;
|
|
903
912
|
strs.push("\t".repeat(level)+"<LineString>");
|
|
904
913
|
if (vec.coordinates[0].length >= 3)
|
|
905
914
|
{
|
|
@@ -927,7 +936,7 @@ export class Placemark extends Feature
|
|
|
927
936
|
}
|
|
928
937
|
else if (vec instanceof geometry.Polygon)
|
|
929
938
|
{
|
|
930
|
-
|
|
939
|
+
let i;
|
|
931
940
|
strs.push("\t".repeat(level)+"<Polygon>");
|
|
932
941
|
if (vec.geometries[0].coordinates[0].length >= 3)
|
|
933
942
|
{
|
|
@@ -958,7 +967,7 @@ export class Placemark extends Feature
|
|
|
958
967
|
}
|
|
959
968
|
else if (vec instanceof geometry.MultiPolygon)
|
|
960
969
|
{
|
|
961
|
-
|
|
970
|
+
let i;
|
|
962
971
|
strs.push("\t".repeat(level)+"<MultiGeometry>");
|
|
963
972
|
for (i in vec.geometries)
|
|
964
973
|
{
|
|
@@ -986,9 +995,9 @@ export class Placemark extends Feature
|
|
|
986
995
|
|
|
987
996
|
export function toString(item)
|
|
988
997
|
{
|
|
989
|
-
|
|
998
|
+
let strs = [];
|
|
990
999
|
strs.push("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
|
|
991
|
-
|
|
1000
|
+
let namespaces = {};
|
|
992
1001
|
item.getUsedNS(namespaces);
|
|
993
1002
|
strs.push("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
|
|
994
1003
|
item.appendOuterXML(strs, 1);
|
|
@@ -996,14 +1005,34 @@ export function toString(item)
|
|
|
996
1005
|
return strs.join("\r\n");
|
|
997
1006
|
}
|
|
998
1007
|
|
|
1008
|
+
export function toColor(color)
|
|
1009
|
+
{
|
|
1010
|
+
if (color.length != 8)
|
|
1011
|
+
return null;
|
|
1012
|
+
|
|
1013
|
+
return {
|
|
1014
|
+
a: Number.parseInt(color.substring(0, 2), 16) / 255,
|
|
1015
|
+
b: Number.parseInt(color.substring(2, 4), 16) / 255,
|
|
1016
|
+
g: Number.parseInt(color.substring(4, 6), 16) / 255,
|
|
1017
|
+
r: Number.parseInt(color.substring(6, 8), 16) / 255
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
|
|
999
1021
|
export function toCSSColor(color)
|
|
1000
1022
|
{
|
|
1001
1023
|
if (color.length != 8)
|
|
1002
1024
|
return null;
|
|
1003
1025
|
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1026
|
+
let a = Number.parseInt(color.substring(0, 2), 16);
|
|
1027
|
+
if (a == 255)
|
|
1028
|
+
{
|
|
1029
|
+
return "#"+color.substring(6, 8)+color.substring(4, 6)+color.substring(2, 4);
|
|
1030
|
+
}
|
|
1031
|
+
else
|
|
1032
|
+
{
|
|
1033
|
+
let b = Number.parseInt(color.substring(2, 4), 16);
|
|
1034
|
+
let g = Number.parseInt(color.substring(4, 6), 16);
|
|
1035
|
+
let r = Number.parseInt(color.substring(6, 8), 16);
|
|
1036
|
+
return "rgba("+r+", "+g+", "+b+", "+(a / 255.0)+")";
|
|
1037
|
+
}
|
|
1009
1038
|
}
|