source: frontend/node_modules/postcss-normalize/index.cjs

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 8.5 KB
Line 
1var postcssBrowserComments = require('postcss-browser-comments');
2var Module = require('module');
3var path = require('path');
4
5var fs = require('fs');
6var postcss = require('postcss');
7
8function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
10var postcssBrowserComments__default = /*#__PURE__*/_interopDefaultLegacy(postcssBrowserComments);
11var Module__default = /*#__PURE__*/_interopDefaultLegacy(Module);
12var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
13var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
14var postcss__default = /*#__PURE__*/_interopDefaultLegacy(postcss);
15
16const assign = (...objects) => Object.assign(...objects);
17const create = (...objects) => assign(Object.create(null), ...objects);
18
19const currentFilename = __filename;
20const currentDirname = path__default['default'].dirname(currentFilename); // get resolved filenames for normalize.css
21
22const normalizeCSS = resolve('@csstools/normalize.css');
23const normalizeDir = path__default['default'].dirname(normalizeCSS);
24const normalizeOpinionatedCSS = path__default['default'].join(normalizeDir, 'opinionated.css'); // get resolved filenames for sanitize.css
25
26const sanitizeCSS = resolve('sanitize.css');
27const sanitizeDir = path__default['default'].dirname(sanitizeCSS);
28const sanitizeAssetsCSS = path__default['default'].join(sanitizeDir, 'assets.css');
29const sanitizeFormsCSS = path__default['default'].join(sanitizeDir, 'forms.css');
30const sanitizeReduceMotionCSS = path__default['default'].join(sanitizeDir, 'reduce-motion.css');
31const sanitizeTypographyCSS = path__default['default'].join(sanitizeDir, 'typography.css');
32const sanitizeSystemUiCSS = path__default['default'].join(sanitizeDir, 'system-ui.css');
33const sanitizeUiMonospace = path__default['default'].join(sanitizeDir, 'ui-monospace.css'); // export a hashmap of css library filenames
34
35const parsableFilenames = create({
36 [normalizeCSS]: true,
37 [normalizeOpinionatedCSS]: true,
38 [sanitizeCSS]: true,
39 [sanitizeAssetsCSS]: true,
40 [sanitizeFormsCSS]: true,
41 [sanitizeReduceMotionCSS]: true,
42 [sanitizeTypographyCSS]: true,
43 [sanitizeSystemUiCSS]: true,
44 [sanitizeUiMonospace]: true
45}); // export a hashmap of css library filenames by id
46
47const resolvedFilenamesById = create({
48 'normalize': [normalizeCSS],
49 'normalize/opinionated': [normalizeOpinionatedCSS],
50 'normalize/*': [normalizeOpinionatedCSS],
51 'sanitize': [sanitizeCSS],
52 'sanitize/assets': [sanitizeAssetsCSS],
53 'sanitize/forms': [sanitizeCSS, sanitizeFormsCSS],
54 'sanitize/page': [sanitizeAssetsCSS],
55 // deprecated; remaining for v10.0.0 compatibility
56 'sanitize/reduce-motion': [sanitizeCSS, sanitizeReduceMotionCSS],
57 'sanitize/system-ui': [sanitizeCSS, sanitizeSystemUiCSS],
58 'sanitize/typography': [sanitizeCSS, sanitizeTypographyCSS],
59 'sanitize/ui-monospace': [sanitizeCSS, sanitizeUiMonospace],
60 'sanitize/*': [sanitizeCSS, sanitizeFormsCSS]
61}); // get the resolved filename of a package/module
62
63function resolve(id) {
64 return resolve[id] = resolve[id] || Module__default['default']._resolveFilename(id, {
65 id: currentFilename,
66 filename: currentFilename,
67 paths: Module__default['default']._nodeModulePaths(currentDirname)
68 });
69}
70
71const cache$1 = create();
72async function readFile(filename) {
73 filename = path__default['default'].resolve(filename);
74 cache$1[filename] = cache$1[filename] || create();
75 return new Promise((resolve, reject) => fs__default['default'].stat(filename, (statsError, {
76 mtime
77 }) => statsError ? reject(statsError) : mtime === cache$1[filename].mtime ? resolve(cache$1[filename].data) : fs__default['default'].readFile(filename, 'utf8', (readFileError, data) => readFileError ? reject(readFileError) : resolve((cache$1[filename] = {
78 data,
79 mtime
80 }).data))));
81}
82
83const cache = create(null);
84var parse = ((filename, transformer) => readFile(filename).then( // cache the parsed css root
85css => cache[css] = cache[css] || postcss__default['default'].parse(css, {
86 from: filename
87})).then( // clone the cached root
88root => root.clone()).then( // transform the cloned root
89clone => Promise.resolve(transformer(clone)).then( // resolve the cloned root
90() => clone)));
91
92var postcssImportNormalize = (commentsTransformer => opts => {
93 opts = create(opts); // return an postcss-import configuration
94
95 return create({
96 load(filename, importOptions) {
97 return filename in parsableFilenames // parse the file (the file and css are conservatively cached)
98 ? parse(filename, commentsTransformer).then(root => root.toResult({
99 to: filename,
100 map: true
101 }).css) : typeof opts.load === 'function' // otherwise, use the override loader
102 ? opts.load.call(null, filename, importOptions) // otherwise, return the (conservatively cached) contents of the file
103 : readFile(filename);
104 },
105
106 resolve(id, basedir, importOptions) {
107 // get the css id by removing css extensions
108 const cssId = id.replace(cssExtRegExp$1, '');
109 return cssId in resolvedFilenamesById // return the known resolved path for the css id
110 ? resolvedFilenamesById[cssId] : typeof opts.resolve === 'function' // otherwise, use the override resolver
111 ? opts.resolve.call(null, id, basedir, importOptions) // otherwise, return the id to be resolved by postcss-import
112 : id;
113 }
114
115 });
116});
117const cssExtRegExp$1 = /\.css\b/g;
118
119const postcssPlugin = (commentsTransformer, opts) => root => {
120 const promises = [];
121 const insertedFilenames = {}; // use @import insertion point
122
123 root.walkAtRules(importRegExp, atrule => {
124 // get name as a fallback value for the library (e.g. @import-normalize is like @import "normalize.css")
125 const name = atrule.name.match(importRegExp)[1]; // get url from "library", 'library', url("library"), url('library'), or the fallback value
126
127 const url = (atrule.params.match(paramsRegExp) || []).slice(1).find(part => part) || name;
128
129 if (url) {
130 // get the css id by removing css extensions
131 const cssId = url.replace(cssExtRegExp, '');
132
133 if (cssId in resolvedFilenamesById) {
134 // promise the library import is replaced with its contents
135 promises.push(Promise.all(resolvedFilenamesById[cssId].filter( // ignore filenames that have already been inserted
136 filename => insertedFilenames[filename] = opts.allowDuplicates || !(filename in insertedFilenames)).map( // parse the file (the file and css are conservatively cached)
137 filename => parse(filename, commentsTransformer))).then(roots => {
138 if (roots.length) {
139 // combine all the library nodes returned by the parsed files
140 const nodes = roots.reduce((all, root) => all.concat(root.nodes), []); // replace the import with all the library nodes
141
142 atrule.replaceWith(...nodes);
143 }
144 }));
145 }
146 }
147 });
148 return Promise.all([].concat( // promise the library imports are replaced with their contents
149 promises, // promise certain libraries are prepended
150 Promise.all([].concat(opts.forceImport || []).reduce( // filter the id to be a known id or boolean true
151 (all, id) => {
152 if (id === true) {
153 all.push(...resolvedFilenamesById.normalize);
154 } else if (typeof id === 'string') {
155 const cssId = id.replace(cssExtRegExp, '');
156
157 if (cssId in resolvedFilenamesById) {
158 all.push(...resolvedFilenamesById[cssId]);
159 }
160 }
161
162 return all;
163 }, []).filter( // ignore filenames that have already been inserted
164 filename => insertedFilenames[filename] = opts.allowDuplicates || !(filename in insertedFilenames)).map( // parse the file (the file and css are conservatively cached)
165 filename => parse(filename, commentsTransformer))).then(roots => {
166 if (roots.length) {
167 // combine all the library nodes returned by the parsed files
168 const nodes = roots.reduce((all, root) => all.concat(root.nodes), []); // prepend the stylesheet with all the library nodes
169
170 root.prepend(...nodes);
171 }
172 })));
173};
174
175const cssExtRegExp = /\.css\b/g;
176const importRegExp = /^import(?:-(normalize|sanitize))?$/;
177const paramsRegExp = /^\s*(?:url\((?:"(.+)"|'(.+)')\)|"(.+)"|'(.+)')[\W\w]*$/;
178
179const plugin = opts => {
180 opts = create(opts);
181 const commentsTransformer = postcssBrowserComments__default['default'](opts).Once;
182 const normalizeTransformer = postcssPlugin(commentsTransformer, opts);
183 const postcssImportConfig = postcssImportNormalize(commentsTransformer);
184 return {
185 postcssPlugin: 'postcss-normalize',
186
187 Once(root) {
188 return normalizeTransformer(root);
189 },
190
191 postcssImport: postcssImportConfig
192 };
193};
194
195plugin.postcss = true;
196
197module.exports = plugin;
Note: See TracBrowser for help on using the repository browser.