@drghaliasri/butex 8.0.0 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/document.mjs CHANGED
@@ -2142,6 +2142,15 @@ var ATOMIC_COMMANDS = {
2142
2142
  title: "\u0641\u0631\u0627\u063A \u0633\u0627\u0644\u0628 \u0631\u0641\u064A\u0639",
2143
2143
  spacing: { direction: "negative", level: 1 }
2144
2144
  },
2145
+ thinSpace: {
2146
+ id: "thinSpace",
2147
+ category: "spacing",
2148
+ englishTex: "\\,",
2149
+ arabicTex: "\\,",
2150
+ arabicLabel: "",
2151
+ title: "\u0641\u0631\u0627\u063A \u0631\u0641\u064A\u0639",
2152
+ spacing: { direction: "positive", level: 1 }
2153
+ },
2145
2154
  mediumSpace: {
2146
2155
  id: "mediumSpace",
2147
2156
  category: "spacing",
@@ -3302,6 +3311,10 @@ function renderNodeEnglish(node, options) {
3302
3311
  }
3303
3312
  if (node.kind === "char") {
3304
3313
  if (node.sourceLatex) {
3314
+ if (node.wrapperCommand === "\\boldarabic" || node.wrapperCommand === "\\mathbf") {
3315
+ const boldSource = node.sourceLatex.startsWith("\\mathbf{") ? node.sourceLatex : `\\mathbf{${node.sourceLatex}}`;
3316
+ return `${boldSource}${latinScripts(node, options)}`;
3317
+ }
3305
3318
  return `${node.sourceLatex}${latinScripts(node, options)}`;
3306
3319
  }
3307
3320
  if (node.wrapperCommand) {
@@ -4439,20 +4452,27 @@ function editableWrapperCommand(node) {
4439
4452
  return null;
4440
4453
  }
4441
4454
  const child = singleCommandChar(node);
4442
- if (!child) {
4443
- return null;
4444
- }
4445
- const normalized = normalizeCharImportExpr(child.expr);
4446
- const editorNode = createEditorNode("char", normalized.expr);
4447
- if (normalized.characterFont !== "default") {
4448
- editorNode.characterFont = normalized.characterFont;
4455
+ let editorNode;
4456
+ if (child) {
4457
+ const normalized = normalizeCharImportExpr(child.expr);
4458
+ editorNode = createEditorNode("char", normalized.expr);
4459
+ if (normalized.characterFont !== "default") {
4460
+ editorNode.characterFont = normalized.characterFont;
4461
+ }
4462
+ } else {
4463
+ if (node.optionalArgs.length || node.mandatoryArgs.length !== 1) return null;
4464
+ const nodes = node.mandatoryArgs[0]?.chain;
4465
+ if (!nodes || nodes.length !== 1 || !(nodes[0] instanceof CommandNode)) return null;
4466
+ const nested = charFromTextLikeCommand(nodes[0]);
4467
+ if (!nested?.editable) return null;
4468
+ editorNode = nested.node;
4449
4469
  }
4450
4470
  editorNode.wrapperCommand = node.name === "\\mathtt" ? "\\mathtt" : node.name === "\\mathbf" ? "\\mathbf" : node.name === "\\boldarabic" ? "\\boldarabic" : "\\unit";
4451
4471
  const scripts = attachScripts(node, editorNode);
4452
4472
  if (scripts) {
4453
4473
  return scripts;
4454
4474
  }
4455
- if (!editorNode.sourceLatex && node.name === "\\mathsf") {
4475
+ if (!editorNode.sourceLatex && node.name === "\\mathsf" && child) {
4456
4476
  editorNode.sourceLatex = `\\mathsf{${child.expr}}`;
4457
4477
  }
4458
4478
  return { editable: true, node: editorNode };
@@ -5857,6 +5877,52 @@ function updateDocumentMeta(document2, patch) {
5857
5877
  return next;
5858
5878
  }
5859
5879
 
5880
+ // src/document/keys.ts
5881
+ var DOCUMENT_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
5882
+ function normalizeDocumentKey(key) {
5883
+ return key.normalize("NFC").trim();
5884
+ }
5885
+ function isValidDocumentKey(key) {
5886
+ const normalized = normalizeDocumentKey(key);
5887
+ return normalized.length > 0 && DOCUMENT_KEY_PATTERN.test(normalized);
5888
+ }
5889
+ function isDuplicateDocumentKey(key, namespace) {
5890
+ const normalized = normalizeDocumentKey(key);
5891
+ if (normalized.length === 0) {
5892
+ return false;
5893
+ }
5894
+ for (const reference of namespace.references ?? []) {
5895
+ if (namespace.excludeReferenceId && reference.id === namespace.excludeReferenceId) {
5896
+ continue;
5897
+ }
5898
+ if (normalizeDocumentKey(reference.key) === normalized) {
5899
+ return true;
5900
+ }
5901
+ }
5902
+ for (const label of namespace.labels ?? []) {
5903
+ if (namespace.excludeOwnerId && label.ownerId === namespace.excludeOwnerId) {
5904
+ continue;
5905
+ }
5906
+ if (normalizeDocumentKey(label.key) === normalized) {
5907
+ return true;
5908
+ }
5909
+ }
5910
+ return false;
5911
+ }
5912
+ function documentKeyError(key, namespace = {}) {
5913
+ const normalized = normalizeDocumentKey(key);
5914
+ if (normalized.length === 0) {
5915
+ return "empty";
5916
+ }
5917
+ if (!DOCUMENT_KEY_PATTERN.test(normalized)) {
5918
+ return "invalid";
5919
+ }
5920
+ if (isDuplicateDocumentKey(normalized, namespace)) {
5921
+ return "duplicate";
5922
+ }
5923
+ return null;
5924
+ }
5925
+
5860
5926
  // src/document/jsonCommandTypes.ts
5861
5927
  var DocumentCommandError = class extends Error {
5862
5928
  code;
@@ -5868,6 +5934,22 @@ var DocumentCommandError = class extends Error {
5868
5934
  };
5869
5935
 
5870
5936
  // src/document/jsonCommandHelpers.ts
5937
+ function normalizedNewFloatLabel(document2, label) {
5938
+ if (label === void 0) return void 0;
5939
+ const normalized = label.trim().length > 0 ? normalizeDocumentKey(label) : "";
5940
+ if (!normalized) return "";
5941
+ const error = documentKeyError(normalized, {
5942
+ references: document2.references,
5943
+ labels: collectDocumentLabels(document2)
5944
+ });
5945
+ if (error === "duplicate") {
5946
+ throw new DocumentCommandError("duplicate_key", "Float label is already in use");
5947
+ }
5948
+ if (error !== null) {
5949
+ throw new DocumentCommandError("invalid_key", "Float label is invalid");
5950
+ }
5951
+ return normalized;
5952
+ }
5871
5953
  function isObject3(value) {
5872
5954
  return typeof value === "object" && value !== null && !Array.isArray(value);
5873
5955
  }
@@ -6116,6 +6198,9 @@ function replacePlainField(document2, field, text) {
6116
6198
  "Whole-field replacement is not supported for formatted or structured inline content"
6117
6199
  );
6118
6200
  }
6201
+ if (field.tokens.map((token) => token.kind === "text" ? token.text : "").join("") === text) {
6202
+ return;
6203
+ }
6119
6204
  const next = createCommandInlineField(document2, text);
6120
6205
  field.tokens = next.tokens;
6121
6206
  }
@@ -6135,52 +6220,6 @@ function compactTextTokens2(tokens, emptyTokenId = documentId("text")) {
6135
6220
  return compacted.length > 0 ? compacted : [{ id: emptyTokenId, kind: "text", text: "" }];
6136
6221
  }
6137
6222
 
6138
- // src/document/keys.ts
6139
- var DOCUMENT_KEY_PATTERN = /^[\p{L}\p{M}\p{Nd}:._-]+$/u;
6140
- function normalizeDocumentKey(key) {
6141
- return key.normalize("NFC").trim();
6142
- }
6143
- function isValidDocumentKey(key) {
6144
- const normalized = normalizeDocumentKey(key);
6145
- return normalized.length > 0 && DOCUMENT_KEY_PATTERN.test(normalized);
6146
- }
6147
- function isDuplicateDocumentKey(key, namespace) {
6148
- const normalized = normalizeDocumentKey(key);
6149
- if (normalized.length === 0) {
6150
- return false;
6151
- }
6152
- for (const reference of namespace.references ?? []) {
6153
- if (namespace.excludeReferenceId && reference.id === namespace.excludeReferenceId) {
6154
- continue;
6155
- }
6156
- if (normalizeDocumentKey(reference.key) === normalized) {
6157
- return true;
6158
- }
6159
- }
6160
- for (const label of namespace.labels ?? []) {
6161
- if (namespace.excludeOwnerId && label.ownerId === namespace.excludeOwnerId) {
6162
- continue;
6163
- }
6164
- if (normalizeDocumentKey(label.key) === normalized) {
6165
- return true;
6166
- }
6167
- }
6168
- return false;
6169
- }
6170
- function documentKeyError(key, namespace = {}) {
6171
- const normalized = normalizeDocumentKey(key);
6172
- if (normalized.length === 0) {
6173
- return "empty";
6174
- }
6175
- if (!DOCUMENT_KEY_PATTERN.test(normalized)) {
6176
- return "invalid";
6177
- }
6178
- if (isDuplicateDocumentKey(normalized, namespace)) {
6179
- return "duplicate";
6180
- }
6181
- return null;
6182
- }
6183
-
6184
6223
  // src/document/articleJsonCommands.ts
6185
6224
  var REFERENCE_TEXT_FIELDS = ["authors", "title", "year", "venue", "url"];
6186
6225
  function hasOwn(value, field) {
@@ -6864,6 +6903,7 @@ function parseTableCommand(value) {
6864
6903
  throw new DocumentCommandError("invalid_command", "Unsupported table command");
6865
6904
  }
6866
6905
  function insertTable(document2, command) {
6906
+ const label = normalizedNewFloatLabel(document2, command.label);
6867
6907
  const block = {
6868
6908
  id: newBlockId(document2),
6869
6909
  kind: "table",
@@ -6872,7 +6912,7 @@ function insertTable(document2, command) {
6872
6912
  columns: command.columns,
6873
6913
  rows: command.rows.map((row) => row.map((cell) => createCommandInlineField(document2, cell))),
6874
6914
  ...defaultFloatMeta(),
6875
- ...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
6915
+ ...label !== void 0 ? { label, labelEnabled: label.length > 0 } : {},
6876
6916
  ...command.metadata ? { metadata: { ...command.metadata } } : {}
6877
6917
  };
6878
6918
  if (command.caption !== void 0) {
@@ -7386,12 +7426,12 @@ function applyBasicCommand(document2, command) {
7386
7426
  if (block2.kind !== "image" && block2.kind !== "table") {
7387
7427
  throw new DocumentCommandError("block_kind_mismatch", "Target block is not a figure or table");
7388
7428
  }
7389
- let label = command.label;
7390
- if (label !== void 0) {
7391
- label = label.trim().length > 0 ? normalizeDocumentKey(label) : "";
7429
+ let label2 = command.label;
7430
+ if (label2 !== void 0) {
7431
+ label2 = label2.trim().length > 0 ? normalizeDocumentKey(label2) : "";
7392
7432
  }
7393
- if (label !== void 0 && label.length > 0) {
7394
- const keyError = documentKeyError(label, {
7433
+ if (label2 !== void 0 && label2.length > 0) {
7434
+ const keyError = documentKeyError(label2, {
7395
7435
  references: document2.references,
7396
7436
  labels: collectDocumentLabels(document2),
7397
7437
  excludeOwnerId: block2.id
@@ -7408,10 +7448,11 @@ function applyBasicCommand(document2, command) {
7408
7448
  ...command.caption_enabled !== void 0 ? { captionEnabled: command.caption_enabled } : {},
7409
7449
  ...command.caption !== void 0 ? { caption: command.caption } : {},
7410
7450
  ...command.label_enabled !== void 0 ? { labelEnabled: command.label_enabled } : {},
7411
- ...label !== void 0 ? { label } : {}
7451
+ ...label2 !== void 0 ? { label: label2 } : {}
7412
7452
  });
7413
7453
  return;
7414
7454
  }
7455
+ const label = normalizedNewFloatLabel(document2, command.label);
7415
7456
  const block = {
7416
7457
  id: newBlockId(document2),
7417
7458
  kind: "image",
@@ -7420,7 +7461,7 @@ function applyBasicCommand(document2, command) {
7420
7461
  assetId: command.asset_id,
7421
7462
  options: { width: "0.8\\columnwidth" },
7422
7463
  ...defaultFloatMeta(),
7423
- ...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
7464
+ ...label !== void 0 ? { label, labelEnabled: label.length > 0 } : {},
7424
7465
  ...command.metadata ? { metadata: { ...command.metadata } } : {}
7425
7466
  };
7426
7467
  if (command.caption !== void 0) {