mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
load dropins from local folder
This commit is contained in:
parent
f7d72c2255
commit
ae75f93174
4 changed files with 17 additions and 14 deletions
|
|
@ -4295,6 +4295,6 @@
|
||||||
<script defer src="libs/jquery.ui.touch-punch.min.js"></script>
|
<script defer src="libs/jquery.ui.touch-punch.min.js"></script>
|
||||||
<script defer src="libs/pell.min.js"></script>
|
<script defer src="libs/pell.min.js"></script>
|
||||||
<script defer src="libs/jszip.min.js"></script>
|
<script defer src="libs/jszip.min.js"></script>
|
||||||
<script defer src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="pdr9ae64ip0qno4"></script>
|
<script defer src="libs/dropins.min.js" id="dropboxjs" data-app-key="pdr9ae64ip0qno4"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
2
libs/dropins.min.js
vendored
Normal file
2
libs/dropins.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -52,16 +52,16 @@ function getFontsList(svg) {
|
||||||
return [...new Set(fontsInUse)];
|
return [...new Set(fontsInUse)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// code from Kaiido's answer https://stackoverflow.com/questions/42402584/how-to-use-google-fonts-in-canvas-when-drawing-dom-objects-in-svg
|
function convertFontToDataURI(url) {
|
||||||
function GFontToDataURI(url) {
|
|
||||||
if (!url) return Promise.resolve();
|
if (!url) return Promise.resolve();
|
||||||
return fetch(url) // first fecth the embed stylesheet page
|
return fetch(url)
|
||||||
.then(resp => resp.text()) // we only need the text of it
|
.then(resp => resp.text())
|
||||||
.then(text => {
|
.then(text => {
|
||||||
let s = document.createElement("style");
|
const style = document.createElement("style");
|
||||||
s.innerHTML = text;
|
style.innerHTML = text;
|
||||||
document.head.appendChild(s);
|
document.head.appendChild(style);
|
||||||
const styleSheet = Array.prototype.filter.call(document.styleSheets, sS => sS.ownerNode === s)[0];
|
|
||||||
|
const styleSheet = document.styleSheets.find(sheet => sheet.ownerNode === style);
|
||||||
|
|
||||||
const FontRule = rule => {
|
const FontRule = rule => {
|
||||||
const src = rule.style.getPropertyValue("src");
|
const src = rule.style.getPropertyValue("src");
|
||||||
|
|
@ -70,12 +70,12 @@ function GFontToDataURI(url) {
|
||||||
};
|
};
|
||||||
const fontProms = [];
|
const fontProms = [];
|
||||||
|
|
||||||
for (const r of styleSheet.cssRules) {
|
for (const rule of styleSheet.cssRules) {
|
||||||
let fR = FontRule(r);
|
let fR = FontRule(rule);
|
||||||
if (!fR.url) continue;
|
if (!fR.url) continue;
|
||||||
|
|
||||||
fontProms.push(
|
fontProms.push(
|
||||||
fetch(fR.url) // fetch the actual font-file (.woff)
|
fetch(fR.url)
|
||||||
.then(resp => resp.blob())
|
.then(resp => resp.blob())
|
||||||
.then(blob => {
|
.then(blob => {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|
@ -87,7 +87,8 @@ function GFontToDataURI(url) {
|
||||||
.then(dataURL => fR.rule.cssText.replace(fR.url, dataURL))
|
.then(dataURL => fR.rule.cssText.replace(fR.url, dataURL))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
document.head.removeChild(s); // clean up
|
|
||||||
|
document.head.removeChild(style); // clean up
|
||||||
return Promise.all(fontProms); // wait for all this has been done
|
return Promise.all(fontProms); // wait for all this has been done
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ async function getMapURL(type, options = {}) {
|
||||||
const fontsToLoad = usedFonts.filter(font => !webSafe.includes(font));
|
const fontsToLoad = usedFonts.filter(font => !webSafe.includes(font));
|
||||||
if (fontsToLoad.length) {
|
if (fontsToLoad.length) {
|
||||||
const url = "https://fonts.googleapis.com/css?family=" + fontsToLoad.join("|");
|
const url = "https://fonts.googleapis.com/css?family=" + fontsToLoad.join("|");
|
||||||
const fontStyle = await GFontToDataURI(url);
|
const fontStyle = await convertFontToDataURI(url);
|
||||||
if (fontStyle) clone.select("defs").append("style").text(fontStyle.join("\n"));
|
if (fontStyle) clone.select("defs").append("style").text(fontStyle.join("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue