-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
50 lines (44 loc) · 971 Bytes
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
let book = {
fonts:{},
colors:{}
};
module.exports = {
colors:{
add:(name,val)=>{
book.colors[name] = val;
},
get:(name)=>{
return book.colors[name];
}
},
fonts:{
add:async (tag,name,location,style,global_url)=>{
return new Promise((resolve,reject)=>{
if((window.hasOwnProperty('is_electron') || window.hasOwnProperty('is_cordova') && !global_url)){
location = location;
} else {
if(!global_url){
if(location[0] !== "/"){
location = "/" + location;
}
location = baseHref + location;
}
}
location = "URL(" + location + ")";
const run = new FontFace(name,location);
run.load()
.then((d)=>{
document.fonts.add(d);
book.fonts[tag] = name;
resolve();
})
.catch((e)=>{
reject(e);
});
});
},
get:(tag)=>{
return book.fonts[tag];
}
}
};