@xlfont/load 2.0.0 → 2.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,131 @@
1
+ # Change Logs
2
+
3
+ ## v2.1.0
4
+
5
+ - fix bug: format of css generation in fetch is not correct
6
+ - export xlfont class
7
+
8
+
9
+ ## v2.0.2
10
+
11
+ - fix bug: default value for input dir and `output` directory should be `font` and `output`.
12
+ - remove `dist` folder since it's flatten in root dir
13
+
14
+
15
+ ## v2.0.1
16
+
17
+ - publish module with files under `dist` in root too.
18
+
19
+
20
+ ## v2.0.0
21
+
22
+ - remove deprecated `xfl.js` and `xfl.min.js`
23
+ - further minimize generated js file with mangling and compression
24
+ - update `main`, add `browser` field in `package.json`.
25
+ - upgrade modules
26
+ - patch test code to make it work with upgraded modules
27
+ - fix bug: opentype-url doesn't work
28
+ - use Object URL for worker loading so we don't have to specify its path by ourselves
29
+
30
+
31
+ ## v1.1.1
32
+
33
+ - correctly support web worker by accepting options for worker and dependency url
34
+
35
+
36
+ ## v1.1.0
37
+
38
+ - support merging font locally by opentype.js
39
+ - support web worker ( TBD )
40
+ - suppoty `style` and `weight` information
41
+ - wait explicitly until fonts loaded according to document.fonts in `xfl.update`
42
+ - accept `use-worker` as an option, but still dont enable it
43
+ - normalize font name if it's derived from url
44
+ - load xlfont with woff instead of ttf.
45
+ - support `hasChar(c)`
46
+ - support `getPath(opt)` as xlfont method, which check chars for availability before rendering.
47
+ - let misschar also keep tracks of supported char (by setting it to false)
48
+
49
+
50
+ ## v1.0.13
51
+
52
+ - null check sub.font[0] before using it
53
+ - support string param in `load` api
54
+ - point entry point from `xfl.js` to `index.js`
55
+
56
+
57
+ ## v1.0.12
58
+
59
+ - add back proxise since we can't actually remove it for now
60
+
61
+
62
+ ## v1.0.11
63
+
64
+ - remove dependency to proxise by inlining `once` function
65
+ - rename `xfl.js` while keeping `index.js`, which will be removed in future minor update
66
+ - rename `xfont` to `xlfont` to reflect package name.
67
+
68
+
69
+ ## v1.0.10
70
+
71
+ - escape space in class name
72
+ - quote name in font family name that didn't quote in the last version
73
+
74
+
75
+ ## v1.0.9
76
+
77
+ - escape space in font name
78
+ - quote name and url in font family styles
79
+ - call update for non-xl fonts
80
+ - fix incorrectly assignment in xfl.update
81
+
82
+
83
+ ## v1.0.8
84
+
85
+ - fix bug: `-a` option doesn't work in `xfl-meta`
86
+
87
+
88
+ ## v1.0.7
89
+
90
+ - fix incorrect versioning issue
91
+
92
+
93
+ ## v1.0.5 / v1.0.6
94
+
95
+ - skip notdef by reference instead of by name. This fixed `Taipei Sans TC Beta` generation issue.
96
+
97
+
98
+ ## v1.0.4
99
+
100
+ - handle newlines in metadata
101
+
102
+
103
+ ## v1.0.3
104
+
105
+ - support subsetting only single font in xfl command
106
+ - better formatting of xfl-meta output
107
+
108
+
109
+ ## v1.0.2
110
+
111
+ - add `xfl-meta` command
112
+ - add missing dependency in `build.js`
113
+ - update `package.json` for some dependencies that should be for production
114
+
115
+
116
+ ## v1.0.1
117
+
118
+ - remove npm-shrinkwrap.json
119
+
120
+
121
+ ## v1.0.0
122
+
123
+ - completely rewrite xfl.ls
124
+ - support font merging based on opentype.js
125
+ - non-xl-font aware
126
+ - better support for concurrent fetching
127
+ - support promise in all api
128
+ - use SIL-Open Licensed fonts only for demonstration
129
+ - remove fontmin / gulp-rename dependency
130
+ - add `woff` format output
131
+ - use `@plotdb/opentype.js` for bug fixing
package/README.md CHANGED
@@ -19,7 +19,7 @@ This is a javascript project based on nodeJS / npm. After installing node / npm,
19
19
 
20
20
  use `npx xfl` to subset fonts with `xfl`:
21
21
 
22
- npx xfl font-dir [-f word-frequency-csv] [-o output-dir] [-c major-subset-size] [-s subset-size]
22
+ npx xfl font-dir [o output-dir] [-f word-frequency-csv] [-c major-subset-size] [-s subset-size]
23
23
 
24
24
 
25
25
  where:
@@ -73,6 +73,14 @@ Sync font based on given text:
73
73
  font.sync("含有這些字的字型子集會被載入。Subset containgin glyphs from these chars will be loaded.");
74
74
  });
75
75
 
76
+ Use `font.className` for font related CSS rules:
77
+
78
+ xfl
79
+ .load( ... )
80
+ .then(function(font) {
81
+ font.sync( ... ).then(function() { document.body.classList.add(font.className); });
82
+ })
83
+
76
84
 
77
85
  ## xfl API
78
86
 
@@ -107,6 +115,7 @@ Besides loading from `xfl.load`, you can also manually construct a `xlfont` obje
107
115
 
108
116
  - `init()`: init this font object. `xfl.load` will do this job for you.
109
117
  - `sync(text)`: load fonts based on given text.
118
+ - return a Promise. this will also call `update`
110
119
  - `getotf()`: return a promise, resolved to `opentype.Font` from `opentype.js`.
111
120
  - `opentype.js` is required for this method
112
121
  - `fetchAll()` will be called by this method.
package/bin/build.js CHANGED
@@ -13,7 +13,7 @@
13
13
  ttf2woff = require('ttf2woff');
14
14
  argv = yargs.usage("usage: npx xfl font-dir [-o output-dir] [-c major-subset-size] [-s subset-size]").option('output', {
15
15
  alias: 'o',
16
- description: "output directory. default `./output/`",
16
+ description: "output directory. default `output`",
17
17
  type: 'string'
18
18
  }).option('major-subset-size', {
19
19
  alias: 'c',
@@ -37,8 +37,8 @@
37
37
  commonRanges = [[0, 0xff], [0xff00, 0xffef]];
38
38
  commonSize = argv.c || 1500;
39
39
  setSize = argv.s || 100;
40
- fontDir = argv._[0] || "../fonts";
41
- outDir = argv.o || "../output";
40
+ fontDir = argv._[0] || "fonts";
41
+ outDir = argv.o || "output";
42
42
  defaultFrequencyFile = path.join(libdir, '..', 'tool', 'data', 'word-frequency.csv');
43
43
  if (!fs.existsSync(fontDir)) {
44
44
  console.log(fontDir + " directory not found.");
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function() { var xlfWorkerCode = '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})})};'; var err, xlfWorker, xlfMerger, xlfont, xfl;
1
+ (function() { var xlfWorkerCode = 'var local={},onmessage=function(e){var e=e.data||{},n=e.bufs,p=e.key,e=e.lib;return local.inited||(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,a,o=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,o.push(n.glyphs.glyphs[s]);return n=e[0],a=new opentype.Font(((a={glyphs:o,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,a.ascender=n.ascender,a.descender=n.descender,a)),postMessage({buf:a.toArrayBuffer(),key:p})})};'; var err, xlfWorker, xlfMerger, xlfont, xfl;
2
2
  err = function(e){
3
3
  e == null && (e = {});
4
4
  return import$(new Error(), import$({
@@ -45,7 +45,6 @@ xlfWorker = {
45
45
  rej: rej,
46
46
  key: this$.key++
47
47
  });
48
- console.log(">", opt);
49
48
  return this$.worker.postMessage({
50
49
  bufs: abs,
51
50
  key: item.key,
@@ -88,7 +87,7 @@ xlfMerger = function(arg$){
88
87
  });
89
88
  };
90
89
  xlfont = function(opt){
91
- var that, this$ = this;
90
+ var this$ = this;
92
91
  opt == null && (opt = {});
93
92
  this.opt = opt;
94
93
  this.sub = {
@@ -106,12 +105,7 @@ xlfont = function(opt){
106
105
  this.style = opt.style || 'normal';
107
106
  this.weight = opt.weight || '400';
108
107
  this.ext = opt.ext || (/\.(ttf|otf|woff2|woff)$/.exec(this.path) || [])[1] || '';
109
- this.format = (that = this.ext.toLowerCase()) ? that === 'ttf'
110
- ? 'truetype'
111
- : that === 'otf' ? 'truetype' : that : '';
112
- if (this.format) {
113
- this.format = "format('" + this.format + "')";
114
- }
108
+ this.format = this._format(this.ext);
115
109
  this.className = "xfl-" + (this.name || '').replace(/\s+/g, '_') + "-" + Math.random().toString(36).substring(2);
116
110
  this.isXl = opt.isXl != null
117
111
  ? opt.isXl
@@ -130,6 +124,14 @@ xlfont = function(opt){
130
124
  return this;
131
125
  };
132
126
  xlfont.prototype = import$(Object.create(Object.prototype), {
127
+ _format: function(f){
128
+ f == null && (f = '');
129
+ f = f.toLowerCase();
130
+ f = f === 'ttf'
131
+ ? 'truetype'
132
+ : f === 'otf' ? 'truetype' : f;
133
+ return "format('" + f + "')";
134
+ },
133
135
  _init: function(){
134
136
  var this$ = this;
135
137
  return Promise.resolve().then(function(){
@@ -318,18 +320,17 @@ xlfont.prototype = import$(Object.create(Object.prototype), {
318
320
  }).concat([font]);
319
321
  });
320
322
  }).then(function(subfonts){
321
- var css, k, ref$, f, i$, len$;
323
+ var css, i$, len$, f, format;
322
324
  if (!subfonts.length) {
323
325
  return;
324
326
  }
325
- css = "." + this$.className + " { font-family: \"" + this$.name + "\"; }";
326
- for (k in ref$ = this$.sub.font) {
327
- f = ref$[k];
328
- }
327
+ css = "";
329
328
  for (i$ = 0, len$ = subfonts.length; i$ < len$; ++i$) {
330
329
  f = subfonts[i$];
331
- css += "@font-face {\n font-family: \"" + this$.name + "\";\n src: url(\"" + f.url + "\") format('" + f.type + "');\n font-style: " + this$.style + ";\n font-weight: " + this$.weight + ";\n}";
330
+ format = this$._format(f.type);
331
+ css += "@font-face {\n font-family: \"" + this$.name + "\";\n src: url(\"" + f.url + "\") " + format + ";\n font-style: " + this$.style + ";\n font-weight: " + this$.weight + ";\n}";
332
332
  }
333
+ css += "." + this$.className + " { font-family: \"" + this$.name + "\"; }";
333
334
  return this$.css.push({
334
335
  content: css
335
336
  });
@@ -475,6 +476,7 @@ xlfont.prototype = import$(Object.create(Object.prototype), {
475
476
  }
476
477
  });
477
478
  xfl = {
479
+ xlfont: xlfont,
478
480
  range: {
479
481
  CJK: [[0x3040, 0x30ff], [0x3400, 0x4dbf], [0x4e00, 0x9fff], [0xf900, 0xfaff], [0xff66, 0xff9f], [0x3131, 0xD79D]]
480
482
  },
package/dist/index.min.js CHANGED
@@ -1 +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)}();
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||(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,a,o=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,o.push(n.glyphs.glyphs[s]);return n=e[0],a=new opentype.Font(((a={glyphs:o,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,a.ascender=n.ascender,a.descender=n.descender,a)),postMessage({buf:a.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++}),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=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=this._format(this.ext),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 t._init()}),this.init(),this}).prototype=l(Object.create(Object.prototype),{_format:function(e){return"format('"+(e="ttf"===(e=(e=null==e?"":e).toLowerCase())||"otf"===e?"truetype":e)+"')"},_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,i=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!i.sub.font[e]}).map(function(e,t){var n,r;return i.sub.font[e]=n={key:e},r=i.isXl?"woff":"ttf",n.needMerge=1!=+e,i._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:i.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;if(e.length){for(t="",n=0,r=e.length;n<r;++n)o=e[n],s=i._format(o.type),t+='@font-face {\n font-family: "'+i.name+'";\n src: url("'+o.url+'") '+s+";\n font-style: "+i.style+";\n font-weight: "+i.weight+";\n}";return t+="."+i.className+' { font-family: "'+i.name+'"; }',i.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={xlfont:o,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/dist/worker.js CHANGED
@@ -4,7 +4,6 @@ onmessage = function(e){
4
4
  var ref$, bufs, key, lib;
5
5
  ref$ = e.data || {}, bufs = ref$.bufs, key = ref$.key, lib = ref$.lib;
6
6
  if (!local.inited) {
7
- console.log(lib);
8
7
  importScripts(lib || "opentype.js");
9
8
  local.inited = true;
10
9
  }
@@ -1 +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})})};
1
+ var local={},onmessage=function(e){var e=e.data||{},n=e.bufs,p=e.key,e=e.lib;return local.inited||(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,a,o=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,o.push(n.glyphs.glyphs[s]);return n=e[0],a=new opentype.Font(((a={glyphs:o,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,a.ascender=n.ascender,a.descender=n.descender,a)),postMessage({buf:a.toArrayBuffer(),key:p})})};
package/index.js ADDED
@@ -0,0 +1,592 @@
1
+ (function() { var xlfWorkerCode = 'var local={},onmessage=function(e){var e=e.data||{},n=e.bufs,p=e.key,e=e.lib;return local.inited||(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,a,o=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,o.push(n.glyphs.glyphs[s]);return n=e[0],a=new opentype.Font(((a={glyphs:o,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,a.ascender=n.ascender,a.descender=n.descender,a)),postMessage({buf:a.toArrayBuffer(),key:p})})};'; var err, xlfWorker, xlfMerger, xlfont, xfl;
2
+ err = function(e){
3
+ e == null && (e = {});
4
+ return import$(new Error(), import$({
5
+ name: 'lderror'
6
+ }, e));
7
+ };
8
+ xlfWorker = {
9
+ key: 0,
10
+ worker: null,
11
+ queue: [],
12
+ init: function(opt){
13
+ var this$ = this;
14
+ opt == null && (opt = {});
15
+ return Promise.resolve().then(function(){
16
+ var url;
17
+ if (this$.worker) {
18
+ return;
19
+ }
20
+ url = URL.createObjectURL(new Blob([xlfWorkerCode], {
21
+ type: 'text/javascript'
22
+ }));
23
+ this$.worker = new Worker(url);
24
+ URL.revokeObjectURL(url);
25
+ return this$.worker.onmessage = function(e){
26
+ var ref$, buf, key, item;
27
+ ref$ = e.data, buf = ref$.buf, key = ref$.key;
28
+ if (!(item = this$.queue.filter(function(q){
29
+ return key === q.key;
30
+ })[0])) {
31
+ return;
32
+ }
33
+ this$.queue.splice(this$.queue.indexOf(item), 1);
34
+ return item.res(buf);
35
+ };
36
+ });
37
+ },
38
+ run: function(abs, opt){
39
+ var this$ = this;
40
+ return new Promise(function(res, rej){
41
+ return this$.init(opt).then(function(){
42
+ var item;
43
+ this$.queue.push(item = {
44
+ res: res,
45
+ rej: rej,
46
+ key: this$.key++
47
+ });
48
+ return this$.worker.postMessage({
49
+ bufs: abs,
50
+ key: item.key,
51
+ lib: opt.opentypeUrl
52
+ });
53
+ });
54
+ });
55
+ }
56
+ };
57
+ xlfMerger = function(arg$){
58
+ var bufs, useWorker;
59
+ bufs = arg$.bufs, useWorker = arg$.useWorker;
60
+ if (!bufs.length) {
61
+ return Promise.resolve();
62
+ }
63
+ if (useWorker) {
64
+ return xlfWorker.run(bufs, useWorker);
65
+ }
66
+ return Promise.resolve().then(function(){
67
+ return bufs.map(function(it){
68
+ return opentype.parse(it);
69
+ });
70
+ }).then(function(fonts){
71
+ var glyphs, i$, len$, font, j$, to$, i, merged, ref$;
72
+ glyphs = [];
73
+ for (i$ = 0, len$ = fonts.length; i$ < len$; ++i$) {
74
+ font = fonts[i$];
75
+ for (j$ = 0, to$ = font.glyphs.length; j$ < to$; ++j$) {
76
+ i = j$;
77
+ glyphs.push(font.glyphs.glyphs[i]);
78
+ }
79
+ }
80
+ font = fonts[0];
81
+ merged = new opentype.Font((ref$ = {
82
+ glyphs: glyphs,
83
+ familyName: font.names.fontFamily.en,
84
+ styleName: font.names.fontSubfamily.en
85
+ }, ref$.unitsPerEm = font.unitsPerEm, ref$.ascender = font.ascender, ref$.descender = font.descender, ref$));
86
+ return merged.toArrayBuffer();
87
+ });
88
+ };
89
+ xlfont = function(opt){
90
+ var this$ = this;
91
+ opt == null && (opt = {});
92
+ this.opt = opt;
93
+ this.sub = {
94
+ set: {},
95
+ font: {}
96
+ };
97
+ this.cjkOnly = opt.cjkOnly || false;
98
+ this.codemap = {};
99
+ this.otf = {
100
+ font: null,
101
+ dirty: true
102
+ };
103
+ this.path = opt.path;
104
+ this.name = opt.name || this.path.replace(/\.[a-zA-Z0-9]+$/, '').replace(/^https?:\/\/[^/]+\//g, '').replace(/\s/g, '-').replace(/\//g, '-').toLowerCase();
105
+ this.style = opt.style || 'normal';
106
+ this.weight = opt.weight || '400';
107
+ this.ext = opt.ext || (/\.(ttf|otf|woff2|woff)$/.exec(this.path) || [])[1] || '';
108
+ this.format = this._format(this.ext);
109
+ this.className = "xfl-" + (this.name || '').replace(/\s+/g, '_') + "-" + Math.random().toString(36).substring(2);
110
+ this.isXl = opt.isXl != null
111
+ ? opt.isXl
112
+ : !this.ext;
113
+ if (!this.ext) {
114
+ this.ext = 'woff';
115
+ }
116
+ this.doMerge = opt.doMerge != null ? opt.doMerge : false;
117
+ this.useWorker = opt.useWorker != null ? opt.useWorker : false;
118
+ this.misschar = {};
119
+ this.css = [];
120
+ this.init = proxise.once(function(){
121
+ return this$._init();
122
+ });
123
+ this.init();
124
+ return this;
125
+ };
126
+ xlfont.prototype = import$(Object.create(Object.prototype), {
127
+ _format: function(f){
128
+ f == null && (f = '');
129
+ f = f.toLowerCase();
130
+ f = f === 'ttf'
131
+ ? 'truetype'
132
+ : f === 'otf' ? 'truetype' : f;
133
+ return "format('" + f + "')";
134
+ },
135
+ _init: function(){
136
+ var this$ = this;
137
+ return Promise.resolve().then(function(){
138
+ if (!this$.isXl) {
139
+ this$.css = [{
140
+ content: "@font-face {\n font-family: \"" + this$.name + "\";\n src: url(\"" + this$.path + "\") " + this$.format + ";\n font-style: " + this$.style + ";\n font-weight: " + this$.weight + ";\n}\n." + this$.className + " { font-family: \"" + this$.name + "\"; }"
141
+ }];
142
+ return xfl.update();
143
+ } else {
144
+ return new Promise(function(res, rej){
145
+ var xhr;
146
+ xhr = new XMLHttpRequest();
147
+ xhr.addEventListener('readystatechange', function(){
148
+ if (xhr.readyState !== XMLHttpRequest.DONE) {
149
+ return;
150
+ }
151
+ if (xhr.status !== 200) {
152
+ return rej(err({
153
+ code: xhr.status,
154
+ message: xhr.responseText
155
+ }));
156
+ }
157
+ (xhr.responseText || '').split('\n').map(function(d, i){
158
+ return d.split(' ').map(function(e, j){
159
+ return this$.codemap[e] = i + 1;
160
+ });
161
+ });
162
+ return res();
163
+ });
164
+ xhr.open('GET', this$.path + "/charmap.txt");
165
+ return xhr.send();
166
+ });
167
+ }
168
+ });
169
+ },
170
+ _fetch: function(f, dofetch, type){
171
+ var this$ = this;
172
+ f == null && (f = {});
173
+ dofetch == null && (dofetch = false);
174
+ type == null && (type = 'ttf');
175
+ if (!dofetch) {
176
+ if (!f.url) {
177
+ if (this.isXl) {
178
+ f.url = this.path + "/" + f.key + "." + type;
179
+ f.type = type;
180
+ } else {
181
+ f.url = this.path;
182
+ f.type = this.ext.toLowerCase() || type;
183
+ }
184
+ }
185
+ return Promise.resolve(f);
186
+ }
187
+ if (f.blob) {
188
+ return Promise.resolve(f);
189
+ }
190
+ if (!f.proxy) {
191
+ f.proxy = proxise(function(f){
192
+ var p;
193
+ if (f.running) {
194
+ return;
195
+ }
196
+ f.running = true;
197
+ p = new Promise(function(res, rej){
198
+ var xhr;
199
+ if (f.blob) {
200
+ return res(f);
201
+ }
202
+ xhr = new XMLHttpRequest();
203
+ xhr.addEventListener('readystatechange', function(){
204
+ if (xhr.readyState !== XMLHttpRequest.DONE) {
205
+ return;
206
+ }
207
+ if (xhr.status !== 200) {
208
+ return rej(err({
209
+ code: xhr.status,
210
+ message: xhr.responseText
211
+ }));
212
+ }
213
+ this$.otf.dirty = true;
214
+ f.url = URL.createObjectURL(xhr.response);
215
+ f.blob = xhr.response;
216
+ f.type = this$.ext.toLowerCase() || type;
217
+ return res(f);
218
+ });
219
+ if (this$.isXl) {
220
+ xhr.open('GET', this$.path + "/" + f.key + "." + type);
221
+ } else {
222
+ xhr.open('GET', this$.path);
223
+ }
224
+ xhr.responseType = 'blob';
225
+ return xhr.send();
226
+ });
227
+ return p['finally'](function(){
228
+ return f.running = false;
229
+ });
230
+ });
231
+ }
232
+ return f.proxy(f);
233
+ },
234
+ fetchAll: function(){
235
+ var k, f, this$ = this;
236
+ if (this.isXl) {
237
+ return Promise.all((function(){
238
+ var ref$, results$ = [];
239
+ for (k in ref$ = this.sub.font) {
240
+ f = ref$[k];
241
+ results$.push(f);
242
+ }
243
+ return results$;
244
+ }.call(this)).map(function(it){
245
+ return this$._fetch(it, true, 'woff');
246
+ }));
247
+ } else {
248
+ return this._fetch(this.sub.font[0], true, 'ttf');
249
+ }
250
+ },
251
+ fetch: function(list, dofetch){
252
+ var doMerge, ps, this$ = this;
253
+ list == null && (list = []);
254
+ dofetch == null && (dofetch = false);
255
+ if (!this.isXl) {
256
+ if (this.sub.font[0] && this.sub.font[0].blob) {
257
+ return Promise.resolve();
258
+ }
259
+ list = [0];
260
+ }
261
+ doMerge = this.doMerge;
262
+ ps = Array.from(new Set(list.map(function(it){
263
+ return it;
264
+ }))).filter(function(it){
265
+ return !this$.sub.font[it];
266
+ }).map(function(d, i){
267
+ var f, type;
268
+ this$.sub.font[d] = f = {
269
+ key: d
270
+ };
271
+ type = !this$.isXl ? 'ttf' : 'woff';
272
+ f.needMerge = +d !== 1;
273
+ return this$._fetch(f, !doMerge ? dofetch : true, type);
274
+ });
275
+ return Promise.all(ps).then(function(subfonts){
276
+ var ps;
277
+ if (!doMerge) {
278
+ return subfonts;
279
+ }
280
+ ps = subfonts.filter(function(it){
281
+ return it.needMerge;
282
+ }).map(function(font){
283
+ return new Promise(function(res, rej){
284
+ var fr;
285
+ fr = new FileReader();
286
+ fr.onerror = function(it){
287
+ return rej(it);
288
+ };
289
+ fr.onload = function(){
290
+ return res(fr.result);
291
+ };
292
+ return fr.readAsArrayBuffer(font.blob);
293
+ });
294
+ });
295
+ return Promise.all(ps).then(function(it){
296
+ return xlfMerger({
297
+ bufs: it,
298
+ useWorker: this$.useWorker
299
+ });
300
+ }).then(function(ab){
301
+ var font, blob;
302
+ if (!ab) {
303
+ return subfonts.filter(function(it){
304
+ return !it.needMerge;
305
+ });
306
+ }
307
+ font = subfonts.filter(function(it){
308
+ return it.needMerge;
309
+ })[0];
310
+ blob = new Blob([ab], {
311
+ type: "font/" + (font.type || 'ttf')
312
+ });
313
+ font = {
314
+ url: URL.createObjectURL(blob),
315
+ blob: blob,
316
+ type: font.type || 'ttf'
317
+ };
318
+ return subfonts.filter(function(it){
319
+ return !it.needMerge;
320
+ }).concat([font]);
321
+ });
322
+ }).then(function(subfonts){
323
+ var css, i$, len$, f, format;
324
+ if (!subfonts.length) {
325
+ return;
326
+ }
327
+ css = "";
328
+ for (i$ = 0, len$ = subfonts.length; i$ < len$; ++i$) {
329
+ f = subfonts[i$];
330
+ format = this$._format(f.type);
331
+ css += "@font-face {\n font-family: \"" + this$.name + "\";\n src: url(\"" + f.url + "\") " + format + ";\n font-style: " + this$.style + ";\n font-weight: " + this$.weight + ";\n}";
332
+ }
333
+ css += "." + this$.className + " { font-family: \"" + this$.name + "\"; }";
334
+ return this$.css.push({
335
+ content: css
336
+ });
337
+ });
338
+ },
339
+ hasChar: function(c){
340
+ return typeof this.misschar[c] === 'undefined'
341
+ ? undefined
342
+ : !this.misshcar[c];
343
+ },
344
+ getPath: function(opt){
345
+ var ref$, text, x, y, fontSize, this$ = this;
346
+ opt == null && (opt = {});
347
+ ref$ = import$({
348
+ text: '',
349
+ x: 0,
350
+ y: 0,
351
+ fontSize: 48
352
+ }, opt), text = ref$.text, x = ref$.x, y = ref$.y, fontSize = ref$.fontSize;
353
+ return this.sync(text).then(function(){
354
+ return this$.getotf();
355
+ }).then(function(otf){
356
+ var txt, i$, to$, i, path;
357
+ txt = '';
358
+ for (i$ = 0, to$ = text.length; i$ < to$; ++i$) {
359
+ i = i$;
360
+ txt += !this$.misschar[text[i]] ? text[i] : ' ';
361
+ }
362
+ path = otf.getPath(txt, x, y, fontSize);
363
+ return path;
364
+ });
365
+ },
366
+ getotf: function(){
367
+ var this$ = this;
368
+ if (!(typeof opentype != 'undefined' && opentype !== null)) {
369
+ return Promise.reject(err({
370
+ id: 1022,
371
+ message: "[@plotdb/xfl] need opentype.js to merge subfonts"
372
+ }));
373
+ }
374
+ if (!this.otf.dirty) {
375
+ return Promise.resolve(this.otf.font);
376
+ }
377
+ return Promise.resolve().then(function(){
378
+ if (!this$.isXl) {
379
+ return this$.fetch();
380
+ } else {
381
+ return this$.fetchAll();
382
+ }
383
+ }).then(function(){
384
+ var ps, k, f;
385
+ ps = (function(){
386
+ var ref$, results$ = [];
387
+ for (k in ref$ = this.sub.font) {
388
+ f = ref$[k];
389
+ results$.push(f);
390
+ }
391
+ return results$;
392
+ }.call(this$)).map(function(f){
393
+ if (f.otf) {
394
+ return Promise.resolve(f);
395
+ } else {
396
+ return opentype.load(f.url).then(function(it){
397
+ f.otf = it;
398
+ return f;
399
+ });
400
+ }
401
+ });
402
+ return Promise.all(ps);
403
+ }).then(function(list){
404
+ var glyphs, ref$, ref1$;
405
+ list == null && (list = []);
406
+ if (list.length === 1) {
407
+ return list[0].otf;
408
+ }
409
+ glyphs = list.map(function(f){
410
+ var glyphs, i$, to$, i, results$ = [];
411
+ glyphs = f.otf.glyphs;
412
+ for (i$ = 1, to$ = glyphs.length; i$ <= to$; ++i$) {
413
+ i = i$;
414
+ results$.push(glyphs.glyphs[i]);
415
+ }
416
+ return results$;
417
+ }).reduce(function(a, b){
418
+ return a.concat(b);
419
+ }, []).filter(function(it){
420
+ return it;
421
+ });
422
+ this$.otf.font = new opentype.Font((ref1$ = {
423
+ familyName: this$.name,
424
+ styleName: this$.style || 'normal',
425
+ glyphs: glyphs
426
+ }, ref1$.unitsPerEm = (ref$ = list[0].otf).unitsPerEm, ref1$.ascender = ref$.ascender, ref1$.descender = ref$.descender, ref1$));
427
+ this$.otf.font.kerningPairs = {};
428
+ return this$.otf.font;
429
+ });
430
+ },
431
+ sync: function(txt){
432
+ var this$ = this;
433
+ txt == null && (txt = "");
434
+ if (!this.isXl) {
435
+ xfl.update();
436
+ return Promise.resolve();
437
+ }
438
+ return Promise.resolve().then(function(){
439
+ var ref$, misscodes, missset, i$, to$, i, code, setIdx, k, list, res$;
440
+ ref$ = [{}, {}], misscodes = ref$[0], missset = ref$[1];
441
+ for (i$ = 0, to$ = txt.length; i$ < to$; ++i$) {
442
+ i = i$;
443
+ code = txt.charCodeAt(i);
444
+ if (this$.cjkOnly && !xfl.isCJK(code)) {
445
+ continue;
446
+ }
447
+ setIdx = this$.codemap[code.toString(16)];
448
+ this$.misschar[txt[i]] = misscodes[txt[i]] = !setIdx ? true : false;
449
+ if (setIdx && !this$.sub.set[setIdx]) {
450
+ this$.sub.set[setIdx] = missset[setIdx] = true;
451
+ }
452
+ }
453
+ misscodes = (function(){
454
+ var results$ = [];
455
+ for (k in misscodes) {
456
+ results$.push(k);
457
+ }
458
+ return results$;
459
+ }()).filter(function(it){
460
+ return misscodes[it];
461
+ });
462
+ if (misscodes.length) {
463
+ console.log("[@plotdb/xfl] sync xl-font with following chars unsupported: " + misscodes.join(''));
464
+ }
465
+ res$ = [];
466
+ for (k in missset) {
467
+ res$.push(k);
468
+ }
469
+ list = res$;
470
+ if (list.length) {
471
+ return this$.fetch(list);
472
+ }
473
+ }).then(function(){
474
+ return xfl.update();
475
+ });
476
+ }
477
+ });
478
+ xfl = {
479
+ xlfont: xlfont,
480
+ range: {
481
+ CJK: [[0x3040, 0x30ff], [0x3400, 0x4dbf], [0x4e00, 0x9fff], [0xf900, 0xfaff], [0xff66, 0xff9f], [0x3131, 0xD79D]]
482
+ },
483
+ fonts: {},
484
+ running: {},
485
+ isCJK: function(code){
486
+ return this.range.CJK.filter(function(it){
487
+ return code >= it[0] && code <= it[1];
488
+ }).length;
489
+ },
490
+ proxy: {},
491
+ update: function(){
492
+ var css, k, ref$, v, node, f;
493
+ css = "";
494
+ for (k in ref$ = this.fonts) {
495
+ v = ref$[k];
496
+ (v.css || []).filter(fn$).map(fn1$);
497
+ }
498
+ if (css) {
499
+ node = document.createElement("style");
500
+ node.textContent = css;
501
+ node.setAttribute('type', 'text/css');
502
+ document.body.appendChild(node);
503
+ }
504
+ return Promise.all((function(){
505
+ var ref$, results$ = [];
506
+ for (k in ref$ = this.fonts) {
507
+ f = ref$[k];
508
+ results$.push(f);
509
+ }
510
+ return results$;
511
+ }.call(this)).map(function(){
512
+ return document.fonts.load("16px " + v.name);
513
+ })).then(function(){
514
+ return new Promise(function(res, rej){
515
+ return setTimeout(function(){
516
+ return res();
517
+ }, 350);
518
+ });
519
+ });
520
+ function fn$(it){
521
+ return !it.rendered;
522
+ }
523
+ function fn1$(it){
524
+ it.rendered = true;
525
+ return css = css + it.content;
526
+ }
527
+ },
528
+ _load: function(opt){
529
+ var path, this$ = this;
530
+ opt == null && (opt = {});
531
+ path = opt.path;
532
+ if (this.running[path]) {
533
+ return;
534
+ }
535
+ this.running[path] = true;
536
+ return Promise.resolve().then(function(){
537
+ var fobj;
538
+ this$.fonts[path] = fobj = new xlfont(opt);
539
+ return fobj.init();
540
+ })['finally'](function(){
541
+ return this$.running[path] = false;
542
+ }).then(function(){
543
+ this$.proxy[path].resolve(this$.fonts[path]);
544
+ return this$.fonts[path];
545
+ })['catch'](function(it){
546
+ this$.proxy[path].reject(it);
547
+ return Promise.reject(it);
548
+ });
549
+ },
550
+ load: function(opt){
551
+ var this$ = this;
552
+ opt == null && (opt = {});
553
+ if (typeof opt === 'string') {
554
+ opt = {
555
+ path: opt
556
+ };
557
+ }
558
+ return new Promise(function(res, rej){
559
+ var path, that, ref$;
560
+ if (!(path = opt.path)) {
561
+ return rej(err({
562
+ id: 400
563
+ }));
564
+ }
565
+ path = path.replace(/\/$/, '');
566
+ if (that = this$.fonts[path]) {
567
+ return res(that);
568
+ }
569
+ if (!this$.proxy[path]) {
570
+ this$.proxy[path] = proxise(function(it){
571
+ return this$._load(it);
572
+ });
573
+ }
574
+ return this$.proxy[path]((ref$ = import$({}, opt), ref$.path = path, ref$)).then(function(it){
575
+ return res(it);
576
+ })['catch'](function(it){
577
+ return rej(it);
578
+ });
579
+ });
580
+ }
581
+ };
582
+ if (typeof module != 'undefined' && module !== null) {
583
+ module.exports = xfl;
584
+ } else if (typeof window != 'undefined' && window !== null) {
585
+ window.xfl = xfl;
586
+ }
587
+ function import$(obj, src){
588
+ var own = {}.hasOwnProperty;
589
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
590
+ return obj;
591
+ }
592
+ }());
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||(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,a,o=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,o.push(n.glyphs.glyphs[s]);return n=e[0],a=new opentype.Font(((a={glyphs:o,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,a.ascender=n.ascender,a.descender=n.descender,a)),postMessage({buf:a.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++}),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=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=this._format(this.ext),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 t._init()}),this.init(),this}).prototype=l(Object.create(Object.prototype),{_format:function(e){return"format('"+(e="ttf"===(e=(e=null==e?"":e).toLowerCase())||"otf"===e?"truetype":e)+"')"},_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,i=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!i.sub.font[e]}).map(function(e,t){var n,r;return i.sub.font[e]=n={key:e},r=i.isXl?"woff":"ttf",n.needMerge=1!=+e,i._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:i.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;if(e.length){for(t="",n=0,r=e.length;n<r;++n)o=e[n],s=i._format(o.type),t+='@font-face {\n font-family: "'+i.name+'";\n src: url("'+o.url+'") '+s+";\n font-style: "+i.style+";\n font-weight: "+i.weight+";\n}";return t+="."+i.className+' { font-family: "'+i.name+'"; }',i.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={xlfont:o,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,78 +1 @@
1
- {
2
- "author": "zbryikt",
3
- "name": "@xlfont/load",
4
- "license": "MIT",
5
- "description": "XL font generator and loader",
6
- "version": "2.0.0",
7
- "browser": "dist/index.min.js",
8
- "main": "dist/index.min.js",
9
- "homepage": "https://github.com/xlfont/load",
10
- "files": [
11
- "dist/**/*",
12
- "tool/data/*"
13
- ],
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/xlfont/load"
17
- },
18
- "engines": {
19
- "node": ">=10.14.1",
20
- "npm": ">=6.4.1"
21
- },
22
- "scripts": {
23
- "start": "npx server -r web -o true"
24
- },
25
- "bin": {
26
- "xfl": "./bin/build.js",
27
- "xfl-meta": "./bin/meta.js"
28
- },
29
- "dependencies": {
30
- "@plotdb/opentype.js": "^1.3.5",
31
- "@plotdb/colors": "^0.0.1",
32
- "fs-extra": "^9.1.0",
33
- "progress": "^2.0.3",
34
- "ttf2woff": "^2.0.2",
35
- "ttf2woff2": "^4.0.0",
36
- "yargs": "^16.2.0"
37
- },
38
- "devDependencies": {
39
- "@loadingio/bootstrap.ext": "^0.0.4",
40
- "@loadingio/debounce.js": "^1.0.1",
41
- "@loadingio/ldquery": "^3.0.1",
42
- "@loadingio/loading.css": "^3.0.0",
43
- "@zbryikt/deploy": "^0.0.1",
44
- "@zbryikt/template": "^2.3.33",
45
- "bootstrap": "^4.5.3",
46
- "bootstrap.native": "^3.0.13",
47
- "fedep": "^1.1.0",
48
- "ldbutton": "^2.0.0",
49
- "ldcover": "^3.0.1",
50
- "ldloader": "^3.0.0",
51
- "ldview": "^1.0.0",
52
- "livescript": "^1.6.0",
53
- "stylus": "^0.55.0",
54
- "uglify-js": "^3.13.1",
55
- "uglifycss": "^0.0.29"
56
- },
57
- "peerDependencies": {
58
- "@plotdb/opentype.js": "^1.3.5",
59
- "proxise": "^1.0.1"
60
- },
61
- "frontendDependencies": {
62
- "root": "web/static/assets/lib",
63
- "modules": [
64
- "bootstrap",
65
- "bootstrap.native",
66
- "@loadingio/bootstrap.ext",
67
- "@loadingio/ldquery",
68
- "@loadingio/debounce.js",
69
- "@loadingio/loading.css",
70
- "@plotdb/opentype.js",
71
- "ldview",
72
- "ldcover",
73
- "ldloader",
74
- "ldbutton",
75
- "proxise"
76
- ]
77
- }
78
- }
1
+ {"author":"zbryikt","name":"@xlfont/load","license":"MIT","description":"XL font generator and loader","version":"2.1.0","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,35 @@
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
+ importScripts(lib || "opentype.js");
8
+ local.inited = true;
9
+ }
10
+ return Promise.resolve().then(function(){
11
+ return bufs.map(function(it){
12
+ return opentype.parse(it);
13
+ });
14
+ }).then(function(fonts){
15
+ var glyphs, i$, len$, font, j$, to$, i, merged, ref$;
16
+ glyphs = [];
17
+ for (i$ = 0, len$ = fonts.length; i$ < len$; ++i$) {
18
+ font = fonts[i$];
19
+ for (j$ = 0, to$ = font.glyphs.length; j$ < to$; ++j$) {
20
+ i = j$;
21
+ glyphs.push(font.glyphs.glyphs[i]);
22
+ }
23
+ }
24
+ font = fonts[0];
25
+ merged = new opentype.Font((ref$ = {
26
+ glyphs: glyphs,
27
+ familyName: font.names.fontFamily.en,
28
+ styleName: font.names.fontSubfamily.en
29
+ }, ref$.unitsPerEm = font.unitsPerEm, ref$.ascender = font.ascender, ref$.descender = font.descender, ref$));
30
+ return postMessage({
31
+ buf: merged.toArrayBuffer(),
32
+ key: key
33
+ });
34
+ });
35
+ };
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||(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,a,o=[],l=0,i=e.length;l<i;++l)for(t=0,r=(n=e[l]).glyphs.length;t<r;++t)s=t,o.push(n.glyphs.glyphs[s]);return n=e[0],a=new opentype.Font(((a={glyphs:o,familyName:n.names.fontFamily.en,styleName:n.names.fontSubfamily.en}).unitsPerEm=n.unitsPerEm,a.ascender=n.ascender,a.descender=n.descender,a)),postMessage({buf:a.toArrayBuffer(),key:p})})};