Skip to content

Commit

Permalink
Remove SVG build-time modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Aug 27, 2024
1 parent f168849 commit e82c1f1
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 20 deletions.
94 changes: 94 additions & 0 deletions buildtools/svg-viewbox-cmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const simpleHTMLTokenizer = require('simple-html-tokenizer');
const querystring = require('querystring');
const generate = require('./generate-xml-from-tokens.js');
const parseUnit = require('parse-absolute-css-unit');
const {program} = require('commander');
console.log('11');

function process(source, resourceQuery) {
let tokens = simpleHTMLTokenizer.tokenize(source);

tokens = tokens.map((tag) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
if (tag.type === 'StartTag' && tag.tagName === 'svg') {
let width = undefined;
let height = undefined;
let viewBox = undefined;
for (const attribute of tag.attributes) {
if (attribute[0] === 'width') {
try {
width = parseUnit(attribute[1]);
} catch (e) {
console.warn('Unable to read width: ' + attribute[1]);
}
}
if (attribute[0] === 'height') {
try {
height = parseUnit(attribute[1]);
} catch (e) {
console.warn('Unable to read height: ' + attribute[1]);
}
}
if (attribute[0] === 'viewBox') {
viewBox = attribute[1];
}
}
if (viewBox !== undefined && width === undefined && height === undefined) {
try {
const attrs = viewBox.split(' ');
width = parseFloat(attrs[2]);
height = parseFloat(attrs[3]);
} catch (e) {
console.warn('Unable to read viewBox: ' + viewBox);
}
}
if (width !== undefined && height != undefined) {
tag.attributes = tag.attributes.filter((attribute) => {
return (
attribute[0] !== 'width' &&
attribute[0] !== 'height' &&
attribute[0] !== 'x' &&
attribute[0] !== 'y'
);
});
if (viewBox === undefined) {
tag.attributes.push(['viewBox', `0 0 ${width} ${height}`, true]);
}
const queryString = resourceQuery.startsWith('?') ? resourceQuery.substring(1) : resourceQuery;
const query = querystring.decode(queryString);
if (query.width !== undefined) {
const parsed = query.width.match(/^([0-9]+)([a-z]*)$/);
tag.attributes.push(['width', query.width, true]);
tag.attributes.push(['height', `${(height / width) * parseFloat(parsed[1])}${parsed[2]}`, true]);
} else if (query.height !== undefined) {
const parsed = query.height.match(/^([0-9]+)([a-z]*)$/);
tag.attributes.push(['width', `${(width / height) * parseFloat(parsed[1])}${parsed[2]}`, true]);
tag.attributes.push(['height', query.height, true]);
} else {
tag.attributes.push(['width', width, true]);
tag.attributes.push(['height', height, true]);
}
}
}
return tag;
});

return generate(tokens);
}

function main(args) {
uri = args[0];

Check failure on line 80 in buildtools/svg-viewbox-cmd.js

View workflow job for this annotation

GitHub Actions / Continuous integration

'uri' is not defined
resourceQuery = args[1];

Check failure on line 81 in buildtools/svg-viewbox-cmd.js

View workflow job for this annotation

GitHub Actions / Continuous integration

'resourceQuery' is not defined
const fs = require('fs');
const source = fs.readFileSync(uri, 'utf-8');

Check failure on line 83 in buildtools/svg-viewbox-cmd.js

View workflow job for this annotation

GitHub Actions / Continuous integration

'uri' is not defined
const result = process(source, resourceQuery);

Check failure on line 84 in buildtools/svg-viewbox-cmd.js

View workflow job for this annotation

GitHub Actions / Continuous integration

'resourceQuery' is not defined
fs.writeFileSync(uri, result, 'utf-8');

Check failure on line 85 in buildtools/svg-viewbox-cmd.js

View workflow job for this annotation

GitHub Actions / Continuous integration

'uri' is not defined
}

// If running this module directly then call the main function.
if (require.main === module) {
program.parse(process.argv);
main(program.args);
}

module.exports = main;
2 changes: 1 addition & 1 deletion contribs/gmf/apps/desktop/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body ng-class="{'gmf-profile-chart-active': !!profileChartActive, 'gmf-query-grid-active': !!mainCtrl.queryGridActive}" ng-keydown="mainCtrl.onKeydown($event)" tabindex="0">
<div ng-show="mainCtrl.loading" class="loading-mask">
<i class="fa custom-spinner-loading fa-spin spinner-loading-mask">
<%=require('gmf/icons/spinner.svg?viewbox&height=1em')%>
<%=require('gmf/icons/spinner-1em.svg')%>
</i>
</div>
<gmf-header gmf-header-template-url="desktop/header.html"></gmf-header>
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/apps/desktop_alt/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body ng-keydown="mainCtrl.onKeydown($event)" tabindex="0">
<div ng-show="mainCtrl.loading" class="loading-mask">
<i class="fa custom-spinner-loading fa-spin spinner-loading-mask">
<%=require('gmf/icons/spinner.svg?viewbox&height=1em')%>
<%=require('gmf/icons/spinner-1em.svg')%>
</i>
</div>
<gmf-desktop-canvas>
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/apps/iframe_api/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<body>
<div ng-show="mainCtrl.loading" class="loading-mask">
<i class="fa custom-spinner-loading fa-spin spinner-loading-mask">
<%=require('gmf/icons/spinner.svg?viewbox&height=1em')%>
<%=require('gmf/icons/spinner-1em.svg')%>
</i>
</div>
<main>
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/apps/mobile/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'gmf-mobile-nav-right-is-visible': mainCtrl.rightNavVisible}">
<div ng-show="mainCtrl.loading" class="loading-mask">
<i class="fa custom-spinner-loading fa-spin spinner-loading-mask">
<%=require('gmf/icons/spinner.svg?viewbox&height=1em')%>
<%=require('gmf/icons/spinner-1em.svg')%>
</i>
</div>
<main ng-class="{'gmf-search-is-active': mainCtrl.searchOverlayVisible}">
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/apps/mobile_alt/index.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'gmf-mobile-nav-right-is-visible': mainCtrl.rightNavVisible}">
<div ng-show="mainCtrl.loading" class="loading-mask">
<i class="fa custom-spinner-loading fa-spin spinner-loading-mask">
<%=require('gmf/icons/spinner.svg?viewbox&height=1em')%>
<%=require('gmf/icons/spinner-1em.svg')%>
</i>
</div>
<main ng-class="{'gmf-search-is-active': mainCtrl.searchOverlayVisible}">
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
},
"bin": {
"compile-catalog": "buildtools/compile-catalog.js",
"check-example": "buildtools/check-example.js"
"check-example": "buildtools/check-example.js",
"svg-viewbox": "buildtools/svg-viewbox-cmd.js"
},
"browser": {
"ngeo/test": "./test/spec",
Expand Down
1 change: 1 addition & 0 deletions src/icons/spinner-1em.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/icons/spinner-1rem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/icons/spinner-3rem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 1 addition & 3 deletions src/import/importdatasourceComponent.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
</div>

<div ng-if="$ctrl.isLoading">
<i class="fa custom-spinner-importkml fa-spin">
<%=require('gmf/icons/spinner.svg?viewbox&height=1em')%>
</i>
<i class="fa custom-spinner-importkml fa-spin"> <%=require('gmf/icons/spinner-1em.svg')%> </i>
</div>

<div
Expand Down
2 changes: 1 addition & 1 deletion src/layertree/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
ng-click="::gmfLayertreeCtrl.toggleActive(layertreeCtrl)"
ng-if="layertreeCtrl.node.children && layertreeCtrl.layer.loading"
class="fa fa-fw custom-spinner-generic fa-spin"
><%=require('gmf/icons/spinner.svg?viewbox&height=1rem')%></a
><%=require('gmf/icons/spinner-1rem.svg')%></a
>
<a
href
Expand Down
4 changes: 1 addition & 3 deletions src/permalink/shareComponent.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ <h4 class="modal-title" translate>Share this map</h4>
></textarea>
</div>
<span class="text-default" ng-if="!$ctrl.isFinishedState">
<i class="fa custom-spinner-generic fa-spin">
<%=require('gmf/icons/spinner.svg?viewbox&height=1rem')%>
</i>
<i class="fa custom-spinner-generic fa-spin"> <%=require('gmf/icons/spinner-1rem.svg')%> </i>
</span>
<span class="text-success" ng-if="$ctrl.successfullySent">
<i class="fa fa-check" aria-hidden="true"></i>
Expand Down
4 changes: 1 addition & 3 deletions src/print/component.html
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@

<div class="gmf-print-actions form-group pull-right">
<span ng-show="$ctrl.isState('PRINTING')">
<i class="fa custom-spinner-generic fa-spin">
<%=require('gmf/icons/spinner.svg?viewbox&height=1rem')%>
</i>
<i class="fa custom-spinner-generic fa-spin"> <%=require('gmf/icons/spinner-1rem.svg')%> </i>
</span>

<a
Expand Down
2 changes: 1 addition & 1 deletion src/profile/component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="gmf-profile-container panel" ng-show="ctrl.active">
<div class="spinner-profile" ng-show="ctrl.isLoading">
<i class="fa fa-spin"> <%=require('gmf/icons/spinner.svg?viewbox&height=3rem')%> </i>
<i class="fa fa-spin"> <%=require('gmf/icons/spinner-3rem.svg')%> </i>
</div>

<div
Expand Down
2 changes: 1 addition & 1 deletion src/query/gridComponent.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
</div>

<div ng-show="ctrl.pending" class="spinner-grid">
<i class="fa fa-spin"> <%=require('gmf/icons/spinner.svg?viewbox&height=3rem')%> </i>
<i class="fa fa-spin"> <%=require('gmf/icons/spinner-3rem.svg')%> </i>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion src/query/windowComponent.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="spinner-window" ng-if="ctrl.isLoading">
<i class="fa fa-spin"> <%=require('gmf/icons/spinner.svg?viewbox&height=3rem')%> </i>
<i class="fa fa-spin"> <%=require('gmf/icons/spinner-3rem.svg')%> </i>
</div>

<div
Expand Down
2 changes: 1 addition & 1 deletion src/raster/widgetComponent.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<span class="gmf-elevationwidget-value">
{{ctrl.elevationValue}}
<span ng-show="ctrl.elevationLoading" class="fa fa-spin custom-spinner-generic">
<%=require('gmf/icons/spinner.svg?viewbox&height=1rem')%>
<%=require('gmf/icons/spinner-1rem.svg')%>
</span>
<span ng-show="!ctrl.elevationValue && !ctrl.elevationLoading" translate>Raster</span> </span
><span class="caret" ng-if="::ctrl.options.layers.length > 1"></span>
Expand Down

0 comments on commit e82c1f1

Please sign in to comment.