Skip to content

Commit 77c5628

Browse files
authored
Merge pull request #343 from gtt-project/dkastl/issue342
Improves font icon handling
2 parents 4c0b533 + 622e5e0 commit 77c5628

File tree

8 files changed

+36
-60
lines changed

8 files changed

+36
-60
lines changed
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
<%= tag.meta(
2-
name: 'gtt-font-custom-icons',
3-
content: asset_path('plugin_assets/redmine_gtt/custom-icons.woff2')) %>
4-
5-
<%= tag.meta(
6-
name: 'gtt-font-mdi-webfont',
7-
content: asset_path('plugin_assets/redmine_gtt/materialdesignicons-webfont.woff2')) %>
1+
<% # Header hook %>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
"dependencies": {
2323
"@juggle/resize-observer": "^3.4.0",
2424
"@mdi/font": "^7.4.47",
25-
"dompurify": "^3.2.2",
25+
"dompurify": "^3.2.3",
2626
"fontfaceobserver": "^2.3.0",
2727
"geojson": "^0.5.0",
2828
"ol": "^10.3.1",
2929
"ol-ext": "^4.0.24",
30-
"ol-mapbox-style": "^12.3.5"
30+
"ol-mapbox-style": "^12.4.0"
3131
},
3232
"devDependencies": {
3333
"@types/dompurify": "^3.2.0",
@@ -38,7 +38,7 @@
3838
"@types/jqueryui": "^1.12.23",
3939
"@types/ol-ext": "npm:@siedlerchr/types-ol-ext",
4040
"css-loader": "^7.1.2",
41-
"sass": "^1.82.0",
41+
"sass": "^1.83.0",
4242
"sass-loader": "^16.0.4",
4343
"style-loader": "^4.0.0",
4444
"ts-loader": "^9.5.1",

src/styles/icons/custom/custom-icons-def.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,7 @@ const iconMappings: { [key: string]: any } = {
88
'waste': '\uf104'
99
};
1010

11-
// Read the meta tag for custom-icons
12-
const customIconsMeta = document.querySelector('meta[name="gtt-font-custom-icons"]');
13-
const customIconsUrl = customIconsMeta ? customIconsMeta.getAttribute('content') : 'data:application/font-woff2;base64,'; // Provide a data URL for an empty font
14-
15-
// Dynamically create the @font-face rule
16-
if (customIconsUrl) {
17-
// Remove the existing @font-face rule
18-
const styleSheets = document.styleSheets;
19-
for (let i = 0; i < styleSheets.length; i++) {
20-
const cssRules = styleSheets[i].cssRules || styleSheets[i].rules;
21-
for (let j = 0; j < cssRules.length; j++) {
22-
const rule = cssRules[j];
23-
if (rule instanceof CSSFontFaceRule && rule.style.fontFamily === 'custom-icons') {
24-
styleSheets[i].deleteRule(j);
25-
break;
26-
}
27-
}
28-
}
29-
30-
const style = document.createElement('style');
31-
style.innerHTML = `
32-
@font-face {
33-
font-family: 'custom-icons';
34-
font-style: normal;
35-
font-weight: 400;
36-
font-display: block;
37-
src: url(${customIconsUrl}) format('woff2');
38-
}
39-
`;
40-
document.head.appendChild(style);
41-
}
11+
const customIconsUrl = 'RAILS_ASSET_URL("custom-icons.woff2")';
4212

4313
// Define the font face
4414
let customFont: FontFace;

src/styles/icons/custom/custom-icons.css renamed to src/styles/icons/custom/custom-icons.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
$custom-icons-path: 'RAILS_ASSET_URL("custom-icons.woff2")';
2+
13
@font-face {
24
font-family: "custom-icons";
35
font-style: normal;
46
font-weight: 400;
57
font-display: block;
6-
src: url("./custom-icons.woff2") format("woff2");
8+
src: url(#{$custom-icons-path}) format("woff2");
79
}
810

911
.custom-icons {

src/styles/icons/material-design/material-design-def.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7300,13 +7300,11 @@ const iconMappings: { [key: string]: any } = {
73007300
"zodiac-virgo": "\u{F0A88}",
73017301
};
73027302

7303-
// Read the meta tag for MDI webfont
7304-
const mdiWebfontMeta = document.querySelector('meta[name="gtt-font-mdi-webfont"]');
7305-
const mdiWebfontUrl = mdiWebfontMeta ? mdiWebfontMeta.getAttribute('content') : 'data:application/font-woff2;base64,'; // Provide a data URL for an empty font
7303+
const mdiWebfontUrl = 'RAILS_ASSET_URL("materialdesignicons-webfont.woff2")';
73067304

73077305
// Dynamically create the @font-face rule
73087306
const style = document.createElement('style');
7309-
style.type = 'text/css';
7307+
// style.type = 'text/css';
73107308
style.innerHTML = `
73117309
@font-face {
73127310
font-family: 'Material Design Icons';

src/styles/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import 'ol-ext/dist/ol-ext.min.css';
88
import './scss/app.scss';
99

1010
// Import custom icons CSS file for adding custom icon designs in the application
11-
import './icons/custom/custom-icons.css';
11+
import './icons/custom/custom-icons.scss';
1212

1313
// Import custom icons definition JS file to define icon names, sizes, and variations
1414
import './icons/custom/custom-icons-def';
1515

1616
// Import Material Design icons filled style CSS for using a large collection of Google-designed icons
1717
// import '@material-design-icons/font/filled.css';
18-
import '@mdi/font/scss/materialdesignicons.scss';
18+
import '@mdi/font/css/materialdesignicons.css';
1919

2020
// Import Material Design icons definition JS file to define icon names and variations
2121
import './icons/material-design/material-design-def';

webpack.config.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ const path = require('path');
33
// Define loaders
44
// Loaders for processing Sass files
55
const sassLoaders = [
6-
'style-loader', // Creates `style` nodes from JS strings
7-
'css-loader', // Translates CSS into CommonJS
8-
'sass-loader', // Compiles Sass to CSS
6+
'style-loader',
7+
{
8+
loader: 'css-loader',
9+
options: {
10+
url: false, // Prevent css-loader from interpreting URLs
11+
},
12+
},
13+
'sass-loader',
914
];
1015

1116
// Loaders for processing CSS files

yarn.lock

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,20 @@ detect-libc@^1.0.3:
616616
resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b"
617617
integrity sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==
618618

619-
dompurify@*, dompurify@^3.2.2:
619+
dompurify@*:
620620
version "3.2.2"
621621
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.2.2.tgz#6c0518745e81686c74a684f5af1e5613e7cc0246"
622622
integrity sha512-YMM+erhdZ2nkZ4fTNRTSI94mb7VG7uVF5vj5Zde7tImgnhZE3R6YW/IACGIHb2ux+QkEXMhe591N+5jWOmL4Zw==
623623
optionalDependencies:
624624
"@types/trusted-types" "^2.0.7"
625625

626+
dompurify@^3.2.3:
627+
version "3.2.3"
628+
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.2.3.tgz#05dd2175225324daabfca6603055a09b2382a4cd"
629+
integrity sha512-U1U5Hzc2MO0oW3DF+G9qYN0aT7atAou4AgI0XjWz061nyBPbdxkfdhfy5uMgGn6+oLFCfn44ZGbdDqCzVmlOWA==
630+
optionalDependencies:
631+
"@types/trusted-types" "^2.0.7"
632+
626633
earcut@^3.0.0:
627634
version "3.0.0"
628635
resolved "https://registry.yarnpkg.com/earcut/-/earcut-3.0.0.tgz#a8d5bf891224eaea8287201b5e787c6c0318af89"
@@ -960,10 +967,10 @@ ol-ext@^4.0.24:
960967
resolved "https://registry.yarnpkg.com/ol-ext/-/ol-ext-4.0.24.tgz#86f3bb662fc9932ee16481604b2cbce87d96d28f"
961968
integrity sha512-VEf1+mjvbe35mMsszVsugqcvWfeGcU8TwS+GgXm3nGYqiHR7CckX2DWmM9B94QCDnrJWKKXBicfInbkoe2xT7w==
962969

963-
ol-mapbox-style@^12.3.5:
964-
version "12.3.5"
965-
resolved "https://registry.yarnpkg.com/ol-mapbox-style/-/ol-mapbox-style-12.3.5.tgz#8653890ce9f1ee2c0fc98cad6857bd0ca1e64628"
966-
integrity sha512-1tdq+jpzJ7BuqCeRpNV5u90X369MXDbHKpPPt0BNpbzi+4UEJ2dJIrd3eFQV9VbqvZeEIioEjyK7qOqXsUZs8w==
970+
ol-mapbox-style@^12.4.0:
971+
version "12.4.0"
972+
resolved "https://registry.yarnpkg.com/ol-mapbox-style/-/ol-mapbox-style-12.4.0.tgz#775deb25994ae6fe36cb0748582712c9d61a698e"
973+
integrity sha512-P8Jg9AXSG6FpUNrADejpwMG0HbmHTZOJQQocACzaDL0QrU4kzmCvj06xUIKhTxT5mtC413pCVAbyXJ4mx0XFnQ==
967974
dependencies:
968975
"@mapbox/mapbox-gl-style-spec" "^13.23.1"
969976
mapbox-to-css-font "^2.4.1"
@@ -1195,10 +1202,10 @@ sass-loader@^16.0.4:
11951202
dependencies:
11961203
neo-async "^2.6.2"
11971204

1198-
sass@^1.82.0:
1199-
version "1.82.0"
1200-
resolved "https://registry.yarnpkg.com/sass/-/sass-1.82.0.tgz#30da277af3d0fa6042e9ceabd0d984ed6d07df70"
1201-
integrity sha512-j4GMCTa8elGyN9A7x7bEglx0VgSpNUG4W4wNedQ33wSMdnkqQCT8HTwOaVSV4e6yQovcu/3Oc4coJP/l0xhL2Q==
1205+
sass@^1.83.0:
1206+
version "1.83.0"
1207+
resolved "https://registry.yarnpkg.com/sass/-/sass-1.83.0.tgz#e36842c0b88a94ed336fd16249b878a0541d536f"
1208+
integrity sha512-qsSxlayzoOjdvXMVLkzF84DJFc2HZEL/rFyGIKbbilYtAvlCxyuzUeff9LawTn4btVnLKg75Z8MMr1lxU1lfGw==
12021209
dependencies:
12031210
chokidar "^4.0.0"
12041211
immutable "^5.0.2"

0 commit comments

Comments
 (0)