modern-text 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/dist/web-components/index.cjs +271 -230
- package/dist/web-components/index.d.cts +38 -32
- package/dist/web-components/index.d.mts +38 -32
- package/dist/web-components/index.d.ts +38 -32
- package/dist/web-components/index.mjs +271 -230
- package/package.json +8 -8
- package/dist/shared/{modern-text.y0a7DPYV.mjs → modern-text.B2pcGP3X.mjs} +1 -1
- package/dist/shared/{modern-text.XBrC1nBJ.cjs → modern-text.BmTeQ51D.cjs} +1 -1
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -32,4 +32,4 @@ ${o}
|
|
|
32
32
|
</svg>`}toSvgUrl(){return`data:image/svg+xml;base64,${btoa(this.toSvgString())}`}toSvg(){return new DOMParser().parseFromString(this.toSvgString(),"image/svg+xml").documentElement}toCanvas(t={}){const{pixelRatio:e=2,...n}=t,{left:i,top:o,width:s,height:a}=this.getBoundingBox(),l=document.createElement("canvas");l.width=s*e,l.height=a*e,l.style.width=`${s}px`,l.style.height=`${a}px`;const c=l.getContext("2d");return c&&(c.scale(e,e),c.translate(-i,-o),this.paths.forEach(h=>{h.drawTo(c,n)})),l}}const Za=new Set(["©","®","÷"]),Ya=new Set(["—","…","“","”","﹏","﹋","﹌","‘","’","˜"]),Ka={1:"italic",32:"bold"},Qa={1:"italic",2:"bold"},wi={100:-.2,200:-.1,300:0,400:0,normal:0,500:.1,600:.2,700:.3,bold:.3,800:.4,900:.5};class bi{constructor(t,e,n){this.content=t,this.index=e,this.parent=n}path=new _t().setMeta(this);lineBox=new X;inlineBox=new X;glyphBox;advanceWidth=0;advanceHeight=0;underlinePosition=0;underlineThickness=0;strikeoutPosition=0;strikeoutSize=0;ascender=0;descender=0;typoAscender=0;typoDescender=0;typoLineGap=0;winAscent=0;winDescent=0;xHeight=0;capHeight=0;baseline=0;centerDiviation=0;fontStyle;get compatibleGlyphBox(){const t=this.computedStyle.fontSize*.8;return this.glyphBox??(this.isVertical?new X(this.lineBox.left+this.lineBox.width/2-t/2,this.lineBox.top,t,this.lineBox.height):new X(this.lineBox.left,this.lineBox.top+this.lineBox.height/2-t/2,this.lineBox.width,t))}get center(){return this.compatibleGlyphBox.center}get computedFill(){return this.parent.computedFill}get computedOutline(){return this.parent.computedOutline}get computedStyle(){return this.parent.computedStyle}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get fontSize(){return this.computedStyle.fontSize}get fontHeight(){return this.fontSize*this.computedStyle.lineHeight}_getFontSFNT(t){const e=this.computedStyle.fontFamily,n=t??Io;let o=(e?n.get(e):n.fallbackFont)?.getSFNT();return o?.textToGlyphIndexes(this.content).includes(0)&&(o=n.fallbackFont?.getSFNT()),o}updateGlyph(t=this._getFontSFNT()){if(!t)return this;const{hhea:e,os2:n,post:i,head:o}=t,s=o.unitsPerEm,a=e.ascent,l=e.descent,{content:c,computedStyle:h,isVertical:u}=this,{fontSize:p}=h,g=s/p,f=t.getAdvanceWidth(c,p),y=(a+Math.abs(l))/g,d=a/g;return this.advanceWidth=f,this.advanceHeight=y,this.inlineBox.width=u?y:f,this.inlineBox.height=u?f:y,this.underlinePosition=(a-i.underlinePosition)/g,this.underlineThickness=i.underlineThickness/g,this.strikeoutPosition=(a-n.yStrikeoutPosition)/g,this.strikeoutSize=n.yStrikeoutSize/g,this.ascender=a/g,this.descender=l/g,this.typoAscender=n.sTypoAscender/g,this.typoDescender=n.sTypoDescender/g,this.typoLineGap=n.sTypoLineGap/g,this.winAscent=n.usWinAscent/g,this.winDescent=n.usWinDescent/g,this.xHeight=n.sxHeight/g,this.capHeight=n.sCapHeight/g,this.baseline=d,this.centerDiviation=y/2-d,this.fontStyle=Ka[n.fsSelection]??Qa[o.macStyle],this}update(t){const e=this._getFontSFNT(t);if(!e)return this;this.updateGlyph(e);const{isVertical:n,content:i,computedStyle:o,baseline:s,inlineBox:a,ascender:l,descender:c,typoAscender:h,fontStyle:u,advanceWidth:p,advanceHeight:g}=this,{left:f,top:y}=a,d=o.fontStyle==="italic"&&u!=="italic";let P=f,M=y+s,w;const C=new _t().setMeta(this);if(n&&(P+=(g-p)/2,Math.abs(p-g)>.1&&(M-=(l-h)/(l+Math.abs(c))*g),w=void 0),n&&!Za.has(i)&&(i.codePointAt(0)<=256||Ya.has(i))){C.addCommands(e.getPathCommands(i,P,y+s-(g-p)/2,o.fontSize));const x={y:y-(g-p)/2+g/2,x:P+p/2};d&&this._italic(C,n?{x:x.x,y:y-(g-p)/2+s}:void 0),C.rotate(90,x)}else w!==void 0?(C.addCommands(e.glyphs.get(w).getPathCommands(P,M,o.fontSize)),d&&this._italic(C,n?{x:P+p/2,y:y+h/(l+Math.abs(c))*g}:void 0)):(C.addCommands(e.getPathCommands(i,P,M,o.fontSize)),d&&this._italic(C,n?{x:P+g/2,y:M}:void 0));const v=o.fontWeight??400;return v in wi&&(v===700||v==="bold")&&u!=="bold"&&C.bold(wi[v]*o.fontSize*.05),C.style={fill:this.computedFill??o.color,fillRule:"nonzero",stroke:this.computedOutline??(o.textStrokeWidth?o.textStrokeColor:"none"),strokeWidth:o.textStrokeWidth?o.textStrokeWidth*o.fontSize*.03:0},this.path=C,this.glyphBox=this.getGlyphBoundingBox(),this}_italic(t,e){t.skew(-.24,0,e||{y:this.inlineBox.top+this.baseline,x:this.inlineBox.left+this.inlineBox.width/2})}getGlyphMinMax(t,e,n){if(this.path.curves[0]?.curves.length)return this.path.getMinMax(t,e,n)}getGlyphBoundingBox(t){const e=this.getGlyphMinMax(void 0,void 0,t);if(!e)return;const{min:n,max:i}=e;return new X(n.x,n.y,i.x-n.x,i.y-n.y)}drawTo(t,e={}){const n=this.computedStyle,i={ctx:t,path:this.path,fontSize:n.fontSize,color:n.color,...e};if(this.glyphBox)he(i);else{t.save(),t.beginPath();const o=this.path.style,s={...o,fill:i.color??o.fill,stroke:i.textStrokeColor??o.stroke,strokeWidth:i.textStrokeWidth?i.textStrokeWidth*i.fontSize:o.strokeWidth,shadowOffsetX:(i.shadowOffsetX??0)*i.fontSize,shadowOffsetY:(i.shadowOffsetY??0)*i.fontSize,shadowBlur:(i.shadowBlur??0)*i.fontSize,shadowColor:i.shadowColor};Yr(t,s),t.font=`${i.fontSize}px ${i.fontFamily}`,this.isVertical?(t.textBaseline="middle",t.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.inlineBox.height/2)):(t.textBaseline="alphabetic",t.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.baseline)),t.restore()}}}function sn(){const r=new Map;async function t(n){if(!r.has(n)){r.set(n,n);try{r.set(n,await fetch(n).then(i=>i.text()))}catch(i){console.warn(i),r.delete(n)}}}function e(n){return n.startsWith("http://")||n.startsWith("https://")||n.startsWith("blob://")}return{loaded:r,needsLoad:e,load:t}}function on(r){const t=new Map;function e(n){let i=t.get(n);if(!i){const o=ri(r.needsLoad(n)?r.loaded.get(n)??n:n),s=ai(o);i={dom:o,pathSet:s},t.set(n,i)}return i}return{parsed:t,parse:e}}var Ja={grad:.9,turn:360,rad:360/(2*Math.PI)},Jt=function(r){return typeof r=="string"?r.length>0:typeof r=="number"},at=function(r,t,e){return t===void 0&&(t=0),e===void 0&&(e=Math.pow(10,t)),Math.round(e*r)/e+0},Et=function(r,t,e){return t===void 0&&(t=0),e===void 0&&(e=1),r>e?e:r>t?r:t},Si=function(r){return(r=isFinite(r)?r%360:0)>0?r:r+360},Ci=function(r){return{r:Et(r.r,0,255),g:Et(r.g,0,255),b:Et(r.b,0,255),a:Et(r.a)}},an=function(r){return{r:at(r.r),g:at(r.g),b:at(r.b),a:at(r.a,3)}},tl=/^#([0-9a-f]{3,8})$/i,pr=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},Pi=function(r){var t=r.r,e=r.g,n=r.b,i=r.a,o=Math.max(t,e,n),s=o-Math.min(t,e,n),a=s?o===t?(e-n)/s:o===e?2+(n-t)/s:4+(t-e)/s:0;return{h:60*(a<0?a+6:a),s:o?s/o*100:0,v:o/255*100,a:i}},Mi=function(r){var t=r.h,e=r.s,n=r.v,i=r.a;t=t/360*6,e/=100,n/=100;var o=Math.floor(t),s=n*(1-e),a=n*(1-(t-o)*e),l=n*(1-(1-t+o)*e),c=o%6;return{r:255*[n,a,s,s,l,n][c],g:255*[l,n,n,a,s,s][c],b:255*[s,s,l,n,n,a][c],a:i}},_i=function(r){return{h:Si(r.h),s:Et(r.s,0,100),l:Et(r.l,0,100),a:Et(r.a)}},Ti=function(r){return{h:at(r.h),s:at(r.s),l:at(r.l),a:at(r.a,3)}},ki=function(r){return Mi((e=(t=r).s,{h:t.h,s:(e*=((n=t.l)<50?n:100-n)/100)>0?2*e/(n+e)*100:0,v:n+e,a:t.a}));var t,e,n},qe=function(r){return{h:(t=Pi(r)).h,s:(i=(200-(e=t.s))*(n=t.v)/100)>0&&i<200?e*n/100/(i<=100?i:200-i)*100:0,l:i/2,a:t.a};var t,e,n,i},el=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,rl=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,nl=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,il=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Ai={string:[[function(r){var t=tl.exec(r);return t?(r=t[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:r.length===4?at(parseInt(r[3]+r[3],16)/255,2):1}:r.length===6||r.length===8?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:r.length===8?at(parseInt(r.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(r){var t=nl.exec(r)||il.exec(r);return t?t[2]!==t[4]||t[4]!==t[6]?null:Ci({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(r){var t=el.exec(r)||rl.exec(r);if(!t)return null;var e,n,i=_i({h:(e=t[1],n=t[2],n===void 0&&(n="deg"),Number(e)*(Ja[n]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return ki(i)},"hsl"]],object:[[function(r){var t=r.r,e=r.g,n=r.b,i=r.a,o=i===void 0?1:i;return Jt(t)&&Jt(e)&&Jt(n)?Ci({r:Number(t),g:Number(e),b:Number(n),a:Number(o)}):null},"rgb"],[function(r){var t=r.h,e=r.s,n=r.l,i=r.a,o=i===void 0?1:i;if(!Jt(t)||!Jt(e)||!Jt(n))return null;var s=_i({h:Number(t),s:Number(e),l:Number(n),a:Number(o)});return ki(s)},"hsl"],[function(r){var t=r.h,e=r.s,n=r.v,i=r.a,o=i===void 0?1:i;if(!Jt(t)||!Jt(e)||!Jt(n))return null;var s=(function(a){return{h:Si(a.h),s:Et(a.s,0,100),v:Et(a.v,0,100),a:Et(a.a)}})({h:Number(t),s:Number(e),v:Number(n),a:Number(o)});return Mi(s)},"hsv"]]},Oi=function(r,t){for(var e=0;e<t.length;e++){var n=t[e][0](r);if(n)return[n,t[e][1]]}return[null,void 0]},sl=function(r){return typeof r=="string"?Oi(r.trim(),Ai.string):typeof r=="object"&&r!==null?Oi(r,Ai.object):[null,void 0]},ln=function(r,t){var e=qe(r);return{h:e.h,s:Et(e.s+100*t,0,100),l:e.l,a:e.a}},cn=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},Ii=function(r,t){var e=qe(r);return{h:e.h,s:e.s,l:Et(e.l+100*t,0,100),a:e.a}},Ei=(function(){function r(t){this.parsed=sl(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return r.prototype.isValid=function(){return this.parsed!==null},r.prototype.brightness=function(){return at(cn(this.rgba),2)},r.prototype.isDark=function(){return cn(this.rgba)<.5},r.prototype.isLight=function(){return cn(this.rgba)>=.5},r.prototype.toHex=function(){return t=an(this.rgba),e=t.r,n=t.g,i=t.b,s=(o=t.a)<1?pr(at(255*o)):"","#"+pr(e)+pr(n)+pr(i)+s;var t,e,n,i,o,s},r.prototype.toRgb=function(){return an(this.rgba)},r.prototype.toRgbString=function(){return t=an(this.rgba),e=t.r,n=t.g,i=t.b,(o=t.a)<1?"rgba("+e+", "+n+", "+i+", "+o+")":"rgb("+e+", "+n+", "+i+")";var t,e,n,i,o},r.prototype.toHsl=function(){return Ti(qe(this.rgba))},r.prototype.toHslString=function(){return t=Ti(qe(this.rgba)),e=t.h,n=t.s,i=t.l,(o=t.a)<1?"hsla("+e+", "+n+"%, "+i+"%, "+o+")":"hsl("+e+", "+n+"%, "+i+"%)";var t,e,n,i,o},r.prototype.toHsv=function(){return t=Pi(this.rgba),{h:at(t.h),s:at(t.s),v:at(t.v),a:at(t.a,3)};var t},r.prototype.invert=function(){return Xt({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},r.prototype.saturate=function(t){return t===void 0&&(t=.1),Xt(ln(this.rgba,t))},r.prototype.desaturate=function(t){return t===void 0&&(t=.1),Xt(ln(this.rgba,-t))},r.prototype.grayscale=function(){return Xt(ln(this.rgba,-1))},r.prototype.lighten=function(t){return t===void 0&&(t=.1),Xt(Ii(this.rgba,t))},r.prototype.darken=function(t){return t===void 0&&(t=.1),Xt(Ii(this.rgba,-t))},r.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},r.prototype.alpha=function(t){return typeof t=="number"?Xt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):at(this.rgba.a,3);var e},r.prototype.hue=function(t){var e=qe(this.rgba);return typeof t=="number"?Xt({h:t,s:e.s,l:e.l,a:e.a}):at(e.h)},r.prototype.isEqual=function(t){return this.toHex()===Xt(t).toHex()},r})(),Xt=function(r){return r instanceof Ei?r:new Ei(r)};function tt(r){return r==null||r==="none"}function Pe(r,t=0,e=10**t){return Math.round(e*r)/e+0}function zt(r,t=!1){if(typeof r!="object"||!r)return r;if(Array.isArray(r))return t?r.map(n=>zt(n,t)):r;const e={};for(const n in r){const i=r[n];i!=null&&(t?e[n]=zt(i,t):e[n]=i)}return e}function dr(r,t){const e={};return t.forEach(n=>{n in r&&(e[n]=r[n])}),e}function hn(r,t){if(r===t)return!0;if(r&&t&&typeof r=="object"&&typeof t=="object"){const e=Array.from(new Set([...Object.keys(r),...Object.keys(t)]));return!e.length||e.every(n=>r[n]===t[n])}return!1}function ol(r,t,e){const n=t.length-1;if(n<0)return r===void 0?e:r;for(let i=0;i<n;i++){if(r==null)return e;r=r[t[i]]}return r==null||r[t[n]]===void 0?e:r[t[n]]}function al(r,t,e){const n=t.length-1;for(let i=0;i<n;i++)typeof r[t[i]]!="object"&&(r[t[i]]={}),r=r[t[i]];r[t[n]]=e}function ll(r,t,e){return r==null||!t||typeof t!="string"?e:r[t]!==void 0?r[t]:(t=t.replace(/\[(\w+)\]/g,".$1"),t=t.replace(/^\./,""),ol(r,t.split("."),e))}function cl(r,t,e){if(!(typeof r!="object"||!t))return t=t.replace(/\[(\w+)\]/g,".$1"),t=t.replace(/^\./,""),al(r,t.split("."),e)}class hl{_observers=new Map;on(t,e){let n=this._observers.get(t);return n===void 0&&this._observers.set(t,n=new Set),n.add(e),this}once(t,e){const n=(...i)=>{this.off(t,n),e(...i)};return this.on(t,n),this}off(t,e){const n=this._observers.get(t);return n!==void 0&&(n.delete(e),n.size===0&&this._observers.delete(t)),this}emit(t,...e){return Array.from((this._observers.get(t)||new Map).values()).forEach(n=>n(...e)),this}destroy(){this._observers=new Map}}const un=Symbol("properties"),Bi=Symbol("inited");function fn(r){let t;if(Object.hasOwn(r,un))t=r[un];else{const e=Object.getPrototypeOf(r);t=new Map(e?fn(e):void 0),r[un]=t}return t}function Di(r,t,e,n){const{alias:i,internalKey:o}=n,s=r[t];i?cl(r,i,e):r[o]=e,r.onUpdateProperty?.(t,e,s)}function Fi(r,t,e){const{alias:n,internalKey:i}=e;let o;return n?o=ll(r,n):o=r[i],o=o??Ui(r,t,e),o}function Ui(r,t,e){const{default:n,fallback:i}=e;let o;if(n!==void 0&&!r[Bi]){r[Bi]=!0;const s=typeof n=="function"?n():n;s!==void 0&&(r[t]=s,o=s)}return o=o??(typeof i=="function"?i():i),o}function ul(r,t){function e(){return typeof this.getProperty<"u"?this.getProperty(r):Fi(this,r,t)}function n(i){typeof this.setProperty<"u"?this.setProperty(r,i):Di(this,r,i,t)}return{get:e,set:n}}function fl(r,t,e={}){const n={...e,internalKey:Symbol(t)};fn(r).set(t,n);const i=ul(t,n);Object.defineProperty(r.prototype,t,{get(){return i.get.call(this)},set(o){i.set.call(this,o)},configurable:!0,enumerable:!0})}function oe(r){return function(t,e){if(typeof e!="string")throw new TypeError("Failed to @property decorator, prop name cannot be a symbol");fl(t.constructor,e,r)}}class pl extends hl{_propertyAccessor;_properties=new Map;_updatedProperties=new Map;_changedProperties=new Set;_updatingPromise=Promise.resolve();_updating=!1;constructor(t){super(),this.setProperties(t)}isDirty(t){return t?this._updatedProperties.has(t):this._updatedProperties.size>0}getProperty(t){const e=this.getPropertyDeclaration(t);if(e){if(e.internal||e.alias)return Fi(this,t,e);{let n;return this._propertyAccessor?.getProperty?n=this._propertyAccessor.getProperty(t):n=this._properties.get(t),n??Ui(this,t,e)}}}setProperty(t,e){const n=this.getPropertyDeclaration(t);if(n)if(n.internal||n.alias)Di(this,t,e,n);else{const i=this.getProperty(t);this._propertyAccessor?.setProperty?.(t,e),this._properties.set(t,e),this.onUpdateProperty?.(t,e,i)}}getProperties(t){const e={};for(const[n,i]of this.getPropertyDeclarations())!i.internal&&!i.alias&&(!t||t.includes(n))&&(e[n]=this.getProperty(n));return e}setProperties(t){if(t&&typeof t=="object")for(const e in t)this.setProperty(e,t[e]);return this}resetProperties(){for(const[t,e]of this.getPropertyDeclarations())this.setProperty(t,typeof e.default=="function"?e.default():e.default);return this}getPropertyDeclarations(){return fn(this.constructor)}getPropertyDeclaration(t){return this.getPropertyDeclarations().get(t)}setPropertyAccessor(t){const e=this.getPropertyDeclarations();this._propertyAccessor=void 0;const n={};return e.forEach((i,o)=>{n[o]=this.getProperty(o)}),this._propertyAccessor=t,e.forEach((i,o)=>{const s=this.getProperty(o),a=n[o];s!==void 0&&!Object.is(s,a)&&(this.setProperty(o,s),!i.internal&&!i.alias&&this.requestUpdate(o,s,a))}),this}async _nextTick(){return"requestAnimationFrame"in globalThis?new Promise(t=>globalThis.requestAnimationFrame(t)):Promise.resolve()}async _enqueueUpdate(){this._updating=!0;try{await this._updatingPromise}catch(t){Promise.reject(t)}await this._nextTick(),this._updating&&(this.onUpdate(),this._updating=!1)}onUpdate(){this._update(this._updatedProperties),this._updatedProperties=new Map}onUpdateProperty(t,e,n){Object.is(e,n)||this.requestUpdate(t,e,n)}requestUpdate(t,e,n){t!==void 0&&(this._updatedProperties.set(t,n),this._changedProperties.add(t),this._updateProperty(t,e,n),this.emit("updateProperty",t,e,n)),this._updating||(this._updatingPromise=this._enqueueUpdate())}_update(t){}_updateProperty(t,e,n){}toJSON(){const t={};return this._properties.forEach((e,n)=>{e!==void 0&&(e&&typeof e=="object"?"toJSON"in e&&typeof e.toJSON=="function"?t[n]=e.toJSON():Array.isArray(e)?t[n]=[...e]:t[n]={...e}:t[n]=e)}),t}clone(){return new this.constructor(this.toJSON())}}function Li(r){let t;return typeof r=="number"?t={r:r>>24&255,g:r>>16&255,b:r>>8&255,a:(r&255)/255}:t=r,Xt(t)}function dl(r){return{r:Pe(r.r),g:Pe(r.g),b:Pe(r.b),a:Pe(r.a,3)}}function gr(r){const t=r.toString(16);return t.length<2?`0${t}`:t}const gl="#000000FF";function yl(r){return Li(r).isValid()}function Bt(r,t=!1){const e=Li(r);if(!e.isValid()){if(typeof r=="string")return r;const a=`Failed to normalizeColor ${r}`;if(t)throw new Error(a);return console.warn(a),gl}const{r:n,g:i,b:o,a:s}=dl(e.rgba);return`#${gr(n)}${gr(i)}${gr(o)}${gr(Pe(s*255))}`}var yr=yr||{};yr.parse=(function(){const r={linearGradient:/^(-(webkit|o|ms|moz)-)?(linear-gradient)/i,repeatingLinearGradient:/^(-(webkit|o|ms|moz)-)?(repeating-linear-gradient)/i,radialGradient:/^(-(webkit|o|ms|moz)-)?(radial-gradient)/i,repeatingRadialGradient:/^(-(webkit|o|ms|moz)-)?(repeating-radial-gradient)/i,sideOrCorner:/^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,extentKeywords:/^(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/,positionKeywords:/^(left|center|right|top|bottom)/i,pixelValue:/^(-?((\d*\.\d+)|(\d+\.?)))px/,percentageValue:/^(-?((\d*\.\d+)|(\d+\.?)))%/,emValue:/^(-?((\d*\.\d+)|(\d+\.?)))em/,angleValue:/^(-?((\d*\.\d+)|(\d+\.?)))deg/,radianValue:/^(-?((\d*\.\d+)|(\d+\.?)))rad/,startCall:/^\(/,endCall:/^\)/,comma:/^,/,hexColor:/^#([0-9a-f]+)/i,literalColor:/^([a-z]+)/i,rgbColor:/^rgb/i,rgbaColor:/^rgba/i,varColor:/^var/i,calcValue:/^calc/i,variableName:/^(--[a-z0-9-,\s#]+)/i,number:/^((\d*\.\d+)|(\d+\.?))/,hslColor:/^hsl/i,hslaColor:/^hsla/i};let t="";function e(T){const _=new Error(`${t}: ${T}`);throw _.source=t,_}function n(){const T=i();return t.length>0&&e("Invalid input not EOF"),T}function i(){return w(o)}function o(){return s("linear-gradient",r.linearGradient,l)||s("repeating-linear-gradient",r.repeatingLinearGradient,l)||s("radial-gradient",r.radialGradient,u)||s("repeating-radial-gradient",r.repeatingRadialGradient,u)}function s(T,_,U){return a(_,$=>{const q=U();return q&&(I(r.comma)||e("Missing comma before color stops")),{type:T,orientation:q,colorStops:w(C)}})}function a(T,_){const U=I(T);if(U){I(r.startCall)||e("Missing (");const $=_(U);return I(r.endCall)||e("Missing )"),$}}function l(){const T=c();if(T)return T;const _=j("position-keyword",r.positionKeywords,1);return _?{type:"directional",value:_.value}:h()}function c(){return j("directional",r.sideOrCorner,1)}function h(){return j("angular",r.angleValue,1)||j("angular",r.radianValue,1)}function u(){let T,_=p(),U;return _&&(T=[],T.push(_),U=t,I(r.comma)&&(_=p(),_?T.push(_):t=U)),T}function p(){let T=g()||f();if(T)T.at=d();else{const _=y();if(_){T=_;const U=d();U&&(T.at=U)}else{const U=d();if(U)T={type:"default-radial",at:U};else{const $=P();$&&(T={type:"default-radial",at:$})}}}return T}function g(){const T=j("shape",/^(circle)/i,0);return T&&(T.style=L()||y()),T}function f(){const T=j("shape",/^(ellipse)/i,0);return T&&(T.style=P()||A()||y()),T}function y(){return j("extent-keyword",r.extentKeywords,1)}function d(){if(j("position",/^at/,0)){const T=P();return T||e("Missing positioning value"),T}}function P(){const T=M();if(T.x||T.y)return{type:"position",value:T}}function M(){return{x:A(),y:A()}}function w(T){let _=T();const U=[];if(_)for(U.push(_);I(r.comma);)_=T(),_?U.push(_):e("One extra comma");return U}function C(){const T=v();return T||e("Expected color definition"),T.length=A(),T}function v(){return S()||F()||E()||D()||b()||N()||x()}function x(){return j("literal",r.literalColor,0)}function S(){return j("hex",r.hexColor,1)}function b(){return a(r.rgbColor,()=>({type:"rgb",value:w(B)}))}function D(){return a(r.rgbaColor,()=>({type:"rgba",value:w(B)}))}function N(){return a(r.varColor,()=>({type:"var",value:z()}))}function E(){return a(r.hslColor,()=>{I(r.percentageValue)&&e("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const _=B();I(r.comma);let U=I(r.percentageValue);const $=U?U[1]:null;I(r.comma),U=I(r.percentageValue);const q=U?U[1]:null;return(!$||!q)&&e("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[_,$,q]}})}function F(){return a(r.hslaColor,()=>{const T=B();I(r.comma);let _=I(r.percentageValue);const U=_?_[1]:null;I(r.comma),_=I(r.percentageValue);const $=_?_[1]:null;I(r.comma);const q=B();return(!U||!$)&&e("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[T,U,$,q]}})}function z(){return I(r.variableName)[1]}function B(){return I(r.number)[1]}function A(){return j("%",r.percentageValue,1)||W()||O()||L()}function W(){return j("position-keyword",r.positionKeywords,1)}function O(){return a(r.calcValue,()=>{let T=1,_=0;for(;T>0&&_<t.length;){const $=t.charAt(_);$==="("?T++:$===")"&&T--,_++}T>0&&e("Missing closing parenthesis in calc() expression");const U=t.substring(0,_-1);return V(_-1),{type:"calc",value:U}})}function L(){return j("px",r.pixelValue,1)||j("em",r.emValue,1)}function j(T,_,U){const $=I(_);if($)return{type:T,value:$[U]}}function I(T){let _,U;return U=/^\s+/.exec(t),U&&V(U[0].length),_=T.exec(t),_&&V(_[0].length),_}function V(T){t=t.substr(T)}return function(T){return t=T.toString().trim(),t.endsWith(";")&&(t=t.slice(0,-1)),n()}})();const ml=yr.parse.bind(yr);var mr=mr||{};mr.stringify=(function(){var r={"visit_linear-gradient":function(t){return r.visit_gradient(t)},"visit_repeating-linear-gradient":function(t){return r.visit_gradient(t)},"visit_radial-gradient":function(t){return r.visit_gradient(t)},"visit_repeating-radial-gradient":function(t){return r.visit_gradient(t)},visit_gradient:function(t){var e=r.visit(t.orientation);return e&&(e+=", "),t.type+"("+e+r.visit(t.colorStops)+")"},visit_shape:function(t){var e=t.value,n=r.visit(t.at),i=r.visit(t.style);return i&&(e+=" "+i),n&&(e+=" at "+n),e},"visit_default-radial":function(t){var e="",n=r.visit(t.at);return n&&(e+=n),e},"visit_extent-keyword":function(t){var e=t.value,n=r.visit(t.at);return n&&(e+=" at "+n),e},"visit_position-keyword":function(t){return t.value},visit_position:function(t){return r.visit(t.value.x)+" "+r.visit(t.value.y)},"visit_%":function(t){return t.value+"%"},visit_em:function(t){return t.value+"em"},visit_px:function(t){return t.value+"px"},visit_calc:function(t){return"calc("+t.value+")"},visit_literal:function(t){return r.visit_color(t.value,t)},visit_hex:function(t){return r.visit_color("#"+t.value,t)},visit_rgb:function(t){return r.visit_color("rgb("+t.value.join(", ")+")",t)},visit_rgba:function(t){return r.visit_color("rgba("+t.value.join(", ")+")",t)},visit_hsl:function(t){return r.visit_color("hsl("+t.value[0]+", "+t.value[1]+"%, "+t.value[2]+"%)",t)},visit_hsla:function(t){return r.visit_color("hsla("+t.value[0]+", "+t.value[1]+"%, "+t.value[2]+"%, "+t.value[3]+")",t)},visit_var:function(t){return r.visit_color("var("+t.value+")",t)},visit_color:function(t,e){var n=t,i=r.visit(e.length);return i&&(n+=" "+i),n},visit_angular:function(t){return t.value+"deg"},visit_directional:function(t){return"to "+t.value},visit_array:function(t){var e="",n=t.length;return t.forEach(function(i,o){e+=r.visit(i),o<n-1&&(e+=", ")}),e},visit_object:function(t){return t.width&&t.height?r.visit(t.width)+" "+r.visit(t.height):""},visit:function(t){if(!t)return"";if(t instanceof Array)return r.visit_array(t);if(typeof t=="object"&&!t.type)return r.visit_object(t);if(t.type){var e=r["visit_"+t.type];if(e)return e(t);throw Error("Missing visitor visit_"+t.type)}else throw Error("Invalid node.")}};return function(t){return r.visit(t)}})(),mr.stringify.bind(mr);function $i(r){const t=r.length-1;return r.map((e,n)=>{const i=e.value;let o=Pe(n/t,3),s="#00000000";switch(e.type){case"rgb":s=Bt({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0)});break;case"rgba":s=Bt({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0),a:Number(i[3]??0)});break;case"literal":s=Bt(e.value);break;case"hex":s=Bt(`#${e.value}`);break}switch(e.length?.type){case"%":o=Number(e.length.value)/100;break}return{offset:o,color:s}})}function zi(r){let t=0;switch(r.orientation?.type){case"angular":t=Number(r.orientation.value);break}return{type:"linear-gradient",angle:t,stops:$i(r.colorStops)}}function Ni(r){return r.orientation?.map(t=>{switch(t?.type){case"shape":case"default-radial":case"extent-keyword":default:return null}}),{type:"radial-gradient",stops:$i(r.colorStops)}}function xr(r){return r.startsWith("linear-gradient(")||r.startsWith("radial-gradient(")}function xl(r){return ml(r).map(t=>{switch(t?.type){case"linear-gradient":return zi(t);case"repeating-linear-gradient":return{...zi(t),repeat:!0};case"radial-gradient":return Ni(t);case"repeating-radial-gradient":return{...Ni(t),repeat:!0};default:return}}).filter(Boolean)}function vl(r){let t;return typeof r=="string"?t={color:r}:t={...r},{color:Bt(t.color)}}function wl(r){let t;if(typeof r=="string"?t={image:r}:t={...r},t.image){const{type:e,...n}=xl(t.image)[0]??{};switch(e){case"radial-gradient":return{radialGradient:n};case"linear-gradient":return{linearGradient:n}}}return dr(t,["linearGradient","radialGradient","rotateWithShape"])}function bl(r){let t;return typeof r=="string"?t={image:r}:t={...r},dr(t,["image","cropRect","stretchRect","tile","dpi","opacity","rotateWithShape"])}function Sl(r){let t;return typeof r=="string"?t={preset:r}:t={...r},tt(t.foregroundColor)?delete t.foregroundColor:t.foregroundColor=Bt(t.foregroundColor),tt(t.backgroundColor)?delete t.backgroundColor:t.backgroundColor=Bt(t.backgroundColor),dr(t,["preset","foregroundColor","backgroundColor"])}function Cl(r){return!tt(r.color)}function Pl(r){return typeof r=="string"?yl(r):Cl(r)}function Ml(r){return!tt(r.image)&&xr(r.image)||!!r.linearGradient||!!r.radialGradient}function _l(r){return typeof r=="string"?xr(r):Ml(r)}function Tl(r){return!tt(r.image)&&!xr(r.image)}function kl(r){return typeof r=="string"?!xr(r):Tl(r)}function Al(r){return!tt(r.preset)}function Ol(r){return typeof r=="string"?!1:Al(r)}function We(r){const t=r&&typeof r=="object"?r.enabled:void 0;return Pl(r)?zt({enabled:t,...vl(r)}):_l(r)?zt({enabled:t,...wl(r)}):kl(r)?zt({enabled:t,...bl(r)}):Ol(r)?zt({enabled:t,...Sl(r)}):{}}function pn(r){return typeof r=="string"?{...We(r)}:{...We(r),...dr(r,["width","style","lineCap","lineJoin","headEnd","tailEnd"])}}function Il(){return{boxShadow:"none"}}function El(){return{overflow:"visible",direction:void 0,display:void 0,boxSizing:void 0,width:void 0,height:void 0,maxHeight:void 0,maxWidth:void 0,minHeight:void 0,minWidth:void 0,position:void 0,left:0,top:0,right:void 0,bottom:void 0,borderTop:void 0,borderLeft:void 0,borderRight:void 0,borderBottom:void 0,borderWidth:0,border:void 0,flex:void 0,flexBasis:void 0,flexDirection:void 0,flexGrow:void 0,flexShrink:void 0,flexWrap:void 0,justifyContent:void 0,gap:void 0,alignContent:void 0,alignItems:void 0,alignSelf:void 0,marginTop:void 0,marginLeft:void 0,marginRight:void 0,marginBottom:void 0,margin:void 0,paddingTop:void 0,paddingLeft:void 0,paddingRight:void 0,paddingBottom:void 0,padding:void 0}}function Bl(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function Dl(){return{...El(),...Bl(),...Il(),backgroundImage:"none",backgroundSize:"auto, auto",backgroundColor:"none",backgroundColormap:"none",borderRadius:0,borderColor:"none",borderStyle:"solid",outlineWidth:0,outlineOffset:0,outlineColor:"rgb(0, 0, 0)",outlineStyle:"none",visibility:"visible",filter:"none",opacity:1,pointerEvents:"auto",maskImage:"none"}}function Fl(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function Ul(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function Ll(){return{...Fl(),color:"rgb(0, 0, 0)",verticalAlign:"baseline",letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:"normal",fontFamily:"",fontStyle:"normal",fontKerning:"normal",textTransform:"none",textOrientation:"mixed",textDecoration:"none"}}function $l(){return{...Ul(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function zl(){return{...$l(),...Ll(),textStrokeWidth:0,textStrokeColor:"rgb(0, 0, 0)"}}function vr(r){return zt({...r,color:tt(r.color)?void 0:Bt(r.color),backgroundColor:tt(r.backgroundColor)?void 0:Bt(r.backgroundColor),borderColor:tt(r.borderColor)?void 0:Bt(r.borderColor),outlineColor:tt(r.outlineColor)?void 0:Bt(r.outlineColor),shadowColor:tt(r.shadowColor)?void 0:Bt(r.shadowColor)})}function Nl(){return{...Dl(),...zl()}}const Vl=/\r\n|\n\r|\n|\r/,jl=new RegExp(`^(${Vl.source})$`),Rl=`
|
|
33
33
|
`;function Gl(r){return jl.test(r)}function Vi(r){const t=[];function e(){return t[t.length-1]}function n(a,l,c){const h=a?vr(a):{},u=l?We(l):void 0,p=c?pn(c):void 0,g=zt({...h,fill:u,outline:p,fragments:[]});return t[t.length-1]?.fragments.length===0?t[t.length-1]=g:t.push(g),g}function i(a="",l,c,h){const u=l?vr(l):{},p=c?We(c):void 0,g=h?pn(h):void 0;Array.from(a).forEach(f=>{if(Gl(f)){const{fragments:y,fill:d,outline:P,...M}=e()||n();y.length||y.push(zt({...u,fill:p,outline:g,content:Rl})),n(M,d,P)}else{const y=e()||n(),d=y.fragments[y.fragments.length-1];if(d){const{content:P,fill:M,outline:w,...C}=d;if(hn(p,M)&&hn(g,w)&&hn(u,C)){d.content=`${P}${f}`;return}}y.fragments.push(zt({...u,fill:p,outline:g,content:f}))}})}(Array.isArray(r)?r:[r]).forEach(a=>{if(typeof a=="string")n(),i(a);else if(ji(a)){const{content:l,fill:c,outline:h,...u}=a;n(u,c,h),i(l)}else if(ql(a)){const{fragments:l,fill:c,outline:h,...u}=a;n(u,c,h),l.forEach(p=>{const{content:g,fill:f,outline:y,...d}=p;i(g,d,f,y)})}else Array.isArray(a)?(n(),a.forEach(l=>{if(typeof l=="string")i(l);else if(ji(l)){const{content:c,fill:h,outline:u,...p}=l;i(c,p,h,u)}})):console.warn("Failed to parse text content",a)});const s=e();return s&&!s.fragments.length&&s.fragments.push({content:""}),t}function ql(r){return r&&typeof r=="object"&&"fragments"in r&&Array.isArray(r.fragments)}function ji(r){return r&&typeof r=="object"&&"content"in r&&typeof r.content=="string"}function Wl(r){return typeof r=="string"||Array.isArray(r)?{content:Vi(r)}:zt({...r,content:Vi(r.content??""),style:r.style?vr(r.style):void 0,effects:r.effects?r.effects.map(t=>vr(t)):void 0,measureDom:r.measureDom,fonts:r.fonts,fill:r.fill?We(r.fill):void 0,outline:r.outline?pn(r.outline):void 0})}function wr(r,t){return typeof r=="number"?r:r.endsWith("%")?(r=r.substring(0,r.length-1),Math.ceil(Number(r)/100*t.total)):r.endsWith("rem")?(r=r.substring(0,r.length-3),Number(r)*t.fontSize):r.endsWith("em")?(r=r.substring(0,r.length-2),Number(r)*t.fontSize):Number(r)}function br(r){return tt(r)?{}:r}function Ri(r,t){const e=Object.keys(r),n=Object.keys(t);return Array.from(new Set([...e,...n])).every(o=>ge(r[o],t[o]))}function ge(r,t){const e=typeof r;return e===typeof t?e==="object"?Ri(r,t):r===t:!1}function Hl(r){const t=r.startsWith("#")?r.slice(1):r;if(!/^(?:[0-9A-F]{3}|[0-9A-F]{6})$/i.test(t))return null;const n=t.length===3?t.split("").map(a=>a+a).join(""):t,i=Number.parseInt(n.slice(0,2),16),o=Number.parseInt(n.slice(2,4),16),s=Number.parseInt(n.slice(4,6),16);return`rgb(${i}, ${o}, ${s})`}function Sr(r){if(!r)return r;const t={};for(const e in r)r[e]!==""&&r[e]!==void 0&&(t[e]=r[e]);return t}class Gi{constructor(t,e={},n,i){this.content=t,this.style=e,this.index=n,this.parent=i,this.updateComputedStyle().initCharacters()}inlineBox=new X;fill;outline;get computedFill(){return this.fill??this.parent.computedFill}get computedOutline(){return this.outline??this.parent.computedOutline}get computedContent(){const t=this.computedStyle;return t.textTransform==="uppercase"?this.content.toUpperCase():t.textTransform==="lowercase"?this.content.toLowerCase():this.content}updateComputedStyle(){return this.computedStyle={...this.parent.computedStyle,...Sr(this.style)},this}initCharacters(){const t=[];let e=0;for(const n of this.computedContent)t.push(new bi(n,e++,this));return this.characters=t,this}}class qi{constructor(t,e,n){this.style=t,this.index=e,this.parent=n,this.updateComputedStyle()}lineBox=new X;fragments=[];fill;outline;get computedFill(){return this.fill??this.parent.fill}get computedOutline(){return this.outline??this.parent.outline}updateComputedStyle(){return this.computedStyle={...Sr(this.parent.computedStyle),...Sr(this.style)},this}}function Xl(r){return r}class He{static notZeroStyles=new Set(["width","height"]);static pxStyles=new Set(["width","height","fontSize","letterSpacing","textStrokeWidth","textIndent","shadowOffsetX","shadowOffsetY","shadowBlur","margin","marginLeft","marginTop","marginRight","marginBottom","padding","paddingLeft","paddingTop","paddingRight","paddingBottom"]);_toDomStyle(t){const e={};for(const n in t){const i=t[n];He.notZeroStyles.has(n)&&i===0||(typeof i=="number"&&He.pxStyles.has(n)?e[n]=`${i}px`:e[n]=i)}return e}createDom(t,e){const n=document.createElement("section"),i={...e},o=e.writingMode.includes("horizontal");switch(e.textAlign){case"start":case"left":i.justifyContent="flex-start";break;case"center":i.justifyContent="center";break;case"end":case"right":i.justifyContent="flex-end";break}switch(e.verticalAlign){case"top":i.alignItems="flex-start";break;case"middle":i.alignItems="center";break;case"bottom":i.alignItems="flex-end";break}const s=!!(i.justifyContent||i.alignItems);Object.assign(n.style,{...this._toDomStyle({...i,boxSizing:i.boxSizing??"border-box",display:i.display??(s?"inline-flex":void 0),width:i.width??"max-content",height:i.height??"max-content"}),whiteSpace:"pre-wrap",wordBreak:"break-all"});const a=document.createElement("ul");return Object.assign(a.style,{verticalAlign:"inherit",listStyleType:"inherit",padding:"0",margin:"0",width:s&&o?"100%":void 0,height:s&&!o?"100%":void 0}),t.forEach(l=>{const c=document.createElement("li");Object.assign(c.style,{verticalAlign:"inherit",...this._toDomStyle(l.style)}),l.fragments.forEach(h=>{const u=document.createElement("span");Object.assign(u.style,{verticalAlign:"inherit",...this._toDomStyle(h.style)}),u.appendChild(document.createTextNode(h.content)),c.appendChild(u)}),a.appendChild(c)}),n.appendChild(a),n}measureDomText(t){const e=document.createRange();e.selectNodeContents(t);const n=t.data??"";let i=0;return Array.from(n).map(o=>{const s=i+=n.substring(i).indexOf(o),a=s+o.length;i+=o.length,e.setStart(t,Math.max(s,0)),e.setEnd(t,a);const l=e.getClientRects?.()??[e.getBoundingClientRect()];let c=l[l.length-1];l.length>1&&c.width<2&&(c=l[l.length-2]);const h=e.toString();if(h!==""&&c&&c.width+c.height!==0)return{content:h,top:c.top,left:c.left,height:c.height,width:c.width}}).filter(Boolean)}measureDom(t){const e=[],n=[],i=[];return t.querySelectorAll("li").forEach((o,s)=>{const a=o.getBoundingClientRect();e.push({paragraphIndex:s,left:a.left,top:a.top,width:a.width,height:a.height}),o.querySelectorAll(":scope > *").forEach((l,c)=>{const h=l.getBoundingClientRect();n.push({paragraphIndex:s,fragmentIndex:c,left:h.left,top:h.top,width:h.width,height:h.height});let u=0;!l.children.length&&l.firstChild instanceof window.Text?this.measureDomText(l.firstChild).forEach(p=>{i.push({...p,newParagraphIndex:-1,paragraphIndex:s,fragmentIndex:c,characterIndex:u++,textWidth:-1,textHeight:-1})}):l.querySelectorAll(":scope > *").forEach(p=>{p.firstChild instanceof window.Text&&this.measureDomText(p.firstChild).forEach(g=>{i.push({...g,newParagraphIndex:-1,paragraphIndex:s,fragmentIndex:c,characterIndex:u++,textWidth:-1,textHeight:-1})})})})}),{paragraphs:e,fragments:n,characters:i}}measureParagraphDom(t,e){const n=e.getBoundingClientRect(),i=this.measureDom(e);i.paragraphs.forEach(a=>{const l=t[a.paragraphIndex];l.lineBox.left=a.left-n.left,l.lineBox.top=a.top-n.top,l.lineBox.width=a.width,l.lineBox.height=a.height}),i.fragments.forEach(a=>{const l=t[a.paragraphIndex].fragments[a.fragmentIndex];l.inlineBox.left=a.left-n.left,l.inlineBox.top=a.top-n.top,l.inlineBox.width=a.width,l.inlineBox.height=a.height});const o=[];let s=0;return i.characters.forEach(a=>{const{paragraphIndex:l,fragmentIndex:c,characterIndex:h}=a;o.push({...a,newParagraphIndex:l,left:a.left-n.left,top:a.top-n.top});const u=t[l].fragments[c].characters[h],{fontHeight:p,isVertical:g}=u,f=o[s];u.inlineBox.left=f.left,u.inlineBox.top=f.top,u.inlineBox.width=f.width,u.inlineBox.height=f.height,g?(u.lineBox.left=f.left+(f.width-p)/2,u.lineBox.top=f.top,u.lineBox.width=p,u.lineBox.height=f.height):(u.lineBox.left=f.left,u.lineBox.top=f.top+(f.height-p)/2,u.lineBox.width=f.width,u.lineBox.height=p),s++}),{paragraphs:t,boundingBox:new X(0,0,n.width,n.height)}}measure(t,e,n){let i;n||(n=this.createDom(t,e),Object.assign(n.style,{position:"fixed",visibility:"hidden"}),document.body.appendChild(n),i=()=>n?.parentNode?.removeChild(n));const o=this.measureParagraphDom(t,n);return i?.(),o}}function Wi(){const r=new se,t=sn(),e=on(t);return{name:"background",pathSet:r,load:async n=>{const{backgroundImage:i}=n.computedStyle;i&&t.needsLoad(i)&&await t.load(i)},update:n=>{r.paths.length=0;const{computedStyle:i,lineBox:o,isVertical:s}=n,{backgroundImage:a,backgroundSize:l,backgroundColormap:c}=i;if(tt(a))return;const{pathSet:h}=e.parse(a),u=h.getBoundingBox(!0);let p,g,f,y;s?{x:g,y:p,width:y,height:f}=o:{x:p,y:g,width:f,height:y}=o;const d=br(c??"none"),P=h.paths.map(v=>{const x=v.clone();return x.style.fill&&x.style.fill in d&&(x.style.fill=d[x.style.fill]),x.style.stroke&&x.style.stroke in d&&(x.style.stroke=d[x.style.stroke]),x});let M,w;if(l==="rigid"){M=Math.max(n.fontSize*5/u.width),w=M;const v=new k;v.x=u.width-f/M,v.y=u.height-y/w,P.forEach(x=>{x.applyTransform(S=>{const b=S.x>u.left+u.width/2,D=S.y>u.top+u.height/2;b&&(S.x-=v.x),D&&(S.y-=v.y)})})}else M=f/u.width,w=y/u.height;const C=new Ct;C.translate(-u.x,-u.y),C.scale(M,w),s&&(C.translate(-f/2,-y/2),C.rotate(-Math.PI/2),C.translate(y/2,f/2)),C.translate(p,g),P.forEach(v=>{v.applyTransform(x=>{x.applyMatrix3(C)})}),r.paths.push(...P)},renderOrder:-2,render:(n,i)=>{const{boundingBox:o,computedStyle:s}=i;tt(s.backgroundColor)||(n.fillStyle=s.backgroundColor,n.fillRect(...o.array)),r.paths.forEach(a=>{if(he({ctx:n,path:a,fontSize:s.fontSize}),i.debug){const l=new se([a]).getBoundingBox();l&&n.strokeRect(l.x,l.y,l.width,l.height)}}),i.paragraphs.forEach(a=>{const{lineBox:l,style:c}=a;tt(c.backgroundColor)||(n.fillStyle=c.backgroundColor,n.fillRect(...l.array)),a.fragments.forEach(h=>{const{inlineBox:u,style:p}=h;tt(p.backgroundColor)||(n.fillStyle=p.backgroundColor,n.fillRect(...u.array))})})}}}function Cr(r){const{highlight:t,highlightImage:e,highlightReferImage:n,highlightColormap:i,highlightLine:o,highlightSize:s,highlightThickness:a}=r;return{image:t?.image??e??"none",referImage:t?.referImage??n??"none",colormap:t?.colormap??i??"none",line:t?.line??o??"none",size:t?.size??s??"cover",thickness:t?.thickness??a??"100%"}}function Hi(){const r=new se,t=[],e=sn(),n=on(e);return{name:"highlight",pathSet:r,load:async i=>{const o=new Set;i.forEachCharacter(s=>{const{computedStyle:a}=s,{image:l,referImage:c}=Cr(a);l&&e.needsLoad(l)&&o.add(l),c&&e.needsLoad(c)&&o.add(c)}),await Promise.all(Array.from(o).map(s=>e.load(s)))},update:i=>{t.length=0,r.paths.length=0;let o=[],s,a;i.forEachCharacter(l=>{const{computedStyle:c}=l,h=Cr(c),{image:u,colormap:p,line:g,size:f,thickness:y}=h;if(tt(u))s?.length&&(s=[],o.push(s));else{const{inlineBox:d,isVertical:P}=l,{fontSize:M}=c;(!a||ge(a.image,u)&&ge(a.colormap,p)&&ge(a.line,g)&&ge(a.size,f)&&ge(a.thickness,y))&&s?.length&&(P?s[0].inlineBox.left===d.left:s[0].inlineBox.top===d.top)&&s[0].fontSize===M?s.push(l):(s=[],s.push(l),o.push(s))}a=h}),o=o.filter(l=>l.length);for(let l=0;l<o.length;l++){const c=o[l],h=c[0],u=X.from(...c.map(I=>I.compatibleGlyphBox));if(!u.height||!u.width)continue;const{computedStyle:p,isVertical:g,inlineBox:f,compatibleGlyphBox:y,strikeoutPosition:d,underlinePosition:P}=h,{fontSize:M}=p,{image:w,referImage:C,colormap:v,line:x,size:S,thickness:b}=Cr(p),D=wr(b,{fontSize:M,total:u.width})/u.width,N=br(v),{pathSet:E,dom:F}=n.parse(w),z=E.getBoundingBox(!0),B=M/z.width*2,A=new X().copy(u);g&&(A.width=u.height,A.height=u.width,A.left=u.left+u.width);const W=Math.floor(A.width);let O=W;S!=="cover"&&(O=wr(S,{fontSize:M,total:u.width})||W,A.width=O);const L=!tt(C)&&tt(x);if(L)z.copy(n.parse(C).pathSet.getBoundingBox(!0));else{let I;if(tt(x))if(z.width/z.height>4){I="underline";const V=F.getAttribute("viewBox");if(V){const[T,_,U,$]=V.split(" ").map(Z=>Number(Z)),q=_+$/2;z.y<q&&z.y+z.height>q?I="line-through":z.y+z.height<q?I="overline":I="underline"}}else I="outline";else I=x;switch(I){case"outline":{const V=A.width*.2,T=A.height*.2;g?(A.x-=T/2,A.y-=V/2,A.x-=A.height):(A.x-=V/2,A.y-=T/2),A.width+=V,A.height+=T;break}case"overline":A.height=z.height*B,g?A.x=f.left+f.width:A.y=f.top;break;case"line-through":A.height=z.height*B,g?A.x=f.left+f.width-d+A.height/2:A.y=f.top+d-A.height/2;break;case"underline":A.height=z.height*B,g?A.x=y.left+y.width-P:A.y=f.top+P;break}}const j=new Ct;if(j.translate(-z.x,-z.y),j.scale(A.width/z.width,A.height/z.height),g){const I=A.width/2,V=A.height/2;L||j.translate(-I,-V),j.rotate(-Math.PI/2),L||j.translate(V,I)}j.translate(A.x,A.y);for(let I=0;I<Math.ceil(W/O);I++){const V=j.clone();g?V.translate(0,I*A.width):V.translate(I*A.width,0),E.paths.forEach(T=>{const _=T.clone().applyTransform(V);_.style.strokeWidth&&(_.style.strokeWidth*=B*D),_.style.strokeMiterlimit&&(_.style.strokeMiterlimit*=B),_.style.strokeDashoffset&&(_.style.strokeDashoffset*=B),_.style.strokeDasharray&&(_.style.strokeDasharray=_.style.strokeDasharray.map(U=>U*B)),_.style.fill&&_.style.fill in N&&(_.style.fill=N[_.style.fill]),_.style.stroke&&_.style.stroke in N&&(_.style.stroke=N[_.style.stroke]),r.paths.push(_),W!==O&&(g?t[r.paths.length-1]=new X(u.left-u.width*2,u.top,u.width*4,u.height):t[r.paths.length-1]=new X(u.left,u.top-u.height*2,u.width,u.height*4))})}}},renderOrder:-1,getBoundingBox:()=>{const i=[];return r.paths.forEach((o,s)=>{const a=t[s];let l=o.getBoundingBox();if(a){const c=Math.max(l.x,a.x),h=Math.max(l.y,a.y),u=Math.min(l.right,a.right),p=Math.min(l.bottom,a.bottom);l=new X(c,h,u-c,p-h)}i.push(l)}),X.from(...i)},render:(i,o)=>{r.paths.forEach((s,a)=>{if(he({ctx:i,path:s,fontSize:o.computedStyle.fontSize,clipRect:t[a]}),o.debug){const l=new se([s]).getBoundingBox();l&&i.strokeRect(l.x,l.y,l.width,l.height)}})}}}function Zl(r,t){return`<svg width="${r*2}" height="${r*2}" xmlns="http://www.w3.org/2000/svg">
|
|
34
34
|
<circle cx="${r}" cy="${r}" r="${r}" fill="${t}" />
|
|
35
|
-
</svg>`}function Xi(){const r=new se;return{name:"listStyle",pathSet:r,update:t=>{r.paths.length=0;const{paragraphs:e,isVertical:n,fontSize:i}=t,o=i*.45;e.forEach(s=>{const{computedStyle:a}=s,{color:l,listStyleImage:c,listStyleColormap:h,listStyleSize:u,listStyleType:p}=a,g=br(h);let f=u,y;if(!tt(c))y=c;else if(!tt(p)){const x=i*.38/2;switch(f=f==="cover"?x*2:f,p){case"disc":y=Zl(x,String(l));break}}if(!y)return;const d=ai(y),P=d.getBoundingBox(),M=s.fragments[0]?.characters[0];if(!M)return;const{inlineBox:w}=M,C=f==="cover"?1:wr(f,{total:i,fontSize:i})/i,v=new Ct;if(n){const x=i/P.height*C;v.translate(-P.left,-P.top).rotate(Math.PI/2).scale(x,x).translate(w.left+(w.width-P.height*x)/2,w.top-o)}else{const x=i/P.height*C;v.translate(-P.left,-P.top).scale(x,x).translate(w.left-P.width*x-o,w.top+(w.height-P.height*x)/2)}r.paths.push(...d.paths.map(x=>{const S=x.clone();return S.applyTransform(v),S.style.fill&&S.style.fill in g&&(S.style.fill=g[S.style.fill]),S.style.stroke&&S.style.stroke in g&&(S.style.stroke=g[S.style.stroke]),S}))})}}}function Zi(){return{name:"outline"}}const ae=new k,Me=new Ct,le=new Ct;function Yi(){const r=new se;return{name:"render",pathSet:r,update:t=>{r.paths.length=0;const{paragraphs:e}=t;e.forEach(n=>{n.fragments.forEach(i=>{i.characters.forEach(o=>{r.paths.push(o.path)})})})},getBoundingBox:t=>{const{characters:e,fontSize:n,effects:i}=t,o=[];return e.forEach(s=>{i?.forEach(a=>{if(!s.glyphBox)return;const l=s.glyphBox.clone(),c=Pr(t,a);ae.set(l.left,l.top),ae.applyMatrix3(c),l.left=ae.x,l.top=ae.y,ae.set(l.right,l.bottom),ae.applyMatrix3(c),l.width=ae.x-l.left,l.height=ae.y-l.top;const h=(a.shadowOffsetX??0)*n,u=(a.shadowOffsetY??0)*n,p=Math.max(.1,a.textStrokeWidth??0)*n;l.left+=h-p,l.top+=u-p,l.width+=p*2,l.height+=p*2,o.push(l)})}),o.length?X.from(...o):void 0},render:(t,e)=>{const{paragraphs:n,glyphBox:i,effects:o}=e;o?o.forEach(s=>{_e(s,i,t),t.save();const[a,l,c,h,u,p]=Pr(e,s).transpose().elements;t.transform(a,h,l,u,c,p),e.forEachCharacter(g=>{g.drawTo(t,s)}),t.restore()}):n.forEach(s=>{s.fragments.forEach(a=>{a.characters.forEach(l=>{l.drawTo(t)})})}),e.debug&&n.forEach(s=>{t.strokeRect(s.lineBox.x,s.lineBox.y,s.lineBox.width,s.lineBox.height)})}}}function Pr(r,t){const{fontSize:e,glyphBox:n}=r,i=(t.translateX??0)*e,o=(t.translateY??0)*e,s=Math.PI*2,a=(t.skewX??0)/360*s,l=(t.skewY??0)/360*s,{left:c,top:h,width:u,height:p}=n,g=c+u/2,f=h+p/2;return Me.identity(),le.makeTranslation(i,o),Me.multiply(le),le.makeTranslation(g,f),Me.multiply(le),le.set(1,Math.tan(a),0,Math.tan(l),1,0,0,0,1),Me.multiply(le),le.makeTranslation(-g,-f),Me.multiply(le),Me.clone()}function Ki(){const r=new se;return{name:"textDecoration",pathSet:r,update:t=>{r.paths.length=0;const e=[];let n,i;t.forEachCharacter(o=>{const{computedStyle:s,isVertical:a,inlineBox:l,underlinePosition:c,underlineThickness:h,strikeoutPosition:u,strikeoutSize:p}=o,{color:g,textDecoration:f,writingMode:y}=s;if(tt(f))i=void 0;else{let d=!1;if(i?.textDecoration===f&&i?.writingMode===y&&i?.color===g&&(a?n[0].inlineBox.left===l.left:n[0].inlineBox.top===l.top))switch(f){case"underline":n[0].underlinePosition===c&&n[0].underlineThickness===h&&(d=!0);break;case"line-through":n[0].strikeoutPosition===u&&n[0].strikeoutSize===p&&(d=!0);break}d?n.push(o):(n=[],n.push(o),e.push(n)),i=s}}),e.forEach(o=>{const{computedStyle:s,isVertical:a,underlinePosition:l,underlineThickness:c,strikeoutPosition:h,strikeoutSize:u}=o[0],{color:p,textDecoration:g}=s,f=X.from(...o.map(S=>S.inlineBox)),{left:y,top:d,width:P,height:M}=f;let w=a?y+P:d;const C=a?-1:1;let v=0;switch(g){case"overline":v=c*2;break;case"underline":w+=C*l,v=c*2;break;case"line-through":w+=C*h,v=u*2;break}w-=v;let x;a?x=new _t([{type:"M",x:w,y:d},{type:"L",x:w,y:d+M},{type:"L",x:w+v,y:d+M},{type:"L",x:w+v,y:d},{type:"Z"}],{fill:p}):x=new _t([{type:"M",x:y,y:w},{type:"L",x:y+P,y:w},{type:"L",x:y+P,y:w+v},{type:"L",x:y,y:w+v},{type:"Z"}],{fill:p}),r.paths.push(x)})},render:(t,e)=>{const{effects:n,computedStyle:i}=e;n?n.forEach(o=>{t.save();const[s,a,l,c,h,u]=Pr(e,o).transpose().elements;t.transform(s,c,a,h,l,u),r.paths.forEach(p=>{he({ctx:t,path:p,fontSize:i.fontSize,...o})}),t.restore()}):r.paths.forEach(o=>{he({ctx:t,path:o,fontSize:i.fontSize})})}}}var Yl=Object.defineProperty,ce=(r,t,e,n)=>{for(var i=void 0,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(t,e,i)||i);return i&&Yl(t,e,i),i};const dn=Nl();class Nt extends pl{needsUpdate=!0;computedStyle={...dn};paragraphs=[];lineBox=new X;rawGlyphBox=new X;glyphBox=new X;pathBox=new X;boundingBox=new X;measurer=new He;plugins=new Map;pathSets=[];get fontSize(){return this.computedStyle.fontSize}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get characters(){return this.paragraphs.flatMap(t=>t.fragments.flatMap(e=>e.characters))}constructor(t={}){super(),this.set(t)}set(t={}){const{content:e,effects:n,style:i,measureDom:o,fonts:s,fill:a,outline:l}=Wl(t);this.debug=t.debug??!1,this.content=e,this.effects=n,this.style=i,this.measureDom=o,this.fonts=s,this.fill=a,this.outline=l,this.use(Wi()).use(Zi()).use(Xi()).use(Ki()).use(Hi()).use(Yi()),(t.plugins??[]).forEach(c=>{this.use(c)}),this.updateParagraphs()}use(t){return this.plugins.set(t.name,t),this}forEachCharacter(t){return this.paragraphs.forEach((e,n)=>{e.fragments.forEach((i,o)=>{i.characters.forEach((s,a)=>{t(s,{paragraphIndex:n,fragmentIndex:o,characterIndex:a})})})}),this}async load(){await Promise.all(Array.from(this.plugins.values()).map(t=>t.load?.(this)))}updateParagraphs(){this.computedStyle={...dn,...this.style};const{content:t}=this,e=[];return t.forEach((n,i)=>{const{fragments:o,fill:s,outline:a,...l}=n,c=new qi(l,i,this);c.fill=s,c.outline=a,o.forEach((h,u)=>{const{content:p,fill:g,outline:f,...y}=h;if(p!==void 0){const d=new Gi(p,y,u,c);c.fragments.push(d),d.fill=g,d.outline=f}}),e.push(c)}),this.paragraphs=e,this}createDom(){return this.updateParagraphs(),this.measurer.createDom(this.paragraphs,this.computedStyle)}measure(t=this.measureDom){const e={paragraphs:this.paragraphs,lineBox:this.lineBox,rawGlyphBox:this.rawGlyphBox,glyphBox:this.glyphBox,pathBox:this.pathBox,boundingBox:this.boundingBox};this.updateParagraphs();const n=this.measurer.measure(this.paragraphs,this.computedStyle,t);this.paragraphs=n.paragraphs,this.lineBox=n.boundingBox,this.characters.forEach(i=>{i.update(this.fonts)}),this.rawGlyphBox=this.getGlyphBox(),Array.from(this.plugins.values()).sort((i,o)=>(i.updateOrder??0)-(o.updateOrder??0)).forEach(i=>{i.update?.(this)}),this.pathSets.length=0,Array.from(this.plugins.values()).sort((i,o)=>(i.renderOrder??0)-(o.renderOrder??0)).forEach(i=>{i.pathSet?.paths.length&&this.pathSets.push(i.pathSet)}),this.glyphBox=this.getGlyphBox(),this.updatePathBox().updateBoundingBox();for(const i in e)n[i]=this[i],this[i]=e[i];return this.emit("measure",{text:this,result:n}),n}getGlyphBox(){const t=k.MAX,e=k.MIN;return this.characters.forEach(n=>{if(!n.getGlyphMinMax(t,e)){const{inlineBox:i}=n,{left:o,top:s,width:a,height:l}=i,c=new k(o,s),h=new k(o+a,s+l);t.min(c,h),e.max(c,h)}}),new X(t.x,t.y,e.x-t.x,e.y-t.y)}updatePathBox(){return this.pathBox=X.from(this.glyphBox,...Array.from(this.plugins.values()).map(t=>t.getBoundingBox?t.getBoundingBox(this):t.pathSet?.getBoundingBox()).filter(Boolean)),this}updateBoundingBox(){return this.boundingBox=X.from(this.rawGlyphBox,this.lineBox,this.pathBox),this}requestUpdate(){return this.needsUpdate=!0,this}update(t=this.measureDom){const e=this.measure(t);for(const n in e)this[n]=e[n];return this.emit("update",{text:this}),this
|
|
35
|
+
</svg>`}function Xi(){const r=new se;return{name:"listStyle",pathSet:r,update:t=>{r.paths.length=0;const{paragraphs:e,isVertical:n,fontSize:i}=t,o=i*.45;e.forEach(s=>{const{computedStyle:a}=s,{color:l,listStyleImage:c,listStyleColormap:h,listStyleSize:u,listStyleType:p}=a,g=br(h);let f=u,y;if(!tt(c))y=c;else if(!tt(p)){const x=i*.38/2;switch(f=f==="cover"?x*2:f,p){case"disc":y=Zl(x,String(l));break}}if(!y)return;const d=ai(y),P=d.getBoundingBox(),M=s.fragments[0]?.characters[0];if(!M)return;const{inlineBox:w}=M,C=f==="cover"?1:wr(f,{total:i,fontSize:i})/i,v=new Ct;if(n){const x=i/P.height*C;v.translate(-P.left,-P.top).rotate(Math.PI/2).scale(x,x).translate(w.left+(w.width-P.height*x)/2,w.top-o)}else{const x=i/P.height*C;v.translate(-P.left,-P.top).scale(x,x).translate(w.left-P.width*x-o,w.top+(w.height-P.height*x)/2)}r.paths.push(...d.paths.map(x=>{const S=x.clone();return S.applyTransform(v),S.style.fill&&S.style.fill in g&&(S.style.fill=g[S.style.fill]),S.style.stroke&&S.style.stroke in g&&(S.style.stroke=g[S.style.stroke]),S}))})}}}function Zi(){return{name:"outline"}}const ae=new k,Me=new Ct,le=new Ct;function Yi(){const r=new se;return{name:"render",pathSet:r,update:t=>{r.paths.length=0;const{paragraphs:e}=t;e.forEach(n=>{n.fragments.forEach(i=>{i.characters.forEach(o=>{r.paths.push(o.path)})})})},getBoundingBox:t=>{const{characters:e,fontSize:n,effects:i}=t,o=[];return e.forEach(s=>{i?.forEach(a=>{if(!s.glyphBox)return;const l=s.glyphBox.clone(),c=Pr(t,a);ae.set(l.left,l.top),ae.applyMatrix3(c),l.left=ae.x,l.top=ae.y,ae.set(l.right,l.bottom),ae.applyMatrix3(c),l.width=ae.x-l.left,l.height=ae.y-l.top;const h=(a.shadowOffsetX??0)*n,u=(a.shadowOffsetY??0)*n,p=Math.max(.1,a.textStrokeWidth??0)*n;l.left+=h-p,l.top+=u-p,l.width+=p*2,l.height+=p*2,o.push(l)})}),o.length?X.from(...o):void 0},render:(t,e)=>{const{paragraphs:n,glyphBox:i,effects:o}=e;o?o.forEach(s=>{_e(s,i,t),t.save();const[a,l,c,h,u,p]=Pr(e,s).transpose().elements;t.transform(a,h,l,u,c,p),e.forEachCharacter(g=>{g.drawTo(t,s)}),t.restore()}):n.forEach(s=>{s.fragments.forEach(a=>{a.characters.forEach(l=>{l.drawTo(t)})})}),e.debug&&n.forEach(s=>{t.strokeRect(s.lineBox.x,s.lineBox.y,s.lineBox.width,s.lineBox.height)})}}}function Pr(r,t){const{fontSize:e,glyphBox:n}=r,i=(t.translateX??0)*e,o=(t.translateY??0)*e,s=Math.PI*2,a=(t.skewX??0)/360*s,l=(t.skewY??0)/360*s,{left:c,top:h,width:u,height:p}=n,g=c+u/2,f=h+p/2;return Me.identity(),le.makeTranslation(i,o),Me.multiply(le),le.makeTranslation(g,f),Me.multiply(le),le.set(1,Math.tan(a),0,Math.tan(l),1,0,0,0,1),Me.multiply(le),le.makeTranslation(-g,-f),Me.multiply(le),Me.clone()}function Ki(){const r=new se;return{name:"textDecoration",pathSet:r,update:t=>{r.paths.length=0;const e=[];let n,i;t.forEachCharacter(o=>{const{computedStyle:s,isVertical:a,inlineBox:l,underlinePosition:c,underlineThickness:h,strikeoutPosition:u,strikeoutSize:p}=o,{color:g,textDecoration:f,writingMode:y}=s;if(tt(f))i=void 0;else{let d=!1;if(i?.textDecoration===f&&i?.writingMode===y&&i?.color===g&&(a?n[0].inlineBox.left===l.left:n[0].inlineBox.top===l.top))switch(f){case"underline":n[0].underlinePosition===c&&n[0].underlineThickness===h&&(d=!0);break;case"line-through":n[0].strikeoutPosition===u&&n[0].strikeoutSize===p&&(d=!0);break}d?n.push(o):(n=[],n.push(o),e.push(n)),i=s}}),e.forEach(o=>{const{computedStyle:s,isVertical:a,underlinePosition:l,underlineThickness:c,strikeoutPosition:h,strikeoutSize:u}=o[0],{color:p,textDecoration:g}=s,f=X.from(...o.map(S=>S.inlineBox)),{left:y,top:d,width:P,height:M}=f;let w=a?y+P:d;const C=a?-1:1;let v=0;switch(g){case"overline":v=c*2;break;case"underline":w+=C*l,v=c*2;break;case"line-through":w+=C*h,v=u*2;break}w-=v;let x;a?x=new _t([{type:"M",x:w,y:d},{type:"L",x:w,y:d+M},{type:"L",x:w+v,y:d+M},{type:"L",x:w+v,y:d},{type:"Z"}],{fill:p}):x=new _t([{type:"M",x:y,y:w},{type:"L",x:y+P,y:w},{type:"L",x:y+P,y:w+v},{type:"L",x:y,y:w+v},{type:"Z"}],{fill:p}),r.paths.push(x)})},render:(t,e)=>{const{effects:n,computedStyle:i}=e;n?n.forEach(o=>{t.save();const[s,a,l,c,h,u]=Pr(e,o).transpose().elements;t.transform(s,c,a,h,l,u),r.paths.forEach(p=>{he({ctx:t,path:p,fontSize:i.fontSize,...o})}),t.restore()}):r.paths.forEach(o=>{he({ctx:t,path:o,fontSize:i.fontSize})})}}}var Yl=Object.defineProperty,ce=(r,t,e,n)=>{for(var i=void 0,o=r.length-1,s;o>=0;o--)(s=r[o])&&(i=s(t,e,i)||i);return i&&Yl(t,e,i),i};const dn=Nl();class Nt extends pl{needsUpdate=!0;computedStyle={...dn};paragraphs=[];lineBox=new X;rawGlyphBox=new X;glyphBox=new X;pathBox=new X;boundingBox=new X;measurer=new He;plugins=new Map;pathSets=[];get fontSize(){return this.computedStyle.fontSize}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get characters(){return this.paragraphs.flatMap(t=>t.fragments.flatMap(e=>e.characters))}constructor(t={}){super(),this.set(t)}set(t={}){const{content:e,effects:n,style:i,measureDom:o,fonts:s,fill:a,outline:l}=Wl(t);this.debug=t.debug??!1,this.content=e,this.effects=n,this.style=i,this.measureDom=o,this.fonts=s,this.fill=a,this.outline=l,this.use(Wi()).use(Zi()).use(Xi()).use(Ki()).use(Hi()).use(Yi()),(t.plugins??[]).forEach(c=>{this.use(c)}),this.updateParagraphs()}use(t){return this.plugins.set(t.name,t),this}forEachCharacter(t){return this.paragraphs.forEach((e,n)=>{e.fragments.forEach((i,o)=>{i.characters.forEach((s,a)=>{t(s,{paragraphIndex:n,fragmentIndex:o,characterIndex:a})})})}),this}async load(){await Promise.all(Array.from(this.plugins.values()).map(t=>t.load?.(this)))}updateParagraphs(){this.computedStyle={...dn,...this.style};const{content:t}=this,e=[];return t.forEach((n,i)=>{const{fragments:o,fill:s,outline:a,...l}=n,c=new qi(l,i,this);c.fill=s,c.outline=a,o.forEach((h,u)=>{const{content:p,fill:g,outline:f,...y}=h;if(p!==void 0){const d=new Gi(p,y,u,c);c.fragments.push(d),d.fill=g,d.outline=f}}),e.push(c)}),this.paragraphs=e,this}createDom(){return this.updateParagraphs(),this.measurer.createDom(this.paragraphs,this.computedStyle)}measure(t=this.measureDom){const e={paragraphs:this.paragraphs,lineBox:this.lineBox,rawGlyphBox:this.rawGlyphBox,glyphBox:this.glyphBox,pathBox:this.pathBox,boundingBox:this.boundingBox};this.updateParagraphs();const n=this.measurer.measure(this.paragraphs,this.computedStyle,t);this.paragraphs=n.paragraphs,this.lineBox=n.boundingBox,this.characters.forEach(i=>{i.update(this.fonts)}),this.rawGlyphBox=this.getGlyphBox(),Array.from(this.plugins.values()).sort((i,o)=>(i.updateOrder??0)-(o.updateOrder??0)).forEach(i=>{i.update?.(this)}),this.pathSets.length=0,Array.from(this.plugins.values()).sort((i,o)=>(i.renderOrder??0)-(o.renderOrder??0)).forEach(i=>{i.pathSet?.paths.length&&this.pathSets.push(i.pathSet)}),this.glyphBox=this.getGlyphBox(),this.updatePathBox().updateBoundingBox();for(const i in e)n[i]=this[i],this[i]=e[i];return this.emit("measure",{text:this,result:n}),n}getGlyphBox(){const t=k.MAX,e=k.MIN;return this.characters.forEach(n=>{if(!n.getGlyphMinMax(t,e)){const{inlineBox:i}=n,{left:o,top:s,width:a,height:l}=i,c=new k(o,s),h=new k(o+a,s+l);t.min(c,h),e.max(c,h)}}),new X(t.x,t.y,e.x-t.x,e.y-t.y)}updatePathBox(){return this.pathBox=X.from(this.glyphBox,...Array.from(this.plugins.values()).map(t=>t.getBoundingBox?t.getBoundingBox(this):t.pathSet?.getBoundingBox()).filter(Boolean)),this}updateBoundingBox(){return this.boundingBox=X.from(this.rawGlyphBox,this.lineBox,this.pathBox),this}requestUpdate(){return this.needsUpdate=!0,this}update(t=this.measureDom){this.needsUpdate=!1;const e=this.measure(t);for(const n in e)this[n]=e[n];return this.emit("update",{text:this}),this}render(t){const{view:e,pixelRatio:n=2}=t,i=e.getContext("2d");i&&(this.needsUpdate&&this.update(),yn(i,n,this.boundingBox),mn(i,this),Array.from(this.plugins.values()).sort((o,s)=>(o.renderOrder??0)-(s.renderOrder??0)).forEach(o=>{if(o.render)o.render?.(i,this);else if(o.pathSet){const s=this.computedStyle;o.pathSet.paths.forEach(a=>{he({ctx:i,path:a,fontSize:s.fontSize})})}}),this.emit("render",{text:this,view:e,pixelRatio:n}),t.onContext?.(i))}toString(){return this.content.flatMap(t=>t.fragments.map(e=>e.content)).join("")}}ce([oe({internal:!0})],Nt.prototype,"debug"),ce([oe()],Nt.prototype,"content"),ce([oe()],Nt.prototype,"style"),ce([oe()],Nt.prototype,"effects"),ce([oe()],Nt.prototype,"fill"),ce([oe()],Nt.prototype,"outline"),ce([oe({internal:!0})],Nt.prototype,"measureDom"),ce([oe({internal:!0})],Nt.prototype,"fonts");function Kl(r,t){const e=new Nt(r);return t?e.load().then(()=>e.measure()):e.measure()}function Ql(r,t){const e=new Nt(r);return t?e.load().then(()=>e.render(r)):e.render(r)}H.Character=bi,H.Fragment=Gi,H.Measurer=He,H.Paragraph=qi,H.Text=Nt,H.backgroundPlugin=Wi,H.createSVGLoader=sn,H.createSVGParser=on,H.definePlugin=Xl,H.drawPath=he,H.filterEmpty=Sr,H.getHighlightStyle=Cr,H.getTransform2D=Pr,H.hexToRgb=Hl,H.highlightPlugin=Hi,H.isEqualObject=Ri,H.isEqualValue=ge,H.listStylePlugin=Xi,H.measureText=Kl,H.outlinePlugin=Zi,H.parseColor=te,H.parseColormap=br,H.parseValueNumber=wr,H.renderPlugin=Yi,H.renderText=Ql,H.setupView=yn,H.textDecorationPlugin=Ki,H.textDefaultStyle=dn,H.uploadColor=_e,H.uploadColors=mn,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as Text } from './shared/modern-text.
|
|
2
|
-
export { C as Character, F as Fragment, M as Measurer, P as Paragraph, c as backgroundPlugin, i as createSVGLoader, j as createSVGParser, b as definePlugin, d as drawPath, w as filterEmpty, g as getHighlightStyle, e as getTransform2D, v as hexToRgb, h as highlightPlugin, n as isEqualObject, q as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColor, m as parseColormap, k as parseValueNumber, r as renderPlugin, s as setupView, t as textDecorationPlugin, f as textDefaultStyle, u as uploadColor, a as uploadColors } from './shared/modern-text.
|
|
1
|
+
import { T as Text } from './shared/modern-text.B2pcGP3X.mjs';
|
|
2
|
+
export { C as Character, F as Fragment, M as Measurer, P as Paragraph, c as backgroundPlugin, i as createSVGLoader, j as createSVGParser, b as definePlugin, d as drawPath, w as filterEmpty, g as getHighlightStyle, e as getTransform2D, v as hexToRgb, h as highlightPlugin, n as isEqualObject, q as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColor, m as parseColormap, k as parseValueNumber, r as renderPlugin, s as setupView, t as textDecorationPlugin, f as textDefaultStyle, u as uploadColor, a as uploadColors } from './shared/modern-text.B2pcGP3X.mjs';
|
|
3
3
|
import 'modern-idoc';
|
|
4
4
|
import 'modern-path2d';
|
|
5
5
|
import 'modern-font';
|