UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

3 lines (2 loc) 1.31 kB
import{reNewline as t}from"../../constants.min.mjs";import{cloneStyles as e}from"../internals/cloneStyles.min.mjs";import{graphemeSplit as n}from"../lang_string.min.mjs";const o=function(t,e){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];return t.fill!==e.fill||t.stroke!==e.stroke||t.strokeWidth!==e.strokeWidth||t.fontSize!==e.fontSize||t.fontFamily!==e.fontFamily||t.fontWeight!==e.fontWeight||t.fontStyle!==e.fontStyle||t.textDecorationThickness!==e.textDecorationThickness||t.textBackgroundColor!==e.textBackgroundColor||t.deltaY!==e.deltaY||n&&(t.overline!==e.overline||t.underline!==e.underline||t.linethrough!==e.linethrough)},r=(t,r)=>{const l=r.split("\n"),i=[];let s=-1,f={};t=e(t);for(let e=0;e<l.length;e++){const r=n(l[e]);if(t[e])for(let n=0;n<r.length;n++){s++;const r=t[e][n];r&&Object.keys(r).length>0&&(o(f,r,!0)?i.push({start:s,end:s+1,style:r}):i[i.length-1].end++),f=r||{}}else s+=r.length,f={}}return i},l=(o,r)=>{if(!Array.isArray(o))return e(o);const l=r.split(t),i={};let s=-1,f=0;for(let t=0;t<l.length;t++){const e=n(l[t]);for(let n=0;n<e.length;n++)s++,o[f]&&o[f].start<=s&&s<o[f].end&&(i[t]=i[t]||{},i[t][n]={...o[f].style},s===o[f].end-1&&f++)}return i};export{o as hasStyleChanged,l as stylesFromArray,r as stylesToArray}; //# sourceMappingURL=textStyles.min.mjs.map