@stylexjs/shared 0.17.4 → 0.18.0

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.
Files changed (145) hide show
  1. package/lib/common-types.d.ts +61 -0
  2. package/lib/common-types.js +1 -0
  3. package/lib/common-types.js.flow +85 -0
  4. package/lib/hash.d.ts +15 -0
  5. package/lib/hash.js +49 -0
  6. package/lib/hash.js.flow +12 -0
  7. package/lib/messages.d.ts +70 -0
  8. package/lib/messages.js +38 -0
  9. package/lib/messages.js.flow +44 -0
  10. package/lib/physical-rtl/generate-ltr.d.ts +15 -0
  11. package/lib/physical-rtl/generate-ltr.js +75 -0
  12. package/lib/physical-rtl/generate-ltr.js.flow +14 -0
  13. package/lib/physical-rtl/generate-rtl.d.ts +15 -0
  14. package/lib/physical-rtl/generate-rtl.js +157 -0
  15. package/lib/physical-rtl/generate-rtl.js.flow +14 -0
  16. package/lib/preprocess-rules/PreRule.d.ts +51 -0
  17. package/lib/preprocess-rules/PreRule.js +79 -0
  18. package/lib/preprocess-rules/PreRule.js.flow +63 -0
  19. package/lib/preprocess-rules/__tests__/PreRule-test.js +33 -0
  20. package/lib/preprocess-rules/__tests__/flatten-raw-style-obj-test.js +196 -0
  21. package/lib/preprocess-rules/application-order.d.ts +186 -0
  22. package/lib/preprocess-rules/application-order.js +195 -0
  23. package/lib/preprocess-rules/application-order.js.flow +141 -0
  24. package/lib/preprocess-rules/basic-validation.d.ts +13 -0
  25. package/lib/preprocess-rules/basic-validation.js +70 -0
  26. package/lib/preprocess-rules/basic-validation.js.flow +13 -0
  27. package/lib/preprocess-rules/flatten-raw-style-obj.d.ts +20 -0
  28. package/lib/preprocess-rules/flatten-raw-style-obj.js +100 -0
  29. package/lib/preprocess-rules/flatten-raw-style-obj.js.flow +23 -0
  30. package/lib/preprocess-rules/index.d.ts +21 -0
  31. package/lib/preprocess-rules/index.js +45 -0
  32. package/lib/preprocess-rules/index.js.flow +23 -0
  33. package/lib/preprocess-rules/legacy-expand-shorthands.d.ts +170 -0
  34. package/lib/preprocess-rules/legacy-expand-shorthands.js +222 -0
  35. package/lib/preprocess-rules/legacy-expand-shorthands.js.flow +142 -0
  36. package/lib/preprocess-rules/property-specificity.d.ts +79 -0
  37. package/lib/preprocess-rules/property-specificity.js +107 -0
  38. package/lib/preprocess-rules/property-specificity.js.flow +93 -0
  39. package/lib/stylex-consts-utils.d.ts +11 -0
  40. package/lib/stylex-consts-utils.js +1 -0
  41. package/lib/stylex-consts-utils.js.flow +14 -0
  42. package/lib/stylex-create-theme.d.ts +26 -0
  43. package/lib/stylex-create-theme.js +53 -0
  44. package/lib/stylex-create-theme.js.flow +19 -0
  45. package/lib/stylex-create.d.ts +27 -0
  46. package/lib/stylex-create.js +60 -0
  47. package/lib/stylex-create.js.flow +37 -0
  48. package/lib/stylex-defaultMarker.d.ts +14 -0
  49. package/lib/stylex-defaultMarker.js +14 -0
  50. package/lib/stylex-defaultMarker.js.flow +13 -0
  51. package/lib/stylex-define-consts.d.ts +23 -0
  52. package/lib/stylex-define-consts.js +40 -0
  53. package/lib/stylex-define-consts.js.flow +19 -0
  54. package/lib/stylex-define-vars.d.ts +28 -0
  55. package/lib/stylex-define-vars.js +90 -0
  56. package/lib/stylex-define-vars.js.flow +26 -0
  57. package/lib/stylex-first-that-works.d.ts +13 -0
  58. package/lib/stylex-first-that-works.js +23 -0
  59. package/lib/stylex-first-that-works.js.flow +12 -0
  60. package/lib/stylex-keyframes.d.ts +17 -0
  61. package/lib/stylex-keyframes.js +46 -0
  62. package/lib/stylex-keyframes.js.flow +20 -0
  63. package/lib/stylex-position-try.d.ts +15 -0
  64. package/lib/stylex-position-try.js +47 -0
  65. package/lib/stylex-position-try.js.flow +18 -0
  66. package/lib/stylex-vars-utils.d.ts +27 -0
  67. package/lib/stylex-vars-utils.js +66 -0
  68. package/lib/stylex-vars-utils.js.flow +31 -0
  69. package/lib/stylex-view-transition-class.d.ts +22 -0
  70. package/lib/stylex-view-transition-class.js +42 -0
  71. package/lib/stylex-view-transition-class.js.flow +23 -0
  72. package/lib/types/__tests__/stylex-types-test.js +178 -0
  73. package/lib/types/index.d.ts +254 -0
  74. package/lib/types/index.js +147 -0
  75. package/lib/types/index.js.flow +280 -0
  76. package/lib/utils/Rule.d.ts +58 -0
  77. package/lib/utils/Rule.js +50 -0
  78. package/lib/utils/Rule.js.flow +64 -0
  79. package/lib/utils/__tests__/convert-to-className-test.js +85 -0
  80. package/lib/utils/__tests__/property-priorities-test.js +33 -0
  81. package/lib/utils/__tests__/split-css-value-test.js +26 -0
  82. package/lib/utils/__tests__/transform-value-test.js +36 -0
  83. package/lib/utils/convert-to-className.d.ts +21 -0
  84. package/lib/utils/convert-to-className.js +61 -0
  85. package/lib/utils/convert-to-className.js.flow +29 -0
  86. package/lib/utils/css-properties.js.flow +155 -0
  87. package/lib/utils/dashify.d.ts +11 -0
  88. package/lib/utils/dashify.js +9 -0
  89. package/lib/utils/dashify.js.flow +10 -0
  90. package/lib/utils/default-options.d.ts +12 -0
  91. package/lib/utils/default-options.js +26 -0
  92. package/lib/utils/default-options.js.flow +12 -0
  93. package/lib/utils/file-based-identifier.d.ts +15 -0
  94. package/lib/utils/file-based-identifier.js +13 -0
  95. package/lib/utils/file-based-identifier.js.flow +14 -0
  96. package/lib/utils/generate-css-rule.d.ts +19 -0
  97. package/lib/utils/generate-css-rule.js +37 -0
  98. package/lib/utils/generate-css-rule.js.flow +19 -0
  99. package/lib/utils/normalize-value.d.ts +16 -0
  100. package/lib/utils/normalize-value.js +27 -0
  101. package/lib/utils/normalize-value.js.flow +16 -0
  102. package/lib/utils/normalizers/convert-camel-case-values.d.ts +14 -0
  103. package/lib/utils/normalizers/convert-camel-case-values.js +23 -0
  104. package/lib/utils/normalizers/convert-camel-case-values.js.flow +13 -0
  105. package/lib/utils/normalizers/detect-unclosed-fns.d.ts +17 -0
  106. package/lib/utils/normalizers/detect-unclosed-fns.js +16 -0
  107. package/lib/utils/normalizers/detect-unclosed-fns.js.flow +16 -0
  108. package/lib/utils/normalizers/font-size-px-to-rem.d.ts +19 -0
  109. package/lib/utils/normalizers/font-size-px-to-rem.js +24 -0
  110. package/lib/utils/normalizers/font-size-px-to-rem.js.flow +18 -0
  111. package/lib/utils/normalizers/leading-zero.d.ts +17 -0
  112. package/lib/utils/normalizers/leading-zero.js +24 -0
  113. package/lib/utils/normalizers/leading-zero.js.flow +16 -0
  114. package/lib/utils/normalizers/quotes.d.ts +18 -0
  115. package/lib/utils/normalizers/quotes.js +17 -0
  116. package/lib/utils/normalizers/quotes.js.flow +17 -0
  117. package/lib/utils/normalizers/timings.d.ts +18 -0
  118. package/lib/utils/normalizers/timings.js +25 -0
  119. package/lib/utils/normalizers/timings.js.flow +17 -0
  120. package/lib/utils/normalizers/whitespace.d.ts +19 -0
  121. package/lib/utils/normalizers/whitespace.js +54 -0
  122. package/lib/utils/normalizers/whitespace.js.flow +18 -0
  123. package/lib/utils/normalizers/zero-dimensions.d.ts +19 -0
  124. package/lib/utils/normalizers/zero-dimensions.js +45 -0
  125. package/lib/utils/normalizers/zero-dimensions.js.flow +18 -0
  126. package/lib/utils/object-utils.d.ts +68 -0
  127. package/lib/utils/object-utils.js +89 -0
  128. package/lib/utils/object-utils.js.flow +78 -0
  129. package/lib/utils/property-priorities.js +22 -1
  130. package/lib/utils/rule-utils.d.ts +17 -0
  131. package/lib/utils/rule-utils.js +41 -0
  132. package/lib/utils/rule-utils.js.flow +16 -0
  133. package/lib/utils/split-css-value.d.ts +14 -0
  134. package/lib/utils/split-css-value.js +41 -0
  135. package/lib/utils/split-css-value.js.flow +15 -0
  136. package/lib/utils/transform-value.d.ts +24 -0
  137. package/lib/utils/transform-value.js +50 -0
  138. package/lib/utils/transform-value.js.flow +25 -0
  139. package/lib/validate.d.ts +12 -0
  140. package/lib/validate.js +19 -0
  141. package/lib/validate.js.flow +14 -0
  142. package/lib/when/when.d.ts +67 -0
  143. package/lib/when/when.js +71 -0
  144. package/lib/when/when.js.flow +73 -0
  145. package/package.json +1 -1
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = styleXViewTransitionClass;
7
+ var _hash = _interopRequireDefault(require("./hash"));
8
+ var _index = _interopRequireDefault(require("./preprocess-rules/index"));
9
+ var _objectUtils = require("./utils/object-utils");
10
+ var _defaultOptions = require("./utils/default-options");
11
+ var _transformValue = _interopRequireDefault(require("./utils/transform-value"));
12
+ var _dashify = _interopRequireDefault(require("./utils/dashify"));
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ function styleXViewTransitionClass(styles, options = _defaultOptions.defaultOptions) {
15
+ const {
16
+ classNamePrefix = 'x'
17
+ } = options;
18
+ const preprocessedObject = (0, _objectUtils.objMap)(styles, style => _objectUtils.Pipe.create(style).pipe(style => preprocessProperties(style, options)).pipe(x => (0, _objectUtils.objMapKeys)(x, _dashify.default)).pipe(x => (0, _objectUtils.objMap)(x, (value, key) => (0, _transformValue.default)(key, value, options))).done());
19
+ const expandedObject = (0, _objectUtils.objMapKeys)(preprocessedObject, k => `::view-transition-${(0, _dashify.default)(k)}`);
20
+ const styleStrings = (0, _objectUtils.objMap)(expandedObject, constructViewTransitionClassStyleStr);
21
+ const viewTransitionClassName = classNamePrefix + (0, _hash.default)(constructViewTransitionClassStyleStr(styleStrings));
22
+ const style = constructFinalViewTransitionCSSStr(styleStrings, viewTransitionClassName);
23
+ return [viewTransitionClassName, {
24
+ ltr: style,
25
+ rtl: null,
26
+ priority: 1
27
+ }];
28
+ }
29
+ function preprocessProperties(styles, options) {
30
+ return (0, _objectUtils.objFromEntries)((0, _objectUtils.objEntries)(styles).flatMap(pair => (0, _index.default)(pair, options).map(([key, value]) => {
31
+ if (typeof value === 'string' || typeof value === 'number') {
32
+ return [key, value];
33
+ }
34
+ return null;
35
+ }).filter(Boolean)).filter(([_key, value]) => value != null));
36
+ }
37
+ function constructViewTransitionClassStyleStr(style) {
38
+ return (0, _objectUtils.objEntries)(style).map(([k, v]) => `${k}:${v};`).join('');
39
+ }
40
+ function constructFinalViewTransitionCSSStr(styles, className) {
41
+ return (0, _objectUtils.objEntries)(styles).map(([k, v]) => `${k}(*.${className}){${v}}`).join('');
42
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type { InjectableStyle, StyleXOptions } from './common-types';
11
+
12
+ type StyleValue = { +[string]: string | number };
13
+ type StyleObj = {
14
+ group?: StyleValue,
15
+ imagePair?: StyleValue,
16
+ old?: StyleValue,
17
+ new?: StyleValue,
18
+ };
19
+
20
+ declare export default function styleXViewTransitionClass(
21
+ styles: StyleObj,
22
+ options?: StyleXOptions,
23
+ ): [string, InjectableStyle];
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ var t = _interopRequireWildcard(require("../index"));
4
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
5
+ describe('stylex-types-test', () => {
6
+ describe('class methods', () => {
7
+ test('angle', () => {
8
+ const obj = t.Angle.create('45deg');
9
+ expect(obj.value).toEqual('45deg');
10
+ expect(obj.syntax).toEqual('<angle>');
11
+ });
12
+ test('color', () => {
13
+ const value = {
14
+ default: 'red'
15
+ };
16
+ const obj = t.Color.create(value);
17
+ expect(obj.value).toEqual(value);
18
+ expect(obj.syntax).toEqual('<color>');
19
+ });
20
+ test('image', () => {
21
+ const value = 'url(#image)';
22
+ const obj = t.Image.create(value);
23
+ expect(obj.value).toEqual(value);
24
+ expect(obj.syntax).toEqual('<image>');
25
+ });
26
+ test('integer', () => {
27
+ const value = 1;
28
+ const obj = t.Integer.create(value);
29
+ expect(obj.value).toEqual('1');
30
+ expect(obj.syntax).toEqual('<integer>');
31
+ });
32
+ test('length', () => {
33
+ const value = '1px';
34
+ const obj = t.Length.create(value);
35
+ expect(obj.value).toEqual(value);
36
+ expect(obj.syntax).toEqual('<length>');
37
+ const obj2 = t.Length.create(1);
38
+ expect(obj2.value).toEqual(value);
39
+ expect(obj2.syntax).toEqual('<length>');
40
+ });
41
+ test('percentage', () => {
42
+ const value = '50%';
43
+ const obj = t.Percentage.create(value);
44
+ expect(obj.value).toEqual(value);
45
+ expect(obj.syntax).toEqual('<percentage>');
46
+ const obj2 = t.Percentage.create(0.5);
47
+ expect(obj2.value).toEqual(value);
48
+ expect(obj2.syntax).toEqual('<percentage>');
49
+ });
50
+ test('num', () => {
51
+ const value = 1;
52
+ const obj = t.Num.create(value);
53
+ expect(obj.value).toEqual('1');
54
+ expect(obj.syntax).toEqual('<number>');
55
+ });
56
+ test('integer', () => {
57
+ const value = 1;
58
+ const obj = t.Integer.create(value);
59
+ expect(obj.value).toEqual('1');
60
+ expect(obj.syntax).toEqual('<integer>');
61
+ });
62
+ test('resolution', () => {
63
+ const value = '96dpi';
64
+ const obj = t.Resolution.create(value);
65
+ expect(obj.value).toEqual(value);
66
+ expect(obj.syntax).toEqual('<resolution>');
67
+ });
68
+ test('time', () => {
69
+ const value = '1s';
70
+ const obj = t.Time.create(value);
71
+ expect(obj.value).toEqual(value);
72
+ expect(obj.syntax).toEqual('<time>');
73
+ });
74
+ test('transformFunction', () => {
75
+ const value = 'translateX(10px)';
76
+ const obj = t.TransformFunction.create(value);
77
+ expect(obj.value).toEqual(value);
78
+ expect(obj.syntax).toEqual('<transform-function>');
79
+ });
80
+ test('transformList', () => {
81
+ const value = 'translateX(10px)';
82
+ const obj = t.TransformList.create(value);
83
+ expect(obj.value).toEqual(value);
84
+ expect(obj.syntax).toEqual('<transform-list>');
85
+ });
86
+ test('url', () => {
87
+ const value = 'url(#image)';
88
+ const obj = t.Url.create(value);
89
+ expect(obj.value).toEqual(value);
90
+ });
91
+ });
92
+ describe('standalone factory functions', () => {
93
+ test('angle', () => {
94
+ const obj = t.angle('45deg');
95
+ expect(obj.value).toEqual('45deg');
96
+ expect(obj.syntax).toEqual('<angle>');
97
+ });
98
+ test('color', () => {
99
+ const value = {
100
+ default: 'red'
101
+ };
102
+ const obj = t.color(value);
103
+ expect(obj.value).toEqual(value);
104
+ expect(obj.syntax).toEqual('<color>');
105
+ });
106
+ test('image', () => {
107
+ const value = 'url(#image)';
108
+ const obj = t.image(value);
109
+ expect(obj.value).toEqual(value);
110
+ expect(obj.syntax).toEqual('<image>');
111
+ });
112
+ test('integer', () => {
113
+ const value = 1;
114
+ const obj = t.integer(value);
115
+ expect(obj.value).toEqual('1');
116
+ expect(obj.syntax).toEqual('<integer>');
117
+ });
118
+ test('length', () => {
119
+ const value = '1px';
120
+ const obj = t.length(value);
121
+ expect(obj.value).toEqual(value);
122
+ expect(obj.syntax).toEqual('<length>');
123
+ const obj2 = t.length(1);
124
+ expect(obj2.value).toEqual(value);
125
+ expect(obj2.syntax).toEqual('<length>');
126
+ });
127
+ test('percentage', () => {
128
+ const value = '50%';
129
+ const obj = t.percentage(value);
130
+ expect(obj.value).toEqual(value);
131
+ expect(obj.syntax).toEqual('<percentage>');
132
+ const obj2 = t.percentage(0.5);
133
+ expect(obj2.value).toEqual(value);
134
+ expect(obj2.syntax).toEqual('<percentage>');
135
+ });
136
+ test('num', () => {
137
+ const value = 1;
138
+ const obj = t.number(value);
139
+ expect(obj.value).toEqual('1');
140
+ expect(obj.syntax).toEqual('<number>');
141
+ });
142
+ test('integer', () => {
143
+ const value = 1;
144
+ const obj = t.integer(value);
145
+ expect(obj.value).toEqual('1');
146
+ expect(obj.syntax).toEqual('<integer>');
147
+ });
148
+ test('resolution', () => {
149
+ const value = '96dpi';
150
+ const obj = t.resolution(value);
151
+ expect(obj.value).toEqual(value);
152
+ expect(obj.syntax).toEqual('<resolution>');
153
+ });
154
+ test('time', () => {
155
+ const value = '1s';
156
+ const obj = t.time(value);
157
+ expect(obj.value).toEqual(value);
158
+ expect(obj.syntax).toEqual('<time>');
159
+ });
160
+ test('transformFunction', () => {
161
+ const value = 'translateX(10px)';
162
+ const obj = t.transformFunction(value);
163
+ expect(obj.value).toEqual(value);
164
+ expect(obj.syntax).toEqual('<transform-function>');
165
+ });
166
+ test('transformList', () => {
167
+ const value = 'translateX(10px)';
168
+ const obj = t.transformList(value);
169
+ expect(obj.value).toEqual(value);
170
+ expect(obj.syntax).toEqual('<transform-list>');
171
+ });
172
+ test('url', () => {
173
+ const value = 'url(#image)';
174
+ const obj = t.url(value);
175
+ expect(obj.value).toEqual(value);
176
+ });
177
+ });
178
+ });
@@ -0,0 +1,254 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
10
+ /* eslint-disable no-unused-vars, no-redeclare */
11
+ type NestedWithNumbers =
12
+ | number
13
+ | string
14
+ | Readonly<{
15
+ default: NestedWithNumbers;
16
+ [$$Key$$: string]: NestedWithNumbers;
17
+ }>;
18
+ type ValueWithDefault =
19
+ | string
20
+ | Readonly<{
21
+ default: ValueWithDefault;
22
+ [$$Key$$: string]: ValueWithDefault;
23
+ }>;
24
+ type CSSSyntax =
25
+ | '*'
26
+ | '<length>'
27
+ | '<number>'
28
+ | '<percentage>'
29
+ | '<length-percentage>'
30
+ | '<color>'
31
+ | '<image>'
32
+ | '<url>'
33
+ | '<integer>'
34
+ | '<angle>'
35
+ | '<time>'
36
+ | '<resolution>'
37
+ | '<transform-function>'
38
+ | '<custom-ident>'
39
+ | '<transform-list>';
40
+ type CSSSyntaxType = CSSSyntax;
41
+ declare class BaseCSSType {
42
+ readonly value: ValueWithDefault;
43
+ readonly syntax: CSSSyntaxType;
44
+ constructor(value: ValueWithDefault);
45
+ }
46
+ export interface CSSType<_T extends string | number = string | number> {
47
+ readonly value: ValueWithDefault;
48
+ readonly syntax: CSSSyntaxType;
49
+ }
50
+ export declare const isCSSType: (
51
+ value: unknown,
52
+ ) => value is CSSType<string | number>;
53
+ export declare type isCSSType = typeof isCSSType;
54
+ type AngleValue = string;
55
+ export declare class Angle<T extends AngleValue>
56
+ extends BaseCSSType
57
+ implements CSSType<T>
58
+ {
59
+ readonly value: ValueWithDefault;
60
+ readonly syntax: CSSSyntaxType;
61
+ static readonly syntax: CSSSyntaxType;
62
+ static create<T extends AngleValue = AngleValue>(
63
+ value: ValueWithDefault,
64
+ ): Angle<T>;
65
+ }
66
+ export declare const angle: <T extends AngleValue = AngleValue>(
67
+ value: ValueWithDefault,
68
+ ) => Angle<T>;
69
+ export declare type angle = typeof angle;
70
+ type ColorValue = string;
71
+ export declare class Color<T extends ColorValue>
72
+ extends BaseCSSType
73
+ implements CSSType<T>
74
+ {
75
+ readonly value: ValueWithDefault;
76
+ readonly syntax: CSSSyntaxType;
77
+ static create<T extends ColorValue = ColorValue>(
78
+ value: ValueWithDefault,
79
+ ): Color<T>;
80
+ }
81
+ export declare const color: <T extends ColorValue = ColorValue>(
82
+ value: ValueWithDefault,
83
+ ) => Color<T>;
84
+ export declare type color = typeof color;
85
+ type URLValue = string;
86
+ export declare class Url<T extends URLValue>
87
+ extends BaseCSSType
88
+ implements CSSType<T>
89
+ {
90
+ readonly value: ValueWithDefault;
91
+ readonly syntax: CSSSyntaxType;
92
+ static create<T extends URLValue = URLValue>(value: ValueWithDefault): Url<T>;
93
+ }
94
+ export declare const url: <T extends URLValue = URLValue>(
95
+ value: ValueWithDefault,
96
+ ) => Url<T>;
97
+ export declare type url = typeof url;
98
+ type ImageValue = string;
99
+ export declare class Image<T extends ImageValue>
100
+ extends Url<T>
101
+ implements CSSType<T>
102
+ {
103
+ readonly value: ValueWithDefault;
104
+ readonly syntax: CSSSyntaxType;
105
+ constructor(value: ValueWithDefault);
106
+ static create<T extends ImageValue = ImageValue>(
107
+ value: ValueWithDefault,
108
+ ): Image<T>;
109
+ }
110
+ export declare const image: <T extends ImageValue = ImageValue>(
111
+ value: ValueWithDefault,
112
+ ) => Image<T>;
113
+ export declare type image = typeof image;
114
+ type IntegerValue = number;
115
+ export declare class Integer<T extends IntegerValue>
116
+ extends BaseCSSType
117
+ implements CSSType<T>
118
+ {
119
+ readonly value: ValueWithDefault;
120
+ readonly syntax: CSSSyntaxType;
121
+ static create<T extends IntegerValue = IntegerValue>(value: T): Integer<T>;
122
+ }
123
+ export declare const integer: <T extends IntegerValue = IntegerValue>(
124
+ value: T,
125
+ ) => Integer<T>;
126
+ export declare type integer = typeof integer;
127
+ type LengthPercentageValue = string;
128
+ export declare class LengthPercentage<_T extends LengthPercentageValue>
129
+ extends BaseCSSType
130
+ implements CSSType<string>
131
+ {
132
+ readonly value: ValueWithDefault;
133
+ readonly syntax: CSSSyntaxType;
134
+ static createLength<_T extends LengthPercentageValue | number>(
135
+ value: ValueWithDefault,
136
+ ): LengthPercentage<string>;
137
+ static createPercentage<_T extends LengthPercentageValue | number>(
138
+ value: ValueWithDefault,
139
+ ): LengthPercentage<string>;
140
+ }
141
+ export declare const lengthPercentage: <
142
+ _T extends LengthPercentageValue | number,
143
+ >(
144
+ value: ValueWithDefault,
145
+ ) => LengthPercentage<string>;
146
+ export declare type lengthPercentage = typeof lengthPercentage;
147
+ type LengthValue = number | string;
148
+ export declare class Length<_T extends LengthValue>
149
+ extends LengthPercentage<string>
150
+ implements CSSType<string>
151
+ {
152
+ readonly value: ValueWithDefault;
153
+ readonly syntax: CSSSyntaxType;
154
+ static create<T extends LengthValue = LengthValue>(
155
+ value: NestedWithNumbers,
156
+ ): Length<T>;
157
+ }
158
+ export declare const length: <T extends LengthValue = LengthValue>(
159
+ value: NestedWithNumbers,
160
+ ) => Length<T>;
161
+ export declare type length = typeof length;
162
+ type PercentageValue = string | number;
163
+ export declare class Percentage<_T extends PercentageValue>
164
+ extends LengthPercentage<string>
165
+ implements CSSType<string>
166
+ {
167
+ readonly value: ValueWithDefault;
168
+ readonly syntax: CSSSyntaxType;
169
+ static create<T extends PercentageValue = PercentageValue>(
170
+ value: NestedWithNumbers,
171
+ ): Percentage<T>;
172
+ }
173
+ export declare const percentage: <T extends PercentageValue = PercentageValue>(
174
+ value: NestedWithNumbers,
175
+ ) => Percentage<T>;
176
+ export declare type percentage = typeof percentage;
177
+ type NumberValue = number;
178
+ export declare class Num<T extends NumberValue>
179
+ extends BaseCSSType
180
+ implements CSSType<T>
181
+ {
182
+ readonly value: ValueWithDefault;
183
+ readonly syntax: CSSSyntaxType;
184
+ static create<T extends NumberValue = NumberValue>(
185
+ value: NestedWithNumbers,
186
+ ): Num<T>;
187
+ }
188
+ export declare const number: <T extends NumberValue = NumberValue>(
189
+ value: NestedWithNumbers,
190
+ ) => Num<T>;
191
+ type ResolutionValue = string | 0;
192
+ export declare class Resolution<T extends ResolutionValue>
193
+ extends BaseCSSType
194
+ implements CSSType<T>
195
+ {
196
+ readonly value: ValueWithDefault;
197
+ readonly syntax: CSSSyntaxType;
198
+ static create<T extends ResolutionValue = ResolutionValue>(
199
+ value: ValueWithDefault,
200
+ ): Resolution<T>;
201
+ }
202
+ export declare const resolution: <T extends ResolutionValue = ResolutionValue>(
203
+ value: ValueWithDefault,
204
+ ) => Resolution<T>;
205
+ export declare type resolution = typeof resolution;
206
+ type TimeValue = string | 0;
207
+ export declare class Time<T extends TimeValue>
208
+ extends BaseCSSType
209
+ implements CSSType<T>
210
+ {
211
+ readonly value: ValueWithDefault;
212
+ readonly syntax: CSSSyntaxType;
213
+ static create<T extends TimeValue = TimeValue>(
214
+ value: ValueWithDefault,
215
+ ): Time<T>;
216
+ }
217
+ export declare const time: <T extends TimeValue = TimeValue>(
218
+ value: ValueWithDefault,
219
+ ) => Time<T>;
220
+ export declare type time = typeof time;
221
+ type TransformFunctionValue = string;
222
+ export declare class TransformFunction<T extends TransformFunctionValue>
223
+ extends BaseCSSType
224
+ implements CSSType<T>
225
+ {
226
+ readonly value: ValueWithDefault;
227
+ readonly syntax: CSSSyntaxType;
228
+ static create<T extends TransformFunctionValue = TransformFunctionValue>(
229
+ value: ValueWithDefault,
230
+ ): TransformFunction<T>;
231
+ }
232
+ export declare const transformFunction: <
233
+ T extends TransformFunctionValue = TransformFunctionValue,
234
+ >(
235
+ value: ValueWithDefault,
236
+ ) => TransformFunction<T>;
237
+ export declare type transformFunction = typeof transformFunction;
238
+ type TransformListValue = string;
239
+ export declare class TransformList<T extends TransformListValue>
240
+ extends BaseCSSType
241
+ implements CSSType<T>
242
+ {
243
+ readonly value: ValueWithDefault;
244
+ readonly syntax: CSSSyntaxType;
245
+ static create<T extends TransformListValue = TransformListValue>(
246
+ value: ValueWithDefault,
247
+ ): TransformList<T>;
248
+ }
249
+ export declare const transformList: <
250
+ T extends TransformListValue = TransformListValue,
251
+ >(
252
+ value: ValueWithDefault,
253
+ ) => TransformList<T>;
254
+ export declare type transformList = typeof transformList;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.url = exports.transformList = exports.transformFunction = exports.time = exports.resolution = exports.percentage = exports.number = exports.lengthPercentage = exports.length = exports.isCSSType = exports.integer = exports.image = exports.color = exports.angle = exports.Url = exports.TransformList = exports.TransformFunction = exports.Time = exports.Resolution = exports.Percentage = exports.Num = exports.LengthPercentage = exports.Length = exports.Integer = exports.Image = exports.Color = exports.Angle = void 0;
7
+ class BaseCSSType {
8
+ constructor(value) {
9
+ this.value = value;
10
+ }
11
+ }
12
+ const isCSSType = value => {
13
+ return value instanceof BaseCSSType && value.value != null && typeof value.syntax === 'string';
14
+ };
15
+ exports.isCSSType = isCSSType;
16
+ class Angle extends BaseCSSType {
17
+ syntax = '<angle>';
18
+ static syntax = '<angle>';
19
+ static create(value) {
20
+ return new Angle(value);
21
+ }
22
+ }
23
+ exports.Angle = Angle;
24
+ const angle = exports.angle = Angle.create;
25
+ class Color extends BaseCSSType {
26
+ syntax = '<color>';
27
+ static create(value) {
28
+ return new Color(value);
29
+ }
30
+ }
31
+ exports.Color = Color;
32
+ const color = exports.color = Color.create;
33
+ class Url extends BaseCSSType {
34
+ syntax = '<url>';
35
+ static create(value) {
36
+ return new Url(value);
37
+ }
38
+ }
39
+ exports.Url = Url;
40
+ const url = exports.url = Url.create;
41
+ class Image extends Url {
42
+ syntax = '<image>';
43
+ constructor(value) {
44
+ super(value);
45
+ this.value = value;
46
+ }
47
+ static create(value) {
48
+ return new Image(value);
49
+ }
50
+ }
51
+ exports.Image = Image;
52
+ const image = exports.image = Image.create;
53
+ class Integer extends BaseCSSType {
54
+ syntax = '<integer>';
55
+ static create(value) {
56
+ return new Integer(convertNumberToStringUsing(String, '0')(value));
57
+ }
58
+ }
59
+ exports.Integer = Integer;
60
+ const integer = exports.integer = Integer.create;
61
+ class LengthPercentage extends BaseCSSType {
62
+ syntax = '<length-percentage>';
63
+ static createLength(value) {
64
+ return new LengthPercentage(convertNumberToLength(value));
65
+ }
66
+ static createPercentage(value) {
67
+ return new LengthPercentage(convertNumberToPercentage(value));
68
+ }
69
+ }
70
+ exports.LengthPercentage = LengthPercentage;
71
+ const lengthPercentage = exports.lengthPercentage = LengthPercentage.createLength;
72
+ class Length extends LengthPercentage {
73
+ syntax = '<length>';
74
+ static create(value) {
75
+ return new Length(convertNumberToLength(value));
76
+ }
77
+ }
78
+ exports.Length = Length;
79
+ const length = exports.length = Length.create;
80
+ class Percentage extends LengthPercentage {
81
+ syntax = '<percentage>';
82
+ static create(value) {
83
+ return new Percentage(convertNumberToPercentage(value));
84
+ }
85
+ }
86
+ exports.Percentage = Percentage;
87
+ const percentage = exports.percentage = Percentage.create;
88
+ class Num extends BaseCSSType {
89
+ syntax = '<number>';
90
+ static create(value) {
91
+ return new Num(convertNumberToBareString(value));
92
+ }
93
+ }
94
+ exports.Num = Num;
95
+ const number = exports.number = Num.create;
96
+ class Resolution extends BaseCSSType {
97
+ syntax = '<resolution>';
98
+ static create(value) {
99
+ return new Resolution(value);
100
+ }
101
+ }
102
+ exports.Resolution = Resolution;
103
+ const resolution = exports.resolution = Resolution.create;
104
+ class Time extends BaseCSSType {
105
+ syntax = '<time>';
106
+ static create(value) {
107
+ return new Time(value);
108
+ }
109
+ }
110
+ exports.Time = Time;
111
+ const time = exports.time = Time.create;
112
+ class TransformFunction extends BaseCSSType {
113
+ syntax = '<transform-function>';
114
+ static create(value) {
115
+ return new TransformFunction(value);
116
+ }
117
+ }
118
+ exports.TransformFunction = TransformFunction;
119
+ const transformFunction = exports.transformFunction = TransformFunction.create;
120
+ class TransformList extends BaseCSSType {
121
+ syntax = '<transform-list>';
122
+ static create(value) {
123
+ return new TransformList(value);
124
+ }
125
+ }
126
+ exports.TransformList = TransformList;
127
+ const transformList = exports.transformList = TransformList.create;
128
+ const convertNumberToStringUsing = (transformNumber, defaultStr) => value => {
129
+ if (typeof value === 'number') {
130
+ return transformNumber(value);
131
+ }
132
+ if (typeof value === 'string') {
133
+ return value;
134
+ }
135
+ if (typeof value === 'object') {
136
+ const val = value;
137
+ const result = {};
138
+ for (const key of Object.keys(val)) {
139
+ result[key] = convertNumberToStringUsing(transformNumber, defaultStr)(val[key]);
140
+ }
141
+ return result;
142
+ }
143
+ return value;
144
+ };
145
+ const convertNumberToBareString = convertNumberToStringUsing(value => String(value), '0');
146
+ const convertNumberToLength = convertNumberToStringUsing(value => value === 0 ? '0' : `${value}px`, '0px');
147
+ const convertNumberToPercentage = convertNumberToStringUsing(value => value === 0 ? '0' : `${value * 100}%`, '0');