Skip to content

Commit

Permalink
Treeview: Fixed icons on dark themes (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Dec 22, 2020
1 parent 7f23ef3 commit 7266e32
Show file tree
Hide file tree
Showing 19 changed files with 1,052 additions and 29 deletions.
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -11,6 +11,7 @@ examples/
tests/
*.tgz
*.html
*.svg
bower.json
composer.json
dangerfile.js
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Expand Up @@ -18,6 +18,7 @@
"docs",
"tests",
"CNAME",
"*.html"
"*.html",
"*.svg"
]
}
6 changes: 4 additions & 2 deletions gulpfile.js/changelog.js
Expand Up @@ -100,14 +100,16 @@ async function getLog(range) {
}

const revisionRanges = {
nextRelease: git.raw(['describe', '--abbrev=0', '--tags']).then(res => `${res.trim()}..HEAD`)
nextRelease() {
return git.raw(['describe', '--abbrev=0', '--tags']).then(res => `${res.trim()}..HEAD`);
}
};
const strCompare = (a, b) => a.localeCompare(b, 'en');

async function changes() {
const { languages, plugins } = require('../components.js');

const infos = await getLog(revisionRanges.nextRelease);
const infos = await getLog(revisionRanges.nextRelease());

const entries = {
'TODO:': {},
Expand Down
64 changes: 63 additions & 1 deletion gulpfile.js/index.js
Expand Up @@ -7,6 +7,7 @@ const uglify = require('gulp-uglify');
const header = require('gulp-header');
const concat = require('gulp-concat');
const replace = require('gulp-replace');
const webfont = require('webfont').default;
const pump = require('pump');
const util = require('util');
const fs = require('fs');
Expand Down Expand Up @@ -211,8 +212,69 @@ async function languagePlugins() {
}
}

async function treeviewIconFont() {
// List of all icons
// Add new icons to the end of the list.
const iconList = [
'file', 'folder',
'image', 'audio', 'video',
'text', 'code',
'archive', 'pdf',
'excel', 'powerpoint', 'word'
];
const fontName = 'PrismTreeview';

// generate the font
const result = await webfont({
files: iconList.map(n => `plugins/treeview/icons/${n}.svg`),
formats: ['woff'],
fontName,
sort: false
});

/** @type {Buffer} */
const woff = result.woff;
/**
* @type {{ contents: string; srcPath: string; metadata: Metadata }[]}
* @typedef Metadata
* @property {string} path
* @property {string} name
* @property {string[]} unicode
* @property {boolean} renamed
* @property {number} width
* @property {number} height
* */
const glyphsData = result.glyphsData;

const fontFace = `
/* @GENERATED-FONT */
@font-face {
font-family: "${fontName}";
/**
* This font is generated from the .svg files in the \`icons\` folder. See the \`treeviewIconFont\` function in
* \`gulpfile.js/index.js\` for more information.
*
* Use the following escape sequences to refer to a specific icon:
*
* - ${glyphsData.map(({ metadata }) => {
const codePoint = metadata.unicode[0].codePointAt(0);
return `\\${codePoint.toString(16)} ${metadata.name}`;
}).join('\n\t * - ')}
*/
src: url("data:application/font-woff;base64,${woff.toString('base64')}")
format("woff");
}
`.trim();

const cssPath = 'plugins/treeview/prism-treeview.css';
const fontFaceRegex = /\/\*\s*@GENERATED-FONT\s*\*\/\s*@font-face\s*\{(?:[^{}/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/)*\}/;

const css = fs.readFileSync(cssPath, 'utf-8');
fs.writeFileSync(cssPath, css.replace(fontFaceRegex, fontFace), 'utf-8');
}

const components = minifyComponents;
const plugins = series(languagePlugins, minifyPlugins);
const plugins = series(languagePlugins, treeviewIconFont, minifyPlugins);


module.exports = {
Expand Down

0 comments on commit 7266e32

Please sign in to comment.