@antv/g 5.0.23-alpha.2 → 5.0.23-alpha.7

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.
@@ -1,259 +0,0 @@
1
- import { DCHECK_EQ, DCHECK_NE } from '../../utils';
2
- import { UnitType } from './types'; // 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
- import { UnitType } from './types';
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,272 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CSSNumericValueType = exports.BaseType = void 0;
7
- exports.baseTypeToString = baseTypeToString;
8
- exports.unitTypeToBaseType = unitTypeToBaseType;
9
-
10
- var _utils = require("../../utils");
11
-
12
- var _types = require("./types");
13
-
14
- // https://drafts.css-houdini.org/css-typed-om/#enumdef-cssnumericbasetype
15
- var BaseType;
16
- exports.BaseType = BaseType;
17
-
18
- (function (BaseType) {
19
- BaseType[BaseType["kLength"] = 0] = "kLength";
20
- BaseType[BaseType["kAngle"] = 1] = "kAngle";
21
- BaseType[BaseType["kTime"] = 2] = "kTime";
22
- BaseType[BaseType["kFrequency"] = 3] = "kFrequency";
23
- BaseType[BaseType["kResolution"] = 4] = "kResolution";
24
- BaseType[BaseType["kFlex"] = 5] = "kFlex";
25
- BaseType[BaseType["kPercent"] = 6] = "kPercent";
26
- BaseType[BaseType["kNumBaseTypes"] = 7] = "kNumBaseTypes";
27
- })(BaseType || (exports.BaseType = BaseType = {}));
28
-
29
- function unitTypeToBaseType(unit) {
30
- (0, _utils.DCHECK_NE)(unit, _types.UnitType.kNumber);
31
-
32
- switch (unit) {
33
- case _types.UnitType.kEms:
34
- case _types.UnitType.kExs:
35
- case _types.UnitType.kPixels:
36
- case _types.UnitType.kCentimeters:
37
- case _types.UnitType.kMillimeters:
38
- case _types.UnitType.kQuarterMillimeters:
39
- case _types.UnitType.kInches:
40
- case _types.UnitType.kPoints:
41
- case _types.UnitType.kPicas:
42
- case _types.UnitType.kUserUnits:
43
- case _types.UnitType.kViewportWidth:
44
- case _types.UnitType.kViewportHeight:
45
- case _types.UnitType.kViewportInlineSize:
46
- case _types.UnitType.kViewportBlockSize:
47
- case _types.UnitType.kViewportMin:
48
- case _types.UnitType.kViewportMax:
49
- case _types.UnitType.kSmallViewportWidth:
50
- case _types.UnitType.kSmallViewportHeight:
51
- case _types.UnitType.kSmallViewportInlineSize:
52
- case _types.UnitType.kSmallViewportBlockSize:
53
- case _types.UnitType.kSmallViewportMin:
54
- case _types.UnitType.kSmallViewportMax:
55
- case _types.UnitType.kLargeViewportWidth:
56
- case _types.UnitType.kLargeViewportHeight:
57
- case _types.UnitType.kLargeViewportInlineSize:
58
- case _types.UnitType.kLargeViewportBlockSize:
59
- case _types.UnitType.kLargeViewportMin:
60
- case _types.UnitType.kLargeViewportMax:
61
- case _types.UnitType.kDynamicViewportWidth:
62
- case _types.UnitType.kDynamicViewportHeight:
63
- case _types.UnitType.kDynamicViewportInlineSize:
64
- case _types.UnitType.kDynamicViewportBlockSize:
65
- case _types.UnitType.kDynamicViewportMin:
66
- case _types.UnitType.kDynamicViewportMax:
67
- case _types.UnitType.kContainerWidth:
68
- case _types.UnitType.kContainerHeight:
69
- case _types.UnitType.kContainerInlineSize:
70
- case _types.UnitType.kContainerBlockSize:
71
- case _types.UnitType.kContainerMin:
72
- case _types.UnitType.kContainerMax:
73
- case _types.UnitType.kRems:
74
- case _types.UnitType.kChs:
75
- return BaseType.kLength;
76
-
77
- case _types.UnitType.kMilliseconds:
78
- case _types.UnitType.kSeconds:
79
- return BaseType.kTime;
80
-
81
- case _types.UnitType.kDegrees:
82
- case _types.UnitType.kRadians:
83
- case _types.UnitType.kGradians:
84
- case _types.UnitType.kTurns:
85
- return BaseType.kAngle;
86
-
87
- case _types.UnitType.kHertz:
88
- case _types.UnitType.kKilohertz:
89
- return BaseType.kFrequency;
90
-
91
- case _types.UnitType.kDotsPerPixel:
92
- case _types.UnitType.kDotsPerInch:
93
- case _types.UnitType.kDotsPerCentimeter:
94
- return BaseType.kResolution;
95
-
96
- case _types.UnitType.kFraction:
97
- return BaseType.kFlex;
98
-
99
- case _types.UnitType.kPercentage:
100
- return BaseType.kPercent;
101
-
102
- default:
103
- return BaseType.kLength;
104
- }
105
- }
106
-
107
- function baseTypeToString(baseType) {
108
- switch (baseType) {
109
- case BaseType.kLength:
110
- return 'length';
111
-
112
- case BaseType.kAngle:
113
- return 'angle';
114
-
115
- case BaseType.kTime:
116
- return 'time';
117
-
118
- case BaseType.kFrequency:
119
- return 'frequency';
120
-
121
- case BaseType.kResolution:
122
- return 'resolution';
123
-
124
- case BaseType.kFlex:
125
- return 'flex';
126
-
127
- case BaseType.kPercent:
128
- return 'percent';
129
-
130
- default:
131
- break;
132
- }
133
-
134
- return '';
135
- }
136
-
137
- var CSSNumericValueType =
138
- /** @class */
139
- function () {
140
- function CSSNumericValueType(unit, exponent) {
141
- if (unit === void 0) {
142
- unit = _types.UnitType.kNumber;
143
- }
144
-
145
- if (exponent === void 0) {
146
- exponent = 1;
147
- }
148
-
149
- this.exponents = [];
150
- this.numNonZeroEntries = 0;
151
- this.percentHint = BaseType.kPercent;
152
- this.hasPercentHint = false;
153
- this.exponents = new Array(BaseType.kNumBaseTypes).fill(0);
154
-
155
- if (unit !== _types.UnitType.kNumber) {
156
- this.setExponent(unitTypeToBaseType(unit), exponent);
157
- }
158
- }
159
-
160
- CSSNumericValueType.prototype.applyPercentHint = function (hint) {
161
- (0, _utils.DCHECK_NE)(hint, BaseType.kPercent);
162
- this.setExponent(hint, this.exponent(hint) + this.exponent(BaseType.kPercent));
163
- this.setExponent(BaseType.kPercent, 0);
164
- this.percentHint = hint;
165
- this.hasPercentHint = true;
166
- };
167
-
168
- CSSNumericValueType.prototype.hasNonZeroEntries = function () {
169
- return this.numNonZeroEntries > 0;
170
- };
171
-
172
- CSSNumericValueType.prototype.isOnlyNonZeroEntry = function (baseType, value) {
173
- (0, _utils.DCHECK_NE)(value, 0);
174
- return this.numNonZeroEntries === 1 && this.exponent(baseType) === value;
175
- };
176
-
177
- CSSNumericValueType.prototype.exponent = function (type) {
178
- return this.exponents[type];
179
- };
180
-
181
- CSSNumericValueType.prototype.setExponent = function (type, newValue) {
182
- var oldValue = this.exponents[type];
183
-
184
- if (oldValue == 0 && newValue !== 0) {
185
- this.numNonZeroEntries++;
186
- } else if (oldValue !== 0 && newValue == 0) {
187
- this.numNonZeroEntries--;
188
- }
189
-
190
- this.exponents[type] = newValue;
191
- };
192
-
193
- CSSNumericValueType.negateExponents = function (type) {
194
- type.exponents.forEach(function (v) {
195
- return v *= -1;
196
- });
197
- return type;
198
- };
199
-
200
- CSSNumericValueType.prototype.matchesBaseType = function (baseType) {
201
- (0, _utils.DCHECK_NE)(baseType, BaseType.kPercent);
202
- return this.isOnlyNonZeroEntry(baseType, 1) && !this.hasPercentHint;
203
- };
204
-
205
- CSSNumericValueType.prototype.matchesPercentage = function () {
206
- return this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
207
- };
208
-
209
- CSSNumericValueType.prototype.matchesBaseTypePercentage = function (baseType) {
210
- (0, _utils.DCHECK_NE)(baseType, BaseType.kPercent);
211
- return this.isOnlyNonZeroEntry(baseType, 1) || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
212
- };
213
-
214
- CSSNumericValueType.prototype.matchesNumber = function () {
215
- return !this.hasNonZeroEntries() && !this.hasPercentHint;
216
- };
217
-
218
- CSSNumericValueType.prototype.matchesNumberPercentage = function () {
219
- return !this.hasNonZeroEntries() || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
220
- };
221
-
222
- CSSNumericValueType.add = function (type1, type2, error) {
223
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
224
- error = true;
225
- return type1;
226
- }
227
-
228
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
229
- (0, _utils.DCHECK_EQ)(type1.percentHint, type2.percentHint); // Match up base types. Try to use the percent hint to match up any
230
- // differences.
231
-
232
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
233
- var base_type = i;
234
-
235
- if (type1.exponents[i] !== type2.exponents[i]) {
236
- if (base_type !== BaseType.kPercent) {
237
- type1.applyPercentHint(base_type);
238
- type2.applyPercentHint(base_type);
239
- }
240
-
241
- if (type1.exponents[i] !== type2.exponents[i]) {
242
- error = true;
243
- return type1;
244
- }
245
- }
246
- }
247
-
248
- error = false;
249
- return type1;
250
- };
251
-
252
- CSSNumericValueType.multiply = function (type1, type2, error) {
253
- if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
254
- error = true;
255
- return type1;
256
- }
257
-
258
- if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
259
-
260
- for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
261
- var base_type = i;
262
- type1.setExponent(base_type, type1.exponent(base_type) + type2.exponent(base_type));
263
- }
264
-
265
- error = false;
266
- return type1;
267
- };
268
-
269
- return CSSNumericValueType;
270
- }();
271
-
272
- exports.CSSNumericValueType = CSSNumericValueType;