Merge branch 'develop' into sort-imports

Signed-off-by: Aaron Raimist <aaron@raim.ist>
pull/21833/head
Aaron Raimist 2021-12-09 09:13:26 +00:00
commit ba0f15bbb5
5 changed files with 72 additions and 26 deletions

View File

@ -69,7 +69,7 @@ jobs:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 1 timeout-minutes: 1
- name: Edit PR Description - name: Edit PR Description
uses: velas/pr-description@v1.0.1 uses: Beakyn/gha-comment-pull-request@2167a7aee24f9e61ce76a23039f322e49a990409
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:

View File

@ -105,3 +105,23 @@ $roomtopic-color: $secondary-content;
.mx_ThemeChoicePanel > .mx_ThemeSelectors > .mx_StyledRadioButton.mx_StyledRadioButton_disabled { .mx_ThemeChoicePanel > .mx_ThemeSelectors > .mx_StyledRadioButton.mx_StyledRadioButton_disabled {
color: $primary-content; color: $primary-content;
} }
.mx_RoomSearch {
&.mx_RoomSearch_focused, &.mx_RoomSearch_hasQuery {
.mx_RoomSearch_clearButton {
&::before {
background-color: $background !important;
}
}
}
}
.mx_PollCreateDialog {
.mx_PollCreateDialog_option {
.mx_PollCreateDialog_removeOption {
&::before {
background-color: $background !important;
}
}
}
}

View File

@ -420,11 +420,18 @@ export default class HTMLExporter extends Exporter {
this.updateProgress(`Fetched ${res.length} events in ${(fetchEnd - fetchStart)/1000}s`, true, false); this.updateProgress(`Fetched ${res.length} events in ${(fetchEnd - fetchStart)/1000}s`, true, false);
this.updateProgress("Creating HTML..."); this.updateProgress("Creating HTML...");
const usedClasses = new Set<string>();
for (let page = 0; page < res.length / 1000; page++) { for (let page = 0; page < res.length / 1000; page++) {
const html = await this.createHTML(res, page * 1000); const html = await this.createHTML(res, page * 1000);
const document = new DOMParser().parseFromString(html, "text/html");
document.querySelectorAll("*").forEach(element => {
element.classList.forEach(c => usedClasses.add(c));
});
this.addFile(`messages${page ? page + 1 : ""}.html`, new Blob([html])); this.addFile(`messages${page ? page + 1 : ""}.html`, new Blob([html]));
} }
const exportCSS = await getExportCSS();
const exportCSS = await getExportCSS(usedClasses);
this.addFile("css/style.css", new Blob([exportCSS])); this.addFile("css/style.css", new Blob([exportCSS]));
this.addFile("js/script.js", new Blob([exportJS])); this.addFile("js/script.js", new Blob([exportJS]));

View File

@ -18,33 +18,52 @@ limitations under the License.
import customCSS from "!!raw-loader!./exportCustomCSS.css"; import customCSS from "!!raw-loader!./exportCustomCSS.css";
const getExportCSS = async (): Promise<string> => { const cssSelectorTextClassesRegex = /\.[\w-]+/g;
const stylesheets: string[] = [];
document.querySelectorAll('link[rel="stylesheet"]').forEach((e: any) => { function mutateCssText(css: string): string {
if (e.href.endsWith("bundle.css") || e.href.endsWith("theme-light.css")) { // replace used fonts so that we don't have to bundle Inter & Inconsalata
stylesheets.push(e.href); return css
} .replace(
/font-family: ?(Inter|'Inter'|"Inter")/g,
`font-family: -apple-system, BlinkMacSystemFont, avenir next,
avenir, segoe ui, helvetica neue, helvetica, Ubuntu, roboto, noto, arial, sans-serif`,
)
.replace(
/font-family: ?Inconsolata/g,
"font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace",
);
}
// naively culls unused css rules based on which classes are present in the html,
// doesn't cull rules which won't apply due to the full selector not matching but gets rid of a LOT of cruft anyway.
const getExportCSS = async (usedClasses: Set<string>): Promise<string> => {
// only include bundle.css and the data-mx-theme=light styling
const stylesheets = Array.from(document.styleSheets).filter(s => {
return s.href?.endsWith("bundle.css") || (s.ownerNode as HTMLStyleElement).dataset.mxTheme === "light";
}); });
let CSS = "";
let css = "";
for (const stylesheet of stylesheets) { for (const stylesheet of stylesheets) {
const res = await fetch(stylesheet); for (const rule of stylesheet.cssRules) {
const innerText = await res.text(); if (rule instanceof CSSFontFaceRule) continue; // we don't want to bundle any fonts
CSS += innerText;
const selectorText = (rule as CSSStyleRule).selectorText;
// only skip the rule if all branches (,) of the selector are redundant
if (selectorText?.split(",").every(selector => {
const classes = selector.match(cssSelectorTextClassesRegex);
if (classes && !classes.every(c => usedClasses.has(c.substring(1)))) {
return true; // signal as a redundant selector
}
})) {
continue; // skip this rule as it is redundant
}
css += mutateCssText(rule.cssText) + "\n";
}
} }
const fontFaceRegex = /@font-face {.*?}/sg;
CSS = CSS.replace(fontFaceRegex, ''); return css + customCSS;
CSS = CSS.replace(
/font-family: (Inter|'Inter')/g,
`font-family: -apple-system, BlinkMacSystemFont, avenir next,
avenir, segoe ui, helvetica neue, helvetica, Ubuntu, roboto, noto, arial, sans-serif`,
);
CSS = CSS.replace(
/font-family: Inconsolata/g,
"font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace",
);
return CSS + customCSS;
}; };
export default getExportCSS; export default getExportCSS;

View File

@ -13,7 +13,7 @@
"declaration": true, "declaration": true,
"jsx": "react", "jsx": "react",
"lib": [ "lib": [
"es2019", "es2020",
"dom", "dom",
"dom.iterable" "dom.iterable"
], ],