Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

canvas-hypertxt

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

canvas-hypertxt - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

4

dist/cjs/index.js

@@ -1,3 +0,3 @@

"use strict";var z=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var P=(o,n)=>{for(var e in n)z(o,e,{get:n[e],enumerable:!0})},W=(o,n,e,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of D(n))!L.call(o,s)&&s!==e&&z(o,s,{get:()=>n[s],enumerable:!(u=T(n,s))||u.enumerable});return o};var j=o=>W(z({},"__esModule",{value:!0}),o);var y={};P(y,{clearCache:()=>w,split:()=>R});module.exports=j(y);var d=new Map,h=new Map,k=new Map;function w(){d.clear(),k.clear(),h.clear()}function I(o,n,e,u,s){var t,r,c;let g=0,a={};for(let i of o)g+=(t=e.get(i))!=null?t:s,a[i]=((r=a[i])!=null?r:0)+1;let f=n-g;for(let i of Object.keys(a)){let b=a[i],l=(c=e.get(i))!=null?c:s,m=l*b/g,M=f*m*u/b,C=l+M;e.set(i,C)}}function V(o,n){var t;let e=new Map,u=0;for(let r of"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.-+=?"){let c=o.measureText(r).width;e.set(r,c),u+=c}let s=u/e.size,g=3,a=(n/s+g)/(g+1),f=e.keys();for(let r of f)e.set(r,((t=e.get(r))!=null?t:s)*a);return e}function p(o,n,e,u){var f,t;let s=h.get(e);if(u&&s!==void 0&&s.count>2e4){let r=k.get(e);if(r===void 0&&(r=V(o,s.size),k.set(e,r)),s.count>5e5){let i=0;for(let b of n)i+=(f=r.get(b))!=null?f:s.size;return i*1.01}let c=o.measureText(n);return I(n,c.width,r,Math.max(.05,1-s.count/2e5),s.size),h.set(e,{count:s.count+n.length,size:s.size}),c.width}let g=o.measureText(n),a=g.width/n.length;if(((t=s==null?void 0:s.count)!=null?t:0)>2e4)return g.width;if(s===void 0)h.set(e,{count:n.length,size:a});else{let r=a-s.size,c=n.length/(s.count+n.length),i=s.size+r*c;h.set(e,{count:s.count+n.length,size:i})}return g.width}function $(o,n,e,u,s,g,a,f){if(n.length<=1)return n.length;if(s<e)return-1;let t=Math.floor(e/s*g),r=p(o,n.substring(0,t),u,a),c=f==null?void 0:f(n);if(r!==e)if(r<e){for(;r<e;)t++,r=p(o,n.substring(0,t),u,a);t--}else for(;r>e;){let i=c!==void 0?0:n.lastIndexOf(" ",t-1);i>0?t=i:t--,r=p(o,n.substring(0,t),u,a)}if(n[t]!==" "){let i=0;if(c===void 0)i=n.lastIndexOf(" ",t);else{console.log(n,c);for(let b of c){if(b>t)break;i=b}}i>0&&(t=i)}return t}function R(o,n,e,u,s,g){let a=`${n}_${e}_${u}px`,f=d.get(a);if(f!==void 0)return f;if(u<=0)return[];let t=[],r=n.split(`
`),c=h.get(e),i=c===void 0?n.length:u/c.size*1.5,b=s&&c!==void 0&&c.count>2e4;for(let l of r){let m=p(o,l.substring(0,i),e,b),M=Math.min(l.length,i);if(m<=u)t.push(l);else{for(;m>u;){let C=$(o,l,u,e,m,M,b,g),v=l.substring(0,C);l=l.substring(v.length),t.push(v),m=p(o,l.substring(0,i),e,b),M=Math.min(l.length,i)}m>0&&t.push(l)}}return t=t.map((l,m)=>m===0?l.trimEnd():l.trim()),d.set(a,t),d.size>500&&d.delete(d.keys().next().value),t}
"use strict";var z=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var x=(o,e)=>{for(var n in e)z(o,n,{get:e[n],enumerable:!0})},L=(o,e,n,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of _(e))!D.call(o,s)&&s!==n&&z(o,s,{get:()=>e[s],enumerable:!(c=T(e,s))||c.enumerable});return o};var P=o=>L(z({},"__esModule",{value:!0}),o);var V={};x(V,{clearCache:()=>w,split:()=>R});module.exports=P(V);var d=new Map,b=new Map,k=new Map;function w(){d.clear(),k.clear(),b.clear()}function W(o,e,n,c,s){var t,r,a;let f=0,u={};for(let i of o)f+=(t=n.get(i))!=null?t:s,u[i]=((r=u[i])!=null?r:0)+1;let g=e-f;for(let i of Object.keys(u)){let m=u[i],l=(a=n.get(i))!=null?a:s,h=l*m/f,M=g*h*c/m,C=l+M;n.set(i,C)}}function j(o,e){var t;let n=new Map,c=0;for(let r of"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.-+=?"){let a=o.measureText(r).width;n.set(r,a),c+=a}let s=c/n.size,f=3,u=(e/s+f)/(f+1),g=n.keys();for(let r of g)n.set(r,((t=n.get(r))!=null?t:s)*u);return n}function p(o,e,n,c){var g,t;let s=b.get(n);if(c&&s!==void 0&&s.count>2e4){let r=k.get(n);if(r===void 0&&(r=j(o,s.size),k.set(n,r)),s.count>5e5){let i=0;for(let m of e)i+=(g=r.get(m))!=null?g:s.size;return i*1.01}let a=o.measureText(e);return W(e,a.width,r,Math.max(.05,1-s.count/2e5),s.size),b.set(n,{count:s.count+e.length,size:s.size}),a.width}let f=o.measureText(e),u=f.width/e.length;if(((t=s==null?void 0:s.count)!=null?t:0)>2e4)return f.width;if(s===void 0)b.set(n,{count:e.length,size:u});else{let r=u-s.size,a=e.length/(s.count+e.length),i=s.size+r*a;b.set(n,{count:s.count+e.length,size:i})}return f.width}function I(o,e,n,c,s,f,u,g){if(e.length<=1)return e.length;if(s<n)return-1;let t=Math.floor(n/s*f),r=p(o,e.slice(0,Math.max(0,t)),c,u),a=g==null?void 0:g(e);if(r!==n)if(r<n){for(;r<n;)t++,r=p(o,e.slice(0,Math.max(0,t)),c,u);t--}else for(;r>n;){let i=a!==void 0?0:e.lastIndexOf(" ",t-1);i>0?t=i:t--,r=p(o,e.slice(0,Math.max(0,t)),c,u)}if(e[t]!==" "){let i=0;if(a===void 0)i=e.lastIndexOf(" ",t);else for(let m of a){if(m>t)break;i=m}i>0&&(t=i)}return t}function R(o,e,n,c,s,f){let u=`${e}_${n}_${c}px`,g=d.get(u);if(g!==void 0)return g;if(c<=0)return[];let t=[],r=e.split(`
`),a=b.get(n),i=a===void 0?e.length:c/a.size*1.5,m=s&&a!==void 0&&a.count>2e4;for(let l of r){let h=p(o,l.slice(0,Math.max(0,i)),n,m),M=Math.min(l.length,i);if(h<=c)t.push(l);else{for(;h>c;){let C=I(o,l,c,n,h,M,m,f),v=l.slice(0,Math.max(0,C));l=l.slice(v.length),t.push(v),h=p(o,l.slice(0,Math.max(0,i)),n,m),M=Math.min(l.length,i)}h>0&&t.push(l)}}return t=t.map((l,h)=>h===0?l.trimEnd():l.trim()),d.set(u,t),d.size>500&&d.delete(d.keys().next().value),t}
//# sourceMappingURL=index.js.map

@@ -1,3 +0,3 @@

"use strict";var d=new Map,h=new Map,z=new Map;function v(){d.clear(),z.clear(),h.clear()}function w(l,s,n,u,t){var e,r,o;let g=0,c={};for(let i of l)g+=(e=n.get(i))!=null?e:t,c[i]=((r=c[i])!=null?r:0)+1;let f=s-g;for(let i of Object.keys(c)){let b=c[i],a=(o=n.get(i))!=null?o:t,m=a*b/g,M=f*m*u/b,C=a+M;n.set(i,C)}}function R(l,s){var e;let n=new Map,u=0;for(let r of"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.-+=?"){let o=l.measureText(r).width;n.set(r,o),u+=o}let t=u/n.size,g=3,c=(s/t+g)/(g+1),f=n.keys();for(let r of f)n.set(r,((e=n.get(r))!=null?e:t)*c);return n}function p(l,s,n,u){var f,e;let t=h.get(n);if(u&&t!==void 0&&t.count>2e4){let r=z.get(n);if(r===void 0&&(r=R(l,t.size),z.set(n,r)),t.count>5e5){let i=0;for(let b of s)i+=(f=r.get(b))!=null?f:t.size;return i*1.01}let o=l.measureText(s);return w(s,o.width,r,Math.max(.05,1-t.count/2e5),t.size),h.set(n,{count:t.count+s.length,size:t.size}),o.width}let g=l.measureText(s),c=g.width/s.length;if(((e=t==null?void 0:t.count)!=null?e:0)>2e4)return g.width;if(t===void 0)h.set(n,{count:s.length,size:c});else{let r=c-t.size,o=s.length/(t.count+s.length),i=t.size+r*o;h.set(n,{count:t.count+s.length,size:i})}return g.width}function T(l,s,n,u,t,g,c,f){if(s.length<=1)return s.length;if(t<n)return-1;let e=Math.floor(n/t*g),r=p(l,s.substring(0,e),u,c),o=f==null?void 0:f(s);if(r!==n)if(r<n){for(;r<n;)e++,r=p(l,s.substring(0,e),u,c);e--}else for(;r>n;){let i=o!==void 0?0:s.lastIndexOf(" ",e-1);i>0?e=i:e--,r=p(l,s.substring(0,e),u,c)}if(s[e]!==" "){let i=0;if(o===void 0)i=s.lastIndexOf(" ",e);else{console.log(s,o);for(let b of o){if(b>e)break;i=b}}i>0&&(e=i)}return e}function D(l,s,n,u,t,g){let c=`${s}_${n}_${u}px`,f=d.get(c);if(f!==void 0)return f;if(u<=0)return[];let e=[],r=s.split(`
`),o=h.get(n),i=o===void 0?s.length:u/o.size*1.5,b=t&&o!==void 0&&o.count>2e4;for(let a of r){let m=p(l,a.substring(0,i),n,b),M=Math.min(a.length,i);if(m<=u)e.push(a);else{for(;m>u;){let C=T(l,a,u,n,m,M,b,g),k=a.substring(0,C);a=a.substring(k.length),e.push(k),m=p(l,a.substring(0,i),n,b),M=Math.min(a.length,i)}m>0&&e.push(a)}}return e=e.map((a,m)=>m===0?a.trimEnd():a.trim()),d.set(c,e),d.size>500&&d.delete(d.keys().next().value),e}export{v as clearCache,D as split};
"use strict";var d=new Map,b=new Map,z=new Map;function v(){d.clear(),z.clear(),b.clear()}function w(l,s,e,c,t){var n,r,o;let f=0,a={};for(let i of l)f+=(n=e.get(i))!=null?n:t,a[i]=((r=a[i])!=null?r:0)+1;let g=s-f;for(let i of Object.keys(a)){let m=a[i],u=(o=e.get(i))!=null?o:t,h=u*m/f,M=g*h*c/m,C=u+M;e.set(i,C)}}function R(l,s){var n;let e=new Map,c=0;for(let r of"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,.-+=?"){let o=l.measureText(r).width;e.set(r,o),c+=o}let t=c/e.size,f=3,a=(s/t+f)/(f+1),g=e.keys();for(let r of g)e.set(r,((n=e.get(r))!=null?n:t)*a);return e}function p(l,s,e,c){var g,n;let t=b.get(e);if(c&&t!==void 0&&t.count>2e4){let r=z.get(e);if(r===void 0&&(r=R(l,t.size),z.set(e,r)),t.count>5e5){let i=0;for(let m of s)i+=(g=r.get(m))!=null?g:t.size;return i*1.01}let o=l.measureText(s);return w(s,o.width,r,Math.max(.05,1-t.count/2e5),t.size),b.set(e,{count:t.count+s.length,size:t.size}),o.width}let f=l.measureText(s),a=f.width/s.length;if(((n=t==null?void 0:t.count)!=null?n:0)>2e4)return f.width;if(t===void 0)b.set(e,{count:s.length,size:a});else{let r=a-t.size,o=s.length/(t.count+s.length),i=t.size+r*o;b.set(e,{count:t.count+s.length,size:i})}return f.width}function T(l,s,e,c,t,f,a,g){if(s.length<=1)return s.length;if(t<e)return-1;let n=Math.floor(e/t*f),r=p(l,s.slice(0,Math.max(0,n)),c,a),o=g==null?void 0:g(s);if(r!==e)if(r<e){for(;r<e;)n++,r=p(l,s.slice(0,Math.max(0,n)),c,a);n--}else for(;r>e;){let i=o!==void 0?0:s.lastIndexOf(" ",n-1);i>0?n=i:n--,r=p(l,s.slice(0,Math.max(0,n)),c,a)}if(s[n]!==" "){let i=0;if(o===void 0)i=s.lastIndexOf(" ",n);else for(let m of o){if(m>n)break;i=m}i>0&&(n=i)}return n}function _(l,s,e,c,t,f){let a=`${s}_${e}_${c}px`,g=d.get(a);if(g!==void 0)return g;if(c<=0)return[];let n=[],r=s.split(`
`),o=b.get(e),i=o===void 0?s.length:c/o.size*1.5,m=t&&o!==void 0&&o.count>2e4;for(let u of r){let h=p(l,u.slice(0,Math.max(0,i)),e,m),M=Math.min(u.length,i);if(h<=c)n.push(u);else{for(;h>c;){let C=T(l,u,c,e,h,M,m,f),k=u.slice(0,Math.max(0,C));u=u.slice(k.length),n.push(k),h=p(l,u.slice(0,Math.max(0,i)),e,m),M=Math.min(u.length,i)}h>0&&n.push(u)}}return n=n.map((u,h)=>h===0?u.trimEnd():u.trim()),d.set(a,n),d.size>500&&d.delete(d.keys().next().value),n}export{v as clearCache,_ as split};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,1 @@

import { splitMultilineText, clearMultilineCache } from "./multi-line";
export { splitMultilineText as split, clearMultilineCache as clearCache };
export { splitMultilineText as split, clearMultilineCache as clearCache } from "./multi-line";
{
"name": "canvas-hypertxt",
"version": "0.0.3",
"version": "0.0.4",
"description": "The fastest way to layout wrapped text on a HTML5 canvas",

@@ -21,2 +21,3 @@ "sideEffects": false,

"test": "jest",
"lint": "eslint src --ext .ts,.tsx",
"storybook": "start-storybook -p 6006",

@@ -63,2 +64,5 @@ "build-storybook": "build-storybook -o storybook-build/"

"@types/jest": "^28.1.3",
"@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.5",
"@typescript-eslint/typescript-estree": "^5.30.5",
"babel-loader": "^8.2.5",

@@ -68,2 +72,8 @@ "canvas-multiline-text": "^1.0.3",

"esbuild": "^0.14.47",
"eslint": "^8.19.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-sonarjs": "^0.13.0",
"eslint-plugin-unicorn": "^43.0.1",
"jest": "^28.1.1",

@@ -70,0 +80,0 @@ "jest-canvas-mock": "^2.4.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc