@antv/g 5.0.23-alpha.0 → 5.0.23-alpha.12
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/index.umd.min.js +2 -2
- package/es/css/StyleValueRegistry.d.ts +2 -0
- package/es/css/StyleValueRegistry.js +7 -3
- package/es/css/cssom/CSSKeywordValue.d.ts +1 -1
- package/es/css/cssom/CSSNumericSumValue.d.ts +1 -1
- package/es/css/cssom/CSSNumericValue.d.ts +141 -4
- package/es/css/cssom/CSSNumericValue.js +1166 -5
- package/es/css/cssom/CSSTransformValue.d.ts +1 -1
- package/es/css/cssom/index.d.ts +0 -10
- package/es/css/cssom/index.js +1 -11
- package/es/css/parser/numeric.d.ts +1 -1
- package/es/css/parser/numeric.js +1 -1
- package/es/css/parser/transform-origin.d.ts +1 -1
- package/es/css/parser/transform-origin.js +1 -1
- package/es/css/parser/transform.d.ts +1 -3
- package/es/css/parser/transform.js +9 -8
- package/es/css/properties/CSSPropertyTransform.js +2 -2
- package/es/plugins/PrepareRendererPlugin.js +2 -2
- package/es/services/RenderingService.js +2 -2
- package/lib/css/StyleValueRegistry.d.ts +2 -0
- package/lib/css/StyleValueRegistry.js +13 -5
- package/lib/css/cssom/CSSKeywordValue.d.ts +1 -1
- package/lib/css/cssom/CSSNumericSumValue.d.ts +1 -1
- package/lib/css/cssom/CSSNumericValue.d.ts +141 -4
- package/lib/css/cssom/CSSNumericValue.js +1232 -58
- package/lib/css/cssom/CSSTransformValue.d.ts +1 -1
- package/lib/css/cssom/index.d.ts +0 -10
- package/lib/css/cssom/index.js +0 -130
- package/lib/css/parser/numeric.d.ts +1 -1
- package/lib/css/parser/numeric.js +4 -4
- package/lib/css/parser/transform-origin.d.ts +1 -1
- package/lib/css/parser/transform-origin.js +2 -2
- package/lib/css/parser/transform.d.ts +1 -3
- package/lib/css/parser/transform.js +25 -24
- package/lib/css/properties/CSSPropertyTransform.js +18 -18
- package/lib/plugins/PrepareRendererPlugin.js +2 -2
- package/lib/services/RenderingService.js +2 -2
- package/package.json +3 -3
- package/es/css/cssom/CSSMathInvert.d.ts +0 -14
- package/es/css/cssom/CSSMathInvert.js +0 -84
- package/es/css/cssom/CSSMathMax.d.ts +0 -17
- package/es/css/cssom/CSSMathMax.js +0 -118
- package/es/css/cssom/CSSMathMin.d.ts +0 -17
- package/es/css/cssom/CSSMathMin.js +0 -119
- package/es/css/cssom/CSSMathNegate.d.ts +0 -14
- package/es/css/cssom/CSSMathNegate.js +0 -80
- package/es/css/cssom/CSSMathProduct.d.ts +0 -16
- package/es/css/cssom/CSSMathProduct.js +0 -109
- package/es/css/cssom/CSSMathSum.d.ts +0 -17
- package/es/css/cssom/CSSMathSum.js +0 -117
- package/es/css/cssom/CSSMathValue.d.ts +0 -11
- package/es/css/cssom/CSSMathValue.js +0 -27
- package/es/css/cssom/CSSMathVariadic.d.ts +0 -9
- package/es/css/cssom/CSSMathVariadic.js +0 -44
- package/es/css/cssom/CSSNumericValueType.d.ts +0 -33
- package/es/css/cssom/CSSNumericValueType.js +0 -259
- package/es/css/cssom/CSSUnitValue.d.ts +0 -33
- package/es/css/cssom/CSSUnitValue.js +0 -252
- package/lib/css/cssom/CSSMathInvert.d.ts +0 -14
- package/lib/css/cssom/CSSMathInvert.js +0 -94
- package/lib/css/cssom/CSSMathMax.d.ts +0 -17
- package/lib/css/cssom/CSSMathMax.js +0 -128
- package/lib/css/cssom/CSSMathMin.d.ts +0 -17
- package/lib/css/cssom/CSSMathMin.js +0 -128
- package/lib/css/cssom/CSSMathNegate.d.ts +0 -14
- package/lib/css/cssom/CSSMathNegate.js +0 -89
- package/lib/css/cssom/CSSMathProduct.d.ts +0 -16
- package/lib/css/cssom/CSSMathProduct.js +0 -119
- package/lib/css/cssom/CSSMathSum.d.ts +0 -17
- package/lib/css/cssom/CSSMathSum.js +0 -129
- package/lib/css/cssom/CSSMathValue.d.ts +0 -11
- package/lib/css/cssom/CSSMathValue.js +0 -35
- package/lib/css/cssom/CSSMathVariadic.d.ts +0 -9
- package/lib/css/cssom/CSSMathVariadic.js +0 -55
- package/lib/css/cssom/CSSNumericValueType.d.ts +0 -33
- package/lib/css/cssom/CSSNumericValueType.js +0 -272
- package/lib/css/cssom/CSSUnitValue.d.ts +0 -33
- package/lib/css/cssom/CSSUnitValue.js +0 -267
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
2
|
-
import { CSSMathValue } from './CSSMathValue';
|
|
3
|
-
export function typeCheck(values, op, error) {
|
|
4
|
-
error = false;
|
|
5
|
-
var final_type = values[0].type_;
|
|
6
|
-
|
|
7
|
-
for (var i = 1; i < values.length; i++) {
|
|
8
|
-
final_type = op(final_type, values[i].type_, error);
|
|
9
|
-
if (error) return final_type;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return final_type;
|
|
13
|
-
} // Represents an arithmetic operation with one or more CSSNumericValues.
|
|
14
|
-
|
|
15
|
-
var CSSMathVariadic =
|
|
16
|
-
/** @class */
|
|
17
|
-
function (_super) {
|
|
18
|
-
__extends(CSSMathVariadic, _super);
|
|
19
|
-
|
|
20
|
-
function CSSMathVariadic(values, type) {
|
|
21
|
-
var _this = _super.call(this, type) || this;
|
|
22
|
-
|
|
23
|
-
_this.values = values;
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
CSSMathVariadic.prototype.numericValues = function () {
|
|
28
|
-
return this.values;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
CSSMathVariadic.prototype.equals = function (other) {
|
|
32
|
-
if (this.getType() !== other.getType()) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return this.values.every(function (value, i) {
|
|
37
|
-
return value.equals(other.values[i]);
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return CSSMathVariadic;
|
|
42
|
-
}(CSSMathValue);
|
|
43
|
-
|
|
44
|
-
export { CSSMathVariadic };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { UnitType } from '.';
|
|
2
|
-
export declare enum BaseType {
|
|
3
|
-
kLength = 0,
|
|
4
|
-
kAngle = 1,
|
|
5
|
-
kTime = 2,
|
|
6
|
-
kFrequency = 3,
|
|
7
|
-
kResolution = 4,
|
|
8
|
-
kFlex = 5,
|
|
9
|
-
kPercent = 6,
|
|
10
|
-
kNumBaseTypes = 7
|
|
11
|
-
}
|
|
12
|
-
export declare function unitTypeToBaseType(unit: UnitType): BaseType.kLength | BaseType.kAngle | BaseType.kTime | BaseType.kFrequency | BaseType.kResolution | BaseType.kFlex | BaseType.kPercent;
|
|
13
|
-
export declare function baseTypeToString(baseType: BaseType): "" | "percent" | "length" | "angle" | "time" | "frequency" | "resolution" | "flex";
|
|
14
|
-
export declare class CSSNumericValueType {
|
|
15
|
-
private exponents;
|
|
16
|
-
private numNonZeroEntries;
|
|
17
|
-
percentHint: BaseType;
|
|
18
|
-
hasPercentHint: boolean;
|
|
19
|
-
constructor(unit?: UnitType, exponent?: number);
|
|
20
|
-
applyPercentHint(hint: BaseType): void;
|
|
21
|
-
hasNonZeroEntries(): boolean;
|
|
22
|
-
isOnlyNonZeroEntry(baseType: BaseType, value: number): boolean;
|
|
23
|
-
exponent(type: BaseType): number;
|
|
24
|
-
setExponent(type: BaseType, newValue: number): void;
|
|
25
|
-
static negateExponents(type: CSSNumericValueType): CSSNumericValueType;
|
|
26
|
-
matchesBaseType(baseType: BaseType): boolean;
|
|
27
|
-
matchesPercentage(): boolean;
|
|
28
|
-
matchesBaseTypePercentage(baseType: BaseType): boolean;
|
|
29
|
-
matchesNumber(): boolean;
|
|
30
|
-
matchesNumberPercentage(): boolean;
|
|
31
|
-
static add(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
|
|
32
|
-
static multiply(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
|
|
33
|
-
}
|
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { DCHECK_EQ, DCHECK_NE } from '../../utils';
|
|
2
|
-
import { UnitType } from '.'; // https://drafts.css-houdini.org/css-typed-om/#enumdef-cssnumericbasetype
|
|
3
|
-
|
|
4
|
-
export var BaseType;
|
|
5
|
-
|
|
6
|
-
(function (BaseType) {
|
|
7
|
-
BaseType[BaseType["kLength"] = 0] = "kLength";
|
|
8
|
-
BaseType[BaseType["kAngle"] = 1] = "kAngle";
|
|
9
|
-
BaseType[BaseType["kTime"] = 2] = "kTime";
|
|
10
|
-
BaseType[BaseType["kFrequency"] = 3] = "kFrequency";
|
|
11
|
-
BaseType[BaseType["kResolution"] = 4] = "kResolution";
|
|
12
|
-
BaseType[BaseType["kFlex"] = 5] = "kFlex";
|
|
13
|
-
BaseType[BaseType["kPercent"] = 6] = "kPercent";
|
|
14
|
-
BaseType[BaseType["kNumBaseTypes"] = 7] = "kNumBaseTypes";
|
|
15
|
-
})(BaseType || (BaseType = {}));
|
|
16
|
-
|
|
17
|
-
export function unitTypeToBaseType(unit) {
|
|
18
|
-
DCHECK_NE(unit, UnitType.kNumber);
|
|
19
|
-
|
|
20
|
-
switch (unit) {
|
|
21
|
-
case UnitType.kEms:
|
|
22
|
-
case UnitType.kExs:
|
|
23
|
-
case UnitType.kPixels:
|
|
24
|
-
case UnitType.kCentimeters:
|
|
25
|
-
case UnitType.kMillimeters:
|
|
26
|
-
case UnitType.kQuarterMillimeters:
|
|
27
|
-
case UnitType.kInches:
|
|
28
|
-
case UnitType.kPoints:
|
|
29
|
-
case UnitType.kPicas:
|
|
30
|
-
case UnitType.kUserUnits:
|
|
31
|
-
case UnitType.kViewportWidth:
|
|
32
|
-
case UnitType.kViewportHeight:
|
|
33
|
-
case UnitType.kViewportInlineSize:
|
|
34
|
-
case UnitType.kViewportBlockSize:
|
|
35
|
-
case UnitType.kViewportMin:
|
|
36
|
-
case UnitType.kViewportMax:
|
|
37
|
-
case UnitType.kSmallViewportWidth:
|
|
38
|
-
case UnitType.kSmallViewportHeight:
|
|
39
|
-
case UnitType.kSmallViewportInlineSize:
|
|
40
|
-
case UnitType.kSmallViewportBlockSize:
|
|
41
|
-
case UnitType.kSmallViewportMin:
|
|
42
|
-
case UnitType.kSmallViewportMax:
|
|
43
|
-
case UnitType.kLargeViewportWidth:
|
|
44
|
-
case UnitType.kLargeViewportHeight:
|
|
45
|
-
case UnitType.kLargeViewportInlineSize:
|
|
46
|
-
case UnitType.kLargeViewportBlockSize:
|
|
47
|
-
case UnitType.kLargeViewportMin:
|
|
48
|
-
case UnitType.kLargeViewportMax:
|
|
49
|
-
case UnitType.kDynamicViewportWidth:
|
|
50
|
-
case UnitType.kDynamicViewportHeight:
|
|
51
|
-
case UnitType.kDynamicViewportInlineSize:
|
|
52
|
-
case UnitType.kDynamicViewportBlockSize:
|
|
53
|
-
case UnitType.kDynamicViewportMin:
|
|
54
|
-
case UnitType.kDynamicViewportMax:
|
|
55
|
-
case UnitType.kContainerWidth:
|
|
56
|
-
case UnitType.kContainerHeight:
|
|
57
|
-
case UnitType.kContainerInlineSize:
|
|
58
|
-
case UnitType.kContainerBlockSize:
|
|
59
|
-
case UnitType.kContainerMin:
|
|
60
|
-
case UnitType.kContainerMax:
|
|
61
|
-
case UnitType.kRems:
|
|
62
|
-
case UnitType.kChs:
|
|
63
|
-
return BaseType.kLength;
|
|
64
|
-
|
|
65
|
-
case UnitType.kMilliseconds:
|
|
66
|
-
case UnitType.kSeconds:
|
|
67
|
-
return BaseType.kTime;
|
|
68
|
-
|
|
69
|
-
case UnitType.kDegrees:
|
|
70
|
-
case UnitType.kRadians:
|
|
71
|
-
case UnitType.kGradians:
|
|
72
|
-
case UnitType.kTurns:
|
|
73
|
-
return BaseType.kAngle;
|
|
74
|
-
|
|
75
|
-
case UnitType.kHertz:
|
|
76
|
-
case UnitType.kKilohertz:
|
|
77
|
-
return BaseType.kFrequency;
|
|
78
|
-
|
|
79
|
-
case UnitType.kDotsPerPixel:
|
|
80
|
-
case UnitType.kDotsPerInch:
|
|
81
|
-
case UnitType.kDotsPerCentimeter:
|
|
82
|
-
return BaseType.kResolution;
|
|
83
|
-
|
|
84
|
-
case UnitType.kFraction:
|
|
85
|
-
return BaseType.kFlex;
|
|
86
|
-
|
|
87
|
-
case UnitType.kPercentage:
|
|
88
|
-
return BaseType.kPercent;
|
|
89
|
-
|
|
90
|
-
default:
|
|
91
|
-
return BaseType.kLength;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
export function baseTypeToString(baseType) {
|
|
95
|
-
switch (baseType) {
|
|
96
|
-
case BaseType.kLength:
|
|
97
|
-
return 'length';
|
|
98
|
-
|
|
99
|
-
case BaseType.kAngle:
|
|
100
|
-
return 'angle';
|
|
101
|
-
|
|
102
|
-
case BaseType.kTime:
|
|
103
|
-
return 'time';
|
|
104
|
-
|
|
105
|
-
case BaseType.kFrequency:
|
|
106
|
-
return 'frequency';
|
|
107
|
-
|
|
108
|
-
case BaseType.kResolution:
|
|
109
|
-
return 'resolution';
|
|
110
|
-
|
|
111
|
-
case BaseType.kFlex:
|
|
112
|
-
return 'flex';
|
|
113
|
-
|
|
114
|
-
case BaseType.kPercent:
|
|
115
|
-
return 'percent';
|
|
116
|
-
|
|
117
|
-
default:
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return '';
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
var CSSNumericValueType =
|
|
125
|
-
/** @class */
|
|
126
|
-
function () {
|
|
127
|
-
function CSSNumericValueType(unit, exponent) {
|
|
128
|
-
if (unit === void 0) {
|
|
129
|
-
unit = UnitType.kNumber;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (exponent === void 0) {
|
|
133
|
-
exponent = 1;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
this.exponents = [];
|
|
137
|
-
this.numNonZeroEntries = 0;
|
|
138
|
-
this.percentHint = BaseType.kPercent;
|
|
139
|
-
this.hasPercentHint = false;
|
|
140
|
-
this.exponents = new Array(BaseType.kNumBaseTypes).fill(0);
|
|
141
|
-
|
|
142
|
-
if (unit !== UnitType.kNumber) {
|
|
143
|
-
this.setExponent(unitTypeToBaseType(unit), exponent);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
CSSNumericValueType.prototype.applyPercentHint = function (hint) {
|
|
148
|
-
DCHECK_NE(hint, BaseType.kPercent);
|
|
149
|
-
this.setExponent(hint, this.exponent(hint) + this.exponent(BaseType.kPercent));
|
|
150
|
-
this.setExponent(BaseType.kPercent, 0);
|
|
151
|
-
this.percentHint = hint;
|
|
152
|
-
this.hasPercentHint = true;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
CSSNumericValueType.prototype.hasNonZeroEntries = function () {
|
|
156
|
-
return this.numNonZeroEntries > 0;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
CSSNumericValueType.prototype.isOnlyNonZeroEntry = function (baseType, value) {
|
|
160
|
-
DCHECK_NE(value, 0);
|
|
161
|
-
return this.numNonZeroEntries === 1 && this.exponent(baseType) === value;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
CSSNumericValueType.prototype.exponent = function (type) {
|
|
165
|
-
return this.exponents[type];
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
CSSNumericValueType.prototype.setExponent = function (type, newValue) {
|
|
169
|
-
var oldValue = this.exponents[type];
|
|
170
|
-
|
|
171
|
-
if (oldValue == 0 && newValue !== 0) {
|
|
172
|
-
this.numNonZeroEntries++;
|
|
173
|
-
} else if (oldValue !== 0 && newValue == 0) {
|
|
174
|
-
this.numNonZeroEntries--;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
this.exponents[type] = newValue;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
CSSNumericValueType.negateExponents = function (type) {
|
|
181
|
-
type.exponents.forEach(function (v) {
|
|
182
|
-
return v *= -1;
|
|
183
|
-
});
|
|
184
|
-
return type;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
CSSNumericValueType.prototype.matchesBaseType = function (baseType) {
|
|
188
|
-
DCHECK_NE(baseType, BaseType.kPercent);
|
|
189
|
-
return this.isOnlyNonZeroEntry(baseType, 1) && !this.hasPercentHint;
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
CSSNumericValueType.prototype.matchesPercentage = function () {
|
|
193
|
-
return this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
CSSNumericValueType.prototype.matchesBaseTypePercentage = function (baseType) {
|
|
197
|
-
DCHECK_NE(baseType, BaseType.kPercent);
|
|
198
|
-
return this.isOnlyNonZeroEntry(baseType, 1) || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
CSSNumericValueType.prototype.matchesNumber = function () {
|
|
202
|
-
return !this.hasNonZeroEntries() && !this.hasPercentHint;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
CSSNumericValueType.prototype.matchesNumberPercentage = function () {
|
|
206
|
-
return !this.hasNonZeroEntries() || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
CSSNumericValueType.add = function (type1, type2, error) {
|
|
210
|
-
if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
|
|
211
|
-
error = true;
|
|
212
|
-
return type1;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
|
|
216
|
-
DCHECK_EQ(type1.percentHint, type2.percentHint); // Match up base types. Try to use the percent hint to match up any
|
|
217
|
-
// differences.
|
|
218
|
-
|
|
219
|
-
for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
|
|
220
|
-
var base_type = i;
|
|
221
|
-
|
|
222
|
-
if (type1.exponents[i] !== type2.exponents[i]) {
|
|
223
|
-
if (base_type !== BaseType.kPercent) {
|
|
224
|
-
type1.applyPercentHint(base_type);
|
|
225
|
-
type2.applyPercentHint(base_type);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (type1.exponents[i] !== type2.exponents[i]) {
|
|
229
|
-
error = true;
|
|
230
|
-
return type1;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
error = false;
|
|
236
|
-
return type1;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
CSSNumericValueType.multiply = function (type1, type2, error) {
|
|
240
|
-
if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
|
|
241
|
-
error = true;
|
|
242
|
-
return type1;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
|
|
246
|
-
|
|
247
|
-
for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
|
|
248
|
-
var base_type = i;
|
|
249
|
-
type1.setExponent(base_type, type1.exponent(base_type) + type2.exponent(base_type));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
error = false;
|
|
253
|
-
return type1;
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
return CSSNumericValueType;
|
|
257
|
-
}();
|
|
258
|
-
|
|
259
|
-
export { CSSNumericValueType };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The CSSUnitValue interface of the CSS_Object_Model represents values that contain a single unit type.
|
|
3
|
-
* For example, "42px" would be represented by a CSSNumericValue.
|
|
4
|
-
*
|
|
5
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSUnitValue
|
|
6
|
-
*/
|
|
7
|
-
import { CSSMathInvert } from './CSSMathInvert';
|
|
8
|
-
import type { CSSNumericSumValue } from './CSSNumericSumValue';
|
|
9
|
-
import type { Nested, ParenLess } from '.';
|
|
10
|
-
import { CSSNumericValue } from './CSSNumericValue';
|
|
11
|
-
import { CSSStyleValueType, UnitType } from '.';
|
|
12
|
-
/**
|
|
13
|
-
* Represents numeric values that can be expressed as a single number plus a
|
|
14
|
-
* unit (or a naked number or percentage).
|
|
15
|
-
* @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
|
|
16
|
-
*/
|
|
17
|
-
export declare class CSSUnitValue extends CSSNumericValue {
|
|
18
|
-
static toCanonicalUnit(unit: UnitType): UnitType.kUnknown | UnitType.kNumber | UnitType.kPixels | UnitType.kDegrees | UnitType.kSeconds | UnitType.kHertz | UnitType.kDotsPerPixel;
|
|
19
|
-
static toCanonicalUnitIfPossible(unit: UnitType): UnitType;
|
|
20
|
-
static formatInfinityOrNaN(number: number, suffix?: string): string;
|
|
21
|
-
static formatNumber(number: number, suffix?: string): string;
|
|
22
|
-
unit: UnitType;
|
|
23
|
-
value: number;
|
|
24
|
-
constructor(value: number, unitOrName?: UnitType | string);
|
|
25
|
-
clone(): CSSUnitValue;
|
|
26
|
-
convertTo(target_unit: UnitType): CSSUnitValue;
|
|
27
|
-
equals(other: CSSNumericValue): boolean;
|
|
28
|
-
getType(): CSSStyleValueType;
|
|
29
|
-
sumValue(): CSSNumericSumValue;
|
|
30
|
-
negate(): CSSUnitValue;
|
|
31
|
-
invert(): CSSUnitValue | CSSMathInvert;
|
|
32
|
-
buildCSSText(n: Nested, p: ParenLess, result: string): string;
|
|
33
|
-
}
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The CSSUnitValue interface of the CSS_Object_Model represents values that contain a single unit type.
|
|
3
|
-
* For example, "42px" would be represented by a CSSNumericValue.
|
|
4
|
-
*
|
|
5
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSUnitValue
|
|
6
|
-
*/
|
|
7
|
-
import { __extends } from "tslib";
|
|
8
|
-
import { DCHECK } from '../../utils';
|
|
9
|
-
import { CSSMathInvert } from './CSSMathInvert';
|
|
10
|
-
import { CSSNumericValue } from './CSSNumericValue';
|
|
11
|
-
import { CSSNumericValueType } from './CSSNumericValueType';
|
|
12
|
-
import { CSSStyleValueType, UnitType } from '.';
|
|
13
|
-
import { CSSStyleValue } from './CSSStyleValue';
|
|
14
|
-
/**
|
|
15
|
-
* Represents numeric values that can be expressed as a single number plus a
|
|
16
|
-
* unit (or a naked number or percentage).
|
|
17
|
-
* @see https://drafts.css-houdini.org/css-typed-om/#cssunitvalue
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
var CSSUnitValue =
|
|
21
|
-
/** @class */
|
|
22
|
-
function (_super) {
|
|
23
|
-
__extends(CSSUnitValue, _super);
|
|
24
|
-
|
|
25
|
-
function CSSUnitValue(value, unitOrName) {
|
|
26
|
-
if (unitOrName === void 0) {
|
|
27
|
-
unitOrName = UnitType.kNumber;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var _this = this;
|
|
31
|
-
|
|
32
|
-
var unit;
|
|
33
|
-
|
|
34
|
-
if (typeof unitOrName === 'string') {
|
|
35
|
-
unit = CSSUnitValue.unitFromName(unitOrName);
|
|
36
|
-
} else {
|
|
37
|
-
unit = unitOrName;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
DCHECK(CSSUnitValue.isValidUnit(unit));
|
|
41
|
-
_this = _super.call(this, new CSSNumericValueType(unit)) || this;
|
|
42
|
-
_this.unit = unit;
|
|
43
|
-
_this.value = value;
|
|
44
|
-
return _this;
|
|
45
|
-
} // static fromCSSValue(value: CSSNumericLiteralValue) {
|
|
46
|
-
// let unit = value.type;
|
|
47
|
-
// if (unit === UnitType.kInteger) unit = UnitType.kNumber;
|
|
48
|
-
// if (!this.isValidUnit(unit)) return null;
|
|
49
|
-
// return new CSSUnitValue(value.getDoubleValue(), unit);
|
|
50
|
-
// }
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
CSSUnitValue.toCanonicalUnit = function (unit) {
|
|
54
|
-
return this.canonicalUnitTypeForCategory(this.unitTypeToUnitCategory(unit));
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
CSSUnitValue.toCanonicalUnitIfPossible = function (unit) {
|
|
58
|
-
var canonical_unit = this.toCanonicalUnit(unit);
|
|
59
|
-
if (canonical_unit === UnitType.kUnknown) return unit;
|
|
60
|
-
return canonical_unit;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
CSSUnitValue.formatInfinityOrNaN = function (number, suffix) {
|
|
64
|
-
if (suffix === void 0) {
|
|
65
|
-
suffix = '';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
var result = '';
|
|
69
|
-
|
|
70
|
-
if (!Number.isFinite(number)) {
|
|
71
|
-
if (number > 0) result = 'infinity';else result = '-infinity';
|
|
72
|
-
} else {
|
|
73
|
-
DCHECK(Number.isNaN(number));
|
|
74
|
-
result = 'NaN';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return result += suffix;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
CSSUnitValue.formatNumber = function (number, suffix) {
|
|
81
|
-
if (suffix === void 0) {
|
|
82
|
-
suffix = '';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return number + suffix;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
CSSUnitValue.prototype.clone = function () {
|
|
89
|
-
return new CSSUnitValue(this.value, this.unit);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
CSSUnitValue.prototype.convertTo = function (target_unit) {
|
|
93
|
-
if (this.unit === target_unit) {
|
|
94
|
-
return new CSSUnitValue(this.value, this.unit);
|
|
95
|
-
} // Instead of defining the scale factors for every unit to every other unit,
|
|
96
|
-
// we simply convert to the canonical unit and back since we already have
|
|
97
|
-
// the scale factors for canonical units.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
var canonical_unit = CSSUnitValue.toCanonicalUnit(this.unit);
|
|
101
|
-
|
|
102
|
-
if (canonical_unit !== CSSUnitValue.toCanonicalUnit(target_unit) || canonical_unit === UnitType.kUnknown) {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
var scale_factor = CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit) / CSSStyleValue.conversionToCanonicalUnitsScaleFactor(target_unit);
|
|
107
|
-
return new CSSUnitValue(this.value * scale_factor, target_unit);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
CSSUnitValue.prototype.equals = function (other) {
|
|
111
|
-
var other_unit_value = other;
|
|
112
|
-
return this.value === other_unit_value.value && this.unit === other_unit_value.unit;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
CSSUnitValue.prototype.getType = function () {
|
|
116
|
-
return CSSStyleValueType.kUnitType;
|
|
117
|
-
}; // toCSSValue() {
|
|
118
|
-
// return new CSSNumericLiteralValue(this.value, this.unit);
|
|
119
|
-
// }
|
|
120
|
-
// // const CSSPrimitiveValue* ToCSSValueWithProperty(CSSPropertyID) const final;
|
|
121
|
-
// toCalcExpressionNode() {
|
|
122
|
-
// return CSSMathExpressionNumericLiteral.create(
|
|
123
|
-
// new CSSNumericLiteralValue(this.value, this.unit),
|
|
124
|
-
// );
|
|
125
|
-
// }
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
CSSUnitValue.prototype.sumValue = function () {
|
|
129
|
-
var sum = [];
|
|
130
|
-
var unit_map = {};
|
|
131
|
-
|
|
132
|
-
if (this.unit !== UnitType.kNumber) {
|
|
133
|
-
unit_map[CSSUnitValue.toCanonicalUnitIfPossible(this.unit)] = 1;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
sum.push({
|
|
137
|
-
value: this.value * CSSStyleValue.conversionToCanonicalUnitsScaleFactor(this.unit),
|
|
138
|
-
units: unit_map
|
|
139
|
-
});
|
|
140
|
-
return sum;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
CSSUnitValue.prototype.negate = function () {
|
|
144
|
-
return new CSSUnitValue(-this.value, this.unit);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
CSSUnitValue.prototype.invert = function () {
|
|
148
|
-
if (this.unit === UnitType.kNumber) {
|
|
149
|
-
if (this.value === 0) return null;
|
|
150
|
-
return new CSSUnitValue(1.0 / this.value, this.unit);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return CSSMathInvert.create(this);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
CSSUnitValue.prototype.buildCSSText = function (n, p, result) {
|
|
157
|
-
var text;
|
|
158
|
-
|
|
159
|
-
switch (this.unit) {
|
|
160
|
-
case UnitType.kUnknown:
|
|
161
|
-
// FIXME
|
|
162
|
-
break;
|
|
163
|
-
|
|
164
|
-
case UnitType.kInteger:
|
|
165
|
-
text = Number(this.value).toFixed(0);
|
|
166
|
-
break;
|
|
167
|
-
|
|
168
|
-
case UnitType.kNumber:
|
|
169
|
-
case UnitType.kPercentage:
|
|
170
|
-
case UnitType.kEms:
|
|
171
|
-
case UnitType.kQuirkyEms:
|
|
172
|
-
case UnitType.kExs:
|
|
173
|
-
case UnitType.kRems:
|
|
174
|
-
case UnitType.kChs:
|
|
175
|
-
case UnitType.kPixels:
|
|
176
|
-
case UnitType.kCentimeters:
|
|
177
|
-
case UnitType.kDotsPerPixel:
|
|
178
|
-
case UnitType.kDotsPerInch:
|
|
179
|
-
case UnitType.kDotsPerCentimeter:
|
|
180
|
-
case UnitType.kMillimeters:
|
|
181
|
-
case UnitType.kQuarterMillimeters:
|
|
182
|
-
case UnitType.kInches:
|
|
183
|
-
case UnitType.kPoints:
|
|
184
|
-
case UnitType.kPicas:
|
|
185
|
-
case UnitType.kUserUnits:
|
|
186
|
-
case UnitType.kDegrees:
|
|
187
|
-
case UnitType.kRadians:
|
|
188
|
-
case UnitType.kGradians:
|
|
189
|
-
case UnitType.kMilliseconds:
|
|
190
|
-
case UnitType.kSeconds:
|
|
191
|
-
case UnitType.kHertz:
|
|
192
|
-
case UnitType.kKilohertz:
|
|
193
|
-
case UnitType.kTurns:
|
|
194
|
-
case UnitType.kFraction:
|
|
195
|
-
case UnitType.kViewportWidth:
|
|
196
|
-
case UnitType.kViewportHeight:
|
|
197
|
-
case UnitType.kViewportInlineSize:
|
|
198
|
-
case UnitType.kViewportBlockSize:
|
|
199
|
-
case UnitType.kViewportMin:
|
|
200
|
-
case UnitType.kViewportMax:
|
|
201
|
-
case UnitType.kSmallViewportWidth:
|
|
202
|
-
case UnitType.kSmallViewportHeight:
|
|
203
|
-
case UnitType.kSmallViewportInlineSize:
|
|
204
|
-
case UnitType.kSmallViewportBlockSize:
|
|
205
|
-
case UnitType.kSmallViewportMin:
|
|
206
|
-
case UnitType.kSmallViewportMax:
|
|
207
|
-
case UnitType.kLargeViewportWidth:
|
|
208
|
-
case UnitType.kLargeViewportHeight:
|
|
209
|
-
case UnitType.kLargeViewportInlineSize:
|
|
210
|
-
case UnitType.kLargeViewportBlockSize:
|
|
211
|
-
case UnitType.kLargeViewportMin:
|
|
212
|
-
case UnitType.kLargeViewportMax:
|
|
213
|
-
case UnitType.kDynamicViewportWidth:
|
|
214
|
-
case UnitType.kDynamicViewportHeight:
|
|
215
|
-
case UnitType.kDynamicViewportInlineSize:
|
|
216
|
-
case UnitType.kDynamicViewportBlockSize:
|
|
217
|
-
case UnitType.kDynamicViewportMin:
|
|
218
|
-
case UnitType.kDynamicViewportMax:
|
|
219
|
-
case UnitType.kContainerWidth:
|
|
220
|
-
case UnitType.kContainerHeight:
|
|
221
|
-
case UnitType.kContainerInlineSize:
|
|
222
|
-
case UnitType.kContainerBlockSize:
|
|
223
|
-
case UnitType.kContainerMin:
|
|
224
|
-
case UnitType.kContainerMax:
|
|
225
|
-
{
|
|
226
|
-
var kMinInteger = -999999;
|
|
227
|
-
var kMaxInteger = 999999;
|
|
228
|
-
var value = this.value;
|
|
229
|
-
var unit = CSSUnitValue.unitTypeToString(this.unit);
|
|
230
|
-
|
|
231
|
-
if (value < kMinInteger || value > kMaxInteger) {
|
|
232
|
-
var unit_1 = CSSUnitValue.unitTypeToString(this.unit);
|
|
233
|
-
|
|
234
|
-
if (!Number.isFinite(value) || Number.isNaN(value)) {
|
|
235
|
-
text = CSSUnitValue.formatInfinityOrNaN(value, unit_1);
|
|
236
|
-
} else {
|
|
237
|
-
text = CSSUnitValue.formatNumber(value, unit_1);
|
|
238
|
-
}
|
|
239
|
-
} else {
|
|
240
|
-
text = "".concat(value).concat(unit);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
result += text;
|
|
246
|
-
return result;
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
return CSSUnitValue;
|
|
250
|
-
}(CSSNumericValue);
|
|
251
|
-
|
|
252
|
-
export { CSSUnitValue };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CSSMathValue } from './CSSMathValue';
|
|
2
|
-
import type { CSSNumericSumValue, CSSNumericValue } from '.';
|
|
3
|
-
import { CSSNumericValueType, CSSStyleValueType, Nested, ParenLess } from '.';
|
|
4
|
-
export declare class CSSMathInvert extends CSSMathValue {
|
|
5
|
-
private value;
|
|
6
|
-
static create(value: CSSNumericValue): CSSMathInvert;
|
|
7
|
-
constructor(value: CSSNumericValue, type: CSSNumericValueType);
|
|
8
|
-
operator: string;
|
|
9
|
-
clone(): CSSMathInvert;
|
|
10
|
-
getType(): CSSStyleValueType;
|
|
11
|
-
equals(other: CSSNumericValue): any;
|
|
12
|
-
sumValue(): CSSNumericSumValue;
|
|
13
|
-
buildCSSText(nested: Nested, paren_less: ParenLess, result: string): string;
|
|
14
|
-
}
|