@uipath/apollo-wind 2.83.0 → 2.84.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.
- package/dist/components/ui/index.cjs +20 -20
- package/dist/styles.css +15 -13
- package/dist/tailwind.css +28 -18
- package/package.json +10 -3
- package/postcss-scope-preflight.d.ts +23 -0
- package/postcss-scope-preflight.js +218 -0
|
@@ -39,7 +39,7 @@ var __webpack_modules__ = {
|
|
|
39
39
|
"@/components/ui/calendar" (module) {
|
|
40
40
|
module.exports = require("./calendar.cjs");
|
|
41
41
|
},
|
|
42
|
-
"
|
|
42
|
+
"./card" (module) {
|
|
43
43
|
module.exports = require("./card.cjs");
|
|
44
44
|
},
|
|
45
45
|
"./chart" (module) {
|
|
@@ -69,7 +69,7 @@ var __webpack_modules__ = {
|
|
|
69
69
|
"@/components/ui/command" (module) {
|
|
70
70
|
module.exports = require("./command.cjs");
|
|
71
71
|
},
|
|
72
|
-
"
|
|
72
|
+
"@/components/ui/context-menu" (module) {
|
|
73
73
|
module.exports = require("./context-menu.cjs");
|
|
74
74
|
},
|
|
75
75
|
"./data-table" (module) {
|
|
@@ -90,7 +90,7 @@ var __webpack_modules__ = {
|
|
|
90
90
|
"./drawer" (module) {
|
|
91
91
|
module.exports = require("./drawer.cjs");
|
|
92
92
|
},
|
|
93
|
-
"
|
|
93
|
+
"@/components/ui/dropdown-menu" (module) {
|
|
94
94
|
module.exports = require("./dropdown-menu.cjs");
|
|
95
95
|
},
|
|
96
96
|
"./dropzone-overlay" (module) {
|
|
@@ -117,7 +117,7 @@ var __webpack_modules__ = {
|
|
|
117
117
|
"./file-validation" (module) {
|
|
118
118
|
module.exports = require("./file-validation.cjs");
|
|
119
119
|
},
|
|
120
|
-
"
|
|
120
|
+
"./form-field" (module) {
|
|
121
121
|
module.exports = require("./form-field.cjs");
|
|
122
122
|
},
|
|
123
123
|
"./hover-card" (module) {
|
|
@@ -129,7 +129,7 @@ var __webpack_modules__ = {
|
|
|
129
129
|
"@/components/ui/input-group" (module) {
|
|
130
130
|
module.exports = require("./input-group.cjs");
|
|
131
131
|
},
|
|
132
|
-
"
|
|
132
|
+
"@/components/ui/input" (module) {
|
|
133
133
|
module.exports = require("./input.cjs");
|
|
134
134
|
},
|
|
135
135
|
"./json-tree-view" (module) {
|
|
@@ -138,7 +138,7 @@ var __webpack_modules__ = {
|
|
|
138
138
|
"./label" (module) {
|
|
139
139
|
module.exports = require("./label.cjs");
|
|
140
140
|
},
|
|
141
|
-
"
|
|
141
|
+
"@/components/ui/layout" (module) {
|
|
142
142
|
module.exports = require("./layout/index.cjs");
|
|
143
143
|
},
|
|
144
144
|
"./live-region" (module) {
|
|
@@ -207,7 +207,7 @@ var __webpack_modules__ = {
|
|
|
207
207
|
"./reference-chip-colors" (module) {
|
|
208
208
|
module.exports = require("./reference-chip-colors.cjs");
|
|
209
209
|
},
|
|
210
|
-
"
|
|
210
|
+
"@/components/ui/reference-chip" (module) {
|
|
211
211
|
module.exports = require("./reference-chip.cjs");
|
|
212
212
|
},
|
|
213
213
|
"./resizable" (module) {
|
|
@@ -255,13 +255,13 @@ var __webpack_modules__ = {
|
|
|
255
255
|
"./switch" (module) {
|
|
256
256
|
module.exports = require("./switch.cjs");
|
|
257
257
|
},
|
|
258
|
-
"
|
|
258
|
+
"@/components/ui/table" (module) {
|
|
259
259
|
module.exports = require("./table.cjs");
|
|
260
260
|
},
|
|
261
261
|
"./tabs" (module) {
|
|
262
262
|
module.exports = require("./tabs.cjs");
|
|
263
263
|
},
|
|
264
|
-
"
|
|
264
|
+
"@/components/ui/textarea" (module) {
|
|
265
265
|
module.exports = require("./textarea.cjs");
|
|
266
266
|
},
|
|
267
267
|
"./thinking-indicator" (module) {
|
|
@@ -282,7 +282,7 @@ var __webpack_modules__ = {
|
|
|
282
282
|
"./tree-view" (module) {
|
|
283
283
|
module.exports = require("./tree-view.cjs");
|
|
284
284
|
},
|
|
285
|
-
"
|
|
285
|
+
"@/components/ui/variable-picker" (module) {
|
|
286
286
|
module.exports = require("./variable-picker/index.cjs");
|
|
287
287
|
},
|
|
288
288
|
"./variable-value-control" (module) {
|
|
@@ -468,7 +468,7 @@ var __webpack_exports__ = {};
|
|
|
468
468
|
"ReferenceChip"
|
|
469
469
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_calendar__rspack_import_12[__rspack_import_key];
|
|
470
470
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
471
|
-
var _card__rspack_import_13 = __webpack_require__("
|
|
471
|
+
var _card__rspack_import_13 = __webpack_require__("./card");
|
|
472
472
|
var __rspack_reexport = {};
|
|
473
473
|
for(const __rspack_import_key in _card__rspack_import_13)if ([
|
|
474
474
|
"getReferenceChipColors",
|
|
@@ -568,7 +568,7 @@ var __webpack_exports__ = {};
|
|
|
568
568
|
"ReferenceChip"
|
|
569
569
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_command__rspack_import_22[__rspack_import_key];
|
|
570
570
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
571
|
-
var _context_menu__rspack_import_23 = __webpack_require__("
|
|
571
|
+
var _context_menu__rspack_import_23 = __webpack_require__("@/components/ui/context-menu");
|
|
572
572
|
var __rspack_reexport = {};
|
|
573
573
|
for(const __rspack_import_key in _context_menu__rspack_import_23)if ([
|
|
574
574
|
"getReferenceChipColors",
|
|
@@ -638,7 +638,7 @@ var __webpack_exports__ = {};
|
|
|
638
638
|
"ReferenceChip"
|
|
639
639
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_drawer__rspack_import_29[__rspack_import_key];
|
|
640
640
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
641
|
-
var _dropdown_menu__rspack_import_30 = __webpack_require__("
|
|
641
|
+
var _dropdown_menu__rspack_import_30 = __webpack_require__("@/components/ui/dropdown-menu");
|
|
642
642
|
var __rspack_reexport = {};
|
|
643
643
|
for(const __rspack_import_key in _dropdown_menu__rspack_import_30)if ([
|
|
644
644
|
"getReferenceChipColors",
|
|
@@ -728,7 +728,7 @@ var __webpack_exports__ = {};
|
|
|
728
728
|
"ReferenceChip"
|
|
729
729
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_file_validation__rspack_import_38[__rspack_import_key];
|
|
730
730
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
731
|
-
var _form_field__rspack_import_39 = __webpack_require__("
|
|
731
|
+
var _form_field__rspack_import_39 = __webpack_require__("./form-field");
|
|
732
732
|
var __rspack_reexport = {};
|
|
733
733
|
for(const __rspack_import_key in _form_field__rspack_import_39)if ([
|
|
734
734
|
"getReferenceChipColors",
|
|
@@ -758,7 +758,7 @@ var __webpack_exports__ = {};
|
|
|
758
758
|
"ReferenceChip"
|
|
759
759
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_info_tooltip__rspack_import_41[__rspack_import_key];
|
|
760
760
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
761
|
-
var _input__rspack_import_42 = __webpack_require__("
|
|
761
|
+
var _input__rspack_import_42 = __webpack_require__("@/components/ui/input");
|
|
762
762
|
var __rspack_reexport = {};
|
|
763
763
|
for(const __rspack_import_key in _input__rspack_import_42)if ([
|
|
764
764
|
"getReferenceChipColors",
|
|
@@ -798,7 +798,7 @@ var __webpack_exports__ = {};
|
|
|
798
798
|
"ReferenceChip"
|
|
799
799
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_label__rspack_import_45[__rspack_import_key];
|
|
800
800
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
801
|
-
var _layout__rspack_import_46 = __webpack_require__("
|
|
801
|
+
var _layout__rspack_import_46 = __webpack_require__("@/components/ui/layout");
|
|
802
802
|
var __rspack_reexport = {};
|
|
803
803
|
for(const __rspack_import_key in _layout__rspack_import_46)if ([
|
|
804
804
|
"getReferenceChipColors",
|
|
@@ -1018,7 +1018,7 @@ var __webpack_exports__ = {};
|
|
|
1018
1018
|
"ReferenceChip"
|
|
1019
1019
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_radio_group__rspack_import_67[__rspack_import_key];
|
|
1020
1020
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
1021
|
-
var _reference_chip__rspack_import_68 = __webpack_require__("
|
|
1021
|
+
var _reference_chip__rspack_import_68 = __webpack_require__("@/components/ui/reference-chip");
|
|
1022
1022
|
var _reference_chip_colors__rspack_import_69 = __webpack_require__("./reference-chip-colors");
|
|
1023
1023
|
var _resizable__rspack_import_70 = __webpack_require__("./resizable");
|
|
1024
1024
|
var __rspack_reexport = {};
|
|
@@ -1170,7 +1170,7 @@ var __webpack_exports__ = {};
|
|
|
1170
1170
|
"ReferenceChip"
|
|
1171
1171
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_switch__rspack_import_84[__rspack_import_key];
|
|
1172
1172
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
1173
|
-
var _table__rspack_import_85 = __webpack_require__("
|
|
1173
|
+
var _table__rspack_import_85 = __webpack_require__("@/components/ui/table");
|
|
1174
1174
|
var __rspack_reexport = {};
|
|
1175
1175
|
for(const __rspack_import_key in _table__rspack_import_85)if ([
|
|
1176
1176
|
"getReferenceChipColors",
|
|
@@ -1190,7 +1190,7 @@ var __webpack_exports__ = {};
|
|
|
1190
1190
|
"ReferenceChip"
|
|
1191
1191
|
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_tabs__rspack_import_86[__rspack_import_key];
|
|
1192
1192
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
1193
|
-
var _textarea__rspack_import_87 = __webpack_require__("
|
|
1193
|
+
var _textarea__rspack_import_87 = __webpack_require__("@/components/ui/textarea");
|
|
1194
1194
|
var __rspack_reexport = {};
|
|
1195
1195
|
for(const __rspack_import_key in _textarea__rspack_import_87)if ([
|
|
1196
1196
|
"getReferenceChipColors",
|
|
@@ -1252,7 +1252,7 @@ var __webpack_exports__ = {};
|
|
|
1252
1252
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
1253
1253
|
var _tree_view__rspack_import_93 = __webpack_require__("./tree-view");
|
|
1254
1254
|
var _tree_view__rspack_import_93_default = /*#__PURE__*/ __webpack_require__.n(_tree_view__rspack_import_93);
|
|
1255
|
-
var _variable_picker__rspack_import_94 = __webpack_require__("
|
|
1255
|
+
var _variable_picker__rspack_import_94 = __webpack_require__("@/components/ui/variable-picker");
|
|
1256
1256
|
var __rspack_reexport = {};
|
|
1257
1257
|
for(const __rspack_import_key in _variable_picker__rspack_import_94)if ([
|
|
1258
1258
|
"getReferenceChipColors",
|
package/dist/styles.css
CHANGED
|
@@ -13923,19 +13923,21 @@ body.canvas, .canvas {
|
|
|
13923
13923
|
.future-dark, .dark, .dark-hc {
|
|
13924
13924
|
scrollbar-width: thin;
|
|
13925
13925
|
scrollbar-color: var(--color-border) transparent;
|
|
13926
|
-
|
|
13927
|
-
|
|
13928
|
-
|
|
13929
|
-
|
|
13930
|
-
|
|
13931
|
-
|
|
13932
|
-
|
|
13933
|
-
|
|
13934
|
-
|
|
13935
|
-
|
|
13936
|
-
|
|
13937
|
-
|
|
13938
|
-
|
|
13926
|
+
@supports not (scrollbar-color: auto) {
|
|
13927
|
+
& *::-webkit-scrollbar {
|
|
13928
|
+
width: 6px;
|
|
13929
|
+
height: 6px;
|
|
13930
|
+
}
|
|
13931
|
+
& *::-webkit-scrollbar-track {
|
|
13932
|
+
background: transparent;
|
|
13933
|
+
}
|
|
13934
|
+
& *::-webkit-scrollbar-thumb {
|
|
13935
|
+
background-color: var(--color-border);
|
|
13936
|
+
border-radius: 9999px;
|
|
13937
|
+
}
|
|
13938
|
+
& *::-webkit-scrollbar-thumb:hover {
|
|
13939
|
+
background-color: var(--color-border-hover);
|
|
13940
|
+
}
|
|
13939
13941
|
}
|
|
13940
13942
|
}
|
|
13941
13943
|
.mat-typography :is( [data-slot="dialog-content"], [data-slot="sheet-content"], [data-slot="alert-dialog-content"], [data-slot="drawer-content"] ) :where(p) {
|
package/dist/tailwind.css
CHANGED
|
@@ -897,32 +897,42 @@ body.canvas, .canvas {
|
|
|
897
897
|
* Dark themes: future-dark + dark-hc are applied to <html>;
|
|
898
898
|
* dark + dark-hc are applied to <body>. Both cases are covered by the
|
|
899
899
|
* class selectors below since * matches all descendants.
|
|
900
|
+
*
|
|
901
|
+
* The standard properties inherit, so they cost nothing per element. The
|
|
902
|
+
* WebKit pseudo-element rules do not: `.dark *::-webkit-scrollbar` makes
|
|
903
|
+
* Chrome walk every element's ancestors for the theme class on every style
|
|
904
|
+
* recalc (about 7 ms per copy of this block in Studio Web, MST-17369).
|
|
905
|
+
* Browsers that implement `scrollbar-color` ignore `::-webkit-scrollbar`
|
|
906
|
+
* once it is set (Chrome 121+, Safari 26.2+), so the WebKit rules only
|
|
907
|
+
* exist where the standard properties are missing.
|
|
900
908
|
* ============================================================================ */
|
|
901
909
|
|
|
902
910
|
.future-dark,
|
|
903
911
|
.dark,
|
|
904
912
|
.dark-hc {
|
|
905
|
-
/* Firefox — inherits down the tree */
|
|
913
|
+
/* Firefox, Chrome 121+, Safari 26.2+ — inherits down the tree */
|
|
906
914
|
scrollbar-width: thin;
|
|
907
915
|
scrollbar-color: var(--color-border) transparent;
|
|
908
916
|
|
|
909
|
-
/* WebKit — pseudo-elements don't inherit, must target descendants */
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
917
|
+
/* Older WebKit — pseudo-elements don't inherit, must target descendants */
|
|
918
|
+
@supports not (scrollbar-color: auto) {
|
|
919
|
+
& *::-webkit-scrollbar {
|
|
920
|
+
width: 6px;
|
|
921
|
+
height: 6px;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
& *::-webkit-scrollbar-track {
|
|
925
|
+
background: transparent;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
& *::-webkit-scrollbar-thumb {
|
|
929
|
+
background-color: var(--color-border);
|
|
930
|
+
border-radius: 9999px;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
& *::-webkit-scrollbar-thumb:hover {
|
|
934
|
+
background-color: var(--color-border-hover);
|
|
935
|
+
}
|
|
926
936
|
}
|
|
927
937
|
}
|
|
928
938
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uipath/apollo-wind",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.84.0",
|
|
4
4
|
"description": "UiPath wind design system - A Tailwind CSS based React component library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -51,6 +51,11 @@
|
|
|
51
51
|
"import": "./dist/postcss.config.export.js",
|
|
52
52
|
"require": "./dist/postcss.config.export.cjs"
|
|
53
53
|
},
|
|
54
|
+
"./postcss-scope-preflight": {
|
|
55
|
+
"types": "./postcss-scope-preflight.d.ts",
|
|
56
|
+
"import": "./postcss-scope-preflight.js",
|
|
57
|
+
"default": "./postcss-scope-preflight.js"
|
|
58
|
+
},
|
|
54
59
|
"./editor-themes": {
|
|
55
60
|
"import": "./dist/editor-themes/index.js",
|
|
56
61
|
"require": "./dist/editor-themes/index.cjs",
|
|
@@ -59,7 +64,9 @@
|
|
|
59
64
|
},
|
|
60
65
|
"files": [
|
|
61
66
|
"dist",
|
|
62
|
-
"postcss.config.export.js"
|
|
67
|
+
"postcss.config.export.js",
|
|
68
|
+
"postcss-scope-preflight.js",
|
|
69
|
+
"postcss-scope-preflight.d.ts"
|
|
63
70
|
],
|
|
64
71
|
"peerDependencies": {
|
|
65
72
|
"react": ">=18.0.0",
|
|
@@ -177,7 +184,7 @@
|
|
|
177
184
|
"storybook": "^10.6.2",
|
|
178
185
|
"typescript": "^5.9.3",
|
|
179
186
|
"vitest": "^4.1.12",
|
|
180
|
-
"@uipath/apollo-ui-icons-react": "
|
|
187
|
+
"@uipath/apollo-ui-icons-react": "0.0.0"
|
|
181
188
|
},
|
|
182
189
|
"keywords": [
|
|
183
190
|
"react",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Plugin, PluginCreator } from 'postcss';
|
|
2
|
+
|
|
3
|
+
export interface ScopePreflightOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Selectors for the elements that own the consumer's DOM: web-component tags, portal markers,
|
|
6
|
+
* `[data-slot]`. Preflight applies to these elements and their descendants.
|
|
7
|
+
*/
|
|
8
|
+
roots: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Preflight's `html, :host` rule sets the page font from `--font-sans`, a `:root` variable every
|
|
11
|
+
* consumer in a shared document redefines. By default the font declarations stay on the outermost
|
|
12
|
+
* root. Pass the selector of the element the consumer renders when it owns the whole document to
|
|
13
|
+
* apply them there only, so embedded roots inherit the host's font; pass `false` to drop them.
|
|
14
|
+
*/
|
|
15
|
+
documentRoot?: string | false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Inserts `:where(:scope)` into the subject of a selector, ahead of any pseudo-element. */
|
|
19
|
+
export function scopeSelector(selector: string): string;
|
|
20
|
+
|
|
21
|
+
declare const scopePreflight: PluginCreator<ScopePreflightOptions> &
|
|
22
|
+
((options: ScopePreflightOptions) => Plugin);
|
|
23
|
+
export default scopePreflight;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostCSS plugin: confine Tailwind's Preflight reset to the DOM a consumer renders.
|
|
3
|
+
*
|
|
4
|
+
* A micro-frontend's CSS lands in its host's document. Preflight is written for a page you own:
|
|
5
|
+
* left global it restyles the host's markup, and its `[hidden] { display: none !important }` beats
|
|
6
|
+
* the host's own unlayered `display` rules. This plugin wraps the Preflight rules, and the bare `*`
|
|
7
|
+
* resets apollo-wind adds to `@layer base`, in `@scope (roots) { … }`, so they match only inside the
|
|
8
|
+
* consumer's own root elements.
|
|
9
|
+
*
|
|
10
|
+
* `@scope` is the cheap way to do this. The older `X:where(R1, …, Rn, R1 *, …, Rn *)` wrapper makes
|
|
11
|
+
* Chrome walk every element's ancestor chain once per root for every universal Preflight rule, which
|
|
12
|
+
* showed up as 100+ ms style recalcs in Studio Web (MST-17369). Inside `@scope`, a bare selector
|
|
13
|
+
* matches descendants of the root only, so each rule also gets an `X:where(:scope)` copy for the root
|
|
14
|
+
* itself. `:where()` keeps Preflight at zero specificity, as upstream.
|
|
15
|
+
*
|
|
16
|
+
* Runs after Tailwind. Preflight is found by shape, not source file: Tailwind's production optimise
|
|
17
|
+
* pass re-parses its output, so every rule reports the entry file as its source. The run starts at
|
|
18
|
+
* the `::backdrop` box-sizing rule and ends at `[hidden]:where(:not([hidden=until-found]))`; if a
|
|
19
|
+
* Tailwind update moves the end, the plugin throws rather than scope the rest of the base layer. If
|
|
20
|
+
* the start moves, nothing is scoped: the test against real Tailwind output in `src/styles` is what
|
|
21
|
+
* catches that, so keep it when bumping Tailwind.
|
|
22
|
+
*
|
|
23
|
+
* Two cascade details for consumers:
|
|
24
|
+
*
|
|
25
|
+
* - Scoping proximity ranks below specificity but above source order. A scoped Preflight
|
|
26
|
+
* declaration therefore beats an unscoped one of equal specificity in the same layer, whatever
|
|
27
|
+
* the order, which the old wrapper did not. Override Preflight from an unlayered rule or with
|
|
28
|
+
* higher specificity, not from a later rule in `@layer base`.
|
|
29
|
+
* - Safari 26.0 to 26.3 do not apply `@scope` rules to elements with a UA shadow root (`input`,
|
|
30
|
+
* `textarea`; WebKit 305369, fixed in 26.4). Form controls render with UA styles there. Those
|
|
31
|
+
* versions are outside UiPath's support matrix (Safari: latest version only), and `@supports`
|
|
32
|
+
* cannot detect the bug, so there is no workaround.
|
|
33
|
+
*
|
|
34
|
+
* Usage, in a consumer's postcss config:
|
|
35
|
+
*
|
|
36
|
+
* import apolloWind from '@uipath/apollo-wind/postcss';
|
|
37
|
+
* import scopePreflight from '@uipath/apollo-wind/postcss-scope-preflight';
|
|
38
|
+
* export default { plugins: [...apolloWind.plugins, scopePreflight({ roots: ['my-canvas', '[data-my-portal]'] })] };
|
|
39
|
+
*
|
|
40
|
+
* Anything the consumer portals onto `document.body` must carry one of the roots, or it renders
|
|
41
|
+
* without Preflight. apollo-wind stamps `data-slot` on its components, including what it portals, so
|
|
42
|
+
* `[data-slot]` is a sensible root for apollo-wind consumers.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {object} ScopePreflightOptions
|
|
47
|
+
* @property {string[]} roots
|
|
48
|
+
* Selectors for the elements that own the consumer's DOM: web-component tags, portal markers,
|
|
49
|
+
* `[data-slot]`. Preflight applies to these elements and their descendants.
|
|
50
|
+
* @property {string | false} [documentRoot]
|
|
51
|
+
* Preflight's `html, :host` rule sets the page font from `--font-sans`, a `:root` variable every
|
|
52
|
+
* consumer in a shared document redefines. By default the font declarations stay on the outermost
|
|
53
|
+
* root. Pass the selector of the element the consumer renders when it owns the whole document to
|
|
54
|
+
* apply them there only, so embedded roots inherit the host's font; pass `false` to drop them.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
/** Preflight's first rule: the `*, ::before, ::after, ::backdrop` box-sizing reset. */
|
|
58
|
+
const isPreflightStart = (/** @type {import('postcss').Rule} */ rule) =>
|
|
59
|
+
rule.selectors.some((s) => s.trim() === '::backdrop') &&
|
|
60
|
+
rule.some((d) => d.type === 'decl' && d.prop === 'box-sizing');
|
|
61
|
+
|
|
62
|
+
/** Preflight's last rule. */
|
|
63
|
+
const isPreflightEnd = (/** @type {import('postcss').Rule} */ rule) =>
|
|
64
|
+
/^\[hidden\]:where\(:not\(\[hidden=["']?until-found["']?\]\)\)$/.test(rule.selector.trim());
|
|
65
|
+
|
|
66
|
+
/** @param {string} selector */
|
|
67
|
+
const isDocumentRoot = (selector) => selector === 'html' || selector === ':host';
|
|
68
|
+
|
|
69
|
+
/** The inherited typography `html, :host` sets; on an embedded root these follow the host instead. */
|
|
70
|
+
const DOCUMENT_FONT_PROPS = new Set([
|
|
71
|
+
'font-family',
|
|
72
|
+
'font-feature-settings',
|
|
73
|
+
'font-variation-settings',
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
// Tailwind's production pass prints `::before`/`::after` in their single-colon form; a pseudo-class
|
|
77
|
+
// after one is invalid, and the minifier empties it to `:where()`.
|
|
78
|
+
const LEGACY_PSEUDO_ELEMENT = /^:(before|after|first-line|first-letter)(?![\w-])/;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Inserts `:where(:scope)` into the subject (last compound) of a selector, ahead of any pseudo-element.
|
|
82
|
+
* @param {string} selector
|
|
83
|
+
*/
|
|
84
|
+
export function scopeSelector(selector) {
|
|
85
|
+
const s = selector.trim();
|
|
86
|
+
let depth = 0;
|
|
87
|
+
let subjectStart = 0;
|
|
88
|
+
for (let i = 0; i < s.length; i++) {
|
|
89
|
+
const c = s[i];
|
|
90
|
+
if (c === '(' || c === '[') depth++;
|
|
91
|
+
else if (c === ')' || c === ']') depth--;
|
|
92
|
+
else if (depth === 0 && (c === ' ' || c === '>' || c === '+' || c === '~'))
|
|
93
|
+
subjectStart = i + 1;
|
|
94
|
+
}
|
|
95
|
+
depth = 0;
|
|
96
|
+
for (let i = subjectStart; i < s.length; i++) {
|
|
97
|
+
const c = s[i];
|
|
98
|
+
if (c === '(' || c === '[') depth++;
|
|
99
|
+
else if (c === ')' || c === ']') depth--;
|
|
100
|
+
else if (
|
|
101
|
+
depth === 0 &&
|
|
102
|
+
c === ':' &&
|
|
103
|
+
(s[i + 1] === ':' || LEGACY_PSEUDO_ELEMENT.test(s.slice(i)))
|
|
104
|
+
)
|
|
105
|
+
return `${s.slice(0, i)}:where(:scope)${s.slice(i)}`;
|
|
106
|
+
}
|
|
107
|
+
return `${s}:where(:scope)`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {ScopePreflightOptions} options
|
|
112
|
+
* @returns {import('postcss').Plugin}
|
|
113
|
+
*/
|
|
114
|
+
const scopePreflight = (options) => {
|
|
115
|
+
const roots = options?.roots?.map((r) => r.trim()).filter(Boolean) ?? [];
|
|
116
|
+
if (roots.length === 0)
|
|
117
|
+
throw new Error('scope-preflight: `roots` must list at least one selector');
|
|
118
|
+
const { documentRoot } = options;
|
|
119
|
+
|
|
120
|
+
const ROOTS = roots.join(', ');
|
|
121
|
+
// The outermost root only: `html, :host` sets inherited typography, and on every nested root it
|
|
122
|
+
// would override what the component's parent chose. Flat lists, no `:is()`: minifiers lower `:is()`
|
|
123
|
+
// into `:-webkit-any()`/`:-moz-any()` copies.
|
|
124
|
+
const SCOPE_TOP = `:where(${ROOTS}):where(:not(${roots.map((r) => `${r} *`).join(', ')}))`;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Rewrites one rule for use inside the `@scope` block: a `:where(:scope)` copy for the root, the
|
|
128
|
+
* bare selector for its descendants.
|
|
129
|
+
* @param {import('postcss').Rule} rule
|
|
130
|
+
*/
|
|
131
|
+
const scopeRule = (rule) => {
|
|
132
|
+
const selectors = rule.selectors.map((s) => s.trim());
|
|
133
|
+
rule.selectors = [...selectors.map(scopeSelector), ...selectors];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* `html, :host` becomes a rule on the outermost root, outside the block. Its font declarations move
|
|
138
|
+
* to `documentRoot`, or are dropped, when the consumer asked for that.
|
|
139
|
+
* @param {import('postcss').Rule} rule
|
|
140
|
+
* @param {import('postcss').Helpers} helpers
|
|
141
|
+
*/
|
|
142
|
+
const scopeDocumentRule = (rule, { Rule }) => {
|
|
143
|
+
if (documentRoot !== undefined) {
|
|
144
|
+
const fontDecls = rule.nodes.filter(
|
|
145
|
+
(n) => n.type === 'decl' && DOCUMENT_FONT_PROPS.has(n.prop)
|
|
146
|
+
);
|
|
147
|
+
for (const decl of fontDecls) decl.remove();
|
|
148
|
+
if (documentRoot && fontDecls.length) {
|
|
149
|
+
rule.after(
|
|
150
|
+
new Rule({ selector: `:where(${documentRoot})`, nodes: fontDecls.map((d) => d.clone()) })
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
rule.selector = SCOPE_TOP;
|
|
155
|
+
if (rule.nodes.length === 0) rule.remove();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
postcssPlugin: 'scope-preflight',
|
|
160
|
+
OnceExit(root, helpers) {
|
|
161
|
+
const { AtRule } = helpers;
|
|
162
|
+
root.walkAtRules('layer', (layer) => {
|
|
163
|
+
if (layer.params !== 'base') return;
|
|
164
|
+
// Collect the nodes to scope first, so the walk is not disturbed by the rewrite.
|
|
165
|
+
/** @type {import('postcss').ChildNode[]} */
|
|
166
|
+
const toScope = [];
|
|
167
|
+
let inPreflight = false;
|
|
168
|
+
for (const node of layer.nodes ?? []) {
|
|
169
|
+
if (node.type === 'atrule') {
|
|
170
|
+
if (inPreflight) toScope.push(node);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (node.type !== 'rule') continue;
|
|
174
|
+
if (isPreflightStart(node)) inPreflight = true;
|
|
175
|
+
if (inPreflight) {
|
|
176
|
+
toScope.push(node);
|
|
177
|
+
if (isPreflightEnd(node)) inPreflight = false;
|
|
178
|
+
} else if (node.selector.trim() === '*') {
|
|
179
|
+
// A bare `*` in the base layer (apollo-wind's `border-color`) is the same kind of page-wide reset.
|
|
180
|
+
toScope.push(node);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (inPreflight) {
|
|
184
|
+
// Scoping on to the end of the layer would also wrap the consumer's own base rules
|
|
185
|
+
// (`body { … }` matches nothing inside a root), with no build error. Fail instead.
|
|
186
|
+
throw layer.error(
|
|
187
|
+
'scope-preflight: found the start of Preflight but not its last rule, `[hidden]:where(:not([hidden=until-found]))`. Tailwind may have changed Preflight; update isPreflightEnd.',
|
|
188
|
+
{ plugin: 'scope-preflight' }
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// One `@scope` block per run of consecutive nodes. Chrome resolves scope activations per
|
|
193
|
+
// block, so hundreds of single-rule blocks cost measurably more than a handful.
|
|
194
|
+
/** @type {import('postcss').AtRule | null} */
|
|
195
|
+
let block = null;
|
|
196
|
+
for (const node of toScope) {
|
|
197
|
+
if (!block || node.prev() !== block) {
|
|
198
|
+
block = new AtRule({ name: 'scope', params: `(${ROOTS})` });
|
|
199
|
+
node.before(block);
|
|
200
|
+
}
|
|
201
|
+
if (node.type === 'rule' && node.selectors.map((s) => s.trim()).every(isDocumentRoot)) {
|
|
202
|
+
// Stays outside the block, ahead of it, so its position in the cascade does not change.
|
|
203
|
+
block.before(node);
|
|
204
|
+
scopeDocumentRule(node, helpers);
|
|
205
|
+
// The next node is still adjacent to the block.
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (node.type === 'rule') scopeRule(node);
|
|
209
|
+
else node.walkRules(scopeRule);
|
|
210
|
+
block.append(node);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
scopePreflight.postcss = true;
|
|
217
|
+
|
|
218
|
+
export default scopePreflight;
|