@ones-editor/editor 2.1.7-beta.37 → 2.1.7-beta.38

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
@@ -10414,9 +10414,9 @@ var __publicField = (obj, key, value) => {
10414
10414
  const fontStyle = style2.getPropertyValue("font-style");
10415
10415
  const fontVariant = style2.getPropertyValue("font-variant");
10416
10416
  const fontWeight = style2.getPropertyValue("font-weight");
10417
- const fontSize = style2.getPropertyValue("font-size");
10417
+ const fontSize2 = style2.getPropertyValue("font-size");
10418
10418
  const fontFamily = style2.getPropertyValue("font-family");
10419
- elementFont = `${fontStyle} ${fontVariant} ${fontWeight} ${fontSize} ${fontFamily}`.replace(/ +/g, " ").trim();
10419
+ elementFont = `${fontStyle} ${fontVariant} ${fontWeight} ${fontSize2} ${fontFamily}`.replace(/ +/g, " ").trim();
10420
10420
  return elementFont;
10421
10421
  }
10422
10422
  function getTextWidth(text2, font) {
@@ -10839,13 +10839,13 @@ var __publicField = (obj, key, value) => {
10839
10839
  function replaceAllCaseInsensitive(str, find, replace) {
10840
10840
  return str.replace(new RegExp(escapeRegExp(find), "gi"), replace);
10841
10841
  }
10842
- function overflowText(text2, fontSize, maxwidth) {
10842
+ function overflowText(text2, fontSize2, maxwidth) {
10843
10843
  const canvas = document.createElement("canvas");
10844
10844
  const ctx = canvas.getContext("2d");
10845
10845
  if (!ctx) {
10846
10846
  return null;
10847
10847
  }
10848
- ctx.font = String(fontSize);
10848
+ ctx.font = String(fontSize2);
10849
10849
  const metrics = ctx.measureText(text2);
10850
10850
  if (metrics.width > maxwidth) {
10851
10851
  let i = 0;
@@ -14326,8 +14326,8 @@ var __publicField = (obj, key, value) => {
14326
14326
  } else if (lineHeightStyle.endsWith("pt")) {
14327
14327
  lineHeight = parseFloat(lineHeightStyle) * 4 / 3;
14328
14328
  } else if (lineHeightStyle === "em") {
14329
- const fontSize = parseFloat(style2.getPropertyValue("font-size"));
14330
- lineHeight = fontSize * parseFloat(lineHeightStyle);
14329
+ const fontSize2 = parseFloat(style2.getPropertyValue("font-size"));
14330
+ lineHeight = fontSize2 * parseFloat(lineHeightStyle);
14331
14331
  } else {
14332
14332
  lineHeight = parseFloat(style2.getPropertyValue("font-size")) * 1.2;
14333
14333
  }
@@ -25169,6 +25169,9 @@ var __publicField = (obj, key, value) => {
25169
25169
  if (key === "inline-style-background-color") {
25170
25170
  newStyles.backgroundColor = value;
25171
25171
  }
25172
+ if (key === "inline-style-font-size") {
25173
+ newStyles.fontSize = value;
25174
+ }
25172
25175
  }
25173
25176
  });
25174
25177
  return { classes, attributes: newAttributes, styles: newStyles };
@@ -72297,6 +72300,104 @@ ${codeText}
72297
72300
  }
72298
72301
  }
72299
72302
  }
72303
+ function getColorValue(html, tagPrefix) {
72304
+ const colorIndex = html.indexOf(tagPrefix);
72305
+ if (colorIndex < 0) {
72306
+ return -1;
72307
+ }
72308
+ const endIndex = html.indexOf(">", colorIndex);
72309
+ if (endIndex < 0) {
72310
+ return -1;
72311
+ }
72312
+ const colorValue = html.substring(colorIndex + tagPrefix.length, endIndex);
72313
+ return parseInt(colorValue, 10);
72314
+ }
72315
+ function getColorIndexFromHtml(html, tagPrefix) {
72316
+ const startIndex = getColorValue(html, `<${tagPrefix}`);
72317
+ if (startIndex !== -1) {
72318
+ return {
72319
+ start: true,
72320
+ color: startIndex
72321
+ };
72322
+ }
72323
+ const endIndex = getColorValue(html, `</${tagPrefix}`);
72324
+ if (endIndex !== -1) {
72325
+ return {
72326
+ start: false,
72327
+ color: endIndex
72328
+ };
72329
+ }
72330
+ return {
72331
+ start: false,
72332
+ color: -1
72333
+ };
72334
+ }
72335
+ function applyColorTagToText(htm, attributes) {
72336
+ const html = htm.toLowerCase();
72337
+ {
72338
+ const { start, color } = getColorIndexFromHtml(html, "color-");
72339
+ if (color !== -1) {
72340
+ if (start) {
72341
+ attributes[`style-color-${color}`] = true;
72342
+ } else {
72343
+ delete attributes[`style-color-${color}`];
72344
+ }
72345
+ }
72346
+ }
72347
+ {
72348
+ const { start, color } = getColorIndexFromHtml(html, "background-color-");
72349
+ if (color !== -1) {
72350
+ if (start) {
72351
+ attributes[`style-bg-color-${color}`] = true;
72352
+ } else {
72353
+ delete attributes[`style-bg-color-${color}`];
72354
+ }
72355
+ }
72356
+ }
72357
+ }
72358
+ function getFontSizeValue(html, tagPrefix) {
72359
+ const sizeIndex = html.indexOf(tagPrefix);
72360
+ if (sizeIndex < 0) {
72361
+ return -1;
72362
+ }
72363
+ const endIndex = html.indexOf(">", sizeIndex);
72364
+ if (endIndex < 0) {
72365
+ return -1;
72366
+ }
72367
+ const sizeValue = html.substring(sizeIndex + tagPrefix.length, endIndex);
72368
+ return parseInt(sizeValue, 10);
72369
+ }
72370
+ function getFontSizeIndexFromHtml(html, tagPrefix) {
72371
+ const startIndex = getFontSizeValue(html, `<${tagPrefix}`);
72372
+ if (startIndex !== -1) {
72373
+ return {
72374
+ start: true,
72375
+ size: startIndex
72376
+ };
72377
+ }
72378
+ const endIndex = getFontSizeValue(html, `</${tagPrefix}`);
72379
+ if (endIndex !== -1) {
72380
+ return {
72381
+ start: false,
72382
+ size: endIndex
72383
+ };
72384
+ }
72385
+ return {
72386
+ start: false,
72387
+ size: -1
72388
+ };
72389
+ }
72390
+ function applyFontSizeTagToText(htm, attributes) {
72391
+ const html = htm.toLowerCase();
72392
+ const { start, size } = getFontSizeIndexFromHtml(html, "font-size-");
72393
+ if (size !== -1) {
72394
+ if (start) {
72395
+ attributes["inline-style-font-size"] = `${size}px`;
72396
+ } else {
72397
+ delete attributes["inline-style-font-size"];
72398
+ }
72399
+ }
72400
+ }
72300
72401
  const logger$M = getLogger("token-to-text");
72301
72402
  function tokensToText(tokens, attributes, options) {
72302
72403
  const ops = tokens.map((token) => {
@@ -72332,6 +72433,9 @@ ${codeText}
72332
72433
  if (token.type === "html") {
72333
72434
  const html = token.text;
72334
72435
  applyHtmlToText(html, attributes);
72436
+ applyColorTagToText(html, attributes);
72437
+ applyFontSizeTagToText(html, attributes);
72438
+ return [];
72335
72439
  }
72336
72440
  if (token.type === "br") {
72337
72441
  return [{
@@ -74107,6 +74211,142 @@ ${docStr}
74107
74211
  }
74108
74212
  });
74109
74213
  }
74214
+ const COLORS = [
74215
+ "#e52727",
74216
+ "#eb6414",
74217
+ "#f0a100",
74218
+ "#24b47e",
74219
+ "#0064ff",
74220
+ "#9678d3",
74221
+ "#909090"
74222
+ ];
74223
+ const BACKGROUND_COLORS = [
74224
+ "#fad4d4",
74225
+ "#fbe0d0",
74226
+ "#fceccc",
74227
+ "#d3f0e5",
74228
+ "#d6e9fa",
74229
+ "#eae4f6",
74230
+ "#EDEFF2",
74231
+ "#FA9287",
74232
+ "#FF9F6B",
74233
+ "#FFBD59",
74234
+ "#60D1A4",
74235
+ "#7AAFFF",
74236
+ "#BC9BFA",
74237
+ "#BEBFC2",
74238
+ "#DFE1E5"
74239
+ ];
74240
+ function toCssColor(color) {
74241
+ if (color.startsWith("#")) {
74242
+ return color;
74243
+ }
74244
+ if (color.startsWith("rgba")) {
74245
+ const values = color.substring(5, color.length - 1).split(",");
74246
+ if (values.length === 4) {
74247
+ return `#${parseInt(values[0], 10).toString(16).padStart(2, "0")}${parseInt(values[1], 10).toString(16).padStart(2, "0")}${parseInt(values[2], 10).toString(16).padStart(2, "0")}`;
74248
+ }
74249
+ }
74250
+ if (color.startsWith("rgb")) {
74251
+ const values = color.substring(4, color.length - 1).split(",");
74252
+ if (values.length === 3) {
74253
+ return `#${parseInt(values[0], 10).toString(16).padStart(2, "0")}${parseInt(values[1], 10).toString(16).padStart(2, "0")}${parseInt(values[2], 10).toString(16).padStart(2, "0")}`;
74254
+ }
74255
+ }
74256
+ return color;
74257
+ }
74258
+ function getDistance(color1, color2) {
74259
+ const c1 = color1.substring(1);
74260
+ const c2 = color2.substring(1);
74261
+ const r1 = parseInt(c1.substring(0, 2), 16);
74262
+ const g1 = parseInt(c1.substring(2, 4), 16);
74263
+ const b1 = parseInt(c1.substring(4, 6), 16);
74264
+ const r2 = parseInt(c2.substring(0, 2), 16);
74265
+ const g2 = parseInt(c2.substring(2, 4), 16);
74266
+ const b2 = parseInt(c2.substring(4, 6), 16);
74267
+ return Math.sqrt((r1 - r2) ** 2 + (g1 - g2) ** 2 + (b1 - b2) ** 2);
74268
+ }
74269
+ function getColorIndex(colors, color) {
74270
+ let minDistance = Number.MAX_SAFE_INTEGER;
74271
+ let index2 = -1;
74272
+ for (let i = 0; i < colors.length; i += 1) {
74273
+ const distance = getDistance(colors[i], color);
74274
+ if (distance < minDistance) {
74275
+ minDistance = distance;
74276
+ index2 = i;
74277
+ }
74278
+ }
74279
+ return index2;
74280
+ }
74281
+ function textColor(ts) {
74282
+ ts.addRule("figcaption", {
74283
+ filter: (node) => {
74284
+ if (node.nodeName !== "SPAN") {
74285
+ return false;
74286
+ }
74287
+ const span = node;
74288
+ const style2 = span.style;
74289
+ if (!style2) {
74290
+ return false;
74291
+ }
74292
+ if (style2.color || style2.backgroundColor) {
74293
+ return true;
74294
+ }
74295
+ return false;
74296
+ },
74297
+ replacement: (content, node, options) => {
74298
+ const span = node;
74299
+ const style2 = span.style;
74300
+ const color = toCssColor(style2.color);
74301
+ const backgroundColor = toCssColor(style2.backgroundColor);
74302
+ const prefixes = [];
74303
+ const suffixes = [];
74304
+ if (color) {
74305
+ const colorIndex = getColorIndex(COLORS, color);
74306
+ prefixes.push(`<color-${colorIndex}>`);
74307
+ suffixes.push(`</color-${colorIndex}>`);
74308
+ }
74309
+ if (backgroundColor) {
74310
+ const backgroundColorIndex = getColorIndex(BACKGROUND_COLORS, backgroundColor);
74311
+ prefixes.push(`<background-color-${backgroundColorIndex}>`);
74312
+ suffixes.push(`</background-color-${backgroundColorIndex}>`);
74313
+ }
74314
+ let ret = content;
74315
+ prefixes.forEach((prefix, index2) => {
74316
+ ret = `${prefix}${ret}${suffixes[index2]}`;
74317
+ });
74318
+ return ret;
74319
+ }
74320
+ });
74321
+ }
74322
+ function fontSize(ts) {
74323
+ ts.addRule("figcaption", {
74324
+ filter: (node) => {
74325
+ if (node.nodeName !== "SPAN") {
74326
+ return false;
74327
+ }
74328
+ const span = node;
74329
+ const style2 = span.style;
74330
+ if (!style2) {
74331
+ return false;
74332
+ }
74333
+ if (style2.fontSize) {
74334
+ return true;
74335
+ }
74336
+ return false;
74337
+ },
74338
+ replacement: (content, node, options) => {
74339
+ const span = node;
74340
+ const style2 = span.style;
74341
+ const fontSize2 = style2.fontSize;
74342
+ if (fontSize2) {
74343
+ const fontSizeValue = fontSize2.replace("px", "");
74344
+ return `<font-size-${fontSizeValue}>${content}</font-size-${fontSizeValue}>`;
74345
+ }
74346
+ return content;
74347
+ }
74348
+ });
74349
+ }
74110
74350
  const logger$K = getLogger("html-to-doc");
74111
74351
  const turndownService = new TurndownService();
74112
74352
  turndownService.use(codeListToCode);
@@ -74120,6 +74360,8 @@ ${docStr}
74120
74360
  turndownService.use(turndownPluginGfm.gfm);
74121
74361
  turndownService.use(underline);
74122
74362
  turndownService.use(figcaptionToTextBlock);
74363
+ turndownService.use(textColor);
74364
+ turndownService.use(fontSize);
74123
74365
  function htmlToBlocks$1(html, options) {
74124
74366
  const subDoc = processedHtmlToDocByMarkdown(html, options);
74125
74367
  if (!subDoc) {
@@ -87650,12 +87892,12 @@ ${data2.flowchartText}
87650
87892
  return void 0;
87651
87893
  return fonts[0].trim();
87652
87894
  }
87653
- function textObjectToTextRun(obj, fontSize) {
87895
+ function textObjectToTextRun(obj, fontSize2) {
87654
87896
  var _a;
87655
87897
  let style2;
87656
87898
  style2 = obj.inlineCode ? "InlineCode" : void 0;
87657
87899
  style2 = obj.link ? "Hyperlink" : style2;
87658
- const sizeOfFont = obj.size || fontSize;
87900
+ const sizeOfFont = obj.size || fontSize2;
87659
87901
  const size = sizeOfFont != null ? Math.floor(sizeOfFont * 1.5 + 0.5) : void 0;
87660
87902
  obj.text = (_a = obj.text) == null ? void 0 : _a.replace(/\x00/g, " ");
87661
87903
  return new docx.TextRun({
@@ -87674,11 +87916,11 @@ ${data2.flowchartText}
87674
87916
  highlight: styleBackgroundColorToHighlight(obj.highlight)
87675
87917
  });
87676
87918
  }
87677
- function textObjectToHyperLink(obj, fontSize) {
87919
+ function textObjectToHyperLink(obj, fontSize2) {
87678
87920
  if (obj.link) {
87679
87921
  obj.link = obj.link.replace(/\x00/g, " ");
87680
87922
  return new docx.ExternalHyperlink({
87681
- children: [textObjectToTextRun(obj, fontSize)],
87923
+ children: [textObjectToTextRun(obj, fontSize2)],
87682
87924
  link: obj.link
87683
87925
  });
87684
87926
  }
@@ -88087,11 +88329,11 @@ ${data2.flowchartText}
88087
88329
  async paragraphsFromBlockTexts(obj) {
88088
88330
  if (obj.texts == null)
88089
88331
  return void 0;
88090
- const fontSize = getFontSizeByHeadingLevel(this.defaultFontSize, obj.heading);
88332
+ const fontSize2 = getFontSizeByHeadingLevel(this.defaultFontSize, obj.heading);
88091
88333
  const ret = [];
88092
88334
  for (const text2 of obj.texts) {
88093
88335
  if (text2.link) {
88094
- const link2 = textObjectToHyperLink(text2, fontSize);
88336
+ const link2 = textObjectToHyperLink(text2, fontSize2);
88095
88337
  if (link2) {
88096
88338
  ret.push(link2);
88097
88339
  }
@@ -88116,7 +88358,7 @@ ${data2.flowchartText}
88116
88358
  ret.push(ir);
88117
88359
  continue;
88118
88360
  }
88119
- ret.push(textObjectToTextRun(text2, fontSize));
88361
+ ret.push(textObjectToTextRun(text2, fontSize2));
88120
88362
  }
88121
88363
  return ret;
88122
88364
  }
@@ -89410,7 +89652,7 @@ ${data2.flowchartText}
89410
89652
  }
89411
89653
  }
89412
89654
  });
89413
- editor.version = "2.1.7-beta.37";
89655
+ editor.version = "2.1.7-beta.38";
89414
89656
  return editor;
89415
89657
  }
89416
89658
  function isDoc(doc2) {
@@ -89524,7 +89766,7 @@ ${data2.flowchartText}
89524
89766
  }
89525
89767
  }
89526
89768
  OnesEditorToolbar.register(editor);
89527
- editor.version = "2.1.7-beta.37";
89769
+ editor.version = "2.1.7-beta.38";
89528
89770
  return editor;
89529
89771
  }
89530
89772
  async function showDocVersions(editor, options, serverUrl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ones-editor/editor",
3
- "version": "2.1.7-beta.37",
3
+ "version": "2.1.7-beta.38",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",