@scrider/formatter 1.10.1 → 1.10.3

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
@@ -36,6 +36,7 @@ __export(index_exports, {
36
36
  BOX_OVERFLOW_VALUES: () => BOX_OVERFLOW_VALUES,
37
37
  BlockHandlerRegistry: () => BlockHandlerRegistry,
38
38
  BrowserDOMAdapter: () => BrowserDOMAdapter,
39
+ HEADER_SIZE_PRESETS: () => HEADER_SIZE_PRESETS,
39
40
  LINE_HEIGHT_BLOCK_TAGS: () => LINE_HEIGHT_BLOCK_TAGS,
40
41
  NODE_TYPE: () => NODE_TYPE,
41
42
  NodeDOMAdapter: () => NodeDOMAdapter,
@@ -90,6 +91,7 @@ __export(index_exports, {
90
91
  getNamedColors: () => getNamedColors,
91
92
  headerFormat: () => headerFormat,
92
93
  headerIdFormat: () => headerIdFormat,
94
+ headingPolicyStyleParts: () => headingPolicyStyleParts,
93
95
  htmlToDelta: () => htmlToDelta,
94
96
  imageFormat: () => imageFormat,
95
97
  indentFormat: () => indentFormat,
@@ -118,6 +120,7 @@ __export(index_exports, {
118
120
  preloadRemark: () => preloadRemark,
119
121
  renderDelta: () => renderDelta,
120
122
  resolveDocumentPresentation: () => resolveDocumentPresentation,
123
+ resolveHeadingPolicy: () => resolveHeadingPolicy,
121
124
  resolveTablePresentation: () => resolveTablePresentation,
122
125
  sanitizeDelta: () => sanitizeDelta,
123
126
  sizeFormat: () => sizeFormat,
@@ -3314,6 +3317,90 @@ function joinStyleParts(parts) {
3314
3317
  return parts.length > 0 ? ` style="${parts.join("; ")}"` : "";
3315
3318
  }
3316
3319
 
3320
+ // src/conversion/html/heading-presentation.ts
3321
+ var HEADER_SIZE_PRESETS = Object.freeze({
3322
+ scrider: Object.freeze({
3323
+ 1: "32pt",
3324
+ 2: "24pt",
3325
+ 3: "20pt",
3326
+ 4: "18pt",
3327
+ 5: "16pt",
3328
+ 6: "14pt"
3329
+ }),
3330
+ google: Object.freeze({
3331
+ 1: "26pt",
3332
+ 2: "20pt",
3333
+ 3: "16pt",
3334
+ 4: "14pt",
3335
+ 5: "12pt",
3336
+ 6: "11pt"
3337
+ }),
3338
+ word: Object.freeze({
3339
+ 1: "22pt",
3340
+ 2: "18pt",
3341
+ 3: "16pt",
3342
+ 4: "14pt",
3343
+ 5: "12pt",
3344
+ 6: "12pt"
3345
+ }),
3346
+ browser: Object.freeze({
3347
+ 1: "24pt",
3348
+ 2: "18pt",
3349
+ 3: "14pt",
3350
+ 4: "12pt",
3351
+ 5: "10pt",
3352
+ 6: "8pt"
3353
+ }),
3354
+ githubEm: Object.freeze({
3355
+ 1: "32pt",
3356
+ 2: "24pt",
3357
+ 3: "20pt",
3358
+ 4: "16pt",
3359
+ 5: "14pt",
3360
+ 6: "14pt"
3361
+ })
3362
+ });
3363
+ var HEADING_TAGS = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
3364
+ function isHeaderSizePresetName(value) {
3365
+ return Object.prototype.hasOwnProperty.call(HEADER_SIZE_PRESETS, value);
3366
+ }
3367
+ function resolveHeadingPolicy(metadata) {
3368
+ if (!metadata) return void 0;
3369
+ const align = metadata.headingAlign === "left" || metadata.headingAlign === "center" || metadata.headingAlign === "right" ? metadata.headingAlign : void 0;
3370
+ const bold = metadata.headingBold === true;
3371
+ const auto = metadata.headingAuto === true;
3372
+ const presetRaw = metadata.headingSizeGridPreset;
3373
+ const sizePreset = !auto && typeof presetRaw === "string" && isHeaderSizePresetName(presetRaw) ? presetRaw : void 0;
3374
+ if (align === void 0 && !bold && sizePreset === void 0 && !auto) {
3375
+ return void 0;
3376
+ }
3377
+ return { align, bold, sizePreset, auto };
3378
+ }
3379
+ function headingLevelFromTag(tag) {
3380
+ if (!HEADING_TAGS.has(tag)) return void 0;
3381
+ const n = Number(tag.slice(1));
3382
+ if (n >= 1 && n <= 6) return n;
3383
+ return void 0;
3384
+ }
3385
+ function headingPolicyStyleParts(tag, blockAttributes, policy) {
3386
+ if (!policy) return [];
3387
+ const level = headingLevelFromTag(tag);
3388
+ if (level === void 0) return [];
3389
+ const parts = [];
3390
+ const bakedAlign = blockAttributes?.align;
3391
+ if (policy.align && policy.align !== "left" && !(typeof bakedAlign === "string" && bakedAlign.length > 0)) {
3392
+ parts.push(`text-align: ${policy.align}`);
3393
+ }
3394
+ if (policy.bold) {
3395
+ parts.push("font-weight: bold");
3396
+ }
3397
+ if (policy.sizePreset) {
3398
+ const size = HEADER_SIZE_PRESETS[policy.sizePreset][level];
3399
+ if (size) parts.push(`font-size: ${size}`);
3400
+ }
3401
+ return parts;
3402
+ }
3403
+
3317
3404
  // src/conversion/html/table-presentation.ts
3318
3405
  var DEFAULT_BORDER_COLOR = "#e7e7e7";
3319
3406
  var DEFAULT_HEADER_BG = "#f5f5f5";
@@ -3478,6 +3565,12 @@ function deltaToHtml(delta, options = {}) {
3478
3565
  const resolvedDocumentPresentation = resolveDocumentPresentation(
3479
3566
  options.documentPresentation ?? documentMetadataToPresentation(options.documentMetadata)
3480
3567
  );
3568
+ const resolvedHeadingPolicy = resolveHeadingPolicy(options.documentMetadata);
3569
+ const effectiveTablePresentation = options.tablePresentation ?? options.documentMetadata?.tablePresentation;
3570
+ const optionsWithTable = {
3571
+ ...options,
3572
+ ...effectiveTablePresentation !== void 0 ? { tablePresentation: effectiveTablePresentation } : {}
3573
+ };
3481
3574
  let html = "";
3482
3575
  let listStack = [];
3483
3576
  let counters = [];
@@ -3490,7 +3583,7 @@ function deltaToHtml(delta, options = {}) {
3490
3583
  listStack = [];
3491
3584
  counters = [];
3492
3585
  const tableLines = collectAdjacentTableLines(lines, i);
3493
- html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, options);
3586
+ html += renderTable(tableLines, embedRenderers, pretty, blockHandlers, optionsWithTable);
3494
3587
  i += tableLines.length - 1;
3495
3588
  continue;
3496
3589
  }
@@ -3581,7 +3674,8 @@ function deltaToHtml(delta, options = {}) {
3581
3674
  line.attributes,
3582
3675
  pretty,
3583
3676
  headingId,
3584
- resolvedDocumentPresentation
3677
+ resolvedDocumentPresentation,
3678
+ resolvedHeadingPolicy
3585
3679
  );
3586
3680
  }
3587
3681
  }
@@ -3901,19 +3995,23 @@ function renderListItem(content, attrs, blockAttributes, pretty, indentLevel, hi
3901
3995
  const html = `${indent}<li${fullAttrs}>${innerContent}</li>`;
3902
3996
  return pretty ? html + "\n" : html;
3903
3997
  }
3904
- function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation) {
3998
+ function renderBlock(content, tag, attributes, pretty, id, resolvedDocumentPresentation, resolvedHeadingPolicy) {
3905
3999
  const idAttr = id ? ` id="${escapeHtml(id)}"` : "";
3906
- const styleAttr = getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation);
4000
+ const styleAttr = getBlockStyleAttribute(
4001
+ tag,
4002
+ attributes,
4003
+ resolvedDocumentPresentation,
4004
+ resolvedHeadingPolicy
4005
+ );
3907
4006
  const innerContent = content || "<br>";
3908
4007
  const html = `<${tag}${idAttr}${styleAttr}>${innerContent}</${tag}>`;
3909
4008
  return pretty ? html + "\n" : html;
3910
4009
  }
3911
- function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation) {
3912
- const styles = blockPresentationStyleParts(
3913
- tag,
3914
- attributes,
3915
- resolvedDocumentPresentation
3916
- );
4010
+ function getBlockStyleAttribute(tag, attributes, resolvedDocumentPresentation, resolvedHeadingPolicy) {
4011
+ const styles = [
4012
+ ...blockPresentationStyleParts(tag, attributes, resolvedDocumentPresentation),
4013
+ ...headingPolicyStyleParts(tag, attributes, resolvedHeadingPolicy)
4014
+ ];
3917
4015
  if (attributes) {
3918
4016
  const alignVal = attributes.align;
3919
4017
  if (alignVal && typeof alignVal === "string" && alignVal !== "left") {
@@ -6234,6 +6332,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
6234
6332
  BOX_OVERFLOW_VALUES,
6235
6333
  BlockHandlerRegistry,
6236
6334
  BrowserDOMAdapter,
6335
+ HEADER_SIZE_PRESETS,
6237
6336
  LINE_HEIGHT_BLOCK_TAGS,
6238
6337
  NODE_TYPE,
6239
6338
  NodeDOMAdapter,
@@ -6288,6 +6387,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
6288
6387
  getNamedColors,
6289
6388
  headerFormat,
6290
6389
  headerIdFormat,
6390
+ headingPolicyStyleParts,
6291
6391
  htmlToDelta,
6292
6392
  imageFormat,
6293
6393
  indentFormat,
@@ -6316,6 +6416,7 @@ function astToDelta(tree, customHandlers, mathBlock, mermaidBlock, plantumlBlock
6316
6416
  preloadRemark,
6317
6417
  renderDelta,
6318
6418
  resolveDocumentPresentation,
6419
+ resolveHeadingPolicy,
6319
6420
  resolveTablePresentation,
6320
6421
  sanitizeDelta,
6321
6422
  sizeFormat,