modern-idoc 0.6.0 → 0.6.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.js CHANGED
@@ -1 +1 @@
1
- (function(u,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(u=typeof globalThis<"u"?globalThis:u||self,N(u.modernIdoc={}))})(this,function(u){"use strict";function N(t){return typeof t=="string"?{src:t}:t}var Gt={grad:.9,turn:360,rad:360/(2*Math.PI)},S=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},v=function(t,e,r){return e===void 0&&(e=0),r===void 0&&(r=Math.pow(10,e)),Math.round(r*t)/r+0},p=function(t,e,r){return e===void 0&&(e=0),r===void 0&&(r=1),t>r?r:t>e?t:e},U=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},q=function(t){return{r:p(t.r,0,255),g:p(t.g,0,255),b:p(t.b,0,255),a:p(t.a)}},M=function(t){return{r:v(t.r),g:v(t.g),b:v(t.b),a:v(t.a,3)}},Tt=/^#([0-9a-f]{3,8})$/i,E=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},J=function(t){var e=t.r,r=t.g,n=t.b,i=t.a,l=Math.max(e,r,n),s=l-Math.min(e,r,n),f=s?l===e?(r-n)/s:l===r?2+(n-e)/s:4+(e-r)/s:0;return{h:60*(f<0?f+6:f),s:l?s/l*100:0,v:l/255*100,a:i}},Q=function(t){var e=t.h,r=t.s,n=t.v,i=t.a;e=e/360*6,r/=100,n/=100;var l=Math.floor(e),s=n*(1-r),f=n*(1-(e-l)*r),C=n*(1-(1-e+l)*r),I=l%6;return{r:255*[n,f,s,s,C,n][I],g:255*[C,n,n,f,s,s][I],b:255*[s,s,C,n,n,f][I],a:i}},Z=function(t){return{h:U(t.h),s:p(t.s,0,100),l:p(t.l,0,100),a:p(t.a)}},tt=function(t){return{h:v(t.h),s:v(t.s),l:v(t.l),a:v(t.a,3)}},et=function(t){return Q((r=(e=t).s,{h:e.h,s:(r*=((n=e.l)<50?n:100-n)/100)>0?2*r/(n+r)*100:0,v:n+r,a:e.a}));var e,r,n},_=function(t){return{h:(e=J(t)).h,s:(i=(200-(r=e.s))*(n=e.v)/100)>0&&i<200?r*n/100/(i<=100?i:200-i)*100:0,l:i/2,a:e.a};var e,r,n,i},Ot=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Vt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,At=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Ht=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,rt={string:[[function(t){var e=Tt.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?v(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?v(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=At.exec(t)||Ht.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:q({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Ot.exec(t)||Vt.exec(t);if(!e)return null;var r,n,i=Z({h:(r=e[1],n=e[2],n===void 0&&(n="deg"),Number(r)*(Gt[n]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return et(i)},"hsl"]],object:[[function(t){var e=t.r,r=t.g,n=t.b,i=t.a,l=i===void 0?1:i;return S(e)&&S(r)&&S(n)?q({r:Number(e),g:Number(r),b:Number(n),a:Number(l)}):null},"rgb"],[function(t){var e=t.h,r=t.s,n=t.l,i=t.a,l=i===void 0?1:i;if(!S(e)||!S(r)||!S(n))return null;var s=Z({h:Number(e),s:Number(r),l:Number(n),a:Number(l)});return et(s)},"hsl"],[function(t){var e=t.h,r=t.s,n=t.v,i=t.a,l=i===void 0?1:i;if(!S(e)||!S(r)||!S(n))return null;var s=function(f){return{h:U(f.h),s:p(f.s,0,100),v:p(f.v,0,100),a:p(f.a)}}({h:Number(e),s:Number(r),v:Number(n),a:Number(l)});return Q(s)},"hsv"]]},nt=function(t,e){for(var r=0;r<e.length;r++){var n=e[r][0](t);if(n)return[n,e[r][1]]}return[null,void 0]},Mt=function(t){return typeof t=="string"?nt(t.trim(),rt.string):typeof t=="object"&&t!==null?nt(t,rt.object):[null,void 0]},R=function(t,e){var r=_(t);return{h:r.h,s:p(r.s+100*e,0,100),l:r.l,a:r.a}},$=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},it=function(t,e){var r=_(t);return{h:r.h,s:r.s,l:p(r.l+100*e,0,100),a:r.a}},ot=function(){function t(e){this.parsed=Mt(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return v($(this.rgba),2)},t.prototype.isDark=function(){return $(this.rgba)<.5},t.prototype.isLight=function(){return $(this.rgba)>=.5},t.prototype.toHex=function(){return e=M(this.rgba),r=e.r,n=e.g,i=e.b,s=(l=e.a)<1?E(v(255*l)):"","#"+E(r)+E(n)+E(i)+s;var e,r,n,i,l,s},t.prototype.toRgb=function(){return M(this.rgba)},t.prototype.toRgbString=function(){return e=M(this.rgba),r=e.r,n=e.g,i=e.b,(l=e.a)<1?"rgba("+r+", "+n+", "+i+", "+l+")":"rgb("+r+", "+n+", "+i+")";var e,r,n,i,l},t.prototype.toHsl=function(){return tt(_(this.rgba))},t.prototype.toHslString=function(){return e=tt(_(this.rgba)),r=e.h,n=e.s,i=e.l,(l=e.a)<1?"hsla("+r+", "+n+"%, "+i+"%, "+l+")":"hsl("+r+", "+n+"%, "+i+"%)";var e,r,n,i,l},t.prototype.toHsv=function(){return e=J(this.rgba),{h:v(e.h),s:v(e.s),v:v(e.v),a:v(e.a,3)};var e},t.prototype.invert=function(){return y({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},t.prototype.saturate=function(e){return e===void 0&&(e=.1),y(R(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),y(R(this.rgba,-e))},t.prototype.grayscale=function(){return y(R(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),y(it(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),y(it(this.rgba,-e))},t.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},t.prototype.alpha=function(e){return typeof e=="number"?y({r:(r=this.rgba).r,g:r.g,b:r.b,a:e}):v(this.rgba.a,3);var r},t.prototype.hue=function(e){var r=_(this.rgba);return typeof e=="number"?y({h:e,s:r.s,l:r.l,a:r.a}):v(r.h)},t.prototype.isEqual=function(e){return this.toHex()===y(e).toHex()},t}(),y=function(t){return t instanceof ot?t:new ot(t)};function at(t){let e;return typeof t=="number"?e={r:t>>24&255,g:t>>16&255,b:t>>8&255,a:(t&255)/255}:e=t,y(e)}function x(t,e=0,r=10**e){return Math.round(r*t)/r+0}function Rt(t){return{r:x(t.r),g:x(t.g),b:x(t.b),a:x(t.a,3)}}function G(t){const e=t.toString(16);return e.length<2?`0${e}`:e}const D="#000000FF";function g(t,e=!1){const r=at(t);if(!r.isValid()){if(typeof t=="string")return t;const f=`Failed to normalizeColor ${t}`;if(e)throw new Error(f);return console.warn(f),D}const{r:n,g:i,b:l,a:s}=Rt(r.rgba);return`#${G(n)}${G(i)}${G(l)}${G(x(s*255))}`}var T=T||{};T.parse=function(){const t={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 e="";function r(o){const a=new Error(`${e}: ${o}`);throw a.source=e,a}function n(){const o=i();return e.length>0&&r("Invalid input not EOF"),o}function i(){return A(l)}function l(){return s("linear-gradient",t.linearGradient,C)||s("repeating-linear-gradient",t.repeatingLinearGradient,C)||s("radial-gradient",t.radialGradient,It)||s("repeating-radial-gradient",t.repeatingRadialGradient,It)}function s(o,a,c){return f(a,m=>{const z=c();return z&&(h(t.comma)||r("Missing comma before color stops")),{type:o,orientation:z,colorStops:A(Ut)}})}function f(o,a){const c=h(o);if(c){h(t.startCall)||r("Missing (");const m=a(c);return h(t.endCall)||r("Missing )"),m}}function C(){const o=I();if(o)return o;const a=b("position-keyword",t.positionKeywords,1);return a?{type:"directional",value:a.value}:Kt()}function I(){return b("directional",t.sideOrCorner,1)}function Kt(){return b("angular",t.angleValue,1)||b("angular",t.radianValue,1)}function It(){let o,a=Lt(),c;return a&&(o=[],o.push(a),c=e,h(t.comma)&&(a=Lt(),a?o.push(a):e=c)),o}function Lt(){let o=Xt()||Yt();if(o)o.at=X();else{const a=K();if(a){o=a;const c=X();c&&(o.at=c)}else{const c=X();if(c)o={type:"default-radial",at:c};else{const m=Y();m&&(o={type:"default-radial",at:m})}}}return o}function Xt(){const o=b("shape",/^(circle)/i,0);return o&&(o.style=Et()||K()),o}function Yt(){const o=b("shape",/^(ellipse)/i,0);return o&&(o.style=Y()||H()||K()),o}function K(){return b("extent-keyword",t.extentKeywords,1)}function X(){if(b("position",/^at/,0)){const o=Y();return o||r("Missing positioning value"),o}}function Y(){const o=jt();if(o.x||o.y)return{type:"position",value:o}}function jt(){return{x:H(),y:H()}}function A(o){let a=o();const c=[];if(a)for(c.push(a);h(t.comma);)a=o(),a?c.push(a):r("One extra comma");return c}function Ut(){const o=qt();return o||r("Expected color definition"),o.length=H(),o}function qt(){return Qt()||ne()||re()||te()||Zt()||ee()||Jt()}function Jt(){return b("literal",t.literalColor,0)}function Qt(){return b("hex",t.hexColor,1)}function Zt(){return f(t.rgbColor,()=>({type:"rgb",value:A(L)}))}function te(){return f(t.rgbaColor,()=>({type:"rgba",value:A(L)}))}function ee(){return f(t.varColor,()=>({type:"var",value:ie()}))}function re(){return f(t.hslColor,()=>{h(t.percentageValue)&&r("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const a=L();h(t.comma);let c=h(t.percentageValue);const m=c?c[1]:null;h(t.comma),c=h(t.percentageValue);const z=c?c[1]:null;return(!m||!z)&&r("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[a,m,z]}})}function ne(){return f(t.hslaColor,()=>{const o=L();h(t.comma);let a=h(t.percentageValue);const c=a?a[1]:null;h(t.comma),a=h(t.percentageValue);const m=a?a[1]:null;h(t.comma);const z=L();return(!c||!m)&&r("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[o,c,m,z]}})}function ie(){return h(t.variableName)[1]}function L(){return h(t.number)[1]}function H(){return b("%",t.percentageValue,1)||oe()||ae()||Et()}function oe(){return b("position-keyword",t.positionKeywords,1)}function ae(){return f(t.calcValue,()=>{let o=1,a=0;for(;o>0&&a<e.length;){const m=e.charAt(a);m==="("?o++:m===")"&&o--,a++}o>0&&r("Missing closing parenthesis in calc() expression");const c=e.substring(0,a-1);return j(a-1),{type:"calc",value:c}})}function Et(){return b("px",t.pixelValue,1)||b("em",t.emValue,1)}function b(o,a,c){const m=h(a);if(m)return{type:o,value:m[c]}}function h(o){let a,c;return c=/^\s+/.exec(e),c&&j(c[0].length),a=o.exec(e),a&&j(a[0].length),a}function j(o){e=e.substr(o)}return function(o){return e=o.toString().trim(),e.endsWith(";")&&(e=e.slice(0,-1)),n()}}();const ut=T.parse.bind(T);var O=O||{};O.stringify=function(){var t={"visit_linear-gradient":function(e){return t.visit_gradient(e)},"visit_repeating-linear-gradient":function(e){return t.visit_gradient(e)},"visit_radial-gradient":function(e){return t.visit_gradient(e)},"visit_repeating-radial-gradient":function(e){return t.visit_gradient(e)},visit_gradient:function(e){var r=t.visit(e.orientation);return r&&(r+=", "),e.type+"("+r+t.visit(e.colorStops)+")"},visit_shape:function(e){var r=e.value,n=t.visit(e.at),i=t.visit(e.style);return i&&(r+=" "+i),n&&(r+=" at "+n),r},"visit_default-radial":function(e){var r="",n=t.visit(e.at);return n&&(r+=n),r},"visit_extent-keyword":function(e){var r=e.value,n=t.visit(e.at);return n&&(r+=" at "+n),r},"visit_position-keyword":function(e){return e.value},visit_position:function(e){return t.visit(e.value.x)+" "+t.visit(e.value.y)},"visit_%":function(e){return e.value+"%"},visit_em:function(e){return e.value+"em"},visit_px:function(e){return e.value+"px"},visit_calc:function(e){return"calc("+e.value+")"},visit_literal:function(e){return t.visit_color(e.value,e)},visit_hex:function(e){return t.visit_color("#"+e.value,e)},visit_rgb:function(e){return t.visit_color("rgb("+e.value.join(", ")+")",e)},visit_rgba:function(e){return t.visit_color("rgba("+e.value.join(", ")+")",e)},visit_hsl:function(e){return t.visit_color("hsl("+e.value[0]+", "+e.value[1]+"%, "+e.value[2]+"%)",e)},visit_hsla:function(e){return t.visit_color("hsla("+e.value[0]+", "+e.value[1]+"%, "+e.value[2]+"%, "+e.value[3]+")",e)},visit_var:function(e){return t.visit_color("var("+e.value+")",e)},visit_color:function(e,r){var n=e,i=t.visit(r.length);return i&&(n+=" "+i),n},visit_angular:function(e){return e.value+"deg"},visit_directional:function(e){return"to "+e.value},visit_array:function(e){var r="",n=e.length;return e.forEach(function(i,l){r+=t.visit(i),l<n-1&&(r+=", ")}),r},visit_object:function(e){return e.width&&e.height?t.visit(e.width)+" "+t.visit(e.height):""},visit:function(e){if(!e)return"";if(e instanceof Array)return t.visit_array(e);if(typeof e=="object"&&!e.type)return t.visit_object(e);if(e.type){var r=t["visit_"+e.type];if(r)return r(e);throw Error("Missing visitor visit_"+e.type)}else throw Error("Invalid node.")}};return function(e){return t.visit(e)}}();const $t=O.stringify.bind(O);function lt(t){var n;let e=0;switch((n=t.orientation)==null?void 0:n.type){case"angular":e=Number(t.orientation.value);break}const r=t.colorStops.map(i=>{var C;const l=i.value;let s=0,f="#00000000";switch(i.type){case"rgb":f=g({r:Number(l[0]??0),g:Number(l[1]??0),b:Number(l[2]??0)});break;case"rgba":f=g({r:Number(l[0]??0),g:Number(l[1]??0),b:Number(l[2]??0),a:Number(l[3]??0)});break;case"literal":f=g(i.value);break;case"hex":f=g(i.value);break}switch((C=i.length)==null?void 0:C.type){case"%":s=Number(i.length.value)/100;break}return{offset:s,color:f}});return{type:"linear-gradient",angle:e,stops:r}}function st(t){var r;return(r=t.orientation)==null||r.map(n=>{switch(n==null?void 0:n.type){case"shape":case"default-radial":case"extent-keyword":default:return null}}),{type:"radial-gradient",stops:t.colorStops.map(n=>{var f;const i=n.value;let l=0,s="#00000000";switch(n.type){case"rgb":s=g({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0)});break;case"rgba":s=g({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0),a:Number(i[3]??0)});break;case"literal":s=g(n.value);break;case"hex":s=g(n.value);break}switch((f=n.length)==null?void 0:f.type){case"%":l=Number(n.length.value)/100;break}return{offset:l,color:s}})}}function Pt(t){return ut(t).map(e=>{switch(e==null?void 0:e.type){case"linear-gradient":return lt(e);case"repeating-linear-gradient":return{...lt(e),repeat:!0};case"radial-gradient":return st(e);case"repeating-radial-gradient":return{...st(e),repeat:!0};default:return}}).filter(Boolean)}function d(t){return t==null||t==="none"}function w(t,e=!1){if(typeof t!="object"||!t)return t;if(Array.isArray(t))return e?t.map(n=>w(n,e)):t;const r={};for(const n in t){const i=t[n];i!=null&&(e?r[n]=w(i,e):r[n]=i)}return r}function V(t){return typeof t=="string"?{color:g(t)}:{...t,color:d(t.color)?void 0:g(t.color)}}function ct(t){return typeof t=="string"?{src:t}:{...t,...V(t)}}function P(){return{color:D,offsetX:0,offsetY:0,blurRadius:1}}function F(t){return{...P(),...w({...t,color:d(t.color)?D:g(t.color)})}}function ft(){return{...P(),scaleX:1,scaleY:1}}function dt(t){return{...ft(),...F(t)}}function Ft(t){return t}function gt(t){return w({...t,softEdge:d(t.softEdge)?void 0:t.softEdge,outerShadow:d(t.outerShadow)?void 0:dt(t.outerShadow),innerShadow:d(t.innerShadow)?void 0:F(t.innerShadow)})}function ht(t){return typeof t=="string"?{src:t}:{...t,...V(t)}}function vt(t){return typeof t=="string"?{paths:[{data:t}]}:Array.isArray(t)?{paths:t.map(e=>typeof e=="string"?{data:e}:e)}:t}function mt(t){return typeof t=="string"?{color:g(t)}:{...t,color:d(t.color)?void 0:g(t.color)}}function bt(t){return typeof t=="string"?{color:g(t)}:{...t,color:d(t.color)?D:g(t.color)}}function pt(){return{boxShadow:"none"}}function yt(){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 St(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function Ct(){return{...yt(),...St(),...pt(),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 wt(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function zt(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function Nt(){return{...wt(),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 kt(){return{...zt(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function _t(){return{...kt(),...Nt(),textStrokeWidth:0,textStrokeColor:"rgb(0, 0, 0)"}}function k(t){return w({...t,color:d(t.color)?void 0:g(t.color),backgroundColor:d(t.backgroundColor)?void 0:g(t.backgroundColor),borderColor:d(t.borderColor)?void 0:g(t.borderColor),outlineColor:d(t.outlineColor)?void 0:g(t.outlineColor),shadowColor:d(t.shadowColor)?void 0:g(t.shadowColor)})}function Bt(){return{...Ct(),..._t()}}function B(t=""){return(Array.isArray(t)?t:[t]).map(r=>typeof r=="string"?{fragments:[{content:r}]}:"content"in r?{fragments:[k(r)]}:"fragments"in r?{...k(r),fragments:r.fragments.map(n=>k(n))}:Array.isArray(r)?{fragments:r.map(n=>typeof n=="string"?{content:n}:k(n))}:{fragments:[]})}function xt(t){return typeof t=="string"?{content:[{fragments:[{content:t}]}]}:"content"in t?{...t,content:B(t.content)}:{content:B(t)}}function Dt(t){return typeof t=="string"?{src:t}:t}function W(t){var e;return w({...t,style:d(t.style)?void 0:k(t.style),text:d(t.text)?void 0:xt(t.text),background:d(t.background)?void 0:ct(t.background),geometry:d(t.geometry)?void 0:vt(t.geometry),fill:d(t.fill)?void 0:V(t.fill),outline:d(t.outline)?void 0:mt(t.outline),foreground:d(t.foreground)?void 0:ht(t.foreground),shadow:d(t.shadow)?void 0:bt(t.shadow),video:d(t.video)?void 0:Dt(t.video),audio:d(t.audio)?void 0:N(t.audio),effect:d(t.effect)?void 0:gt(t.effect),children:(e=t.children)==null?void 0:e.map(r=>W(r))})}function Wt(t){return W(t)}u.clearUndef=w,u.defaultColor=D,u.getDefaultElementStyle=Ct,u.getDefaultHighlightStyle=wt,u.getDefaultInnerShadow=P,u.getDefaultLayoutStyle=yt,u.getDefaultListStyleStyle=zt,u.getDefaultOuterShadow=ft,u.getDefaultShadowStyle=pt,u.getDefaultStyle=Bt,u.getDefaultTextInlineStyle=Nt,u.getDefaultTextLineStyle=kt,u.getDefaultTextStyle=_t,u.getDefaultTransformStyle=St,u.isNone=d,u.normalizeAudio=N,u.normalizeBackground=ct,u.normalizeColor=g,u.normalizeDocument=Wt,u.normalizeEffect=gt,u.normalizeElement=W,u.normalizeFill=V,u.normalizeForeground=ht,u.normalizeGeometry=vt,u.normalizeGradient=Pt,u.normalizeInnerShadow=F,u.normalizeOuterShadow=dt,u.normalizeOutline=mt,u.normalizeShadow=bt,u.normalizeSoftEdge=Ft,u.normalizeStyle=k,u.normalizeText=xt,u.normalizeTextContent=B,u.normalizeVideo=Dt,u.parseColor=at,u.parseGradient=ut,u.stringifyGradient=$t,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,k){typeof exports=="object"&&typeof module<"u"?k(exports):typeof define=="function"&&define.amd?define(["exports"],k):(a=typeof globalThis<"u"?globalThis:a||self,k(a.modernIdoc={}))})(this,function(a){"use strict";function k(t){return typeof t=="string"?{src:t}:t}var Wt={grad:.9,turn:360,rad:360/(2*Math.PI)},S=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},h=function(t,e,r){return e===void 0&&(e=0),r===void 0&&(r=Math.pow(10,e)),Math.round(r*t)/r+0},b=function(t,e,r){return e===void 0&&(e=0),r===void 0&&(r=1),t>r?r:t>e?t:e},Z=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},tt=function(t){return{r:b(t.r,0,255),g:b(t.g,0,255),b:b(t.b,0,255),a:b(t.a)}},H=function(t){return{r:h(t.r),g:h(t.g),b:h(t.b),a:h(t.a,3)}},Mt=/^#([0-9a-f]{3,8})$/i,E=function(t){var e=t.toString(16);return e.length<2?"0"+e:e},et=function(t){var e=t.r,r=t.g,n=t.b,o=t.a,l=Math.max(e,r,n),c=l-Math.min(e,r,n),d=c?l===e?(r-n)/c:l===r?2+(n-e)/c:4+(e-r)/c:0;return{h:60*(d<0?d+6:d),s:l?c/l*100:0,v:l/255*100,a:o}},rt=function(t){var e=t.h,r=t.s,n=t.v,o=t.a;e=e/360*6,r/=100,n/=100;var l=Math.floor(e),c=n*(1-r),d=n*(1-(e-l)*r),D=n*(1-(1-e+l)*r),x=l%6;return{r:255*[n,d,c,c,D,n][x],g:255*[D,n,n,d,c,c][x],b:255*[c,c,D,n,n,d][x],a:o}},nt=function(t){return{h:Z(t.h),s:b(t.s,0,100),l:b(t.l,0,100),a:b(t.a)}},it=function(t){return{h:h(t.h),s:h(t.s),l:h(t.l),a:h(t.a,3)}},ot=function(t){return rt((r=(e=t).s,{h:e.h,s:(r*=((n=e.l)<50?n:100-n)/100)>0?2*r/(n+r)*100:0,v:n+r,a:e.a}));var e,r,n},G=function(t){return{h:(e=et(t)).h,s:(o=(200-(r=e.s))*(n=e.v)/100)>0&&o<200?r*n/100/(o<=100?o:200-o)*100:0,l:o/2,a:e.a};var e,r,n,o},Rt=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,$t=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Pt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Bt=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,at={string:[[function(t){var e=Mt.exec(t);return e?(t=e[1]).length<=4?{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:t.length===4?h(parseInt(t[3]+t[3],16)/255,2):1}:t.length===6||t.length===8?{r:parseInt(t.substr(0,2),16),g:parseInt(t.substr(2,2),16),b:parseInt(t.substr(4,2),16),a:t.length===8?h(parseInt(t.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(t){var e=Pt.exec(t)||Bt.exec(t);return e?e[2]!==e[4]||e[4]!==e[6]?null:tt({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(t){var e=Rt.exec(t)||$t.exec(t);if(!e)return null;var r,n,o=nt({h:(r=e[1],n=e[2],n===void 0&&(n="deg"),Number(r)*(Wt[n]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return ot(o)},"hsl"]],object:[[function(t){var e=t.r,r=t.g,n=t.b,o=t.a,l=o===void 0?1:o;return S(e)&&S(r)&&S(n)?tt({r:Number(e),g:Number(r),b:Number(n),a:Number(l)}):null},"rgb"],[function(t){var e=t.h,r=t.s,n=t.l,o=t.a,l=o===void 0?1:o;if(!S(e)||!S(r)||!S(n))return null;var c=nt({h:Number(e),s:Number(r),l:Number(n),a:Number(l)});return ot(c)},"hsl"],[function(t){var e=t.h,r=t.s,n=t.v,o=t.a,l=o===void 0?1:o;if(!S(e)||!S(r)||!S(n))return null;var c=function(d){return{h:Z(d.h),s:b(d.s,0,100),v:b(d.v,0,100),a:b(d.a)}}({h:Number(e),s:Number(r),v:Number(n),a:Number(l)});return rt(c)},"hsv"]]},ut=function(t,e){for(var r=0;r<e.length;r++){var n=e[r][0](t);if(n)return[n,e[r][1]]}return[null,void 0]},jt=function(t){return typeof t=="string"?ut(t.trim(),at.string):typeof t=="object"&&t!==null?ut(t,at.object):[null,void 0]},W=function(t,e){var r=G(t);return{h:r.h,s:b(r.s+100*e,0,100),l:r.l,a:r.a}},M=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},lt=function(t,e){var r=G(t);return{h:r.h,s:r.s,l:b(r.l+100*e,0,100),a:r.a}},st=function(){function t(e){this.parsed=jt(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return t.prototype.isValid=function(){return this.parsed!==null},t.prototype.brightness=function(){return h(M(this.rgba),2)},t.prototype.isDark=function(){return M(this.rgba)<.5},t.prototype.isLight=function(){return M(this.rgba)>=.5},t.prototype.toHex=function(){return e=H(this.rgba),r=e.r,n=e.g,o=e.b,c=(l=e.a)<1?E(h(255*l)):"","#"+E(r)+E(n)+E(o)+c;var e,r,n,o,l,c},t.prototype.toRgb=function(){return H(this.rgba)},t.prototype.toRgbString=function(){return e=H(this.rgba),r=e.r,n=e.g,o=e.b,(l=e.a)<1?"rgba("+r+", "+n+", "+o+", "+l+")":"rgb("+r+", "+n+", "+o+")";var e,r,n,o,l},t.prototype.toHsl=function(){return it(G(this.rgba))},t.prototype.toHslString=function(){return e=it(G(this.rgba)),r=e.h,n=e.s,o=e.l,(l=e.a)<1?"hsla("+r+", "+n+"%, "+o+"%, "+l+")":"hsl("+r+", "+n+"%, "+o+"%)";var e,r,n,o,l},t.prototype.toHsv=function(){return e=et(this.rgba),{h:h(e.h),s:h(e.s),v:h(e.v),a:h(e.a,3)};var e},t.prototype.invert=function(){return y({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},t.prototype.saturate=function(e){return e===void 0&&(e=.1),y(W(this.rgba,e))},t.prototype.desaturate=function(e){return e===void 0&&(e=.1),y(W(this.rgba,-e))},t.prototype.grayscale=function(){return y(W(this.rgba,-1))},t.prototype.lighten=function(e){return e===void 0&&(e=.1),y(lt(this.rgba,e))},t.prototype.darken=function(e){return e===void 0&&(e=.1),y(lt(this.rgba,-e))},t.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},t.prototype.alpha=function(e){return typeof e=="number"?y({r:(r=this.rgba).r,g:r.g,b:r.b,a:e}):h(this.rgba.a,3);var r},t.prototype.hue=function(e){var r=G(this.rgba);return typeof e=="number"?y({h:e,s:r.s,l:r.l,a:r.a}):h(r.h)},t.prototype.isEqual=function(e){return this.toHex()===y(e).toHex()},t}(),y=function(t){return t instanceof st?t:new st(t)};function f(t){return t==null||t==="none"}function C(t,e=0,r=10**e){return Math.round(r*t)/r+0}function w(t,e=!1){if(typeof t!="object"||!t)return t;if(Array.isArray(t))return e?t.map(n=>w(n,e)):t;const r={};for(const n in t){const o=t[n];o!=null&&(e?r[n]=w(o,e):r[n]=o)}return r}function R(t){let e;return typeof t=="number"?e={r:t>>24&255,g:t>>16&255,b:t>>8&255,a:(t&255)/255}:e=t,y(e)}function Kt(t){return{r:C(t.r),g:C(t.g),b:C(t.b),a:C(t.a,3)}}function V(t){const e=t.toString(16);return e.length<2?`0${e}`:e}const I="#000000FF";function ct(t){return R(t).isValid()}function v(t,e=!1){const r=R(t);if(!r.isValid()){if(typeof t=="string")return t;const d=`Failed to normalizeColor ${t}`;if(e)throw new Error(d);return console.warn(d),I}const{r:n,g:o,b:l,a:c}=Kt(r.rgba);return`#${V(n)}${V(o)}${V(l)}${V(C(c*255))}`}var O=O||{};O.parse=function(){const t={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 e="";function r(i){const u=new Error(`${e}: ${i}`);throw u.source=e,u}function n(){const i=o();return e.length>0&&r("Invalid input not EOF"),i}function o(){return A(l)}function l(){return c("linear-gradient",t.linearGradient,D)||c("repeating-linear-gradient",t.repeatingLinearGradient,D)||c("radial-gradient",t.radialGradient,At)||c("repeating-radial-gradient",t.repeatingRadialGradient,At)}function c(i,u,s){return d(u,m=>{const z=s();return z&&(g(t.comma)||r("Missing comma before color stops")),{type:i,orientation:z,colorStops:A(re)}})}function d(i,u){const s=g(i);if(s){g(t.startCall)||r("Missing (");const m=u(s);return g(t.endCall)||r("Missing )"),m}}function D(){const i=x();if(i)return i;const u=p("position-keyword",t.positionKeywords,1);return u?{type:"directional",value:u.value}:Qt()}function x(){return p("directional",t.sideOrCorner,1)}function Qt(){return p("angular",t.angleValue,1)||p("angular",t.radianValue,1)}function At(){let i,u=Ft(),s;return u&&(i=[],i.push(u),s=e,g(t.comma)&&(u=Ft(),u?i.push(u):e=s)),i}function Ft(){let i=Zt()||te();if(i)i.at=q();else{const u=U();if(u){i=u;const s=q();s&&(i.at=s)}else{const s=q();if(s)i={type:"default-radial",at:s};else{const m=J();m&&(i={type:"default-radial",at:m})}}}return i}function Zt(){const i=p("shape",/^(circle)/i,0);return i&&(i.style=Ht()||U()),i}function te(){const i=p("shape",/^(ellipse)/i,0);return i&&(i.style=J()||F()||U()),i}function U(){return p("extent-keyword",t.extentKeywords,1)}function q(){if(p("position",/^at/,0)){const i=J();return i||r("Missing positioning value"),i}}function J(){const i=ee();if(i.x||i.y)return{type:"position",value:i}}function ee(){return{x:F(),y:F()}}function A(i){let u=i();const s=[];if(u)for(s.push(u);g(t.comma);)u=i(),u?s.push(u):r("One extra comma");return s}function re(){const i=ne();return i||r("Expected color definition"),i.length=F(),i}function ne(){return oe()||ce()||se()||ue()||ae()||le()||ie()}function ie(){return p("literal",t.literalColor,0)}function oe(){return p("hex",t.hexColor,1)}function ae(){return d(t.rgbColor,()=>({type:"rgb",value:A(L)}))}function ue(){return d(t.rgbaColor,()=>({type:"rgba",value:A(L)}))}function le(){return d(t.varColor,()=>({type:"var",value:fe()}))}function se(){return d(t.hslColor,()=>{g(t.percentageValue)&&r("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const u=L();g(t.comma);let s=g(t.percentageValue);const m=s?s[1]:null;g(t.comma),s=g(t.percentageValue);const z=s?s[1]:null;return(!m||!z)&&r("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[u,m,z]}})}function ce(){return d(t.hslaColor,()=>{const i=L();g(t.comma);let u=g(t.percentageValue);const s=u?u[1]:null;g(t.comma),u=g(t.percentageValue);const m=u?u[1]:null;g(t.comma);const z=L();return(!s||!m)&&r("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[i,s,m,z]}})}function fe(){return g(t.variableName)[1]}function L(){return g(t.number)[1]}function F(){return p("%",t.percentageValue,1)||de()||ge()||Ht()}function de(){return p("position-keyword",t.positionKeywords,1)}function ge(){return d(t.calcValue,()=>{let i=1,u=0;for(;i>0&&u<e.length;){const m=e.charAt(u);m==="("?i++:m===")"&&i--,u++}i>0&&r("Missing closing parenthesis in calc() expression");const s=e.substring(0,u-1);return Q(u-1),{type:"calc",value:s}})}function Ht(){return p("px",t.pixelValue,1)||p("em",t.emValue,1)}function p(i,u,s){const m=g(u);if(m)return{type:i,value:m[s]}}function g(i){let u,s;return s=/^\s+/.exec(e),s&&Q(s[0].length),u=i.exec(e),u&&Q(u[0].length),u}function Q(i){e=e.substr(i)}return function(i){return e=i.toString().trim(),e.endsWith(";")&&(e=e.slice(0,-1)),n()}}();const ft=O.parse.bind(O);var T=T||{};T.stringify=function(){var t={"visit_linear-gradient":function(e){return t.visit_gradient(e)},"visit_repeating-linear-gradient":function(e){return t.visit_gradient(e)},"visit_radial-gradient":function(e){return t.visit_gradient(e)},"visit_repeating-radial-gradient":function(e){return t.visit_gradient(e)},visit_gradient:function(e){var r=t.visit(e.orientation);return r&&(r+=", "),e.type+"("+r+t.visit(e.colorStops)+")"},visit_shape:function(e){var r=e.value,n=t.visit(e.at),o=t.visit(e.style);return o&&(r+=" "+o),n&&(r+=" at "+n),r},"visit_default-radial":function(e){var r="",n=t.visit(e.at);return n&&(r+=n),r},"visit_extent-keyword":function(e){var r=e.value,n=t.visit(e.at);return n&&(r+=" at "+n),r},"visit_position-keyword":function(e){return e.value},visit_position:function(e){return t.visit(e.value.x)+" "+t.visit(e.value.y)},"visit_%":function(e){return e.value+"%"},visit_em:function(e){return e.value+"em"},visit_px:function(e){return e.value+"px"},visit_calc:function(e){return"calc("+e.value+")"},visit_literal:function(e){return t.visit_color(e.value,e)},visit_hex:function(e){return t.visit_color("#"+e.value,e)},visit_rgb:function(e){return t.visit_color("rgb("+e.value.join(", ")+")",e)},visit_rgba:function(e){return t.visit_color("rgba("+e.value.join(", ")+")",e)},visit_hsl:function(e){return t.visit_color("hsl("+e.value[0]+", "+e.value[1]+"%, "+e.value[2]+"%)",e)},visit_hsla:function(e){return t.visit_color("hsla("+e.value[0]+", "+e.value[1]+"%, "+e.value[2]+"%, "+e.value[3]+")",e)},visit_var:function(e){return t.visit_color("var("+e.value+")",e)},visit_color:function(e,r){var n=e,o=t.visit(r.length);return o&&(n+=" "+o),n},visit_angular:function(e){return e.value+"deg"},visit_directional:function(e){return"to "+e.value},visit_array:function(e){var r="",n=e.length;return e.forEach(function(o,l){r+=t.visit(o),l<n-1&&(r+=", ")}),r},visit_object:function(e){return e.width&&e.height?t.visit(e.width)+" "+t.visit(e.height):""},visit:function(e){if(!e)return"";if(e instanceof Array)return t.visit_array(e);if(typeof e=="object"&&!e.type)return t.visit_object(e);if(e.type){var r=t["visit_"+e.type];if(r)return r(e);throw Error("Missing visitor visit_"+e.type)}else throw Error("Invalid node.")}};return function(e){return t.visit(e)}}();const Xt=T.stringify.bind(T);function dt(t){const e=t.length-1;return t.map((r,n)=>{var d;const o=r.value;let l=C(n/e,3),c="#00000000";switch(r.type){case"rgb":c=v({r:Number(o[0]??0),g:Number(o[1]??0),b:Number(o[2]??0)});break;case"rgba":c=v({r:Number(o[0]??0),g:Number(o[1]??0),b:Number(o[2]??0),a:Number(o[3]??0)});break;case"literal":c=v(r.value);break;case"hex":c=v(r.value);break}switch((d=r.length)==null?void 0:d.type){case"%":l=Number(r.length.value)/100;break}return{offset:l,color:c}})}function gt(t){var r;let e=0;switch((r=t.orientation)==null?void 0:r.type){case"angular":e=Number(t.orientation.value);break}return{type:"linear-gradient",angle:e,stops:dt(t.colorStops)}}function ht(t){var e;return(e=t.orientation)==null||e.map(r=>{switch(r==null?void 0:r.type){case"shape":case"default-radial":case"extent-keyword":default:return null}}),{type:"radial-gradient",stops:dt(t.colorStops)}}function $(t){return t.startsWith("linear-gradient")||t.startsWith("radial-gradient")}function vt(t){return ft(t).map(e=>{switch(e==null?void 0:e.type){case"linear-gradient":return gt(e);case"repeating-linear-gradient":return{...gt(e),repeat:!0};case"radial-gradient":return ht(e);case"repeating-radial-gradient":return{...ht(e),repeat:!0};default:return}}).filter(Boolean)}function P(t){let e;return typeof t=="string"?e={color:t}:e=t,{color:v(e.color)}}function B(t){let e;typeof t=="string"?e={image:t}:e=t;const r=vt(e.image)[0];switch(r==null?void 0:r.type){case"radial-gradient":return{radialGradient:r};case"linear-gradient":return{linearGradient:r}}return{}}function Yt(t){return t}function mt(t){let e;return typeof t=="string"?e={preset:t}:e=t,{preset:e.preset,foregroundColor:f(e.foregroundColor)?void 0:v(e.foregroundColor),backgroundColor:f(e.backgroundColor)?void 0:v(e.backgroundColor)}}function _(t){if(typeof t=="string")return ct(t)?P({color:t}):$(t)?B({image:t}):{image:t};if(f(t.color))if(f(t.image)){if(f(t.preset))return mt(t)}else return $(t.image)?B(t):t;else return P(t);throw new Error("Unknown fill property object")}function pt(t){return typeof t=="string"?{..._(t),fillWithShape:!1}:{..._(t),fillWithShape:!!t.fillWithShape}}function j(){return{color:I,offsetX:0,offsetY:0,blurRadius:1}}function K(t){return{...j(),...w({...t,color:f(t.color)?I:v(t.color)})}}function bt(){return{...j(),scaleX:1,scaleY:1}}function yt(t){return{...bt(),...K(t)}}function Ut(t){return t}function St(t){return w({...t,softEdge:f(t.softEdge)?void 0:t.softEdge,outerShadow:f(t.outerShadow)?void 0:yt(t.outerShadow),innerShadow:f(t.innerShadow)?void 0:K(t.innerShadow)})}function Ct(t){return typeof t=="string"?{..._(t),fillWithShape:!1}:{..._(t),fillWithShape:!!t.fillWithShape}}function wt(t){return typeof t=="string"?{color:v(t)}:{...t,color:f(t.color)?void 0:v(t.color)}}function zt(t){return typeof t=="string"?{color:v(t)}:{...t,color:f(t.color)?I:v(t.color)}}function kt(){return{boxShadow:"none"}}function _t(t){return typeof t=="string"?{paths:[{data:t}]}:Array.isArray(t)?{paths:t.map(e=>typeof e=="string"?{data:e}:e)}:t}function Nt(){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 Dt(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function Gt(){return{...Nt(),...Dt(),...kt(),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 It(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function xt(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function Lt(){return{...It(),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 Et(){return{...xt(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function Vt(){return{...Et(),...Lt(),textStrokeWidth:0,textStrokeColor:"rgb(0, 0, 0)"}}function N(t){return w({...t,color:f(t.color)?void 0:v(t.color),backgroundColor:f(t.backgroundColor)?void 0:v(t.backgroundColor),borderColor:f(t.borderColor)?void 0:v(t.borderColor),outlineColor:f(t.outlineColor)?void 0:v(t.outlineColor),shadowColor:f(t.shadowColor)?void 0:v(t.shadowColor)})}function qt(){return{...Gt(),...Vt()}}function X(t=""){return(Array.isArray(t)?t:[t]).map(r=>typeof r=="string"?{fragments:[{content:r}]}:"content"in r?{fragments:[N(r)]}:"fragments"in r?{...N(r),fragments:r.fragments.map(n=>N(n))}:Array.isArray(r)?{fragments:r.map(n=>typeof n=="string"?{content:n}:N(n))}:{fragments:[]})}function Ot(t){return typeof t=="string"?{content:[{fragments:[{content:t}]}]}:"content"in t?{...t,content:X(t.content)}:{content:X(t)}}function Tt(t){return typeof t=="string"?{src:t}:t}function Y(t){var e;return w({...t,style:f(t.style)?void 0:N(t.style),text:f(t.text)?void 0:Ot(t.text),background:f(t.background)?void 0:pt(t.background),shape:f(t.shape)?void 0:_t(t.shape),fill:f(t.fill)?void 0:_(t.fill),outline:f(t.outline)?void 0:wt(t.outline),foreground:f(t.foreground)?void 0:Ct(t.foreground),shadow:f(t.shadow)?void 0:zt(t.shadow),video:f(t.video)?void 0:Tt(t.video),audio:f(t.audio)?void 0:k(t.audio),effect:f(t.effect)?void 0:St(t.effect),children:(e=t.children)==null?void 0:e.map(r=>Y(r))})}function Jt(t){return Y(t)}a.clearUndef=w,a.defaultColor=I,a.getDefaultElementStyle=Gt,a.getDefaultHighlightStyle=It,a.getDefaultInnerShadow=j,a.getDefaultLayoutStyle=Nt,a.getDefaultListStyleStyle=xt,a.getDefaultOuterShadow=bt,a.getDefaultShadowStyle=kt,a.getDefaultStyle=qt,a.getDefaultTextInlineStyle=Lt,a.getDefaultTextLineStyle=Et,a.getDefaultTextStyle=Vt,a.getDefaultTransformStyle=Dt,a.isColor=ct,a.isGradient=$,a.isNone=f,a.normalizeAudio=k,a.normalizeBackground=pt,a.normalizeColor=v,a.normalizeColorFill=P,a.normalizeDocument=Jt,a.normalizeEffect=St,a.normalizeElement=Y,a.normalizeFill=_,a.normalizeForeground=Ct,a.normalizeGradient=vt,a.normalizeGradientFill=B,a.normalizeImageFill=Yt,a.normalizeInnerShadow=K,a.normalizeOuterShadow=yt,a.normalizeOutline=wt,a.normalizePresetFill=mt,a.normalizeShadow=zt,a.normalizeShape=_t,a.normalizeSoftEdge=Ut,a.normalizeStyle=N,a.normalizeText=Ot,a.normalizeTextContent=X,a.normalizeVideo=Tt,a.parseColor=R,a.parseGradient=ft,a.round=C,a.stringifyGradient=Xt,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
package/dist/index.mjs CHANGED
@@ -8,6 +8,38 @@ function normalizeAudio(audio) {
8
8
  }
9
9
  }
10
10
 
11
+ function isNone(value) {
12
+ return value === null || value === void 0 || value === "none";
13
+ }
14
+ function round(number, digits = 0, base = 10 ** digits) {
15
+ return Math.round(base * number) / base + 0;
16
+ }
17
+ function clearUndef(obj, deep = false) {
18
+ if (typeof obj !== "object" || !obj) {
19
+ return obj;
20
+ }
21
+ if (Array.isArray(obj)) {
22
+ if (deep) {
23
+ return obj.map((v) => clearUndef(v, deep));
24
+ } else {
25
+ return obj;
26
+ }
27
+ }
28
+ const newObj = {};
29
+ for (const key in obj) {
30
+ const value = obj[key];
31
+ if (value === void 0 || value === null) {
32
+ continue;
33
+ }
34
+ if (deep) {
35
+ newObj[key] = clearUndef(value, deep);
36
+ } else {
37
+ newObj[key] = value;
38
+ }
39
+ }
40
+ return newObj;
41
+ }
42
+
11
43
  function parseColor(color) {
12
44
  let input;
13
45
  if (typeof color === "number") {
@@ -22,9 +54,6 @@ function parseColor(color) {
22
54
  }
23
55
  return colord(input);
24
56
  }
25
- function round(number, digits = 0, base = 10 ** digits) {
26
- return Math.round(base * number) / base + 0;
27
- }
28
57
  function roundRgba(rgba) {
29
58
  return {
30
59
  r: round(rgba.r),
@@ -38,6 +67,9 @@ function format(number) {
38
67
  return hex.length < 2 ? `0${hex}` : hex;
39
68
  }
40
69
  const defaultColor = "#000000FF";
70
+ function isColor(value) {
71
+ return parseColor(value).isValid();
72
+ }
41
73
  function normalizeColor(color, orFail = false) {
42
74
  const parsed = parseColor(color);
43
75
  if (!parsed.isValid()) {
@@ -572,16 +604,11 @@ GradientParser.stringify = /* @__PURE__ */ function() {
572
604
  }();
573
605
  const stringifyGradient = GradientParser.stringify.bind(GradientParser);
574
606
 
575
- function parseLinearGradientNode(node) {
576
- let angle = 0;
577
- switch (node.orientation?.type) {
578
- case "angular":
579
- angle = Number(node.orientation.value);
580
- break;
581
- }
582
- const stops = node.colorStops.map((stop) => {
607
+ function parseColorStopNodeList(colorStops) {
608
+ const count = colorStops.length - 1;
609
+ return colorStops.map((stop, index) => {
583
610
  const value = stop.value;
584
- let offset = 0;
611
+ let offset = round(index / count, 3);
585
612
  let color = "#00000000";
586
613
  switch (stop.type) {
587
614
  case "rgb":
@@ -613,14 +640,22 @@ function parseLinearGradientNode(node) {
613
640
  }
614
641
  return { offset, color };
615
642
  });
643
+ }
644
+ function parseLinearGradientNode(node) {
645
+ let angle = 0;
646
+ switch (node.orientation?.type) {
647
+ case "angular":
648
+ angle = Number(node.orientation.value);
649
+ break;
650
+ }
616
651
  return {
617
652
  type: "linear-gradient",
618
653
  angle,
619
- stops
654
+ stops: parseColorStopNodeList(node.colorStops)
620
655
  };
621
656
  }
622
- function parseRadialGradientNode(ast) {
623
- ast.orientation?.map((item) => {
657
+ function parseRadialGradientNode(node) {
658
+ node.orientation?.map((item) => {
624
659
  switch (item?.type) {
625
660
  case "shape":
626
661
  case "default-radial":
@@ -629,45 +664,14 @@ function parseRadialGradientNode(ast) {
629
664
  return null;
630
665
  }
631
666
  });
632
- const stops = ast.colorStops.map((stop) => {
633
- const value = stop.value;
634
- let offset = 0;
635
- let color = "#00000000";
636
- switch (stop.type) {
637
- case "rgb":
638
- color = normalizeColor({
639
- r: Number(value[0] ?? 0),
640
- g: Number(value[1] ?? 0),
641
- b: Number(value[2] ?? 0)
642
- });
643
- break;
644
- case "rgba":
645
- color = normalizeColor({
646
- r: Number(value[0] ?? 0),
647
- g: Number(value[1] ?? 0),
648
- b: Number(value[2] ?? 0),
649
- a: Number(value[3] ?? 0)
650
- });
651
- break;
652
- case "literal":
653
- color = normalizeColor(stop.value);
654
- break;
655
- case "hex":
656
- color = normalizeColor(stop.value);
657
- break;
658
- }
659
- switch (stop.length?.type) {
660
- case "%":
661
- offset = Number(stop.length.value) / 100;
662
- break;
663
- }
664
- return { offset, color };
665
- });
666
667
  return {
667
668
  type: "radial-gradient",
668
- stops
669
+ stops: parseColorStopNodeList(node.colorStops)
669
670
  };
670
671
  }
672
+ function isGradient(cssText) {
673
+ return cssText.startsWith("linear-gradient") || cssText.startsWith("radial-gradient");
674
+ }
671
675
  function normalizeGradient(cssText) {
672
676
  return parseGradient(cssText).map((node) => {
673
677
  switch (node?.type) {
@@ -685,53 +689,92 @@ function normalizeGradient(cssText) {
685
689
  }).filter(Boolean);
686
690
  }
687
691
 
688
- function isNone(value) {
689
- return value === null || value === void 0 || value === "none";
692
+ function normalizeColorFill(fill) {
693
+ let obj;
694
+ if (typeof fill === "string") {
695
+ obj = { color: fill };
696
+ } else {
697
+ obj = fill;
698
+ }
699
+ return {
700
+ color: normalizeColor(obj.color)
701
+ };
690
702
  }
691
- function clearUndef(obj, deep = false) {
692
- if (typeof obj !== "object" || !obj) {
693
- return obj;
703
+
704
+ function normalizeGradientFill(fill) {
705
+ let obj;
706
+ if (typeof fill === "string") {
707
+ obj = { image: fill };
708
+ } else {
709
+ obj = fill;
694
710
  }
695
- if (Array.isArray(obj)) {
696
- if (deep) {
697
- return obj.map((v) => clearUndef(v, deep));
698
- } else {
699
- return obj;
700
- }
711
+ const res = normalizeGradient(obj.image)[0];
712
+ switch (res?.type) {
713
+ case "radial-gradient":
714
+ return {
715
+ radialGradient: res
716
+ };
717
+ case "linear-gradient":
718
+ return {
719
+ linearGradient: res
720
+ };
701
721
  }
702
- const newObj = {};
703
- for (const key in obj) {
704
- const value = obj[key];
705
- if (value === void 0 || value === null) {
706
- continue;
707
- }
708
- if (deep) {
709
- newObj[key] = clearUndef(value, deep);
710
- } else {
711
- newObj[key] = value;
712
- }
722
+ return {};
723
+ }
724
+
725
+ function normalizeImageFill(fill) {
726
+ return fill;
727
+ }
728
+
729
+ function normalizePresetFill(fill) {
730
+ let obj;
731
+ if (typeof fill === "string") {
732
+ obj = { preset: fill };
733
+ } else {
734
+ obj = fill;
713
735
  }
714
- return newObj;
736
+ return {
737
+ preset: obj.preset,
738
+ foregroundColor: isNone(obj.foregroundColor) ? void 0 : normalizeColor(obj.foregroundColor),
739
+ backgroundColor: isNone(obj.backgroundColor) ? void 0 : normalizeColor(obj.backgroundColor)
740
+ };
715
741
  }
716
742
 
717
743
  function normalizeFill(fill) {
718
744
  if (typeof fill === "string") {
719
- return { color: normalizeColor(fill) };
745
+ if (isColor(fill)) {
746
+ return normalizeColorFill({ color: fill });
747
+ } else if (isGradient(fill)) {
748
+ return normalizeGradientFill({ image: fill });
749
+ } else {
750
+ return normalizeImageFill({ image: fill });
751
+ }
720
752
  } else {
721
- return {
722
- ...fill,
723
- color: isNone(fill.color) ? void 0 : normalizeColor(fill.color)
724
- };
753
+ if (!isNone(fill.color)) {
754
+ return normalizeColorFill(fill);
755
+ } else if (!isNone(fill.image)) {
756
+ if (isGradient(fill.image)) {
757
+ return normalizeGradientFill(fill);
758
+ } else {
759
+ return normalizeImageFill(fill);
760
+ }
761
+ } else if (isNone(fill.preset)) {
762
+ return normalizePresetFill(fill);
763
+ }
725
764
  }
765
+ throw new Error("Unknown fill property object");
726
766
  }
727
767
 
728
768
  function normalizeBackground(background) {
729
769
  if (typeof background === "string") {
730
- return { src: background };
770
+ return {
771
+ ...normalizeFill(background),
772
+ fillWithShape: false
773
+ };
731
774
  } else {
732
775
  return {
733
- ...background,
734
- ...normalizeFill(background)
776
+ ...normalizeFill(background),
777
+ fillWithShape: Boolean(background.fillWithShape)
735
778
  };
736
779
  }
737
780
  }
@@ -783,35 +826,15 @@ function normalizeEffect(effect) {
783
826
 
784
827
  function normalizeForeground(foreground) {
785
828
  if (typeof foreground === "string") {
786
- return { src: foreground };
787
- } else {
788
829
  return {
789
- ...foreground,
790
- ...normalizeFill(foreground)
830
+ ...normalizeFill(foreground),
831
+ fillWithShape: false
791
832
  };
792
- }
793
- }
794
-
795
- function normalizeGeometry(geometry) {
796
- if (typeof geometry === "string") {
797
- return {
798
- paths: [
799
- { data: geometry }
800
- ]
801
- };
802
- } else if (Array.isArray(geometry)) {
833
+ } else {
803
834
  return {
804
- paths: geometry.map((data) => {
805
- if (typeof data === "string") {
806
- return {
807
- data
808
- };
809
- }
810
- return data;
811
- })
835
+ ...normalizeFill(foreground),
836
+ fillWithShape: Boolean(foreground.fillWithShape)
812
837
  };
813
- } else {
814
- return geometry;
815
838
  }
816
839
  }
817
840
 
@@ -846,6 +869,29 @@ function getDefaultShadowStyle() {
846
869
  };
847
870
  }
848
871
 
872
+ function normalizeShape(shape) {
873
+ if (typeof shape === "string") {
874
+ return {
875
+ paths: [
876
+ { data: shape }
877
+ ]
878
+ };
879
+ } else if (Array.isArray(shape)) {
880
+ return {
881
+ paths: shape.map((data) => {
882
+ if (typeof data === "string") {
883
+ return {
884
+ data
885
+ };
886
+ }
887
+ return data;
888
+ })
889
+ };
890
+ } else {
891
+ return shape;
892
+ }
893
+ }
894
+
849
895
  function getDefaultLayoutStyle() {
850
896
  return {
851
897
  // box
@@ -1098,7 +1144,7 @@ function normalizeElement(element) {
1098
1144
  style: isNone(element.style) ? void 0 : normalizeStyle(element.style),
1099
1145
  text: isNone(element.text) ? void 0 : normalizeText(element.text),
1100
1146
  background: isNone(element.background) ? void 0 : normalizeBackground(element.background),
1101
- geometry: isNone(element.geometry) ? void 0 : normalizeGeometry(element.geometry),
1147
+ shape: isNone(element.shape) ? void 0 : normalizeShape(element.shape),
1102
1148
  fill: isNone(element.fill) ? void 0 : normalizeFill(element.fill),
1103
1149
  outline: isNone(element.outline) ? void 0 : normalizeOutline(element.outline),
1104
1150
  foreground: isNone(element.foreground) ? void 0 : normalizeForeground(element.foreground),
@@ -1114,4 +1160,4 @@ function normalizeDocument(doc) {
1114
1160
  return normalizeElement(doc);
1115
1161
  }
1116
1162
 
1117
- export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isNone, normalizeAudio, normalizeBackground, normalizeColor, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGeometry, normalizeGradient, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizeShadow, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, stringifyGradient };
1163
+ export { clearUndef, defaultColor, getDefaultElementStyle, getDefaultHighlightStyle, getDefaultInnerShadow, getDefaultLayoutStyle, getDefaultListStyleStyle, getDefaultOuterShadow, getDefaultShadowStyle, getDefaultStyle, getDefaultTextInlineStyle, getDefaultTextLineStyle, getDefaultTextStyle, getDefaultTransformStyle, isColor, isGradient, isNone, normalizeAudio, normalizeBackground, normalizeColor, normalizeColorFill, normalizeDocument, normalizeEffect, normalizeElement, normalizeFill, normalizeForeground, normalizeGradient, normalizeGradientFill, normalizeImageFill, normalizeInnerShadow, normalizeOuterShadow, normalizeOutline, normalizePresetFill, normalizeShadow, normalizeShape, normalizeSoftEdge, normalizeStyle, normalizeText, normalizeTextContent, normalizeVideo, parseColor, parseGradient, round, stringifyGradient };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-idoc",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "Intermediate document for modern codec libs",
7
7
  "author": "wxm",