mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-11-20 03:25:52 +01:00
Split code so that it can be reused
This commit is contained in:
parent
2f3db89e0a
commit
c5f4a75d4b
@ -17,6 +17,7 @@ limitations under the License.
|
||||
import {readFileSync, mkdirSync, writeFileSync} from "fs";
|
||||
import {resolve} from "path";
|
||||
import {h32} from "xxhashjs";
|
||||
import {getColoredSvgString} from "./svg-colorizer.js";
|
||||
|
||||
function createHash(content) {
|
||||
const hasher = new h32(0);
|
||||
@ -32,11 +33,7 @@ function createHash(content) {
|
||||
*/
|
||||
export function buildColorizedSVG(svgLocation, primaryColor, secondaryColor) {
|
||||
const svgCode = readFileSync(svgLocation, { encoding: "utf8"});
|
||||
let coloredSVGCode = svgCode.replaceAll("#ff00ff", primaryColor);
|
||||
coloredSVGCode = coloredSVGCode.replaceAll("#00ffff", secondaryColor);
|
||||
if (svgCode === coloredSVGCode) {
|
||||
throw new Error("svg-colorizer made no color replacements! The input svg should only contain colors #ff00ff (primary, case-sensitive) and #00ffff (secondary, case-sensitive).");
|
||||
}
|
||||
const coloredSVGCode = getColoredSvgString(svgCode, primaryColor, secondaryColor);
|
||||
const fileName = svgLocation.match(/.+[/\\](.+\.svg)/)[1];
|
||||
const outputName = `${fileName.substring(0, fileName.length - 4)}-${createHash(coloredSVGCode)}.svg`;
|
||||
const outputPath = resolve(__dirname, "../../.tmp");
|
24
scripts/postcss/svg-colorizer.js
Normal file
24
scripts/postcss/svg-colorizer.js
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
export function getColoredSvgString(svgString, primaryColor, secondaryColor) {
|
||||
let coloredSVGCode = svgString.replaceAll("#ff00ff", primaryColor);
|
||||
coloredSVGCode = coloredSVGCode.replaceAll("#00ffff", secondaryColor);
|
||||
if (svgString === coloredSVGCode) {
|
||||
throw new Error("svg-colorizer made no color replacements! The input svg should only contain colors #ff00ff (primary, case-sensitive) and #00ffff (secondary, case-sensitive).");
|
||||
}
|
||||
return coloredSVGCode;
|
||||
}
|
@ -8,7 +8,7 @@ const path = require("path");
|
||||
const manifest = require("./package.json");
|
||||
const version = manifest.version;
|
||||
const compiledVariables = new Map();
|
||||
import {buildColorizedSVG as replacer} from "./scripts/postcss/svg-colorizer.mjs";
|
||||
import {buildColorizedSVG as replacer} from "./scripts/postcss/svg-builder.mjs";
|
||||
import {derive} from "./scripts/postcss/color.mjs";
|
||||
|
||||
const commonOptions = {
|
||||
|
Loading…
Reference in New Issue
Block a user