UNPKG

invisible-watermark

Version:
46 lines (45 loc) 1.55 kB
import jsonp from './jsonp'; var measureTextCtx = null; export function measureText(text, fontSize) { if (fontSize === void 0) { fontSize = 13; } if (!measureTextCtx) { var canvas = document.createElement('canvas'); canvas.style.display = 'none'; measureTextCtx = canvas.getContext('2d'); } if (typeof text !== 'string') return 0; measureTextCtx.font = fontSize + "px Microsoft YaHei"; return measureTextCtx.measureText(text).width; } /** * 获取text或者sso返回的水印数据 * @param param0 * @returns string[] */ export function resolveText(_a) { var sso = _a.sso, text = _a.text; return new Promise(function (resolve, reject) { if (text) return resolve(text.split(/<br\/>/i)); jsonp(sso, { prefix: '__sso_jp' }, function (err, res) { if (err) { console.error(err); return resolve([]); } var data = res.data; var _a = data.displayName, displayName = _a === void 0 ? '' : _a, _b = data.jobnumber, jobnumber = _b === void 0 ? '' : _b, _c = data.iid, iid = _c === void 0 ? '' : _c, _d = data.phone, phone = _d === void 0 ? '' : _d; var id = ''; if (jobnumber) { id = jobnumber.substr(-5); } else if (iid) { id = iid; } else if (phone) { id = phone.substr(-4); } return resolve([displayName + ' ' + id]); }); }); }