Skip to content

Commit f66ef73

Browse files
authored
Merge pull request #144 from umbraco/bugfix/replace-postcss-custom-properties-fallback-with-local-version
2 parents d88b12f + 2a0a3c2 commit f66ef73

File tree

13 files changed

+13432
-3790
lines changed

13 files changed

+13432
-3790
lines changed

.storybook/main.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const tsconfigPaths = require('vite-tsconfig-paths').default;
2-
const processLitCSSPlugin =
3-
require('../scripts/vite.processLitCSSPlugin').default;
42

53
module.exports = {
64
stories: ['../packages/**/*.story.ts'],
@@ -10,9 +8,14 @@ module.exports = {
108
'@storybook/addon-a11y',
119
],
1210
core: { builder: 'storybook-builder-vite' },
11+
staticDirs: ['./images'],
12+
1313
async viteFinal(config, { configType }) {
1414
// customize the Vite config here
1515

16+
const processLitCSSPlugin = (
17+
await import('../scripts/processLitCSSPlugin.mjs')
18+
).default;
1619
config.plugins.push(processLitCSSPlugin());
1720

1821
if (configType === 'DEVELOPMENT') {

package-lock.json

Lines changed: 13228 additions & 3690 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"format:prettier": "prettier \"**/*.js\" \"**/*.ts\" \"**/*.mjs\" --write --ignore-path .gitignore",
2626
"lint": "npm run lint:eslint && npm run lint:prettier",
2727
"format": "npm run format:eslint && npm run format:prettier",
28-
"storybook": "npm run bootstrap && npm run storybook:analyze && start-storybook -p 6006 -s ./.storybook/images",
29-
"storybook:build": "npm run bootstrap && npm run storybook:analyze && build-storybook -s ./.storybook/images",
28+
"storybook": "npm run bootstrap && npm run storybook:analyze && start-storybook -p 6006",
29+
"storybook:build": "npm run bootstrap && npm run storybook:analyze && build-storybook",
3030
"storybook:analyze": "web-component-analyzer **/*.element.ts --outFile custom-elements.json",
3131
"test": "web-test-runner --coverage",
3232
"test:watch": "web-test-runner --watch",
@@ -91,7 +91,6 @@
9191
"postcss-cli": "9.0.1",
9292
"postcss-color-function": "4.1.0",
9393
"postcss-custom-properties": "12.0.0",
94-
"postcss-custom-properties-fallback": "1.0.1",
9594
"postcss-jsx": "0.36.4",
9695
"postcss-load-config": "3.1.0",
9796
"postcss-url": "^10.1.3",

packages/rollup-package.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
33
import minifyHTML from 'rollup-plugin-minify-html-literals';
44
import { readPackageJson } from '../scripts/modify-pkgjson.mjs';
55
import rollupPostcss from 'rollup-plugin-postcss';
6-
import postcssCustomPropertiesFallback from 'postcss-custom-properties-fallback';
6+
import postcssCustomPropertiesFallback from '../scripts/postcss-custom-properties-fallback/plugin.mjs';
77
import path from 'path';
8-
import processLitCSSPlugin from '../scripts/rollup.processLitCSSPlugin.mjs';
8+
import processLitCSSPlugin from '../scripts/processLitCSSPlugin.mjs';
99
import importCss from 'rollup-plugin-import-css';
1010

1111
// @ts-ignore-start

packages/uui-box/lib/uui-box.element.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export class UUIBoxElement extends LitElement {
1515
css`
1616
:host {
1717
display: block;
18-
/* TODO: fix automatic fallback values for shadows shadows.*/
19-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
18+
box-shadow: var(--uui-shadow-depth-1);
2019
border-radius: var(--uui-border-radius);
2120
background-color: var(--uui-interface-surface);
2221
}

packages/uui-card/lib/uui-card.element.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ export class UUICardElement extends SelectOnlyMixin(
2727
width: 100%;
2828
justify-content: center;
2929
box-sizing: border-box;
30-
/* TODO: fix automatic fallback values for shadows before we use them: var(--uui-shadow-depth-1)*/
31-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
30+
box-shadow: var(--uui-shadow-depth-1);
3231
border-radius: var(--uui-border-radius);
3332
min-height: var(--uui-layout-medium);
3433
background-color: var(--uui-interface-surface);

packages/uui-css/scripts/cache-custom-properties.mjs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ export const CacheCustomProperties = async masterCSSPath => {
3535

3636
let json = JSON.stringify(fileData);
3737

38-
try {
39-
await fs.writeFile(
40-
'./custom-properties.cjs',
41-
`module.exports = ${json};`,
42-
'utf8'
43-
);
44-
} catch (err) {
45-
console.error(err);
46-
}
47-
48-
// Second file for ESM, TODO: fix so we can use the same file in both cases.
4938
try {
5039
await fs.writeFile(
5140
'./custom-properties.module.js',

packages/uui-dialog/lib/uui-dialog.element.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ export class UUIDialogElement extends LitElement {
2020
var(--uui-interface-surface)
2121
);
2222
23-
/* TODO: fix automatic fallback values for shadows shadows. var(--uui-shadow-depth-5) */
24-
box-shadow: var(
25-
--uui-dialog-box-shadow,
26-
0 19px 38px rgba(0, 0, 0, 0.3),
27-
0 15px 12px rgba(0, 0, 0, 0.22)
28-
);
23+
box-shadow: var(--uui-shadow-depth-5);
2924
border-radius: var(
3025
--uui-dialog-border-radius,
3126
calc(var(--uui-border-radius) * 2)

packages/uui-toast-notification/lib/uui-toast-notification.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class UUIToastNotificationElement extends LitElement {
6767
display: block;
6868
6969
box-sizing: border-box;
70-
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.21);
70+
box-shadow: var(--uui-shadow-depth-1);
7171
background-color: var(--uui-interface-surface);
7272
padding: var(--uui-size-layout-1);
7373
padding-right: var(--uui-size-layout-1);
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import * as postcss from 'postcss';
4+
import { parse } from 'postcss-values-parser';
5+
6+
async function getCustomPropertiesFromCSSFile(from) {
7+
const css = await readFile(from); // eslint-disable-next-line no-unused-vars
8+
9+
postcss.parse(css, {
10+
from,
11+
});
12+
throw new Error('Importing from CSS files not supported yet'); //return getCustomPropertiesFromRoot(root, { preserve: true });
13+
}
14+
/* Get Custom Properties from Object
15+
/* ========================================================================== */
16+
17+
function getCustomPropertiesFromObject(object) {
18+
const customProperties = Object.assign(
19+
{},
20+
Object(object).customProperties,
21+
Object(object)['custom-properties']
22+
);
23+
24+
for (const key in customProperties) {
25+
customProperties[key] = parse(String(customProperties[key])).nodes;
26+
}
27+
28+
return customProperties;
29+
}
30+
/* Get Custom Properties from JSON file
31+
/* ========================================================================== */
32+
33+
async function getCustomPropertiesFromJSONFile(from) {
34+
const object = await readJSON(from);
35+
return getCustomPropertiesFromObject(object);
36+
}
37+
/* Get Custom Properties from JS file
38+
/* ========================================================================== */
39+
40+
async function getCustomPropertiesFromJSFile(from) {
41+
const object = await import(from);
42+
43+
return getCustomPropertiesFromObject(object);
44+
}
45+
46+
export default function getCustomPropertiesFromImports(sources) {
47+
return sources
48+
.map(source => {
49+
if (source instanceof Promise) {
50+
return source;
51+
} else if (source instanceof Function) {
52+
return source();
53+
} // read the source as an object
54+
55+
const opts =
56+
source === Object(source)
57+
? source
58+
: {
59+
from: String(source),
60+
}; // skip objects with Custom Properties
61+
62+
if (opts.customProperties || opts['custom-properties']) {
63+
return opts;
64+
} // source pathname
65+
66+
const from = path.resolve(String(opts.from || '')); // type of file being read from
67+
68+
const type = (opts.type || path.extname(from).slice(1)).toLowerCase();
69+
return {
70+
type,
71+
from,
72+
};
73+
})
74+
.reduce(async (customProperties, source) => {
75+
const { type, from } = await source;
76+
77+
if (type === 'css') {
78+
return Object.assign(
79+
await customProperties,
80+
await getCustomPropertiesFromCSSFile(from)
81+
);
82+
}
83+
84+
if (type === 'js') {
85+
return Object.assign(
86+
await customProperties,
87+
await getCustomPropertiesFromJSFile(from)
88+
);
89+
}
90+
91+
if (type === 'json') {
92+
return Object.assign(
93+
await customProperties,
94+
await getCustomPropertiesFromJSONFile(from)
95+
);
96+
}
97+
98+
return Object.assign(
99+
await customProperties,
100+
await getCustomPropertiesFromObject(await source)
101+
);
102+
}, {});
103+
}
104+
105+
const readFile = from =>
106+
new Promise((resolve, reject) => {
107+
fs.readFile(from, 'utf8', (error, result) => {
108+
if (error) {
109+
reject(error);
110+
} else {
111+
resolve(result);
112+
}
113+
});
114+
});
115+
116+
const readJSON = async from => JSON.parse(await readFile(from));
117+
//# sourceMappingURL=import-from.js.map

0 commit comments

Comments
 (0)