@drghaliasri/butex 6.1.5 → 7.0.2

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/document2.js CHANGED
@@ -3899,14 +3899,20 @@ var BUTEX_EDITOR_CSS = `
3899
3899
  ${BUTEX_FONT_FACE_CSS}
3900
3900
 
3901
3901
  .surface {
3902
+ background: var(--butex-surface-bg, linear-gradient(180deg, #ffffff 0%, #fafbfc 100%));
3902
3903
  border: 1px solid var(--butex-border, #e2e8f0);
3903
3904
  border-radius: 12px;
3904
- min-height: 100px;
3905
- padding: 8px 10px;
3906
- background: var(--butex-surface-bg, linear-gradient(180deg, #ffffff 0%, #fafbfc 100%));
3907
3905
  color: var(--butex-surface-fg, #0f172a);
3908
- outline: none;
3909
3906
  cursor: text;
3907
+ max-width: 100%;
3908
+ min-height: 100px;
3909
+ min-width: 0;
3910
+ outline: none;
3911
+ overflow-x: auto;
3912
+ overflow-y: hidden;
3913
+ overscroll-behavior-inline: contain;
3914
+ padding: 8px 10px;
3915
+ touch-action: pan-x pan-y;
3910
3916
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
3911
3917
  }
3912
3918
 
@@ -3971,6 +3977,17 @@ ${CHARACTER_FONT_CSS}
3971
3977
  50% { opacity: 0; }
3972
3978
  }
3973
3979
 
3980
+ @media (prefers-reduced-motion: reduce) {
3981
+ .surface {
3982
+ scroll-behavior: auto;
3983
+ transition: none;
3984
+ }
3985
+
3986
+ .caret {
3987
+ animation: none;
3988
+ }
3989
+ }
3990
+
3974
3991
  .node {
3975
3992
  display: inline-flex;
3976
3993
  align-items: stretch;
@@ -5586,6 +5603,12 @@ function requireBoolean(value, field) {
5586
5603
  }
5587
5604
  return value;
5588
5605
  }
5606
+ function optionalBoolean(value, field) {
5607
+ if (!(field in value)) {
5608
+ return void 0;
5609
+ }
5610
+ return requireBoolean(value[field], field);
5611
+ }
5589
5612
  function requireIndex(value, field) {
5590
5613
  if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
5591
5614
  throw new Document2CommandError("invalid_command", `${field} must be a non-negative integer`);
@@ -5816,6 +5839,301 @@ function compactTextTokens2(tokens, emptyTokenId = document2Id("text")) {
5816
5839
  return compacted.length > 0 ? compacted : [{ id: emptyTokenId, kind: "text", text: "" }];
5817
5840
  }
5818
5841
 
5842
+ // src/document2/keys.ts
5843
+ var DOCUMENT2_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
5844
+ function normalizeDocument2Key(key) {
5845
+ return key.normalize("NFC").trim();
5846
+ }
5847
+ function isValidDocument2Key(key) {
5848
+ const normalized = normalizeDocument2Key(key);
5849
+ return normalized.length > 0 && DOCUMENT2_KEY_PATTERN.test(normalized);
5850
+ }
5851
+ function isDuplicateDocument2Key(key, namespace) {
5852
+ const normalized = normalizeDocument2Key(key);
5853
+ if (normalized.length === 0) {
5854
+ return false;
5855
+ }
5856
+ for (const reference of namespace.references ?? []) {
5857
+ if (namespace.excludeReferenceId && reference.id === namespace.excludeReferenceId) {
5858
+ continue;
5859
+ }
5860
+ if (normalizeDocument2Key(reference.key) === normalized) {
5861
+ return true;
5862
+ }
5863
+ }
5864
+ for (const label of namespace.labels ?? []) {
5865
+ if (namespace.excludeOwnerId && label.ownerId === namespace.excludeOwnerId) {
5866
+ continue;
5867
+ }
5868
+ if (normalizeDocument2Key(label.key) === normalized) {
5869
+ return true;
5870
+ }
5871
+ }
5872
+ return false;
5873
+ }
5874
+ function document2KeyError(key, namespace = {}) {
5875
+ const normalized = normalizeDocument2Key(key);
5876
+ if (normalized.length === 0) {
5877
+ return "empty";
5878
+ }
5879
+ if (!DOCUMENT2_KEY_PATTERN.test(normalized)) {
5880
+ return "invalid";
5881
+ }
5882
+ if (isDuplicateDocument2Key(normalized, namespace)) {
5883
+ return "duplicate";
5884
+ }
5885
+ return null;
5886
+ }
5887
+
5888
+ // src/document2/articleJsonCommands.ts
5889
+ var REFERENCE_TEXT_FIELDS = ["authors", "title", "year", "venue", "url"];
5890
+ function hasOwn(value, field) {
5891
+ return Object.prototype.hasOwnProperty.call(value, field);
5892
+ }
5893
+ function parseDatePatch(value) {
5894
+ if (!isObject3(value)) {
5895
+ throw new Document2CommandError("invalid_command", "date must be an object");
5896
+ }
5897
+ const patch = {};
5898
+ if (hasOwn(value, "day")) {
5899
+ if (typeof value.day !== "number" || !Number.isInteger(value.day) || value.day < 1 || value.day > 30) {
5900
+ throw new Document2CommandError("invalid_command", "date.day must be an integer from 1 to 30");
5901
+ }
5902
+ patch.day = value.day;
5903
+ }
5904
+ if (hasOwn(value, "month")) {
5905
+ if (typeof value.month !== "string" || !HIJRI_MONTH_IDS.includes(value.month)) {
5906
+ throw new Document2CommandError("invalid_command", "date.month must be a supported Hijri month");
5907
+ }
5908
+ patch.month = value.month;
5909
+ }
5910
+ if (hasOwn(value, "year")) {
5911
+ if (typeof value.year !== "number" || !Number.isInteger(value.year) || value.year < HIJRI_YEAR_MIN || value.year > HIJRI_YEAR_MAX) {
5912
+ throw new Document2CommandError(
5913
+ "invalid_command",
5914
+ `date.year must be an integer from ${String(HIJRI_YEAR_MIN)} to ${String(HIJRI_YEAR_MAX)}`
5915
+ );
5916
+ }
5917
+ patch.year = value.year;
5918
+ }
5919
+ if (Object.keys(patch).length === 0) {
5920
+ throw new Document2CommandError("invalid_command", "date requires at least one field");
5921
+ }
5922
+ return patch;
5923
+ }
5924
+ function parseReferenceSeparator(value) {
5925
+ if (!hasOwn(value, "field_separator")) {
5926
+ return void 0;
5927
+ }
5928
+ if (value.field_separator !== "," && value.field_separator !== "\u060C") {
5929
+ throw new Document2CommandError("invalid_command", "field_separator must be , or \u060C");
5930
+ }
5931
+ return value.field_separator;
5932
+ }
5933
+ function parseReferenceAnchor(value) {
5934
+ if (!isObject3(value)) {
5935
+ throw new Document2CommandError("invalid_anchor", "anchor must be an object");
5936
+ }
5937
+ const before = typeof value.before_reference_key === "string" ? normalizeDocument2Key(value.before_reference_key) : "";
5938
+ const after = typeof value.after_reference_key === "string" ? normalizeDocument2Key(value.after_reference_key) : "";
5939
+ const choices = Number(before.length > 0) + Number(after.length > 0) + Number(value.end === true);
5940
+ if (choices !== 1) {
5941
+ throw new Document2CommandError("invalid_anchor", "anchor requires exactly one reference position");
5942
+ }
5943
+ if (before) {
5944
+ return { before_reference_key: before };
5945
+ }
5946
+ if (after) {
5947
+ return { after_reference_key: after };
5948
+ }
5949
+ return { end: true };
5950
+ }
5951
+ function parseUpdateDocumentMeta(value) {
5952
+ const title = optionalString(value, "title");
5953
+ const authors = optionalString(value, "authors");
5954
+ const abstract = optionalString(value, "abstract");
5955
+ const date = hasOwn(value, "date") ? parseDatePatch(value.date) : void 0;
5956
+ if (title === void 0 && authors === void 0 && abstract === void 0 && date === void 0) {
5957
+ throw new Document2CommandError("invalid_command", "update_document_meta requires at least one field");
5958
+ }
5959
+ return {
5960
+ op: "update_document_meta",
5961
+ ...title !== void 0 ? { title } : {},
5962
+ ...authors !== void 0 ? { authors } : {},
5963
+ ...abstract !== void 0 ? { abstract } : {},
5964
+ ...date !== void 0 ? { date } : {}
5965
+ };
5966
+ }
5967
+ function referenceFields(value) {
5968
+ const fields = {};
5969
+ for (const field of REFERENCE_TEXT_FIELDS) {
5970
+ const parsed = optionalString(value, field);
5971
+ if (parsed !== void 0) {
5972
+ fields[field] = parsed;
5973
+ }
5974
+ }
5975
+ const separator = parseReferenceSeparator(value);
5976
+ if (separator !== void 0) {
5977
+ fields.field_separator = separator;
5978
+ }
5979
+ return fields;
5980
+ }
5981
+ function parseInsertReference(value) {
5982
+ const key = requireString2(value.key, "key", false);
5983
+ return {
5984
+ op: "insert_reference",
5985
+ key,
5986
+ ...referenceFields(value),
5987
+ anchor: parseReferenceAnchor(value.anchor)
5988
+ };
5989
+ }
5990
+ function parseUpdateReference(value) {
5991
+ const nextKey = optionalString(value, "key");
5992
+ const fields = referenceFields(value);
5993
+ if (nextKey === void 0 && Object.keys(fields).length === 0) {
5994
+ throw new Document2CommandError("invalid_command", "update_reference requires at least one field");
5995
+ }
5996
+ return {
5997
+ op: "update_reference",
5998
+ reference_key: requireString2(value.reference_key, "reference_key", false),
5999
+ ...nextKey !== void 0 ? { key: nextKey } : {},
6000
+ ...fields
6001
+ };
6002
+ }
6003
+ function parseArticleCommand(value) {
6004
+ if (value.op === "update_document_meta") {
6005
+ return parseUpdateDocumentMeta(value);
6006
+ }
6007
+ if (value.op === "insert_reference") {
6008
+ return parseInsertReference(value);
6009
+ }
6010
+ if (value.op === "update_reference") {
6011
+ return parseUpdateReference(value);
6012
+ }
6013
+ if (value.op === "remove_reference") {
6014
+ return {
6015
+ op: value.op,
6016
+ reference_key: requireString2(value.reference_key, "reference_key", false)
6017
+ };
6018
+ }
6019
+ if (value.op === "move_reference") {
6020
+ return {
6021
+ op: value.op,
6022
+ reference_key: requireString2(value.reference_key, "reference_key", false),
6023
+ anchor: parseReferenceAnchor(value.anchor)
6024
+ };
6025
+ }
6026
+ throw new Document2CommandError("invalid_command", "Unsupported article command");
6027
+ }
6028
+ function referenceIndexes(document2, key) {
6029
+ const normalized = normalizeDocument2Key(key);
6030
+ const indexes = [];
6031
+ document2.references.forEach((reference, index) => {
6032
+ if (normalizeDocument2Key(reference.key) === normalized) {
6033
+ indexes.push(index);
6034
+ }
6035
+ });
6036
+ return indexes;
6037
+ }
6038
+ function referenceTargetIndex(document2, key) {
6039
+ const indexes = referenceIndexes(document2, key);
6040
+ if (indexes.length === 0) {
6041
+ throw new Document2CommandError("reference_not_found", "Document reference was not found");
6042
+ }
6043
+ if (indexes.length > 1) {
6044
+ throw new Document2CommandError("duplicate_key", "Reference key is ambiguous");
6045
+ }
6046
+ return indexes[0];
6047
+ }
6048
+ function validateReferenceKey(document2, key, excludeReferenceId) {
6049
+ const normalized = normalizeDocument2Key(key);
6050
+ const error = document2KeyError(normalized, {
6051
+ references: document2.references,
6052
+ labels: collectDocument2Labels(document2),
6053
+ ...excludeReferenceId ? { excludeReferenceId } : {}
6054
+ });
6055
+ if (error === "duplicate") {
6056
+ throw new Document2CommandError("duplicate_key", "Reference key is already in use");
6057
+ }
6058
+ if (error !== null) {
6059
+ throw new Document2CommandError("invalid_key", "Reference key is invalid");
6060
+ }
6061
+ return normalized;
6062
+ }
6063
+ function referenceInsertionIndex(document2, anchor) {
6064
+ if ("end" in anchor) {
6065
+ return document2.references.length;
6066
+ }
6067
+ const key = "before_reference_key" in anchor ? anchor.before_reference_key : anchor.after_reference_key;
6068
+ const indexes = referenceIndexes(document2, key);
6069
+ if (indexes.length === 0) {
6070
+ throw new Document2CommandError("anchor_not_found", "Anchor reference was not found");
6071
+ }
6072
+ if (indexes.length > 1) {
6073
+ throw new Document2CommandError("duplicate_key", "Anchor reference key is ambiguous");
6074
+ }
6075
+ return "before_reference_key" in anchor ? indexes[0] : indexes[0] + 1;
6076
+ }
6077
+ function applyReferenceFields(reference, command) {
6078
+ for (const field of REFERENCE_TEXT_FIELDS) {
6079
+ const next = command[field];
6080
+ if (next !== void 0) {
6081
+ reference[field] = next;
6082
+ }
6083
+ }
6084
+ if (command.field_separator !== void 0) {
6085
+ reference.fieldSeparator = command.field_separator;
6086
+ }
6087
+ }
6088
+ function applyArticleCommand(document2, command) {
6089
+ if (command.op === "update_document_meta") {
6090
+ document2.meta = {
6091
+ title: command.title ?? document2.meta.title,
6092
+ authors: command.authors ?? document2.meta.authors,
6093
+ abstract: command.abstract ?? document2.meta.abstract,
6094
+ date: command.date ? normalizeDocument2HijriDate({ ...document2.meta.date, ...command.date }) : { ...document2.meta.date }
6095
+ };
6096
+ return;
6097
+ }
6098
+ if (command.op === "insert_reference") {
6099
+ const key = validateReferenceKey(document2, command.key);
6100
+ const reference2 = referenceFromJson({
6101
+ key,
6102
+ authors: command.authors,
6103
+ title: command.title,
6104
+ year: command.year,
6105
+ venue: command.venue,
6106
+ url: command.url,
6107
+ field_separator: command.field_separator
6108
+ });
6109
+ document2.references.splice(referenceInsertionIndex(document2, command.anchor), 0, reference2);
6110
+ return;
6111
+ }
6112
+ const targetIndex = referenceTargetIndex(document2, command.reference_key);
6113
+ const target = document2.references[targetIndex];
6114
+ if (command.op === "update_reference") {
6115
+ if (command.key !== void 0) {
6116
+ target.key = validateReferenceKey(document2, command.key, target.id);
6117
+ }
6118
+ applyReferenceFields(target, command);
6119
+ return;
6120
+ }
6121
+ if (command.op === "remove_reference") {
6122
+ document2.references.splice(targetIndex, 1);
6123
+ return;
6124
+ }
6125
+ const targetKey = normalizeDocument2Key(target.key);
6126
+ const anchorKey = "before_reference_key" in command.anchor ? command.anchor.before_reference_key : "after_reference_key" in command.anchor ? command.anchor.after_reference_key : null;
6127
+ if (anchorKey !== null && normalizeDocument2Key(anchorKey) === targetKey) {
6128
+ throw new Document2CommandError("invalid_anchor", "A reference cannot be moved relative to itself");
6129
+ }
6130
+ if (anchorKey !== null) {
6131
+ referenceInsertionIndex(document2, command.anchor);
6132
+ }
6133
+ const [reference] = document2.references.splice(targetIndex, 1);
6134
+ document2.references.splice(referenceInsertionIndex(document2, command.anchor), 0, reference);
6135
+ }
6136
+
5819
6137
  // src/document2/inlineJsonCommands.ts
5820
6138
  function parseInlineAnchor(value) {
5821
6139
  if (!isObject3(value)) {
@@ -6490,6 +6808,9 @@ function isListCommand(command) {
6490
6808
  function isTableCommand(command) {
6491
6809
  return command.op === "insert_table" || command.op === "replace_table_cell" || command.op === "insert_table_row" || command.op === "remove_table_row" || command.op === "move_table_row" || command.op === "insert_table_column" || command.op === "remove_table_column" || command.op === "move_table_column";
6492
6810
  }
6811
+ function isArticleCommand(command) {
6812
+ return command.op === "update_document_meta" || command.op === "insert_reference" || command.op === "update_reference" || command.op === "remove_reference" || command.op === "move_reference";
6813
+ }
6493
6814
  function parseTextBlockKind(value) {
6494
6815
  if (value === "section" || value === "subsection" || value === "subsubsection" || value === "paragraph") {
6495
6816
  return value;
@@ -6517,6 +6838,62 @@ function parseBasicCommand(value) {
6517
6838
  if (value.op === "remove_block") {
6518
6839
  return { op: value.op, block_id: requireString2(value.block_id, "block_id", false).trim() };
6519
6840
  }
6841
+ if (value.op === "move_block") {
6842
+ return {
6843
+ op: value.op,
6844
+ block_id: requireString2(value.block_id, "block_id", false).trim(),
6845
+ anchor: parseBlockAnchor(value.anchor)
6846
+ };
6847
+ }
6848
+ if (value.op === "insert_bibliography") {
6849
+ const metadata = parseMetadata(value.metadata);
6850
+ return {
6851
+ op: value.op,
6852
+ anchor: parseBlockAnchor(value.anchor),
6853
+ ...metadata ? { metadata } : {}
6854
+ };
6855
+ }
6856
+ if (value.op === "update_figure") {
6857
+ const hasAssetId = Object.prototype.hasOwnProperty.call(value, "asset_id");
6858
+ const hasValue = Object.prototype.hasOwnProperty.call(value, "value");
6859
+ if (!hasAssetId && !hasValue) {
6860
+ throw new Document2CommandError("invalid_command", "update_figure requires asset_id or value");
6861
+ }
6862
+ let assetId;
6863
+ if (hasAssetId) {
6864
+ if (value.asset_id === null) {
6865
+ assetId = null;
6866
+ } else {
6867
+ assetId = requireString2(value.asset_id, "asset_id", false).trim();
6868
+ }
6869
+ }
6870
+ const figureValue = hasValue ? requireString2(value.value, "value") : void 0;
6871
+ return {
6872
+ op: value.op,
6873
+ block_id: requireString2(value.block_id, "block_id", false).trim(),
6874
+ ...hasAssetId ? { asset_id: assetId } : {},
6875
+ ...hasValue ? { value: figureValue } : {}
6876
+ };
6877
+ }
6878
+ if (value.op === "update_float_meta") {
6879
+ const centered = optionalBoolean(value, "centered");
6880
+ const captionEnabled = optionalBoolean(value, "caption_enabled");
6881
+ const caption = optionalString(value, "caption");
6882
+ const labelEnabled = optionalBoolean(value, "label_enabled");
6883
+ const label = optionalString(value, "label");
6884
+ if (centered === void 0 && captionEnabled === void 0 && caption === void 0 && labelEnabled === void 0 && label === void 0) {
6885
+ throw new Document2CommandError("invalid_command", "update_float_meta requires at least one field");
6886
+ }
6887
+ return {
6888
+ op: value.op,
6889
+ block_id: requireString2(value.block_id, "block_id", false).trim(),
6890
+ ...centered !== void 0 ? { centered } : {},
6891
+ ...captionEnabled !== void 0 ? { caption_enabled: captionEnabled } : {},
6892
+ ...caption !== void 0 ? { caption } : {},
6893
+ ...labelEnabled !== void 0 ? { label_enabled: labelEnabled } : {},
6894
+ ...label !== void 0 ? { label } : {}
6895
+ };
6896
+ }
6520
6897
  if (value.op === "insert_figure") {
6521
6898
  const figureValue = optionalString(value, "value");
6522
6899
  const caption = optionalString(value, "caption");
@@ -6547,7 +6924,10 @@ function parseCommand2(value) {
6547
6924
  if (value.op === "insert_table" || value.op === "replace_table_cell" || value.op === "insert_table_row" || value.op === "remove_table_row" || value.op === "move_table_row" || value.op === "insert_table_column" || value.op === "remove_table_column" || value.op === "move_table_column") {
6548
6925
  return parseTableCommand(value);
6549
6926
  }
6550
- if (value.op === "insert_text_block" || value.op === "replace_text_block" || value.op === "remove_block" || value.op === "insert_figure") {
6927
+ if (value.op === "update_document_meta" || value.op === "insert_reference" || value.op === "update_reference" || value.op === "remove_reference" || value.op === "move_reference") {
6928
+ return parseArticleCommand(value);
6929
+ }
6930
+ if (value.op === "insert_text_block" || value.op === "replace_text_block" || value.op === "remove_block" || value.op === "move_block" || value.op === "insert_figure" || value.op === "update_figure" || value.op === "update_float_meta" || value.op === "insert_bibliography") {
6551
6931
  return parseBasicCommand(value);
6552
6932
  }
6553
6933
  throw new Document2CommandError("invalid_command", "Unsupported document command");
@@ -6600,6 +6980,94 @@ function applyBasicCommand(document2, command) {
6600
6980
  document2.blocks.splice(index, 1);
6601
6981
  return;
6602
6982
  }
6983
+ if (command.op === "move_block") {
6984
+ const index = document2.blocks.findIndex((block3) => block3.id === command.block_id);
6985
+ if (index < 0) {
6986
+ throw new Document2CommandError("block_not_found", "Document block was not found");
6987
+ }
6988
+ const anchorId = "before_block_id" in command.anchor ? command.anchor.before_block_id : "after_block_id" in command.anchor ? command.anchor.after_block_id : null;
6989
+ if (anchorId === command.block_id) {
6990
+ throw new Document2CommandError("invalid_anchor", "A block cannot be moved relative to itself");
6991
+ }
6992
+ if (anchorId !== null) {
6993
+ blockInsertionIndex(document2, command.anchor);
6994
+ }
6995
+ const [block2] = document2.blocks.splice(index, 1);
6996
+ document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block2);
6997
+ return;
6998
+ }
6999
+ if (command.op === "insert_bibliography") {
7000
+ let hasBibliography2 = function(blocks) {
7001
+ return blocks.some((block3) => block3.kind === "bibliography" || block3.kind === "list" && block3.items.some((item) => hasBibliography2(item.blocks)));
7002
+ };
7003
+ var hasBibliography = hasBibliography2;
7004
+ if (hasBibliography2(document2.blocks)) {
7005
+ throw new Document2CommandError("bibliography_exists", "Document already contains a bibliography block");
7006
+ }
7007
+ const block2 = {
7008
+ id: newBlockId(document2),
7009
+ kind: "bibliography",
7010
+ command: "\\begin{thebibliography}",
7011
+ closing: "\\end{thebibliography}",
7012
+ ...command.metadata ? { metadata: { ...command.metadata } } : {}
7013
+ };
7014
+ document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block2);
7015
+ return;
7016
+ }
7017
+ if (command.op === "update_figure") {
7018
+ const block2 = findBlock(document2.blocks, command.block_id);
7019
+ if (!block2) {
7020
+ throw new Document2CommandError("block_not_found", "Document block was not found");
7021
+ }
7022
+ if (block2.kind !== "image") {
7023
+ throw new Document2CommandError("block_kind_mismatch", "Target block is not a figure");
7024
+ }
7025
+ if ("asset_id" in command) {
7026
+ if (command.asset_id === null) {
7027
+ delete block2.assetId;
7028
+ } else {
7029
+ block2.assetId = command.asset_id;
7030
+ }
7031
+ }
7032
+ if (command.value !== void 0) {
7033
+ block2.value = command.value;
7034
+ }
7035
+ return;
7036
+ }
7037
+ if (command.op === "update_float_meta") {
7038
+ const block2 = findBlock(document2.blocks, command.block_id);
7039
+ if (!block2) {
7040
+ throw new Document2CommandError("block_not_found", "Document block was not found");
7041
+ }
7042
+ if (block2.kind !== "image" && block2.kind !== "table") {
7043
+ throw new Document2CommandError("block_kind_mismatch", "Target block is not a figure or table");
7044
+ }
7045
+ let label = command.label;
7046
+ if (label !== void 0) {
7047
+ label = label.trim().length > 0 ? normalizeDocument2Key(label) : "";
7048
+ }
7049
+ if (label !== void 0 && label.length > 0) {
7050
+ const keyError = document2KeyError(label, {
7051
+ references: document2.references,
7052
+ labels: collectDocument2Labels(document2),
7053
+ excludeOwnerId: block2.id
7054
+ });
7055
+ if (keyError === "duplicate") {
7056
+ throw new Document2CommandError("duplicate_key", "Float label is already in use");
7057
+ }
7058
+ if (keyError !== null) {
7059
+ throw new Document2CommandError("invalid_key", "Float label is invalid");
7060
+ }
7061
+ }
7062
+ applyFloatMetaPatch(block2, {
7063
+ ...command.centered !== void 0 ? { centered: command.centered } : {},
7064
+ ...command.caption_enabled !== void 0 ? { captionEnabled: command.caption_enabled } : {},
7065
+ ...command.caption !== void 0 ? { caption: command.caption } : {},
7066
+ ...command.label_enabled !== void 0 ? { labelEnabled: command.label_enabled } : {},
7067
+ ...label !== void 0 ? { label } : {}
7068
+ });
7069
+ return;
7070
+ }
6603
7071
  const block = {
6604
7072
  id: newBlockId(document2),
6605
7073
  kind: "image",
@@ -6623,6 +7091,8 @@ function applyDocument2Command(json, commandInput) {
6623
7091
  applyListCommand(document2, command);
6624
7092
  } else if (isTableCommand(command)) {
6625
7093
  applyTableCommand(document2, command);
7094
+ } else if (isArticleCommand(command)) {
7095
+ applyArticleCommand(document2, command);
6626
7096
  } else {
6627
7097
  applyBasicCommand(document2, command);
6628
7098
  }
@@ -6703,52 +7173,6 @@ function document2Outline(json) {
6703
7173
  });
6704
7174
  }
6705
7175
 
6706
- // src/document2/keys.ts
6707
- var DOCUMENT2_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
6708
- function normalizeDocument2Key(key) {
6709
- return key.normalize("NFC").trim();
6710
- }
6711
- function isValidDocument2Key(key) {
6712
- const normalized = normalizeDocument2Key(key);
6713
- return normalized.length > 0 && DOCUMENT2_KEY_PATTERN.test(normalized);
6714
- }
6715
- function isDuplicateDocument2Key(key, namespace) {
6716
- const normalized = normalizeDocument2Key(key);
6717
- if (normalized.length === 0) {
6718
- return false;
6719
- }
6720
- for (const reference of namespace.references ?? []) {
6721
- if (namespace.excludeReferenceId && reference.id === namespace.excludeReferenceId) {
6722
- continue;
6723
- }
6724
- if (normalizeDocument2Key(reference.key) === normalized) {
6725
- return true;
6726
- }
6727
- }
6728
- for (const label of namespace.labels ?? []) {
6729
- if (namespace.excludeOwnerId && label.ownerId === namespace.excludeOwnerId) {
6730
- continue;
6731
- }
6732
- if (normalizeDocument2Key(label.key) === normalized) {
6733
- return true;
6734
- }
6735
- }
6736
- return false;
6737
- }
6738
- function document2KeyError(key, namespace = {}) {
6739
- const normalized = normalizeDocument2Key(key);
6740
- if (normalized.length === 0) {
6741
- return "empty";
6742
- }
6743
- if (!DOCUMENT2_KEY_PATTERN.test(normalized)) {
6744
- return "invalid";
6745
- }
6746
- if (isDuplicateDocument2Key(normalized, namespace)) {
6747
- return "duplicate";
6748
- }
6749
- return null;
6750
- }
6751
-
6752
7176
  // src/document2/arabicPreamble.ts
6753
7177
  function fontOptions(digitsMapping, includeScript = true) {
6754
7178
  const parts = [];
@@ -7756,6 +8180,7 @@ function blockPreview(block, islands, output, equationSide, document2, previewOp
7756
8180
  src: block.value,
7757
8181
  ...block.assetId !== void 0 ? { assetId: block.assetId } : {},
7758
8182
  options: block.options,
8183
+ centered: block.centered,
7759
8184
  ...block.captionEnabled && block.caption.trim().length > 0 ? { caption: block.caption.trim() } : {},
7760
8185
  ...label.length > 0 ? { label, numberLabel: floatNumberLabel(document2, label, previewOptions) } : {},
7761
8186
  ...block.metadata ? { metadata: { ...block.metadata } } : {}