var F=(d,u)=>()=>(u||d((u={exports:{}}).exports,u),u.exports);var m=F((v,A)=>{(function(d,u){typeof v=="object"&&typeof A<"u"?A.exports=u():typeof define=="function"&&define.amd?define(u):(d=d||self,d.FontReader=u())})(v,function(){"use strict";function d(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function u(t,r){for(var e=0;e<r.length;e++){var a=r[e];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function o(t,r,e){return r&&u(t.prototype,r),e&&u(t,e),t}function h(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function y(t){return k(t)||S(t)||p()}function k(t){if(Array.isArray(t)){for(var r=0,e=new Array(t.length);r<t.length;r++)e[r]=t[r];return e}}function S(t){if(Symbol.iterator in Object(t)||Object.prototype.toString.call(t)==="[object Arguments]")return Array.from(t)}function p(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function b(t,r){return(Array(r+1).join("0")+t).slice(-r)}var l=function(){o(t,null,[{key:"read",value:function(e){return new this(e)}}]);function t(r){d(this,t),h(this,"index",0),this.view=new DataView(r),this.typeArray=new Uint8Array(r)}return o(t,[{key:"readAsDataChunk",value:function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,a=this.typeArray.slice(this.index,this.index+=e);return this.constructor.read(a.buffer)}},{key:"readAsUShort",value:function(){var e=this.view.getUint16(this.index);return this.index+=2,e}},{key:"readAsULong",value:function(){var e=this.view.getUint32(this.index);return this.index+=4,e}},{key:"readAsStringFrom",value:function(e,a){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1,i=y(this.typeArray.slice(e,e+a));return n?unescape(i.map(function(s){return b(s.toString(16),2)}).join("").replace(/(\w{4})/g,"%u$1")):i.map(function(s){return String.fromCharCode(s)}).join("")}},{key:"readAsString",value:function(e,a){var n=this.readAsStringFrom(this.index,e,a);return this.index+=e,n}},{key:"seek",value:function(e){return this.index=e,this}},{key:"skip",value:function(e){return this.index+=e,this}},{key:"tell",value:function(){return this.index}},{key:"length",get:function(){return this.typeArray.length}}]),t}(),w=function(){function t(r){d(this,t),h(this,"attrs",[]),this.reader=l.read(r);for(var e=this.reader.readAsDataChunk(12),a=this.readFileHeader(e),n=0;n<a;n++){var i=this.reader.readAsULong(),s=new c(r,i);this.attrs.push(s.getAttrs())}}return o(t,[{key:"readFileHeader",value:function(e){var a=e.readAsString(4);if(a==="ttcf"){var n=e.readAsUShort(),i=e.readAsUShort();if((n===1||n===2)&&i===0){var s=e.readAsULong();return s}}throw new Error("Not a ttc file")}},{key:"getAttrs",value:function(){return this.attrs}}]),t}(),c=function(){function t(r){var e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;d(this,t),h(this,"attrsMap",{0:"copyright",1:"fontFamily",2:"fontSubFamily",3:"fontIdentifier",4:"fontName",5:"fontVersion",6:"postscriptName",7:"trademark"}),h(this,"attrs",{}),this.reader=l.read(r),this.reader.seek(e);var a=this.reader.readAsDataChunk(12),n=this.readFileHeader(a),i=this.findNameTablesOffset(n);this.reader.seek(i),this.readAttrs()}return o(t,[{key:"readFileHeader",value:function(e){var a=e.readAsUShort(),n=e.readAsUShort(),i=e.readAsUShort();if(a!==1||n!==0)throw new Error("Not a ttf file");return i}},{key:"findNameTablesOffset",value:function(e){for(var a=!1,n,i=0;i<e;i++){n=this.reader.readAsDataChunk(16);var s=n.readAsString(4);if(s==="name"){a=!0;break}}if(!a)throw new Error("Can't find name table");n.skip(4);var f=n.readAsULong();return f}},{key:"readAttrs",value:function(){var e=this.reader.tell();this.reader.skip(2);for(var a=this.reader.readAsUShort(),n=this.reader.readAsUShort(),i=e+n,s=0;s<a;s++){var f=this.reader.readAsDataChunk(12);this.readNameeRecord(f,i)}}},{key:"readNameeRecord",value:function(e,a){var n=e.readAsUShort(),i=e.readAsUShort();e.skip(2);var s=e.readAsUShort(),f=e.readAsUShort(),T=e.readAsUShort();if(!(s>7||f<=0)&&[0,3].indexOf(n)!==-1&&!(n===0&&[0,1,3].indexOf(i)===-1)&&!(n===3&&i!==1)){var g=this.reader.readAsStringFrom(a+T,f,!0);if(g.trim()){var C=this.attrsMap[s];this.setAttr(C,g)}}}},{key:"setAttr",value:function(e,a){this.attrs[e]||(this.attrs[e]=a)}},{key:"getAttrs",value:function(){return this.attrs}}]),t}(),U={DataReader:l,TTFReader:c,TTCReader:w};return U})});var O=m();module.exports=O;
