@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,5 +1,4 @@
1
1
  import type { CSSNumericSumValue, UnitMap } from './CSSNumericSumValue';
2
- import { CSSNumericValueType } from './CSSNumericValueType';
3
2
  import { CSSStyleValue, CSSStyleValueType } from './CSSStyleValue';
4
3
  import { Nested, ParenLess, UnitType } from './types';
5
4
  export declare type CSSNumberish = number | CSSNumericValue;
@@ -14,6 +13,38 @@ interface CSSNumericType {
14
13
  percent: number;
15
14
  percentHint: CSSNumericBaseType;
16
15
  }
16
+ export declare enum BaseType {
17
+ kLength = 0,
18
+ kAngle = 1,
19
+ kTime = 2,
20
+ kFrequency = 3,
21
+ kResolution = 4,
22
+ kFlex = 5,
23
+ kPercent = 6,
24
+ kNumBaseTypes = 7
25
+ }
26
+ export declare function unitTypeToBaseType(unit: UnitType): BaseType.kLength | BaseType.kAngle | BaseType.kTime | BaseType.kFrequency | BaseType.kResolution | BaseType.kFlex | BaseType.kPercent;
27
+ export declare function baseTypeToString(baseType: BaseType): "" | "percent" | "length" | "angle" | "time" | "frequency" | "resolution" | "flex";
28
+ export declare class CSSNumericValueType {
29
+ private exponents;
30
+ private numNonZeroEntries;
31
+ percentHint: BaseType;
32
+ hasPercentHint: boolean;
33
+ constructor(unit?: UnitType, exponent?: number);
34
+ applyPercentHint(hint: BaseType): void;
35
+ hasNonZeroEntries(): boolean;
36
+ isOnlyNonZeroEntry(baseType: BaseType, value: number): boolean;
37
+ exponent(type: BaseType): number;
38
+ setExponent(type: BaseType, newValue: number): void;
39
+ static negateExponents(type: CSSNumericValueType): CSSNumericValueType;
40
+ matchesBaseType(baseType: BaseType): boolean;
41
+ matchesPercentage(): boolean;
42
+ matchesBaseTypePercentage(baseType: BaseType): boolean;
43
+ matchesNumber(): boolean;
44
+ matchesNumberPercentage(): boolean;
45
+ static add(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
46
+ static multiply(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
47
+ }
17
48
  /**
18
49
  * CSSNumericValue is the base class for numeric and length typed CSS Values.
19
50
  * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
@@ -176,4 +207,6 @@ export declare class CSSMathProduct extends CSSMathVariadic {
176
207
  sumValue(): CSSNumericSumValue;
177
208
  buildCSSText(nested: Nested, paren_less: ParenLess, result: string): string;
178
209
  }
210
+ export declare const Opx: CSSUnitValue;
211
+ export declare const Odeg: CSSUnitValue;
179
212
  export {};
@@ -1,9 +1,265 @@
1
1
  import { __assign, __extends, __read, __spreadArray, __values } from "tslib";
2
- import { DCHECK, DCHECK_NE } from '../../utils';
2
+ import { DCHECK, DCHECK_EQ, DCHECK_NE } from '../../utils';
3
3
  import { CSSMathOperator } from './CSSMathOperator';
4
- import { BaseType, baseTypeToString, CSSNumericValueType } from './CSSNumericValueType';
5
4
  import { CSSStyleValue, CSSStyleValueType } from './CSSStyleValue';
6
- import { Nested, ParenLess, UnitType } from './types';
5
+ import { Nested, ParenLess, UnitType } from './types'; // https://drafts.css-houdini.org/css-typed-om/#enumdef-cssnumericbasetype
6
+
7
+ export var BaseType;
8
+
9
+ (function (BaseType) {
10
+ BaseType[BaseType["kLength"] = 0] = "kLength";
11
+ BaseType[BaseType["kAngle"] = 1] = "kAngle";
12
+ BaseType[BaseType["kTime"] = 2] = "kTime";
13
+ BaseType[BaseType["kFrequency"] = 3] = "kFrequency";
14
+ BaseType[BaseType["kResolution"] = 4] = "kResolution";
15
+ BaseType[BaseType["kFlex"] = 5] = "kFlex";
16
+ BaseType[BaseType["kPercent"] = 6] = "kPercent";
17
+ BaseType[BaseType["kNumBaseTypes"] = 7] = "kNumBaseTypes";
18
+ })(BaseType || (BaseType = {}));
19
+
20
+ export function unitTypeToBaseType(unit) {
21
+ DCHECK_NE(unit, UnitType.kNumber);
22
+
23
+ switch (unit) {
24
+ case UnitType.kEms:
25
+ case UnitType.kExs:
26
+ case UnitType.kPixels:
27
+ case UnitType.kCentimeters:
28
+ case UnitType.kMillimeters:
29
+ case UnitType.kQuarterMillimeters:
30
+ case UnitType.kInches:
31
+ case UnitType.kPoints:
32
+ case UnitType.kPicas:
33
+ case UnitType.kUserUnits:
34
+ case UnitType.kViewportWidth:
35
+ case UnitType.kViewportHeight:
36
+ case UnitType.kViewportInlineSize:
37
+ case UnitType.kViewportBlockSize:
38
+ case UnitType.kViewportMin:
39
+ case UnitType.kViewportMax:
40
+ case UnitType.kSmallViewportWidth:
41
+ case UnitType.kSmallViewportHeight:
42
+ case UnitType.kSmallViewportInlineSize:
43
+ case UnitType.kSmallViewportBlockSize:
44
+ case UnitType.kSmallViewportMin:
45
+ case UnitType.kSmallViewportMax:
46
+ case UnitType.kLargeViewportWidth:
47
+ case UnitType.kLargeViewportHeight:
48
+ case UnitType.kLargeViewportInlineSize:
49
+ case UnitType.kLargeViewportBlockSize:
50
+ case UnitType.kLargeViewportMin:
51
+ case UnitType.kLargeViewportMax:
52
+ case UnitType.kDynamicViewportWidth:
53
+ case UnitType.kDynamicViewportHeight:
54
+ case UnitType.kDynamicViewportInlineSize:
55
+ case UnitType.kDynamicViewportBlockSize:
56
+ case UnitType.kDynamicViewportMin:
57
+ case UnitType.kDynamicViewportMax:
58
+ case UnitType.kContainerWidth:
59
+ case UnitType.kContainerHeight:
60
+ case UnitType.kContainerInlineSize:
61
+ case UnitType.kContainerBlockSize:
62
+ case UnitType.kContainerMin:
63
+ case UnitType.kContainerMax:
64
+ case UnitType.kRems:
65
+ case UnitType.kChs:
66
+ return BaseType.kLength;
67
+
68
+ case UnitType.kMilliseconds:
69
+ case UnitType.kSeconds:
70
+ return BaseType.kTime;
71
+
72
+ case UnitType.kDegrees:
73
+ case UnitType.kRadians:
74
+ case UnitType.kGradians:
75
+ case UnitType.kTurns:
76
+ return BaseType.kAngle;
77
+
78
+ case UnitType.kHertz:
79
+ case UnitType.kKilohertz:
80
+ return BaseType.kFrequency;
81
+
82
+ case UnitType.kDotsPerPixel:
83
+ case UnitType.kDotsPerInch:
84
+ case UnitType.kDotsPerCentimeter:
85
+ return BaseType.kResolution;
86
+
87
+ case UnitType.kFraction:
88
+ return BaseType.kFlex;
89
+
90
+ case UnitType.kPercentage:
91
+ return BaseType.kPercent;
92
+
93
+ default:
94
+ return BaseType.kLength;
95
+ }
96
+ }
97
+ export function baseTypeToString(baseType) {
98
+ switch (baseType) {
99
+ case BaseType.kLength:
100
+ return 'length';
101
+
102
+ case BaseType.kAngle:
103
+ return 'angle';
104
+
105
+ case BaseType.kTime:
106
+ return 'time';
107
+
108
+ case BaseType.kFrequency:
109
+ return 'frequency';
110
+
111
+ case BaseType.kResolution:
112
+ return 'resolution';
113
+
114
+ case BaseType.kFlex:
115
+ return 'flex';
116
+
117
+ case BaseType.kPercent:
118
+ return 'percent';
119
+
120
+ default:
121
+ break;
122
+ }
123
+
124
+ return '';
125
+ }
126
+
127
+ var CSSNumericValueType =
128
+ /** @class */
129
+ function () {
130
+ function CSSNumericValueType(unit, exponent) {
131
+ if (unit === void 0) {
132
+ unit = UnitType.kNumber;
133
+ }
134
+
135
+ if (exponent === void 0) {
136
+ exponent = 1;
137
+ }
138
+
139
+ this.exponents = [];
140
+ this.numNonZeroEntries = 0;
141
+ this.percentHint = BaseType.kPercent;
142
+ this.hasPercentHint = false;
143
+ this.exponents = new Array(BaseType.kNumBaseTypes).fill(0);
144
+
145
+ if (unit !== UnitType.kNumber) {
146
+ this.setExponent(unitTypeToBaseType(unit), exponent);
147
+ }
148
+ }
149
+
150
+ CSSNumericValueType.prototype.applyPercentHint = function (hint) {
151
+ DCHECK_NE(hint, BaseType.kPercent);
152
+ this.setExponent(hint, this.exponent(hint) + this.exponent(BaseType.kPercent));
153
+ this.setExponent(BaseType.kPercent, 0);
154
+ this.percentHint = hint;
155
+ this.hasPercentHint = true;
156
+ };
157
+
158
+ CSSNumericValueType.prototype.hasNonZeroEntries = function () {
159
+ return this.numNonZeroEntries > 0;
160
+ };
161
+
162
+ CSSNumericValueType.prototype.isOnlyNonZeroEntry = function (baseType, value) {
163
+ DCHECK_NE(value, 0);
164
+ return this.numNonZeroEntries === 1 && this.exponent(baseType) === value;
165
+ };
166
+
167
+ CSSNumericValueType.prototype.exponent = function (type) {
168
+ return this.exponents[type];
169
+ };
170
+
171
+ CSSNumericValueType.prototype.setExponent = function (type, newValue) {
172
+ var oldValue = this.exponents[type];
173
+
174
+ if (oldValue == 0 && newValue !== 0) {
175
+ this.numNonZeroEntries++;
176
+ } else if (oldValue !== 0 && newValue == 0) {
177
+ this.numNonZeroEntries--;
178
+ }
179
+
180
+ this.exponents[type] = newValue;
181
+ };
182
+
183
+ CSSNumericValueType.negateExponents = function (type) {
184
+ type.exponents.forEach(function (v) {
185
+ return v *= -1;
186
+ });
187
+ return type;
188
+ };
189
+
190
+ CSSNumericValueType.prototype.matchesBaseType = function (baseType) {
191
+ DCHECK_NE(baseType, BaseType.kPercent);
192
+ return this.isOnlyNonZeroEntry(baseType, 1) && !this.hasPercentHint;
193
+ };
194
+
195
+ CSSNumericValueType.prototype.matchesPercentage = function () {
196
+ return this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
197
+ };
198
+
199
+ CSSNumericValueType.prototype.matchesBaseTypePercentage = function (baseType) {
200
+ DCHECK_NE(baseType, BaseType.kPercent);
201
+ return this.isOnlyNonZeroEntry(baseType, 1) || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
202
+ };
203
+
204
+ CSSNumericValueType.prototype.matchesNumber = function () {
205
+ return !this.hasNonZeroEntries() && !this.hasPercentHint;
206
+ };
207
+
208
+ CSSNumericValueType.prototype.matchesNumberPercentage = function () {
209
+ return !this.hasNonZeroEntries() || this.isOnlyNonZeroEntry(BaseType.kPercent, 1);
210
+ };
211
+
212
+ CSSNumericValueType.add = function (type1, type2, error) {
213
+ if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
214
+ error = true;
215
+ return type1;
216
+ }
217
+
218
+ if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
219
+ DCHECK_EQ(type1.percentHint, type2.percentHint); // Match up base types. Try to use the percent hint to match up any
220
+ // differences.
221
+
222
+ for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
223
+ var base_type = i;
224
+
225
+ if (type1.exponents[i] !== type2.exponents[i]) {
226
+ if (base_type !== BaseType.kPercent) {
227
+ type1.applyPercentHint(base_type);
228
+ type2.applyPercentHint(base_type);
229
+ }
230
+
231
+ if (type1.exponents[i] !== type2.exponents[i]) {
232
+ error = true;
233
+ return type1;
234
+ }
235
+ }
236
+ }
237
+
238
+ error = false;
239
+ return type1;
240
+ };
241
+
242
+ CSSNumericValueType.multiply = function (type1, type2, error) {
243
+ if (type1.hasPercentHint && type2.hasPercentHint && type1.percentHint != type2.percentHint) {
244
+ error = true;
245
+ return type1;
246
+ }
247
+
248
+ if (type1.hasPercentHint) type2.applyPercentHint(type1.percentHint);else if (type2.hasPercentHint) type1.applyPercentHint(type2.percentHint);
249
+
250
+ for (var i = 0; i < BaseType.kNumBaseTypes; ++i) {
251
+ var base_type = i;
252
+ type1.setExponent(base_type, type1.exponent(base_type) + type2.exponent(base_type));
253
+ }
254
+
255
+ error = false;
256
+ return type1;
257
+ };
258
+
259
+ return CSSNumericValueType;
260
+ }();
261
+
262
+ export { CSSNumericValueType };
7
263
  /**
8
264
  * CSSNumericValue is the base class for numeric and length typed CSS Values.
9
265
  * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
@@ -1400,4 +1656,6 @@ function (_super) {
1400
1656
  return CSSMathProduct;
1401
1657
  }(CSSMathVariadic);
1402
1658
 
1403
- export { CSSMathProduct };
1659
+ export { CSSMathProduct };
1660
+ export var Opx = new CSSUnitValue(0, 'px');
1661
+ export var Odeg = new CSSUnitValue(0, 'deg');
@@ -12,7 +12,6 @@ export * from './CSSKeywordValue';
12
12
  export * from './CSSMathOperator';
13
13
  export * from './CSSNumericSumValue';
14
14
  export * from './CSSNumericValue';
15
- export * from './CSSNumericValueType';
16
15
  export * from './CSSRGB';
17
16
  export * from './CSSGradientValue';
18
17
  export * from './CSSStyleValue';
@@ -12,7 +12,6 @@ export * from './CSSKeywordValue';
12
12
  export * from './CSSMathOperator';
13
13
  export * from './CSSNumericSumValue';
14
14
  export * from './CSSNumericValue';
15
- export * from './CSSNumericValueType';
16
15
  export * from './CSSRGB';
17
16
  export * from './CSSGradientValue';
18
17
  export * from './CSSStyleValue';
@@ -4,8 +4,6 @@ export interface ParsedTransform {
4
4
  t: string;
5
5
  d: CSSUnitValue[];
6
6
  }
7
- export declare const Opx: CSSUnitValue;
8
- export declare const Odeg: CSSUnitValue;
9
7
  /**
10
8
  * none
11
9
  * scale(1) scale(1, 2)
@@ -1,8 +1,7 @@
1
- import { parseNumber, mergeNumbers, parseAngle, parseLength, parseLengthOrPercentage, mergeDimensions } from './';
2
- import { UnitType, CSSUnitValue } from '../cssom';
1
+ import { UnitType, CSSUnitValue, Opx, Odeg } from '../cssom';
2
+ import { mergeDimensions, parseAngle, parseLength, parseLengthOrPercentage } from './dimension';
3
+ import { mergeNumbers, parseNumber } from './numeric';
3
4
  var _ = null;
4
- export var Opx = new CSSUnitValue(0, 'px');
5
- export var Odeg = new CSSUnitValue(0, 'deg');
6
5
 
7
6
  function cast(pattern) {
8
7
  return function (contents) {
@@ -1,7 +1,7 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { singleton } from 'mana-syringe';
3
- import { CSSKeywordValue } from '../cssom';
4
- import { Opx, Odeg, parseTransform, mergeTransforms } from '../parser';
3
+ import { CSSKeywordValue, Opx, Odeg } from '../cssom';
4
+ import { parseTransform, mergeTransforms } from '../parser';
5
5
  /**
6
6
  * @see /zh/docs/api/animation#支持变换的属性
7
7
  *
@@ -1,5 +1,4 @@
1
1
  import type { CSSNumericSumValue, UnitMap } from './CSSNumericSumValue';
2
- import { CSSNumericValueType } from './CSSNumericValueType';
3
2
  import { CSSStyleValue, CSSStyleValueType } from './CSSStyleValue';
4
3
  import { Nested, ParenLess, UnitType } from './types';
5
4
  export declare type CSSNumberish = number | CSSNumericValue;
@@ -14,6 +13,38 @@ interface CSSNumericType {
14
13
  percent: number;
15
14
  percentHint: CSSNumericBaseType;
16
15
  }
16
+ export declare enum BaseType {
17
+ kLength = 0,
18
+ kAngle = 1,
19
+ kTime = 2,
20
+ kFrequency = 3,
21
+ kResolution = 4,
22
+ kFlex = 5,
23
+ kPercent = 6,
24
+ kNumBaseTypes = 7
25
+ }
26
+ export declare function unitTypeToBaseType(unit: UnitType): BaseType.kLength | BaseType.kAngle | BaseType.kTime | BaseType.kFrequency | BaseType.kResolution | BaseType.kFlex | BaseType.kPercent;
27
+ export declare function baseTypeToString(baseType: BaseType): "" | "percent" | "length" | "angle" | "time" | "frequency" | "resolution" | "flex";
28
+ export declare class CSSNumericValueType {
29
+ private exponents;
30
+ private numNonZeroEntries;
31
+ percentHint: BaseType;
32
+ hasPercentHint: boolean;
33
+ constructor(unit?: UnitType, exponent?: number);
34
+ applyPercentHint(hint: BaseType): void;
35
+ hasNonZeroEntries(): boolean;
36
+ isOnlyNonZeroEntry(baseType: BaseType, value: number): boolean;
37
+ exponent(type: BaseType): number;
38
+ setExponent(type: BaseType, newValue: number): void;
39
+ static negateExponents(type: CSSNumericValueType): CSSNumericValueType;
40
+ matchesBaseType(baseType: BaseType): boolean;
41
+ matchesPercentage(): boolean;
42
+ matchesBaseTypePercentage(baseType: BaseType): boolean;
43
+ matchesNumber(): boolean;
44
+ matchesNumberPercentage(): boolean;
45
+ static add(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
46
+ static multiply(type1: CSSNumericValueType, type2: CSSNumericValueType, error: boolean): CSSNumericValueType;
47
+ }
17
48
  /**
18
49
  * CSSNumericValue is the base class for numeric and length typed CSS Values.
19
50
  * @see https://drafts.css-houdini.org/css-typed-om/#numeric-objects
@@ -176,4 +207,6 @@ export declare class CSSMathProduct extends CSSMathVariadic {
176
207
  sumValue(): CSSNumericSumValue;
177
208
  buildCSSText(nested: Nested, paren_less: ParenLess, result: string): string;
178
209
  }
210
+ export declare const Opx: CSSUnitValue;
211
+ export declare const Odeg: CSSUnitValue;
179
212
  export {};