UNPKG

svg-text-to-vector

Version:

Converts textfield tags in an SVG file to vector paths.

1 lines 7.58 kB
const _0x2137e4=_0xdf78;(function(_0xa4ffd7,_0x4ad2f6){const _0x40c062=_0xdf78,_0x4e65d2=_0xa4ffd7();while(!![]){try{const _0x30f7cd=parseInt(_0x40c062(0x1a2))/0x1+parseInt(_0x40c062(0x1c1))/0x2+-parseInt(_0x40c062(0x1a3))/0x3*(parseInt(_0x40c062(0x1d9))/0x4)+-parseInt(_0x40c062(0x1c6))/0x5*(parseInt(_0x40c062(0x1cf))/0x6)+parseInt(_0x40c062(0x1a5))/0x7+parseInt(_0x40c062(0x1a8))/0x8+-parseInt(_0x40c062(0x1b7))/0x9;if(_0x30f7cd===_0x4ad2f6)break;else _0x4e65d2['push'](_0x4e65d2['shift']());}catch(_0xd97a26){_0x4e65d2['push'](_0x4e65d2['shift']());}}}(_0x1e40,0x46a98));const opentype=require(_0x2137e4(0x1ca)),fs=require('fs'),fontConfigPath=require['resolve'](_0x2137e4(0x1dc));function _0x1e40(){const _0x44d91c=['y=\x22','</text','path','fontSize','replace','test','all','utf-8','save','221238PYtCVb','forEach','toPathData','svgToPath','<path\x20','55iSnTIp','loadSync','toString','readFileSync','opentype.js','load','<text','resolve','(?:[A-Za-z0-9+\x5c/]{4})*(?:[A-Za-z0-9+\x5c/]{2}==|[A-Za-z0-9+/]{3}=)?','252660mckSVH','</text>','fontPath','Times\x20New\x20Roman','toLowerCase','size','length','includes','buffer','font-family=\x22','1228CHReOp','line','split','svg-text-to-vector/config/fonts.json','trim','svg-text-to-vector/config/fonts/times.ttf','<tspan\x20','226057nDAHIp','1497cTIEEP','utf8','3513930ZmotQc','from','font-size','2072920lgCFvD','</path>','</tspan>','name','keys','d=\x22','base64','writeFileSync','pop','font','map','parse','getPath','<tspan','match','1727514OhpTkE'];_0x1e40=function(){return _0x44d91c;};return _0x1e40();}var defaultFont=_0x2137e4(0x1d2),defaultFontPath=require[_0x2137e4(0x1cd)](_0x2137e4(0x1de)),defaultFontSize=0x10,regex_base64=_0x2137e4(0x1ce),regex_svg=/(<svg)([^<]*|[^>]*)/g;exports[_0x2137e4(0x1c4)]=async function(_0x19e3f0){const _0x1185eb=_0x2137e4;var _0x1f193b;if(Buffer['isBuffer'](_0x19e3f0[_0x1185eb(0x1cb)])==!![])_0x1f193b=_0x19e3f0[_0x1185eb(0x1cb)]['toString'](_0x1185eb(0x1a4));else{if(new RegExp('^'+regex_base64+'$','gi')[_0x1185eb(0x1bd)](_0x19e3f0['load'])==!![])_0x1f193b=Buffer[_0x1185eb(0x1a6)](_0x19e3f0['load'],_0x1185eb(0x1ae))[_0x1185eb(0x1c8)](_0x1185eb(0x1a4));else{if(new RegExp(regex_svg)[_0x1185eb(0x1bd)](_0x19e3f0[_0x1185eb(0x1cb)])==!![])_0x1f193b=_0x19e3f0[_0x1185eb(0x1cb)];else _0x1f193b=fs[_0x1185eb(0x1c9)](_0x19e3f0[_0x1185eb(0x1cb)],_0x1185eb(0x1a4));}}_0x19e3f0[_0x1185eb(0x1b1)]&&_0x19e3f0[_0x1185eb(0x1d1)]&&(_0x19e3f0['font']['trim']()!=''&&_0x19e3f0[_0x1185eb(0x1d1)][_0x1185eb(0x1dd)]()!=''&&(defaultFont=_0x19e3f0[_0x1185eb(0x1b1)],defaultFontPath=_0x19e3f0['fontPath']));_0x19e3f0[_0x1185eb(0x1bb)]&&(_0x19e3f0[_0x1185eb(0x1bb)]['toString']()[_0x1185eb(0x1dd)]()!=''&&(defaultFontSize=_0x19e3f0[_0x1185eb(0x1bb)]));var _0x532c2e=(_0x1f193b['match'](/<text/g)||[])[_0x1185eb(0x1d5)];Array[_0x1185eb(0x1a6)]({'length':_0x532c2e})[_0x1185eb(0x1c2)]((_0x58bdc2,_0x255fd6)=>{const _0x24ff13=_0x1185eb;_0x1f193b=_0x1f193b['replace']('<text\x20',_0x24ff13(0x1cc)+_0x255fd6+'\x20'),_0x1f193b=_0x1f193b[_0x24ff13(0x1bc)](_0x24ff13(0x1d0),_0x24ff13(0x1b9)+_0x255fd6+'>');});const _0x568744=Array(_0x532c2e)['fill']()[_0x1185eb(0x1b2)](async(_0x3dde6a,_0x5160c3)=>{const _0x319957=_0x1185eb;let _0x289696=_0x1f193b[_0x319957(0x1db)]('<text'+_0x5160c3+'')[_0x319957(0x1b0)]()[_0x319957(0x1db)](_0x319957(0x1b9)+_0x5160c3+'>')[0x0][_0x319957(0x1dd)](),_0x420c18,_0x593926,_0x226682,_0x655716,_0x1b8622;if(_0x289696[_0x319957(0x1d6)]('font-family'))_0x655716=_0x289696[_0x319957(0x1db)](_0x319957(0x1d8))[_0x319957(0x1b0)]()[_0x319957(0x1db)]('\x22')[0x0];if(_0x289696['includes'](_0x319957(0x1a7)))_0x1b8622=_0x289696[_0x319957(0x1db)]('font-size=\x22')[_0x319957(0x1b0)]()['split']('\x22')[0x0];else _0x1b8622=defaultFontSize;if(!_0x289696[_0x319957(0x1d6)](_0x319957(0x1b5)))_0x420c18=_0x289696[_0x319957(0x1db)]('>')[0x1][_0x319957(0x1dd)](),_0x593926=_0x289696[_0x319957(0x1db)]('x=\x22')['pop']()[_0x319957(0x1db)]('\x22')[0x0],_0x226682=_0x289696[_0x319957(0x1db)](_0x319957(0x1b8))[_0x319957(0x1b0)]()[_0x319957(0x1db)]('\x22')[0x0];else{_0x420c18=_0x289696[_0x319957(0x1db)](_0x319957(0x1a1))[_0x319957(0x1b0)]()['split'](_0x319957(0x1aa))[0x0],_0x420c18=_0x420c18[_0x319957(0x1db)]('>')[0x1],_0x593926=_0x289696[_0x319957(0x1db)]('x=\x22')['pop']()['split']('\x22')[0x0],_0x226682=_0x289696[_0x319957(0x1db)](_0x319957(0x1b8))[_0x319957(0x1b0)]()[_0x319957(0x1db)]('\x22')[0x0];let _0x3b0286=_0x289696['split'](_0x319957(0x1b5))[_0x319957(0x1b0)]()[_0x319957(0x1db)]('>')[0x0];_0x289696=_0x289696[_0x319957(0x1bc)](_0x319957(0x1b5)+_0x3b0286+'>',''),_0x289696=_0x289696[_0x319957(0x1bc)](_0x319957(0x1aa),''),_0x1f193b=_0x1f193b['replace'](_0x319957(0x1b5)+_0x3b0286+'>',''),_0x1f193b=_0x1f193b['replace'](_0x319957(0x1aa),'');}try{_0x420c18=_0x420c18[_0x319957(0x1dd)](),_0x420c18=_0x420c18[_0x319957(0x1bc)](/amp;/g,'')[_0x319957(0x1bc)](/&lt;/g,'<')[_0x319957(0x1bc)](/&gt;/g,'>')[_0x319957(0x1bc)](/&quot;/g,'\x22')[_0x319957(0x1bc)](/&#39;/g,'\x27')[_0x319957(0x1bc)](/&amp;/g,'&')[_0x319957(0x1bc)](/&apos;/g,'\x27');}catch(_0xeb1379){}let _0x530c8d=/font-family="(.+?)"|font-size="(.+?)"|font-weight="(.+?)"/g;_0x289696[_0x319957(0x1b6)](_0x530c8d)?_0x289696=_0x289696['replace'](_0x530c8d,''):null;var _0x5de210;_0x5de210=_0x655716?await fetchFont(_0x655716):null;!_0x5de210&&(_0x655716=defaultFont,_0x5de210=defaultFontPath);const _0x1c1833={'line':_0x420c18,'x':_0x593926,'y':_0x226682,'font':_0x5de210,'size':_0x1b8622},_0x288107=await toPath(_0x1c1833);_0x289696=_0x289696[_0x319957(0x1dd)]()['replace'](_0x420c18,''),_0x289696=_0x319957(0x1ad)+_0x288107+'\x22\x20'+_0x289696;const _0x4f91a9=_0x1f193b[_0x319957(0x1db)](_0x319957(0x1cc)+_0x5160c3+'')[_0x319957(0x1b0)]()[_0x319957(0x1db)](_0x319957(0x1b9)+_0x5160c3+'>')[0x0][_0x319957(0x1dd)]();_0x1f193b=_0x1f193b[_0x319957(0x1bc)](_0x319957(0x1cc)+_0x5160c3+'\x20'+_0x4f91a9,_0x319957(0x1c5)+_0x289696)['replace'](_0x319957(0x1b9)+_0x5160c3+'>',_0x319957(0x1a9));return;});await Promise[_0x1185eb(0x1be)](_0x568744);if(_0x19e3f0[_0x1185eb(0x1c0)][_0x1185eb(0x1d3)]()==_0x1185eb(0x1d7))return Buffer['from'](_0x1f193b,'utf8');else{if(_0x19e3f0['save'][_0x1185eb(0x1d3)]()==_0x1185eb(0x1ae))return new Buffer[(_0x1185eb(0x1a6))](_0x1f193b)[_0x1185eb(0x1c8)](_0x1185eb(0x1ae));else{if(_0x19e3f0[_0x1185eb(0x1c0)]['toLowerCase']()==_0x1185eb(0x1bf)||_0x19e3f0[_0x1185eb(0x1c0)][_0x1185eb(0x1d3)]()==_0x1185eb(0x1a4))return _0x1f193b;else{fs[_0x1185eb(0x1af)](_0x19e3f0['save'],_0x1f193b);return;}}}};function _0xdf78(_0x31230d,_0x3ccb7b){const _0x1e4025=_0x1e40();return _0xdf78=function(_0xdf7869,_0x53dc1f){_0xdf7869=_0xdf7869-0x1a1;let _0x4cb392=_0x1e4025[_0xdf7869];return _0x4cb392;},_0xdf78(_0x31230d,_0x3ccb7b);}async function toPath(_0x3d5682){const _0x229b8b=_0x2137e4,_0x262053={'kerning':!![]},_0x26c891=opentype[_0x229b8b(0x1c7)](_0x3d5682[_0x229b8b(0x1b1)]),_0x18b75f=_0x26c891[_0x229b8b(0x1b4)](_0x3d5682[_0x229b8b(0x1da)],Number(_0x3d5682['x']),Number(_0x3d5682['y']),Number(_0x3d5682[_0x229b8b(0x1d4)]),_0x262053),_0x42beed=_0x18b75f[_0x229b8b(0x1c3)](0x2);return _0x42beed;}async function fetchFont(_0x5df401){const _0x18dc7e=_0x2137e4,_0x1e47d3=require[_0x18dc7e(0x1cd)]('svg-text-to-vector/config/fonts.json'),_0x22fd0c=JSON[_0x18dc7e(0x1b3)](fs[_0x18dc7e(0x1c9)](_0x1e47d3));let _0x4cb5c0=![];var _0x5105bf;return Object[_0x18dc7e(0x1ac)](_0x22fd0c['font'])[_0x18dc7e(0x1c2)](_0x5127c7=>{const _0xd20c2e=_0x18dc7e;!_0x4cb5c0&&(_0x22fd0c['font'][_0x5127c7][_0xd20c2e(0x1ab)]==_0x5df401['trim']()&&(_0x5105bf=_0x22fd0c[_0xd20c2e(0x1b1)][_0x5127c7][_0xd20c2e(0x1ba)],_0x4cb5c0=!![]));}),_0x5105bf;}