@univerjs/core 1.0.0-alpha.8 → 1.0.0-beta.0

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/lib/cjs/index.js CHANGED
@@ -1498,6 +1498,8 @@ let TextDecoration = /* @__PURE__ */ function(TextDecoration) {
1498
1498
  TextDecoration[TextDecoration["WAVY_DOUBLE"] = 15] = "WAVY_DOUBLE";
1499
1499
  TextDecoration[TextDecoration["WAVY_HEAVY"] = 16] = "WAVY_HEAVY";
1500
1500
  TextDecoration[TextDecoration["WORDS"] = 17] = "WORDS";
1501
+ TextDecoration[TextDecoration["SINGLE_ACCOUNTING"] = 18] = "SINGLE_ACCOUNTING";
1502
+ TextDecoration[TextDecoration["DOUBLE_ACCOUNTING"] = 19] = "DOUBLE_ACCOUNTING";
1501
1503
  return TextDecoration;
1502
1504
  }({});
1503
1505
  /**
@@ -1669,7 +1671,7 @@ let ThemeColors = /* @__PURE__ */ function(ThemeColors) {
1669
1671
  //#endregion
1670
1672
  //#region package.json
1671
1673
  var name = "@univerjs/core";
1672
- var version = "1.0.0-alpha.8";
1674
+ var version = "1.0.0-beta.0";
1673
1675
 
1674
1676
  //#endregion
1675
1677
  //#region src/common/array.ts
@@ -1878,9 +1880,8 @@ var ConfigService = class {
1878
1880
  return this._config.get(id);
1879
1881
  }
1880
1882
  setConfig(id, value, options) {
1881
- var _this$_config$get;
1882
1883
  const { merge: isMerge = false } = options || {};
1883
- let nextValue = (_this$_config$get = this._config.get(id)) !== null && _this$_config$get !== void 0 ? _this$_config$get : {};
1884
+ let nextValue = this._config.get(id) ?? {};
1884
1885
  if (isMerge) nextValue = (0, lodash_es.merge)(nextValue, value);
1885
1886
  else nextValue = value;
1886
1887
  this._config.set(id, nextValue);
@@ -1929,8 +1930,7 @@ var ContextService = class extends Disposable {
1929
1930
  this._contextMap.clear();
1930
1931
  }
1931
1932
  getContextValue(key) {
1932
- var _this$_contextMap$get;
1933
- return (_this$_contextMap$get = this._contextMap.get(key)) !== null && _this$_contextMap$get !== void 0 ? _this$_contextMap$get : false;
1933
+ return this._contextMap.get(key) ?? false;
1934
1934
  }
1935
1935
  setContextValue(key, value) {
1936
1936
  this._contextMap.set(key, value);
@@ -2188,7 +2188,7 @@ let CommandService = class CommandService extends Disposable {
2188
2188
  params
2189
2189
  };
2190
2190
  const stackItemDisposable = this._pushCommandExecutionStack(commandInfo);
2191
- const _options = options !== null && options !== void 0 ? options : {};
2191
+ const _options = options ?? {};
2192
2192
  this._beforeCommandExecutionListeners.forEach((listener) => listener(commandInfo, _options));
2193
2193
  if (this._disposed) {
2194
2194
  stackItemDisposable.dispose();
@@ -2228,13 +2228,12 @@ let CommandService = class CommandService extends Disposable {
2228
2228
  if (command.type === 2) {
2229
2229
  const triggerCommand = findLast(this._commandExecutionStack, (item) => item.type === 0);
2230
2230
  if (triggerCommand) {
2231
- var _commandInfo$params;
2232
- commandInfo.params = (_commandInfo$params = commandInfo.params) !== null && _commandInfo$params !== void 0 ? _commandInfo$params : {};
2231
+ commandInfo.params = commandInfo.params ?? {};
2233
2232
  commandInfo.params.trigger = triggerCommand.id;
2234
2233
  }
2235
2234
  }
2236
2235
  const stackItemDisposable = this._pushCommandExecutionStack(commandInfo);
2237
- const _options = options !== null && options !== void 0 ? options : {};
2236
+ const _options = options ?? {};
2238
2237
  this._beforeCommandExecutionListeners.forEach((listener) => listener(commandInfo, _options));
2239
2238
  if (this._disposed) {
2240
2239
  stackItemDisposable.dispose();
@@ -3322,12 +3321,11 @@ const COLORS = {
3322
3321
  };
3323
3322
  var ColorKit = class ColorKit {
3324
3323
  static mix(color1, color2, amount) {
3325
- var _rgb1$a, _rgb2$a;
3326
3324
  amount = Math.min(1, Math.max(0, amount));
3327
3325
  const rgb1 = new ColorKit(color1).toRgb();
3328
3326
  const rgb2 = new ColorKit(color2).toRgb();
3329
- const alpha1 = (_rgb1$a = rgb1.a) !== null && _rgb1$a !== void 0 ? _rgb1$a : 1;
3330
- const alpha2 = (_rgb2$a = rgb2.a) !== null && _rgb2$a !== void 0 ? _rgb2$a : 1;
3327
+ const alpha1 = rgb1.a ?? 1;
3328
+ const alpha2 = rgb2.a ?? 1;
3331
3329
  const rgba = {
3332
3330
  r: (rgb2.r - rgb1.r) * amount + rgb1.r,
3333
3331
  g: (rgb2.g - rgb1.g) * amount + rgb1.g,
@@ -3432,8 +3430,7 @@ var ColorKit = class ColorKit {
3432
3430
  return (r * 299 + g * 587 + b * 114) / 1e3;
3433
3431
  }
3434
3432
  getAlpha() {
3435
- var _this$_color$a;
3436
- return (_this$_color$a = this._color.a) !== null && _this$_color$a !== void 0 ? _this$_color$a : 1;
3433
+ return this._color.a ?? 1;
3437
3434
  }
3438
3435
  isDark() {
3439
3436
  return this.getBrightness() < 128;
@@ -4025,7 +4022,6 @@ const dateCodes = [
4025
4022
  ["hm", 9]
4026
4023
  ];
4027
4024
  function info(partitions, currencyId = null) {
4028
- var _positive$scale;
4029
4025
  const [partPositive, partNegative] = partitions;
4030
4026
  if (!partPositive) throw new TypeError("Cannot read properties of undefined (reading 'frac_max')");
4031
4027
  const positive = isParsedSection$1(partPositive) ? partPositive : void 0;
@@ -4037,8 +4033,8 @@ function info(partitions, currencyId = null) {
4037
4033
  isDate: isDate(partitions),
4038
4034
  isText: isText(partitions),
4039
4035
  isPercent: isPercent(partitions),
4040
- maxDecimals: (positive === null || positive === void 0 ? void 0 : positive.general) ? 9 : fracMax !== null && fracMax !== void 0 ? fracMax : 0,
4041
- scale: (_positive$scale = positive === null || positive === void 0 ? void 0 : positive.scale) !== null && _positive$scale !== void 0 ? _positive$scale : 1,
4036
+ maxDecimals: (positive === null || positive === void 0 ? void 0 : positive.general) ? 9 : fracMax ?? 0,
4037
+ scale: (positive === null || positive === void 0 ? void 0 : positive.scale) ?? 1,
4042
4038
  color: 0,
4043
4039
  parentheses: 0,
4044
4040
  grouped: (positive === null || positive === void 0 ? void 0 : positive.grouping) ? 1 : 0,
@@ -4121,11 +4117,10 @@ function info(partitions, currencyId = null) {
4121
4117
  return Object.freeze(output);
4122
4118
  }
4123
4119
  function dateInfo(partitions) {
4124
- var _positive$date;
4125
4120
  const [partPositive] = partitions;
4126
4121
  if (!partPositive) throw new TypeError("Cannot read properties of undefined (reading 'date')");
4127
4122
  const positive = isParsedSection$1(partPositive) ? partPositive : void 0;
4128
- const date = (_positive$date = positive === null || positive === void 0 ? void 0 : positive.date) !== null && _positive$date !== void 0 ? _positive$date : 0;
4123
+ const date = (positive === null || positive === void 0 ? void 0 : positive.date) ?? 0;
4129
4124
  return {
4130
4125
  year: !!(date & 2),
4131
4126
  month: !!(date & 4),
@@ -5701,8 +5696,7 @@ function getAbsoluteDecimal(value) {
5701
5696
  } : value;
5702
5697
  }
5703
5698
  function getDecimalExponent(value) {
5704
- var _value$exponent;
5705
- return (_value$exponent = value === null || value === void 0 ? void 0 : value.exponent) !== null && _value$exponent !== void 0 ? _value$exponent : 0;
5699
+ return (value === null || value === void 0 ? void 0 : value.exponent) ?? 0;
5706
5700
  }
5707
5701
  function usesShortestSignificand(value) {
5708
5702
  return !value || value.exponent < -308;
@@ -5888,7 +5882,6 @@ function legacyRound(number, places = 0) {
5888
5882
  return Math.round(number);
5889
5883
  }
5890
5884
  function runPart(value, part, options, locale, decimalValue = null) {
5891
- var _options$grouping$, _options$grouping$2;
5892
5885
  const section = part;
5893
5886
  let renderValue = value;
5894
5887
  let numericValue = value;
@@ -5951,8 +5944,8 @@ function runPart(value, part, options, locale, decimalValue = null) {
5951
5944
  const roundedInteger = Math.abs(Number.isSafeInteger(numericValue) && places === 0 ? numericValue : legacyRound(numericValue, places));
5952
5945
  integer += roundedInteger < 1 ? "" : Math.floor(roundedInteger);
5953
5946
  }
5954
- const primaryGroup = (_options$grouping$ = options.grouping[0]) !== null && _options$grouping$ !== void 0 ? _options$grouping$ : 3;
5955
- const secondaryGroup = (_options$grouping$2 = options.grouping[1]) !== null && _options$grouping$2 !== void 0 ? _options$grouping$2 : primaryGroup;
5947
+ const primaryGroup = options.grouping[0] ?? 3;
5948
+ const secondaryGroup = options.grouping[1] ?? primaryGroup;
5956
5949
  if (section.dec_fractions) fraction = roundedNumber ? roundedNumber.fraction : String(legacyRound(numericValue, section.frac_max)).split(".")[1] || "";
5957
5950
  const fixedSlash = !section.error && (section.num_p.includes("0") || section.den_p.includes("0"));
5958
5951
  let haveFraction = fixedSlash;
@@ -6629,7 +6622,7 @@ function dateToSerial(date, options) {
6629
6622
  let timestamp = null;
6630
6623
  if (Array.isArray(date)) {
6631
6624
  const [year, month, day, hours, minutes, seconds] = date;
6632
- timestamp = dateUTC(year, month == null ? 0 : month - 1, day !== null && day !== void 0 ? day : 1, hours || 0, minutes || 0, seconds || 0);
6625
+ timestamp = dateUTC(year, month == null ? 0 : month - 1, day ?? 1, hours || 0, minutes || 0, seconds || 0);
6633
6626
  } else if (date instanceof Date) {
6634
6627
  timestamp = date.getTime();
6635
6628
  if (!(options === null || options === void 0 ? void 0 : options.ignoreTimezone)) {
@@ -6953,6 +6946,7 @@ function isValidDate(year, month, day) {
6953
6946
  } else if ((month === 4 || month === 6 || month === 9 || month === 11) && day > 30 || (month === 1 || month === 3 || month === 5 || month === 7 || month === 8 || month === 10 || month === 12) && day > 31) return false;
6954
6947
  return true;
6955
6948
  }
6949
+ const dateLocaleLookupCache = /* @__PURE__ */ new WeakMap();
6956
6950
  const matchRec = (string, data, skipPeriod = false) => {
6957
6951
  for (const item of data) if (string.startsWith(item[0])) {
6958
6952
  let length = item[0].length;
@@ -7063,23 +7057,39 @@ const getLookups = (values, symbol) => {
7063
7057
  lookups.sort((a, b) => b[0].length - a[0].length);
7064
7058
  return lookups;
7065
7059
  };
7060
+ const tokensMatch = (values, cachedValues) => values.length === cachedValues.length && values.every((value, index) => value === cachedValues[index]);
7061
+ const getDateLocaleLookups = (locale) => {
7062
+ let cached = dateLocaleLookupCache.get(locale);
7063
+ if (!cached || !tokensMatch(locale.mmmm, cached.mmmm) || !tokensMatch(locale.mmm, cached.mmm) || !tokensMatch(locale.dddd, cached.dddd) || !tokensMatch(locale.ddd, cached.ddd)) {
7064
+ cached = {
7065
+ lookups: {
7066
+ mon: getLookups(locale.mmmm, "F").concat(getLookups(locale.mmm, "M")),
7067
+ mp: locale.mmm[0].endsWith("."),
7068
+ day: getLookups(locale.dddd, "l").concat(getLookups(locale.ddd, "D")),
7069
+ dp: locale.ddd[0].endsWith(".")
7070
+ },
7071
+ mmmm: [...locale.mmmm],
7072
+ mmm: [...locale.mmm],
7073
+ dddd: [...locale.dddd],
7074
+ ddd: [...locale.ddd]
7075
+ };
7076
+ dateLocaleLookupCache.set(locale, cached);
7077
+ }
7078
+ return cached.lookups;
7079
+ };
7066
7080
  /** Parse a date or datetime string and return its serial value and format. */
7067
7081
  function parseDate(value, options = {}) {
7068
- var _date$year, _date$day;
7069
7082
  const l10n = getLocale(options.locale || "") || defaultLocale;
7070
7083
  const localeData = {
7071
- mon: getLookups(l10n.mmmm, "F").concat(getLookups(l10n.mmm, "M")),
7072
- mp: l10n.mmm[0].at(-1) === ".",
7073
- day: getLookups(l10n.dddd, "l").concat(getLookups(l10n.ddd, "D")),
7074
- dp: l10n.ddd[0].at(-1) === ".",
7084
+ ...getDateLocaleLookups(l10n),
7075
7085
  locale: options.locale
7076
7086
  };
7077
7087
  const date = nextToken(normDateStr(value), l10n.preferMDY ? dateTrieMD : dateTrieDM, { path: "" }, localeData);
7078
7088
  if (!date) return null;
7079
7089
  if (date.sep === "." && date.path.length === 3) return null;
7080
7090
  if (date.month == null || date._mon == null) return null;
7081
- const year = +((_date$year = date.year) !== null && _date$year !== void 0 ? _date$year : currentYear);
7082
- const day = (_date$day = date.day) !== null && _date$day !== void 0 ? _date$day : "1";
7091
+ const year = +(date.year ?? currentYear);
7092
+ const day = date.day ?? "1";
7083
7093
  let epoch = -Infinity;
7084
7094
  if (year < 1900) return null;
7085
7095
  else if (year <= 1900 && date.month <= 2) epoch = 25568;
@@ -7144,8 +7154,7 @@ function parseBool(value, options = {}) {
7144
7154
  }
7145
7155
  /** Parse a spreadsheet input as a number, date, time, or boolean. */
7146
7156
  function parseValue(value, options) {
7147
- var _ref, _ref2, _parseNumber;
7148
- return (_ref = (_ref2 = (_parseNumber = parseNumber(value, options)) !== null && _parseNumber !== void 0 ? _parseNumber : parseDate(value, options)) !== null && _ref2 !== void 0 ? _ref2 : parseTime(value, options)) !== null && _ref !== void 0 ? _ref : parseBool(value, options);
7157
+ return parseNumber(value, options) ?? parseDate(value, options) ?? parseTime(value, options) ?? parseBool(value, options);
7149
7158
  }
7150
7159
 
7151
7160
  //#endregion
@@ -7206,19 +7215,17 @@ function prepareFormatterData(pattern, shouldThrow = false) {
7206
7215
  * Formats a value as a string and returns the result.
7207
7216
  */
7208
7217
  function format(pattern, value, options = {}) {
7209
- var _handleDates;
7210
7218
  const resolvedOptions = Object.assign({}, defaultOptions, options);
7211
7219
  const data = prepareFormatterData(pattern, resolvedOptions.throws);
7212
- return formatValue((_handleDates = dateToSerial(value, resolvedOptions)) !== null && _handleDates !== void 0 ? _handleDates : value, data, resolvedOptions);
7220
+ return formatValue(dateToSerial(value, resolvedOptions) ?? value, data, resolvedOptions);
7213
7221
  }
7214
7222
  /**
7215
7223
  * Find the color appropriate to a value as dictated by a format pattern.
7216
7224
  */
7217
7225
  function formatColor(pattern, value, options) {
7218
- var _handleDates2;
7219
7226
  const resolvedOptions = Object.assign({}, defaultOptions, options);
7220
7227
  const data = prepareFormatterData(pattern, resolvedOptions.throws);
7221
- return formatColor$1((_handleDates2 = dateToSerial(value, resolvedOptions)) !== null && _handleDates2 !== void 0 ? _handleDates2 : value, data, resolvedOptions);
7228
+ return formatColor$1(dateToSerial(value, resolvedOptions) ?? value, data, resolvedOptions);
7222
7229
  }
7223
7230
  /** Determine if a given format pattern is a date pattern. */
7224
7231
  function isDateFormat(pattern) {
@@ -7688,8 +7695,7 @@ const CURRENCY_SYMBOL_PREFIX_REG = new RegExp(`^${regexp.charset(...Array.from(n
7688
7695
  * Get the numfmt parse value, and filter out the parse error.
7689
7696
  */
7690
7697
  const getNumfmtParseValueFilter = (value) => {
7691
- var _ref, _parseDate;
7692
- const parseData = (_ref = (_parseDate = parseDate(value)) !== null && _parseDate !== void 0 ? _parseDate : parseTime(value)) !== null && _ref !== void 0 ? _ref : parseNumber(value);
7698
+ const parseData = parseDate(value) ?? parseTime(value) ?? parseNumber(value);
7693
7699
  if (!parseData) return null;
7694
7700
  const { z } = parseData;
7695
7701
  if (z) {
@@ -8408,20 +8414,20 @@ function handleStyleToString(style, isCell = false) {
8408
8414
  ["bd", () => {
8409
8415
  var _style$bd, _style$bd3, _style$bd5, _style$bd7;
8410
8416
  if ((_style$bd = style.bd) === null || _style$bd === void 0 ? void 0 : _style$bd.b) {
8411
- var _style$bd2, _getColorStyle;
8412
- str += `border-bottom: ${getBorderStyle((_style$bd2 = style.bd) === null || _style$bd2 === void 0 ? void 0 : _style$bd2.b.s)} ${(_getColorStyle = getColorStyle(style.bd.b.cl)) !== null && _getColorStyle !== void 0 ? _getColorStyle : ""}; `;
8417
+ var _style$bd2;
8418
+ str += `border-bottom: ${getBorderStyle((_style$bd2 = style.bd) === null || _style$bd2 === void 0 ? void 0 : _style$bd2.b.s)} ${getColorStyle(style.bd.b.cl) ?? ""}; `;
8413
8419
  }
8414
8420
  if ((_style$bd3 = style.bd) === null || _style$bd3 === void 0 ? void 0 : _style$bd3.t) {
8415
- var _style$bd4, _getColorStyle2;
8416
- str += `border-top: ${getBorderStyle((_style$bd4 = style.bd) === null || _style$bd4 === void 0 ? void 0 : _style$bd4.t.s)} ${(_getColorStyle2 = getColorStyle(style.bd.t.cl)) !== null && _getColorStyle2 !== void 0 ? _getColorStyle2 : ""}; `;
8421
+ var _style$bd4;
8422
+ str += `border-top: ${getBorderStyle((_style$bd4 = style.bd) === null || _style$bd4 === void 0 ? void 0 : _style$bd4.t.s)} ${getColorStyle(style.bd.t.cl) ?? ""}; `;
8417
8423
  }
8418
8424
  if ((_style$bd5 = style.bd) === null || _style$bd5 === void 0 ? void 0 : _style$bd5.r) {
8419
- var _style$bd6, _getColorStyle3;
8420
- str += `border-right: ${getBorderStyle((_style$bd6 = style.bd) === null || _style$bd6 === void 0 ? void 0 : _style$bd6.r.s)} ${(_getColorStyle3 = getColorStyle(style.bd.r.cl)) !== null && _getColorStyle3 !== void 0 ? _getColorStyle3 : ""}; `;
8425
+ var _style$bd6;
8426
+ str += `border-right: ${getBorderStyle((_style$bd6 = style.bd) === null || _style$bd6 === void 0 ? void 0 : _style$bd6.r.s)} ${getColorStyle(style.bd.r.cl) ?? ""}; `;
8421
8427
  }
8422
8428
  if ((_style$bd7 = style.bd) === null || _style$bd7 === void 0 ? void 0 : _style$bd7.l) {
8423
- var _style$bd8, _getColorStyle4;
8424
- str += `border-left: ${getBorderStyle((_style$bd8 = style.bd) === null || _style$bd8 === void 0 ? void 0 : _style$bd8.l.s)} ${(_getColorStyle4 = getColorStyle(style.bd.l.cl)) !== null && _getColorStyle4 !== void 0 ? _getColorStyle4 : ""}; `;
8429
+ var _style$bd8;
8430
+ str += `border-left: ${getBorderStyle((_style$bd8 = style.bd) === null || _style$bd8 === void 0 ? void 0 : _style$bd8.l.s)} ${getColorStyle(style.bd.l.cl) ?? ""}; `;
8425
8431
  }
8426
8432
  }],
8427
8433
  ["cl", () => {
@@ -8838,8 +8844,7 @@ function parseDateString(input, isUTC) {
8838
8844
  return new Date(text);
8839
8845
  }
8840
8846
  function normalizeUnit(unit) {
8841
- var _UNIT_ALIASES$unit;
8842
- return (_UNIT_ALIASES$unit = UNIT_ALIASES[unit]) !== null && _UNIT_ALIASES$unit !== void 0 ? _UNIT_ALIASES$unit : UNIT_ALIASES[String(unit).toLowerCase()];
8847
+ return UNIT_ALIASES[unit] ?? UNIT_ALIASES[String(unit).toLowerCase()];
8843
8848
  }
8844
8849
  function daysInMonth(year, month, isUTC) {
8845
8850
  return isUTC ? new Date(Date.UTC(year, month, 0)).getUTCDate() : new Date(year, month, 0).getDate();
@@ -8958,10 +8963,7 @@ function ordinal(value) {
8958
8963
  }
8959
8964
  }
8960
8965
  function replaceLocalizedTokens(template) {
8961
- return template.replace(/LLLL|LLL|LL|L|llll|lll|ll|l/g, (token) => {
8962
- var _LOCALIZED_FORMAT_MAP;
8963
- return (_LOCALIZED_FORMAT_MAP = LOCALIZED_FORMAT_MAP[token]) !== null && _LOCALIZED_FORMAT_MAP !== void 0 ? _LOCALIZED_FORMAT_MAP : token;
8964
- });
8966
+ return template.replace(/LLLL|LLL|LL|L|llll|lll|ll|l/g, (token) => LOCALIZED_FORMAT_MAP[token] ?? token);
8965
8967
  }
8966
8968
  function formatDate(date, template, isUTC) {
8967
8969
  const parts = getDateParts(date, isUTC);
@@ -9003,13 +9005,7 @@ function formatDate(date, template, isUTC) {
9003
9005
  const escapedBlocks = [];
9004
9006
  return replaceLocalizedTokens(template.replace(/\[([^\]]+)]/g, (_, value) => {
9005
9007
  return `\u0000${escapedBlocks.push(value) - 1}\u0000`;
9006
- })).replace(/YYYY|YY|MMMM|MMM|MM|M|DD|Do|D|dddd|ddd|dd|d|HH|H|hh|h|mm|m|ss|s|SSS|A|a|Qo|Q|X|x|ZZ|Z/g, (token) => {
9007
- var _tokenMap$token;
9008
- return (_tokenMap$token = tokenMap[token]) !== null && _tokenMap$token !== void 0 ? _tokenMap$token : token;
9009
- }).replace(/\u0000(\d+)\u0000/g, (_, indexText) => {
9010
- var _escapedBlocks$Number;
9011
- return (_escapedBlocks$Number = escapedBlocks[Number(indexText)]) !== null && _escapedBlocks$Number !== void 0 ? _escapedBlocks$Number : "";
9012
- });
9008
+ })).replace(/YYYY|YY|MMMM|MMM|MM|M|DD|Do|D|dddd|ddd|dd|d|HH|H|hh|h|mm|m|ss|s|SSS|A|a|Qo|Q|X|x|ZZ|Z/g, (token) => tokenMap[token] ?? token).replace(/\u0000(\d+)\u0000/g, (_, indexText) => escapedBlocks[Number(indexText)] ?? "");
9013
9009
  }
9014
9010
  function createDateKit(input) {
9015
9011
  return new DateKitImpl(toDate(input, false), false);
@@ -10668,8 +10664,8 @@ var Range = class Range {
10668
10664
  * Returns the underline of the cells in the range.
10669
10665
  */
10670
10666
  getUnderline() {
10671
- var _this$getValue, _p$body;
10672
- const { p } = (_this$getValue = this.getValue()) !== null && _this$getValue !== void 0 ? _this$getValue : {};
10667
+ var _p$body;
10668
+ const { p } = this.getValue() ?? {};
10673
10669
  if (p && Array.isArray((_p$body = p.body) === null || _p$body === void 0 ? void 0 : _p$body.textRuns) && p.body.textRuns.length > 0) return isAllFormatInTextRuns("ul", p.body) === 1 ? { s: 1 } : { s: 0 };
10674
10670
  return this.getUnderlines()[0][0];
10675
10671
  }
@@ -10689,8 +10685,8 @@ var Range = class Range {
10689
10685
  * Returns the strikeThrough of the cells in the range.
10690
10686
  */
10691
10687
  getStrikeThrough() {
10692
- var _this$getValue2, _p$body2;
10693
- const { p } = (_this$getValue2 = this.getValue()) !== null && _this$getValue2 !== void 0 ? _this$getValue2 : {};
10688
+ var _p$body2;
10689
+ const { p } = this.getValue() ?? {};
10694
10690
  if (p && Array.isArray((_p$body2 = p.body) === null || _p$body2 === void 0 ? void 0 : _p$body2.textRuns) && p.body.textRuns.length > 0) return isAllFormatInTextRuns("st", p.body) === 1 ? { s: 1 } : { s: 0 };
10695
10691
  return this.getStrikeThroughs()[0][0];
10696
10692
  }
@@ -10704,8 +10700,8 @@ var Range = class Range {
10704
10700
  * Returns the font size in point size of the cell in the top-left corner of the range.
10705
10701
  */
10706
10702
  getFontSize() {
10707
- var _this$getValue3, _p$body3;
10708
- const p = ((_this$getValue3 = this.getValue()) === null || _this$getValue3 === void 0 ? void 0 : _this$getValue3.p) || {};
10703
+ var _this$getValue, _p$body3;
10704
+ const p = ((_this$getValue = this.getValue()) === null || _this$getValue === void 0 ? void 0 : _this$getValue.p) || {};
10709
10705
  if (p && Array.isArray((_p$body3 = p.body) === null || _p$body3 === void 0 ? void 0 : _p$body3.textRuns) && p.body.textRuns.length > 0) if (p.body.textRuns.some((textRun) => {
10710
10706
  var _textRun$ts;
10711
10707
  return (textRun === null || textRun === void 0 || (_textRun$ts = textRun.ts) === null || _textRun$ts === void 0 ? void 0 : _textRun$ts.fs) != null;
@@ -10735,8 +10731,8 @@ var Range = class Range {
10735
10731
  * Returns the font style ('italic' or 'normal') of the cell in the top-left corner of the range.
10736
10732
  */
10737
10733
  getFontStyle() {
10738
- var _this$getValue4, _p$body4;
10739
- const { p } = (_this$getValue4 = this.getValue()) !== null && _this$getValue4 !== void 0 ? _this$getValue4 : {};
10734
+ var _p$body4;
10735
+ const { p } = this.getValue() ?? {};
10740
10736
  if (p && Array.isArray((_p$body4 = p.body) === null || _p$body4 === void 0 ? void 0 : _p$body4.textRuns) && p.body.textRuns.length > 0) return isAllFormatInTextRuns("it", p.body) === 1 ? 1 : 0;
10741
10737
  return this._getFontStyles()[0][0];
10742
10738
  }
@@ -10753,8 +10749,8 @@ var Range = class Range {
10753
10749
  * otherwise return FontWeight.NORMAL.
10754
10750
  */
10755
10751
  getFontWeight() {
10756
- var _this$getValue5, _p$body5;
10757
- const { p } = (_this$getValue5 = this.getValue()) !== null && _this$getValue5 !== void 0 ? _this$getValue5 : {};
10752
+ var _p$body5;
10753
+ const { p } = this.getValue() ?? {};
10758
10754
  if (p && Array.isArray((_p$body5 = p.body) === null || _p$body5 === void 0 ? void 0 : _p$body5.textRuns) && p.body.textRuns.length > 0) return isAllFormatInTextRuns("bl", p.body) === 1 ? 1 : 0;
10759
10755
  return this._getFontWeights()[0][0];
10760
10756
  }
@@ -11929,7 +11925,6 @@ function ABCToNumber(a) {
11929
11925
  const orderA = "A".charCodeAt(0);
11930
11926
  "Z".charCodeAt(0);
11931
11927
  const order_a = "a".charCodeAt(0);
11932
- "z".charCodeAt(0);
11933
11928
  /**
11934
11929
  * column subscript number to letters
11935
11930
  * @param n number
@@ -12026,26 +12021,25 @@ let BaseFieldType = /* @__PURE__ */ function(BaseFieldType) {
12026
12021
  BaseFieldType["Checkbox"] = "checkbox";
12027
12022
  BaseFieldType["Link"] = "link";
12028
12023
  BaseFieldType["Formula"] = "formula";
12029
- BaseFieldType["Lookup"] = "lookup";
12030
- BaseFieldType["Flow"] = "flow";
12031
- BaseFieldType["Button"] = "button";
12032
12024
  BaseFieldType["Numbering"] = "numbering";
12033
12025
  BaseFieldType["Phone"] = "phone";
12034
12026
  BaseFieldType["Email"] = "email";
12035
- BaseFieldType["Location"] = "location";
12036
- BaseFieldType["Barcode"] = "barcode";
12037
12027
  BaseFieldType["Progress"] = "progress";
12038
12028
  BaseFieldType["Currency"] = "currency";
12039
12029
  BaseFieldType["Rating"] = "rating";
12040
- BaseFieldType["TwoWayLink"] = "twoWayLink";
12030
+ BaseFieldType["RecordLink"] = "recordLink";
12041
12031
  BaseFieldType["RecordId"] = "recordId";
12042
12032
  BaseFieldType["CreatedBy"] = "createdBy";
12043
12033
  BaseFieldType["UpdatedBy"] = "updatedBy";
12044
12034
  BaseFieldType["CreatedAt"] = "createdAt";
12045
12035
  BaseFieldType["UpdatedAt"] = "updatedAt";
12046
- BaseFieldType["Summary"] = "summary";
12047
12036
  return BaseFieldType;
12048
12037
  }({});
12038
+ /** Semantic roles supported by Base RecordLink fields. */
12039
+ let BaseRecordLinkRole = /* @__PURE__ */ function(BaseRecordLinkRole) {
12040
+ BaseRecordLinkRole["Parent"] = "parent";
12041
+ return BaseRecordLinkRole;
12042
+ }({});
12049
12043
  let BaseViewType = /* @__PURE__ */ function(BaseViewType) {
12050
12044
  BaseViewType["Grid"] = "grid";
12051
12045
  BaseViewType["Kanban"] = "kanban";
@@ -12054,6 +12048,56 @@ let BaseViewType = /* @__PURE__ */ function(BaseViewType) {
12054
12048
  BaseViewType["Gallery"] = "gallery";
12055
12049
  return BaseViewType;
12056
12050
  }({});
12051
+ /** Where a Base conditional color is painted when its condition matches. */
12052
+ const BaseConditionalColorTarget = {
12053
+ /** Paint only the cell in the rule's field. */
12054
+ CELL: "cell",
12055
+ /** Paint the complete record row. */
12056
+ ROW: "row",
12057
+ /** Paint the rule's field column unconditionally; operator, operand, and date mode are ignored. */
12058
+ COLUMN: "column"
12059
+ };
12060
+ /**
12061
+ * Operators supported by Base conditional coloring rules.
12062
+ *
12063
+ * Text, select, person, and similar fields support equality, containment, and
12064
+ * empty checks. Number, currency, progress, and rating fields support equality,
12065
+ * numeric comparison, and empty checks. Date-like fields support equality,
12066
+ * before/after, and empty checks. Checkbox fields support equality only.
12067
+ */
12068
+ const BaseConditionalColorOperator = {
12069
+ IS: "is",
12070
+ IS_NOT: "isNot",
12071
+ CONTAINS: "contains",
12072
+ NOT_CONTAINS: "notContains",
12073
+ IS_EMPTY: "isEmpty",
12074
+ IS_NOT_EMPTY: "isNotEmpty",
12075
+ GREATER_THAN: "greaterThan",
12076
+ LESS_THAN: "lessThan",
12077
+ BEFORE: "before",
12078
+ AFTER: "after"
12079
+ };
12080
+ /**
12081
+ * Relative or exact date windows supported by date conditional coloring rules.
12082
+ *
12083
+ * With `IS`, dates inside the selected window match. `IS_NOT` matches dates
12084
+ * outside it, `BEFORE` matches dates before its start, and `AFTER` matches
12085
+ * dates after its end. Relative windows do not use an operand; `EXACT` does.
12086
+ */
12087
+ const BaseConditionalDateMode = {
12088
+ EXACT: "exact",
12089
+ TODAY: "today",
12090
+ TOMORROW: "tomorrow",
12091
+ YESTERDAY: "yesterday",
12092
+ THIS_WEEK: "thisWeek",
12093
+ LAST_WEEK: "lastWeek",
12094
+ THIS_MONTH: "thisMonth",
12095
+ LAST_MONTH: "lastMonth",
12096
+ PAST_7_DAYS: "past7",
12097
+ NEXT_7_DAYS: "next7",
12098
+ PAST_30_DAYS: "past30",
12099
+ NEXT_30_DAYS: "next30"
12100
+ };
12057
12101
  let BaseFilterOperator = /* @__PURE__ */ function(BaseFilterOperator) {
12058
12102
  BaseFilterOperator["IS"] = "is";
12059
12103
  BaseFilterOperator["IS_NOT"] = "isNot";
@@ -12079,18 +12123,58 @@ let BaseSortDirection = /* @__PURE__ */ function(BaseSortDirection) {
12079
12123
  BaseSortDirection["DESC"] = "desc";
12080
12124
  return BaseSortDirection;
12081
12125
  }({});
12126
+ /** Why a stored Parent link cannot participate in the effective hierarchy. */
12127
+ let BaseHierarchyInvalidReason = /* @__PURE__ */ function(BaseHierarchyInvalidReason) {
12128
+ BaseHierarchyInvalidReason["MissingParent"] = "missingParent";
12129
+ BaseHierarchyInvalidReason["SelfParent"] = "selfParent";
12130
+ BaseHierarchyInvalidReason["Cycle"] = "cycle";
12131
+ BaseHierarchyInvalidReason["MaxDepth"] = "maxDepth";
12132
+ return BaseHierarchyInvalidReason;
12133
+ }({});
12134
+
12135
+ //#endregion
12136
+ //#region src/bases/record-identity.ts
12137
+ const BASE_RECORD_ID_FIELD_ID = "__record_id";
12138
+ const BASE_RECORD_ID_FIELD_NAME = "record-id";
12139
+ const BASE_RECORD_ID_PATTERN = /^[A-Za-z0-9_-]+$/;
12140
+ function createBaseRecordIdField() {
12141
+ return {
12142
+ id: BASE_RECORD_ID_FIELD_ID,
12143
+ name: BASE_RECORD_ID_FIELD_NAME,
12144
+ type: "recordId",
12145
+ config: {},
12146
+ system: true,
12147
+ readonly: true
12148
+ };
12149
+ }
12150
+ function isValidBaseRecordId(recordId) {
12151
+ return BASE_RECORD_ID_PATTERN.test(recordId);
12152
+ }
12153
+ function isBaseRecordIdFieldName(name) {
12154
+ return name.trim().toLowerCase() === BASE_RECORD_ID_FIELD_NAME;
12155
+ }
12156
+ function assertBaseTableRecordIdentity(table) {
12157
+ const recordIdField = table.fields[BASE_RECORD_ID_FIELD_ID];
12158
+ const recordIdFields = Object.values(table.fields).filter((field) => field.type === "recordId");
12159
+ if (!recordIdField || recordIdFields.length !== 1 || recordIdField.type !== "recordId" || recordIdField.name !== "record-id" || recordIdField.system !== true || recordIdField.readonly !== true || table.fieldOrder[0] !== "__record_id" || table.primaryFieldId === "__record_id" || !table.fields[table.primaryFieldId]) throw new Error(`[BaseDataModel]: table "${table.id}" has an invalid record-id system field.`);
12160
+ const conflictingField = Object.values(table.fields).find((field) => {
12161
+ return field.id !== "__record_id" && isBaseRecordIdFieldName(field.name);
12162
+ });
12163
+ if (conflictingField) throw new Error(`[BaseDataModel]: field name "${conflictingField.name}" is reserved for the record-id system field.`);
12164
+ for (const [recordKey, record] of Object.entries(table.records)) if (record.id !== recordKey || !isValidBaseRecordId(record.id) || record.values["__record_id"] !== record.id) throw new Error(`[BaseDataModel]: record "${recordKey}" has an invalid record-id projection.`);
12165
+ }
12082
12166
 
12083
12167
  //#endregion
12084
12168
  //#region src/bases/empty-snapshot.ts
12085
12169
  function createDefaultBaseTableSnapshot(options) {
12086
- var _options$now, _options$primaryField, _options$gridViewId, _options$recordCount, _options$primaryField2;
12087
- const now = (_options$now = options.now) !== null && _options$now !== void 0 ? _options$now : Date.now();
12088
- const primaryFieldId = (_options$primaryField = options.primaryFieldId) !== null && _options$primaryField !== void 0 ? _options$primaryField : generateRandomId(6);
12089
- const gridViewId = (_options$gridViewId = options.gridViewId) !== null && _options$gridViewId !== void 0 ? _options$gridViewId : generateRandomId(6);
12090
- const recordCount = (_options$recordCount = options.recordCount) !== null && _options$recordCount !== void 0 ? _options$recordCount : 5;
12170
+ const now = options.now ?? Date.now();
12171
+ const primaryFieldId = options.primaryFieldId ?? generateRandomId(6);
12172
+ const gridViewId = options.gridViewId ?? generateRandomId(6);
12173
+ const recordCount = options.recordCount ?? 0;
12174
+ const recordIdField = createBaseRecordIdField();
12091
12175
  const primaryField = {
12092
12176
  id: primaryFieldId,
12093
- name: (_options$primaryField2 = options.primaryFieldName) !== null && _options$primaryField2 !== void 0 ? _options$primaryField2 : "Name",
12177
+ name: options.primaryFieldName ?? "Name",
12094
12178
  type: "text",
12095
12179
  config: { placeholder: "bases.fieldConfig.textPlaceholder" }
12096
12180
  };
@@ -12103,7 +12187,7 @@ function createDefaultBaseTableSnapshot(options) {
12103
12187
  const recordId = `${options.id}-record-${index + 1}`;
12104
12188
  records[recordId] = {
12105
12189
  id: recordId,
12106
- values: {},
12190
+ values: { [BASE_RECORD_ID_FIELD_ID]: recordId },
12107
12191
  orderKey: String(index + 1).padStart(4, "0"),
12108
12192
  createdAt: now,
12109
12193
  updatedAt: now
@@ -12111,29 +12195,41 @@ function createDefaultBaseTableSnapshot(options) {
12111
12195
  recordOrder.push(recordId);
12112
12196
  rowIndex[recordId] = index;
12113
12197
  rowId[index] = recordId;
12114
- cellData[index] = {};
12198
+ cellData[index] = { 0: {
12199
+ v: recordId,
12200
+ t: 1
12201
+ } };
12115
12202
  }
12116
12203
  const gridView = {
12117
12204
  id: gridViewId,
12118
12205
  tableId: options.id,
12119
12206
  name: "Grid",
12120
12207
  type: "grid",
12121
- fieldOrder: [primaryFieldId],
12122
- fieldSettings: {},
12208
+ fieldOrder: [BASE_RECORD_ID_FIELD_ID, primaryFieldId],
12209
+ fieldSettings: { [BASE_RECORD_ID_FIELD_ID]: { hidden: true } },
12123
12210
  config: { frozenFieldCount: 1 }
12124
12211
  };
12125
12212
  return {
12126
12213
  id: options.id,
12127
12214
  name: options.name,
12128
12215
  primaryFieldId,
12129
- fieldOrder: [primaryFieldId],
12130
- fields: { [primaryFieldId]: primaryField },
12216
+ fieldOrder: [BASE_RECORD_ID_FIELD_ID, primaryFieldId],
12217
+ fields: {
12218
+ [BASE_RECORD_ID_FIELD_ID]: recordIdField,
12219
+ [primaryFieldId]: primaryField
12220
+ },
12131
12221
  records,
12132
12222
  recordOrder,
12133
12223
  rowIndex,
12134
12224
  rowId,
12135
- colIndex: { [primaryFieldId]: 0 },
12136
- colId: { 0: primaryFieldId },
12225
+ colIndex: {
12226
+ [BASE_RECORD_ID_FIELD_ID]: 0,
12227
+ [primaryFieldId]: 1
12228
+ },
12229
+ colId: {
12230
+ 0: BASE_RECORD_ID_FIELD_ID,
12231
+ 1: primaryFieldId
12232
+ },
12137
12233
  cellData,
12138
12234
  resources: {
12139
12235
  attachmentSets: {},
@@ -12151,13 +12247,13 @@ function getEmptySnapshot(unitId = generateRandomId(), name = "", locale = "zhCN
12151
12247
  name,
12152
12248
  locale,
12153
12249
  appVersion: version,
12154
- schemaVersion: 1,
12250
+ schemaVersion: 2,
12155
12251
  tableOrder: [tableId],
12156
12252
  tables: { [tableId]: createDefaultBaseTableSnapshot({
12157
12253
  id: tableId,
12158
12254
  name: "Table 1",
12159
12255
  now,
12160
- recordCount: 5
12256
+ recordCount: 0
12161
12257
  }) },
12162
12258
  createdAt: now,
12163
12259
  updatedAt: now
@@ -12211,8 +12307,7 @@ var BaseDataModel = class extends UnitModel {
12211
12307
  this._name$.next(snapshot.name);
12212
12308
  }
12213
12309
  getRev() {
12214
- var _this$_snapshot$rev;
12215
- return (_this$_snapshot$rev = this._snapshot.rev) !== null && _this$_snapshot$rev !== void 0 ? _this$_snapshot$rev : 1;
12310
+ return this._snapshot.rev ?? 1;
12216
12311
  }
12217
12312
  incrementRev() {
12218
12313
  this._snapshot.rev = this.getRev() + 1;
@@ -12226,27 +12321,28 @@ var BaseDataModel = class extends UnitModel {
12226
12321
  }
12227
12322
  };
12228
12323
  function normalizeBaseSnapshot(snapshot) {
12229
- var _snapshot$tables;
12230
12324
  delete snapshot.compress;
12231
12325
  delete snapshot.kind;
12232
- Object.values((_snapshot$tables = snapshot.tables) !== null && _snapshot$tables !== void 0 ? _snapshot$tables : {}).forEach((table) => {
12326
+ Object.values(snapshot.tables ?? {}).forEach((table) => {
12327
+ assertBaseTableRecordIdentity(table);
12233
12328
  normalizeBaseTable(table);
12329
+ assertMaterializedRecordIdentity(table);
12234
12330
  });
12235
12331
  return snapshot;
12236
12332
  }
12237
12333
  function isNormalizedBaseSnapshot(snapshot) {
12238
- var _snapshot$tables2;
12239
- return Object.values((_snapshot$tables2 = snapshot.tables) !== null && _snapshot$tables2 !== void 0 ? _snapshot$tables2 : {}).every((table) => isNormalizedBaseTable(table));
12334
+ return Object.values(snapshot.tables ?? {}).every((table) => isNormalizedBaseTable(table));
12240
12335
  }
12241
12336
  function isNormalizedBaseTable(table) {
12242
- var _table$records, _table$fields;
12243
- const records = (_table$records = table.records) !== null && _table$records !== void 0 ? _table$records : {};
12244
- const fields = (_table$fields = table.fields) !== null && _table$fields !== void 0 ? _table$fields : {};
12337
+ const records = table.records ?? {};
12338
+ const fields = table.fields ?? {};
12339
+ assertBaseTableRecordIdentity(table);
12245
12340
  if (!Array.isArray(table.recordOrder) || !table.rowIndex || !table.rowId || !table.colIndex || !table.colId || !table.cellData || !table.resources || !table.resources.attachmentSets || !table.resources.attachments) return false;
12246
12341
  if (Object.keys(records).length !== table.recordOrder.length) return false;
12247
12342
  for (let index = 0; index < table.recordOrder.length; index++) {
12343
+ var _table$cellData$index;
12248
12344
  const recordId = table.recordOrder[index];
12249
- if (!records[recordId] || table.rowIndex[recordId] !== index || table.rowId[index] !== recordId) return false;
12345
+ if (!records[recordId] || table.rowIndex[recordId] !== index || table.rowId[index] !== recordId || ((_table$cellData$index = table.cellData[index]) === null || _table$cellData$index === void 0 || (_table$cellData$index = _table$cellData$index[0]) === null || _table$cellData$index === void 0 ? void 0 : _table$cellData$index.v) !== recordId) return false;
12250
12346
  }
12251
12347
  for (let index = 0; index < table.fieldOrder.length; index++) {
12252
12348
  const fieldId = table.fieldOrder[index];
@@ -12256,10 +12352,9 @@ function isNormalizedBaseTable(table) {
12256
12352
  return true;
12257
12353
  }
12258
12354
  function normalizeBaseTable(table) {
12259
- var _table$records2, _table$fields2;
12260
12355
  hydrateCompressedCellData(table);
12261
- const records = (_table$records2 = table.records) !== null && _table$records2 !== void 0 ? _table$records2 : {};
12262
- const fields = (_table$fields2 = table.fields) !== null && _table$fields2 !== void 0 ? _table$fields2 : {};
12356
+ const records = table.records ?? {};
12357
+ const fields = table.fields ?? {};
12263
12358
  const orderedRecordIds = getOrderedRecordIds(table, records);
12264
12359
  const orderedFieldIds = getOrderedFieldIds(table, fields);
12265
12360
  table.recordOrder = orderedRecordIds;
@@ -12274,8 +12369,7 @@ function hydrateCompressedCellData(table) {
12274
12369
  if (compressedCellData && !table.cellData) {
12275
12370
  table.cellData = Object.create(null);
12276
12371
  compressedCellData.forEach(([row, col, cell]) => {
12277
- var _row;
12278
- table.cellData[row] = (_row = table.cellData[row]) !== null && _row !== void 0 ? _row : {};
12372
+ table.cellData[row] = table.cellData[row] ?? {};
12279
12373
  const { c: _compressed, ...cellData } = cell;
12280
12374
  table.cellData[row][col] = cellData;
12281
12375
  });
@@ -12283,8 +12377,8 @@ function hydrateCompressedCellData(table) {
12283
12377
  }
12284
12378
  }
12285
12379
  function getOrderedRecordIds(table, records) {
12286
- var _table$recordOrder$fi, _table$recordOrder;
12287
- const orderedRecordIds = (_table$recordOrder$fi = (_table$recordOrder = table.recordOrder) === null || _table$recordOrder === void 0 ? void 0 : _table$recordOrder.filter((recordId) => records[recordId])) !== null && _table$recordOrder$fi !== void 0 ? _table$recordOrder$fi : [];
12380
+ var _table$recordOrder;
12381
+ const orderedRecordIds = ((_table$recordOrder = table.recordOrder) === null || _table$recordOrder === void 0 ? void 0 : _table$recordOrder.filter((recordId) => records[recordId])) ?? [];
12288
12382
  const orderedRecordIdSet = new Set(orderedRecordIds);
12289
12383
  const missingRecords = Object.values(records).filter((record) => !orderedRecordIdSet.has(record.id));
12290
12384
  if (!missingRecords.length) return orderedRecordIds;
@@ -12304,12 +12398,10 @@ function cloneBaseTableMutableMaps(table) {
12304
12398
  table.resources.attachments = { ...table.resources.attachments };
12305
12399
  }
12306
12400
  function normalizeExistingCellData(table, fields) {
12307
- var _table$cellData;
12308
- Object.entries((_table$cellData = table.cellData) !== null && _table$cellData !== void 0 ? _table$cellData : {}).forEach(([rowKey, rowData]) => {
12309
- var _row2;
12401
+ Object.entries(table.cellData ?? {}).forEach(([rowKey, rowData]) => {
12310
12402
  const row = Number(rowKey);
12311
12403
  table.cellData[row] = { ...rowData };
12312
- Object.entries((_row2 = table.cellData[row]) !== null && _row2 !== void 0 ? _row2 : {}).forEach(([colKey, cell]) => {
12404
+ Object.entries(table.cellData[row] ?? {}).forEach(([colKey, cell]) => {
12313
12405
  var _table$colId;
12314
12406
  const col = Number(colKey);
12315
12407
  const fieldId = (_table$colId = table.colId) === null || _table$colId === void 0 ? void 0 : _table$colId[col];
@@ -12318,44 +12410,58 @@ function normalizeExistingCellData(table, fields) {
12318
12410
  });
12319
12411
  }
12320
12412
  function rebuildRowIndexes(table, records, orderedRecordIds) {
12321
- var _table$rowIndex;
12322
12413
  orderedRecordIds.forEach((recordId, index) => {
12323
12414
  if (table.rowIndex[recordId] == null) table.rowIndex[recordId] = index;
12324
12415
  });
12325
- Object.entries((_table$rowIndex = table.rowIndex) !== null && _table$rowIndex !== void 0 ? _table$rowIndex : {}).forEach(([recordId, row]) => {
12416
+ Object.entries(table.rowIndex ?? {}).forEach(([recordId, row]) => {
12326
12417
  if (records[recordId]) table.rowId[row] = recordId;
12327
12418
  });
12328
12419
  }
12329
12420
  function rebuildColumnIndexes(table, fields, orderedFieldIds) {
12330
- var _table$colIndex;
12331
12421
  orderedFieldIds.forEach((fieldId, index) => {
12332
12422
  if (table.colIndex[fieldId] == null) table.colIndex[fieldId] = index;
12333
12423
  });
12334
- Object.entries((_table$colIndex = table.colIndex) !== null && _table$colIndex !== void 0 ? _table$colIndex : {}).forEach(([fieldId, col]) => {
12424
+ Object.entries(table.colIndex ?? {}).forEach(([fieldId, col]) => {
12335
12425
  if (fields[fieldId]) table.colId[col] = fieldId;
12336
12426
  });
12337
12427
  }
12338
12428
  function hydrateRecordCellData(table, records, fields) {
12429
+ const rowIndex = table.rowIndex ?? {};
12430
+ const colIndex = table.colIndex ?? {};
12431
+ const cellData = table.cellData ?? {};
12432
+ table.rowIndex = rowIndex;
12433
+ table.colIndex = colIndex;
12434
+ table.cellData = cellData;
12339
12435
  Object.values(records).forEach((record) => {
12340
- var _record$values;
12341
- const row = table.rowIndex[record.id];
12436
+ const row = rowIndex[record.id];
12342
12437
  if (row == null) return;
12343
- table.cellData[row] = { ...table.cellData[row] };
12344
- Object.entries((_record$values = record.values) !== null && _record$values !== void 0 ? _record$values : {}).forEach(([fieldId, value]) => {
12438
+ cellData[row] = { ...cellData[row] };
12439
+ cellData[row][0] = {
12440
+ v: record.id,
12441
+ t: 1
12442
+ };
12443
+ Object.entries(record.values ?? {}).forEach(([fieldId, value]) => {
12345
12444
  const field = fields[fieldId];
12346
12445
  if ((field === null || field === void 0 ? void 0 : field.type) === "attachment") writeAttachmentResources(table, record.id, fieldId, value);
12347
- const col = table.colIndex[fieldId];
12446
+ const col = colIndex[fieldId];
12348
12447
  if (col == null) return;
12349
- const existingCell = table.cellData[row][col];
12448
+ const existingCell = cellData[row][col];
12350
12449
  if (existingCell != null) {
12351
- table.cellData[row][col] = normalizeBaseCellData(existingCell, field);
12352
- if (shouldRefreshCellDataFromRecord(existingCell, field, value)) table.cellData[row][col] = toBaseCellData(value, field);
12450
+ cellData[row][col] = normalizeBaseCellData(existingCell, field);
12451
+ if (shouldRefreshCellDataFromRecord(existingCell, field, value)) cellData[row][col] = toBaseCellData(value, field);
12353
12452
  return;
12354
12453
  }
12355
- table.cellData[row][col] = toBaseCellData(value, field);
12454
+ cellData[row][col] = toBaseCellData(value, field);
12356
12455
  });
12357
12456
  });
12358
12457
  }
12458
+ function assertMaterializedRecordIdentity(table) {
12459
+ for (const record of Object.values(table.records)) {
12460
+ var _table$rowIndex, _table$colIndex, _table$colId2, _table$cellData;
12461
+ const row = (_table$rowIndex = table.rowIndex) === null || _table$rowIndex === void 0 ? void 0 : _table$rowIndex[record.id];
12462
+ if (row == null || ((_table$colIndex = table.colIndex) === null || _table$colIndex === void 0 ? void 0 : _table$colIndex["__record_id"]) !== 0 || ((_table$colId2 = table.colId) === null || _table$colId2 === void 0 ? void 0 : _table$colId2[0]) !== "__record_id" || ((_table$cellData = table.cellData) === null || _table$cellData === void 0 || (_table$cellData = _table$cellData[row]) === null || _table$cellData === void 0 || (_table$cellData = _table$cellData[0]) === null || _table$cellData === void 0 ? void 0 : _table$cellData.v) !== record.id) throw new Error(`[BaseDataModel]: record "${record.id}" is missing its record-id cell projection.`);
12463
+ }
12464
+ }
12359
12465
  function toBaseCellData(value, field) {
12360
12466
  if (isBaseCellData(value)) {
12361
12467
  if ((field === null || field === void 0 ? void 0 : field.type) === "attachment") return {
@@ -12374,10 +12480,9 @@ function toBaseCellData(value, field) {
12374
12480
  t: 1
12375
12481
  };
12376
12482
  if ((field === null || field === void 0 ? void 0 : field.type) === "link" && value && typeof value === "object" && !Array.isArray(value)) {
12377
- var _ref, _link$text;
12378
12483
  const link = value;
12379
12484
  return {
12380
- v: String((_ref = (_link$text = link.text) !== null && _link$text !== void 0 ? _link$text : link.url) !== null && _ref !== void 0 ? _ref : ""),
12485
+ v: String(link.text ?? link.url ?? ""),
12381
12486
  t: 1
12382
12487
  };
12383
12488
  }
@@ -12411,8 +12516,7 @@ function writeAttachmentResources(table, recordId, fieldId, value) {
12411
12516
  table.resources.attachments = { ...table.resources.attachments };
12412
12517
  const key = `${fieldId}${BASE_ATTACHMENT_RESOURCE_KEY_SEPARATOR}${recordId}`;
12413
12518
  table.resources.attachmentSets[key] = attachments.map((attachment, index) => {
12414
- var _attachment$id;
12415
- const id = String((_attachment$id = attachment.id) !== null && _attachment$id !== void 0 ? _attachment$id : `${key}${BASE_ATTACHMENT_RESOURCE_KEY_SEPARATOR}${index}`);
12519
+ const id = String(attachment.id ?? `${key}${BASE_ATTACHMENT_RESOURCE_KEY_SEPARATOR}${index}`);
12416
12520
  const normalizedAttachment = {
12417
12521
  ...attachment,
12418
12522
  id
@@ -12441,6 +12545,7 @@ function normalizeAttachmentValue(value) {
12441
12545
  return attachments;
12442
12546
  }
12443
12547
  function shouldRefreshCellDataFromRecord(cell, field, value) {
12548
+ if ((field === null || field === void 0 ? void 0 : field.type) === "recordId") return cell.v !== value;
12444
12549
  if ((field === null || field === void 0 ? void 0 : field.type) === "attachment") return cell.v !== "";
12445
12550
  if (isListField(field)) return Array.isArray(value) && (cell.v == null || cell.v === "");
12446
12551
  return false;
@@ -12469,9 +12574,8 @@ function primitiveText(value) {
12469
12574
  if (value == null) return "";
12470
12575
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") return String(value);
12471
12576
  if (typeof value === "object") {
12472
- var _ref2, _ref3, _record$id;
12473
12577
  const record = value;
12474
- return String((_ref2 = (_ref3 = (_record$id = record.id) !== null && _record$id !== void 0 ? _record$id : record.name) !== null && _ref3 !== void 0 ? _ref3 : record.text) !== null && _ref2 !== void 0 ? _ref2 : "");
12578
+ return String(record.id ?? record.name ?? record.text ?? "");
12475
12579
  }
12476
12580
  return String(value);
12477
12581
  }
@@ -12483,7 +12587,7 @@ function inferPrimitiveType(value) {
12483
12587
  }
12484
12588
  function normalizeBaseCellValueType(type, value) {
12485
12589
  if (type === 1 || type === 2 || type === 3 || type === 4 || type == null) return type;
12486
- return inferPrimitiveType(value !== null && value !== void 0 ? value : null);
12590
+ return inferPrimitiveType(value ?? null);
12487
12591
  }
12488
12592
 
12489
12593
  //#endregion
@@ -12653,10 +12757,7 @@ var InterceptorManager = class {
12653
12757
  if (!this._interceptorsByName.has(key)) this._interceptorsByName.set(key, []);
12654
12758
  const interceptors = this._interceptorsByName.get(key);
12655
12759
  interceptors.push(interceptor);
12656
- this._interceptorsByName.set(key, interceptors.sort((a, b) => {
12657
- var _b$priority, _a$priority;
12658
- return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
12659
- }));
12760
+ this._interceptorsByName.set(key, interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)));
12660
12761
  return () => remove(this._interceptorsByName.get(key), interceptor);
12661
12762
  }
12662
12763
  getInterceptPoints() {
@@ -12712,10 +12813,7 @@ var AsyncInterceptorManager = class {
12712
12813
  if (!this._asyncInterceptorsByName.has(key)) this._asyncInterceptorsByName.set(key, []);
12713
12814
  const interceptors = this._asyncInterceptorsByName.get(key);
12714
12815
  interceptors.push(interceptor);
12715
- this._asyncInterceptorsByName.set(key, interceptors.sort((a, b) => {
12716
- var _b$priority2, _a$priority2;
12717
- return ((_b$priority2 = b.priority) !== null && _b$priority2 !== void 0 ? _b$priority2 : 0) - ((_a$priority2 = a.priority) !== null && _a$priority2 !== void 0 ? _a$priority2 : 0);
12718
- }));
12816
+ this._asyncInterceptorsByName.set(key, interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)));
12719
12817
  return () => remove(this._asyncInterceptorsByName.get(key), interceptor);
12720
12818
  }
12721
12819
  getInterceptPoints() {
@@ -13108,10 +13206,9 @@ function createParagraphId(existingIds) {
13108
13206
  return paragraphId;
13109
13207
  }
13110
13208
  function cloneBodyWithFreshParagraphIds(body, _scope) {
13111
- var _cloned$paragraphs;
13112
13209
  const cloned = cloneBody(body);
13113
13210
  const existingIds = /* @__PURE__ */ new Set();
13114
- for (const paragraph of (_cloned$paragraphs = cloned.paragraphs) !== null && _cloned$paragraphs !== void 0 ? _cloned$paragraphs : []) paragraph.paragraphId = createParagraphId(existingIds);
13211
+ for (const paragraph of cloned.paragraphs ?? []) paragraph.paragraphId = createParagraphId(existingIds);
13115
13212
  return cloned;
13116
13213
  }
13117
13214
  function cloneParagraphWithId(paragraph, existingIds, preserveId) {
@@ -13483,13 +13580,12 @@ function normalizeTextRuns(textRuns, reserveEmptyTextRun = false) {
13483
13580
  * @param currentIndex Determining the index where the content will be inserted into the current content.
13484
13581
  */
13485
13582
  function insertTextRuns(body, insertBody, textLength, currentIndex) {
13486
- var _insertBody$textRuns;
13487
13583
  const { textRuns } = body;
13488
13584
  if (textRuns == null) return;
13489
13585
  const newTextRuns = [];
13490
13586
  const len = textRuns.length;
13491
13587
  let hasInserted = false;
13492
- const insertTextRuns = (_insertBody$textRuns = insertBody.textRuns) !== null && _insertBody$textRuns !== void 0 ? _insertBody$textRuns : [];
13588
+ const insertTextRuns = insertBody.textRuns ?? [];
13493
13589
  if (insertTextRuns.length) for (const insertTextRun of insertTextRuns) {
13494
13590
  insertTextRun.st += currentIndex;
13495
13591
  insertTextRun.ed += currentIndex;
@@ -13537,9 +13633,9 @@ function insertTextRuns(body, insertBody, textLength, currentIndex) {
13537
13633
  * @param currentIndex Determining the index where the content will be inserted into the current content.
13538
13634
  */
13539
13635
  function insertParagraphs(body, insertBody, textLength, currentIndex, preserveMissingParagraphIds = false, originalDataStream = body.dataStream) {
13540
- var _insertBody$paragraph, _body$paragraphs;
13636
+ var _insertBody$paragraph;
13541
13637
  if (!body.paragraphs && !((_insertBody$paragraph = insertBody.paragraphs) === null || _insertBody$paragraph === void 0 ? void 0 : _insertBody$paragraph.length)) return;
13542
- (_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 || (body.paragraphs = []);
13638
+ body.paragraphs ??= [];
13543
13639
  const { paragraphs } = body;
13544
13640
  const { paragraphs: insertParagraphs } = insertBody;
13545
13641
  normalizeInsertedParagraphIdsForDocument(paragraphs, insertParagraphs, currentIndex, {
@@ -13572,7 +13668,6 @@ function insertParagraphs(body, insertBody, textLength, currentIndex, preserveMi
13572
13668
  }
13573
13669
  }
13574
13670
  function normalizeInsertedParagraphIdsForDocument(paragraphs, insertParagraphs, currentIndex, options) {
13575
- var _options$reservedPara;
13576
13671
  if (!paragraphs || !(insertParagraphs === null || insertParagraphs === void 0 ? void 0 : insertParagraphs.length)) return;
13577
13672
  const splitParagraph = getParagraphSplitByInsert(paragraphs, currentIndex, options.dataStream);
13578
13673
  const firstSplitInsertIndex = splitParagraph ? getFirstInsertedParagraphIndex(insertParagraphs) : -1;
@@ -13582,12 +13677,11 @@ function normalizeInsertedParagraphIdsForDocument(paragraphs, insertParagraphs,
13582
13677
  const existingParagraphIds = collectParagraphIds(paragraphs);
13583
13678
  const preservedInsertedParagraphIds = /* @__PURE__ */ new Set();
13584
13679
  if (splitParagraphId) existingParagraphIds.delete(splitParagraphId);
13585
- for (const paragraphId of (_options$reservedPara = options.reservedParagraphIds) !== null && _options$reservedPara !== void 0 ? _options$reservedPara : []) existingParagraphIds.add(paragraphId);
13680
+ for (const paragraphId of options.reservedParagraphIds ?? []) existingParagraphIds.add(paragraphId);
13586
13681
  let splitRemainderParagraph;
13587
13682
  if (splitParagraphId && firstSplitInsertIndex !== -1 && !shouldPreserveExplicitSplitParagraphId) {
13588
- var _options$preserveMiss;
13589
13683
  const firstInsertParagraph = insertParagraphs[firstSplitInsertIndex];
13590
- splitRemainderParagraph = firstInsertedParagraphId != null && firstInsertedParagraphId !== splitParagraphId ? cloneInsertedParagraphWithId(firstInsertParagraph, existingParagraphIds, (_options$preserveMiss = options.preserveMissingParagraphIds) !== null && _options$preserveMiss !== void 0 ? _options$preserveMiss : false) : cloneParagraphWithId(firstInsertParagraph, existingParagraphIds, false);
13684
+ splitRemainderParagraph = firstInsertedParagraphId != null && firstInsertedParagraphId !== splitParagraphId ? cloneInsertedParagraphWithId(firstInsertParagraph, existingParagraphIds, options.preserveMissingParagraphIds ?? false) : cloneParagraphWithId(firstInsertParagraph, existingParagraphIds, false);
13591
13685
  if (options.freshenSplitParagraph && splitRemainderParagraph.paragraphId) splitParagraph.paragraphId = splitRemainderParagraph.paragraphId;
13592
13686
  }
13593
13687
  for (let i = 0, len = insertParagraphs.length; i < len; i++) {
@@ -13598,8 +13692,7 @@ function normalizeInsertedParagraphIdsForDocument(paragraphs, insertParagraphs,
13598
13692
  continue;
13599
13693
  }
13600
13694
  if (i !== firstSplitInsertIndex || splitParagraphId == null || shouldPreserveExplicitSplitParagraphId) {
13601
- var _options$preserveMiss2;
13602
- insertParagraphs[i] = cloneInsertedParagraphWithId(insertParagraphs[i], existingParagraphIds, (_options$preserveMiss2 = options.preserveMissingParagraphIds) !== null && _options$preserveMiss2 !== void 0 ? _options$preserveMiss2 : false);
13695
+ insertParagraphs[i] = cloneInsertedParagraphWithId(insertParagraphs[i], existingParagraphIds, options.preserveMissingParagraphIds ?? false);
13603
13696
  continue;
13604
13697
  }
13605
13698
  insertParagraphs[i] = options.freshenSplitParagraph || firstInsertedParagraphId == null || firstInsertedParagraphId === splitParagraphId ? cloneParagraphWithId({
@@ -13608,13 +13701,13 @@ function normalizeInsertedParagraphIdsForDocument(paragraphs, insertParagraphs,
13608
13701
  }, existingParagraphIds) : splitRemainderParagraph;
13609
13702
  }
13610
13703
  for (const insertParagraph of insertParagraphs) if (insertParagraph.paragraphId) {
13611
- var _options$reservedPara2;
13612
- (_options$reservedPara2 = options.reservedParagraphIds) === null || _options$reservedPara2 === void 0 || _options$reservedPara2.add(insertParagraph.paragraphId);
13704
+ var _options$reservedPara;
13705
+ (_options$reservedPara = options.reservedParagraphIds) === null || _options$reservedPara === void 0 || _options$reservedPara.add(insertParagraph.paragraphId);
13613
13706
  }
13614
13707
  }
13615
13708
  function collectParagraphIds(paragraphs) {
13616
13709
  const paragraphIds = /* @__PURE__ */ new Set();
13617
- for (const paragraph of paragraphs !== null && paragraphs !== void 0 ? paragraphs : []) if (paragraph.paragraphId) paragraphIds.add(paragraph.paragraphId);
13710
+ for (const paragraph of paragraphs ?? []) if (paragraph.paragraphId) paragraphIds.add(paragraph.paragraphId);
13618
13711
  return paragraphIds;
13619
13712
  }
13620
13713
  function cloneInsertedParagraphWithId(insertParagraph, existingParagraphIds, preserveMissingParagraphIds) {
@@ -13655,9 +13748,9 @@ function getFirstInsertedParagraphIndex(insertParagraphs) {
13655
13748
  return index;
13656
13749
  }
13657
13750
  function insertSectionBreaks(body, insertBody, textLength, currentIndex) {
13658
- var _insertBody$sectionBr, _body$sectionBreaks;
13751
+ var _insertBody$sectionBr;
13659
13752
  if (!body.sectionBreaks && !((_insertBody$sectionBr = insertBody.sectionBreaks) === null || _insertBody$sectionBr === void 0 ? void 0 : _insertBody$sectionBr.length)) return;
13660
- (_body$sectionBreaks = body.sectionBreaks) !== null && _body$sectionBreaks !== void 0 || (body.sectionBreaks = []);
13753
+ body.sectionBreaks ??= [];
13661
13754
  const { sectionBreaks } = body;
13662
13755
  const insertSectionBreaks = insertBody.sectionBreaks;
13663
13756
  normalizeInsertedSectionIdsForDocument(sectionBreaks, insertSectionBreaks);
@@ -13684,9 +13777,8 @@ function insertSectionBreaks(body, insertBody, textLength, currentIndex) {
13684
13777
  }
13685
13778
  }
13686
13779
  function normalizeInsertedSectionIdsForDocument(sectionBreaks, insertSectionBreaks, reservedSectionIds = /* @__PURE__ */ new Set()) {
13687
- var _sectionBreaks$map;
13688
13780
  if (!(insertSectionBreaks === null || insertSectionBreaks === void 0 ? void 0 : insertSectionBreaks.length)) return;
13689
- const existingSectionIds = new Set((_sectionBreaks$map = sectionBreaks === null || sectionBreaks === void 0 ? void 0 : sectionBreaks.map((sectionBreak) => sectionBreak.sectionId)) !== null && _sectionBreaks$map !== void 0 ? _sectionBreaks$map : []);
13781
+ const existingSectionIds = new Set((sectionBreaks === null || sectionBreaks === void 0 ? void 0 : sectionBreaks.map((sectionBreak) => sectionBreak.sectionId)) ?? []);
13690
13782
  for (const sectionId of reservedSectionIds) existingSectionIds.add(sectionId);
13691
13783
  for (let i = 0; i < insertSectionBreaks.length; i++) {
13692
13784
  insertSectionBreaks[i] = cloneSectionBreakWithId(insertSectionBreaks[i], existingSectionIds);
@@ -14740,7 +14832,7 @@ function updateParagraphs(body, updateBody, textLength, currentIndex, coverType)
14740
14832
  if (updateStartIndex === removeStartIndex) {
14741
14833
  splitUpdateParagraphs.push({
14742
14834
  startIndex: updateStartIndex,
14743
- paragraphId: updateParagraphId !== null && updateParagraphId !== void 0 ? updateParagraphId : removeParagraphId,
14835
+ paragraphId: updateParagraphId ?? removeParagraphId,
14744
14836
  paragraphStyle: newParagraphStyle,
14745
14837
  bullet: newBullet
14746
14838
  });
@@ -15010,7 +15102,7 @@ function isSegmentIntersects(start, end, start2, end2) {
15010
15102
  }
15011
15103
  function getParagraphsInRange(activeRange, paragraphs, dataStream, paragraphRanges) {
15012
15104
  const { startOffset, endOffset } = activeRange;
15013
- const fullParagraphs = paragraphRanges !== null && paragraphRanges !== void 0 ? paragraphRanges : transformParagraphs(paragraphs, dataStream);
15105
+ const fullParagraphs = paragraphRanges ?? transformParagraphs(paragraphs, dataStream);
15014
15106
  const results = [];
15015
15107
  let start = -1;
15016
15108
  for (let i = 0; i < fullParagraphs.length; i++) {
@@ -15058,10 +15150,10 @@ function transformParagraphs(paragraphs, dataStream) {
15058
15150
  //#endregion
15059
15151
  //#region src/docs/data-model/text-x/build-utils/paragraph.ts
15060
15152
  const switchParagraphBullet = (params) => {
15061
- var _docDataModel$getSelf, _docDataModel$getSelf2;
15153
+ var _docDataModel$getSelf;
15062
15154
  const { paragraphs: currentParagraphs, segmentId, document: docDataModel } = params;
15063
15155
  let listType = params.listType;
15064
- const paragraphs = (_docDataModel$getSelf = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 || (_docDataModel$getSelf2 = _docDataModel$getSelf2.getBody()) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.paragraphs) !== null && _docDataModel$getSelf !== void 0 ? _docDataModel$getSelf : [];
15156
+ const paragraphs = ((_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 || (_docDataModel$getSelf = _docDataModel$getSelf.getBody()) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.paragraphs) ?? [];
15065
15157
  const isAlreadyList = currentParagraphs.every((paragraph) => {
15066
15158
  var _paragraph$bullet;
15067
15159
  return ((_paragraph$bullet = paragraph.bullet) === null || _paragraph$bullet === void 0 ? void 0 : _paragraph$bullet.listType.indexOf(listType)) === 0;
@@ -15083,7 +15175,6 @@ const switchParagraphBullet = (params) => {
15083
15175
  memoryCursor.reset();
15084
15176
  const textX = new TextX();
15085
15177
  for (const paragraph of currentParagraphs) {
15086
- var _bullet$nestingLevel;
15087
15178
  const { startIndex, paragraphId, paragraphStyle = {}, bullet } = paragraph;
15088
15179
  textX.push({
15089
15180
  t: "r",
@@ -15103,7 +15194,7 @@ const switchParagraphBullet = (params) => {
15103
15194
  paragraphId,
15104
15195
  paragraphStyle: { ...paragraphStyle },
15105
15196
  bullet: {
15106
- nestingLevel: (_bullet$nestingLevel = bullet === null || bullet === void 0 ? void 0 : bullet.nestingLevel) !== null && _bullet$nestingLevel !== void 0 ? _bullet$nestingLevel : 0,
15197
+ nestingLevel: (bullet === null || bullet === void 0 ? void 0 : bullet.nestingLevel) ?? 0,
15107
15198
  textStyle: { fs: 20 },
15108
15199
  listType,
15109
15200
  listId
@@ -15117,9 +15208,9 @@ const switchParagraphBullet = (params) => {
15117
15208
  return textX;
15118
15209
  };
15119
15210
  const toggleChecklistParagraph = (params) => {
15120
- var _docDataModel$getSelf3;
15211
+ var _docDataModel$getSelf2;
15121
15212
  const { paragraphIndex, segmentId, document: docDataModel } = params;
15122
- const paragraphs = (_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 || (_docDataModel$getSelf3 = _docDataModel$getSelf3.getBody()) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.paragraphs;
15213
+ const paragraphs = (_docDataModel$getSelf2 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf2 === void 0 || (_docDataModel$getSelf2 = _docDataModel$getSelf2.getBody()) === null || _docDataModel$getSelf2 === void 0 ? void 0 : _docDataModel$getSelf2.paragraphs;
15123
15214
  if (paragraphs == null) return false;
15124
15215
  const currentParagraph = paragraphs.find((p) => p.startIndex === paragraphIndex);
15125
15216
  if (!(currentParagraph === null || currentParagraph === void 0 ? void 0 : currentParagraph.bullet) || currentParagraph.bullet.listType.indexOf("CHECK_LIST") === -1) return false;
@@ -15153,15 +15244,14 @@ const toggleChecklistParagraph = (params) => {
15153
15244
  return textX;
15154
15245
  };
15155
15246
  const setParagraphBullet = (params) => {
15156
- var _docDataModel$getSelf4;
15247
+ var _docDataModel$getSelf3;
15157
15248
  const { paragraphs: currentParagraphs, listType, listId: explicitListId, segmentId, document: docDataModel } = params;
15158
- if (((_docDataModel$getSelf4 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf4 === void 0 || (_docDataModel$getSelf4 = _docDataModel$getSelf4.getBody()) === null || _docDataModel$getSelf4 === void 0 ? void 0 : _docDataModel$getSelf4.paragraphs) == null) return false;
15159
- const listId = explicitListId !== null && explicitListId !== void 0 ? explicitListId : generateRandomId(6);
15249
+ if (((_docDataModel$getSelf3 = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf3 === void 0 || (_docDataModel$getSelf3 = _docDataModel$getSelf3.getBody()) === null || _docDataModel$getSelf3 === void 0 ? void 0 : _docDataModel$getSelf3.paragraphs) == null) return false;
15250
+ const listId = explicitListId ?? generateRandomId(6);
15160
15251
  const memoryCursor = new MemoryCursor();
15161
15252
  memoryCursor.reset();
15162
15253
  const textX = new TextX();
15163
15254
  for (const paragraph of currentParagraphs) {
15164
- var _bullet$nestingLevel2;
15165
15255
  const { startIndex, paragraphId, paragraphStyle = {}, bullet } = paragraph;
15166
15256
  textX.push({
15167
15257
  t: "r",
@@ -15177,7 +15267,7 @@ const setParagraphBullet = (params) => {
15177
15267
  paragraphId,
15178
15268
  paragraphStyle,
15179
15269
  bullet: {
15180
- nestingLevel: (_bullet$nestingLevel2 = bullet === null || bullet === void 0 ? void 0 : bullet.nestingLevel) !== null && _bullet$nestingLevel2 !== void 0 ? _bullet$nestingLevel2 : 0,
15270
+ nestingLevel: (bullet === null || bullet === void 0 ? void 0 : bullet.nestingLevel) ?? 0,
15181
15271
  textStyle: (bullet === null || bullet === void 0 ? void 0 : bullet.listType) === listType ? bullet.textStyle : { fs: 20 },
15182
15272
  listType,
15183
15273
  listId
@@ -15212,17 +15302,15 @@ const PARAGRAPH_CONTAINER_TOKENS = /* @__PURE__ */ new Set([
15212
15302
  ""
15213
15303
  ]);
15214
15304
  function getParagraphContentStartOffset(body, paragraph) {
15215
- var _body$paragraphs;
15216
15305
  let previousParagraph;
15217
- for (const candidate of (_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []) if (candidate.startIndex < paragraph.startIndex && (!previousParagraph || candidate.startIndex > previousParagraph.startIndex)) previousParagraph = candidate;
15306
+ for (const candidate of body.paragraphs ?? []) if (candidate.startIndex < paragraph.startIndex && (!previousParagraph || candidate.startIndex > previousParagraph.startIndex)) previousParagraph = candidate;
15218
15307
  let startOffset = previousParagraph ? previousParagraph.startIndex + 1 : 0;
15219
15308
  while (startOffset < paragraph.startIndex && PARAGRAPH_CONTAINER_TOKENS.has(body.dataStream[startOffset])) startOffset++;
15220
15309
  return startOffset;
15221
15310
  }
15222
15311
  function getParagraphContentStartOffsets(body) {
15223
- var _body$paragraphs2;
15224
15312
  const startOffsets = /* @__PURE__ */ new Map();
15225
- const paragraphs = [...(_body$paragraphs2 = body.paragraphs) !== null && _body$paragraphs2 !== void 0 ? _body$paragraphs2 : []].sort((left, right) => left.startIndex - right.startIndex);
15313
+ const paragraphs = [...body.paragraphs ?? []].sort((left, right) => left.startIndex - right.startIndex);
15226
15314
  for (let index = 0; index < paragraphs.length; index++) {
15227
15315
  const paragraph = paragraphs[index];
15228
15316
  let startOffset = index > 0 ? paragraphs[index - 1].startIndex + 1 : 0;
@@ -15232,21 +15320,20 @@ function getParagraphContentStartOffsets(body) {
15232
15320
  return startOffsets;
15233
15321
  }
15234
15322
  function getParagraphFollowingBlockOffset(body, paragraph) {
15235
- var _body$blockRanges;
15236
- const containingBlock = ((_body$blockRanges = body.blockRanges) !== null && _body$blockRanges !== void 0 ? _body$blockRanges : []).find((blockRange) => {
15323
+ const containingBlock = (body.blockRanges ?? []).find((blockRange) => {
15237
15324
  const interval = getBlockRangeInterval(blockRange);
15238
15325
  return paragraph.startIndex > interval.startOffset && paragraph.startIndex < interval.endOffset - 1;
15239
15326
  });
15240
15327
  return containingBlock ? getBlockRangeInterval(containingBlock).endOffset : paragraph.startIndex + 1;
15241
15328
  }
15242
15329
  const changeParagraphBulletNestLevel = (params) => {
15243
- var _docDataModel$getSnap, _docDataModel$getBody, _docDataModel$getBody2;
15330
+ var _docDataModel$getBody;
15244
15331
  const { paragraphs: currentParagraphs, document: docDataModel, type } = params;
15245
15332
  const memoryCursor = new MemoryCursor();
15246
15333
  memoryCursor.reset();
15247
15334
  const textX = new TextX();
15248
- const customLists = (_docDataModel$getSnap = docDataModel.getSnapshot().lists) !== null && _docDataModel$getSnap !== void 0 ? _docDataModel$getSnap : {};
15249
- const tables = (_docDataModel$getBody = (_docDataModel$getBody2 = docDataModel.getBody()) === null || _docDataModel$getBody2 === void 0 ? void 0 : _docDataModel$getBody2.tables) !== null && _docDataModel$getBody !== void 0 ? _docDataModel$getBody : [];
15335
+ const customLists = docDataModel.getSnapshot().lists ?? {};
15336
+ const tables = ((_docDataModel$getBody = docDataModel.getBody()) === null || _docDataModel$getBody === void 0 ? void 0 : _docDataModel$getBody.tables) ?? [];
15250
15337
  const lists = {
15251
15338
  ...PRESET_LIST_TYPE,
15252
15339
  ...customLists
@@ -15287,13 +15374,13 @@ const changeParagraphBulletNestLevel = (params) => {
15287
15374
  return textX;
15288
15375
  };
15289
15376
  const setParagraphStyle = (params) => {
15290
- var _segment$getBody$para, _segment$getBody, _segment$getBody$data, _segment$getBody2;
15377
+ var _segment$getBody, _segment$getBody2;
15291
15378
  const { textRanges, segmentId, document: docDataModel, style, paragraphTextRun, cursor, deleteLen, textX: _textX } = params;
15292
15379
  const segment = docDataModel.getSelfOrHeaderFooterModel(segmentId);
15293
- const currentParagraphs = getParagraphsInRanges(textRanges, (_segment$getBody$para = segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) !== null && _segment$getBody$para !== void 0 ? _segment$getBody$para : [], (_segment$getBody$data = segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) !== null && _segment$getBody$data !== void 0 ? _segment$getBody$data : "");
15380
+ const currentParagraphs = getParagraphsInRanges(textRanges, (segment === null || segment === void 0 || (_segment$getBody = segment.getBody()) === null || _segment$getBody === void 0 ? void 0 : _segment$getBody.paragraphs) ?? [], (segment === null || segment === void 0 || (_segment$getBody2 = segment.getBody()) === null || _segment$getBody2 === void 0 ? void 0 : _segment$getBody2.dataStream) ?? "");
15294
15381
  const memoryCursor = new MemoryCursor();
15295
15382
  if (cursor) memoryCursor.moveCursorTo(cursor);
15296
- const textX = _textX !== null && _textX !== void 0 ? _textX : new TextX();
15383
+ const textX = _textX ?? new TextX();
15297
15384
  currentParagraphs.sort((a, b) => a.startIndex - b.startIndex);
15298
15385
  const start = Math.max(0, currentParagraphs[0].paragraphStart - 1);
15299
15386
  if (start > memoryCursor.cursor) {
@@ -15457,8 +15544,7 @@ function getParagraphsSlice(body, startOffset, endOffset, type = 1) {
15457
15544
  const sortedParagraphs = [...paragraphs].sort((a, b) => a.startIndex - b.startIndex);
15458
15545
  const paragraphStartOffsets = getParagraphContentStartOffsets(body);
15459
15546
  for (const paragraph of sortedParagraphs) {
15460
- var _paragraphStartOffset;
15461
- const paragraphStart = (_paragraphStartOffset = paragraphStartOffsets.get(paragraph.startIndex)) !== null && _paragraphStartOffset !== void 0 ? _paragraphStartOffset : 0;
15547
+ const paragraphStart = paragraphStartOffsets.get(paragraph.startIndex) ?? 0;
15462
15548
  const paragraphEnd = paragraph.startIndex;
15463
15549
  if (paragraphEnd >= startOffset && paragraphEnd < endOffset || Math.max(paragraphStart, startOffset) < Math.min(paragraphEnd, endOffset)) {
15464
15550
  const copy = Tools.deepClone(paragraph);
@@ -15609,11 +15695,11 @@ function getCustomDecorationSlice(body, startOffset, endOffset) {
15609
15695
  return customDecorationSlice;
15610
15696
  }
15611
15697
  function composeTextRuns(updateDataTextRuns, originTextRuns, coverType) {
15612
- if (updateDataTextRuns == null || originTextRuns == null) return updateDataTextRuns !== null && updateDataTextRuns !== void 0 ? updateDataTextRuns : originTextRuns;
15698
+ if (updateDataTextRuns == null || originTextRuns == null) return updateDataTextRuns ?? originTextRuns;
15613
15699
  return coverTextRuns(updateDataTextRuns, originTextRuns, coverType);
15614
15700
  }
15615
15701
  function composeCustomRanges(updateDataCustomRanges, originCustomRanges, coverType) {
15616
- if (updateDataCustomRanges == null || originCustomRanges == null) return updateDataCustomRanges !== null && updateDataCustomRanges !== void 0 ? updateDataCustomRanges : originCustomRanges;
15702
+ if (updateDataCustomRanges == null || originCustomRanges == null) return updateDataCustomRanges ?? originCustomRanges;
15617
15703
  if (originCustomRanges.length === 0 || updateDataCustomRanges.length === 0) return updateDataCustomRanges;
15618
15704
  if (originCustomRanges.length > 1 || updateDataCustomRanges.length > 1) throw new Error("Cannot cover multiple customRanges");
15619
15705
  if (coverType === 1) return [{ ...updateDataCustomRanges[0] }];
@@ -16442,7 +16528,7 @@ const isEmptyDocument = (dataStream) => {
16442
16528
  return getPlainText(dataStream).replaceAll("\r", "") === "";
16443
16529
  };
16444
16530
  const fromPlainText = (text) => {
16445
- const dataStream = text.replace(/\n/g, "\r");
16531
+ const dataStream = text.replace(/\r\n?|\n/g, "\r");
16446
16532
  const paragraphs = [];
16447
16533
  const existingParagraphIds = /* @__PURE__ */ new Set();
16448
16534
  const customRanges = [];
@@ -16518,18 +16604,16 @@ var DocumentDataModelSimple = class extends UnitModel {
16518
16604
  throw new Error("Method not implemented.");
16519
16605
  }
16520
16606
  constructor(snapshot) {
16521
- var _this$snapshot$title;
16522
16607
  super();
16523
16608
  _defineProperty(this, "type", _univerjs_protocol.UniverType.UNIVER_DOC);
16524
16609
  _defineProperty(this, "_name$", new rxjs.BehaviorSubject(""));
16525
16610
  _defineProperty(this, "name$", this._name$.asObservable());
16526
16611
  _defineProperty(this, "snapshot", void 0);
16527
16612
  this.snapshot = createDocumentSnapshot(snapshot);
16528
- this._name$.next((_this$snapshot$title = this.snapshot.title) !== null && _this$snapshot$title !== void 0 ? _this$snapshot$title : "No Title");
16613
+ this._name$.next(this.snapshot.title ?? "No Title");
16529
16614
  }
16530
16615
  getRev() {
16531
- var _this$snapshot$rev;
16532
- return (_this$snapshot$rev = this.snapshot.rev) !== null && _this$snapshot$rev !== void 0 ? _this$snapshot$rev : 1;
16616
+ return this.snapshot.rev ?? 1;
16533
16617
  }
16534
16618
  incrementRev() {
16535
16619
  this.snapshot.rev = this.getRev() + 1;
@@ -16565,8 +16649,7 @@ var DocumentDataModelSimple = class extends UnitModel {
16565
16649
  return this.snapshot;
16566
16650
  }
16567
16651
  getBulletPresetList() {
16568
- var _this$snapshot$lists;
16569
- const customLists = (_this$snapshot$lists = this.snapshot.lists) !== null && _this$snapshot$lists !== void 0 ? _this$snapshot$lists : {};
16652
+ const customLists = this.snapshot.lists ?? {};
16570
16653
  return {
16571
16654
  ...PRESET_LIST_TYPE,
16572
16655
  ...customLists
@@ -16605,8 +16688,8 @@ var DocumentDataModelSimple = class extends UnitModel {
16605
16688
  const { documentStyle } = this.snapshot;
16606
16689
  if (!documentStyle.pageSize) {
16607
16690
  documentStyle.pageSize = {
16608
- width: width !== null && width !== void 0 ? width : Number.POSITIVE_INFINITY,
16609
- height: height !== null && height !== void 0 ? height : Number.POSITIVE_INFINITY
16691
+ width: width ?? Number.POSITIVE_INFINITY,
16692
+ height: height ?? Number.POSITIVE_INFINITY
16610
16693
  };
16611
16694
  return;
16612
16695
  }
@@ -16640,16 +16723,15 @@ var DocumentDataModelSimple = class extends UnitModel {
16640
16723
  };
16641
16724
  var DocumentDataModel = class DocumentDataModel extends DocumentDataModelSimple {
16642
16725
  constructor(snapshot) {
16643
- var _this$snapshot$id, _this$snapshot$title2;
16644
16726
  super(Tools.isEmptyObject(snapshot) ? getEmptySnapshot$1() : snapshot);
16645
16727
  _defineProperty(this, "_unitId", void 0);
16646
16728
  _defineProperty(this, "headerModelMap", /* @__PURE__ */ new Map());
16647
16729
  _defineProperty(this, "footerModelMap", /* @__PURE__ */ new Map());
16648
16730
  _defineProperty(this, "change$", new rxjs.BehaviorSubject(0));
16649
16731
  const UNIT_ID_LENGTH = 6;
16650
- this._unitId = (_this$snapshot$id = this.snapshot.id) !== null && _this$snapshot$id !== void 0 ? _this$snapshot$id : generateRandomId(UNIT_ID_LENGTH);
16732
+ this._unitId = this.snapshot.id ?? generateRandomId(UNIT_ID_LENGTH);
16651
16733
  this._initializeHeaderFooterModel();
16652
- this._name$.next((_this$snapshot$title2 = this.snapshot.title) !== null && _this$snapshot$title2 !== void 0 ? _this$snapshot$title2 : "");
16734
+ this._name$.next(this.snapshot.title ?? "");
16653
16735
  }
16654
16736
  dispose() {
16655
16737
  super.dispose();
@@ -16727,8 +16809,8 @@ var DocumentDataModel = class DocumentDataModel extends DocumentDataModelSimple
16727
16809
  this._unitId = unitId;
16728
16810
  }
16729
16811
  getPlainText() {
16730
- var _this$getBody$dataStr, _this$getBody;
16731
- return getPlainText((_this$getBody$dataStr = (_this$getBody = this.getBody()) === null || _this$getBody === void 0 ? void 0 : _this$getBody.dataStream) !== null && _this$getBody$dataStr !== void 0 ? _this$getBody$dataStr : "");
16812
+ var _this$getBody;
16813
+ return getPlainText(((_this$getBody = this.getBody()) === null || _this$getBody === void 0 ? void 0 : _this$getBody.dataStream) ?? "");
16732
16814
  }
16733
16815
  };
16734
16816
 
@@ -16758,8 +16840,7 @@ function _resolveNamedParagraphStyle(styles, styleId) {
16758
16840
  return resolve(styleId);
16759
16841
  }
16760
16842
  function resolveDocumentParagraphStyle(documentStyle, paragraphStyle, options = {}) {
16761
- var _options$useLegacyMod, _definedParagraphStyl;
16762
- const legacyStyle = ((_options$useLegacyMod = options.useLegacyModernDefaults) !== null && _options$useLegacyMod !== void 0 ? _options$useLegacyMod : (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.documentFlavor) === 2) ? {
16843
+ const legacyStyle = options.useLegacyModernDefaults ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.documentFlavor) === 2 ? {
16763
16844
  lineSpacing: DEFAULT_DOCUMENT_PARAGRAPH_LINE_SPACING,
16764
16845
  spaceAbove: { v: 0 },
16765
16846
  spaceBelow: { v: 12 }
@@ -16775,7 +16856,7 @@ function resolveDocumentParagraphStyle(documentStyle, paragraphStyle, options =
16775
16856
  }
16776
16857
  const definedParagraphStyle = _definedStyle(paragraphStyle);
16777
16858
  const referencedParagraphStyle = _resolveNamedParagraphStyle(options.styles, options.paragraphStyleId);
16778
- const namedStyleType = (_definedParagraphStyl = definedParagraphStyle.namedStyleType) !== null && _definedParagraphStyl !== void 0 ? _definedParagraphStyl : referencedParagraphStyle.namedStyleType;
16859
+ const namedStyleType = definedParagraphStyle.namedStyleType ?? referencedParagraphStyle.namedStyleType;
16779
16860
  const namedStyle = namedStyleType == null ? null : NAMED_STYLE_SPACE_MAP[namedStyleType];
16780
16861
  return Tools.deepClone({
16781
16862
  ...documentDefaults,
@@ -16941,10 +17022,10 @@ function getIntersectingCustomRanges(startIndex, endIndex, customRanges, rangeTy
16941
17022
  return relativeCustomRanges;
16942
17023
  }
16943
17024
  function getSelectionForAddCustomRange(range, body) {
16944
- var _body$customRanges, _ranges$0$startIndex, _ranges$, _ranges$endIndex, _ranges;
16945
- const ranges = getIntersectingCustomRanges(range.startOffset, range.collapsed ? range.startOffset : range.endOffset - 1, (_body$customRanges = body.customRanges) !== null && _body$customRanges !== void 0 ? _body$customRanges : []);
16946
- const startOffset = Math.min(range.startOffset, (_ranges$0$startIndex = (_ranges$ = ranges[0]) === null || _ranges$ === void 0 ? void 0 : _ranges$.startIndex) !== null && _ranges$0$startIndex !== void 0 ? _ranges$0$startIndex : Infinity);
16947
- const endOffset = Math.max(range.endOffset, ((_ranges$endIndex = (_ranges = ranges[ranges.length - 1]) === null || _ranges === void 0 ? void 0 : _ranges.endIndex) !== null && _ranges$endIndex !== void 0 ? _ranges$endIndex : -Infinity) + 1);
17025
+ var _ranges$, _ranges;
17026
+ const ranges = getIntersectingCustomRanges(range.startOffset, range.collapsed ? range.startOffset : range.endOffset - 1, body.customRanges ?? []);
17027
+ const startOffset = Math.min(range.startOffset, ((_ranges$ = ranges[0]) === null || _ranges$ === void 0 ? void 0 : _ranges$.startIndex) ?? Infinity);
17028
+ const endOffset = Math.max(range.endOffset, (((_ranges = ranges[ranges.length - 1]) === null || _ranges === void 0 ? void 0 : _ranges.endIndex) ?? -Infinity) + 1);
16948
17029
  return {
16949
17030
  startOffset,
16950
17031
  endOffset,
@@ -16955,7 +17036,7 @@ function getSelectionForAddCustomRange(range, body) {
16955
17036
  //#endregion
16956
17037
  //#region src/docs/data-model/text-x/build-utils/text-x-utils.ts
16957
17038
  function deleteCustomRangeTextX(params) {
16958
- var _documentDataModel$ge, _insert$dataStream$le;
17039
+ var _documentDataModel$ge;
16959
17040
  const { rangeId, segmentId, documentDataModel, insert } = params;
16960
17041
  const range = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.getBody()) === null || _documentDataModel$ge === void 0 || (_documentDataModel$ge = _documentDataModel$ge.customRanges) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.find((r) => r.rangeId === rangeId);
16961
17042
  if (!range) return false;
@@ -16979,7 +17060,7 @@ function deleteCustomRangeTextX(params) {
16979
17060
  body: insert,
16980
17061
  len: insert.dataStream.length
16981
17062
  });
16982
- const end = endIndex + 1 + ((_insert$dataStream$le = insert === null || insert === void 0 ? void 0 : insert.dataStream.length) !== null && _insert$dataStream$le !== void 0 ? _insert$dataStream$le : 0);
17063
+ const end = endIndex + 1 + ((insert === null || insert === void 0 ? void 0 : insert.dataStream.length) ?? 0);
16983
17064
  textX.selections = [{
16984
17065
  startOffset: end,
16985
17066
  endOffset: end,
@@ -16993,17 +17074,16 @@ function addCustomRangeTextX(param) {
16993
17074
  const textX = new TextX();
16994
17075
  let changed = false;
16995
17076
  ranges.forEach((range) => {
16996
- var _body$customRanges, _body$paragraphs, _body$customBlocks;
16997
17077
  const actualRange = getSelectionForAddCustomRange(range, body);
16998
17078
  if (!actualRange) return false;
16999
17079
  if (!body) return false;
17000
17080
  const { startOffset, endOffset } = actualRange;
17001
- const customRanges = (_body$customRanges = body.customRanges) !== null && _body$customRanges !== void 0 ? _body$customRanges : [];
17081
+ const customRanges = body.customRanges ?? [];
17002
17082
  const addCustomRange = (startIndex, endIndex, index) => {
17003
- var _relativeCustomRanges, _relativeCustomRanges2, _relativeCustomRanges3, _relativeCustomRanges4;
17083
+ var _relativeCustomRanges, _relativeCustomRanges2;
17004
17084
  const relativeCustomRanges = getIntersectingCustomRanges(startIndex, endIndex, customRanges, rangeType);
17005
- const rangeStartIndex = Math.min((_relativeCustomRanges = (_relativeCustomRanges2 = relativeCustomRanges[0]) === null || _relativeCustomRanges2 === void 0 ? void 0 : _relativeCustomRanges2.startIndex) !== null && _relativeCustomRanges !== void 0 ? _relativeCustomRanges : Infinity, startIndex);
17006
- const rangeEndIndex = Math.max((_relativeCustomRanges3 = (_relativeCustomRanges4 = relativeCustomRanges[relativeCustomRanges.length - 1]) === null || _relativeCustomRanges4 === void 0 ? void 0 : _relativeCustomRanges4.endIndex) !== null && _relativeCustomRanges3 !== void 0 ? _relativeCustomRanges3 : -Infinity, endIndex);
17085
+ const rangeStartIndex = Math.min(((_relativeCustomRanges = relativeCustomRanges[0]) === null || _relativeCustomRanges === void 0 ? void 0 : _relativeCustomRanges.startIndex) ?? Infinity, startIndex);
17086
+ const rangeEndIndex = Math.max(((_relativeCustomRanges2 = relativeCustomRanges[relativeCustomRanges.length - 1]) === null || _relativeCustomRanges2 === void 0 ? void 0 : _relativeCustomRanges2.endIndex) ?? -Infinity, endIndex);
17007
17087
  const customRange = {
17008
17088
  rangeId: index ? `${rangeId}$${index}` : rangeId,
17009
17089
  rangeType,
@@ -17027,8 +17107,8 @@ function addCustomRangeTextX(param) {
17027
17107
  });
17028
17108
  cursor = rangeEndIndex + 1;
17029
17109
  };
17030
- const relativeParagraphs = ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).filter((p) => p.startIndex < endOffset && p.startIndex > startOffset);
17031
- const customBlocks = ((_body$customBlocks = body.customBlocks) !== null && _body$customBlocks !== void 0 ? _body$customBlocks : []).filter((block) => block.startIndex < endOffset && block.startIndex > startOffset);
17110
+ const relativeParagraphs = (body.paragraphs ?? []).filter((p) => p.startIndex < endOffset && p.startIndex > startOffset);
17111
+ const customBlocks = (body.customBlocks ?? []).filter((block) => block.startIndex < endOffset && block.startIndex > startOffset);
17032
17112
  excludePointsFromRange([startOffset, endOffset - 1], [...relativeParagraphs.map((p) => p.startIndex), ...customBlocks.map((b) => b.startIndex)]).forEach(([start, end], i) => addCustomRange(start, end, i));
17033
17113
  changed = true;
17034
17114
  textX.selections = [{
@@ -17058,8 +17138,7 @@ function protectDeletedColumnBoundaryTokens(body, selections, protectedOffsets)
17058
17138
  }
17059
17139
  }
17060
17140
  function protectPartiallyDeletedBlockBoundaryTokens(body, selections, protectedOffsets) {
17061
- var _body$blockRanges;
17062
- for (const blockRange of (_body$blockRanges = body.blockRanges) !== null && _body$blockRanges !== void 0 ? _body$blockRanges : []) {
17141
+ for (const blockRange of body.blockRanges ?? []) {
17063
17142
  const blockInterval = getBlockRangeInterval(blockRange);
17064
17143
  if (selections.some((selection) => selection.startOffset <= blockInterval.startOffset && selection.endOffset >= blockInterval.endOffset)) continue;
17065
17144
  if (isOffsetDeleted(blockRange.startIndex, selections)) protectedOffsets.add(blockRange.startIndex);
@@ -17067,8 +17146,7 @@ function protectPartiallyDeletedBlockBoundaryTokens(body, selections, protectedO
17067
17146
  }
17068
17147
  }
17069
17148
  function collectBlockTextContainers(body) {
17070
- var _body$blockRanges2, _body$paragraphs2, _body$sectionBreaks;
17071
- const blockRanges = [...(_body$blockRanges2 = body.blockRanges) !== null && _body$blockRanges2 !== void 0 ? _body$blockRanges2 : []].sort((left, right) => left.startIndex - right.startIndex);
17149
+ const blockRanges = [...body.blockRanges ?? []].sort((left, right) => left.startIndex - right.startIndex);
17072
17150
  const containers = blockRanges.map((blockRange) => {
17073
17151
  const atomicRange = getBlockRangeInterval(blockRange);
17074
17152
  return {
@@ -17096,8 +17174,8 @@ function collectBlockTextContainers(body) {
17096
17174
  }
17097
17175
  if (index >= 0) containers[index][key].push(offset);
17098
17176
  };
17099
- ((_body$paragraphs2 = body.paragraphs) !== null && _body$paragraphs2 !== void 0 ? _body$paragraphs2 : []).forEach((paragraph) => assignPoint(paragraph.startIndex, "paragraphs"));
17100
- ((_body$sectionBreaks = body.sectionBreaks) !== null && _body$sectionBreaks !== void 0 ? _body$sectionBreaks : []).forEach((sectionBreak) => assignPoint(sectionBreak.startIndex, "sectionBreaks"));
17177
+ (body.paragraphs ?? []).forEach((paragraph) => assignPoint(paragraph.startIndex, "paragraphs"));
17178
+ (body.sectionBreaks ?? []).forEach((sectionBreak) => assignPoint(sectionBreak.startIndex, "sectionBreaks"));
17101
17179
  return containers;
17102
17180
  }
17103
17181
  function collectStructuralTextContainers(body) {
@@ -17150,10 +17228,9 @@ function collectStructuralTextContainers(body) {
17150
17228
  return containers;
17151
17229
  }
17152
17230
  function protectRequiredContainerChildren(container, selections, insertBody, insertOffset, protectedOffsets) {
17153
- var _insertBody$dataStrea;
17154
17231
  if (isAtomicContainerDeleted(container, selections)) return;
17155
17232
  const insertAppliesToContainer = insertBody && isInsertInContainer(insertOffset, container);
17156
- const insertDataStream = (_insertBody$dataStrea = insertBody === null || insertBody === void 0 ? void 0 : insertBody.dataStream) !== null && _insertBody$dataStrea !== void 0 ? _insertBody$dataStrea : "";
17233
+ const insertDataStream = (insertBody === null || insertBody === void 0 ? void 0 : insertBody.dataStream) ?? "";
17157
17234
  const insertHasParagraph = insertDataStream.includes("\r");
17158
17235
  const insertHasSectionBreak = insertDataStream.includes("\n");
17159
17236
  if (container.require === "paragraph-or-section") {
@@ -17362,12 +17439,12 @@ const replaceSelectionTextRuns = (params) => {
17362
17439
  t: "r",
17363
17440
  body: isTextRunsEqual(textRunsSlice, oldTextRunsSlice) ? void 0 : {
17364
17441
  textRuns: textRunsSlice === null || textRunsSlice === void 0 ? void 0 : textRunsSlice.map((textRun) => {
17365
- var _textRun$ts, _textRun$ts$cl$rgb, _textRun$ts2, _textRun$ts3;
17442
+ var _textRun$ts, _textRun$ts2, _textRun$ts3;
17366
17443
  return {
17367
17444
  ...textRun,
17368
17445
  ts: {
17369
17446
  ...textRun.ts,
17370
- cl: ((_textRun$ts = textRun.ts) === null || _textRun$ts === void 0 || (_textRun$ts = _textRun$ts.cl) === null || _textRun$ts === void 0 || (_textRun$ts = _textRun$ts.rgb) === null || _textRun$ts === void 0 ? void 0 : _textRun$ts.includes(".")) ? { rgb: themeService.getColorFromTheme((_textRun$ts$cl$rgb = (_textRun$ts2 = textRun.ts) === null || _textRun$ts2 === void 0 || (_textRun$ts2 = _textRun$ts2.cl) === null || _textRun$ts2 === void 0 ? void 0 : _textRun$ts2.rgb) !== null && _textRun$ts$cl$rgb !== void 0 ? _textRun$ts$cl$rgb : "") } : (_textRun$ts3 = textRun.ts) === null || _textRun$ts3 === void 0 ? void 0 : _textRun$ts3.cl
17447
+ cl: ((_textRun$ts = textRun.ts) === null || _textRun$ts === void 0 || (_textRun$ts = _textRun$ts.cl) === null || _textRun$ts === void 0 || (_textRun$ts = _textRun$ts.rgb) === null || _textRun$ts === void 0 ? void 0 : _textRun$ts.includes(".")) ? { rgb: themeService.getColorFromTheme(((_textRun$ts2 = textRun.ts) === null || _textRun$ts2 === void 0 || (_textRun$ts2 = _textRun$ts2.cl) === null || _textRun$ts2 === void 0 ? void 0 : _textRun$ts2.rgb) ?? "") } : (_textRun$ts3 = textRun.ts) === null || _textRun$ts3 === void 0 ? void 0 : _textRun$ts3.cl
17371
17448
  }
17372
17449
  };
17373
17450
  }),
@@ -17419,7 +17496,7 @@ function getCustomBlockIdsInSelections(body, selections) {
17419
17496
  return customBlockIds;
17420
17497
  }
17421
17498
  const addDrawing = (param) => {
17422
- var _documentDataModel$ge, _documentDataModel$ge2, _documentDataModel$ge3;
17499
+ var _documentDataModel$ge, _documentDataModel$ge2;
17423
17500
  const { selection, documentDataModel, drawings } = param;
17424
17501
  const { collapsed, startOffset, segmentId } = selection;
17425
17502
  const textX = new TextX();
@@ -17427,21 +17504,20 @@ const addDrawing = (param) => {
17427
17504
  const rawActions = [];
17428
17505
  const body = (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
17429
17506
  if (!body) return false;
17430
- const drawingOrderLength = (_documentDataModel$ge2 = (_documentDataModel$ge3 = documentDataModel.getSnapshot().drawingsOrder) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.length) !== null && _documentDataModel$ge2 !== void 0 ? _documentDataModel$ge2 : 0;
17507
+ const drawingOrderLength = ((_documentDataModel$ge2 = documentDataModel.getSnapshot().drawingsOrder) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.length) ?? 0;
17431
17508
  let removeDrawingLen = 0;
17432
- const insertOffset = collapsed ? normalizeDrawingInsertOffset(body, startOffset !== null && startOffset !== void 0 ? startOffset : 0) : startOffset !== null && startOffset !== void 0 ? startOffset : 0;
17509
+ const insertOffset = collapsed ? normalizeDrawingInsertOffset(body, startOffset ?? 0) : startOffset ?? 0;
17433
17510
  if (collapsed) {
17434
17511
  if (insertOffset > 0) textX.push({
17435
17512
  t: "r",
17436
17513
  len: insertOffset
17437
17514
  });
17438
17515
  } else {
17439
- var _documentDataModel$ge4, _documentDataModel$ge5;
17440
17516
  const dos = deleteSelectionTextX([selection], body, 0, null, false);
17441
17517
  textX.push(...dos);
17442
17518
  const removedCustomBlockIds = getCustomBlockIdsInSelections(body, [selection]);
17443
- const drawings = (_documentDataModel$ge4 = documentDataModel.getDrawings()) !== null && _documentDataModel$ge4 !== void 0 ? _documentDataModel$ge4 : {};
17444
- const drawingOrder = (_documentDataModel$ge5 = documentDataModel.getDrawingsOrder()) !== null && _documentDataModel$ge5 !== void 0 ? _documentDataModel$ge5 : [];
17519
+ const drawings = documentDataModel.getDrawings() ?? {};
17520
+ const drawingOrder = documentDataModel.getDrawingsOrder() ?? [];
17445
17521
  const sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => {
17446
17522
  if (drawingOrder.indexOf(a) > drawingOrder.indexOf(b)) return -1;
17447
17523
  else if (drawingOrder.indexOf(a) < drawingOrder.indexOf(b)) return 1;
@@ -17479,7 +17555,16 @@ const addDrawing = (param) => {
17479
17555
  }, null);
17480
17556
  };
17481
17557
  function normalizeDrawingInsertOffset(body, offset) {
17482
- return offset === 0 && body.dataStream[0] === "\r" ? 1 : offset;
17558
+ const { dataStream } = body;
17559
+ if (offset === 0 && dataStream[0] === "\r") return 1;
17560
+ if (dataStream[offset] === "\n" && dataStream[offset - 1] === "\r" && isInsideTableCell(dataStream, offset)) return offset - 1;
17561
+ return offset;
17562
+ }
17563
+ function isInsideTableCell(dataStream, offset) {
17564
+ let cellDepth = 0;
17565
+ for (let index = 0; index < offset; index++) if (dataStream[index] === "") cellDepth++;
17566
+ else if (dataStream[index] === "") cellDepth = Math.max(0, cellDepth - 1);
17567
+ return cellDepth > 0;
17483
17568
  }
17484
17569
  function buildDrawingInsertBody(body, drawings, insertOffset) {
17485
17570
  var _body$paragraphs;
@@ -17559,8 +17644,8 @@ function collectNewStructuralStartOffsets(previousBody, nextBody) {
17559
17644
  return Array.from(new Set(offsets)).sort((left, right) => left - right);
17560
17645
  }
17561
17646
  function collectNewStartOffsets(previousItems, nextItems, getId) {
17562
- const previousIds = new Set((previousItems !== null && previousItems !== void 0 ? previousItems : []).map(getId));
17563
- return (nextItems !== null && nextItems !== void 0 ? nextItems : []).filter((item) => !previousIds.has(getId(item))).map((item) => item.startIndex);
17647
+ const previousIds = new Set((previousItems ?? []).map(getId));
17648
+ return (nextItems ?? []).filter((item) => !previousIds.has(getId(item))).map((item) => item.startIndex);
17564
17649
  }
17565
17650
 
17566
17651
  //#endregion
@@ -17654,8 +17739,7 @@ function normalizeBody$1(body) {
17654
17739
  return body;
17655
17740
  }
17656
17741
  function normalizeData(data) {
17657
- var _data$body;
17658
- data.body = normalizeBody$1((_data$body = data.body) !== null && _data$body !== void 0 ? _data$body : { dataStream: "" });
17742
+ data.body = normalizeBody$1(data.body ?? { dataStream: "" });
17659
17743
  if (!data.drawingsOrder) data.drawingsOrder = [];
17660
17744
  if (!data.drawings) data.drawings = {};
17661
17745
  if (!data.documentStyle) data.documentStyle = {};
@@ -17698,8 +17782,8 @@ function normalizeRichTextParagraphStyle(style) {
17698
17782
  };
17699
17783
  }
17700
17784
  function hasRichTextContent(data) {
17701
- var _data$body$dataStream, _data$body2;
17702
- return ((_data$body$dataStream = (_data$body2 = data.body) === null || _data$body2 === void 0 ? void 0 : _data$body2.dataStream) !== null && _data$body$dataStream !== void 0 ? _data$body$dataStream : "").replace(/\r|\n/g, "").length > 0;
17785
+ var _data$body;
17786
+ return (((_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream) ?? "").replace(/\r|\n/g, "").length > 0;
17703
17787
  }
17704
17788
  /**
17705
17789
  * Represents a read-only font style value object.
@@ -19102,8 +19186,8 @@ var RichTextValue = class RichTextValue {
19102
19186
  * ```
19103
19187
  */
19104
19188
  toPlainText() {
19105
- var _this$_data$body$data, _this$_data$body;
19106
- return BuildTextUtils.transform.getPlainText((_this$_data$body$data = (_this$_data$body = this._data.body) === null || _this$_data$body === void 0 ? void 0 : _this$_data$body.dataStream) !== null && _this$_data$body$data !== void 0 ? _this$_data$body$data : "").replaceAll("\r", "\n");
19189
+ var _this$_data$body;
19190
+ return BuildTextUtils.transform.getPlainText(((_this$_data$body = this._data.body) === null || _this$_data$body === void 0 ? void 0 : _this$_data$body.dataStream) ?? "").replaceAll("\r", "\n");
19107
19191
  }
19108
19192
  /**
19109
19193
  * Gets the paragraph style of the current RichTextValue instance
@@ -19141,14 +19225,13 @@ var RichTextValue = class RichTextValue {
19141
19225
  * ```
19142
19226
  */
19143
19227
  getParagraphs() {
19144
- var _this$_data$body$para, _this$_data$body4;
19145
- const paragraphs = (_this$_data$body$para = (_this$_data$body4 = this._data.body) === null || _this$_data$body4 === void 0 ? void 0 : _this$_data$body4.paragraphs) !== null && _this$_data$body$para !== void 0 ? _this$_data$body$para : [];
19146
- let start = 0;
19147
- return paragraphs.map((paragraph) => {
19148
- const sub = this.slice(start, paragraph.startIndex);
19149
- start = paragraph.startIndex;
19150
- return sub;
19151
- });
19228
+ const body = this._data.body;
19229
+ if (!body) return [];
19230
+ const startOffsets = getParagraphContentStartOffsets(body);
19231
+ return (body.paragraphs ?? []).map((paragraph) => RichTextBuilder.create(createParagraphSnapshot(this._data, paragraph.paragraphId, {
19232
+ startOffset: startOffsets.get(paragraph.startIndex) ?? 0,
19233
+ endOffset: paragraph.startIndex
19234
+ })));
19152
19235
  }
19153
19236
  /**
19154
19237
  * Gets the text runs of the current RichTextValue instance
@@ -19160,8 +19243,8 @@ var RichTextValue = class RichTextValue {
19160
19243
  * ```
19161
19244
  */
19162
19245
  getTextRuns() {
19163
- var _this$_data$body$text, _this$_data$body5;
19164
- return ((_this$_data$body$text = (_this$_data$body5 = this._data.body) === null || _this$_data$body5 === void 0 ? void 0 : _this$_data$body5.textRuns) !== null && _this$_data$body$text !== void 0 ? _this$_data$body$text : []).map((t) => ({
19246
+ var _this$_data$body4;
19247
+ return (((_this$_data$body4 = this._data.body) === null || _this$_data$body4 === void 0 ? void 0 : _this$_data$body4.textRuns) ?? []).map((t) => ({
19165
19248
  ...t,
19166
19249
  ts: t.ts ? TextStyleValue.create(t.ts) : null
19167
19250
  }));
@@ -19176,8 +19259,8 @@ var RichTextValue = class RichTextValue {
19176
19259
  * ```
19177
19260
  */
19178
19261
  getLinks() {
19179
- var _this$_data$body$cust, _this$_data$body6;
19180
- return (_this$_data$body$cust = (_this$_data$body6 = this._data.body) === null || _this$_data$body6 === void 0 || (_this$_data$body6 = _this$_data$body6.customRanges) === null || _this$_data$body6 === void 0 ? void 0 : _this$_data$body6.filter((r) => r.rangeType === 0)) !== null && _this$_data$body$cust !== void 0 ? _this$_data$body$cust : [];
19262
+ var _this$_data$body5;
19263
+ return ((_this$_data$body5 = this._data.body) === null || _this$_data$body5 === void 0 || (_this$_data$body5 = _this$_data$body5.customRanges) === null || _this$_data$body5 === void 0 ? void 0 : _this$_data$body5.filter((r) => r.rangeType === 0)) ?? [];
19181
19264
  }
19182
19265
  /**
19183
19266
  * Gets the data of the current RichTextValue instance
@@ -19233,19 +19316,22 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19233
19316
  * @returns {RichTextBuilder} A new RichTextBuilder instance
19234
19317
  */
19235
19318
  static create(data) {
19236
- return new RichTextBuilder(data !== null && data !== void 0 ? data : RichTextBuilder.newEmptyData());
19319
+ return new RichTextBuilder(data ?? RichTextBuilder.newEmptyData());
19237
19320
  }
19238
19321
  constructor(data) {
19239
19322
  super(data);
19240
19323
  _defineProperty(this, "_doc", void 0);
19241
19324
  _defineProperty(this, "_trackedRanges", /* @__PURE__ */ new Set());
19325
+ _defineProperty(this, "_childHandleRevision", 0);
19242
19326
  this._doc = new DocumentDataModel(data);
19243
19327
  }
19244
19328
  /**
19245
19329
  * Returns editable paragraph handles backed by this detached rich-text builder.
19246
19330
  *
19247
- * Paragraph boundaries come from the document model rather than splitting plain text. Each handle stays aligned
19248
- * when text in this builder grows or shrinks, so callers can safely iterate from the first paragraph to the last.
19331
+ * Paragraph boundaries come from the document model rather than splitting plain text. Handles stay aligned across
19332
+ * edits made through their child run handles, so callers can safely iterate from the first paragraph to the last.
19333
+ * Direct builder edits that change text or run boundaries invalidate previously returned paragraph and run handles;
19334
+ * query them again after calling methods such as `insertText()`, `setStyle()`, `setLink()`, or `delete()`.
19249
19335
  *
19250
19336
  * @returns Editable paragraphs in document order.
19251
19337
  * @example
@@ -19260,14 +19346,10 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19260
19346
  * ```
19261
19347
  */
19262
19348
  getParagraphs() {
19263
- var _body$paragraphs;
19264
19349
  const body = this._data.body;
19265
19350
  if (!body) return [];
19266
19351
  const startOffsets = getParagraphContentStartOffsets(body);
19267
- return ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).map((paragraph) => {
19268
- var _startOffsets$get;
19269
- return this._createParagraphBuilder(paragraph.paragraphId, (_startOffsets$get = startOffsets.get(paragraph.startIndex)) !== null && _startOffsets$get !== void 0 ? _startOffsets$get : 0, paragraph.startIndex);
19270
- });
19352
+ return (body.paragraphs ?? []).map((paragraph) => this._createParagraphBuilder(paragraph.paragraphId, startOffsets.get(paragraph.startIndex) ?? 0, paragraph.startIndex));
19271
19353
  }
19272
19354
  /**
19273
19355
  * Returns editable text-run handles for all paragraph text in this builder.
@@ -19291,7 +19373,6 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19291
19373
  }
19292
19374
  /** @internal */
19293
19375
  _createTextRunBuilders(range) {
19294
- var _body$textRuns, _body$customRanges, _body$customDecoratio;
19295
19376
  const body = this._data.body;
19296
19377
  if (!body || range.startOffset >= range.endOffset) return [];
19297
19378
  const boundaries = /* @__PURE__ */ new Set([range.startOffset, range.endOffset]);
@@ -19303,9 +19384,9 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19303
19384
  boundaries.add(end);
19304
19385
  }
19305
19386
  };
19306
- for (const textRun of (_body$textRuns = body.textRuns) !== null && _body$textRuns !== void 0 ? _body$textRuns : []) addRangeBoundaries(textRun.st, textRun.ed);
19307
- for (const customRange of (_body$customRanges = body.customRanges) !== null && _body$customRanges !== void 0 ? _body$customRanges : []) addRangeBoundaries(customRange.startIndex, customRange.endIndex + 1);
19308
- for (const decoration of (_body$customDecoratio = body.customDecorations) !== null && _body$customDecoratio !== void 0 ? _body$customDecoratio : []) addRangeBoundaries(decoration.startIndex, decoration.endIndex + 1);
19387
+ for (const textRun of body.textRuns ?? []) addRangeBoundaries(textRun.st, textRun.ed);
19388
+ for (const customRange of body.customRanges ?? []) addRangeBoundaries(customRange.startIndex, customRange.endIndex + 1);
19389
+ for (const decoration of body.customDecorations ?? []) addRangeBoundaries(decoration.startIndex, decoration.endIndex + 1);
19309
19390
  for (let offset = range.startOffset; offset < range.endOffset; offset++) if (NON_EDITABLE_RICH_TEXT_TOKENS.has(body.dataStream[offset])) {
19310
19391
  boundaries.add(offset);
19311
19392
  boundaries.add(offset + 1);
@@ -19313,12 +19394,11 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19313
19394
  const offsets = [...boundaries].sort((left, right) => left - right);
19314
19395
  const runs = [];
19315
19396
  for (let index = 0; index < offsets.length - 1; index++) {
19316
- var _body$textRuns2;
19317
19397
  const startOffset = offsets[index];
19318
19398
  const endOffset = offsets[index + 1];
19319
19399
  if (startOffset >= endOffset || endOffset - startOffset === 1 && NON_EDITABLE_RICH_TEXT_TOKENS.has(body.dataStream[startOffset])) continue;
19320
- const sourceRun = ((_body$textRuns2 = body.textRuns) !== null && _body$textRuns2 !== void 0 ? _body$textRuns2 : []).find((textRun) => textRun.st <= startOffset && textRun.ed >= endOffset);
19321
- runs.push(new RichTextRunBuilder(this, this._trackRange(startOffset, endOffset), sourceRun === null || sourceRun === void 0 ? void 0 : sourceRun.ts, sourceRun === null || sourceRun === void 0 ? void 0 : sourceRun.sId, Boolean(sourceRun)));
19400
+ const sourceRun = (body.textRuns ?? []).find((textRun) => textRun.st <= startOffset && textRun.ed >= endOffset);
19401
+ runs.push(new RichTextRunBuilder(this, this._trackRange(startOffset, endOffset), sourceRun === null || sourceRun === void 0 ? void 0 : sourceRun.ts, sourceRun === null || sourceRun === void 0 ? void 0 : sourceRun.sId, Boolean(sourceRun), this._childHandleRevision));
19322
19402
  }
19323
19403
  return runs;
19324
19404
  }
@@ -19362,7 +19442,11 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19362
19442
  this._rebaseTrackedRanges(startOffset, endOffset, text.length);
19363
19443
  }
19364
19444
  _createParagraphBuilder(paragraphId, startOffset, endOffset) {
19365
- return new RichTextParagraphBuilder(this, paragraphId, this._trackRange(startOffset, endOffset));
19445
+ return new RichTextParagraphBuilder(this, paragraphId, this._trackRange(startOffset, endOffset), this._childHandleRevision);
19446
+ }
19447
+ /** @internal */
19448
+ _assertChildHandleRevision(revision) {
19449
+ if (revision !== this._childHandleRevision) throw new Error("Rich text child handle is no longer valid.");
19366
19450
  }
19367
19451
  _trackRange(startOffset, endOffset) {
19368
19452
  const range = {
@@ -19389,6 +19473,10 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19389
19473
  trackedRange.endOffset = mapEnd(trackedRange.endOffset);
19390
19474
  }
19391
19475
  }
19476
+ _invalidateChildHandles() {
19477
+ this._childHandleRevision++;
19478
+ this._trackedRanges.clear();
19479
+ }
19392
19480
  /**
19393
19481
  * Appends plain text to the rich text.
19394
19482
  *
@@ -19429,13 +19517,12 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19429
19517
  * ```
19430
19518
  */
19431
19519
  align(alignment) {
19432
- var _this$_data, _this$_data$documentS, _documentStyle$render;
19433
- const documentStyle = (_this$_data$documentS = (_this$_data = this._data).documentStyle) !== null && _this$_data$documentS !== void 0 ? _this$_data$documentS : _this$_data.documentStyle = {};
19434
- const renderConfig = (_documentStyle$render = documentStyle.renderConfig) !== null && _documentStyle$render !== void 0 ? _documentStyle$render : documentStyle.renderConfig = {};
19520
+ const documentStyle = this._data.documentStyle ??= {};
19521
+ const renderConfig = documentStyle.renderConfig ??= {};
19435
19522
  if (alignment.horizontal !== void 0) {
19436
- var _this$_data$body$para2, _this$_data$body7;
19523
+ var _this$_data$body6;
19437
19524
  renderConfig.horizontalAlign = alignment.horizontal;
19438
- for (const paragraph of (_this$_data$body$para2 = (_this$_data$body7 = this._data.body) === null || _this$_data$body7 === void 0 ? void 0 : _this$_data$body7.paragraphs) !== null && _this$_data$body$para2 !== void 0 ? _this$_data$body$para2 : []) paragraph.paragraphStyle = {
19525
+ for (const paragraph of ((_this$_data$body6 = this._data.body) === null || _this$_data$body6 === void 0 ? void 0 : _this$_data$body6.paragraphs) ?? []) paragraph.paragraphStyle = {
19439
19526
  ...paragraph.paragraphStyle,
19440
19527
  horizontalAlign: alignment.horizontal
19441
19528
  };
@@ -19475,18 +19562,17 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19475
19562
  * ```
19476
19563
  */
19477
19564
  columns(options) {
19478
- var _this$_data2, _this$_data2$body, _body$sectionBreaks, _options$spacing;
19479
19565
  if (!Number.isInteger(options.count) || options.count < 1) throw new RangeError("Rich text column count must be a positive integer.");
19480
- const body = (_this$_data2$body = (_this$_data2 = this._data).body) !== null && _this$_data2$body !== void 0 ? _this$_data2$body : _this$_data2.body = { dataStream: "\r\n" };
19481
- const sectionBreaks = (_body$sectionBreaks = body.sectionBreaks) !== null && _body$sectionBreaks !== void 0 ? _body$sectionBreaks : body.sectionBreaks = [];
19566
+ const body = this._data.body ??= { dataStream: "\r\n" };
19567
+ const sectionBreaks = body.sectionBreaks ??= [];
19482
19568
  if (!sectionBreaks.length) {
19483
- var _body$dataStream$leng, _body$dataStream;
19569
+ var _body$dataStream;
19484
19570
  sectionBreaks.push({
19485
19571
  sectionId: createSectionId(/* @__PURE__ */ new Set()),
19486
- startIndex: Math.max(0, ((_body$dataStream$leng = (_body$dataStream = body.dataStream) === null || _body$dataStream === void 0 ? void 0 : _body$dataStream.length) !== null && _body$dataStream$leng !== void 0 ? _body$dataStream$leng : 0) - 1)
19572
+ startIndex: Math.max(0, (((_body$dataStream = body.dataStream) === null || _body$dataStream === void 0 ? void 0 : _body$dataStream.length) ?? 0) - 1)
19487
19573
  });
19488
19574
  }
19489
- const spacing = Math.max(0, (_options$spacing = options.spacing) !== null && _options$spacing !== void 0 ? _options$spacing : 0);
19575
+ const spacing = Math.max(0, options.spacing ?? 0);
19490
19576
  const columns = options.count === 1 ? void 0 : Array.from({ length: options.count }, (_, index) => ({
19491
19577
  width: 0,
19492
19578
  paddingEnd: index === options.count - 1 ? 0 : spacing
@@ -19496,14 +19582,15 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19496
19582
  return this;
19497
19583
  }
19498
19584
  /**
19499
- * Appends one text span with explicit style.
19585
+ * Appends one text span with an optional style.
19500
19586
  *
19501
19587
  * Prefer this method when combining multiple styles, because the style object is local to the inserted text and does
19502
19588
  * not leak into following calls.
19503
19589
  *
19504
19590
  * @param text Text to append.
19505
- * @param style Text style for this span. Agent-friendly aliases such as `bold`, `italic`, `fontFamily`, `fontSize`,
19506
- * `color`, and `background` are supported alongside native document text style fields.
19591
+ * @param style Optional text style for this span. When omitted, the span is appended as unstyled text. Agent-friendly
19592
+ * aliases such as `bold`, `italic`, `fontFamily`, `fontSize`, `color`, and `background` are supported alongside native
19593
+ * document text style fields.
19507
19594
  * @returns The current builder for chaining.
19508
19595
  * @example
19509
19596
  * ```ts
@@ -19514,18 +19601,7 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19514
19601
  */
19515
19602
  span(text, style) {
19516
19603
  if (!text) return this;
19517
- return this.insertRichText(RichTextValue.create({
19518
- id: "d",
19519
- documentStyle: {},
19520
- body: {
19521
- dataStream: text,
19522
- textRuns: [{
19523
- st: 0,
19524
- ed: text.length,
19525
- ts: normalizeRichTextSpanStyle(style)
19526
- }]
19527
- }
19528
- }));
19604
+ return style ? this.insertText(text, normalizeRichTextSpanStyle(style)) : this.insertText(text);
19529
19605
  }
19530
19606
  /**
19531
19607
  * Appends bold text.
@@ -19599,22 +19675,19 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19599
19675
  * ```
19600
19676
  */
19601
19677
  listItem(text, options = {}) {
19602
- var _options$type, _this$_data$body8, _options$listId, _this$_data$body9;
19603
- const listType = (_options$type = options.type) !== null && _options$type !== void 0 ? _options$type : "BULLET_LIST";
19604
- const currentParagraph = (_this$_data$body8 = this._data.body) === null || _this$_data$body8 === void 0 || (_this$_data$body8 = _this$_data$body8.paragraphs) === null || _this$_data$body8 === void 0 ? void 0 : _this$_data$body8.at(-1);
19678
+ var _this$_data$body7, _options$listId, _this$_data$body8;
19679
+ const listType = options.type ?? "BULLET_LIST";
19680
+ const currentParagraph = (_this$_data$body7 = this._data.body) === null || _this$_data$body7 === void 0 || (_this$_data$body7 = _this$_data$body7.paragraphs) === null || _this$_data$body7 === void 0 ? void 0 : _this$_data$body7.slice(-1)[0];
19605
19681
  const currentBullet = currentParagraph === null || currentParagraph === void 0 ? void 0 : currentParagraph.bullet;
19606
19682
  const listId = ((_options$listId = options.listId) === null || _options$listId === void 0 ? void 0 : _options$listId.trim()) || ((currentBullet === null || currentBullet === void 0 ? void 0 : currentBullet.listType) === listType ? currentBullet.listId : generateRandomId());
19607
19683
  if (hasRichTextContent(this._data)) this.paragraph(options.paragraphStyle);
19608
19684
  else if (options.paragraphStyle) this.paragraph(options.paragraphStyle);
19609
- const targetParagraph = (_this$_data$body9 = this._data.body) === null || _this$_data$body9 === void 0 || (_this$_data$body9 = _this$_data$body9.paragraphs) === null || _this$_data$body9 === void 0 ? void 0 : _this$_data$body9.at(-1);
19610
- if (targetParagraph) {
19611
- var _options$level;
19612
- targetParagraph.bullet = {
19613
- listId,
19614
- listType,
19615
- nestingLevel: Math.max(0, Math.trunc((_options$level = options.level) !== null && _options$level !== void 0 ? _options$level : 0))
19616
- };
19617
- }
19685
+ const targetParagraph = (_this$_data$body8 = this._data.body) === null || _this$_data$body8 === void 0 || (_this$_data$body8 = _this$_data$body8.paragraphs) === null || _this$_data$body8 === void 0 ? void 0 : _this$_data$body8.slice(-1)[0];
19686
+ if (targetParagraph) targetParagraph.bullet = {
19687
+ listId,
19688
+ listType,
19689
+ nestingLevel: Math.max(0, Math.trunc(options.level ?? 0))
19690
+ };
19618
19691
  return this.text(text);
19619
19692
  }
19620
19693
  /**
@@ -19635,20 +19708,20 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19635
19708
  * ```
19636
19709
  */
19637
19710
  paragraph(paragraphStyle) {
19638
- var _this$_data$body11, _this$_data$body$data2, _this$_data$body12, _this$_data$body13;
19711
+ var _this$_data$body10, _this$_data$body11, _this$_data$body12;
19639
19712
  const nextParagraphStyle = normalizeRichTextParagraphStyle(paragraphStyle);
19640
19713
  if (!hasRichTextContent(this._data)) {
19641
19714
  if (nextParagraphStyle) {
19642
- var _this$_data$body10;
19643
- const firstParagraph = (_this$_data$body10 = this._data.body) === null || _this$_data$body10 === void 0 || (_this$_data$body10 = _this$_data$body10.paragraphs) === null || _this$_data$body10 === void 0 ? void 0 : _this$_data$body10[0];
19715
+ var _this$_data$body9;
19716
+ const firstParagraph = (_this$_data$body9 = this._data.body) === null || _this$_data$body9 === void 0 || (_this$_data$body9 = _this$_data$body9.paragraphs) === null || _this$_data$body9 === void 0 ? void 0 : _this$_data$body9[0];
19644
19717
  if (firstParagraph) firstParagraph.paragraphStyle = nextParagraphStyle;
19645
19718
  }
19646
19719
  return this;
19647
19720
  }
19648
- const currentParagraph = (_this$_data$body11 = this._data.body) === null || _this$_data$body11 === void 0 || (_this$_data$body11 = _this$_data$body11.paragraphs) === null || _this$_data$body11 === void 0 ? void 0 : _this$_data$body11.at(-1);
19721
+ const currentParagraph = (_this$_data$body10 = this._data.body) === null || _this$_data$body10 === void 0 || (_this$_data$body10 = _this$_data$body10.paragraphs) === null || _this$_data$body10 === void 0 ? void 0 : _this$_data$body10.slice(-1)[0];
19649
19722
  const currentParagraphStyle = Tools.deepClone(currentParagraph === null || currentParagraph === void 0 ? void 0 : currentParagraph.paragraphStyle);
19650
19723
  const currentParagraphBullet = Tools.deepClone(currentParagraph === null || currentParagraph === void 0 ? void 0 : currentParagraph.bullet);
19651
- const startIndex = Math.max(0, ((_this$_data$body$data2 = (_this$_data$body12 = this._data.body) === null || _this$_data$body12 === void 0 ? void 0 : _this$_data$body12.dataStream.length) !== null && _this$_data$body$data2 !== void 0 ? _this$_data$body$data2 : 2) - 2);
19724
+ const startIndex = Math.max(0, (((_this$_data$body11 = this._data.body) === null || _this$_data$body11 === void 0 ? void 0 : _this$_data$body11.dataStream.length) ?? 2) - 2);
19652
19725
  this.insertRichText(startIndex, RichTextValue.create({
19653
19726
  id: "d",
19654
19727
  documentStyle: {},
@@ -19662,7 +19735,7 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19662
19735
  }]
19663
19736
  }
19664
19737
  }));
19665
- const nextParagraph = (_this$_data$body13 = this._data.body) === null || _this$_data$body13 === void 0 || (_this$_data$body13 = _this$_data$body13.paragraphs) === null || _this$_data$body13 === void 0 ? void 0 : _this$_data$body13.at(-1);
19738
+ const nextParagraph = (_this$_data$body12 = this._data.body) === null || _this$_data$body12 === void 0 || (_this$_data$body12 = _this$_data$body12.paragraphs) === null || _this$_data$body12 === void 0 ? void 0 : _this$_data$body12.slice(-1)[0];
19666
19739
  if (nextParagraphStyle) {
19667
19740
  if (nextParagraph) nextParagraph.paragraphStyle = nextParagraphStyle;
19668
19741
  } else if (nextParagraph) delete nextParagraph.paragraphStyle;
@@ -19670,24 +19743,26 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19670
19743
  return this;
19671
19744
  }
19672
19745
  insertText(start, text, style) {
19673
- var _this$_data$body$data3, _this$_data$body14;
19674
- let startIndex = ((_this$_data$body$data3 = (_this$_data$body14 = this._data.body) === null || _this$_data$body14 === void 0 ? void 0 : _this$_data$body14.dataStream.length) !== null && _this$_data$body$data3 !== void 0 ? _this$_data$body$data3 : 2) - 2;
19746
+ var _this$_data$body13;
19747
+ let startIndex = (((_this$_data$body13 = this._data.body) === null || _this$_data$body13 === void 0 ? void 0 : _this$_data$body13.dataStream.length) ?? 2) - 2;
19675
19748
  let insertText;
19676
19749
  let insertStyle;
19677
19750
  if (typeof start === "string") insertText = start;
19678
19751
  else {
19679
19752
  startIndex = Math.min(start, startIndex);
19680
- insertText = text;
19753
+ insertText = typeof text === "string" ? text : "";
19681
19754
  }
19682
19755
  if (typeof text === "object") insertStyle = text instanceof TextStyleBuilder ? text.build() : text;
19683
19756
  else insertStyle = style instanceof TextStyleBuilder ? style.build() : style;
19684
19757
  if (!insertText) return this;
19758
+ const plainTextBody = BuildTextUtils.transform.fromPlainText(insertText);
19685
19759
  const newBody = {
19686
- dataStream: insertText,
19760
+ dataStream: plainTextBody.dataStream,
19761
+ paragraphs: plainTextBody.paragraphs,
19687
19762
  textRuns: insertStyle ? [{
19688
19763
  ts: insertStyle,
19689
- st: startIndex,
19690
- ed: startIndex + insertText.length
19764
+ st: 0,
19765
+ ed: plainTextBody.dataStream.length
19691
19766
  }] : []
19692
19767
  };
19693
19768
  const textX = BuildTextUtils.selection.replace({
@@ -19701,11 +19776,12 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19701
19776
  });
19702
19777
  if (!textX) throw new Error("Insert text failed, please check.");
19703
19778
  TextX.apply(this._doc.getBody(), textX.serialize());
19779
+ this._invalidateChildHandles();
19704
19780
  return this;
19705
19781
  }
19706
19782
  insertRichText(start, richText) {
19707
- var _this$_data$body$data4, _this$_data$body15;
19708
- let startIndex = ((_this$_data$body$data4 = (_this$_data$body15 = this._data.body) === null || _this$_data$body15 === void 0 ? void 0 : _this$_data$body15.dataStream.length) !== null && _this$_data$body$data4 !== void 0 ? _this$_data$body$data4 : 2) - 2;
19783
+ var _this$_data$body14;
19784
+ let startIndex = (((_this$_data$body14 = this._data.body) === null || _this$_data$body14 === void 0 ? void 0 : _this$_data$body14.dataStream.length) ?? 2) - 2;
19709
19785
  let insertText;
19710
19786
  if (typeof start === "object") insertText = start instanceof RichTextValue ? start.getData() : start;
19711
19787
  else {
@@ -19723,17 +19799,32 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19723
19799
  });
19724
19800
  if (!textX) throw new Error("Insert text failed, please check.");
19725
19801
  TextX.apply(this._doc.getBody(), textX.serialize());
19802
+ this._invalidateChildHandles();
19726
19803
  return this;
19727
19804
  }
19728
19805
  delete(start, count) {
19729
- if (count !== void 0) {
19730
- if (!count) return this;
19806
+ var _this$_data$body15;
19807
+ const terminalTokenLength = "\r".length + "\n".length;
19808
+ const contentLength = Math.max(0, (((_this$_data$body15 = this._data.body) === null || _this$_data$body15 === void 0 ? void 0 : _this$_data$body15.dataStream.length) ?? terminalTokenLength) - terminalTokenLength);
19809
+ let startOffset;
19810
+ let deleteCount;
19811
+ if (count === void 0) {
19812
+ if (start < 0) throw new RangeError("Delete count cannot be negative.");
19813
+ deleteCount = Math.min(start, contentLength);
19814
+ startOffset = contentLength - deleteCount;
19815
+ } else {
19816
+ if (start < 0 || count < 0) throw new RangeError("Delete range cannot be negative.");
19817
+ startOffset = Math.min(start, contentLength);
19818
+ deleteCount = Math.min(count, contentLength - startOffset);
19819
+ }
19820
+ if (deleteCount > 0) {
19731
19821
  const actions = BuildTextUtils.selection.delete([{
19732
- startOffset: start,
19733
- endOffset: start + count,
19822
+ startOffset,
19823
+ endOffset: startOffset + deleteCount,
19734
19824
  collapsed: true
19735
19825
  }], this._data.body);
19736
19826
  TextX.apply(this._doc.getBody(), actions);
19827
+ this._invalidateChildHandles();
19737
19828
  }
19738
19829
  return this;
19739
19830
  }
@@ -19764,6 +19855,7 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19764
19855
  collapsed: true
19765
19856
  }], newBody);
19766
19857
  TextX.apply(this._doc.getBody(), actions);
19858
+ this._invalidateChildHandles();
19767
19859
  return this;
19768
19860
  }
19769
19861
  /**
@@ -19792,9 +19884,11 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19792
19884
  });
19793
19885
  if (!textX) throw new Error("Insert text failed, please check.");
19794
19886
  TextX.apply(this._doc.getBody(), textX.serialize());
19887
+ this._invalidateChildHandles();
19795
19888
  return this;
19796
19889
  }
19797
19890
  cancelLink(start, end) {
19891
+ let changed = false;
19798
19892
  if (typeof start === "string") {
19799
19893
  const textX = BuildTextUtils.customRange.delete({
19800
19894
  rangeId: start,
@@ -19802,6 +19896,7 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19802
19896
  });
19803
19897
  if (!textX) throw new Error("Insert text failed, please check.");
19804
19898
  TextX.apply(this._doc.getBody(), textX.serialize());
19899
+ changed = true;
19805
19900
  } else this.slice(start, end).getLinks().forEach((l) => {
19806
19901
  const textX = BuildTextUtils.customRange.delete({
19807
19902
  rangeId: l.rangeId,
@@ -19809,7 +19904,9 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19809
19904
  });
19810
19905
  if (!textX) throw new Error("Insert text failed, please check.");
19811
19906
  TextX.apply(this._doc.getBody(), textX.serialize());
19907
+ changed = true;
19812
19908
  });
19909
+ if (changed) this._invalidateChildHandles();
19813
19910
  return this;
19814
19911
  }
19815
19912
  updateLink(id, url) {
@@ -19823,7 +19920,7 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19823
19920
  let newBody;
19824
19921
  let startIndex;
19825
19922
  if (typeof start === "object") {
19826
- var _this$_data$body$data5, _this$_data$body17;
19923
+ var _this$_data$body17;
19827
19924
  newBody = {
19828
19925
  dataStream: "\r",
19829
19926
  paragraphs: [{
@@ -19832,7 +19929,7 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19832
19929
  paragraphStyle: start.build()
19833
19930
  }]
19834
19931
  };
19835
- startIndex = ((_this$_data$body$data5 = (_this$_data$body17 = this._data.body) === null || _this$_data$body17 === void 0 ? void 0 : _this$_data$body17.dataStream.length) !== null && _this$_data$body$data5 !== void 0 ? _this$_data$body$data5 : 2) - 2;
19932
+ startIndex = (((_this$_data$body17 = this._data.body) === null || _this$_data$body17 === void 0 ? void 0 : _this$_data$body17.dataStream.length) ?? 2) - 2;
19836
19933
  } else {
19837
19934
  startIndex = start;
19838
19935
  newBody = {
@@ -19882,18 +19979,21 @@ var RichTextBuilder = class RichTextBuilder extends RichTextValue {
19882
19979
  */
19883
19980
  var RichTextParagraphBuilder = class extends RichTextValue {
19884
19981
  /** @hideconstructor */
19885
- constructor(_owner, _paragraphId, _range) {
19982
+ constructor(_owner, _paragraphId, _range, _revision) {
19886
19983
  super(createParagraphSnapshot(_owner.getData(), _paragraphId, _range));
19887
19984
  this._owner = _owner;
19888
19985
  this._paragraphId = _paragraphId;
19889
19986
  this._range = _range;
19987
+ this._revision = _revision;
19890
19988
  }
19891
19989
  /** Returns the persisted paragraph id. */
19892
19990
  getId() {
19991
+ this._assertActive();
19893
19992
  return this._paragraphId;
19894
19993
  }
19895
19994
  /** Returns the current paragraph range without its trailing paragraph marker. */
19896
19995
  getRange() {
19996
+ this._assertActive();
19897
19997
  return { ...this._range };
19898
19998
  }
19899
19999
  /**
@@ -19906,8 +20006,9 @@ var RichTextParagraphBuilder = class extends RichTextValue {
19906
20006
  * ```
19907
20007
  */
19908
20008
  getText() {
19909
- var _this$_owner$getData$, _this$_owner$getData$2;
19910
- return ((_this$_owner$getData$ = (_this$_owner$getData$2 = this._owner.getData().body) === null || _this$_owner$getData$2 === void 0 ? void 0 : _this$_owner$getData$2.dataStream) !== null && _this$_owner$getData$ !== void 0 ? _this$_owner$getData$ : "").slice(this._range.startOffset, this._range.endOffset);
20009
+ var _this$_owner$getData$;
20010
+ this._assertActive();
20011
+ return (((_this$_owner$getData$ = this._owner.getData().body) === null || _this$_owner$getData$ === void 0 ? void 0 : _this$_owner$getData$.dataStream) ?? "").slice(this._range.startOffset, this._range.endOffset);
19911
20012
  }
19912
20013
  toPlainText() {
19913
20014
  return this.getText();
@@ -19917,34 +20018,42 @@ var RichTextParagraphBuilder = class extends RichTextValue {
19917
20018
  * @returns Editable text runs in document order.
19918
20019
  */
19919
20020
  getTextRuns() {
20021
+ this._assertActive();
19920
20022
  return this._owner._createTextRunBuilders(this._range);
19921
20023
  }
19922
20024
  getParagraphStyle() {
20025
+ this._assertActive();
19923
20026
  return ParagraphStyleValue.create(this._getParagraph().paragraphStyle);
19924
20027
  }
19925
20028
  getParagraphBullet() {
20029
+ this._assertActive();
19926
20030
  return this._getParagraph().bullet;
19927
20031
  }
19928
20032
  getLinks() {
19929
- var _this$getData$body$cu, _this$getData$body;
19930
- return (_this$getData$body$cu = (_this$getData$body = this.getData().body) === null || _this$getData$body === void 0 || (_this$getData$body = _this$getData$body.customRanges) === null || _this$getData$body === void 0 ? void 0 : _this$getData$body.filter((range) => range.rangeType === 0)) !== null && _this$getData$body$cu !== void 0 ? _this$getData$body$cu : [];
20033
+ var _this$getData$body;
20034
+ this._assertActive();
20035
+ return ((_this$getData$body = this.getData().body) === null || _this$getData$body === void 0 || (_this$getData$body = _this$getData$body.customRanges) === null || _this$getData$body === void 0 ? void 0 : _this$getData$body.filter((range) => range.rangeType === 0)) ?? [];
19931
20036
  }
19932
20037
  /** Agent-friendly alias of `getParagraphBullet()`. */
19933
20038
  getBullet() {
19934
20039
  return this.getParagraphBullet();
19935
20040
  }
19936
20041
  getData() {
20042
+ this._assertActive();
19937
20043
  return createParagraphSnapshot(this._owner.getData(), this._paragraphId, this._range);
19938
20044
  }
19939
20045
  copy() {
19940
20046
  return RichTextBuilder.create(Tools.deepClone(this.getData()));
19941
20047
  }
19942
20048
  _getParagraph() {
19943
- var _this$_owner$getData$3;
19944
- const paragraph = (_this$_owner$getData$3 = this._owner.getData().body) === null || _this$_owner$getData$3 === void 0 || (_this$_owner$getData$3 = _this$_owner$getData$3.paragraphs) === null || _this$_owner$getData$3 === void 0 ? void 0 : _this$_owner$getData$3.find((item) => item.paragraphId === this._paragraphId);
20049
+ var _this$_owner$getData$2;
20050
+ const paragraph = (_this$_owner$getData$2 = this._owner.getData().body) === null || _this$_owner$getData$2 === void 0 || (_this$_owner$getData$2 = _this$_owner$getData$2.paragraphs) === null || _this$_owner$getData$2 === void 0 ? void 0 : _this$_owner$getData$2.find((item) => item.paragraphId === this._paragraphId);
19945
20051
  if (!paragraph) throw new Error(`Rich text paragraph "${this._paragraphId}" was not found.`);
19946
20052
  return paragraph;
19947
20053
  }
20054
+ _assertActive() {
20055
+ this._owner._assertChildHandleRevision(this._revision);
20056
+ }
19948
20057
  };
19949
20058
  /**
19950
20059
  * An editable text-run handle owned by a detached {@link RichTextBuilder}.
@@ -19954,38 +20063,45 @@ var RichTextParagraphBuilder = class extends RichTextValue {
19954
20063
  */
19955
20064
  var RichTextRunBuilder = class {
19956
20065
  /** @hideconstructor */
19957
- constructor(_owner, _range, _textStyle, _styleId, _hasExplicitTextStyle) {
20066
+ constructor(_owner, _range, _textStyle, _styleId, _hasExplicitTextStyle, _revision) {
19958
20067
  this._owner = _owner;
19959
20068
  this._range = _range;
19960
20069
  this._textStyle = _textStyle;
19961
20070
  this._styleId = _styleId;
19962
20071
  this._hasExplicitTextStyle = _hasExplicitTextStyle;
20072
+ this._revision = _revision;
19963
20073
  _defineProperty(this, "_active", true);
19964
20074
  }
19965
20075
  /** Inclusive start offset, kept for compatibility with existing `getTextRuns()` callers. */
19966
20076
  get st() {
20077
+ this._assertActive();
19967
20078
  return this._range.startOffset;
19968
20079
  }
19969
20080
  /** Exclusive end offset, automatically updated after text replacement. */
19970
20081
  get ed() {
20082
+ this._assertActive();
19971
20083
  return this._range.endOffset;
19972
20084
  }
19973
20085
  /** Optional persisted style id. This is not a stable run identity. */
19974
20086
  get sId() {
20087
+ this._assertActive();
19975
20088
  return this._styleId;
19976
20089
  }
19977
20090
  /** Existing text-style value property exposed by `getTextRuns()`. */
19978
20091
  get ts() {
20092
+ this._assertActive();
19979
20093
  return this._textStyle ? TextStyleValue.create(this._textStyle) : null;
19980
20094
  }
19981
20095
  /** Returns the current run range. */
19982
20096
  getRange() {
20097
+ this._assertActive();
19983
20098
  return { ...this._range };
19984
20099
  }
19985
20100
  /** Returns the current run text. */
19986
20101
  getText() {
19987
- var _this$_owner$getData$4, _this$_owner$getData$5;
19988
- return ((_this$_owner$getData$4 = (_this$_owner$getData$5 = this._owner.getData().body) === null || _this$_owner$getData$5 === void 0 ? void 0 : _this$_owner$getData$5.dataStream) !== null && _this$_owner$getData$4 !== void 0 ? _this$_owner$getData$4 : "").slice(this._range.startOffset, this._range.endOffset);
20102
+ var _this$_owner$getData$3;
20103
+ this._assertActive();
20104
+ return (((_this$_owner$getData$3 = this._owner.getData().body) === null || _this$_owner$getData$3 === void 0 ? void 0 : _this$_owner$getData$3.dataStream) ?? "").slice(this._range.startOffset, this._range.endOffset);
19989
20105
  }
19990
20106
  /** Returns this run's explicit text style, or `null` for an unstyled text segment. */
19991
20107
  getTextStyle() {
@@ -19993,6 +20109,7 @@ var RichTextRunBuilder = class {
19993
20109
  }
19994
20110
  /** Returns whether this segment is backed by an explicit document text run. */
19995
20111
  hasTextStyle() {
20112
+ this._assertActive();
19996
20113
  return this._hasExplicitTextStyle;
19997
20114
  }
19998
20115
  /**
@@ -20020,17 +20137,21 @@ var RichTextRunBuilder = class {
20020
20137
  * ```
20021
20138
  */
20022
20139
  setText(text) {
20023
- if (!this._active) throw new Error("Rich text run handle is no longer valid.");
20140
+ this._assertActive();
20024
20141
  this._owner._replaceTextRun(this._range, text, this._textStyle, this._styleId, this._hasExplicitTextStyle);
20025
20142
  if (!text) this._active = false;
20026
20143
  return this;
20027
20144
  }
20145
+ _assertActive() {
20146
+ if (!this._active) throw new Error("Rich text run handle is no longer valid.");
20147
+ this._owner._assertChildHandleRevision(this._revision);
20148
+ }
20028
20149
  };
20029
20150
  function createParagraphSnapshot(data, paragraphId, range) {
20030
- var _body$paragraphs2;
20151
+ var _body$paragraphs;
20031
20152
  const { body, ...documentData } = data;
20032
20153
  if (!body) throw new Error("Rich text body is not available.");
20033
- const paragraph = (_body$paragraphs2 = body.paragraphs) === null || _body$paragraphs2 === void 0 ? void 0 : _body$paragraphs2.find((item) => item.paragraphId === paragraphId);
20154
+ const paragraph = (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.find((item) => item.paragraphId === paragraphId);
20034
20155
  if (!paragraph) throw new Error(`Rich text paragraph "${paragraphId}" was not found.`);
20035
20156
  const paragraphBody = getBodySlice(body, range.startOffset, range.endOffset);
20036
20157
  paragraphBody.paragraphs = [{
@@ -20077,13 +20198,9 @@ function validateMinimumRootSentinels(body, issues, context) {
20077
20198
  if (!body.dataStream.includes("\n")) issues.push(createIssue(context, "missing-root-section-break", "Document body must contain at least one section break sentinel."));
20078
20199
  }
20079
20200
  function validateParagraphMetadata(body, issues, context) {
20080
- var _body$paragraphs;
20081
20201
  const metadataCounts = /* @__PURE__ */ new Map();
20082
- for (const paragraph of (_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []) if (body.dataStream[paragraph.startIndex] !== "\r") issues.push(createIssue(context, "paragraph-token-mismatch", "Paragraph metadata must point to a paragraph sentinel.", paragraph.startIndex));
20083
- else {
20084
- var _metadataCounts$get;
20085
- metadataCounts.set(paragraph.startIndex, ((_metadataCounts$get = metadataCounts.get(paragraph.startIndex)) !== null && _metadataCounts$get !== void 0 ? _metadataCounts$get : 0) + 1);
20086
- }
20202
+ for (const paragraph of body.paragraphs ?? []) if (body.dataStream[paragraph.startIndex] !== "\r") issues.push(createIssue(context, "paragraph-token-mismatch", "Paragraph metadata must point to a paragraph sentinel.", paragraph.startIndex));
20203
+ else metadataCounts.set(paragraph.startIndex, (metadataCounts.get(paragraph.startIndex) ?? 0) + 1);
20087
20204
  validatePointMetadataDuplicates(metadataCounts, {
20088
20205
  context,
20089
20206
  duplicateCode: "duplicate-paragraph-metadata",
@@ -20091,20 +20208,13 @@ function validateParagraphMetadata(body, issues, context) {
20091
20208
  }, issues);
20092
20209
  }
20093
20210
  function validateSectionBreakMetadata(body, issues, context) {
20094
- var _body$sectionBreaks;
20095
20211
  const metadataCounts = /* @__PURE__ */ new Map();
20096
20212
  const sectionIds = /* @__PURE__ */ new Map();
20097
- for (const sectionBreak of (_body$sectionBreaks = body.sectionBreaks) !== null && _body$sectionBreaks !== void 0 ? _body$sectionBreaks : []) {
20213
+ for (const sectionBreak of body.sectionBreaks ?? []) {
20098
20214
  if (!sectionBreak.sectionId) issues.push(createIssue(context, "missing-section-id", "Section break metadata must have a stable section id.", sectionBreak.startIndex));
20099
- else {
20100
- var _sectionIds$get;
20101
- sectionIds.set(sectionBreak.sectionId, ((_sectionIds$get = sectionIds.get(sectionBreak.sectionId)) !== null && _sectionIds$get !== void 0 ? _sectionIds$get : 0) + 1);
20102
- }
20215
+ else sectionIds.set(sectionBreak.sectionId, (sectionIds.get(sectionBreak.sectionId) ?? 0) + 1);
20103
20216
  if (body.dataStream[sectionBreak.startIndex] !== "\n") issues.push(createIssue(context, "section-break-token-mismatch", "Section break metadata must point to a section break sentinel.", sectionBreak.startIndex));
20104
- else {
20105
- var _metadataCounts$get2;
20106
- metadataCounts.set(sectionBreak.startIndex, ((_metadataCounts$get2 = metadataCounts.get(sectionBreak.startIndex)) !== null && _metadataCounts$get2 !== void 0 ? _metadataCounts$get2 : 0) + 1);
20107
- }
20217
+ else metadataCounts.set(sectionBreak.startIndex, (metadataCounts.get(sectionBreak.startIndex) ?? 0) + 1);
20108
20218
  }
20109
20219
  validatePointMetadataDuplicates(metadataCounts, {
20110
20220
  context,
@@ -20133,11 +20243,10 @@ function collectPairedTokenRanges(dataStream, startToken, endToken, exclusiveEnd
20133
20243
  };
20134
20244
  }
20135
20245
  function validateTableMetadata(body, issues, context) {
20136
- var _body$tables;
20137
20246
  const pairedTables = collectPairedTokenRanges(body.dataStream, "", "", true).pairs;
20138
20247
  const metadataStarts = /* @__PURE__ */ new Set();
20139
20248
  let previousTable;
20140
- const tables = [...(_body$tables = body.tables) !== null && _body$tables !== void 0 ? _body$tables : []].sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
20249
+ const tables = [...body.tables ?? []].sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
20141
20250
  for (const table of tables) {
20142
20251
  metadataStarts.add(table.startIndex);
20143
20252
  if (!Number.isInteger(table.startIndex) || body.dataStream[table.startIndex] !== "") issues.push(createIssue(context, "table-start-token-mismatch", "Table startIndex must point to a table start sentinel.", table.startIndex));
@@ -20148,10 +20257,9 @@ function validateTableMetadata(body, issues, context) {
20148
20257
  for (const startIndex of pairedTables.keys()) if (!metadataStarts.has(startIndex)) issues.push(createIssue(context, "missing-table-metadata", "Table token range must have a table metadata entry.", startIndex));
20149
20258
  }
20150
20259
  function validateBlockRangeMetadata(body, issues, context) {
20151
- var _body$blockRanges;
20152
20260
  const pairedBlocks = collectPairedTokenRanges(body.dataStream, "", "", false);
20153
20261
  for (const index of [...pairedBlocks.unmatchedStarts, ...pairedBlocks.unmatchedEnds]) issues.push(createIssue(context, "unbalanced-block", "Block sentinel has no matching boundary.", index));
20154
- const blockRanges = [...(_body$blockRanges = body.blockRanges) !== null && _body$blockRanges !== void 0 ? _body$blockRanges : []].sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
20262
+ const blockRanges = [...body.blockRanges ?? []].sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
20155
20263
  const metadataStarts = /* @__PURE__ */ new Set();
20156
20264
  let previousBlockRange;
20157
20265
  for (let i = 0; i < blockRanges.length; i++) {
@@ -20164,10 +20272,9 @@ function validateBlockRangeMetadata(body, issues, context) {
20164
20272
  for (const startIndex of pairedBlocks.pairs.keys()) if (!metadataStarts.has(startIndex)) issues.push(createIssue(context, "missing-block-range-metadata", "Block token range must have a block metadata entry.", startIndex));
20165
20273
  }
20166
20274
  function validateColumnGroupMetadata(body, issues, context) {
20167
- var _body$columnGroups;
20168
20275
  const pairedColumnGroups = collectPairedTokenRanges(body.dataStream, "", "", false).pairs;
20169
20276
  const metadataStarts = /* @__PURE__ */ new Set();
20170
- const columnGroups = [...(_body$columnGroups = body.columnGroups) !== null && _body$columnGroups !== void 0 ? _body$columnGroups : []].sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
20277
+ const columnGroups = [...body.columnGroups ?? []].sort((a, b) => a.startIndex - b.startIndex || a.endIndex - b.endIndex);
20171
20278
  let previousColumnGroup;
20172
20279
  for (const columnGroup of columnGroups) {
20173
20280
  metadataStarts.add(columnGroup.startIndex);
@@ -20177,7 +20284,7 @@ function validateColumnGroupMetadata(body, issues, context) {
20177
20284
  previousColumnGroup = columnGroup;
20178
20285
  if (Array.isArray(columnGroup.columns)) {
20179
20286
  let streamColumnCount = 0;
20180
- const scanEnd = pairedEndIndex !== null && pairedEndIndex !== void 0 ? pairedEndIndex : columnGroup.endIndex;
20287
+ const scanEnd = pairedEndIndex ?? columnGroup.endIndex;
20181
20288
  for (let index = columnGroup.startIndex + 1; index < scanEnd; index++) if (body.dataStream[index] === "") streamColumnCount++;
20182
20289
  if (streamColumnCount !== columnGroup.columns.length) issues.push(createIssue(context, "column-group-column-count-mismatch", "Column group metadata column count must match the data stream.", columnGroup.startIndex));
20183
20290
  }
@@ -20185,16 +20292,14 @@ function validateColumnGroupMetadata(body, issues, context) {
20185
20292
  for (const startIndex of pairedColumnGroups.keys()) if (!metadataStarts.has(startIndex)) issues.push(createIssue(context, "missing-column-group-metadata", "Column group token range must have a metadata entry.", startIndex));
20186
20293
  }
20187
20294
  function validateCustomBlockMetadata(body, issues, context) {
20188
- var _body$customBlocks;
20189
20295
  const metadataCounts = /* @__PURE__ */ new Map();
20190
- for (const customBlock of (_body$customBlocks = body.customBlocks) !== null && _body$customBlocks !== void 0 ? _body$customBlocks : []) {
20191
- var _metadataCounts$get3;
20296
+ for (const customBlock of body.customBlocks ?? []) {
20192
20297
  const { startIndex } = customBlock;
20193
20298
  if (!Number.isInteger(startIndex) || body.dataStream[startIndex] !== "\b") {
20194
20299
  issues.push(createIssue(context, "custom-block-token-mismatch", "Custom block startIndex must point to a custom block sentinel.", startIndex));
20195
20300
  continue;
20196
20301
  }
20197
- metadataCounts.set(startIndex, ((_metadataCounts$get3 = metadataCounts.get(startIndex)) !== null && _metadataCounts$get3 !== void 0 ? _metadataCounts$get3 : 0) + 1);
20302
+ metadataCounts.set(startIndex, (metadataCounts.get(startIndex) ?? 0) + 1);
20198
20303
  }
20199
20304
  validatePointMetadataDuplicates(metadataCounts, {
20200
20305
  context,
@@ -20269,14 +20374,13 @@ function validateDocBodyStructure(body, context = { segmentType: "body" }) {
20269
20374
  return issues;
20270
20375
  }
20271
20376
  function validateDocumentStructure(snapshot) {
20272
- var _snapshot$headers, _snapshot$footers;
20273
20377
  const issues = [];
20274
20378
  if (snapshot.body) issues.push(...validateDocBodyStructure(snapshot.body, { segmentType: "body" }));
20275
- for (const [headerId, header] of Object.entries((_snapshot$headers = snapshot.headers) !== null && _snapshot$headers !== void 0 ? _snapshot$headers : {})) issues.push(...validateDocBodyStructure(header.body, {
20379
+ for (const [headerId, header] of Object.entries(snapshot.headers ?? {})) issues.push(...validateDocBodyStructure(header.body, {
20276
20380
  segmentType: "header",
20277
20381
  segmentId: headerId
20278
20382
  }));
20279
- for (const [footerId, footer] of Object.entries((_snapshot$footers = snapshot.footers) !== null && _snapshot$footers !== void 0 ? _snapshot$footers : {})) issues.push(...validateDocBodyStructure(footer.body, {
20383
+ for (const [footerId, footer] of Object.entries(snapshot.footers ?? {})) issues.push(...validateDocBodyStructure(footer.body, {
20280
20384
  segmentType: "footer",
20281
20385
  segmentId: footerId
20282
20386
  }));
@@ -20387,10 +20491,7 @@ var EventSubject = class extends rxjs.Subject {
20387
20491
  else ob = observer;
20388
20492
  const subscription = super.subscribe(ob);
20389
20493
  this._sortedObservers.push(ob);
20390
- this._sortedObservers.sort((a, b) => {
20391
- var _a$priority, _b$priority;
20392
- return ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0) - ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0);
20393
- });
20494
+ this._sortedObservers.sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0));
20394
20495
  subscription.add(() => this._sortedObservers = this._sortedObservers.filter((o) => o !== ob));
20395
20496
  return subscription;
20396
20497
  }
@@ -21099,13 +21200,12 @@ const getDefaultBaselineOffset = (fontSize) => ({
21099
21200
  spo: fontSize
21100
21201
  });
21101
21202
  function createDocumentModelWithStyle(content, textStyle, config = {}) {
21102
- var _paddingData$t, _paddingData$r, _paddingData$b, _paddingData$l;
21103
21203
  const contentLength = content.length;
21104
21204
  const { textRotation, paddingData, horizontalAlign = 0, verticalAlign = 0, wrapStrategy = 0, cellValueType } = config;
21105
- const marginTop = (_paddingData$t = paddingData === null || paddingData === void 0 ? void 0 : paddingData.t) !== null && _paddingData$t !== void 0 ? _paddingData$t : DEFAULT_PADDING_DATA.t;
21106
- const marginRight = (_paddingData$r = paddingData === null || paddingData === void 0 ? void 0 : paddingData.r) !== null && _paddingData$r !== void 0 ? _paddingData$r : DEFAULT_PADDING_DATA.r;
21107
- const marginBottom = (_paddingData$b = paddingData === null || paddingData === void 0 ? void 0 : paddingData.b) !== null && _paddingData$b !== void 0 ? _paddingData$b : DEFAULT_PADDING_DATA.b;
21108
- const marginLeft = (_paddingData$l = paddingData === null || paddingData === void 0 ? void 0 : paddingData.l) !== null && _paddingData$l !== void 0 ? _paddingData$l : DEFAULT_PADDING_DATA.l;
21205
+ const marginTop = (paddingData === null || paddingData === void 0 ? void 0 : paddingData.t) ?? DEFAULT_PADDING_DATA.t;
21206
+ const marginRight = (paddingData === null || paddingData === void 0 ? void 0 : paddingData.r) ?? DEFAULT_PADDING_DATA.r;
21207
+ const marginBottom = (paddingData === null || paddingData === void 0 ? void 0 : paddingData.b) ?? DEFAULT_PADDING_DATA.b;
21208
+ const marginLeft = (paddingData === null || paddingData === void 0 ? void 0 : paddingData.l) ?? DEFAULT_PADDING_DATA.l;
21109
21209
  const { vertexAngle, centerAngle } = convertTextRotation(textRotation);
21110
21210
  return new DocumentDataModel({
21111
21211
  id: "d",
@@ -21400,8 +21500,7 @@ var ColumnManager = class {
21400
21500
  const columnData = {};
21401
21501
  let index = 0;
21402
21502
  for (let i = columnPos; i < columnPos + numColumns; i++) {
21403
- const data = this.getColumn(i);
21404
- columnData[index] = data !== null && data !== void 0 ? data : {
21503
+ columnData[index] = this.getColumn(i) ?? {
21405
21504
  w: this._config.defaultColumnWidth,
21406
21505
  hd: 0
21407
21506
  };
@@ -21422,8 +21521,8 @@ var ColumnManager = class {
21422
21521
  * @returns {number} width of column
21423
21522
  */
21424
21523
  getColumnWidth(columnPos) {
21425
- var _this$_columnData$col2, _this$_columnData$col3;
21426
- return (_this$_columnData$col2 = (_this$_columnData$col3 = this._columnData[columnPos]) === null || _this$_columnData$col3 === void 0 ? void 0 : _this$_columnData$col3.w) !== null && _this$_columnData$col2 !== void 0 ? _this$_columnData$col2 : this._config.defaultColumnWidth;
21524
+ var _this$_columnData$col2;
21525
+ return ((_this$_columnData$col2 = this._columnData[columnPos]) === null || _this$_columnData$col2 === void 0 ? void 0 : _this$_columnData$col2.w) ?? this._config.defaultColumnWidth;
21427
21526
  }
21428
21527
  /**
21429
21528
  * Set the width of column
@@ -21544,8 +21643,7 @@ var RowManager = class {
21544
21643
  const rowData = {};
21545
21644
  let index = 0;
21546
21645
  for (let i = rowPos; i < rowPos + numRows; i++) {
21547
- const data = this.getRow(i);
21548
- rowData[index] = data !== null && data !== void 0 ? data : {
21646
+ rowData[index] = this.getRow(i) ?? {
21549
21647
  h: this._config.defaultRowHeight,
21550
21648
  hd: 0
21551
21649
  };
@@ -21986,8 +22084,8 @@ var SheetViewModel = class extends Disposable {
21986
22084
  return this.getRawCell(row, col);
21987
22085
  }
21988
22086
  getRowFiltered(row) {
21989
- var _this$_rowFilteredInt, _this$_rowFilteredInt2;
21990
- return (_this$_rowFilteredInt = (_this$_rowFilteredInt2 = this._rowFilteredInterceptor) === null || _this$_rowFilteredInt2 === void 0 ? void 0 : _this$_rowFilteredInt2.getRowFiltered(row)) !== null && _this$_rowFilteredInt !== void 0 ? _this$_rowFilteredInt : false;
22087
+ var _this$_rowFilteredInt;
22088
+ return ((_this$_rowFilteredInt = this._rowFilteredInterceptor) === null || _this$_rowFilteredInt === void 0 ? void 0 : _this$_rowFilteredInt.getRowFiltered(row)) ?? false;
21991
22089
  }
21992
22090
  registerCellContentInterceptor(interceptor) {
21993
22091
  if (this._cellContentInterceptor) throw new Error("[SheetViewModel]: Interceptor already registered.");
@@ -22013,7 +22111,6 @@ const DEFAULT_CELL_DOCUMENT_MODEL_OPTION = {
22013
22111
  */
22014
22112
  var Worksheet = class {
22015
22113
  constructor(unitId, snapshot, _styles) {
22016
- var _this$_snapshot$id;
22017
22114
  this.unitId = unitId;
22018
22115
  this._styles = _styles;
22019
22116
  _defineProperty(this, "_sheetId", void 0);
@@ -22027,7 +22124,7 @@ var Worksheet = class {
22027
22124
  _defineProperty(this, "_getCellHeight", void 0);
22028
22125
  this._snapshot = mergeWorksheetSnapshotWithDefault(snapshot);
22029
22126
  const { columnData, rowData, cellData } = this._snapshot;
22030
- this._sheetId = (_this$_snapshot$id = this._snapshot.id) !== null && _this$_snapshot$id !== void 0 ? _this$_snapshot$id : generateRandomId(6);
22127
+ this._sheetId = this._snapshot.id ?? generateRandomId(6);
22031
22128
  this._cellData = new ObjectMatrix(cellData);
22032
22129
  this._viewModel = new SheetViewModel((row, col) => this.getCellRaw(row, col));
22033
22130
  this._rowManager = new RowManager(this._snapshot, this._viewModel, rowData);
@@ -22144,7 +22241,7 @@ var Worksheet = class {
22144
22241
  const colStyle = this.getColumnStyle(col);
22145
22242
  const cell = this.getCell(row, col);
22146
22243
  const cellStyle = this._styles.getStyleByCell(cell);
22147
- return (rowPriority !== null && rowPriority !== void 0 ? rowPriority : this._isRowStylePrecedeColumnStyle) ? composeStyles(defaultStyle, colStyle, rowStyle, cell === null || cell === void 0 ? void 0 : cell.themeStyle, cellStyle) : composeStyles(defaultStyle, rowStyle, colStyle, cell === null || cell === void 0 ? void 0 : cell.themeStyle, cellStyle);
22244
+ return rowPriority ?? this._isRowStylePrecedeColumnStyle ? composeStyles(defaultStyle, colStyle, rowStyle, cell === null || cell === void 0 ? void 0 : cell.themeStyle, cellStyle) : composeStyles(defaultStyle, rowStyle, colStyle, cell === null || cell === void 0 ? void 0 : cell.themeStyle, cellStyle);
22148
22245
  }
22149
22246
  /**
22150
22247
  * Get the composed style of the cell. If you want to get the style of the cell without merging row style,
@@ -22162,7 +22259,7 @@ var Worksheet = class {
22162
22259
  const rowStyle = this.getRowStyle(row);
22163
22260
  const colStyle = this.getColumnStyle(col);
22164
22261
  const cellStyle = this._styles.getStyleByCell(cellData);
22165
- return (rowPriority !== null && rowPriority !== void 0 ? rowPriority : this._isRowStylePrecedeColumnStyle) ? composeStyles(defaultStyle, colStyle, rowStyle, cellData === null || cellData === void 0 ? void 0 : cellData.themeStyle, cellStyle) : composeStyles(defaultStyle, rowStyle, colStyle, cellData === null || cellData === void 0 ? void 0 : cellData.themeStyle, cellStyle);
22262
+ return rowPriority ?? this._isRowStylePrecedeColumnStyle ? composeStyles(defaultStyle, colStyle, rowStyle, cellData === null || cellData === void 0 ? void 0 : cellData.themeStyle, cellStyle) : composeStyles(defaultStyle, rowStyle, colStyle, cellData === null || cellData === void 0 ? void 0 : cellData.themeStyle, cellStyle);
22166
22263
  }
22167
22264
  /**
22168
22265
  * Get the composed style of the cell without its own style.
@@ -22870,14 +22967,14 @@ var Worksheet = class {
22870
22967
  };
22871
22968
  }
22872
22969
  _updateConfigAndGetDocumentModel(documentData, horizontalAlign, paddingData, renderConfig) {
22873
- var _documentData$body, _paddingData$t, _paddingData$b, _paddingData$l, _paddingData$r;
22970
+ var _documentData$body;
22874
22971
  if (!renderConfig) return;
22875
22972
  if (!((_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream)) return;
22876
22973
  if (!documentData.documentStyle) documentData.documentStyle = {};
22877
- documentData.documentStyle.marginTop = (_paddingData$t = paddingData.t) !== null && _paddingData$t !== void 0 ? _paddingData$t : 0;
22878
- documentData.documentStyle.marginBottom = (_paddingData$b = paddingData.b) !== null && _paddingData$b !== void 0 ? _paddingData$b : 2;
22879
- documentData.documentStyle.marginLeft = (_paddingData$l = paddingData.l) !== null && _paddingData$l !== void 0 ? _paddingData$l : 2;
22880
- documentData.documentStyle.marginRight = (_paddingData$r = paddingData.r) !== null && _paddingData$r !== void 0 ? _paddingData$r : 2;
22974
+ documentData.documentStyle.marginTop = paddingData.t ?? 0;
22975
+ documentData.documentStyle.marginBottom = paddingData.b ?? 2;
22976
+ documentData.documentStyle.marginLeft = paddingData.l ?? 2;
22977
+ documentData.documentStyle.marginRight = paddingData.r ?? 2;
22881
22978
  documentData.documentStyle.pageSize = {
22882
22979
  width: Number.POSITIVE_INFINITY,
22883
22980
  height: Number.POSITIVE_INFINITY
@@ -23074,8 +23171,7 @@ let Workbook = class Workbook extends UnitModel {
23074
23171
  return this._unitId;
23075
23172
  }
23076
23173
  getRev() {
23077
- var _this$_snapshot$rev;
23078
- return (_this$_snapshot$rev = this._snapshot.rev) !== null && _this$_snapshot$rev !== void 0 ? _this$_snapshot$rev : 1;
23174
+ return this._snapshot.rev ?? 1;
23079
23175
  }
23080
23176
  incrementRev() {
23081
23177
  this._snapshot.rev = this.getRev() + 1;
@@ -23359,10 +23455,7 @@ let UniverInstanceService = class UniverInstanceService extends Disposable {
23359
23455
  return this._ctorByType.get(type);
23360
23456
  }
23361
23457
  getCurrentTypeOfUnit$(type) {
23362
- return this.currentUnits$.pipe((0, rxjs.map)((units) => {
23363
- var _units$get;
23364
- return (_units$get = units.get(type)) !== null && _units$get !== void 0 ? _units$get : null;
23365
- }), (0, rxjs.distinctUntilChanged)());
23458
+ return this.currentUnits$.pipe((0, rxjs.map)((units) => units.get(type) ?? null), (0, rxjs.distinctUntilChanged)());
23366
23459
  }
23367
23460
  getCurrentUnitOfType(type) {
23368
23461
  return this._currentUnits.get(type);
@@ -23385,7 +23478,6 @@ let UniverInstanceService = class UniverInstanceService extends Disposable {
23385
23478
  * @param unit The unit to be added.
23386
23479
  */
23387
23480
  __addUnit(unit, options) {
23388
- var _options$makeCurrent;
23389
23481
  this._logService.debug(`[UniverInstanceService]: Adding unit with id ${unit.getUnitId()}`);
23390
23482
  const type = unit.type;
23391
23483
  if (!this._unitsByType.has(type)) this._unitsByType.set(type, []);
@@ -23398,7 +23490,7 @@ let UniverInstanceService = class UniverInstanceService extends Disposable {
23398
23490
  unit,
23399
23491
  options
23400
23492
  });
23401
- if ((_options$makeCurrent = options === null || options === void 0 ? void 0 : options.makeCurrent) !== null && _options$makeCurrent !== void 0 ? _options$makeCurrent : true) this.setCurrentUnitForType(unit.getUnitId());
23493
+ if ((options === null || options === void 0 ? void 0 : options.makeCurrent) ?? true) this.setCurrentUnitForType(unit.getUnitId());
23402
23494
  }
23403
23495
  getTypeOfUnitDisposed$(type) {
23404
23496
  return this.unitDisposed$.pipe((0, rxjs.filter)((unit) => unit.type === type));
@@ -23410,12 +23502,10 @@ let UniverInstanceService = class UniverInstanceService extends Disposable {
23410
23502
  return unit;
23411
23503
  }
23412
23504
  getUnitCreateOptions(unitId) {
23413
- var _this$_unitCreateOpti;
23414
- return (_this$_unitCreateOpti = this._unitCreateOptions.get(unitId)) !== null && _this$_unitCreateOpti !== void 0 ? _this$_unitCreateOpti : null;
23505
+ return this._unitCreateOptions.get(unitId) ?? null;
23415
23506
  }
23416
23507
  getAllUnitsForType(type) {
23417
- var _this$_unitsByType$ge;
23418
- return (_this$_unitsByType$ge = this._unitsByType.get(type)) !== null && _this$_unitsByType$ge !== void 0 ? _this$_unitsByType$ge : [];
23508
+ return this._unitsByType.get(type) ?? [];
23419
23509
  }
23420
23510
  get focused() {
23421
23511
  var _this$_getUnitById2;
@@ -23724,16 +23814,15 @@ var LocaleService = class extends Disposable {
23724
23814
  * @param locales - Locale object
23725
23815
  */
23726
23816
  load(locales) {
23727
- var _this$_locales;
23728
- this._locales = (0, lodash_es.merge)((_this$_locales = this._locales) !== null && _this$_locales !== void 0 ? _this$_locales : {}, locales);
23817
+ this._locales = (0, lodash_es.merge)(this._locales ?? {}, locales);
23729
23818
  }
23730
23819
  setLocale(locale) {
23731
23820
  this._currentLocale$.next(locale);
23732
23821
  this.localeChanged$.next();
23733
23822
  }
23734
23823
  getLocales() {
23735
- var _this$_locales2;
23736
- return (_this$_locales2 = this._locales) === null || _this$_locales2 === void 0 ? void 0 : _this$_locales2[this._currentLocale];
23824
+ var _this$_locales;
23825
+ return (_this$_locales = this._locales) === null || _this$_locales === void 0 ? void 0 : _this$_locales[this._currentLocale];
23737
23826
  }
23738
23827
  getCurrentLocale() {
23739
23828
  return this._currentLocale;
@@ -24460,12 +24549,12 @@ let LocalUndoRedoService = class LocalUndoRedoService extends Disposable {
24460
24549
  if (isFocusSheet) if (isFocusFormulaEditor) unitID = DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
24461
24550
  else if (isFocusEditor) unitID = DOCS_NORMAL_EDITOR_UNIT_ID_KEY;
24462
24551
  else {
24463
- var _this$_univerInstance, _this$_univerInstance2;
24464
- unitID = (_this$_univerInstance = (_this$_univerInstance2 = this._univerInstanceService.getFocusedUnit()) === null || _this$_univerInstance2 === void 0 ? void 0 : _this$_univerInstance2.getUnitId()) !== null && _this$_univerInstance !== void 0 ? _this$_univerInstance : "";
24552
+ var _this$_univerInstance;
24553
+ unitID = ((_this$_univerInstance = this._univerInstanceService.getFocusedUnit()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getUnitId()) ?? "";
24465
24554
  }
24466
24555
  else {
24467
- var _this$_univerInstance3, _this$_univerInstance4;
24468
- unitID = (_this$_univerInstance3 = (_this$_univerInstance4 = this._univerInstanceService.getFocusedUnit()) === null || _this$_univerInstance4 === void 0 ? void 0 : _this$_univerInstance4.getUnitId()) !== null && _this$_univerInstance3 !== void 0 ? _this$_univerInstance3 : "";
24556
+ var _this$_univerInstance2;
24557
+ unitID = ((_this$_univerInstance2 = this._univerInstanceService.getFocusedUnit()) === null || _this$_univerInstance2 === void 0 ? void 0 : _this$_univerInstance2.getUnitId()) ?? "";
24469
24558
  }
24470
24559
  return unitID;
24471
24560
  }
@@ -25141,9 +25230,8 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25141
25230
  this.initConfig();
25142
25231
  }
25143
25232
  initConfig() {
25144
- var _this$_configService$, _this$_configService$2;
25145
- this._skipAutoHeightForMergedCells = !((_this$_configService$ = this._configService.getConfig(AUTO_HEIGHT_FOR_MERGED_CELLS)) !== null && _this$_configService$ !== void 0 ? _this$_configService$ : false);
25146
- this.worksheet.setIsRowStylePrecedeColumnStyle((_this$_configService$2 = this._configService.getConfig("isRowStylePrecedeColumnStyle")) !== null && _this$_configService$2 !== void 0 ? _this$_configService$2 : false);
25233
+ this._skipAutoHeightForMergedCells = !(this._configService.getConfig(AUTO_HEIGHT_FOR_MERGED_CELLS) ?? false);
25234
+ this.worksheet.setIsRowStylePrecedeColumnStyle(this._configService.getConfig("isRowStylePrecedeColumnStyle") ?? false);
25147
25235
  }
25148
25236
  resetCache() {}
25149
25237
  /**
@@ -25229,28 +25317,27 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25229
25317
  this._updateLayout();
25230
25318
  }
25231
25319
  _fillDefaultGapThemeColors(config) {
25232
- var _config$defaultBackgr, _config$defaultStripe;
25233
25320
  if (config.defaultBackgroundColor && config.defaultStripeColor) return config;
25234
25321
  const { r, g, b } = new ColorKit(this._injector.get(ThemeService).getColorFromTheme("primary.500")).toRgb();
25235
25322
  return {
25236
25323
  ...config,
25237
- defaultBackgroundColor: (_config$defaultBackgr = config.defaultBackgroundColor) !== null && _config$defaultBackgr !== void 0 ? _config$defaultBackgr : `rgba(${r}, ${g}, ${b}, 0.025)`,
25238
- defaultStripeColor: (_config$defaultStripe = config.defaultStripeColor) !== null && _config$defaultStripe !== void 0 ? _config$defaultStripe : `rgba(${r}, ${g}, ${b}, 0.08)`
25324
+ defaultBackgroundColor: config.defaultBackgroundColor ?? `rgba(${r}, ${g}, ${b}, 0.025)`,
25325
+ defaultStripeColor: config.defaultStripeColor ?? `rgba(${r}, ${g}, ${b}, 0.08)`
25239
25326
  };
25240
25327
  }
25241
25328
  /**
25242
25329
  * Get the gap size (in px) BEFORE the given row.
25243
25330
  */
25244
25331
  getRowGapSize(row) {
25245
- var _this$_gapConfig$rowG, _this$_gapConfig$rowG2;
25246
- return (_this$_gapConfig$rowG = (_this$_gapConfig$rowG2 = this._gapConfig.rowGaps) === null || _this$_gapConfig$rowG2 === void 0 || (_this$_gapConfig$rowG2 = _this$_gapConfig$rowG2[row]) === null || _this$_gapConfig$rowG2 === void 0 ? void 0 : _this$_gapConfig$rowG2.size) !== null && _this$_gapConfig$rowG !== void 0 ? _this$_gapConfig$rowG : 0;
25332
+ var _this$_gapConfig$rowG;
25333
+ return ((_this$_gapConfig$rowG = this._gapConfig.rowGaps) === null || _this$_gapConfig$rowG === void 0 || (_this$_gapConfig$rowG = _this$_gapConfig$rowG[row]) === null || _this$_gapConfig$rowG === void 0 ? void 0 : _this$_gapConfig$rowG.size) ?? 0;
25247
25334
  }
25248
25335
  /**
25249
25336
  * Get the gap size (in px) BEFORE the given column.
25250
25337
  */
25251
25338
  getColGapSize(col) {
25252
- var _this$_gapConfig$colG, _this$_gapConfig$colG2;
25253
- return (_this$_gapConfig$colG = (_this$_gapConfig$colG2 = this._gapConfig.colGaps) === null || _this$_gapConfig$colG2 === void 0 || (_this$_gapConfig$colG2 = _this$_gapConfig$colG2[col]) === null || _this$_gapConfig$colG2 === void 0 ? void 0 : _this$_gapConfig$colG2.size) !== null && _this$_gapConfig$colG !== void 0 ? _this$_gapConfig$colG : 0;
25339
+ var _this$_gapConfig$colG;
25340
+ return ((_this$_gapConfig$colG = this._gapConfig.colGaps) === null || _this$_gapConfig$colG === void 0 || (_this$_gapConfig$colG = _this$_gapConfig$colG[col]) === null || _this$_gapConfig$colG === void 0 ? void 0 : _this$_gapConfig$colG.size) ?? 0;
25254
25341
  }
25255
25342
  /**
25256
25343
  * Returns a gap size getter object for use with coordinate utility functions.
@@ -25270,11 +25357,11 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25270
25357
  const { rowGaps } = this._gapConfig;
25271
25358
  if (!rowGaps) return -1;
25272
25359
  for (const rowStr of Object.keys(rowGaps)) {
25273
- var _rowGaps$row$size, _rowGaps$row, _this$_rowHeightAccum;
25360
+ var _rowGaps$row;
25274
25361
  const row = Number(rowStr);
25275
- const gapSize = (_rowGaps$row$size = (_rowGaps$row = rowGaps[row]) === null || _rowGaps$row === void 0 ? void 0 : _rowGaps$row.size) !== null && _rowGaps$row$size !== void 0 ? _rowGaps$row$size : 0;
25362
+ const gapSize = ((_rowGaps$row = rowGaps[row]) === null || _rowGaps$row === void 0 ? void 0 : _rowGaps$row.size) ?? 0;
25276
25363
  if (gapSize <= 0) continue;
25277
- const gapStart = (_this$_rowHeightAccum = this._rowHeightAccumulation[row - 1]) !== null && _this$_rowHeightAccum !== void 0 ? _this$_rowHeightAccum : 0;
25364
+ const gapStart = this._rowHeightAccumulation[row - 1] ?? 0;
25278
25365
  const gapEnd = gapStart + gapSize;
25279
25366
  if (y >= gapStart && y < gapEnd) return row;
25280
25367
  }
@@ -25288,11 +25375,11 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25288
25375
  const { colGaps } = this._gapConfig;
25289
25376
  if (!colGaps) return -1;
25290
25377
  for (const colStr of Object.keys(colGaps)) {
25291
- var _colGaps$col$size, _colGaps$col, _this$_columnWidthAcc;
25378
+ var _colGaps$col;
25292
25379
  const col = Number(colStr);
25293
- const gapSize = (_colGaps$col$size = (_colGaps$col = colGaps[col]) === null || _colGaps$col === void 0 ? void 0 : _colGaps$col.size) !== null && _colGaps$col$size !== void 0 ? _colGaps$col$size : 0;
25380
+ const gapSize = ((_colGaps$col = colGaps[col]) === null || _colGaps$col === void 0 ? void 0 : _colGaps$col.size) ?? 0;
25294
25381
  if (gapSize <= 0) continue;
25295
- const gapStart = (_this$_columnWidthAcc = this._columnWidthAccumulation[col - 1]) !== null && _this$_columnWidthAcc !== void 0 ? _this$_columnWidthAcc : 0;
25382
+ const gapStart = this._columnWidthAccumulation[col - 1] ?? 0;
25296
25383
  const gapEnd = gapStart + gapSize;
25297
25384
  if (x >= gapStart && x < gapEnd) return col;
25298
25385
  }
@@ -25303,7 +25390,7 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25303
25390
  const rowHeightAccumulation = [];
25304
25391
  const data = rowData;
25305
25392
  for (let r = 0; r < rowCount; r++) {
25306
- var _this$_gapConfig$rowG3, _this$_gapConfig$rowG4;
25393
+ var _this$_gapConfig$rowG2;
25307
25394
  let rowHeight = defaultRowHeight;
25308
25395
  if (this.worksheet.getRowFiltered(r)) rowHeight = 0;
25309
25396
  else if (data[r] != null) {
@@ -25314,7 +25401,7 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25314
25401
  else rowHeight = h;
25315
25402
  if (rowDataItem.hd === 1) rowHeight = 0;
25316
25403
  }
25317
- const gapSize = (_this$_gapConfig$rowG3 = (_this$_gapConfig$rowG4 = this._gapConfig.rowGaps) === null || _this$_gapConfig$rowG4 === void 0 || (_this$_gapConfig$rowG4 = _this$_gapConfig$rowG4[r]) === null || _this$_gapConfig$rowG4 === void 0 ? void 0 : _this$_gapConfig$rowG4.size) !== null && _this$_gapConfig$rowG3 !== void 0 ? _this$_gapConfig$rowG3 : 0;
25404
+ const gapSize = ((_this$_gapConfig$rowG2 = this._gapConfig.rowGaps) === null || _this$_gapConfig$rowG2 === void 0 || (_this$_gapConfig$rowG2 = _this$_gapConfig$rowG2[r]) === null || _this$_gapConfig$rowG2 === void 0 ? void 0 : _this$_gapConfig$rowG2.size) ?? 0;
25318
25405
  rowTotalHeight += gapSize;
25319
25406
  rowTotalHeight += rowHeight;
25320
25407
  rowHeightAccumulation.push(rowTotalHeight);
@@ -25332,7 +25419,7 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25332
25419
  const columnWidthAccumulation = [];
25333
25420
  const data = columnData;
25334
25421
  for (let c = 0; c < colCount; c++) {
25335
- var _this$_gapConfig$colG3, _this$_gapConfig$colG4;
25422
+ var _this$_gapConfig$colG2;
25336
25423
  let columnWidth = defaultColumnWidth;
25337
25424
  if (data[c] != null) {
25338
25425
  const columnDataItem = data[c];
@@ -25340,7 +25427,7 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25340
25427
  if (columnDataItem.w != null) columnWidth = columnDataItem.w;
25341
25428
  if (columnDataItem.hd === 1) columnWidth = 0;
25342
25429
  }
25343
- const gapSize = (_this$_gapConfig$colG3 = (_this$_gapConfig$colG4 = this._gapConfig.colGaps) === null || _this$_gapConfig$colG4 === void 0 || (_this$_gapConfig$colG4 = _this$_gapConfig$colG4[c]) === null || _this$_gapConfig$colG4 === void 0 ? void 0 : _this$_gapConfig$colG4.size) !== null && _this$_gapConfig$colG3 !== void 0 ? _this$_gapConfig$colG3 : 0;
25430
+ const gapSize = ((_this$_gapConfig$colG2 = this._gapConfig.colGaps) === null || _this$_gapConfig$colG2 === void 0 || (_this$_gapConfig$colG2 = _this$_gapConfig$colG2[c]) === null || _this$_gapConfig$colG2 === void 0 ? void 0 : _this$_gapConfig$colG2.size) ?? 0;
25344
25431
  columnTotalWidth += gapSize;
25345
25432
  columnTotalWidth += columnWidth;
25346
25433
  columnWidthAccumulation.push(columnTotalWidth);
@@ -25526,8 +25613,7 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25526
25613
  offsetY = getTransformOffsetY(offsetY, scaleY, scrollXY, this.columnHeaderHeightAndMarginTop);
25527
25614
  let row = searchArray(rowHeightAccumulation, offsetY, options === null || options === void 0 ? void 0 : options.firstMatch);
25528
25615
  if (options === null || options === void 0 ? void 0 : options.closeFirst) {
25529
- var _rowHeightAccumulatio;
25530
- if (Math.abs(rowHeightAccumulation[row] - offsetY) < Math.abs(offsetY - ((_rowHeightAccumulatio = rowHeightAccumulation[row - 1]) !== null && _rowHeightAccumulatio !== void 0 ? _rowHeightAccumulatio : 0))) row = row + 1;
25616
+ if (Math.abs(rowHeightAccumulation[row] - offsetY) < Math.abs(offsetY - (rowHeightAccumulation[row - 1] ?? 0))) row = row + 1;
25531
25617
  }
25532
25618
  return row;
25533
25619
  }
@@ -25539,8 +25625,7 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25539
25625
  const { columnWidthAccumulation } = this;
25540
25626
  let column = searchArray(columnWidthAccumulation, offsetX, options === null || options === void 0 ? void 0 : options.firstMatch);
25541
25627
  if (options === null || options === void 0 ? void 0 : options.closeFirst) {
25542
- var _columnWidthAccumulat;
25543
- if (Math.abs(columnWidthAccumulation[column] - offsetX) < Math.abs(offsetX - ((_columnWidthAccumulat = columnWidthAccumulation[column - 1]) !== null && _columnWidthAccumulat !== void 0 ? _columnWidthAccumulat : 0))) column = column + 1;
25628
+ if (Math.abs(columnWidthAccumulation[column] - offsetX) < Math.abs(offsetX - (columnWidthAccumulation[column - 1] ?? 0))) column = column + 1;
25544
25629
  }
25545
25630
  return column;
25546
25631
  }
@@ -25675,14 +25760,14 @@ let SheetSkeleton = class SheetSkeleton extends Skeleton {
25675
25760
  };
25676
25761
  }
25677
25762
  _updateConfigAndGetDocumentModel(documentData, horizontalAlign, paddingData, renderConfig) {
25678
- var _documentData$body, _paddingData$t, _paddingData$b, _paddingData$l, _paddingData$r;
25763
+ var _documentData$body;
25679
25764
  if (!renderConfig) return;
25680
25765
  if (!((_documentData$body = documentData.body) === null || _documentData$body === void 0 ? void 0 : _documentData$body.dataStream)) return;
25681
25766
  if (!documentData.documentStyle) documentData.documentStyle = {};
25682
- documentData.documentStyle.marginTop = (_paddingData$t = paddingData.t) !== null && _paddingData$t !== void 0 ? _paddingData$t : 0;
25683
- documentData.documentStyle.marginBottom = (_paddingData$b = paddingData.b) !== null && _paddingData$b !== void 0 ? _paddingData$b : 2;
25684
- documentData.documentStyle.marginLeft = (_paddingData$l = paddingData.l) !== null && _paddingData$l !== void 0 ? _paddingData$l : 2;
25685
- documentData.documentStyle.marginRight = (_paddingData$r = paddingData.r) !== null && _paddingData$r !== void 0 ? _paddingData$r : 2;
25767
+ documentData.documentStyle.marginTop = paddingData.t ?? 0;
25768
+ documentData.documentStyle.marginBottom = paddingData.b ?? 2;
25769
+ documentData.documentStyle.marginLeft = paddingData.l ?? 2;
25770
+ documentData.documentStyle.marginRight = paddingData.r ?? 2;
25686
25771
  documentData.documentStyle.pageSize = {
25687
25772
  width: Number.POSITIVE_INFINITY,
25688
25773
  height: Number.POSITIVE_INFINITY
@@ -25757,10 +25842,9 @@ function getCellCoordByIndexSimple(row, column, rowHeightAccumulation, columnWid
25757
25842
  * @returns {ICellWithCoord} The cell position information of the specified row and column, including the position information of the cell and the merge information of the cell
25758
25843
  */
25759
25844
  function getCellWithCoordByIndexCore(row, column, rowHeightAccumulation, columnWidthAccumulation, mergeDataInfo, gapSizeGetter) {
25760
- var _gapSizeGetter$row, _gapSizeGetter$col;
25761
25845
  row = Tools.clamp(row, 0, rowHeightAccumulation.length - 1);
25762
25846
  column = Tools.clamp(column, 0, columnWidthAccumulation.length - 1);
25763
- let { startY, endY, startX, endX } = getCellCoordByIndexSimple(row, column, rowHeightAccumulation, columnWidthAccumulation, (_gapSizeGetter$row = gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.row(row)) !== null && _gapSizeGetter$row !== void 0 ? _gapSizeGetter$row : 0, (_gapSizeGetter$col = gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.col(column)) !== null && _gapSizeGetter$col !== void 0 ? _gapSizeGetter$col : 0);
25847
+ let { startY, endY, startX, endX } = getCellCoordByIndexSimple(row, column, rowHeightAccumulation, columnWidthAccumulation, (gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.row(row)) ?? 0, (gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.col(column)) ?? 0);
25764
25848
  if (!mergeDataInfo) return {
25765
25849
  startY,
25766
25850
  endY,
@@ -25795,9 +25879,8 @@ function getCellWithCoordByIndexCore(row, column, rowHeightAccumulation, columnW
25795
25879
  const rowAccumulationCount = rowHeightAccumulation.length - 1;
25796
25880
  const columnAccumulationCount = columnWidthAccumulation.length - 1;
25797
25881
  if (isMerged && startRow !== -1 && startColumn !== -1) {
25798
- var _gapSizeGetter$row2, _gapSizeGetter$col2;
25799
- const mergeRowGapSize = (_gapSizeGetter$row2 = gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.row(startRow)) !== null && _gapSizeGetter$row2 !== void 0 ? _gapSizeGetter$row2 : 0;
25800
- const mergeColGapSize = (_gapSizeGetter$col2 = gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.col(startColumn)) !== null && _gapSizeGetter$col2 !== void 0 ? _gapSizeGetter$col2 : 0;
25882
+ const mergeRowGapSize = (gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.row(startRow)) ?? 0;
25883
+ const mergeColGapSize = (gapSizeGetter === null || gapSizeGetter === void 0 ? void 0 : gapSizeGetter.col(startColumn)) ?? 0;
25801
25884
  const mergeStartY = (rowHeightAccumulation[startRow - 1] || 0) + mergeRowGapSize;
25802
25885
  const mergeEndY = rowHeightAccumulation[endRow] || rowHeightAccumulation[rowAccumulationCount];
25803
25886
  const mergeStartX = (columnWidthAccumulation[startColumn - 1] || 0) + mergeColGapSize;
@@ -26252,13 +26335,12 @@ var Univer = class {
26252
26335
  this._univerInstanceService.registerCtorForType(_univerjs_protocol.UniverType.UNIVER_SLIDE, SlideDataModel);
26253
26336
  const univerInstanceService = injector.get(IUniverInstanceService);
26254
26337
  univerInstanceService.__setCreateHandler((type, data, ctor, options) => {
26255
- var _univerInstanceServic;
26256
26338
  const isFirstTime = !this._startedTypes.has(type);
26257
26339
  if (isFirstTime) {
26258
26340
  this._pluginService.startPluginsForType(type);
26259
26341
  this._startedTypes.add(type);
26260
26342
  }
26261
- const actualCtor = (_univerInstanceServic = univerInstanceService.__getCtorByType(type)) !== null && _univerInstanceServic !== void 0 ? _univerInstanceServic : ctor;
26343
+ const actualCtor = univerInstanceService.__getCtorByType(type) ?? ctor;
26262
26344
  if (!actualCtor) throw new Error(`[Univer]: No constructor registered for unit type ${type}.`);
26263
26345
  const model = injector.createInstance(actualCtor, data);
26264
26346
  univerInstanceService.__addUnit(model, options);
@@ -26361,12 +26443,19 @@ Object.defineProperty(exports, 'AuthzIoLocalService', {
26361
26443
  }
26362
26444
  });
26363
26445
  exports.AutoFillSeries = AutoFillSeries;
26446
+ exports.BASE_RECORD_ID_FIELD_ID = BASE_RECORD_ID_FIELD_ID;
26447
+ exports.BASE_RECORD_ID_FIELD_NAME = BASE_RECORD_ID_FIELD_NAME;
26364
26448
  exports.BORDER_KEYS = BORDER_KEYS;
26365
26449
  exports.BORDER_STYLE_KEYS = BORDER_STYLE_KEYS;
26450
+ exports.BaseConditionalColorOperator = BaseConditionalColorOperator;
26451
+ exports.BaseConditionalColorTarget = BaseConditionalColorTarget;
26452
+ exports.BaseConditionalDateMode = BaseConditionalDateMode;
26366
26453
  exports.BaseDataModel = BaseDataModel;
26367
26454
  exports.BaseFieldType = BaseFieldType;
26368
26455
  exports.BaseFilterConjunction = BaseFilterConjunction;
26369
26456
  exports.BaseFilterOperator = BaseFilterOperator;
26457
+ exports.BaseHierarchyInvalidReason = BaseHierarchyInvalidReason;
26458
+ exports.BaseRecordLinkRole = BaseRecordLinkRole;
26370
26459
  exports.BaseSortDirection = BaseSortDirection;
26371
26460
  exports.BaseViewType = BaseViewType;
26372
26461
  exports.BaselineOffset = BaselineOffset;
@@ -26750,6 +26839,7 @@ exports.WrapTextType = WrapTextType;
26750
26839
  exports.addLinkToDocumentModel = addLinkToDocumentModel;
26751
26840
  exports.afterInitApply = afterInitApply;
26752
26841
  exports.afterTime = afterTime;
26842
+ exports.assertBaseTableRecordIdentity = assertBaseTableRecordIdentity;
26753
26843
  exports.awaitTime = awaitTime;
26754
26844
  exports.binSearchFirstGreaterThanTarget = binSearchFirstGreaterThanTarget;
26755
26845
  exports.binarySearchArray = binarySearchArray;
@@ -26782,6 +26872,7 @@ exports.convertObservableToBehaviorSubject = convertObservableToBehaviorSubject;
26782
26872
  exports.covertCellValue = covertCellValue;
26783
26873
  exports.covertCellValues = covertCellValues;
26784
26874
  exports.createAsyncInterceptorKey = createAsyncInterceptorKey;
26875
+ exports.createBaseRecordIdField = createBaseRecordIdField;
26785
26876
  exports.createDefaultBaseTableSnapshot = createDefaultBaseTableSnapshot;
26786
26877
  exports.createDefaultUser = createDefaultUser;
26787
26878
  exports.createDocumentModelWithStyle = createDocumentModelWithStyle;
@@ -26896,6 +26987,7 @@ Object.defineProperty(exports, 'isAsyncHook', {
26896
26987
  return _wendellhu_redi.isAsyncHook;
26897
26988
  }
26898
26989
  });
26990
+ exports.isBaseRecordIdFieldName = isBaseRecordIdFieldName;
26899
26991
  exports.isBlackColor = isBlackColor;
26900
26992
  exports.isBooleanString = isBooleanString;
26901
26993
  exports.isCellCoverable = isCellCoverable;
@@ -26943,6 +27035,7 @@ exports.isSafeUrl = isSafeUrl;
26943
27035
  exports.isSameStyleTextRun = isSameStyleTextRun;
26944
27036
  exports.isTextFormat = isTextFormat;
26945
27037
  exports.isUnitRangesEqual = isUnitRangesEqual;
27038
+ exports.isValidBaseRecordId = isValidBaseRecordId;
26946
27039
  exports.isValidRange = isValidRange;
26947
27040
  Object.defineProperty(exports, 'isValueDependencyItem', {
26948
27041
  enumerable: true,