Content-Length: 769140 | pFad | http://github.com/NativeScript/NativeScript/commit/c23695c477dc1363e4f30fb45d3666c5b8101e4f

DF fix(core): box-shadow 'none' handling (#10405) · NativeScript/NativeScript@c23695c · GitHub
Skip to content

Commit c23695c

Browse files
authored
fix(core): box-shadow 'none' handling (#10405)
1 parent 212d086 commit c23695c

File tree

6 files changed

+80
-62
lines changed

6 files changed

+80
-62
lines changed

packages/core/ui/styling/css-shadow.spec.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ describe('css-shadow', () => {
77
it('empty', () => {
88
const shadow = parseCSSShadow('');
99
expect(shadow.inset).toBe(false);
10-
expect(shadow.offsetX).toBe(CoreTypes.zeroLength);
10+
expect(shadow.offsetX).toBeUndefined();
1111
expect(shadow.offsetY).toBeUndefined();
1212
expect(shadow.blurRadius).toBeUndefined();
1313
expect(shadow.spreadRadius).toBeUndefined();
14-
expect(shadow.color).toEqual(new Color('black'));
14+
expect(shadow.color).toBeUndefined();
1515
});
1616

1717
it('1px 1px 2px black', () => {
@@ -134,4 +134,14 @@ describe('css-shadow', () => {
134134
expect(shadow.spreadRadius).toBeUndefined();
135135
expect(shadow.color).toEqual(new Color('#333'));
136136
});
137+
138+
it('none', () => {
139+
const shadow = parseCSSShadow('none');
140+
expect(shadow.inset).toBe(false);
141+
expect(shadow.offsetX).toBeUndefined();
142+
expect(shadow.offsetY).toBeUndefined();
143+
expect(shadow.blurRadius).toBeUndefined();
144+
expect(shadow.spreadRadius).toBeUndefined();
145+
expect(shadow.color).toBeUndefined();
146+
});
137147
});
+3-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CoreTypes } from '../../core-types';
21
import { Color } from '../../color';
3-
import { Length } from './style-properties';
2+
import { CoreTypes } from '../../core-types';
3+
import { parseCSSShorthand } from './css-utils';
44

55
export interface ShadowCSSValues {
66
inset: boolean;
@@ -11,57 +11,6 @@ export interface ShadowCSSValues {
1111
color: Color;
1212
}
1313

14-
/**
15-
* Matches whitespace except if the whitespace is contained in parenthesis - ex. rgb(a), hsl color.
16-
*/
17-
const PARTS_RE = /\s(?![^(]*\))/;
18-
19-
/**
20-
* Matches a Length value with or without a unit
21-
*/
22-
const LENGTH_RE = /^-?[0-9]+[a-zA-Z%]*?$/;
23-
24-
/**
25-
* Checks if the value is a Length or 0
26-
*/
27-
const isLength = (v) => v === '0' || LENGTH_RE.test(v);
28-
29-
export function parseCSSShorthand(value: string): {
30-
values: Array<CoreTypes.LengthType>;
31-
color: string;
32-
inset: boolean;
33-
} {
34-
const parts = value.trim().split(PARTS_RE);
35-
const inset = parts.includes('inset');
36-
const first = parts[0];
37-
const last = parts[parts.length - 1];
38-
39-
if (first === 'none') {
40-
return null;
41-
}
42-
43-
let color = 'black';
44-
if (first && !isLength(first) && first !== 'inset') {
45-
color = first;
46-
} else if (last && !isLength(last)) {
47-
color = last;
48-
}
49-
const values = parts
50-
.filter((n) => n !== 'inset')
51-
.filter((n) => n !== color)
52-
.map((val) => {
53-
try {
54-
return Length.parse(val);
55-
} catch (err) {
56-
return CoreTypes.zeroLength;
57-
}
58-
});
59-
return {
60-
inset,
61-
color,
62-
values,
63-
};
64-
}
6514
/**
6615
* Parse a string into ShadowCSSValues
6716
* Supports any valid css box/text shadow combination.
@@ -80,6 +29,6 @@ export function parseCSSShadow(value: string): ShadowCSSValues {
8029
offsetY: offsetY,
8130
blurRadius: blurRadius,
8231
spreadRadius: spreadRadius,
83-
color: new Color(data.color),
32+
color: data.color ? new Color(data.color) : undefined,
8433
};
8534
}

packages/core/ui/styling/css-stroke.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Color } from '../../color';
66
describe('css-text-stroke', () => {
77
it('empty', () => {
88
const stroke = parseCSSStroke('');
9-
expect(stroke.width).toBe(CoreTypes.zeroLength);
10-
expect(stroke.color).toEqual(new Color('black'));
9+
expect(stroke.width).toBeUndefined();
10+
expect(stroke.color).toBeUndefined();
1111
});
1212

1313
it('1px navy', () => {

packages/core/ui/styling/css-stroke.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CoreTypes } from '../../core-types';
22
import { Color } from '../../color';
3-
import { parseCSSShorthand } from './css-shadow';
3+
import { parseCSSShorthand } from './css-utils';
44

55
export interface StrokeCSSValues {
66
width: CoreTypes.LengthType;
@@ -18,6 +18,6 @@ export function parseCSSStroke(value: string): StrokeCSSValues {
1818

1919
return {
2020
width,
21-
color: new Color(data.color),
21+
color: data.color ? new Color(data.color) : undefined,
2222
};
2323
}

packages/core/ui/styling/css-utils.ts

+59
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Trace } from '../../trace';
2+
import { CoreTypes } from '../../core-types';
3+
import { Length } from './style-properties';
24

35
export function cleanupImportantFlags(value: string, propertyName: string) {
46
const index = value?.indexOf('!important');
@@ -10,3 +12,60 @@ export function cleanupImportantFlags(value: string, propertyName: string) {
1012
}
1113
return value;
1214
}
15+
16+
/**
17+
* Matches whitespace except if the whitespace is contained in parenthesis - ex. rgb(a), hsl color.
18+
*/
19+
const PARTS_RE = /\s(?![^(]*\))/;
20+
21+
/**
22+
* Matches a Length value with or without a unit
23+
*/
24+
const LENGTH_RE = /^-?[0-9]+[a-zA-Z%]*?$/;
25+
26+
/**
27+
* Checks if the value is a Length or 0
28+
*/
29+
const isLength = (v) => v === '0' || LENGTH_RE.test(v);
30+
31+
export function parseCSSShorthand(value: string): {
32+
values: Array<CoreTypes.LengthType>;
33+
color: string;
34+
inset: boolean;
35+
} {
36+
const parts = value.trim().split(PARTS_RE);
37+
const first = parts[0];
38+
39+
if (['', 'none'].includes(first)) {
40+
return {
41+
inset: false,
42+
color: undefined,
43+
values: [],
44+
};
45+
} else {
46+
const inset = parts.includes('inset');
47+
const last = parts[parts.length - 1];
48+
let color = 'black';
49+
if (first && !isLength(first) && first !== 'inset') {
50+
color = first;
51+
} else if (last && !isLength(last)) {
52+
color = last;
53+
}
54+
55+
const values = parts
56+
.filter((n) => n !== 'inset')
57+
.filter((n) => n !== color)
58+
.map((val) => {
59+
try {
60+
return Length.parse(val);
61+
} catch (err) {
62+
return CoreTypes.zeroLength;
63+
}
64+
});
65+
return {
66+
inset,
67+
color,
68+
values,
69+
};
70+
}
71+
}

packages/core/utils/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ export function queueGC(delay?: number, useThrottle?: boolean);
3838
* @param fn Function to throttle
3939
* @param delay Customize the delay (default is 300ms)
4040
*/
41-
export function throttle(fn: any, delay?: number);
41+
export function throttle<T extends Function = any>(fn: T, delay?: number): T;
4242

4343
/**
4444
* A simple debounce utility
4545
* @param fn Function to debounce
4646
* @param delay Customize the delay (default is 300ms)
4747
*/
48-
export function debounce(fn: any, delay?: number, options?: { leading?: boolean });
48+
export function debounce<T extends Function = any>(fn: T, delay?: number, options?: { leading?: boolean }): T;
4949

5050
/**
5151
* Releases the reference to the wrapped native object

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/NativeScript/commit/c23695c477dc1363e4f30fb45d3666c5b8101e4f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy