@xlfont/load 1.0.13 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.min.js ADDED
@@ -0,0 +1 @@
1
+ !function(){var i,n,t,o,c;function l(e,t){var n,r={}.hasOwnProperty;for(n in t)r.call(t,n)&&(e[n]=t[n]);return e}i=function(e){return null==e&&(e={}),l(new Error,l({name:"lderror"},e))},n={key:0,worker:null,queue:[],init:function(e){var r=this;return null==e&&(e={}),Promise.resolve().then(function(){var e;if(!r.worker)return e=URL.createObjectURL(new Blob(['var local={},onmessage=function(e){var e=e.data||{},n=e.bufs,p=e.key,e=e.lib;return local.inited||(console.log(e),importScripts(e||"opentype.js"),local.inited=!0),Promise.resolve().then(function(){return n.map(function(e){return opentype.parse(e)})}).then(function(e){for(var n,t,r,s,o,a=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,a.push(n.glyphs.glyphs[s]);return n=e[0],o=new opentype.Font(((o={glyphs:a,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,o.ascender=n.ascender,o.descender=n.descender,o)),postMessage({buf:o.toArrayBuffer(),key:p})})};'],{type:"text/javascript"})),r.worker=new Worker(e),URL.revokeObjectURL(e),r.worker.onmessage=function(e){var t=e.data,e=t.buf,n=t.key;if(t=r.queue.filter(function(e){return n===e.key})[0])return r.queue.splice(r.queue.indexOf(t),1),t.res(e)}})},run:function(r,o){var s=this;return new Promise(function(t,n){return s.init(o).then(function(){var e;return s.queue.push(e={res:t,rej:n,key:s.key++}),console.log(">",o),s.worker.postMessage({bufs:r,key:e.key,lib:o.opentypeUrl})})})}},t=function(e){var t=e.bufs,e=e.useWorker;return t.length?e?n.run(t,e):Promise.resolve().then(function(){return t.map(function(e){return opentype.parse(e)})}).then(function(e){for(var t,n,r,o,s,i=[],u=0,f=e.length;u<f;++u)for(n=0,r=(t=e[u]).glyphs.length;n<r;++n)o=n,i.push(t.glyphs.glyphs[o]);return t=e[0],new opentype.Font(((s={glyphs:i,familyName:t.names.fontFamily.en,styleName:t.names.fontSubfamily.en}).unitsPerEm=t.unitsPerEm,s.ascender=t.ascender,s.descender=t.descender,s)).toArrayBuffer()}):Promise.resolve()},(o=function(e){var t,n=this;return this.opt=e=null==e?{}:e,this.sub={set:{},font:{}},this.cjkOnly=e.cjkOnly||!1,this.codemap={},this.otf={font:null,dirty:!0},this.path=e.path,this.name=e.name||this.path.replace(/\.[a-zA-Z0-9]+$/,"").replace(/^https?:\/\/[^/]+\//g,"").replace(/\s/g,"-").replace(/\//g,"-").toLowerCase(),this.style=e.style||"normal",this.weight=e.weight||"400",this.ext=e.ext||(/\.(ttf|otf|woff2|woff)$/.exec(this.path)||[])[1]||"",this.format=(t=this.ext.toLowerCase())?"ttf"===t||"otf"===t?"truetype":t:"",this.format&&(this.format="format('"+this.format+"')"),this.className="xfl-"+(this.name||"").replace(/\s+/g,"_")+"-"+Math.random().toString(36).substring(2),this.isXl=null!=e.isXl?e.isXl:!this.ext,this.ext||(this.ext="woff"),this.doMerge=null!=e.doMerge&&e.doMerge,this.useWorker=null!=e.useWorker&&e.useWorker,this.misschar={},this.css=[],this.init=proxise.once(function(){return n._init()}),this.init(),this}).prototype=l(Object.create(Object.prototype),{_init:function(){var r=this;return Promise.resolve().then(function(){return r.isXl?new Promise(function(e,t){var n=new XMLHttpRequest;return n.addEventListener("readystatechange",function(){if(n.readyState===XMLHttpRequest.DONE)return 200!==n.status?t(i({code:n.status,message:n.responseText})):((n.responseText||"").split("\n").map(function(e,n){return e.split(" ").map(function(e,t){return r.codemap[e]=n+1})}),e())}),n.open("GET",r.path+"/charmap.txt"),n.send()}):(r.css=[{content:'@font-face {\n font-family: "'+r.name+'";\n src: url("'+r.path+'") '+r.format+";\n font-style: "+r.style+";\n font-weight: "+r.weight+";\n}\n."+r.className+' { font-family: "'+r.name+'"; }'}],c.update())})},_fetch:function(e,t,o){var s=this;return null==e&&(e={}),null==o&&(o="ttf"),(t=null!=t&&t)?e.blob?Promise.resolve(e):(e.proxy||(e.proxy=proxise(function(r){if(!r.running)return r.running=!0,new Promise(function(e,t){var n;return r.blob?e(r):((n=new XMLHttpRequest).addEventListener("readystatechange",function(){if(n.readyState===XMLHttpRequest.DONE)return 200!==n.status?t(i({code:n.status,message:n.responseText})):(s.otf.dirty=!0,r.url=URL.createObjectURL(n.response),r.blob=n.response,r.type=s.ext.toLowerCase()||o,e(r))}),s.isXl?n.open("GET",s.path+"/"+r.key+"."+o):n.open("GET",s.path),n.responseType="blob",n.send())}).finally(function(){return r.running=!1})})),e.proxy(e)):(e.url||(this.isXl?(e.url=this.path+"/"+e.key+"."+o,e.type=o):(e.url=this.path,e.type=this.ext.toLowerCase()||o)),Promise.resolve(e))},fetchAll:function(){var n,r,t=this;return this.isXl?Promise.all(function(){var e,t=[];for(n in e=this.sub.font)r=e[n],t.push(r);return t}.call(this).map(function(e){return t._fetch(e,!0,"woff")})):this._fetch(this.sub.font[0],!0,"ttf")},fetch:function(e,o){var s,u=this;if(null==e&&(e=[]),null==o&&(o=!1),!this.isXl){if(this.sub.font[0]&&this.sub.font[0].blob)return Promise.resolve();e=[0]}return s=this.doMerge,e=Array.from(new Set(e.map(function(e){return e}))).filter(function(e){return!u.sub.font[e]}).map(function(e,t){var n,r;return u.sub.font[e]=n={key:e},r=u.isXl?"woff":"ttf",n.needMerge=1!=+e,u._fetch(n,!!s||o,r)}),Promise.all(e).then(function(n){var e;return s?(e=n.filter(function(e){return e.needMerge}).map(function(r){return new Promise(function(e,t){var n=new FileReader;return n.onerror=function(e){return t(e)},n.onload=function(){return e(n.result)},n.readAsArrayBuffer(r.blob)})}),Promise.all(e).then(function(e){return t({bufs:e,useWorker:u.useWorker})}).then(function(e){var t;return e?(t=n.filter(function(e){return e.needMerge})[0],e=new Blob([e],{type:"font/"+(t.type||"ttf")}),t={url:URL.createObjectURL(e),blob:e,type:t.type||"ttf"},n.filter(function(e){return!e.needMerge}).concat([t])):n.filter(function(e){return!e.needMerge})})):n}).then(function(e){var t,n,r,o,s,i;if(e.length){for(n in t="."+u.className+' { font-family: "'+u.name+'"; }',r=u.sub.font)o=r[n];for(s=0,i=e.length;s<i;++s)o=e[s],t+='@font-face {\n font-family: "'+u.name+'";\n src: url("'+o.url+"\") format('"+o.type+"');\n font-style: "+u.style+";\n font-weight: "+u.weight+";\n}";return u.css.push({content:t})}})},hasChar:function(e){return void 0===this.misschar[e]?void 0:!this.misshcar[e]},getPath:function(e){var s=this,e=l({text:"",x:0,y:0,fontSize:48},e=null==e?{}:e),i=e.text,u=e.x,f=e.y,a=e.fontSize;return this.sync(i).then(function(){return s.getotf()}).then(function(e){for(var t,n="",r=0,o=i.length;r<o;++r)t=r,n+=s.misschar[i[t]]?" ":i[t];return e.getPath(n,u,f,a)})},getotf:function(){var o=this;return"undefined"==typeof opentype||null===opentype?Promise.reject(i({id:1022,message:"[@plotdb/xfl] need opentype.js to merge subfonts"})):this.otf.dirty?Promise.resolve().then(function(){return o.isXl?o.fetchAll():o.fetch()}).then(function(){var n,r,e=function(){var e,t=[];for(n in e=this.sub.font)r=e[n],t.push(r);return t}.call(o).map(function(t){return t.otf?Promise.resolve(t):opentype.load(t.url).then(function(e){return t.otf=e,t})});return Promise.all(e)}).then(function(e){var t;return 1===(e=null==e?[]:e).length?e[0].otf:(t=e.map(function(e){for(var t,n=[],r=e.otf.glyphs,o=1,s=r.length;o<=s;++o)t=o,n.push(r.glyphs[t]);return n}).reduce(function(e,t){return e.concat(t)},[]).filter(function(e){return e}),o.otf.font=new opentype.Font(((t={familyName:o.name,styleName:o.style||"normal",glyphs:t}).unitsPerEm=(e=e[0].otf).unitsPerEm,t.ascender=e.ascender,t.descender=e.descender,t)),o.otf.font.kerningPairs={},o.otf.font)}):Promise.resolve(this.otf.font)},sync:function(a){var l=this;return null==a&&(a=""),this.isXl?Promise.resolve().then(function(){for(var e,t,n,r,o=[{},{}],s=o[0],i=o[1],u=0,f=a.length;u<f;++u)e=u,t=a.charCodeAt(e),l.cjkOnly&&!c.isCJK(t)||(t=l.codemap[t.toString(16)],l.misschar[a[e]]=s[a[e]]=!t,t&&!l.sub.set[t]&&(l.sub.set[t]=i[t]=!0));for(n in(s=function(){var e=[];for(n in s)e.push(n);return e}().filter(function(e){return s[e]})).length&&console.log("[@plotdb/xfl] sync xl-font with following chars unsupported: "+s.join("")),r=[],i)r.push(n);if((o=r).length)return l.fetch(o)}).then(function(){return c.update()}):(c.update(),Promise.resolve())}}),c={range:{CJK:[[12352,12543],[13312,19903],[19968,40959],[63744,64255],[65382,65439],[12593,55197]]},fonts:{},running:{},isCJK:function(t){return this.range.CJK.filter(function(e){return t>=e[0]&&t<=e[1]}).length},proxy:{},update:function(){var n,e,t,r,o,s="";for(n in e=this.fonts)((t=e[n]).css||[]).filter(i).map(u);return s&&((r=document.createElement("style")).textContent=s,r.setAttribute("type","text/css"),document.body.appendChild(r)),Promise.all(function(){var e,t=[];for(n in e=this.fonts)o=e[n],t.push(o);return t}.call(this).map(function(){return document.fonts.load("16px "+t.name)})).then(function(){return new Promise(function(e,t){return setTimeout(function(){return e()},350)})});function i(e){return!e.rendered}function u(e){return e.rendered=!0,s+=e.content}},_load:function(t){var n=this,r=(t=null==t?{}:t).path;if(!this.running[r])return this.running[r]=!0,Promise.resolve().then(function(){var e;return n.fonts[r]=e=new o(t),e.init()}).finally(function(){return n.running[r]=!1}).then(function(){return n.proxy[r].resolve(n.fonts[r]),n.fonts[r]}).catch(function(e){return n.proxy[r].reject(e),Promise.reject(e)})},load:function(o){var s=this;return"string"==typeof(o=null==o?{}:o)&&(o={path:o}),new Promise(function(t,n){var e,r;return(e=o.path)?(e=e.replace(/\/$/,""),(r=s.fonts[e])?t(r):(s.proxy[e]||(s.proxy[e]=proxise(function(e){return s._load(e)})),s.proxy[e](((r=l({},o)).path=e,r)).then(function(e){return t(e)}).catch(function(e){return n(e)}))):n(i({id:400}))})}},"undefined"!=typeof module&&null!==module?module.exports=c:"undefined"!=typeof window&&null!==window&&(window.xfl=c)}();
package/package.json CHANGED
@@ -1,76 +1 @@
1
- {
2
- "author": "zbryikt",
3
- "name": "@xlfont/load",
4
- "license": "MIT",
5
- "description": "XL font generator and loader",
6
- "version": "1.0.13",
7
- "main": "dist/index.js",
8
- "homepage": "https://github.com/xlfont/load",
9
- "files": [
10
- "dist/**/*",
11
- "tool/data/*"
12
- ],
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/xlfont/load"
16
- },
17
- "engines": {
18
- "node": ">=10.14.1",
19
- "npm": ">=6.4.1"
20
- },
21
- "scripts": {
22
- "start": "npx server -r web -o true"
23
- },
24
- "bin": {
25
- "xfl": "./bin/build.js",
26
- "xfl-meta": "./bin/meta.js"
27
- },
28
- "dependencies": {
29
- "@plotdb/opentype.js": "^1.3.4",
30
- "colors": "^1.4.0",
31
- "fs-extra": "^9.1.0",
32
- "progress": "^2.0.3",
33
- "ttf2woff": "^2.0.2",
34
- "ttf2woff2": "^4.0.0",
35
- "yargs": "^16.2.0"
36
- },
37
- "devDependencies": {
38
- "@loadingio/debounce.js": "0.0.1",
39
- "@loadingio/ldquery": "^2.0.0",
40
- "@loadingio/loading.css": "^2.0.1",
41
- "bootstrap": "^4.5.3",
42
- "bootstrap.ldui": "github:loadingio/bootstrap.ldui",
43
- "bootstrap.native": "^3.0.13",
44
- "fedep": "^0.0.12",
45
- "ldbutton": "^1.0.2",
46
- "ldcover": "^1.3.2",
47
- "ldloader": "^1.2.1",
48
- "ldview": "^0.2.0",
49
- "livescript": "^1.6.0",
50
- "stylus": "^0.54.5",
51
- "template": "github:zbryikt/template#v2.3.13",
52
- "uglify-js": "^3.2.0",
53
- "uglifycss": "^0.0.29"
54
- },
55
- "peerDependencies": {
56
- "@plotdb/opentype.js": "^1.3.4",
57
- "proxise": "^0.1.2"
58
- },
59
- "frontendDependencies": {
60
- "root": "web/static/assets/lib",
61
- "modules": [
62
- "bootstrap",
63
- "bootstrap.ldui",
64
- "bootstrap.native",
65
- "@loadingio/ldquery",
66
- "@loadingio/debounce.js",
67
- "@loadingio/loading.css",
68
- "@plotdb/opentype.js",
69
- "ldview",
70
- "ldcover",
71
- "ldloader",
72
- "ldbutton",
73
- "proxise"
74
- ]
75
- }
76
- }
1
+ {"author":"zbryikt","name":"@xlfont/load","license":"MIT","description":"XL font generator and loader","version":"2.0.1","browser":"index.min.js","main":"index.min.js","homepage":"https://github.com/xlfont/load","repository":{"type":"git","url":"https://github.com/xlfont/load"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true"},"bin":{"xfl":"./bin/build.js","xfl-meta":"./bin/meta.js"},"dependencies":{"@plotdb/colors":"^0.0.1","@plotdb/opentype.js":"^1.3.5","fs-extra":"^9.1.0","progress":"^2.0.3","ttf2woff":"^2.0.2","ttf2woff2":"^4.0.0","yargs":"^16.2.0"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.4","@loadingio/debounce.js":"^1.0.1","@loadingio/ldquery":"^3.0.1","@loadingio/loading.css":"^3.0.0","@zbryikt/deploy":"^0.0.1","@zbryikt/template":"^2.3.33","bootstrap":"^4.5.3","bootstrap.native":"^3.0.13","fedep":"^1.1.1","glob":"^7.2.0","ldbutton":"^2.0.0","ldcover":"^3.0.1","ldloader":"^3.0.0","ldview":"^1.0.0","livescript":"^1.6.0","stylus":"^0.55.0","uglify-js":"^3.13.1","uglifycss":"^0.0.29"},"peerDependencies":{"@plotdb/opentype.js":"^1.3.5","proxise":"^1.0.1"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","bootstrap.native","@loadingio/bootstrap.ext","@loadingio/ldquery","@loadingio/debounce.js","@loadingio/loading.css","@plotdb/opentype.js","ldview","ldcover","ldloader","ldbutton","proxise"]}}
package/worker.js ADDED
@@ -0,0 +1,36 @@
1
+ var local, onmessage;
2
+ local = {};
3
+ onmessage = function(e){
4
+ var ref$, bufs, key, lib;
5
+ ref$ = e.data || {}, bufs = ref$.bufs, key = ref$.key, lib = ref$.lib;
6
+ if (!local.inited) {
7
+ console.log(lib);
8
+ importScripts(lib || "opentype.js");
9
+ local.inited = true;
10
+ }
11
+ return Promise.resolve().then(function(){
12
+ return bufs.map(function(it){
13
+ return opentype.parse(it);
14
+ });
15
+ }).then(function(fonts){
16
+ var glyphs, i$, len$, font, j$, to$, i, merged, ref$;
17
+ glyphs = [];
18
+ for (i$ = 0, len$ = fonts.length; i$ < len$; ++i$) {
19
+ font = fonts[i$];
20
+ for (j$ = 0, to$ = font.glyphs.length; j$ < to$; ++j$) {
21
+ i = j$;
22
+ glyphs.push(font.glyphs.glyphs[i]);
23
+ }
24
+ }
25
+ font = fonts[0];
26
+ merged = new opentype.Font((ref$ = {
27
+ glyphs: glyphs,
28
+ familyName: font.names.fontFamily.en,
29
+ styleName: font.names.fontSubfamily.en
30
+ }, ref$.unitsPerEm = font.unitsPerEm, ref$.ascender = font.ascender, ref$.descender = font.descender, ref$));
31
+ return postMessage({
32
+ buf: merged.toArrayBuffer(),
33
+ key: key
34
+ });
35
+ });
36
+ };
package/worker.min.js ADDED
@@ -0,0 +1 @@
1
+ var local={},onmessage=function(e){var e=e.data||{},n=e.bufs,p=e.key,e=e.lib;return local.inited||(console.log(e),importScripts(e||"opentype.js"),local.inited=!0),Promise.resolve().then(function(){return n.map(function(e){return opentype.parse(e)})}).then(function(e){for(var n,t,r,s,o,a=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,a.push(n.glyphs.glyphs[s]);return n=e[0],o=new opentype.Font(((o={glyphs:a,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,o.ascender=n.ascender,o.descender=n.descender,o)),postMessage({buf:o.toArrayBuffer(),key:p})})};
package/dist/xfl.js DELETED
@@ -1,409 +0,0 @@
1
- (function(){
2
- var err, xlfont, xfl;
3
- err = function(e){
4
- e == null && (e = {});
5
- return import$(new Error(), import$({
6
- name: 'lderror'
7
- }, e));
8
- };
9
- xlfont = function(opt){
10
- var ref$, that, this$ = this;
11
- opt == null && (opt = {});
12
- this.opt = opt;
13
- this.sub = {
14
- set: {},
15
- font: {}
16
- };
17
- this.cjkOnly = opt.cjkOnly || false;
18
- this.codemap = {};
19
- this.otf = {
20
- font: null,
21
- dirty: true
22
- };
23
- this.path = opt.path;
24
- this.name = opt.name || (ref$ = this.path.replace(/\.[a-zA-Z0-9]+$/, '').split("/").filter(function(it){
25
- return it;
26
- }))[ref$.length - 1];
27
- this.style = 'normal';
28
- this.ext = opt.ext || (/\.(ttf|otf|woff2|woff)$/.exec(this.path) || [])[1] || '';
29
- this.format = (that = this.ext.toLowerCase()) ? that === 'ttf'
30
- ? 'truetype'
31
- : that === 'otf' ? 'truetype' : that : '';
32
- if (this.format) {
33
- this.format = "format('" + this.format + "')";
34
- }
35
- this.className = "xfl-" + (this.name || '').replace(/\s+/g, '_') + "-" + Math.random().toString(36).substring(2);
36
- this.isXl = !this.ext;
37
- this.css = [];
38
- this.init = proxise.once(function(){
39
- return this$._init();
40
- });
41
- this.init();
42
- return this;
43
- };
44
- xlfont.prototype = import$(Object.create(Object.prototype), {
45
- _init: function(){
46
- var this$ = this;
47
- return Promise.resolve().then(function(){
48
- if (!this$.isXl) {
49
- this$.css = [{
50
- content: "@font-face {\n font-family: \"" + this$.name + "\";\n src: url(\"" + this$.path + "\") " + this$.format + ";\n}\n." + this$.className + " { font-family: \"" + this$.name + "\"; }"
51
- }];
52
- return xfl.update();
53
- } else {
54
- return new Promise(function(res, rej){
55
- var xhr;
56
- xhr = new XMLHttpRequest();
57
- xhr.addEventListener('readystatechange', function(){
58
- if (xhr.readyState !== XMLHttpRequest.DONE) {
59
- return;
60
- }
61
- if (xhr.status !== 200) {
62
- return rej(err({
63
- code: xhr.status,
64
- message: xhr.responseText
65
- }));
66
- }
67
- (xhr.responseText || '').split('\n').map(function(d, i){
68
- return d.split(' ').map(function(e, j){
69
- return this$.codemap[e] = i + 1;
70
- });
71
- });
72
- return res();
73
- });
74
- xhr.open('GET', this$.path + "/charmap.txt");
75
- return xhr.send();
76
- });
77
- }
78
- });
79
- },
80
- _fetch: function(f, dofetch){
81
- var this$ = this;
82
- f == null && (f = {});
83
- dofetch == null && (dofetch = false);
84
- if (!dofetch) {
85
- if (!f.url) {
86
- if (this.isXl) {
87
- f.url = this.path + "/" + f.key + ".woff2";
88
- f.type = 'woff2';
89
- } else {
90
- f.url = this.path;
91
- f.type = this.ext.toLowerCase();
92
- }
93
- }
94
- return Promise.resolve(f);
95
- }
96
- if (f.blob) {
97
- return Promise.resolve(f);
98
- }
99
- if (!f.proxy) {
100
- f.proxy = proxise(function(f){
101
- var p;
102
- if (f.running) {
103
- return;
104
- }
105
- f.running = true;
106
- p = new Promise(function(res, rej){
107
- var xhr;
108
- if (f.blob) {
109
- return res(f);
110
- }
111
- xhr = new XMLHttpRequest();
112
- xhr.addEventListener('readystatechange', function(){
113
- if (xhr.readyState !== XMLHttpRequest.DONE) {
114
- return;
115
- }
116
- if (xhr.status !== 200) {
117
- return rej(err({
118
- code: xhr.status,
119
- message: xhr.responseText
120
- }));
121
- }
122
- this$.otf.dirty = true;
123
- f.url = URL.createObjectURL(xhr.response);
124
- f.blob = xhr.response;
125
- f.type = this$.ext.toLowerCase() || 'ttf';
126
- return res(f);
127
- });
128
- if (this$.isXl) {
129
- xhr.open('GET', this$.path + "/" + f.key + ".ttf");
130
- } else {
131
- xhr.open('GET', this$.path);
132
- }
133
- xhr.responseType = 'blob';
134
- return xhr.send();
135
- });
136
- return p['finally'](function(){
137
- return f.running = false;
138
- });
139
- });
140
- }
141
- return f.proxy(f);
142
- },
143
- fetchAll: function(){
144
- var k, f, this$ = this;
145
- if (this.isXl) {
146
- return Promise.all((function(){
147
- var ref$, results$ = [];
148
- for (k in ref$ = this.sub.font) {
149
- f = ref$[k];
150
- results$.push(f);
151
- }
152
- return results$;
153
- }.call(this)).map(function(it){
154
- return this$._fetch(it, true);
155
- }));
156
- } else {
157
- return this._fetch(this.sub.font[0], true);
158
- }
159
- },
160
- fetch: function(list, dofetch){
161
- var ps, this$ = this;
162
- list == null && (list = []);
163
- dofetch == null && (dofetch = false);
164
- if (!this.isXl) {
165
- if (this.sub.font[0] && this.sub.font[0].blob) {
166
- return Promise.resolve();
167
- }
168
- list = [0];
169
- }
170
- ps = Array.from(new Set(list.map(function(it){
171
- return it;
172
- }))).filter(function(it){
173
- return !this$.sub.font[it];
174
- }).map(function(it){
175
- var f;
176
- this$.sub.font[it] = f = {
177
- key: it
178
- };
179
- return this$._fetch(f, dofetch);
180
- });
181
- return Promise.all(ps).then(function(subfonts){
182
- var css, k, ref$, f, i$, len$;
183
- if (!subfonts.length) {
184
- return;
185
- }
186
- css = "." + this$.className + " { font-family: \"" + this$.name + "\"; }";
187
- for (k in ref$ = this$.sub.font) {
188
- f = ref$[k];
189
- }
190
- for (i$ = 0, len$ = subfonts.length; i$ < len$; ++i$) {
191
- f = subfonts[i$];
192
- css += "@font-face {\n font-family: \"" + this$.name + "\";\n src: url(\"" + f.url + "\") format('" + f.type + "');\n}";
193
- }
194
- return this$.css.push({
195
- content: css
196
- });
197
- });
198
- },
199
- getotf: function(){
200
- var this$ = this;
201
- if (!(typeof opentype != 'undefined' && opentype !== null)) {
202
- return Promise.reject(err({
203
- id: 1022,
204
- message: "[@plotdb/xfl] need opentype.js to merge subfonts"
205
- }));
206
- }
207
- if (!this.otf.dirty) {
208
- return Promise.resolve(this.otf.font);
209
- }
210
- return Promise.resolve().then(function(){
211
- if (!this$.isXl) {
212
- return this$.fetch();
213
- } else {
214
- return this$.fetchAll();
215
- }
216
- }).then(function(){
217
- var ps, k, f;
218
- ps = (function(){
219
- var ref$, results$ = [];
220
- for (k in ref$ = this.sub.font) {
221
- f = ref$[k];
222
- results$.push(f);
223
- }
224
- return results$;
225
- }.call(this$)).map(function(f){
226
- if (f.otf) {
227
- return Promise.resolve(f);
228
- } else {
229
- return opentype.load(f.url).then(function(it){
230
- f.otf = it;
231
- return f;
232
- });
233
- }
234
- });
235
- return Promise.all(ps);
236
- }).then(function(list){
237
- var glyphs, ref$, ref1$;
238
- list == null && (list = []);
239
- if (list.length === 1) {
240
- return list[0].otf;
241
- }
242
- glyphs = list.map(function(f){
243
- var glyphs, i$, to$, i, results$ = [];
244
- glyphs = f.otf.glyphs;
245
- for (i$ = 1, to$ = glyphs.length; i$ <= to$; ++i$) {
246
- i = i$;
247
- results$.push(glyphs.glyphs[i]);
248
- }
249
- return results$;
250
- }).reduce(function(a, b){
251
- return a.concat(b);
252
- }, []).filter(function(it){
253
- return it;
254
- });
255
- this$.otf.font = new opentype.Font((ref1$ = {
256
- familyName: this$.name,
257
- styleName: this$.style || 'normal',
258
- glyphs: glyphs
259
- }, ref1$.unitsPerEm = (ref$ = list[0].otf).unitsPerEm, ref1$.ascender = ref$.ascender, ref1$.descender = ref$.descender, ref1$));
260
- this$.otf.font.kerningPairs = {};
261
- return this$.otf.font;
262
- });
263
- },
264
- sync: function(txt){
265
- var ref$, misschar, missset, this$ = this;
266
- txt == null && (txt = "");
267
- if (!this.isXl) {
268
- xfl.update();
269
- return Promise.resolve();
270
- }
271
- ref$ = [{}, {}], misschar = ref$[0], missset = ref$[1];
272
- return Promise.resolve().then(function(){
273
- var i$, to$, i, code, setIdx, k, list, res$;
274
- for (i$ = 0, to$ = txt.length; i$ < to$; ++i$) {
275
- i = i$;
276
- code = txt.charCodeAt(i);
277
- if (this$.cjkOnly && !xfl.isCJK(code)) {
278
- continue;
279
- }
280
- setIdx = this$.codemap[code.toString(16)];
281
- if (!setIdx) {
282
- misschar[txt[i]] = true;
283
- } else if (!this$.sub.set[setIdx]) {
284
- this$.sub.set[setIdx] = missset[setIdx] = true;
285
- }
286
- }
287
- misschar = (function(){
288
- var results$ = [];
289
- for (k in misschar) {
290
- results$.push(k);
291
- }
292
- return results$;
293
- }()).filter(function(it){
294
- return it.trim();
295
- });
296
- if (misschar.length) {
297
- console.log("[@plotdb/xfl] sync xl-font with following chars unsupported: " + misschar.join(''));
298
- }
299
- res$ = [];
300
- for (k in missset) {
301
- res$.push(k);
302
- }
303
- list = res$;
304
- if (list.length) {
305
- return this$.fetch(list);
306
- }
307
- }).then(function(){
308
- return xfl.update();
309
- });
310
- }
311
- });
312
- xfl = {
313
- range: {
314
- CJK: [[0x3040, 0x30ff], [0x3400, 0x4dbf], [0x4e00, 0x9fff], [0xf900, 0xfaff], [0xff66, 0xff9f], [0x3131, 0xD79D]]
315
- },
316
- fonts: {},
317
- running: {},
318
- isCJK: function(code){
319
- return this.range.CJK.filter(function(it){
320
- return code >= it[0] && code <= it[1];
321
- }).length;
322
- },
323
- proxy: {},
324
- update: function(){
325
- var css, k, ref$, v, node;
326
- css = "";
327
- for (k in ref$ = this.fonts) {
328
- v = ref$[k];
329
- (v.css || []).filter(fn$).map(fn1$);
330
- }
331
- if (css) {
332
- node = document.createElement("style");
333
- node.textContent = css;
334
- node.setAttribute('type', 'text/css');
335
- return document.body.appendChild(node);
336
- }
337
- function fn$(it){
338
- return !it.rendered;
339
- }
340
- function fn1$(it){
341
- it.rendered = true;
342
- return css = css + it.content;
343
- }
344
- },
345
- _load: function(opt){
346
- var path, this$ = this;
347
- opt == null && (opt = {});
348
- path = opt.path;
349
- if (this.running[path]) {
350
- return;
351
- }
352
- this.running[path] = true;
353
- return Promise.resolve().then(function(){
354
- var fobj;
355
- this$.fonts[path] = fobj = new xlfont(opt);
356
- return fobj.init();
357
- })['finally'](function(){
358
- return this$.running[path] = false;
359
- }).then(function(){
360
- this$.proxy[path].resolve(this$.fonts[path]);
361
- return this$.fonts[path];
362
- })['catch'](function(it){
363
- this$.proxy[path].reject(it);
364
- return Promise.reject(it);
365
- });
366
- },
367
- load: function(opt){
368
- var this$ = this;
369
- opt == null && (opt = {});
370
- if (typeof opt === 'string') {
371
- opt = {
372
- path: opt
373
- };
374
- }
375
- return new Promise(function(res, rej){
376
- var path, that, ref$;
377
- if (!(path = opt.path)) {
378
- return rej(err({
379
- id: 400
380
- }));
381
- }
382
- path = path.replace(/\/$/, '');
383
- if (that = this$.fonts[path]) {
384
- return res(that);
385
- }
386
- if (!this$.proxy[path]) {
387
- this$.proxy[path] = proxise(function(it){
388
- return this$._load(it);
389
- });
390
- }
391
- return this$.proxy[path]((ref$ = import$({}, opt), ref$.path = path, ref$)).then(function(it){
392
- return res(it);
393
- })['catch'](function(it){
394
- return rej(it);
395
- });
396
- });
397
- }
398
- };
399
- if (typeof module != 'undefined' && module !== null) {
400
- module.exports = xfl;
401
- } else if (typeof window != 'undefined' && window !== null) {
402
- window.xfl = xfl;
403
- }
404
- function import$(obj, src){
405
- var own = {}.hasOwnProperty;
406
- for (var key in src) if (own.call(src, key)) obj[key] = src[key];
407
- return obj;
408
- }
409
- }).call(this);
package/dist/xfl.min.js DELETED
@@ -1 +0,0 @@
1
- (function(){var err,xlfont,xfl;err=function(e){e==null&&(e={});return import$(new Error,import$({name:"lderror"},e))};xlfont=function(opt){var ref$,that,this$=this;opt==null&&(opt={});this.opt=opt;this.sub={set:{},font:{}};this.cjkOnly=opt.cjkOnly||false;this.codemap={};this.otf={font:null,dirty:true};this.path=opt.path;this.name=opt.name||(ref$=this.path.replace(/\.[a-zA-Z0-9]+$/,"").split("/").filter(function(it){return it}))[ref$.length-1];this.style="normal";this.ext=opt.ext||(/\.(ttf|otf|woff2|woff)$/.exec(this.path)||[])[1]||"";this.format=(that=this.ext.toLowerCase())?that==="ttf"?"truetype":that==="otf"?"truetype":that:"";if(this.format){this.format="format('"+this.format+"')"}this.className="xfl-"+(this.name||"").replace(/\s+/g,"_")+"-"+Math.random().toString(36).substring(2);this.isXl=!this.ext;this.css=[];this.init=proxise.once(function(){return this$._init()});this.init();return this};xlfont.prototype=import$(Object.create(Object.prototype),{_init:function(){var this$=this;return Promise.resolve().then(function(){if(!this$.isXl){this$.css=[{content:'@font-face {\n font-family: "'+this$.name+'";\n src: url("'+this$.path+'") '+this$.format+";\n}\n."+this$.className+' { font-family: "'+this$.name+'"; }'}];return xfl.update()}else{return new Promise(function(res,rej){var xhr;xhr=new XMLHttpRequest;xhr.addEventListener("readystatechange",function(){if(xhr.readyState!==XMLHttpRequest.DONE){return}if(xhr.status!==200){return rej(err({code:xhr.status,message:xhr.responseText}))}(xhr.responseText||"").split("\n").map(function(d,i){return d.split(" ").map(function(e,j){return this$.codemap[e]=i+1})});return res()});xhr.open("GET",this$.path+"/charmap.txt");return xhr.send()})}})},_fetch:function(f,dofetch){var this$=this;f==null&&(f={});dofetch==null&&(dofetch=false);if(!dofetch){if(!f.url){if(this.isXl){f.url=this.path+"/"+f.key+".woff2";f.type="woff2"}else{f.url=this.path;f.type=this.ext.toLowerCase()}}return Promise.resolve(f)}if(f.blob){return Promise.resolve(f)}if(!f.proxy){f.proxy=proxise(function(f){var p;if(f.running){return}f.running=true;p=new Promise(function(res,rej){var xhr;if(f.blob){return res(f)}xhr=new XMLHttpRequest;xhr.addEventListener("readystatechange",function(){if(xhr.readyState!==XMLHttpRequest.DONE){return}if(xhr.status!==200){return rej(err({code:xhr.status,message:xhr.responseText}))}this$.otf.dirty=true;f.url=URL.createObjectURL(xhr.response);f.blob=xhr.response;f.type=this$.ext.toLowerCase()||"ttf";return res(f)});if(this$.isXl){xhr.open("GET",this$.path+"/"+f.key+".ttf")}else{xhr.open("GET",this$.path)}xhr.responseType="blob";return xhr.send()});return p["finally"](function(){return f.running=false})})}return f.proxy(f)},fetchAll:function(){var k,f,this$=this;if(this.isXl){return Promise.all(function(){var ref$,results$=[];for(k in ref$=this.sub.font){f=ref$[k];results$.push(f)}return results$}.call(this).map(function(it){return this$._fetch(it,true)}))}else{return this._fetch(this.sub.font[0],true)}},fetch:function(list,dofetch){var ps,this$=this;list==null&&(list=[]);dofetch==null&&(dofetch=false);if(!this.isXl){if(this.sub.font[0]&&this.sub.font[0].blob){return Promise.resolve()}list=[0]}ps=Array.from(new Set(list.map(function(it){return it}))).filter(function(it){return!this$.sub.font[it]}).map(function(it){var f;this$.sub.font[it]=f={key:it};return this$._fetch(f,dofetch)});return Promise.all(ps).then(function(subfonts){var css,k,ref$,f,i$,len$;if(!subfonts.length){return}css="."+this$.className+' { font-family: "'+this$.name+'"; }';for(k in ref$=this$.sub.font){f=ref$[k]}for(i$=0,len$=subfonts.length;i$<len$;++i$){f=subfonts[i$];css+='@font-face {\n font-family: "'+this$.name+'";\n src: url("'+f.url+"\") format('"+f.type+"');\n}"}return this$.css.push({content:css})})},getotf:function(){var this$=this;if(!(typeof opentype!="undefined"&&opentype!==null)){return Promise.reject(err({id:1022,message:"[@plotdb/xfl] need opentype.js to merge subfonts"}))}if(!this.otf.dirty){return Promise.resolve(this.otf.font)}return Promise.resolve().then(function(){if(!this$.isXl){return this$.fetch()}else{return this$.fetchAll()}}).then(function(){var ps,k,f;ps=function(){var ref$,results$=[];for(k in ref$=this.sub.font){f=ref$[k];results$.push(f)}return results$}.call(this$).map(function(f){if(f.otf){return Promise.resolve(f)}else{return opentype.load(f.url).then(function(it){f.otf=it;return f})}});return Promise.all(ps)}).then(function(list){var glyphs,ref$,ref1$;list==null&&(list=[]);if(list.length===1){return list[0].otf}glyphs=list.map(function(f){var glyphs,i$,to$,i,results$=[];glyphs=f.otf.glyphs;for(i$=1,to$=glyphs.length;i$<=to$;++i$){i=i$;results$.push(glyphs.glyphs[i])}return results$}).reduce(function(a,b){return a.concat(b)},[]).filter(function(it){return it});this$.otf.font=new opentype.Font((ref1$={familyName:this$.name,styleName:this$.style||"normal",glyphs:glyphs},ref1$.unitsPerEm=(ref$=list[0].otf).unitsPerEm,ref1$.ascender=ref$.ascender,ref1$.descender=ref$.descender,ref1$));this$.otf.font.kerningPairs={};return this$.otf.font})},sync:function(txt){var ref$,misschar,missset,this$=this;txt==null&&(txt="");if(!this.isXl){xfl.update();return Promise.resolve()}ref$=[{},{}],misschar=ref$[0],missset=ref$[1];return Promise.resolve().then(function(){var i$,to$,i,code,setIdx,k,list,res$;for(i$=0,to$=txt.length;i$<to$;++i$){i=i$;code=txt.charCodeAt(i);if(this$.cjkOnly&&!xfl.isCJK(code)){continue}setIdx=this$.codemap[code.toString(16)];if(!setIdx){misschar[txt[i]]=true}else if(!this$.sub.set[setIdx]){this$.sub.set[setIdx]=missset[setIdx]=true}}misschar=function(){var results$=[];for(k in misschar){results$.push(k)}return results$}().filter(function(it){return it.trim()});if(misschar.length){console.log("[@plotdb/xfl] sync xl-font with following chars unsupported: "+misschar.join(""))}res$=[];for(k in missset){res$.push(k)}list=res$;if(list.length){return this$.fetch(list)}}).then(function(){return xfl.update()})}});xfl={range:{CJK:[[12352,12543],[13312,19903],[19968,40959],[63744,64255],[65382,65439],[12593,55197]]},fonts:{},running:{},isCJK:function(code){return this.range.CJK.filter(function(it){return code>=it[0]&&code<=it[1]}).length},proxy:{},update:function(){var css,k,ref$,v,node;css="";for(k in ref$=this.fonts){v=ref$[k];(v.css||[]).filter(fn$).map(fn1$)}if(css){node=document.createElement("style");node.textContent=css;node.setAttribute("type","text/css");return document.body.appendChild(node)}function fn$(it){return!it.rendered}function fn1$(it){it.rendered=true;return css=css+it.content}},_load:function(opt){var path,this$=this;opt==null&&(opt={});path=opt.path;if(this.running[path]){return}this.running[path]=true;return Promise.resolve().then(function(){var fobj;this$.fonts[path]=fobj=new xlfont(opt);return fobj.init()})["finally"](function(){return this$.running[path]=false}).then(function(){this$.proxy[path].resolve(this$.fonts[path]);return this$.fonts[path]})["catch"](function(it){this$.proxy[path].reject(it);return Promise.reject(it)})},load:function(opt){var this$=this;opt==null&&(opt={});if(typeof opt==="string"){opt={path:opt}}return new Promise(function(res,rej){var path,that,ref$;if(!(path=opt.path)){return rej(err({id:400}))}path=path.replace(/\/$/,"");if(that=this$.fonts[path]){return res(that)}if(!this$.proxy[path]){this$.proxy[path]=proxise(function(it){return this$._load(it)})}return this$.proxy[path]((ref$=import$({},opt),ref$.path=path,ref$)).then(function(it){return res(it)})["catch"](function(it){return rej(it)})})}};if(typeof module!="undefined"&&module!==null){module.exports=xfl}else if(typeof window!="undefined"&&window!==null){window.xfl=xfl}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}}).call(this);