summaryrefslogtreecommitdiff
path: root/src/compiler/transform/postcss-scoped-styles
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/transform/postcss-scoped-styles')
-rw-r--r--src/compiler/transform/postcss-scoped-styles/index.ts106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/compiler/transform/postcss-scoped-styles/index.ts b/src/compiler/transform/postcss-scoped-styles/index.ts
deleted file mode 100644
index 23350869c..000000000
--- a/src/compiler/transform/postcss-scoped-styles/index.ts
+++ /dev/null
@@ -1,106 +0,0 @@
-import { Declaration, Plugin } from 'postcss';
-
-interface AstroScopedOptions {
- className: string;
-}
-
-interface Selector {
- start: number;
- end: number;
- value: string;
-}
-
-const CSS_SEPARATORS = new Set([' ', ',', '+', '>', '~']);
-const KEYFRAME_PERCENT = /\d+\.?\d*%/;
-
-/** HTML tags that should never get scoped classes */
-export const NEVER_SCOPED_TAGS = new Set<string>(['base', 'body', 'font', 'frame', 'frameset', 'head', 'html', 'link', 'meta', 'noframes', 'noscript', 'script', 'style', 'title']);
-
-/**
- * Scope Rules
- * Given a selector string (`.btn>span,.nav>span`), add an additional CSS class to every selector (`.btn.myClass>span.myClass,.nav.myClass>span.myClass`)
- * @param {string} selector The minified selector string to parse. Cannot contain arbitrary whitespace (other than child selector syntax).
- * @param {string} className The CSS class to apply.
- */
-export function scopeRule(selector: string, className: string) {
- // if this is a keyframe keyword, return original selector
- if (selector === 'from' || selector === 'to' || KEYFRAME_PERCENT.test(selector)) {
- return selector;
- }
-
- // For everything else, parse & scope
- const c = className.replace(/^\.?/, '.'); // make sure class always has leading '.'
- const selectors: Selector[] = [];
- let ss = selector; // final output
-
- // Pass 1: parse selector string; extract top-level selectors
- {
- let start = 0;
- let lastValue = '';
- let parensOpen = false;
- for (let n = 0; n < ss.length; n++) {
- const isEnd = n === selector.length - 1;
- if (selector[n] === '(') parensOpen = true;
- if (selector[n] === ')') parensOpen = false;
- if (isEnd || (parensOpen === false && CSS_SEPARATORS.has(selector[n]))) {
- lastValue = selector.substring(start, isEnd ? undefined : n);
- if (!lastValue) continue;
- selectors.push({ start, end: isEnd ? n + 1 : n, value: lastValue });
- start = n + 1;
- }
- }
- }
-
- // Pass 2: starting from end, transform selectors w/ scoped class
- for (let i = selectors.length - 1; i >= 0; i--) {
- const { start, end, value } = selectors[i];
- const head = ss.substring(0, start);
- const tail = ss.substring(end);
-
- // replace '*' with className
- if (value === '*') {
- ss = head + c + tail;
- continue;
- }
-
- // leave :global() alone!
- if (value.startsWith(':global(')) {
- ss =
- head +
- ss
- .substring(start, end)
- .replace(/^:global\(/, '')
- .replace(/\)$/, '') +
- tail;
- continue;
- }
-
- // don‘t scope body, title, etc.
- if (NEVER_SCOPED_TAGS.has(value)) {
- ss = head + value + tail;
- continue;
- }
-
- // scope everything else
- let newSelector = ss.substring(start, end);
- const pseudoIndex = newSelector.indexOf(':');
- if (pseudoIndex > 0) {
- // if there‘s a pseudoclass (:focus)
- ss = head + newSelector.substring(start, pseudoIndex) + c + newSelector.substr(pseudoIndex) + tail;
- } else {
- ss = head + newSelector + c + tail;
- }
- }
-
- return ss;
-}
-
-/** PostCSS Scope plugin */
-export default function astroScopedStyles(options: AstroScopedOptions): Plugin {
- return {
- postcssPlugin: '@astro/postcss-scoped-styles',
- Rule(rule) {
- rule.selector = scopeRule(rule.selector, options.className);
- },
- };
-}
class='logmsg'> 2021-08-01Delete COMMUNITY.mdGravatar Fred K. Schott 1-15/+0 2021-07-31fix bad merge from outdated layoutGravatar Fred K. Schott 3-3/+3 2021-07-30Fixes throwing 404 (#894)Gravatar Maciej Palmowski 1-3/+0 * Fixes throwing 404 * Update index.css Co-authored-by: Fred K. Schott <fkschott@gmail.com> 2021-07-30small cleanup to installation docsGravatar Fred K. Schott 1-9/+6 2021-07-30add finnish to language selectorGravatar Fred K. Schott 2-2/+5 2021-07-30move finnish translations to fiGravatar Fred K. Schott 3-0/+0 2021-07-30WIP: Documentation in Finnish (#837)Gravatar Vesa Piittinen 3-0/+201 * Initial Finnish getting-started.md * Initial Finnish `quick-start.md` * Missing word * Use a different test path name * Initial Finnish `installation.md` * Sync with `installation.md` * WIP Finnish island-architecture.md * Fix some sillyness * Delete island-architecture.md Co-authored-by: Fred K. Schott <fkschott@gmail.com> 2021-07-30📘 DOC: Add PostCSS configuration on Astro (#947)Gravatar Diogo Felix 1-0/+27 2021-07-30fix styling URL linkGravatar Fred K. Schott 1-1/+1 2021-07-31[ci] yarn formatGravatar FredKSchott 6-36/+61 2021-07-30fix styling guide (#961)Gravatar Rubens de Melo 1-1/+1 * fix styling guide fix styling guide * remove /docs remove /docs 2021-07-30Add svelte file extension to tailwind puge configuration. (#964)Gravatar allanvobraun 1-1/+1 Self explanatory. 2021-07-30Docs site cleanup (#948)Gravatar Fred K. Schott 57-730/+739 * add language selector * docs site cleanup * review feedback * code review comments 2021-07-30Ascii quotes (#928)Gravatar Marcus Otterström 8-63/+63 2021-07-30forced degit template extraction in case of non empty installation directory ↵Gravatar mash-graz 2-23/+7 (#937) * revert recursive file removal routine * forced degit overwrite without previous file removal * add changeset 2021-07-30Version Packages (#940)Gravatar github-actions[bot] 26-34/+45 Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2021-07-30[ci] yarn formatGravatar matthewp 1-1/+1 2021-07-30Fix Vue components nesting and add tests (#924)Gravatar Bartek Igielski 10-34/+171 * Allow @vue/server-renderer to be processed * Bump @vue/server-renderer version * Create twenty-coats-talk.md * Bump Vue packages version to get ESM builds * Add Vue components tests * Create shaggy-pugs-raise.md * Delete shaggy-pugs-raise.md 2021-07-30[ci] yarn formatGravatar FredKSchott 1-1/+0 2021-07-30Fix typos and clarify docs (#880)Gravatar Marcus Otterström 4-4/+5 * Add more missing words * Add missing dot * Add another missing dot * Clarify what optimized css means (discussed on Discord) * Remove oxford comma Co-authored-by: Fred K. Schott <fkschott@gmail.com> 2021-07-29move translated nl docsGravatar Fred K. Schott 3-1/+1