modern-idoc 0.6.12 → 0.6.13

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 CHANGED
@@ -1167,17 +1167,21 @@ function normalizeTextContent(value) {
1167
1167
  const list = Array.isArray(value) ? value : [value];
1168
1168
  list.forEach((p) => {
1169
1169
  if (typeof p === "string") {
1170
+ addParagraph();
1170
1171
  addFragment(p);
1171
1172
  } else if ("content" in p) {
1172
1173
  const { content, ...pStyle } = p;
1173
- addFragment(content, normalizeStyle(pStyle));
1174
+ addParagraph(normalizeStyle(pStyle));
1175
+ addFragment(content);
1174
1176
  } else if ("fragments" in p) {
1175
- addParagraph(normalizeStyle(p));
1176
- p.fragments.forEach((f) => {
1177
+ const { fragments, ...pStyle } = p;
1178
+ addParagraph(normalizeStyle(pStyle));
1179
+ fragments.forEach((f) => {
1177
1180
  const { content, ...fStyle } = f;
1178
1181
  addFragment(content, normalizeStyle(fStyle));
1179
1182
  });
1180
1183
  } else if (Array.isArray(p)) {
1184
+ addParagraph();
1181
1185
  p.forEach((f) => {
1182
1186
  if (typeof f === "string") {
1183
1187
  addFragment(f);
package/dist/index.d.cts CHANGED
@@ -670,13 +670,14 @@ type TextContent = FlatTextContent | FlatTextContent[];
670
670
  type NormalizedTextContent = ParagraphObject[];
671
671
  interface NormalizedText {
672
672
  content: NormalizedTextContent;
673
+ style?: StyleObject;
673
674
  effects?: StyleObject[];
674
675
  measureDom?: any;
675
676
  fonts?: any;
676
677
  }
677
- type Text = string | TextContent | (NormalizedText & {
678
+ type Text = string | (Omit<NormalizedText, 'content'> & {
678
679
  content: TextContent;
679
- }) | NormalizedText;
680
+ });
680
681
  declare function hasCRLF(content: string): boolean;
681
682
  declare function isCRLF(char: string): boolean;
682
683
  declare function normalizeCRLF(content: string): string;
package/dist/index.d.mts CHANGED
@@ -670,13 +670,14 @@ type TextContent = FlatTextContent | FlatTextContent[];
670
670
  type NormalizedTextContent = ParagraphObject[];
671
671
  interface NormalizedText {
672
672
  content: NormalizedTextContent;
673
+ style?: StyleObject;
673
674
  effects?: StyleObject[];
674
675
  measureDom?: any;
675
676
  fonts?: any;
676
677
  }
677
- type Text = string | TextContent | (NormalizedText & {
678
+ type Text = string | (Omit<NormalizedText, 'content'> & {
678
679
  content: TextContent;
679
- }) | NormalizedText;
680
+ });
680
681
  declare function hasCRLF(content: string): boolean;
681
682
  declare function isCRLF(char: string): boolean;
682
683
  declare function normalizeCRLF(content: string): string;
package/dist/index.d.ts CHANGED
@@ -670,13 +670,14 @@ type TextContent = FlatTextContent | FlatTextContent[];
670
670
  type NormalizedTextContent = ParagraphObject[];
671
671
  interface NormalizedText {
672
672
  content: NormalizedTextContent;
673
+ style?: StyleObject;
673
674
  effects?: StyleObject[];
674
675
  measureDom?: any;
675
676
  fonts?: any;
676
677
  }
677
- type Text = string | TextContent | (NormalizedText & {
678
+ type Text = string | (Omit<NormalizedText, 'content'> & {
678
679
  content: TextContent;
679
- }) | NormalizedText;
680
+ });
680
681
  declare function hasCRLF(content: string): boolean;
681
682
  declare function isCRLF(char: string): boolean;
682
683
  declare function normalizeCRLF(content: string): string;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(o,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(o=typeof globalThis<"u"?globalThis:o||self,E(o.modernIdoc={}))})(this,function(o){"use strict";function E(t){return typeof t=="string"?{src:t}:t}var nn={grad:.9,turn:360,rad:360/(2*Math.PI)},w=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},h=function(t,n,e){return n===void 0&&(n=0),e===void 0&&(e=Math.pow(10,n)),Math.round(e*t)/e+0},S=function(t,n,e){return n===void 0&&(n=0),e===void 0&&(e=1),t>e?e:t>n?t:n},it=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},ot=function(t){return{r:S(t.r,0,255),g:S(t.g,0,255),b:S(t.b,0,255),a:S(t.a)}},B=function(t){return{r:h(t.r),g:h(t.g),b:h(t.b),a:h(t.a,3)}},en=/^#([0-9a-f]{3,8})$/i,A=function(t){var n=t.toString(16);return n.length<2?"0"+n:n},at=function(t){var n=t.r,e=t.g,r=t.b,i=t.a,c=Math.max(n,e,r),u=c-Math.min(n,e,r),l=u?c===n?(e-r)/u:c===e?2+(r-n)/u:4+(n-e)/u:0;return{h:60*(l<0?l+6:l),s:c?u/c*100:0,v:c/255*100,a:i}},ut=function(t){var n=t.h,e=t.s,r=t.v,i=t.a;n=n/360*6,e/=100,r/=100;var c=Math.floor(n),u=r*(1-e),l=r*(1-(n-c)*e),p=r*(1-(1-n+c)*e),b=c%6;return{r:255*[r,l,u,u,p,r][b],g:255*[p,r,r,l,u,u][b],b:255*[u,u,p,r,r,l][b],a:i}},lt=function(t){return{h:it(t.h),s:S(t.s,0,100),l:S(t.l,0,100),a:S(t.a)}},st=function(t){return{h:h(t.h),s:h(t.s),l:h(t.l),a:h(t.a,3)}},ct=function(t){return ut((e=(n=t).s,{h:n.h,s:(e*=((r=n.l)<50?r:100-r)/100)>0?2*e/(r+e)*100:0,v:r+e,a:n.a}));var n,e,r},D=function(t){return{h:(n=at(t)).h,s:(i=(200-(e=n.s))*(r=n.v)/100)>0&&i<200?e*r/100/(i<=100?i:200-i)*100:0,l:i/2,a:n.a};var n,e,r,i},rn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,on=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,an=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,un=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ft={string:[[function(t){var n=en.exec(t);return n?(t=n[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 n=an.exec(t)||un.exec(t);return n?n[2]!==n[4]||n[4]!==n[6]?null:ot({r:Number(n[1])/(n[2]?100/255:1),g:Number(n[3])/(n[4]?100/255:1),b:Number(n[5])/(n[6]?100/255:1),a:n[7]===void 0?1:Number(n[7])/(n[8]?100:1)}):null},"rgb"],[function(t){var n=rn.exec(t)||on.exec(t);if(!n)return null;var e,r,i=lt({h:(e=n[1],r=n[2],r===void 0&&(r="deg"),Number(e)*(nn[r]||1)),s:Number(n[3]),l:Number(n[4]),a:n[5]===void 0?1:Number(n[5])/(n[6]?100:1)});return ct(i)},"hsl"]],object:[[function(t){var n=t.r,e=t.g,r=t.b,i=t.a,c=i===void 0?1:i;return w(n)&&w(e)&&w(r)?ot({r:Number(n),g:Number(e),b:Number(r),a:Number(c)}):null},"rgb"],[function(t){var n=t.h,e=t.s,r=t.l,i=t.a,c=i===void 0?1:i;if(!w(n)||!w(e)||!w(r))return null;var u=lt({h:Number(n),s:Number(e),l:Number(r),a:Number(c)});return ct(u)},"hsl"],[function(t){var n=t.h,e=t.s,r=t.v,i=t.a,c=i===void 0?1:i;if(!w(n)||!w(e)||!w(r))return null;var u=function(l){return{h:it(l.h),s:S(l.s,0,100),v:S(l.v,0,100),a:S(l.a)}}({h:Number(n),s:Number(e),v:Number(r),a:Number(c)});return ut(u)},"hsv"]]},dt=function(t,n){for(var e=0;e<n.length;e++){var r=n[e][0](t);if(r)return[r,n[e][1]]}return[null,void 0]},ln=function(t){return typeof t=="string"?dt(t.trim(),ft.string):typeof t=="object"&&t!==null?dt(t,ft.object):[null,void 0]},K=function(t,n){var e=D(t);return{h:e.h,s:S(e.s+100*n,0,100),l:e.l,a:e.a}},X=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},gt=function(t,n){var e=D(t);return{h:e.h,s:e.s,l:S(e.l+100*n,0,100),a:e.a}},ht=function(){function t(n){this.parsed=ln(n)[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(X(this.rgba),2)},t.prototype.isDark=function(){return X(this.rgba)<.5},t.prototype.isLight=function(){return X(this.rgba)>=.5},t.prototype.toHex=function(){return n=B(this.rgba),e=n.r,r=n.g,i=n.b,u=(c=n.a)<1?A(h(255*c)):"","#"+A(e)+A(r)+A(i)+u;var n,e,r,i,c,u},t.prototype.toRgb=function(){return B(this.rgba)},t.prototype.toRgbString=function(){return n=B(this.rgba),e=n.r,r=n.g,i=n.b,(c=n.a)<1?"rgba("+e+", "+r+", "+i+", "+c+")":"rgb("+e+", "+r+", "+i+")";var n,e,r,i,c},t.prototype.toHsl=function(){return st(D(this.rgba))},t.prototype.toHslString=function(){return n=st(D(this.rgba)),e=n.h,r=n.s,i=n.l,(c=n.a)<1?"hsla("+e+", "+r+"%, "+i+"%, "+c+")":"hsl("+e+", "+r+"%, "+i+"%)";var n,e,r,i,c},t.prototype.toHsv=function(){return n=at(this.rgba),{h:h(n.h),s:h(n.s),v:h(n.v),a:h(n.a,3)};var n},t.prototype.invert=function(){return C({r:255-(n=this.rgba).r,g:255-n.g,b:255-n.b,a:n.a});var n},t.prototype.saturate=function(n){return n===void 0&&(n=.1),C(K(this.rgba,n))},t.prototype.desaturate=function(n){return n===void 0&&(n=.1),C(K(this.rgba,-n))},t.prototype.grayscale=function(){return C(K(this.rgba,-1))},t.prototype.lighten=function(n){return n===void 0&&(n=.1),C(gt(this.rgba,n))},t.prototype.darken=function(n){return n===void 0&&(n=.1),C(gt(this.rgba,-n))},t.prototype.rotate=function(n){return n===void 0&&(n=15),this.hue(this.hue()+n)},t.prototype.alpha=function(n){return typeof n=="number"?C({r:(e=this.rgba).r,g:e.g,b:e.b,a:n}):h(this.rgba.a,3);var e},t.prototype.hue=function(n){var e=D(this.rgba);return typeof n=="number"?C({h:n,s:e.s,l:e.l,a:e.a}):h(e.h)},t.prototype.isEqual=function(n){return this.toHex()===C(n).toHex()},t}(),C=function(t){return t instanceof ht?t:new ht(t)};function d(t){return t==null||t==="none"}function _(t,n=0,e=10**n){return Math.round(e*t)/e+0}function F(t,n=!1){if(typeof t!="object"||!t)return t;if(Array.isArray(t))return n?t.map(r=>F(r,n)):t;const e={};for(const r in t){const i=t[r];i!=null&&(n?e[r]=F(i,n):e[r]=i)}return e}function T(t,n){const e={};return n.forEach(r=>{r in t&&(e[r]=t[r])}),e}function Y(t){let n;return typeof t=="number"?n={r:t>>24&255,g:t>>16&255,b:t>>8&255,a:(t&255)/255}:n=t,C(n)}function sn(t){return{r:_(t.r),g:_(t.g),b:_(t.b),a:_(t.a,3)}}function V(t){const n=t.toString(16);return n.length<2?`0${n}`:n}const G="#000000FF";function vt(t){return Y(t).isValid()}function m(t,n=!1){const e=Y(t);if(!e.isValid()){if(typeof t=="string")return t;const l=`Failed to normalizeColor ${t}`;if(n)throw new Error(l);return console.warn(l),G}const{r,g:i,b:c,a:u}=sn(e.rgba);return`#${V(r)}${V(i)}${V(c)}${V(_(u*255))}`}var x=x||{};x.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 n="";function e(a){const s=new Error(`${n}: ${a}`);throw s.source=n,s}function r(){const a=i();return n.length>0&&e("Invalid input not EOF"),a}function i(){return H(c)}function c(){return u("linear-gradient",t.linearGradient,p)||u("repeating-linear-gradient",t.repeatingLinearGradient,p)||u("radial-gradient",t.radialGradient,M)||u("repeating-radial-gradient",t.repeatingRadialGradient,M)}function u(a,s,f){return l(s,v=>{const N=f();return N&&(g(t.comma)||e("Missing comma before color stops")),{type:a,orientation:N,colorStops:H(Cn)}})}function l(a,s){const f=g(a);if(f){g(t.startCall)||e("Missing (");const v=s(f);return g(t.endCall)||e("Missing )"),v}}function p(){const a=b();if(a)return a;const s=y("position-keyword",t.positionKeywords,1);return s?{type:"directional",value:s.value}:k()}function b(){return y("directional",t.sideOrCorner,1)}function k(){return y("angular",t.angleValue,1)||y("angular",t.radianValue,1)}function M(){let a,s=P(),f;return s&&(a=[],a.push(s),f=n,g(t.comma)&&(s=P(),s?a.push(s):n=f)),a}function P(){let a=bn()||yn();if(a)a.at=nt();else{const s=tt();if(s){a=s;const f=nt();f&&(a.at=f)}else{const f=nt();if(f)a={type:"default-radial",at:f};else{const v=et();v&&(a={type:"default-radial",at:v})}}}return a}function bn(){const a=y("shape",/^(circle)/i,0);return a&&(a.style=tn()||tt()),a}function yn(){const a=y("shape",/^(ellipse)/i,0);return a&&(a.style=et()||W()||tt()),a}function tt(){return y("extent-keyword",t.extentKeywords,1)}function nt(){if(y("position",/^at/,0)){const a=et();return a||e("Missing positioning value"),a}}function et(){const a=Sn();if(a.x||a.y)return{type:"position",value:a}}function Sn(){return{x:W(),y:W()}}function H(a){let s=a();const f=[];if(s)for(f.push(s);g(t.comma);)s=a(),s?f.push(s):e("One extra comma");return f}function Cn(){const a=wn();return a||e("Expected color definition"),a.length=W(),a}function wn(){return _n()||Ln()||En()||kn()||Fn()||Nn()||zn()}function zn(){return y("literal",t.literalColor,0)}function _n(){return y("hex",t.hexColor,1)}function Fn(){return l(t.rgbColor,()=>({type:"rgb",value:H(R)}))}function kn(){return l(t.rgbaColor,()=>({type:"rgba",value:H(R)}))}function Nn(){return l(t.varColor,()=>({type:"var",value:Dn()}))}function En(){return l(t.hslColor,()=>{g(t.percentageValue)&&e("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const s=R();g(t.comma);let f=g(t.percentageValue);const v=f?f[1]:null;g(t.comma),f=g(t.percentageValue);const N=f?f[1]:null;return(!v||!N)&&e("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[s,v,N]}})}function Ln(){return l(t.hslaColor,()=>{const a=R();g(t.comma);let s=g(t.percentageValue);const f=s?s[1]:null;g(t.comma),s=g(t.percentageValue);const v=s?s[1]:null;g(t.comma);const N=R();return(!f||!v)&&e("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[a,f,v,N]}})}function Dn(){return g(t.variableName)[1]}function R(){return g(t.number)[1]}function W(){return y("%",t.percentageValue,1)||Gn()||In()||tn()}function Gn(){return y("position-keyword",t.positionKeywords,1)}function In(){return l(t.calcValue,()=>{let a=1,s=0;for(;a>0&&s<n.length;){const v=n.charAt(s);v==="("?a++:v===")"&&a--,s++}a>0&&e("Missing closing parenthesis in calc() expression");const f=n.substring(0,s-1);return rt(s-1),{type:"calc",value:f}})}function tn(){return y("px",t.pixelValue,1)||y("em",t.emValue,1)}function y(a,s,f){const v=g(s);if(v)return{type:a,value:v[f]}}function g(a){let s,f;return f=/^\s+/.exec(n),f&&rt(f[0].length),s=a.exec(n),s&&rt(s[0].length),s}function rt(a){n=n.substr(a)}return function(a){return n=a.toString().trim(),n.endsWith(";")&&(n=n.slice(0,-1)),r()}}();const mt=x.parse.bind(x);var $=$||{};$.stringify=function(){var t={"visit_linear-gradient":function(n){return t.visit_gradient(n)},"visit_repeating-linear-gradient":function(n){return t.visit_gradient(n)},"visit_radial-gradient":function(n){return t.visit_gradient(n)},"visit_repeating-radial-gradient":function(n){return t.visit_gradient(n)},visit_gradient:function(n){var e=t.visit(n.orientation);return e&&(e+=", "),n.type+"("+e+t.visit(n.colorStops)+")"},visit_shape:function(n){var e=n.value,r=t.visit(n.at),i=t.visit(n.style);return i&&(e+=" "+i),r&&(e+=" at "+r),e},"visit_default-radial":function(n){var e="",r=t.visit(n.at);return r&&(e+=r),e},"visit_extent-keyword":function(n){var e=n.value,r=t.visit(n.at);return r&&(e+=" at "+r),e},"visit_position-keyword":function(n){return n.value},visit_position:function(n){return t.visit(n.value.x)+" "+t.visit(n.value.y)},"visit_%":function(n){return n.value+"%"},visit_em:function(n){return n.value+"em"},visit_px:function(n){return n.value+"px"},visit_calc:function(n){return"calc("+n.value+")"},visit_literal:function(n){return t.visit_color(n.value,n)},visit_hex:function(n){return t.visit_color("#"+n.value,n)},visit_rgb:function(n){return t.visit_color("rgb("+n.value.join(", ")+")",n)},visit_rgba:function(n){return t.visit_color("rgba("+n.value.join(", ")+")",n)},visit_hsl:function(n){return t.visit_color("hsl("+n.value[0]+", "+n.value[1]+"%, "+n.value[2]+"%)",n)},visit_hsla:function(n){return t.visit_color("hsla("+n.value[0]+", "+n.value[1]+"%, "+n.value[2]+"%, "+n.value[3]+")",n)},visit_var:function(n){return t.visit_color("var("+n.value+")",n)},visit_color:function(n,e){var r=n,i=t.visit(e.length);return i&&(r+=" "+i),r},visit_angular:function(n){return n.value+"deg"},visit_directional:function(n){return"to "+n.value},visit_array:function(n){var e="",r=n.length;return n.forEach(function(i,c){e+=t.visit(i),c<r-1&&(e+=", ")}),e},visit_object:function(n){return n.width&&n.height?t.visit(n.width)+" "+t.visit(n.height):""},visit:function(n){if(!n)return"";if(n instanceof Array)return t.visit_array(n);if(typeof n=="object"&&!n.type)return t.visit_object(n);if(n.type){var e=t["visit_"+n.type];if(e)return e(n);throw Error("Missing visitor visit_"+n.type)}else throw Error("Invalid node.")}};return function(n){return t.visit(n)}}();const cn=$.stringify.bind($);function pt(t){const n=t.length-1;return t.map((e,r)=>{var l;const i=e.value;let c=_(r/n,3),u="#00000000";switch(e.type){case"rgb":u=m({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0)});break;case"rgba":u=m({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0),a:Number(i[3]??0)});break;case"literal":u=m(e.value);break;case"hex":u=m(`#${e.value}`);break}switch((l=e.length)==null?void 0:l.type){case"%":c=Number(e.length.value)/100;break}return{offset:c,color:u}})}function bt(t){var e;let n=0;switch((e=t.orientation)==null?void 0:e.type){case"angular":n=Number(t.orientation.value);break}return{type:"linear-gradient",angle:n,stops:pt(t.colorStops)}}function yt(t){var n;return(n=t.orientation)==null||n.map(e=>{switch(e==null?void 0:e.type){case"shape":case"default-radial":case"extent-keyword":default:return null}}),{type:"radial-gradient",stops:pt(t.colorStops)}}function I(t){return t.startsWith("linear-gradient(")||t.startsWith("radial-gradient(")}function St(t){return mt(t).map(n=>{switch(n==null?void 0:n.type){case"linear-gradient":return bt(n);case"repeating-linear-gradient":return{...bt(n),repeat:!0};case"radial-gradient":return yt(n);case"repeating-radial-gradient":return{...yt(n),repeat:!0};default:return}}).filter(Boolean)}function Ct(t){let n;return typeof t=="string"?n={color:t}:n=t,{color:m(n.color)}}function wt(t){let n;if(typeof t=="string"?n={image:t}:n=t,n.image){const{type:e,...r}=St(n.image)[0]??{};switch(e){case"radial-gradient":return{radialGradient:r};case"linear-gradient":return{linearGradient:r}}}return n}function zt(t){let n;return typeof t=="string"?n={image:t}:n=t,n}function _t(t){let n;return typeof t=="string"?n={preset:t}:n=t,{preset:n.preset,foregroundColor:d(n.foregroundColor)?void 0:m(n.foregroundColor),backgroundColor:d(n.backgroundColor)?void 0:m(n.backgroundColor)}}function Ft(t){return!d(t.color)}function kt(t){return typeof t=="string"?vt(t):Ft(t)}function Nt(t){return!d(t.image)&&I(t.image)||!!t.linearGradient||!!t.radialGradient}function Et(t){return typeof t=="string"?I(t):Nt(t)}function Lt(t){return!d(t.image)&&!I(t.image)}function Dt(t){return typeof t=="string"?!I(t):Lt(t)}function Gt(t){return!d(t.preset)}function It(t){return typeof t=="string"?!1:Gt(t)}function z(t){return kt(t)?Ct(t):Et(t)?wt(t):Dt(t)?zt(t):It(t)?_t(t):{}}function Ot(t){return typeof t=="string"?{...z(t)}:{...z(t),...T(t,["fillWithShape"])}}function q(){return{color:G,offsetX:0,offsetY:0,blurRadius:1}}function U(t){return{...q(),...F({...t,color:d(t.color)?G:m(t.color)})}}function Rt(){return{...q(),scaleX:1,scaleY:1}}function At(t){return{...Rt(),...U(t)}}function fn(t){return t}function Tt(t){return F({...t,softEdge:d(t.softEdge)?void 0:t.softEdge,outerShadow:d(t.outerShadow)?void 0:At(t.outerShadow),innerShadow:d(t.innerShadow)?void 0:U(t.innerShadow)})}function Vt(t){return typeof t=="string"?{...z(t)}:{...z(t),...T(t,["fillWithShape"])}}function xt(t){return typeof t=="string"?{...z(t)}:{...z(t),...T(t,["width","style","headEnd","tailEnd"])}}function $t(t){return typeof t=="string"?{color:m(t)}:{...t,color:d(t.color)?G:m(t.color)}}function jt(){return{boxShadow:"none"}}function Mt(t){return typeof t=="string"?t.startsWith("<svg")?{svg:t}:{paths:[{data:t}]}:Array.isArray(t)?{paths:t.map(n=>typeof n=="string"?{data:n}:n)}:t}function Pt(){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 Ht(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function Wt(){return{...Pt(),...Ht(),...jt(),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 Bt(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function Kt(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function Xt(){return{...Bt(),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 Yt(){return{...Kt(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function qt(){return{...Yt(),...Xt(),textStrokeWidth:0,textStrokeColor:"rgb(0, 0, 0)"}}function L(t){return F({...t,color:d(t.color)?void 0:m(t.color),backgroundColor:d(t.backgroundColor)?void 0:m(t.backgroundColor),borderColor:d(t.borderColor)?void 0:m(t.borderColor),outlineColor:d(t.outlineColor)?void 0:m(t.outlineColor),shadowColor:d(t.shadowColor)?void 0:m(t.shadowColor)})}function dn(){return{...Wt(),...qt()}}const Z=/\r\n|\n\r|\n|\r/,gn=new RegExp(`${Z.source}|<br\\/>`,"g"),hn=new RegExp(`^(${Z.source})$`),j=`
2
- `;function vn(t){return Z.test(t)}function J(t){return hn.test(t)}function Ut(t){return t.replace(gn,j)}function Zt(t,n){const e=Array.from(new Set([...Object.keys(t),...Object.keys(n)]));return!e.length||e.every(r=>t[r]===n[r])}function O(t){const n=[];function e(){return n[n.length-1]||r()}function r(u={}){let l=n[n.length-1];return(l==null?void 0:l.fragments.length)===0?(l={...u,fragments:[]},n[n.length-1]=l):(l={...u,fragments:[]},n.push(l)),l}function i(u="",l={}){Array.from(u).forEach(p=>{if(J(p)){const{fragments:b,...k}=e();b.length||b.push({...l,content:j}),r(k)}else{const b=e(),k=b.fragments[b.fragments.length-1];if(k){const{content:M,...P}=k;if(Zt(l,P)){k.content=`${M}${p}`;return}}b.fragments.push({...l,content:p})}})}return(Array.isArray(t)?t:[t]).forEach(u=>{if(typeof u=="string")i(u);else if("content"in u){const{content:l,...p}=u;i(l,L(p))}else"fragments"in u?(r(L(u)),u.fragments.forEach(l=>{const{content:p,...b}=l;i(p,L(b))})):Array.isArray(u)?u.forEach(l=>{if(typeof l=="string")i(l);else{const{content:p,...b}=l;i(p,L(b))}}):console.warn("Failed to parse text content",u)}),e().fragments.length||i(j),n}function Jt(t){return typeof t=="string"?{content:O(t)}:"content"in t?{...t,content:O(t.content)}:{content:O(t)}}function mn(t){return O(t).map(n=>{const e=Ut(n.fragments.flatMap(r=>r.content).join(""));return J(e)?"":e}).join(j)}function Qt(t){return typeof t=="string"?{src:t}:t}function Q(t){var n;return F({...t,style:d(t.style)?void 0:L(t.style),text:d(t.text)?void 0:Jt(t.text),background:d(t.background)?void 0:Ot(t.background),shape:d(t.shape)?void 0:Mt(t.shape),fill:d(t.fill)?void 0:z(t.fill),outline:d(t.outline)?void 0:xt(t.outline),foreground:d(t.foreground)?void 0:Vt(t.foreground),shadow:d(t.shadow)?void 0:$t(t.shadow),video:d(t.video)?void 0:Qt(t.video),audio:d(t.audio)?void 0:E(t.audio),effect:d(t.effect)?void 0:Tt(t.effect),children:(n=t.children)==null?void 0:n.map(e=>Q(e))})}function pn(t){return Q(t)}o.clearUndef=F,o.defaultColor=G,o.getDefaultElementStyle=Wt,o.getDefaultHighlightStyle=Bt,o.getDefaultInnerShadow=q,o.getDefaultLayoutStyle=Pt,o.getDefaultListStyleStyle=Kt,o.getDefaultOuterShadow=Rt,o.getDefaultShadowStyle=jt,o.getDefaultStyle=dn,o.getDefaultTextInlineStyle=Xt,o.getDefaultTextLineStyle=Yt,o.getDefaultTextStyle=qt,o.getDefaultTransformStyle=Ht,o.hasCRLF=vn,o.isCRLF=J,o.isColor=vt,o.isColorFill=kt,o.isColorFillObject=Ft,o.isEqualStyle=Zt,o.isGradient=I,o.isGradientFill=Et,o.isGradientFillObject=Nt,o.isImageFill=Dt,o.isImageFillObject=Lt,o.isNone=d,o.isPresetFill=It,o.isPresetFillObject=Gt,o.normalizeAudio=E,o.normalizeBackground=Ot,o.normalizeCRLF=Ut,o.normalizeColor=m,o.normalizeColorFill=Ct,o.normalizeDocument=pn,o.normalizeEffect=Tt,o.normalizeElement=Q,o.normalizeFill=z,o.normalizeForeground=Vt,o.normalizeGradient=St,o.normalizeGradientFill=wt,o.normalizeImageFill=zt,o.normalizeInnerShadow=U,o.normalizeOuterShadow=At,o.normalizeOutline=xt,o.normalizePresetFill=_t,o.normalizeShadow=$t,o.normalizeShape=Mt,o.normalizeSoftEdge=fn,o.normalizeStyle=L,o.normalizeText=Jt,o.normalizeTextContent=O,o.normalizeVideo=Qt,o.parseColor=Y,o.parseGradient=mt,o.pick=T,o.round=_,o.stringifyGradient=cn,o.textContentToString=mn,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,E){typeof exports=="object"&&typeof module<"u"?E(exports):typeof define=="function"&&define.amd?define(["exports"],E):(o=typeof globalThis<"u"?globalThis:o||self,E(o.modernIdoc={}))})(this,function(o){"use strict";function E(t){return typeof t=="string"?{src:t}:t}var nn={grad:.9,turn:360,rad:360/(2*Math.PI)},w=function(t){return typeof t=="string"?t.length>0:typeof t=="number"},h=function(t,n,e){return n===void 0&&(n=0),e===void 0&&(e=Math.pow(10,n)),Math.round(e*t)/e+0},S=function(t,n,e){return n===void 0&&(n=0),e===void 0&&(e=1),t>e?e:t>n?t:n},it=function(t){return(t=isFinite(t)?t%360:0)>0?t:t+360},ot=function(t){return{r:S(t.r,0,255),g:S(t.g,0,255),b:S(t.b,0,255),a:S(t.a)}},B=function(t){return{r:h(t.r),g:h(t.g),b:h(t.b),a:h(t.a,3)}},en=/^#([0-9a-f]{3,8})$/i,T=function(t){var n=t.toString(16);return n.length<2?"0"+n:n},at=function(t){var n=t.r,e=t.g,r=t.b,i=t.a,c=Math.max(n,e,r),u=c-Math.min(n,e,r),l=u?c===n?(e-r)/u:c===e?2+(r-n)/u:4+(n-e)/u:0;return{h:60*(l<0?l+6:l),s:c?u/c*100:0,v:c/255*100,a:i}},ut=function(t){var n=t.h,e=t.s,r=t.v,i=t.a;n=n/360*6,e/=100,r/=100;var c=Math.floor(n),u=r*(1-e),l=r*(1-(n-c)*e),p=r*(1-(1-n+c)*e),b=c%6;return{r:255*[r,l,u,u,p,r][b],g:255*[p,r,r,l,u,u][b],b:255*[u,u,p,r,r,l][b],a:i}},lt=function(t){return{h:it(t.h),s:S(t.s,0,100),l:S(t.l,0,100),a:S(t.a)}},st=function(t){return{h:h(t.h),s:h(t.s),l:h(t.l),a:h(t.a,3)}},ct=function(t){return ut((e=(n=t).s,{h:n.h,s:(e*=((r=n.l)<50?r:100-r)/100)>0?2*e/(r+e)*100:0,v:r+e,a:n.a}));var n,e,r},G=function(t){return{h:(n=at(t)).h,s:(i=(200-(e=n.s))*(r=n.v)/100)>0&&i<200?e*r/100/(i<=100?i:200-i)*100:0,l:i/2,a:n.a};var n,e,r,i},rn=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,on=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,an=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,un=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ft={string:[[function(t){var n=en.exec(t);return n?(t=n[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 n=an.exec(t)||un.exec(t);return n?n[2]!==n[4]||n[4]!==n[6]?null:ot({r:Number(n[1])/(n[2]?100/255:1),g:Number(n[3])/(n[4]?100/255:1),b:Number(n[5])/(n[6]?100/255:1),a:n[7]===void 0?1:Number(n[7])/(n[8]?100:1)}):null},"rgb"],[function(t){var n=rn.exec(t)||on.exec(t);if(!n)return null;var e,r,i=lt({h:(e=n[1],r=n[2],r===void 0&&(r="deg"),Number(e)*(nn[r]||1)),s:Number(n[3]),l:Number(n[4]),a:n[5]===void 0?1:Number(n[5])/(n[6]?100:1)});return ct(i)},"hsl"]],object:[[function(t){var n=t.r,e=t.g,r=t.b,i=t.a,c=i===void 0?1:i;return w(n)&&w(e)&&w(r)?ot({r:Number(n),g:Number(e),b:Number(r),a:Number(c)}):null},"rgb"],[function(t){var n=t.h,e=t.s,r=t.l,i=t.a,c=i===void 0?1:i;if(!w(n)||!w(e)||!w(r))return null;var u=lt({h:Number(n),s:Number(e),l:Number(r),a:Number(c)});return ct(u)},"hsl"],[function(t){var n=t.h,e=t.s,r=t.v,i=t.a,c=i===void 0?1:i;if(!w(n)||!w(e)||!w(r))return null;var u=function(l){return{h:it(l.h),s:S(l.s,0,100),v:S(l.v,0,100),a:S(l.a)}}({h:Number(n),s:Number(e),v:Number(r),a:Number(c)});return ut(u)},"hsv"]]},dt=function(t,n){for(var e=0;e<n.length;e++){var r=n[e][0](t);if(r)return[r,n[e][1]]}return[null,void 0]},ln=function(t){return typeof t=="string"?dt(t.trim(),ft.string):typeof t=="object"&&t!==null?dt(t,ft.object):[null,void 0]},K=function(t,n){var e=G(t);return{h:e.h,s:S(e.s+100*n,0,100),l:e.l,a:e.a}},X=function(t){return(299*t.r+587*t.g+114*t.b)/1e3/255},gt=function(t,n){var e=G(t);return{h:e.h,s:e.s,l:S(e.l+100*n,0,100),a:e.a}},ht=function(){function t(n){this.parsed=ln(n)[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(X(this.rgba),2)},t.prototype.isDark=function(){return X(this.rgba)<.5},t.prototype.isLight=function(){return X(this.rgba)>=.5},t.prototype.toHex=function(){return n=B(this.rgba),e=n.r,r=n.g,i=n.b,u=(c=n.a)<1?T(h(255*c)):"","#"+T(e)+T(r)+T(i)+u;var n,e,r,i,c,u},t.prototype.toRgb=function(){return B(this.rgba)},t.prototype.toRgbString=function(){return n=B(this.rgba),e=n.r,r=n.g,i=n.b,(c=n.a)<1?"rgba("+e+", "+r+", "+i+", "+c+")":"rgb("+e+", "+r+", "+i+")";var n,e,r,i,c},t.prototype.toHsl=function(){return st(G(this.rgba))},t.prototype.toHslString=function(){return n=st(G(this.rgba)),e=n.h,r=n.s,i=n.l,(c=n.a)<1?"hsla("+e+", "+r+"%, "+i+"%, "+c+")":"hsl("+e+", "+r+"%, "+i+"%)";var n,e,r,i,c},t.prototype.toHsv=function(){return n=at(this.rgba),{h:h(n.h),s:h(n.s),v:h(n.v),a:h(n.a,3)};var n},t.prototype.invert=function(){return C({r:255-(n=this.rgba).r,g:255-n.g,b:255-n.b,a:n.a});var n},t.prototype.saturate=function(n){return n===void 0&&(n=.1),C(K(this.rgba,n))},t.prototype.desaturate=function(n){return n===void 0&&(n=.1),C(K(this.rgba,-n))},t.prototype.grayscale=function(){return C(K(this.rgba,-1))},t.prototype.lighten=function(n){return n===void 0&&(n=.1),C(gt(this.rgba,n))},t.prototype.darken=function(n){return n===void 0&&(n=.1),C(gt(this.rgba,-n))},t.prototype.rotate=function(n){return n===void 0&&(n=15),this.hue(this.hue()+n)},t.prototype.alpha=function(n){return typeof n=="number"?C({r:(e=this.rgba).r,g:e.g,b:e.b,a:n}):h(this.rgba.a,3);var e},t.prototype.hue=function(n){var e=G(this.rgba);return typeof n=="number"?C({h:n,s:e.s,l:e.l,a:e.a}):h(e.h)},t.prototype.isEqual=function(n){return this.toHex()===C(n).toHex()},t}(),C=function(t){return t instanceof ht?t:new ht(t)};function d(t){return t==null||t==="none"}function F(t,n=0,e=10**n){return Math.round(e*t)/e+0}function k(t,n=!1){if(typeof t!="object"||!t)return t;if(Array.isArray(t))return n?t.map(r=>k(r,n)):t;const e={};for(const r in t){const i=t[r];i!=null&&(n?e[r]=k(i,n):e[r]=i)}return e}function V(t,n){const e={};return n.forEach(r=>{r in t&&(e[r]=t[r])}),e}function Y(t){let n;return typeof t=="number"?n={r:t>>24&255,g:t>>16&255,b:t>>8&255,a:(t&255)/255}:n=t,C(n)}function sn(t){return{r:F(t.r),g:F(t.g),b:F(t.b),a:F(t.a,3)}}function x(t){const n=t.toString(16);return n.length<2?`0${n}`:n}const I="#000000FF";function vt(t){return Y(t).isValid()}function m(t,n=!1){const e=Y(t);if(!e.isValid()){if(typeof t=="string")return t;const l=`Failed to normalizeColor ${t}`;if(n)throw new Error(l);return console.warn(l),I}const{r,g:i,b:c,a:u}=sn(e.rgba);return`#${x(r)}${x(i)}${x(c)}${x(F(u*255))}`}var $=$||{};$.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 n="";function e(a){const s=new Error(`${n}: ${a}`);throw s.source=n,s}function r(){const a=i();return n.length>0&&e("Invalid input not EOF"),a}function i(){return H(c)}function c(){return u("linear-gradient",t.linearGradient,p)||u("repeating-linear-gradient",t.repeatingLinearGradient,p)||u("radial-gradient",t.radialGradient,D)||u("repeating-radial-gradient",t.repeatingRadialGradient,D)}function u(a,s,f){return l(s,v=>{const N=f();return N&&(g(t.comma)||e("Missing comma before color stops")),{type:a,orientation:N,colorStops:H(Cn)}})}function l(a,s){const f=g(a);if(f){g(t.startCall)||e("Missing (");const v=s(f);return g(t.endCall)||e("Missing )"),v}}function p(){const a=b();if(a)return a;const s=y("position-keyword",t.positionKeywords,1);return s?{type:"directional",value:s.value}:z()}function b(){return y("directional",t.sideOrCorner,1)}function z(){return y("angular",t.angleValue,1)||y("angular",t.radianValue,1)}function D(){let a,s=P(),f;return s&&(a=[],a.push(s),f=n,g(t.comma)&&(s=P(),s?a.push(s):n=f)),a}function P(){let a=bn()||yn();if(a)a.at=nt();else{const s=tt();if(s){a=s;const f=nt();f&&(a.at=f)}else{const f=nt();if(f)a={type:"default-radial",at:f};else{const v=et();v&&(a={type:"default-radial",at:v})}}}return a}function bn(){const a=y("shape",/^(circle)/i,0);return a&&(a.style=tn()||tt()),a}function yn(){const a=y("shape",/^(ellipse)/i,0);return a&&(a.style=et()||W()||tt()),a}function tt(){return y("extent-keyword",t.extentKeywords,1)}function nt(){if(y("position",/^at/,0)){const a=et();return a||e("Missing positioning value"),a}}function et(){const a=Sn();if(a.x||a.y)return{type:"position",value:a}}function Sn(){return{x:W(),y:W()}}function H(a){let s=a();const f=[];if(s)for(f.push(s);g(t.comma);)s=a(),s?f.push(s):e("One extra comma");return f}function Cn(){const a=wn();return a||e("Expected color definition"),a.length=W(),a}function wn(){return _n()||Ln()||En()||kn()||Fn()||Nn()||zn()}function zn(){return y("literal",t.literalColor,0)}function _n(){return y("hex",t.hexColor,1)}function Fn(){return l(t.rgbColor,()=>({type:"rgb",value:H(A)}))}function kn(){return l(t.rgbaColor,()=>({type:"rgba",value:H(A)}))}function Nn(){return l(t.varColor,()=>({type:"var",value:Dn()}))}function En(){return l(t.hslColor,()=>{g(t.percentageValue)&&e("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const s=A();g(t.comma);let f=g(t.percentageValue);const v=f?f[1]:null;g(t.comma),f=g(t.percentageValue);const N=f?f[1]:null;return(!v||!N)&&e("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[s,v,N]}})}function Ln(){return l(t.hslaColor,()=>{const a=A();g(t.comma);let s=g(t.percentageValue);const f=s?s[1]:null;g(t.comma),s=g(t.percentageValue);const v=s?s[1]:null;g(t.comma);const N=A();return(!f||!v)&&e("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[a,f,v,N]}})}function Dn(){return g(t.variableName)[1]}function A(){return g(t.number)[1]}function W(){return y("%",t.percentageValue,1)||Gn()||In()||tn()}function Gn(){return y("position-keyword",t.positionKeywords,1)}function In(){return l(t.calcValue,()=>{let a=1,s=0;for(;a>0&&s<n.length;){const v=n.charAt(s);v==="("?a++:v===")"&&a--,s++}a>0&&e("Missing closing parenthesis in calc() expression");const f=n.substring(0,s-1);return rt(s-1),{type:"calc",value:f}})}function tn(){return y("px",t.pixelValue,1)||y("em",t.emValue,1)}function y(a,s,f){const v=g(s);if(v)return{type:a,value:v[f]}}function g(a){let s,f;return f=/^\s+/.exec(n),f&&rt(f[0].length),s=a.exec(n),s&&rt(s[0].length),s}function rt(a){n=n.substr(a)}return function(a){return n=a.toString().trim(),n.endsWith(";")&&(n=n.slice(0,-1)),r()}}();const mt=$.parse.bind($);var j=j||{};j.stringify=function(){var t={"visit_linear-gradient":function(n){return t.visit_gradient(n)},"visit_repeating-linear-gradient":function(n){return t.visit_gradient(n)},"visit_radial-gradient":function(n){return t.visit_gradient(n)},"visit_repeating-radial-gradient":function(n){return t.visit_gradient(n)},visit_gradient:function(n){var e=t.visit(n.orientation);return e&&(e+=", "),n.type+"("+e+t.visit(n.colorStops)+")"},visit_shape:function(n){var e=n.value,r=t.visit(n.at),i=t.visit(n.style);return i&&(e+=" "+i),r&&(e+=" at "+r),e},"visit_default-radial":function(n){var e="",r=t.visit(n.at);return r&&(e+=r),e},"visit_extent-keyword":function(n){var e=n.value,r=t.visit(n.at);return r&&(e+=" at "+r),e},"visit_position-keyword":function(n){return n.value},visit_position:function(n){return t.visit(n.value.x)+" "+t.visit(n.value.y)},"visit_%":function(n){return n.value+"%"},visit_em:function(n){return n.value+"em"},visit_px:function(n){return n.value+"px"},visit_calc:function(n){return"calc("+n.value+")"},visit_literal:function(n){return t.visit_color(n.value,n)},visit_hex:function(n){return t.visit_color("#"+n.value,n)},visit_rgb:function(n){return t.visit_color("rgb("+n.value.join(", ")+")",n)},visit_rgba:function(n){return t.visit_color("rgba("+n.value.join(", ")+")",n)},visit_hsl:function(n){return t.visit_color("hsl("+n.value[0]+", "+n.value[1]+"%, "+n.value[2]+"%)",n)},visit_hsla:function(n){return t.visit_color("hsla("+n.value[0]+", "+n.value[1]+"%, "+n.value[2]+"%, "+n.value[3]+")",n)},visit_var:function(n){return t.visit_color("var("+n.value+")",n)},visit_color:function(n,e){var r=n,i=t.visit(e.length);return i&&(r+=" "+i),r},visit_angular:function(n){return n.value+"deg"},visit_directional:function(n){return"to "+n.value},visit_array:function(n){var e="",r=n.length;return n.forEach(function(i,c){e+=t.visit(i),c<r-1&&(e+=", ")}),e},visit_object:function(n){return n.width&&n.height?t.visit(n.width)+" "+t.visit(n.height):""},visit:function(n){if(!n)return"";if(n instanceof Array)return t.visit_array(n);if(typeof n=="object"&&!n.type)return t.visit_object(n);if(n.type){var e=t["visit_"+n.type];if(e)return e(n);throw Error("Missing visitor visit_"+n.type)}else throw Error("Invalid node.")}};return function(n){return t.visit(n)}}();const cn=j.stringify.bind(j);function pt(t){const n=t.length-1;return t.map((e,r)=>{var l;const i=e.value;let c=F(r/n,3),u="#00000000";switch(e.type){case"rgb":u=m({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0)});break;case"rgba":u=m({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0),a:Number(i[3]??0)});break;case"literal":u=m(e.value);break;case"hex":u=m(`#${e.value}`);break}switch((l=e.length)==null?void 0:l.type){case"%":c=Number(e.length.value)/100;break}return{offset:c,color:u}})}function bt(t){var e;let n=0;switch((e=t.orientation)==null?void 0:e.type){case"angular":n=Number(t.orientation.value);break}return{type:"linear-gradient",angle:n,stops:pt(t.colorStops)}}function yt(t){var n;return(n=t.orientation)==null||n.map(e=>{switch(e==null?void 0:e.type){case"shape":case"default-radial":case"extent-keyword":default:return null}}),{type:"radial-gradient",stops:pt(t.colorStops)}}function O(t){return t.startsWith("linear-gradient(")||t.startsWith("radial-gradient(")}function St(t){return mt(t).map(n=>{switch(n==null?void 0:n.type){case"linear-gradient":return bt(n);case"repeating-linear-gradient":return{...bt(n),repeat:!0};case"radial-gradient":return yt(n);case"repeating-radial-gradient":return{...yt(n),repeat:!0};default:return}}).filter(Boolean)}function Ct(t){let n;return typeof t=="string"?n={color:t}:n=t,{color:m(n.color)}}function wt(t){let n;if(typeof t=="string"?n={image:t}:n=t,n.image){const{type:e,...r}=St(n.image)[0]??{};switch(e){case"radial-gradient":return{radialGradient:r};case"linear-gradient":return{linearGradient:r}}}return n}function zt(t){let n;return typeof t=="string"?n={image:t}:n=t,n}function _t(t){let n;return typeof t=="string"?n={preset:t}:n=t,{preset:n.preset,foregroundColor:d(n.foregroundColor)?void 0:m(n.foregroundColor),backgroundColor:d(n.backgroundColor)?void 0:m(n.backgroundColor)}}function Ft(t){return!d(t.color)}function kt(t){return typeof t=="string"?vt(t):Ft(t)}function Nt(t){return!d(t.image)&&O(t.image)||!!t.linearGradient||!!t.radialGradient}function Et(t){return typeof t=="string"?O(t):Nt(t)}function Lt(t){return!d(t.image)&&!O(t.image)}function Dt(t){return typeof t=="string"?!O(t):Lt(t)}function Gt(t){return!d(t.preset)}function It(t){return typeof t=="string"?!1:Gt(t)}function _(t){return kt(t)?Ct(t):Et(t)?wt(t):Dt(t)?zt(t):It(t)?_t(t):{}}function Ot(t){return typeof t=="string"?{..._(t)}:{..._(t),...V(t,["fillWithShape"])}}function q(){return{color:I,offsetX:0,offsetY:0,blurRadius:1}}function U(t){return{...q(),...k({...t,color:d(t.color)?I:m(t.color)})}}function Rt(){return{...q(),scaleX:1,scaleY:1}}function At(t){return{...Rt(),...U(t)}}function fn(t){return t}function Tt(t){return k({...t,softEdge:d(t.softEdge)?void 0:t.softEdge,outerShadow:d(t.outerShadow)?void 0:At(t.outerShadow),innerShadow:d(t.innerShadow)?void 0:U(t.innerShadow)})}function Vt(t){return typeof t=="string"?{..._(t)}:{..._(t),...V(t,["fillWithShape"])}}function xt(t){return typeof t=="string"?{..._(t)}:{..._(t),...V(t,["width","style","headEnd","tailEnd"])}}function $t(t){return typeof t=="string"?{color:m(t)}:{...t,color:d(t.color)?I:m(t.color)}}function jt(){return{boxShadow:"none"}}function Mt(t){return typeof t=="string"?t.startsWith("<svg")?{svg:t}:{paths:[{data:t}]}:Array.isArray(t)?{paths:t.map(n=>typeof n=="string"?{data:n}:n)}:t}function Pt(){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 Ht(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function Wt(){return{...Pt(),...Ht(),...jt(),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 Bt(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function Kt(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function Xt(){return{...Bt(),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 Yt(){return{...Kt(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function qt(){return{...Yt(),...Xt(),textStrokeWidth:0,textStrokeColor:"rgb(0, 0, 0)"}}function L(t){return k({...t,color:d(t.color)?void 0:m(t.color),backgroundColor:d(t.backgroundColor)?void 0:m(t.backgroundColor),borderColor:d(t.borderColor)?void 0:m(t.borderColor),outlineColor:d(t.outlineColor)?void 0:m(t.outlineColor),shadowColor:d(t.shadowColor)?void 0:m(t.shadowColor)})}function dn(){return{...Wt(),...qt()}}const Z=/\r\n|\n\r|\n|\r/,gn=new RegExp(`${Z.source}|<br\\/>`,"g"),hn=new RegExp(`^(${Z.source})$`),M=`
2
+ `;function vn(t){return Z.test(t)}function J(t){return hn.test(t)}function Ut(t){return t.replace(gn,M)}function Zt(t,n){const e=Array.from(new Set([...Object.keys(t),...Object.keys(n)]));return!e.length||e.every(r=>t[r]===n[r])}function R(t){const n=[];function e(){return n[n.length-1]||r()}function r(u={}){let l=n[n.length-1];return(l==null?void 0:l.fragments.length)===0?(l={...u,fragments:[]},n[n.length-1]=l):(l={...u,fragments:[]},n.push(l)),l}function i(u="",l={}){Array.from(u).forEach(p=>{if(J(p)){const{fragments:b,...z}=e();b.length||b.push({...l,content:M}),r(z)}else{const b=e(),z=b.fragments[b.fragments.length-1];if(z){const{content:D,...P}=z;if(Zt(l,P)){z.content=`${D}${p}`;return}}b.fragments.push({...l,content:p})}})}return(Array.isArray(t)?t:[t]).forEach(u=>{if(typeof u=="string")r(),i(u);else if("content"in u){const{content:l,...p}=u;r(L(p)),i(l)}else if("fragments"in u){const{fragments:l,...p}=u;r(L(p)),l.forEach(b=>{const{content:z,...D}=b;i(z,L(D))})}else Array.isArray(u)?(r(),u.forEach(l=>{if(typeof l=="string")i(l);else{const{content:p,...b}=l;i(p,L(b))}})):console.warn("Failed to parse text content",u)}),e().fragments.length||i(M),n}function Jt(t){return typeof t=="string"?{content:R(t)}:"content"in t?{...t,content:R(t.content)}:{content:R(t)}}function mn(t){return R(t).map(n=>{const e=Ut(n.fragments.flatMap(r=>r.content).join(""));return J(e)?"":e}).join(M)}function Qt(t){return typeof t=="string"?{src:t}:t}function Q(t){var n;return k({...t,style:d(t.style)?void 0:L(t.style),text:d(t.text)?void 0:Jt(t.text),background:d(t.background)?void 0:Ot(t.background),shape:d(t.shape)?void 0:Mt(t.shape),fill:d(t.fill)?void 0:_(t.fill),outline:d(t.outline)?void 0:xt(t.outline),foreground:d(t.foreground)?void 0:Vt(t.foreground),shadow:d(t.shadow)?void 0:$t(t.shadow),video:d(t.video)?void 0:Qt(t.video),audio:d(t.audio)?void 0:E(t.audio),effect:d(t.effect)?void 0:Tt(t.effect),children:(n=t.children)==null?void 0:n.map(e=>Q(e))})}function pn(t){return Q(t)}o.clearUndef=k,o.defaultColor=I,o.getDefaultElementStyle=Wt,o.getDefaultHighlightStyle=Bt,o.getDefaultInnerShadow=q,o.getDefaultLayoutStyle=Pt,o.getDefaultListStyleStyle=Kt,o.getDefaultOuterShadow=Rt,o.getDefaultShadowStyle=jt,o.getDefaultStyle=dn,o.getDefaultTextInlineStyle=Xt,o.getDefaultTextLineStyle=Yt,o.getDefaultTextStyle=qt,o.getDefaultTransformStyle=Ht,o.hasCRLF=vn,o.isCRLF=J,o.isColor=vt,o.isColorFill=kt,o.isColorFillObject=Ft,o.isEqualStyle=Zt,o.isGradient=O,o.isGradientFill=Et,o.isGradientFillObject=Nt,o.isImageFill=Dt,o.isImageFillObject=Lt,o.isNone=d,o.isPresetFill=It,o.isPresetFillObject=Gt,o.normalizeAudio=E,o.normalizeBackground=Ot,o.normalizeCRLF=Ut,o.normalizeColor=m,o.normalizeColorFill=Ct,o.normalizeDocument=pn,o.normalizeEffect=Tt,o.normalizeElement=Q,o.normalizeFill=_,o.normalizeForeground=Vt,o.normalizeGradient=St,o.normalizeGradientFill=wt,o.normalizeImageFill=zt,o.normalizeInnerShadow=U,o.normalizeOuterShadow=At,o.normalizeOutline=xt,o.normalizePresetFill=_t,o.normalizeShadow=$t,o.normalizeShape=Mt,o.normalizeSoftEdge=fn,o.normalizeStyle=L,o.normalizeText=Jt,o.normalizeTextContent=R,o.normalizeVideo=Qt,o.parseColor=Y,o.parseGradient=mt,o.pick=V,o.round=F,o.stringifyGradient=cn,o.textContentToString=mn,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/dist/index.mjs CHANGED
@@ -1165,17 +1165,21 @@ function normalizeTextContent(value) {
1165
1165
  const list = Array.isArray(value) ? value : [value];
1166
1166
  list.forEach((p) => {
1167
1167
  if (typeof p === "string") {
1168
+ addParagraph();
1168
1169
  addFragment(p);
1169
1170
  } else if ("content" in p) {
1170
1171
  const { content, ...pStyle } = p;
1171
- addFragment(content, normalizeStyle(pStyle));
1172
+ addParagraph(normalizeStyle(pStyle));
1173
+ addFragment(content);
1172
1174
  } else if ("fragments" in p) {
1173
- addParagraph(normalizeStyle(p));
1174
- p.fragments.forEach((f) => {
1175
+ const { fragments, ...pStyle } = p;
1176
+ addParagraph(normalizeStyle(pStyle));
1177
+ fragments.forEach((f) => {
1175
1178
  const { content, ...fStyle } = f;
1176
1179
  addFragment(content, normalizeStyle(fStyle));
1177
1180
  });
1178
1181
  } else if (Array.isArray(p)) {
1182
+ addParagraph();
1179
1183
  p.forEach((f) => {
1180
1184
  if (typeof f === "string") {
1181
1185
  addFragment(f);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-idoc",
3
3
  "type": "module",
4
- "version": "0.6.12",
4
+ "version": "0.6.13",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "Intermediate document for modern codec libs",
7
7
  "author": "wxm",