@stylexjs/stylex 0.11.1 → 0.13.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 (67) hide show
  1. package/README.md +0 -27
  2. package/lib/{stylex-inject.d.ts → cjs/inject.d.ts} +1 -5
  3. package/lib/cjs/inject.js +210 -0
  4. package/lib/{stylex-inject.js.flow → cjs/inject.js.flow} +2 -3
  5. package/lib/cjs/stylesheet/createCSSStyleSheet.d.ts +13 -0
  6. package/lib/cjs/stylesheet/createCSSStyleSheet.js.flow +13 -0
  7. package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
  8. package/lib/cjs/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
  9. package/lib/cjs/stylesheet/createSheet.d.ts +12 -0
  10. package/lib/cjs/stylesheet/createSheet.js.flow +16 -0
  11. package/lib/cjs/stylesheet/utils.d.ts +18 -0
  12. package/lib/cjs/stylesheet/utils.js.flow +19 -0
  13. package/lib/{stylex.d.ts → cjs/stylex.d.ts} +8 -21
  14. package/lib/cjs/stylex.js +242 -0
  15. package/lib/{stylex.js.flow → cjs/stylex.js.flow} +10 -26
  16. package/lib/{StyleXCSSTypes.d.ts → cjs/types/StyleXCSSTypes.d.ts} +22 -0
  17. package/lib/{StyleXCSSTypes.js.flow → cjs/types/StyleXCSSTypes.js.flow} +25 -0
  18. package/lib/{StyleXTypes.d.ts → cjs/types/StyleXTypes.d.ts} +60 -5
  19. package/lib/{StyleXTypes.js.flow → cjs/types/StyleXTypes.js.flow} +56 -5
  20. package/lib/{VarTypes.d.ts → cjs/types/VarTypes.d.ts} +19 -18
  21. package/lib/{VarTypes.js.flow → cjs/types/VarTypes.js.flow} +17 -19
  22. package/lib/es/inject.d.ts +11 -0
  23. package/lib/es/inject.js.flow +13 -0
  24. package/lib/es/inject.mjs +208 -0
  25. package/lib/es/stylesheet/createCSSStyleSheet.d.ts +13 -0
  26. package/lib/es/stylesheet/createCSSStyleSheet.js.flow +13 -0
  27. package/lib/es/stylesheet/createOrderedCSSStyleSheet.d.ts +31 -0
  28. package/lib/es/stylesheet/createOrderedCSSStyleSheet.js.flow +32 -0
  29. package/lib/es/stylesheet/createSheet.d.ts +12 -0
  30. package/lib/es/stylesheet/createSheet.js.flow +16 -0
  31. package/lib/es/stylesheet/utils.d.ts +18 -0
  32. package/lib/es/stylesheet/utils.js.flow +19 -0
  33. package/lib/es/stylex.d.ts +135 -0
  34. package/lib/es/stylex.js.flow +134 -0
  35. package/lib/es/stylex.mjs +8 -20
  36. package/lib/es/types/StyleXCSSTypes.d.ts +1487 -0
  37. package/lib/es/types/StyleXCSSTypes.js.flow +1580 -0
  38. package/lib/es/types/StyleXOpaqueTypes.d.ts +11 -0
  39. package/lib/es/types/StyleXOpaqueTypes.js.flow +16 -0
  40. package/lib/es/types/StyleXTypes.d.ts +292 -0
  41. package/lib/es/types/StyleXTypes.js.flow +240 -0
  42. package/lib/es/types/StyleXUtils.d.ts +15 -0
  43. package/lib/es/types/StyleXUtils.js.flow +15 -0
  44. package/lib/es/types/VarTypes.d.ts +104 -0
  45. package/lib/es/types/VarTypes.js.flow +102 -0
  46. package/package.json +20 -28
  47. package/lib/StyleXCSSTypes.js +0 -1
  48. package/lib/StyleXOpaqueTypes.js +0 -1
  49. package/lib/StyleXSheet.d.ts +0 -49
  50. package/lib/StyleXSheet.js +0 -188
  51. package/lib/StyleXSheet.js.flow +0 -49
  52. package/lib/StyleXTypes.js +0 -1
  53. package/lib/VarTypes.js +0 -1
  54. package/lib/es/StyleXCSSTypes.mjs +0 -1
  55. package/lib/es/StyleXOpaqueTypes.mjs +0 -0
  56. package/lib/es/StyleXSheet.mjs +0 -247
  57. package/lib/es/StyleXTypes.mjs +0 -1
  58. package/lib/es/VarTypes.mjs +0 -0
  59. package/lib/es/stylex-inject.mjs +0 -5
  60. package/lib/es/util-types.mjs +0 -0
  61. package/lib/stylex-inject.js +0 -11
  62. package/lib/stylex.js +0 -125
  63. package/lib/util-types.js +0 -1
  64. /package/lib/{StyleXOpaqueTypes.d.ts → cjs/types/StyleXOpaqueTypes.d.ts} +0 -0
  65. /package/lib/{StyleXOpaqueTypes.js.flow → cjs/types/StyleXOpaqueTypes.js.flow} +0 -0
  66. /package/lib/{util-types.d.ts → cjs/types/StyleXUtils.d.ts} +0 -0
  67. /package/lib/{util-types.js.flow → cjs/types/StyleXUtils.js.flow} +0 -0
@@ -1,247 +0,0 @@
1
- function getDefaultExportFromCjs (x) {
2
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
3
- }
4
-
5
- /**
6
- * Copyright (c) 2013-present, Facebook, Inc.
7
- *
8
- * This source code is licensed under the MIT license found in the
9
- * LICENSE file in the root directory of this source tree.
10
- */
11
-
12
- var invariant_1;
13
- var hasRequiredInvariant;
14
-
15
- function requireInvariant () {
16
- if (hasRequiredInvariant) return invariant_1;
17
- hasRequiredInvariant = 1;
18
-
19
- /**
20
- * Use invariant() to assert state which your program assumes to be true.
21
- *
22
- * Provide sprintf-style format (only %s is supported) and arguments
23
- * to provide information about what broke and what you were
24
- * expecting.
25
- *
26
- * The invariant message will be stripped in production, but the invariant
27
- * will remain to ensure logic does not differ in production.
28
- */
29
-
30
- var NODE_ENV = process.env.NODE_ENV;
31
-
32
- var invariant = function(condition, format, a, b, c, d, e, f) {
33
- if (NODE_ENV !== 'production') {
34
- if (format === undefined) {
35
- throw new Error('invariant requires an error message argument');
36
- }
37
- }
38
-
39
- if (!condition) {
40
- var error;
41
- if (format === undefined) {
42
- error = new Error(
43
- 'Minified exception occurred; use the non-minified dev environment ' +
44
- 'for the full error message and additional helpful warnings.'
45
- );
46
- } else {
47
- var args = [a, b, c, d, e, f];
48
- var argIndex = 0;
49
- error = new Error(
50
- format.replace(/%s/g, function() { return args[argIndex++]; })
51
- );
52
- error.name = 'Invariant Violation';
53
- }
54
-
55
- error.framesToPop = 1; // we don't care about invariant's own frame
56
- throw error;
57
- }
58
- };
59
-
60
- invariant_1 = invariant;
61
- return invariant_1;
62
- }
63
-
64
- var invariantExports = requireInvariant();
65
- var invariant = /*@__PURE__*/getDefaultExportFromCjs(invariantExports);
66
-
67
- const LIGHT_MODE_CLASS_NAME = '__fb-light-mode';
68
- const DARK_MODE_CLASS_NAME = '__fb-dark-mode';
69
- function buildTheme(selector, theme) {
70
- const lines = [];
71
- lines.push(`${selector} {`);
72
- for (const key in theme) {
73
- const value = theme[key];
74
- lines.push(` --${key}: ${value};`);
75
- }
76
- lines.push('}');
77
- return lines.join('\n');
78
- }
79
- function makeStyleTag() {
80
- const tag = document.createElement('style');
81
- tag.setAttribute('type', 'text/css');
82
- tag.setAttribute('data-stylex', 'true');
83
- const head = document.head || document.getElementsByTagName('head')[0];
84
- invariant(head, 'expected head');
85
- head.appendChild(tag);
86
- return tag;
87
- }
88
- function doesSupportCSSVariables() {
89
- return globalThis.CSS != null && globalThis.CSS.supports != null && globalThis.CSS.supports('--fake-var:0');
90
- }
91
- const VARIABLE_MATCH = /var\(--(.*?)\)/g;
92
- class StyleXSheet {
93
- static LIGHT_MODE_CLASS_NAME = (() => LIGHT_MODE_CLASS_NAME)();
94
- static DARK_MODE_CLASS_NAME = (() => DARK_MODE_CLASS_NAME)();
95
- constructor(opts) {
96
- this.tag = null;
97
- this.injected = false;
98
- this.ruleForPriority = new Map();
99
- this.rules = [];
100
- this.rootTheme = opts.rootTheme;
101
- this.rootDarkTheme = opts.rootDarkTheme;
102
- this.supportsVariables = opts.supportsVariables ?? doesSupportCSSVariables();
103
- }
104
- getVariableMatch() {
105
- return VARIABLE_MATCH;
106
- }
107
- isHeadless() {
108
- return this.tag == null || globalThis?.document?.body == null;
109
- }
110
- getTag() {
111
- const {
112
- tag
113
- } = this;
114
- invariant(tag != null, 'expected tag');
115
- return tag;
116
- }
117
- getCSS() {
118
- return this.rules.join('\n');
119
- }
120
- getRulePosition(rule) {
121
- return this.rules.indexOf(rule);
122
- }
123
- getRuleCount() {
124
- return this.rules.length;
125
- }
126
- inject() {
127
- if (this.injected) {
128
- return;
129
- }
130
- this.injected = true;
131
- if (globalThis.document?.body == null) {
132
- this.injectTheme();
133
- return;
134
- }
135
- this.tag = makeStyleTag();
136
- this.injectTheme();
137
- }
138
- injectTheme() {
139
- if (this.rootTheme != null) {
140
- this.insert(buildTheme(`:root, .${LIGHT_MODE_CLASS_NAME}`, this.rootTheme), 0);
141
- }
142
- if (this.rootDarkTheme != null) {
143
- this.insert(buildTheme(`.${DARK_MODE_CLASS_NAME}:root, .${DARK_MODE_CLASS_NAME}`, this.rootDarkTheme), 0);
144
- }
145
- }
146
- __injectCustomThemeForTesting(selector, theme) {
147
- if (theme != null) {
148
- this.insert(buildTheme(selector, theme), 0);
149
- }
150
- }
151
- delete(rule) {
152
- const index = this.rules.indexOf(rule);
153
- invariant(index >= 0, "Couldn't find the index for rule %s", rule);
154
- this.rules.splice(index, 1);
155
- if (this.isHeadless()) {
156
- return;
157
- }
158
- const tag = this.getTag();
159
- const sheet = tag.sheet;
160
- invariant(sheet, 'expected sheet');
161
- sheet.deleteRule(index);
162
- }
163
- normalizeRule(rule) {
164
- const {
165
- rootTheme
166
- } = this;
167
- if (this.supportsVariables || rootTheme == null) {
168
- return rule;
169
- }
170
- return rule.replace(VARIABLE_MATCH, (_match, name) => {
171
- return rootTheme[name];
172
- });
173
- }
174
- getInsertPositionForPriority(priority) {
175
- const priorityRule = this.ruleForPriority.get(priority);
176
- if (priorityRule != null) {
177
- return this.rules.indexOf(priorityRule) + 1;
178
- }
179
- const priorities = Array.from(this.ruleForPriority.keys()).sort((a, b) => b - a).filter(num => num > priority ? 1 : 0);
180
- if (priorities.length === 0) {
181
- return this.getRuleCount();
182
- }
183
- const lastPriority = priorities.pop();
184
- if (lastPriority == null) {
185
- return this.getRuleCount();
186
- }
187
- return this.rules.indexOf(this.ruleForPriority.get(lastPriority));
188
- }
189
- insert(rawLTRRule, priority, rawRTLRule) {
190
- if (this.injected === false) {
191
- this.inject();
192
- }
193
- if (rawRTLRule != null) {
194
- this.insert(addAncestorSelector(rawLTRRule, "html:not([dir='rtl'])"), priority);
195
- this.insert(addAncestorSelector(rawRTLRule, "html[dir='rtl']"), priority);
196
- return;
197
- }
198
- const rawRule = rawLTRRule;
199
- if (this.rules.includes(rawRule)) {
200
- return;
201
- }
202
- const rule = this.normalizeRule(addSpecificityLevel(rawRule, Math.floor(priority / 1000)));
203
- const insertPos = this.getInsertPositionForPriority(priority);
204
- this.rules.splice(insertPos, 0, rule);
205
- this.ruleForPriority.set(priority, rule);
206
- if (this.isHeadless()) {
207
- return;
208
- }
209
- const tag = this.getTag();
210
- const sheet = tag.sheet;
211
- if (sheet != null) {
212
- try {
213
- sheet.insertRule(rule, Math.min(insertPos, sheet.cssRules.length));
214
- } catch (err) {
215
- console.error('insertRule error', err, rule, insertPos);
216
- }
217
- }
218
- }
219
- }
220
- function addAncestorSelector(selector, ancestorSelector) {
221
- if (!selector.startsWith('@')) {
222
- return `${ancestorSelector} ${selector}`;
223
- }
224
- const firstBracketIndex = selector.indexOf('{');
225
- const mediaQueryPart = selector.slice(0, firstBracketIndex + 1);
226
- const rest = selector.slice(firstBracketIndex + 1);
227
- return `${mediaQueryPart}${ancestorSelector} ${rest}`;
228
- }
229
- function addSpecificityLevel(selector, index) {
230
- if (selector.startsWith('@keyframes')) {
231
- return selector;
232
- }
233
- const pseudo = Array.from({
234
- length: index
235
- }).map(() => ':not(#\\#)').join('');
236
- const lastOpenCurly = selector.includes('::') ? selector.indexOf('::') : selector.lastIndexOf('{');
237
- const beforeCurly = selector.slice(0, lastOpenCurly);
238
- const afterCurly = selector.slice(lastOpenCurly);
239
- return `${beforeCurly}${pseudo}${afterCurly}`;
240
- }
241
- const styleSheet = new StyleXSheet({
242
- supportsVariables: true,
243
- rootTheme: {},
244
- rootDarkTheme: {}
245
- });
246
-
247
- export { StyleXSheet, styleSheet };
@@ -1 +0,0 @@
1
- 'use strict';
File without changes
@@ -1,5 +0,0 @@
1
- import { styleSheet } from "./StyleXSheet.mjs";
2
- export default function inject(ltrRule, priority) {
3
- let rtlRule = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
4
- styleSheet.insert(ltrRule, priority, rtlRule);
5
- }
File without changes
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = inject;
7
- var _StyleXSheet = require("./StyleXSheet");
8
- function inject(ltrRule, priority) {
9
- let rtlRule = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
10
- _StyleXSheet.styleSheet.insert(ltrRule, priority, rtlRule);
11
- }
package/lib/stylex.js DELETED
@@ -1,125 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.attrs = attrs;
7
- exports.legacyMerge = exports.keyframes = exports.firstThatWorks = exports.defineVars = exports.createTheme = exports.create = void 0;
8
- exports.props = props;
9
- exports.types = void 0;
10
- var Types = _interopRequireWildcard(require("./VarTypes"));
11
- var _styleq = require("styleq");
12
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- const errorForFn = name => new Error(`Unexpected 'stylex.${name}' call at runtime. Styles must be compiled by '@stylexjs/babel-plugin'.`);
15
- const errorForType = key => errorForFn(`types.${key}`);
16
- function attrs() {
17
- const {
18
- className,
19
- 'data-style-src': dataStyleSrc,
20
- style
21
- } = props(...arguments);
22
- const result = {};
23
- if (className != null && className !== '') {
24
- result.class = className;
25
- }
26
- if (style != null && Object.keys(style).length > 0) {
27
- result.style = Object.keys(style).map(key => `${key}:${style[key]};`).join('');
28
- }
29
- if (dataStyleSrc != null && dataStyleSrc !== '') {
30
- result['data-style-src'] = dataStyleSrc;
31
- }
32
- return result;
33
- }
34
- const create = exports.create = function stylexCreate(_styles) {
35
- throw errorForFn('create');
36
- };
37
- const createTheme = (_baseTokens, _overrides) => {
38
- throw errorForFn('createTheme');
39
- };
40
- exports.createTheme = createTheme;
41
- const defineVars = exports.defineVars = function stylexDefineVars(_styles) {
42
- throw errorForFn('defineVars');
43
- };
44
- const firstThatWorks = function () {
45
- throw errorForFn('firstThatWorks');
46
- };
47
- exports.firstThatWorks = firstThatWorks;
48
- const keyframes = _keyframes => {
49
- throw errorForFn('keyframes');
50
- };
51
- exports.keyframes = keyframes;
52
- function props() {
53
- for (var _len = arguments.length, styles = new Array(_len), _key = 0; _key < _len; _key++) {
54
- styles[_key] = arguments[_key];
55
- }
56
- const [className, style, dataStyleSrc] = (0, _styleq.styleq)(styles);
57
- const result = {};
58
- if (className != null && className !== '') {
59
- result.className = className;
60
- }
61
- if (style != null && Object.keys(style).length > 0) {
62
- result.style = style;
63
- }
64
- if (dataStyleSrc != null && dataStyleSrc !== '') {
65
- result['data-style-src'] = dataStyleSrc;
66
- }
67
- return result;
68
- }
69
- const types = exports.types = {
70
- angle: _v => {
71
- throw errorForType('angle');
72
- },
73
- color: _v => {
74
- throw errorForType('color');
75
- },
76
- url: _v => {
77
- throw errorForType('url');
78
- },
79
- image: _v => {
80
- throw errorForType('image');
81
- },
82
- integer: _v => {
83
- throw errorForType('integer');
84
- },
85
- lengthPercentage: _v => {
86
- throw errorForType('lengthPercentage');
87
- },
88
- length: _v => {
89
- throw errorForType('length');
90
- },
91
- percentage: _v => {
92
- throw errorForType('percentage');
93
- },
94
- number: _v => {
95
- throw errorForType('number');
96
- },
97
- resolution: _v => {
98
- throw errorForType('resolution');
99
- },
100
- time: _v => {
101
- throw errorForType('time');
102
- },
103
- transformFunction: _v => {
104
- throw errorForType('transformFunction');
105
- },
106
- transformList: _v => {
107
- throw errorForType('transformList');
108
- }
109
- };
110
- function _legacyMerge() {
111
- for (var _len2 = arguments.length, styles = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
112
- styles[_key2] = arguments[_key2];
113
- }
114
- const [className] = (0, _styleq.styleq)(styles);
115
- return className;
116
- }
117
- _legacyMerge.attrs = attrs;
118
- _legacyMerge.create = create;
119
- _legacyMerge.createTheme = createTheme;
120
- _legacyMerge.defineVars = defineVars;
121
- _legacyMerge.firstThatWorks = firstThatWorks;
122
- _legacyMerge.keyframes = keyframes;
123
- _legacyMerge.props = props;
124
- _legacyMerge.types = types;
125
- const legacyMerge = exports.legacyMerge = _legacyMerge;
package/lib/util-types.js DELETED
@@ -1 +0,0 @@
1
- "use strict";