@teipublisher/oddity-language-server 0.1.0 → 0.2.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/dist/node.cjs CHANGED
@@ -78,8 +78,8 @@ var require_is = __commonJS({
78
78
  function stringArray(value) {
79
79
  return array(value) && value.every((elem) => string(elem));
80
80
  }
81
- function typedArray(value, check) {
82
- return Array.isArray(value) && value.every(check);
81
+ function typedArray(value, check2) {
82
+ return Array.isArray(value) && value.every(check2);
83
83
  }
84
84
  function thenable(value) {
85
85
  return value && func(value.then);
@@ -1536,14 +1536,14 @@ var require_messageReader = __commonJS({
1536
1536
  this.buffer.append(data);
1537
1537
  while (true) {
1538
1538
  if (this.nextMessageLength === -1) {
1539
- const headers = this.buffer.tryReadHeaders(true);
1540
- if (!headers) {
1539
+ const headers2 = this.buffer.tryReadHeaders(true);
1540
+ if (!headers2) {
1541
1541
  return;
1542
1542
  }
1543
- const contentLength = headers.get("content-length");
1543
+ const contentLength = headers2.get("content-length");
1544
1544
  if (!contentLength) {
1545
1545
  this.fireError(new Error(`Header must provide a Content-Length property.
1546
- ${JSON.stringify(Object.fromEntries(headers))}`));
1546
+ ${JSON.stringify(Object.fromEntries(headers2))}`));
1547
1547
  return;
1548
1548
  }
1549
1549
  const length = parseInt(contentLength);
@@ -1723,19 +1723,19 @@ var require_messageWriter = __commonJS({
1723
1723
  }
1724
1724
  });
1725
1725
  return payload.then((buffer) => {
1726
- const headers = [];
1727
- headers.push(ContentLength, buffer.byteLength.toString(), CRLF);
1728
- headers.push(CRLF);
1729
- return this.doWrite(msg, headers, buffer);
1726
+ const headers2 = [];
1727
+ headers2.push(ContentLength, buffer.byteLength.toString(), CRLF);
1728
+ headers2.push(CRLF);
1729
+ return this.doWrite(msg, headers2, buffer);
1730
1730
  }, (error) => {
1731
1731
  this.fireError(error);
1732
1732
  throw error;
1733
1733
  });
1734
1734
  });
1735
1735
  }
1736
- async doWrite(msg, headers, data) {
1736
+ async doWrite(msg, headers2, data) {
1737
1737
  try {
1738
- await this.writable.write(headers.join(""), "ascii");
1738
+ await this.writable.write(headers2.join(""), "ascii");
1739
1739
  return this.writable.write(data);
1740
1740
  } catch (error) {
1741
1741
  this.handleError(error, msg);
@@ -1832,12 +1832,12 @@ var require_messageBuffer = __commonJS({
1832
1832
  }
1833
1833
  const buffer = this._read(chunkBytesRead + offset);
1834
1834
  const result = /* @__PURE__ */ new Map();
1835
- const headers = this.toString(buffer, "ascii").split(CRLF);
1836
- if (headers.length < 2) {
1835
+ const headers2 = this.toString(buffer, "ascii").split(CRLF);
1836
+ if (headers2.length < 2) {
1837
1837
  return result;
1838
1838
  }
1839
- for (let i = 0; i < headers.length - 2; i++) {
1840
- const header = headers[i];
1839
+ for (let i = 0; i < headers2.length - 2; i++) {
1840
+ const header = headers2[i];
1841
1841
  const index = header.indexOf(":");
1842
1842
  if (index === -1) {
1843
1843
  throw new Error(`Message header must separate key and value using ':'
@@ -4300,33 +4300,33 @@ var init_main = __esm({
4300
4300
  }
4301
4301
  DocumentHighlight2.create = create;
4302
4302
  })(DocumentHighlight || (DocumentHighlight = {}));
4303
- (function(SymbolKind2) {
4304
- SymbolKind2.File = 1;
4305
- SymbolKind2.Module = 2;
4306
- SymbolKind2.Namespace = 3;
4307
- SymbolKind2.Package = 4;
4308
- SymbolKind2.Class = 5;
4309
- SymbolKind2.Method = 6;
4310
- SymbolKind2.Property = 7;
4311
- SymbolKind2.Field = 8;
4312
- SymbolKind2.Constructor = 9;
4313
- SymbolKind2.Enum = 10;
4314
- SymbolKind2.Interface = 11;
4315
- SymbolKind2.Function = 12;
4316
- SymbolKind2.Variable = 13;
4317
- SymbolKind2.Constant = 14;
4318
- SymbolKind2.String = 15;
4319
- SymbolKind2.Number = 16;
4320
- SymbolKind2.Boolean = 17;
4321
- SymbolKind2.Array = 18;
4322
- SymbolKind2.Object = 19;
4323
- SymbolKind2.Key = 20;
4324
- SymbolKind2.Null = 21;
4325
- SymbolKind2.EnumMember = 22;
4326
- SymbolKind2.Struct = 23;
4327
- SymbolKind2.Event = 24;
4328
- SymbolKind2.Operator = 25;
4329
- SymbolKind2.TypeParameter = 26;
4303
+ (function(SymbolKind3) {
4304
+ SymbolKind3.File = 1;
4305
+ SymbolKind3.Module = 2;
4306
+ SymbolKind3.Namespace = 3;
4307
+ SymbolKind3.Package = 4;
4308
+ SymbolKind3.Class = 5;
4309
+ SymbolKind3.Method = 6;
4310
+ SymbolKind3.Property = 7;
4311
+ SymbolKind3.Field = 8;
4312
+ SymbolKind3.Constructor = 9;
4313
+ SymbolKind3.Enum = 10;
4314
+ SymbolKind3.Interface = 11;
4315
+ SymbolKind3.Function = 12;
4316
+ SymbolKind3.Variable = 13;
4317
+ SymbolKind3.Constant = 14;
4318
+ SymbolKind3.String = 15;
4319
+ SymbolKind3.Number = 16;
4320
+ SymbolKind3.Boolean = 17;
4321
+ SymbolKind3.Array = 18;
4322
+ SymbolKind3.Object = 19;
4323
+ SymbolKind3.Key = 20;
4324
+ SymbolKind3.Null = 21;
4325
+ SymbolKind3.EnumMember = 22;
4326
+ SymbolKind3.Struct = 23;
4327
+ SymbolKind3.Event = 24;
4328
+ SymbolKind3.Operator = 25;
4329
+ SymbolKind3.TypeParameter = 26;
4330
4330
  })(SymbolKind || (SymbolKind = {}));
4331
4331
  (function(SymbolTag2) {
4332
4332
  SymbolTag2.Deprecated = 1;
@@ -4847,8 +4847,8 @@ var init_main = __esm({
4847
4847
  return value !== null && typeof value === "object";
4848
4848
  }
4849
4849
  Is2.objectLiteral = objectLiteral;
4850
- function typedArray(value, check) {
4851
- return Array.isArray(value) && value.every(check);
4850
+ function typedArray(value, check2) {
4851
+ return Array.isArray(value) && value.every(check2);
4852
4852
  }
4853
4853
  Is2.typedArray = typedArray;
4854
4854
  })(Is || (Is = {}));
@@ -4973,8 +4973,8 @@ var require_is3 = __commonJS({
4973
4973
  function stringArray(value) {
4974
4974
  return array(value) && value.every((elem) => string(elem));
4975
4975
  }
4976
- function typedArray(value, check) {
4977
- return Array.isArray(value) && value.every(check);
4976
+ function typedArray(value, check2) {
4977
+ return Array.isArray(value) && value.every(check2);
4978
4978
  }
4979
4979
  function objectLiteral(value) {
4980
4980
  return value !== null && typeof value === "object";
@@ -10455,12 +10455,12 @@ var require_interopRequireDefault = __commonJS({
10455
10455
  var require_global_this = __commonJS({
10456
10456
  "node_modules/core-js-pure/internals/global-this.js"(exports2, module2) {
10457
10457
  "use strict";
10458
- var check = function(it) {
10458
+ var check2 = function(it) {
10459
10459
  return it && it.Math === Math && it;
10460
10460
  };
10461
10461
  module2.exports = // eslint-disable-next-line es/no-global-this -- safe
10462
- check(typeof globalThis == "object" && globalThis) || check(typeof window == "object" && window) || // eslint-disable-next-line no-restricted-globals -- safe
10463
- check(typeof self == "object" && self) || check(typeof global == "object" && global) || check(typeof exports2 == "object" && exports2) || // eslint-disable-next-line no-new-func -- fallback
10462
+ check2(typeof globalThis == "object" && globalThis) || check2(typeof window == "object" && window) || // eslint-disable-next-line no-restricted-globals -- safe
10463
+ check2(typeof self == "object" && self) || check2(typeof global == "object" && global) || check2(typeof exports2 == "object" && exports2) || // eslint-disable-next-line no-new-func -- fallback
10464
10464
  /* @__PURE__ */ (function() {
10465
10465
  return this;
10466
10466
  })() || Function("return this")();
@@ -16907,7 +16907,7 @@ var require_regexp_flags_detection = __commonJS({
16907
16907
  }
16908
16908
  var O = {};
16909
16909
  var calls = "";
16910
- var expected = INDICES_SUPPORT ? "dgimsy" : "gimsy";
16910
+ var expected2 = INDICES_SUPPORT ? "dgimsy" : "gimsy";
16911
16911
  var addGetter = function(key2, chr) {
16912
16912
  Object.defineProperty(O, key2, { get: function() {
16913
16913
  calls += chr;
@@ -16924,7 +16924,7 @@ var require_regexp_flags_detection = __commonJS({
16924
16924
  if (INDICES_SUPPORT) pairs2.hasIndices = "d";
16925
16925
  for (var key in pairs2) addGetter(key, pairs2[key]);
16926
16926
  var result = Object.getOwnPropertyDescriptor(RegExp2.prototype, "flags").get.call(O);
16927
- return result !== expected || calls !== expected;
16927
+ return result !== expected2 || calls !== expected2;
16928
16928
  });
16929
16929
  module2.exports = { correct: FLAGS_GETTER_IS_CORRECT };
16930
16930
  }
@@ -25663,7 +25663,7 @@ var require_step10 = __commonJS({
25663
25663
  checkNames(child);
25664
25664
  }
25665
25665
  }
25666
- function walk(check, el) {
25666
+ function walk(check2, el) {
25667
25667
  const { local: local2, children: children2 } = el;
25668
25668
  switch (local2) {
25669
25669
  case "choice":
@@ -25691,7 +25691,7 @@ var require_step10 = __commonJS({
25691
25691
  if (children2.length > 2) {
25692
25692
  el.appendChild(parser_1.Element.makeElement("group", children2.slice(1)));
25693
25693
  }
25694
- if (check) {
25694
+ if (check2) {
25695
25695
  checkNames(children2[0]);
25696
25696
  }
25697
25697
  break;
@@ -25699,7 +25699,7 @@ var require_step10 = __commonJS({
25699
25699
  if (children2.length === 1) {
25700
25700
  el.appendChild(parser_1.Element.makeElement("text", []));
25701
25701
  }
25702
- if (check) {
25702
+ if (check2) {
25703
25703
  checkNames(children2[0]);
25704
25704
  for (const attrName of (0, util_1.findMultiNames)(el, ["name"]).name) {
25705
25705
  switch (attrName.getAttribute("ns")) {
@@ -25770,18 +25770,18 @@ var require_step10 = __commonJS({
25770
25770
  if (!(0, parser_1.isElement)(child)) {
25771
25771
  continue;
25772
25772
  }
25773
- let replaced = walk(check, child);
25773
+ let replaced = walk(check2, child);
25774
25774
  while (replaced !== null) {
25775
- replaced = walk(check, replaced);
25775
+ replaced = walk(check2, replaced);
25776
25776
  }
25777
25777
  }
25778
25778
  return null;
25779
25779
  }
25780
- function step10(el, check) {
25781
- let replaced = walk(check, el);
25780
+ function step10(el, check2) {
25781
+ let replaced = walk(check2, el);
25782
25782
  while (replaced !== null) {
25783
25783
  el = replaced;
25784
- replaced = walk(check, el);
25784
+ replaced = walk(check2, el);
25785
25785
  }
25786
25786
  return el;
25787
25787
  }
@@ -31752,9 +31752,9 @@ var require_errors_public = __commonJS({
31752
31752
  var gast_1 = require_gast();
31753
31753
  exports2.defaultParserErrorProvider = {
31754
31754
  buildMismatchTokenMessage: function(_a) {
31755
- var expected = _a.expected, actual = _a.actual, previous = _a.previous, ruleName = _a.ruleName;
31756
- var hasLabel = tokens_public_1.hasTokenLabel(expected);
31757
- var expectedMsg = hasLabel ? "--> " + tokens_public_1.tokenLabel(expected) + " <--" : "token of type --> " + expected.name + " <--";
31755
+ var expected2 = _a.expected, actual = _a.actual, previous = _a.previous, ruleName = _a.ruleName;
31756
+ var hasLabel = tokens_public_1.hasTokenLabel(expected2);
31757
+ var expectedMsg = hasLabel ? "--> " + tokens_public_1.tokenLabel(expected2) + " <--" : "token of type --> " + expected2.name + " <--";
31758
31758
  var msg = "Expecting " + expectedMsg + " but found --> '" + actual.image + "' <--";
31759
31759
  return msg;
31760
31760
  },
@@ -41182,13 +41182,13 @@ var require_lodash = __commonJS({
41182
41182
  var startCase = createCompounder(function(result2, word, index) {
41183
41183
  return result2 + (index ? " " : "") + upperFirst(word);
41184
41184
  });
41185
- function startsWith(string, target, position) {
41185
+ function startsWith2(string, target, position) {
41186
41186
  string = toString(string);
41187
41187
  position = position == null ? 0 : baseClamp(toInteger(position), 0, string.length);
41188
41188
  target = baseToString(target);
41189
41189
  return string.slice(position, position + target.length) == target;
41190
41190
  }
41191
- function template(string, options, guard) {
41191
+ function template2(string, options, guard) {
41192
41192
  var settings = lodash.templateSettings;
41193
41193
  if (guard && isIterateeCall(string, options, guard)) {
41194
41194
  options = undefined2;
@@ -41819,11 +41819,11 @@ var require_lodash = __commonJS({
41819
41819
  lodash.sortedLastIndexBy = sortedLastIndexBy;
41820
41820
  lodash.sortedLastIndexOf = sortedLastIndexOf;
41821
41821
  lodash.startCase = startCase;
41822
- lodash.startsWith = startsWith;
41822
+ lodash.startsWith = startsWith2;
41823
41823
  lodash.subtract = subtract;
41824
41824
  lodash.sum = sum;
41825
41825
  lodash.sumBy = sumBy;
41826
- lodash.template = template;
41826
+ lodash.template = template2;
41827
41827
  lodash.times = times;
41828
41828
  lodash.toFinite = toFinite;
41829
41829
  lodash.toInteger = toInteger;
@@ -43567,15 +43567,15 @@ function parse(toml, options = {}) {
43567
43567
  skipVoid(ctx);
43568
43568
  while (ctx.p < toml.length) {
43569
43569
  if (toml.charCodeAt(ctx.p) === 91) {
43570
- let isTableArray = toml.charCodeAt(++ctx.p) === 91;
43571
- tmp = ctx.p += +isTableArray;
43570
+ let isTableArray2 = toml.charCodeAt(++ctx.p) === 91;
43571
+ tmp = ctx.p += +isTableArray2;
43572
43572
  skipping = false;
43573
43573
  let k = parseKey(
43574
43574
  ctx,
43575
43575
  93
43576
43576
  /* ] */
43577
43577
  );
43578
- if (isTableArray) {
43578
+ if (isTableArray2) {
43579
43579
  if (toml.charCodeAt(ctx.p) !== 93) {
43580
43580
  TomlError.x("expected end of table array declaration", ctx);
43581
43581
  }
@@ -43586,7 +43586,7 @@ function parse(toml, options = {}) {
43586
43586
  k,
43587
43587
  res,
43588
43588
  meta,
43589
- isTableArray ? 2 : 1
43589
+ isTableArray2 ? 2 : 1
43590
43590
  /* Type.EXPLICIT */
43591
43591
  );
43592
43592
  if (!p) {
@@ -44222,12 +44222,903 @@ function elementOutline(text, max = 2e3) {
44222
44222
  return root ? [walk(root)] : [];
44223
44223
  }
44224
44224
 
44225
+ // schema/opm/opm.schema.json
44226
+ var opm_schema_default = {
44227
+ $schema: "http://json-schema.org/draft-07/schema#",
44228
+ $id: "https://github.com/eeditiones/open-processing-model/opm.schema.json",
44229
+ $comment: "SPDX-FileCopyrightText: 2026 e-editiones. SPDX-License-Identifier: CC0-1.0",
44230
+ title: "opm.toml",
44231
+ description: "Project configuration for the Open Processing Model. Relative paths resolve against the directory of opm.toml.",
44232
+ type: "object",
44233
+ additionalProperties: false,
44234
+ properties: {
44235
+ project: {
44236
+ description: "Python paths and profiles of the project.",
44237
+ type: "object",
44238
+ additionalProperties: false,
44239
+ properties: {
44240
+ pythonpath: {
44241
+ description: "Extra Python paths, relative to opm.toml, so the project's extension modules can be imported.",
44242
+ $ref: "#/definitions/stringOrList",
44243
+ default: ["."]
44244
+ },
44245
+ profiles: {
44246
+ description: "Profiles to switch on: ready-made features such as registers, search or a facsimile viewer. `opm profile list` shows them.",
44247
+ $ref: "#/definitions/profileList"
44248
+ }
44249
+ }
44250
+ },
44251
+ transform: { $ref: "#/definitions/transform" },
44252
+ context: {
44253
+ description: "Free-form values handed to every template as `context`. TOML types are kept. A [transform.<type>.context] table overlays this per output type.",
44254
+ type: "object",
44255
+ properties: {
44256
+ site_name: { description: "Title of the site, shown in the menu bar of opm's page layout.", type: "string" },
44257
+ logo: { description: "Logo shown in the menu bar, as a URL relative to the page.", type: "string" },
44258
+ webcomponents_url: { description: "URL of the TEI Publisher web components bundle, to serve it yourself or pin another version.", type: "string" },
44259
+ menu: {
44260
+ description: "The menu bar of opm's page layout.",
44261
+ type: "object",
44262
+ properties: {
44263
+ items: {
44264
+ description: "Links in the menu bar, after the logo.",
44265
+ type: "array",
44266
+ items: {
44267
+ type: "object",
44268
+ properties: {
44269
+ label: { description: "Text of the link.", type: "string" },
44270
+ url: { description: "Target of the link.", type: "string" }
44271
+ }
44272
+ }
44273
+ }
44274
+ }
44275
+ },
44276
+ features: {
44277
+ description: "Settings of profiles, one table per profile: [context.features.<name>]. They override the defaults in the profile's opm-profile.toml.",
44278
+ type: "object",
44279
+ additionalProperties: { type: "object" }
44280
+ }
44281
+ }
44282
+ },
44283
+ chunking: {
44284
+ description: "How `opm chunk` splits documents into pages. A [chunking] table is one run; a [[chunking]] array declares several, run in order into one output directory.",
44285
+ anyOf: [
44286
+ { $ref: "#/definitions/chunkingRun" },
44287
+ { type: "array", items: { $ref: "#/definitions/chunkingRun" } }
44288
+ ]
44289
+ },
44290
+ pages: {
44291
+ description: "Auxiliary pages of the chunked site, written by `opm chunk` after the chunking runs: an about page, register overviews, one page per register entry.",
44292
+ type: "array",
44293
+ items: { $ref: "#/definitions/page" }
44294
+ },
44295
+ index: { $ref: "#/definitions/index" },
44296
+ document: {
44297
+ description: "Makes this project an `opm odd document` site.",
44298
+ type: "object",
44299
+ additionalProperties: false,
44300
+ properties: {
44301
+ source: { description: "The ODD, compiled spec document or Specs directory to document.", type: "string" },
44302
+ lang: { description: "xml:lang to prefer for gloss, desc and remarks.", type: "string" }
44303
+ }
44304
+ },
44305
+ editor: {
44306
+ description: "Settings for editors (opm studio, ODDity). opm itself ignores them.",
44307
+ type: "object",
44308
+ additionalProperties: false,
44309
+ properties: {
44310
+ schema: { description: "RELAX NG schema to check documents against when they have no <?xml-model?> of their own.", type: "string" }
44311
+ }
44312
+ },
44313
+ web: { $ref: "#/definitions/webSection", deprecated: true, description: "Deprecated: use [transform.web]." },
44314
+ print: { $ref: "#/definitions/printSection", deprecated: true, description: "Deprecated: use [transform.print]." },
44315
+ epub: { $ref: "#/definitions/epubSection", deprecated: true, description: "Deprecated: use [transform.epub]." },
44316
+ markdown: { $ref: "#/definitions/typeSection", deprecated: true, description: "Deprecated: use [transform.markdown]." },
44317
+ docx: { $ref: "#/definitions/docxSection", deprecated: true, description: "Deprecated: use [transform.docx]." },
44318
+ typst: { $ref: "#/definitions/typstSection", deprecated: true, description: "Deprecated: use [transform.typst]." },
44319
+ json: { $ref: "#/definitions/typeSection", deprecated: true, description: "Deprecated: use [transform.json]." }
44320
+ },
44321
+ definitions: {
44322
+ stringOrList: {
44323
+ anyOf: [
44324
+ { type: "string" },
44325
+ { type: "array", items: { type: "string" } }
44326
+ ]
44327
+ },
44328
+ profileList: {
44329
+ anyOf: [
44330
+ { $ref: "#/definitions/profileName" },
44331
+ { type: "array", items: { $ref: "#/definitions/profileName" } }
44332
+ ]
44333
+ },
44334
+ profileName: {
44335
+ type: "string",
44336
+ examples: ["edition-navigation", "iiif", "pagefind", "registers"]
44337
+ },
44338
+ outputType: {
44339
+ type: "string",
44340
+ enum: ["web", "print", "epub", "markdown", "docx", "typst", "json", "json-web", "json-print", "json-epub", "json-markdown", "json-docx", "json-typst"]
44341
+ },
44342
+ scalar: { type: ["string", "number", "boolean"] },
44343
+ odd: { description: "ODD for this output type, overriding [transform] odd.", type: "string" },
44344
+ typeContext: {
44345
+ description: "Template context for this output type only, over [context].",
44346
+ type: "object"
44347
+ },
44348
+ transform: {
44349
+ description: "Settings shared by every output type, and one table per type.",
44350
+ type: "object",
44351
+ additionalProperties: false,
44352
+ properties: {
44353
+ odd: { description: "Default ODD for every output type, compiled on demand. Without one, the packaged teipublisher.odd is used.", type: "string" },
44354
+ css: { description: "Base rules compiled into the ODD stylesheet for every output type, replacing the packaged defaults. Design CSS belongs in [transform.web] assets.", type: "string" },
44355
+ documents: {
44356
+ description: "XML documents loaded up front for XPath doc(), such as registers that most pages look things up in.",
44357
+ $ref: "#/definitions/stringOrList"
44358
+ },
44359
+ document_roots: {
44360
+ description: "Further folders doc() may open any XML file in, read the first time an expression asks for it. The project folder is always allowed.",
44361
+ $ref: "#/definitions/stringOrList"
44362
+ },
44363
+ footnote_order: {
44364
+ description: "Dotted path of a callable that orders each run's footnotes before they are placed (web, markdown).",
44365
+ type: "string",
44366
+ examples: ["opm.runtime.footnote_order.labelled_first"]
44367
+ },
44368
+ xpath_extensions: {
44369
+ description: "Python modules whose functions the ODD calls as tp:\u2026(). [[transform.extensions]] does the same and more.",
44370
+ $ref: "#/definitions/stringOrList"
44371
+ },
44372
+ extensions: {
44373
+ description: "Python modules whose functions the ODD calls, one table each. A module may use its own prefix and define behaviours.",
44374
+ type: "array",
44375
+ items: { $ref: "#/definitions/extension" }
44376
+ },
44377
+ collections: {
44378
+ description: "Documents returned by XPath collection() for a URI.",
44379
+ type: "array",
44380
+ items: {
44381
+ type: "object",
44382
+ additionalProperties: false,
44383
+ required: ["uri"],
44384
+ properties: {
44385
+ uri: { description: "Absolute URI matched against the argument of collection(), e.g. urn:registers.", type: "string" },
44386
+ documents: { description: "Files of the collection; an entry may be a glob such as data/*.xml.", $ref: "#/definitions/stringOrList" }
44387
+ }
44388
+ }
44389
+ },
44390
+ namespaces: {
44391
+ description: "Namespace prefixes for XPath written in the ODD, as prefix = URI.",
44392
+ type: "object",
44393
+ additionalProperties: { type: "string" }
44394
+ },
44395
+ variables: {
44396
+ description: "Values of XPath variables. A key straight under this table is $name; a sub-table named after a prefix from [transform.namespaces] holds that namespace's variables.",
44397
+ type: "object",
44398
+ additionalProperties: {
44399
+ anyOf: [
44400
+ { $ref: "#/definitions/scalar" },
44401
+ { type: "object", additionalProperties: { $ref: "#/definitions/scalar" } }
44402
+ ]
44403
+ }
44404
+ },
44405
+ parameters: {
44406
+ description: "Values of the ODD's $parameters, for every output type.",
44407
+ type: "object",
44408
+ additionalProperties: { $ref: "#/definitions/scalar" }
44409
+ },
44410
+ web: { $ref: "#/definitions/webSection" },
44411
+ print: { $ref: "#/definitions/printSection" },
44412
+ epub: { $ref: "#/definitions/epubSection" },
44413
+ markdown: { $ref: "#/definitions/typeSection", description: "Markdown output." },
44414
+ docx: { $ref: "#/definitions/docxSection" },
44415
+ typst: { $ref: "#/definitions/typstSection" },
44416
+ json: { $ref: "#/definitions/typeSection", description: "JSON data output, for every json-<type> channel." }
44417
+ }
44418
+ },
44419
+ typeSection: {
44420
+ type: "object",
44421
+ additionalProperties: false,
44422
+ properties: {
44423
+ odd: { $ref: "#/definitions/odd" },
44424
+ context: { $ref: "#/definitions/typeContext" }
44425
+ }
44426
+ },
44427
+ webSection: {
44428
+ description: "HTML output of a whole document, and the defaults for chunk pages.",
44429
+ type: "object",
44430
+ additionalProperties: false,
44431
+ properties: {
44432
+ odd: { $ref: "#/definitions/odd" },
44433
+ context: { $ref: "#/definitions/typeContext" },
44434
+ template: { description: "Jinks page template for HTML output (.html.tpl).", type: "string" },
44435
+ webcomponents: { description: "Emit TEI Publisher web components and let the template load their bundle.", type: "boolean", default: false },
44436
+ assets: {
44437
+ description: "Stylesheets, images and fonts the template uses, copied into an assets/ folder beside the output. An entry may be a glob.",
44438
+ type: "array",
44439
+ items: { type: "string" }
44440
+ },
44441
+ pages: {
44442
+ description: 'Show the document page by page: dotted path of a chunk selector, one <section class="opm-page"> per page.',
44443
+ type: "string",
44444
+ examples: ["opm.navigation.tei_pb_chunks"]
44445
+ }
44446
+ }
44447
+ },
44448
+ printSection: {
44449
+ description: "Paged HTML for print.",
44450
+ type: "object",
44451
+ additionalProperties: false,
44452
+ properties: {
44453
+ odd: { $ref: "#/definitions/odd" },
44454
+ context: { $ref: "#/definitions/typeContext" },
44455
+ template: { description: "Jinks page template for print output (.html.tpl).", type: "string" }
44456
+ }
44457
+ },
44458
+ epubSection: {
44459
+ description: "EPUB output.",
44460
+ type: "object",
44461
+ additionalProperties: false,
44462
+ properties: {
44463
+ odd: { $ref: "#/definitions/odd" },
44464
+ context: { $ref: "#/definitions/typeContext" },
44465
+ css: { description: "Stylesheet for the EPUB, replacing the packaged one.", type: "string" },
44466
+ skip_title: { description: "Leave out the generated title page.", type: "boolean", default: false },
44467
+ xpath: { description: "XPath selecting the elements that become the EPUB's chapters, instead of [chunking] xpath.", type: "string" },
44468
+ selector: { description: "Dotted path of a chunk selector for the chapters, instead of [chunking] selector.", type: "string" },
44469
+ depth: { description: "Heading depth for chapters, instead of [chunking] depth.", type: "integer", minimum: 1 }
44470
+ }
44471
+ },
44472
+ docxSection: {
44473
+ description: "Word output.",
44474
+ type: "object",
44475
+ additionalProperties: false,
44476
+ properties: {
44477
+ odd: { $ref: "#/definitions/odd" },
44478
+ context: { $ref: "#/definitions/typeContext" },
44479
+ template: { description: "Word document whose styles the output uses (.docx).", type: "string" }
44480
+ }
44481
+ },
44482
+ typstSection: {
44483
+ description: "Typst output.",
44484
+ type: "object",
44485
+ additionalProperties: false,
44486
+ properties: {
44487
+ odd: { $ref: "#/definitions/odd" },
44488
+ context: { $ref: "#/definitions/typeContext" },
44489
+ template: { description: "Typst template (.typ.tpl).", type: "string" }
44490
+ }
44491
+ },
44492
+ extension: {
44493
+ type: "object",
44494
+ additionalProperties: false,
44495
+ required: ["module"],
44496
+ properties: {
44497
+ module: { description: "Dotted path of the Python module.", type: "string", examples: ["opm.runtime.common_xpath_functions"] },
44498
+ prefix: { description: "Prefix the ODD calls the module's functions with.", type: "string", default: "tp" },
44499
+ namespace: { description: "Namespace URI of the prefix. Not allowed for tp, whose namespace is fixed.", type: "string" },
44500
+ output: {
44501
+ description: "Output types the module is used for; all when empty.",
44502
+ anyOf: [
44503
+ { $ref: "#/definitions/outputType" },
44504
+ { type: "array", items: { $ref: "#/definitions/outputType" } }
44505
+ ]
44506
+ }
44507
+ }
44508
+ },
44509
+ fragment: {
44510
+ description: "A piece of HTML rendered beside each chunk or once for the document, e.g. a table of contents or a register, available to templates by name.",
44511
+ type: "object",
44512
+ additionalProperties: false,
44513
+ required: ["name"],
44514
+ properties: {
44515
+ name: { description: "Name templates use to place the fragment.", type: "string" },
44516
+ scope: { description: "per-chunk: rendered for each chunk; global: once for the document.", type: "string", enum: ["per-chunk", "global"], default: "per-chunk" },
44517
+ xpath: { description: "XPath selecting what the fragment renders, relative to the chunk root.", type: "string", default: "." },
44518
+ xpath_dynamic: { description: "The xpath the consuming pb-view sends, when it differs from xpath (pb-view index keys only).", type: "string" },
44519
+ parameters: { description: `Values of the ODD's $parameters for this fragment, e.g. { mode = "register" }.`, type: "object" },
44520
+ odd: { description: "ODD to render the fragment with.", type: "string" },
44521
+ mode: { description: "Output type the ODD is compiled for.", $ref: "#/definitions/outputType", default: "web" }
44522
+ }
44523
+ },
44524
+ chunkingRun: {
44525
+ type: "object",
44526
+ additionalProperties: false,
44527
+ properties: {
44528
+ name: { description: "Label of the run, for [[chunking]] arrays: names it in manifest.json, progress and errors, and for `opm chunk --run`.", type: "string" },
44529
+ input: { description: "What the run reads: an XML file, a directory or a glob pattern (** matches any number of subdirectories).", type: "string", examples: ["data/**/*.xml"] },
44530
+ odd: { description: "ODD used for chunking; falls back to [transform] odd.", type: "string" },
44531
+ xpath: { description: "XPath selecting the chunk root elements.", type: "string", examples: ["//text/body/div"] },
44532
+ xpath_dynamic: { description: "The xpath the consuming pb-view sends, when it differs from xpath (pb-view index keys only).", type: "string" },
44533
+ selector: { description: "Dotted path of a Python callable that selects the chunks, instead of xpath.", type: "string", examples: ["opm.navigation.tei_pb_chunks"] },
44534
+ depth: { description: "Maximum heading depth for splitting.", type: "integer", minimum: 1, default: 1 },
44535
+ output_dir: { description: "Output directory, relative to the project root. Only the first run may set it.", type: "string", default: "chunks" },
44536
+ template: { description: "Page template for chunk pages; defaults to the [transform.web] template.", type: "string" },
44537
+ index_template: { description: "Page template for the collection index written when chunking several documents.", type: "string" },
44538
+ index_title: { description: "Heading of the collection index; defaults to the input directory name.", type: "string" },
44539
+ assets: {
44540
+ description: "Files copied into <output>/assets/ instead of the [transform.web] assets; [] for none. An entry may be a glob.",
44541
+ type: "array",
44542
+ items: { type: "string" }
44543
+ },
44544
+ file_pattern: { description: "File name of chunk pages, with {xml_id}, {ident}, {index} or {stem}. Default: 001.html, 002.html, \u2026", type: "string", examples: ["{xml_id}.html", "{index:03d}.html"] },
44545
+ document_name: { description: "XPath naming each document's output directory (default: its file name); a / in the name nests it.", type: "string", examples: ["/TEI/@xml:id"] },
44546
+ link_pattern: { description: "URL of cross-chunk links, with {file}, {stem}, {anchor}, {doc} or {doc_stem}. Default: {file}#{anchor}.", type: "string", examples: ["/{doc}/{file}"] },
44547
+ webcomponents: { description: "Web components for this run's pages only; defaults to [transform.web] webcomponents.", type: "boolean" },
44548
+ fragments: {
44549
+ description: "Fragments rendered beside the chunks, such as a table of contents or a register.",
44550
+ type: "array",
44551
+ items: { $ref: "#/definitions/fragment" }
44552
+ },
44553
+ view: { description: "pb-view view mode in index keys (--format pb-view).", type: "string", enum: ["div", "page", "single"], default: "div" },
44554
+ map: { description: "pb-view map parameter in index keys (--format pb-view).", type: "string" },
44555
+ parameters: { description: "pb-view user parameters in index keys (--format pb-view), emitted as user.<key>=<value>.", type: "object" },
44556
+ doc_path: { description: "Subdirectory for --format pb-view data; must match the path of the consuming pb-document.", type: "string" }
44557
+ }
44558
+ },
44559
+ page: {
44560
+ type: "object",
44561
+ additionalProperties: false,
44562
+ required: ["path"],
44563
+ properties: {
44564
+ path: { description: "Output path below the chunk output root. With {xml_id}, {ident}, {stem} or {index}, one page per node xpath selects.", type: "string", examples: ["about.html", "places/{xml_id}.html"] },
44565
+ template: { description: "Page template; defaults to the first chunking run's.", type: "string" },
44566
+ context: { description: "Template context for this page only, over [context].", type: "object" },
44567
+ source: { description: "XML file or directory the page is generated from. Without one the page is static: only the template is rendered.", type: "string" },
44568
+ xpath: { description: "XPath selecting the nodes rendered into the page, from source.", type: "string" },
44569
+ selector: { description: "Dotted path of a chunk selector, instead of xpath.", type: "string" },
44570
+ odd: { description: "ODD for this page; defaults to the first chunking run's.", type: "string" },
44571
+ parameters: { description: "Values of the ODD's $parameters for this page, over [transform.parameters].", type: "object" },
44572
+ fragments: {
44573
+ description: "Fragments rendered into the page, as for chunks.",
44574
+ type: "array",
44575
+ items: { $ref: "#/definitions/fragment" }
44576
+ },
44577
+ enabled: { description: "false switches the page off, e.g. one a profile contributes with the same path.", type: "boolean", default: true }
44578
+ }
44579
+ },
44580
+ index: {
44581
+ description: "Search index written by `opm index`.",
44582
+ type: "object",
44583
+ additionalProperties: false,
44584
+ properties: {
44585
+ granularity: { description: "split: one record per unit, cut to max_chars, for vector search; page: one record per published page, for site search.", type: "string", enum: ["split", "page"], default: "split" },
44586
+ max_chars: { description: "Maximum length of a passage.", type: "integer", minimum: 1, default: 1500 },
44587
+ min_chars: { description: "Records shorter than this are not indexed on their own.", type: "integer", minimum: 0, default: 40 },
44588
+ overlap: { description: "Records carried over from the end of one part into the next, for context (split only).", type: "integer", minimum: 0, default: 1 },
44589
+ units: {
44590
+ description: "JSON records that open a passage; declaring any replaces the default walk over titled divisions.",
44591
+ type: "array",
44592
+ items: {
44593
+ type: "object",
44594
+ additionalProperties: false,
44595
+ required: ["name"],
44596
+ properties: {
44597
+ name: { type: "string" },
44598
+ behaviours: { description: "ODD behaviours whose records open a unit.", $ref: "#/definitions/stringOrList" },
44599
+ elements: { description: "Elements whose records open a unit.", $ref: "#/definitions/stringOrList" },
44600
+ models: { description: "ODD models whose records open a unit.", $ref: "#/definitions/stringOrList" },
44601
+ emit: { description: "false: use the match only as context, e.g. a heading for the following paragraph, and write no record of its own.", type: "boolean", default: true },
44602
+ min_chars: { description: "Overrides [index] min_chars for this unit.", type: "integer", minimum: 0 }
44603
+ }
44604
+ }
44605
+ },
44606
+ fields: {
44607
+ description: "Material pulled out of passages: a facet for filtering, a record of its own, or a chunking fragment copied onto every record of a page.",
44608
+ type: "array",
44609
+ items: {
44610
+ type: "object",
44611
+ additionalProperties: false,
44612
+ required: ["name"],
44613
+ properties: {
44614
+ name: { type: "string" },
44615
+ fragment: { description: "Name of a [[chunking.fragments]] entry, copied onto every record of its page. Cannot be mixed with behaviours, elements or models.", type: "string" },
44616
+ behaviours: { description: "ODD behaviours whose records the field takes its text from.", $ref: "#/definitions/stringOrList" },
44617
+ elements: { description: "Elements whose records the field takes its text from.", $ref: "#/definitions/stringOrList" },
44618
+ models: { description: "ODD models whose records the field takes its text from.", $ref: "#/definitions/stringOrList" },
44619
+ metadata: { description: "true: copy the text onto the passage, for filtering; false: write it as a record of its own.", type: "boolean", default: true },
44620
+ inline: { description: "Whether the text stays in the passage's own text; defaults to metadata.", type: "boolean" }
44621
+ }
44622
+ }
44623
+ }
44624
+ }
44625
+ }
44626
+ }
44627
+ };
44628
+
44629
+ // src/core/tomlScan.ts
44630
+ var isBare = (c) => /[A-Za-z0-9_-]/.test(c);
44631
+ var isSpace = (c) => c === " " || c === " ";
44632
+ function readKey(text, i, stop) {
44633
+ const parts = [];
44634
+ for (; ; ) {
44635
+ while (isSpace(text[i])) i++;
44636
+ const c = text[i];
44637
+ if (c === '"' || c === "'") {
44638
+ let j = i + 1, part = "";
44639
+ while (j < text.length && text[j] !== c && text[j] !== "\n") {
44640
+ if (c === '"' && text[j] === "\\" && j + 1 < text.length) {
44641
+ part += text[j + 1];
44642
+ j += 2;
44643
+ continue;
44644
+ }
44645
+ part += text[j++];
44646
+ }
44647
+ if (text[j] !== c) return null;
44648
+ parts.push(part);
44649
+ i = j + 1;
44650
+ } else if (c !== void 0 && isBare(c)) {
44651
+ const start = i;
44652
+ while (i < text.length && isBare(text[i])) i++;
44653
+ parts.push(text.slice(start, i));
44654
+ } else {
44655
+ return null;
44656
+ }
44657
+ while (isSpace(text[i])) i++;
44658
+ if (text[i] === ".") {
44659
+ i++;
44660
+ continue;
44661
+ }
44662
+ return i < text.length && stop(text[i]) ? { parts, end: i } : null;
44663
+ }
44664
+ }
44665
+ function skipValue(text, i) {
44666
+ let depth = 0, contentEnd = -1;
44667
+ while (i < text.length) {
44668
+ const c = text[i];
44669
+ if (c === '"' || c === "'") {
44670
+ if (text.startsWith(c.repeat(3), i)) {
44671
+ const end = text.indexOf(c.repeat(3), i + 3);
44672
+ i = end < 0 ? text.length : end + 3;
44673
+ while (text[i] === c) i++;
44674
+ } else {
44675
+ i++;
44676
+ while (i < text.length && text[i] !== c && text[i] !== "\n") i += c === '"' && text[i] === "\\" ? 2 : 1;
44677
+ if (text[i] === c) i++;
44678
+ }
44679
+ continue;
44680
+ }
44681
+ if (c === "#") {
44682
+ if (depth === 0 && contentEnd < 0) contentEnd = i;
44683
+ while (i < text.length && text[i] !== "\n") i++;
44684
+ continue;
44685
+ }
44686
+ if (c === "\n" && depth === 0) break;
44687
+ if (c === "[" || c === "{") depth++;
44688
+ else if ((c === "]" || c === "}") && depth) depth--;
44689
+ i++;
44690
+ }
44691
+ let valueTo = contentEnd < 0 ? i : contentEnd;
44692
+ while (valueTo > 0 && /\s/.test(text[valueTo - 1])) valueTo--;
44693
+ return { valueTo, next: i };
44694
+ }
44695
+ function scanToml(text) {
44696
+ const tables = [], keys2 = [];
44697
+ const counts = /* @__PURE__ */ new Map();
44698
+ const id = (p) => JSON.stringify(p);
44699
+ const resolve = (parts, array) => {
44700
+ const path = [];
44701
+ parts.forEach((part, n) => {
44702
+ path.push(part);
44703
+ const last2 = n === parts.length - 1;
44704
+ if (last2 && array) {
44705
+ const count = counts.get(id(path)) ?? 0;
44706
+ counts.set(id(path), count + 1);
44707
+ path.push(count);
44708
+ } else if (!last2 && counts.has(id(path))) {
44709
+ path.push(counts.get(id(path)) - 1);
44710
+ }
44711
+ });
44712
+ return path;
44713
+ };
44714
+ let table = [];
44715
+ let i = 0;
44716
+ while (i < text.length) {
44717
+ const c = text[i];
44718
+ if (c === "\n" || isSpace(c) || c === "\r") {
44719
+ i++;
44720
+ continue;
44721
+ }
44722
+ const eol = () => {
44723
+ const n = text.indexOf("\n", i);
44724
+ return n < 0 ? text.length : n;
44725
+ };
44726
+ if (c === "#") {
44727
+ i = eol();
44728
+ continue;
44729
+ }
44730
+ if (c === "[") {
44731
+ const array = text[i + 1] === "[";
44732
+ const key2 = readKey(text, i + (array ? 2 : 1), (ch) => ch === "]");
44733
+ if (key2 && (!array || text[key2.end + 1] === "]")) {
44734
+ const end = key2.end + (array ? 2 : 1);
44735
+ table = resolve(key2.parts, array);
44736
+ tables.push({ path: table, from: i, to: end, array });
44737
+ }
44738
+ i = eol();
44739
+ continue;
44740
+ }
44741
+ const key = readKey(text, i, (ch) => ch === "=");
44742
+ if (!key) {
44743
+ i = eol();
44744
+ continue;
44745
+ }
44746
+ let keyTo = key.end;
44747
+ while (keyTo > i && isSpace(text[keyTo - 1])) keyTo--;
44748
+ let v = key.end + 1;
44749
+ while (isSpace(text[v])) v++;
44750
+ const { valueTo, next } = skipValue(text, v);
44751
+ keys2.push({ path: [...table, ...key.parts], from: i, to: keyTo, valueFrom: v, valueTo: Math.max(v, valueTo) });
44752
+ i = Math.max(next, i + 1);
44753
+ }
44754
+ return { tables, keys: keys2 };
44755
+ }
44756
+ function tableAt(scan, offset) {
44757
+ let found;
44758
+ for (const t of scan.tables) if (t.from <= offset) found = t;
44759
+ else break;
44760
+ return found;
44761
+ }
44762
+
44763
+ // src/core/opmToml.ts
44764
+ var OPM_SCHEMA = opm_schema_default;
44765
+ var isOpmToml = (uri) => /(^|[/\\])opm\.toml$/.test(uri);
44766
+ function deref(s, root) {
44767
+ let seen = 0;
44768
+ while (s.$ref && seen++ < 20) {
44769
+ const target = s.$ref.replace(/^#\/definitions\//, "");
44770
+ const { $ref: _, ...rest } = s;
44771
+ s = { ...root.definitions?.[target], ...rest };
44772
+ }
44773
+ return s;
44774
+ }
44775
+ var typesOf = (s) => s.type === void 0 ? [] : Array.isArray(s.type) ? s.type : [s.type];
44776
+ var branches = (s, root) => {
44777
+ s = deref(s, root);
44778
+ if (!s.anyOf) return [s];
44779
+ const { anyOf, ...own } = s;
44780
+ return anyOf.flatMap((b) => branches(b, root)).map((b) => ({ ...b, description: own.description ?? b.description, deprecated: own.deprecated ?? b.deprecated }));
44781
+ };
44782
+ function schemaAt(path, root = OPM_SCHEMA) {
44783
+ let s = deref(root, root);
44784
+ for (const seg of path) {
44785
+ if (!s) return void 0;
44786
+ const options = branches(s, root);
44787
+ if (typeof seg === "number") {
44788
+ const arr = options.find((b) => typesOf(b).includes("array"));
44789
+ s = arr?.items && deref(arr.items, root);
44790
+ } else {
44791
+ const obj = options.find((b) => typesOf(b).includes("object") || b.properties);
44792
+ const next = obj?.properties?.[seg] ?? obj?.additionalProperties;
44793
+ s = next && typeof next === "object" ? { ...deref(next, root), ...obj?.properties?.[seg]?.description ? { description: obj.properties[seg].description } : {} } : void 0;
44794
+ }
44795
+ }
44796
+ return s;
44797
+ }
44798
+ var kindOf = (v) => typeof v === "string" ? "string" : typeof v === "boolean" ? "boolean" : typeof v === "number" || typeof v === "bigint" ? Number.isInteger(Number(v)) ? "integer" : "number" : Array.isArray(v) ? "array" : v && typeof v === "object" && !(v instanceof Date) && !("toISOString" in v) ? "object" : "datetime";
44799
+ var accepts = (type, kind) => type === kind || type === "number" && kind === "integer";
44800
+ var NOUN = {
44801
+ string: "a string",
44802
+ integer: "a whole number",
44803
+ number: "a number",
44804
+ boolean: "true or false",
44805
+ array: "a list",
44806
+ object: "a table",
44807
+ datetime: "a date"
44808
+ };
44809
+ function expected(options, root) {
44810
+ const words = options.flatMap((b) => typesOf(b).map((t) => {
44811
+ if (t === "array" && b.items) {
44812
+ const item = typesOf(deref(b.items, root))[0];
44813
+ return item ? `a list of ${NOUN[item].replace(/^an? /, "")}s` : NOUN.array;
44814
+ }
44815
+ return NOUN[t] ?? t;
44816
+ }));
44817
+ return [...new Set(words)].join(" or ");
44818
+ }
44819
+ function tableName(path) {
44820
+ const names2 = path.filter((s) => typeof s === "string");
44821
+ const array = typeof path[path.length - 1] === "number";
44822
+ return names2.length ? array ? `[[${names2.join(".")}]]` : `[${names2.join(".")}]` : "the top level";
44823
+ }
44824
+ var keyName = (path) => String(path.filter((s) => typeof s === "string").pop() ?? "");
44825
+ function distance(a, b) {
44826
+ const d = Array.from({ length: b.length + 1 }, (_, j) => j);
44827
+ for (let i = 1; i <= a.length; i++) {
44828
+ let prev = d[0];
44829
+ d[0] = i;
44830
+ for (let j = 1; j <= b.length; j++) {
44831
+ const tmp = d[j];
44832
+ d[j] = Math.min(d[j] + 1, d[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
44833
+ prev = tmp;
44834
+ }
44835
+ }
44836
+ return d[b.length];
44837
+ }
44838
+ function check(value, s, path, root, errors) {
44839
+ const options = branches(s, root);
44840
+ const kind = kindOf(value);
44841
+ const fits = options.filter((b) => !typesOf(b).length || typesOf(b).some((t) => accepts(t, kind)));
44842
+ if (!fits.length) {
44843
+ const name2 = path.length ? `"${keyName(path)}"` : "opm.toml";
44844
+ errors.push({ path, code: "type", severity: "error", message: `${name2} should be ${expected(options, root)}, not ${NOUN[kind] ?? kind}.` });
44845
+ return;
44846
+ }
44847
+ let chosen = fits[0];
44848
+ if (fits.length > 1) {
44849
+ for (const b of fits) {
44850
+ const trial = [];
44851
+ checkOne(value, b, path, root, trial);
44852
+ if (!trial.some((e) => e.severity === "error")) {
44853
+ chosen = b;
44854
+ break;
44855
+ }
44856
+ }
44857
+ }
44858
+ checkOne(value, chosen, path, root, errors);
44859
+ }
44860
+ function checkOne(value, s, path, root, errors) {
44861
+ if (s.deprecated && path.length) {
44862
+ errors.push({ path, code: "deprecated", severity: "warning", message: s.description ?? `"${keyName(path)}" is deprecated.` });
44863
+ }
44864
+ if (s.enum && !s.enum.includes(value)) {
44865
+ errors.push({ path, code: "enum", severity: "error", message: `"${keyName(path)}" should be one of ${s.enum.map((v) => JSON.stringify(v)).join(", ")}.` });
44866
+ }
44867
+ if (s.minimum !== void 0 && (typeof value === "number" || typeof value === "bigint") && Number(value) < s.minimum) {
44868
+ errors.push({ path, code: "range", severity: "error", message: `"${keyName(path)}" should be at least ${s.minimum}.` });
44869
+ }
44870
+ if (Array.isArray(value) && s.items) {
44871
+ value.forEach((item, n) => check(item, s.items, [...path, n], root, errors));
44872
+ } else if (kindOf(value) === "object") {
44873
+ const obj = value;
44874
+ for (const req of s.required ?? []) {
44875
+ if (!(req in obj)) errors.push({ path, code: "required", severity: "error", message: `${tableName(path)} needs "${req}".` });
44876
+ }
44877
+ for (const [k, v] of Object.entries(obj)) {
44878
+ const prop = s.properties?.[k];
44879
+ if (prop) {
44880
+ check(v, prop, [...path, k], root, errors);
44881
+ continue;
44882
+ }
44883
+ if (s.additionalProperties === false) {
44884
+ const known = Object.keys(s.properties ?? {});
44885
+ const close = known.map((n) => [n, distance(k, n)]).filter(([, d]) => d <= 2).sort((a, b) => a[1] - b[1])[0];
44886
+ errors.push({
44887
+ path: [...path, k],
44888
+ code: "unknown",
44889
+ severity: "warning",
44890
+ message: `opm does not know "${k}" in ${tableName(path)}.${close ? ` Did you mean "${close[0]}"?` : ""}`
44891
+ });
44892
+ } else if (s.additionalProperties && typeof s.additionalProperties === "object") {
44893
+ check(v, s.additionalProperties, [...path, k], root, errors);
44894
+ }
44895
+ }
44896
+ }
44897
+ }
44898
+ var startsWith = (path, prefix) => prefix.length <= path.length && prefix.every((s, i) => path[i] === s);
44899
+ var same = (a, b) => a.length === b.length && startsWith(a, b);
44900
+ function rangeOf(scan, e) {
44901
+ const key = scan.keys.find((k) => same(k.path, e.path));
44902
+ if (key) return e.code === "unknown" || e.code === "deprecated" ? { from: key.from, to: key.to } : { from: key.valueFrom, to: key.valueTo };
44903
+ const table = scan.tables.find((t) => same(t.path, e.path)) ?? scan.tables.find((t) => startsWith(t.path, e.path));
44904
+ if (table) return { from: table.from, to: table.to };
44905
+ const below = scan.keys.find((k) => startsWith(k.path, e.path));
44906
+ if (below) return { from: below.from, to: below.to };
44907
+ let holder;
44908
+ for (const k of scan.keys) if (startsWith(e.path, k.path)) holder = { from: k.valueFrom, to: k.valueTo };
44909
+ return holder ?? { from: 0, to: 0 };
44910
+ }
44911
+ function checkOpmToml(text, schema = OPM_SCHEMA) {
44912
+ let data;
44913
+ try {
44914
+ data = parse(text);
44915
+ } catch (err) {
44916
+ if (!(err instanceof TomlError)) throw err;
44917
+ const lines = text.split("\n");
44918
+ const line = Math.max(0, Math.min(lines.length - 1, err.line - 1));
44919
+ const start = lines.slice(0, line).reduce((n, l) => n + l.length + 1, 0);
44920
+ const from = start + Math.max(0, Math.min(lines[line].length, err.column - 1));
44921
+ const message = err.message.split("\n")[0].replace(/^Invalid TOML document: /, "");
44922
+ return [{ from, to: Math.max(from, start + lines[line].length), message: `Not valid TOML: ${message}.`, severity: "error", code: "syntax" }];
44923
+ }
44924
+ const errors = [];
44925
+ check(data, schema, [], schema, errors);
44926
+ const scan = scanToml(text);
44927
+ return errors.map((e) => ({ ...rangeOf(scan, e), message: e.message, severity: e.severity, code: e.code }));
44928
+ }
44929
+ function summary(s, root) {
44930
+ const options = branches(s, root);
44931
+ if (options.length === 1 && options[0].enum) return options[0].enum.map((v) => JSON.stringify(v)).join(" | ");
44932
+ return expected(options, root).replace(/^an? /, "").replace(/ or an? /g, " or ");
44933
+ }
44934
+ function template(s, root) {
44935
+ const first2 = branches(s, root)[0] ?? {};
44936
+ const t = typesOf(first2)[0];
44937
+ if (first2.enum?.length) return { text: JSON.stringify(first2.enum[0]), cursor: 1 };
44938
+ if (t === "string") return { text: '""', cursor: 1 };
44939
+ if (t === "array") {
44940
+ const item = first2.items && typesOf(deref(first2.items, root))[0];
44941
+ return item === "string" ? { text: '[""]', cursor: 2 } : { text: "[]", cursor: 1 };
44942
+ }
44943
+ if (t === "object") return { text: "{ }", cursor: 2 };
44944
+ if (t === "boolean") return { text: String(first2.default ?? true), cursor: String(first2.default ?? true).length };
44945
+ return { text: "", cursor: 0 };
44946
+ }
44947
+ var isTable = (s, root) => branches(s, root).some((b) => typesOf(b).includes("object") || b.properties);
44948
+ var isTableArray = (s, root) => branches(s, root).some((b) => {
44949
+ if (!typesOf(b).includes("array") || !b.items) return false;
44950
+ return isTable(b.items, root);
44951
+ });
44952
+ var isHeaderOnly = (s, root) => branches(s, root).every((b) => typesOf(b).includes("object") && !!b.properties || typesOf(b).includes("array") && !!b.items && isTable(b.items, root));
44953
+ function headers(root) {
44954
+ const out = [];
44955
+ const walk = (s, names2, depth) => {
44956
+ if (depth > 4) return;
44957
+ for (const b of branches(s, root)) {
44958
+ for (const [k, raw] of Object.entries(b.properties ?? {})) {
44959
+ const p = deref(raw, root);
44960
+ if (p.deprecated || raw.deprecated) continue;
44961
+ const ns = [...names2, k];
44962
+ const desc = { ...p, description: raw.description ?? p.description };
44963
+ if (isTable(p, root)) {
44964
+ out.push({ name: ns.join("."), array: false, schema: desc });
44965
+ walk(p, ns, depth + 1);
44966
+ }
44967
+ if (isTableArray(p, root)) {
44968
+ out.push({ name: ns.join("."), array: true, schema: desc });
44969
+ const items = branches(p, root).find((x) => typesOf(x).includes("array"))?.items;
44970
+ if (items) walk(items, ns, depth + 1);
44971
+ }
44972
+ }
44973
+ }
44974
+ };
44975
+ walk(root, [], 0);
44976
+ return out;
44977
+ }
44978
+ function completeOpmToml(text, offset, schema = OPM_SCHEMA) {
44979
+ const lineStart = text.lastIndexOf("\n", offset - 1) + 1;
44980
+ const before = text.slice(lineStart, offset);
44981
+ if (/^\s*#/.test(before) || /#[^"']*$/.test(before)) return null;
44982
+ const scan = scanToml(text);
44983
+ const header = /^\s*(\[\[?)\s*([A-Za-z0-9_.-]*)$/.exec(before);
44984
+ if (header) {
44985
+ const from2 = offset - header[2].length;
44986
+ const lineEnd = text.indexOf("\n", offset);
44987
+ const rest = text.slice(offset, lineEnd < 0 ? text.length : lineEnd);
44988
+ const closing = /^[A-Za-z0-9_.-]*\]{1,2}/.exec(rest);
44989
+ const to = closing ? offset + closing[0].length : offset;
44990
+ const double = header[1] === "[[";
44991
+ return {
44992
+ from: from2,
44993
+ to,
44994
+ options: headers(schema).filter((h) => h.array === double).map((h) => ({
44995
+ label: h.name,
44996
+ kind: "table",
44997
+ detail: h.array ? "array of tables" : "table",
44998
+ info: h.schema.description,
44999
+ apply: h.name + (double ? "]]" : "]")
45000
+ }))
45001
+ };
45002
+ }
45003
+ const table = tableAt(scan, offset);
45004
+ const tablePath = table?.path ?? [];
45005
+ const eq = before.indexOf("=");
45006
+ if (eq >= 0) {
45007
+ const key = readKey(before, 0, (ch) => ch === "=");
45008
+ if (!key) return null;
45009
+ let s2 = schemaAt([...tablePath, ...key.parts], schema);
45010
+ if (!s2) return null;
45011
+ let after = before.slice(eq + 1);
45012
+ if ((after.match(/\[/g)?.length ?? 0) > (after.match(/\]/g)?.length ?? 0)) {
45013
+ const arr = branches(s2, schema).find((b) => typesOf(b).includes("array"));
45014
+ if (!arr?.items) return null;
45015
+ s2 = deref(arr.items, schema);
45016
+ after = after.slice(after.lastIndexOf(",") >= 0 && after.lastIndexOf(",") > after.lastIndexOf("[") ? after.lastIndexOf(",") + 1 : after.lastIndexOf("[") + 1);
45017
+ }
45018
+ const word = /("?)([^"\s,[\]{}=]*)$/.exec(after);
45019
+ const quoted = word[1] === '"';
45020
+ const from2 = offset - word[2].length - (quoted ? 1 : 0);
45021
+ const values2 = /* @__PURE__ */ new Map();
45022
+ for (const b of branches(s2, schema)) {
45023
+ for (const v of b.enum ?? []) values2.set(JSON.stringify(v), b.description);
45024
+ if (typesOf(b).includes("boolean")) {
45025
+ values2.set("true", void 0);
45026
+ values2.set("false", void 0);
45027
+ }
45028
+ for (const v of b.examples ?? []) values2.set(JSON.stringify(v), "example");
45029
+ if (b.default !== void 0 && typeof b.default !== "object") values2.set(JSON.stringify(b.default), "default");
45030
+ }
45031
+ if (!values2.size) return null;
45032
+ const to = quoted && text[offset] === '"' ? offset + 1 : offset;
45033
+ return {
45034
+ from: from2,
45035
+ to,
45036
+ options: [...values2].map(([v, note]) => ({ label: v, kind: "value", detail: note === "example" || note === "default" ? note : void 0, apply: v }))
45037
+ };
45038
+ }
45039
+ const typed = /^\s*([A-Za-z0-9_.-]*)$/.exec(before);
45040
+ if (!typed) return null;
45041
+ const dots = typed[1].split(".");
45042
+ const partial2 = dots.pop();
45043
+ const parent = [...tablePath, ...dots.filter(Boolean)];
45044
+ const s = schemaAt(parent, schema);
45045
+ const from = offset - partial2.length;
45046
+ if (!table && !dots.filter(Boolean).length) {
45047
+ return {
45048
+ from,
45049
+ to: offset,
45050
+ options: headers(schema).map((h) => ({
45051
+ label: h.array ? `[[${h.name}]]` : `[${h.name}]`,
45052
+ kind: "table",
45053
+ detail: h.array ? "array of tables" : "table",
45054
+ info: h.schema.description,
45055
+ apply: h.array ? `[[${h.name}]]` : `[${h.name}]`
45056
+ }))
45057
+ };
45058
+ }
45059
+ if (!s) return null;
45060
+ const present = new Set(scan.keys.filter((k) => startsWith(k.path, parent) && k.path.length > parent.length).map((k) => k.path[parent.length]));
45061
+ for (const t of scan.tables) if (startsWith(t.path, parent) && t.path.length > parent.length) present.add(t.path[parent.length]);
45062
+ const options = [];
45063
+ for (const b of branches(s, schema)) {
45064
+ for (const [name2, raw] of Object.entries(b.properties ?? {})) {
45065
+ const p = deref(raw, schema);
45066
+ if (present.has(name2) || p.deprecated || raw.deprecated) continue;
45067
+ if (isHeaderOnly(p, schema)) continue;
45068
+ const value = template(p, schema);
45069
+ options.push({
45070
+ label: name2,
45071
+ kind: "key",
45072
+ detail: summary(p, schema),
45073
+ info: raw.description ?? p.description,
45074
+ apply: `${name2} = ${value.text}`,
45075
+ cursor: name2.length + 3 + value.cursor
45076
+ });
45077
+ }
45078
+ }
45079
+ return { from, to: offset, options };
45080
+ }
45081
+ function describeOpmToml(text, offset, schema = OPM_SCHEMA) {
45082
+ const scan = scanToml(text);
45083
+ const table = scan.tables.find((t) => t.from <= offset && offset <= t.to);
45084
+ const key = table ? void 0 : scan.keys.find((k) => k.from <= offset && offset <= k.to);
45085
+ const hit = table ?? key;
45086
+ if (!hit) return null;
45087
+ let path = hit.path;
45088
+ if (key) {
45089
+ const parts = readKey(text, key.from, (ch) => ch === "=")?.parts ?? [];
45090
+ const prefixLen = key.path.length - parts.length;
45091
+ let at = key.from, n = 0;
45092
+ for (; n < parts.length - 1; n++) {
45093
+ at = text.indexOf(parts[n], at) + parts[n].length;
45094
+ if (offset <= at) break;
45095
+ }
45096
+ path = key.path.slice(0, prefixLen + n + 1);
45097
+ } else if (typeof path[path.length - 1] === "number") {
45098
+ path = path.slice(0, -1);
45099
+ }
45100
+ const s = schemaAt(path, schema);
45101
+ if (!s) return null;
45102
+ const extras = [summary(s, schema)];
45103
+ const def = branches(s, schema).find((b) => b.default !== void 0)?.default;
45104
+ if (def !== void 0) extras.push(`default ${JSON.stringify(def)}`);
45105
+ return {
45106
+ from: hit.from,
45107
+ to: hit.to,
45108
+ title: table ? tableName(table.path) : keyName(path),
45109
+ detail: extras.join(", "),
45110
+ info: s.description
45111
+ };
45112
+ }
45113
+
44225
45114
  // src/server/server.ts
44226
45115
  var SOURCE = "oddity-ls";
44227
45116
  var SCHEMA_FOR = "oddity/schemaFor";
44228
45117
  var SCHEMA_CHANGED = "oddity/schemaChanged";
44229
45118
  var ALLOWED_ELEMENTS = "oddity/allowedElements";
44230
45119
  var DELAY = 250;
45120
+ var XML_TRIGGERS = ["<", " ", '"', "'"];
45121
+ var snippetEscape = (s) => s.replace(/[\\$}]/g, (m) => "\\" + m);
44231
45122
  function startServer(connection, host2) {
44232
45123
  const documents = new import_vscode_languageserver.TextDocuments(TextDocument2);
44233
45124
  const grammars = new Grammars(host2.readText);
@@ -44243,7 +45134,8 @@ function startServer(connection, host2) {
44243
45134
  return {
44244
45135
  capabilities: {
44245
45136
  textDocumentSync: import_vscode_languageserver.TextDocumentSyncKind.Incremental,
44246
- completionProvider: { triggerCharacters: ["<", " ", '"', "'"] },
45137
+ completionProvider: { triggerCharacters: [...XML_TRIGGERS, "[", "="] },
45138
+ hoverProvider: true,
44247
45139
  linkedEditingRangeProvider: true,
44248
45140
  documentSymbolProvider: true,
44249
45141
  selectionRangeProvider: true
@@ -44266,10 +45158,25 @@ function startServer(connection, host2) {
44266
45158
  source: SOURCE,
44267
45159
  code
44268
45160
  });
44269
- async function check(uri) {
45161
+ async function check2(uri) {
44270
45162
  const doc = documents.get(uri);
44271
45163
  if (!doc) return;
44272
45164
  const version = doc.version, text = doc.getText();
45165
+ if (isOpmToml(uri)) {
45166
+ const diagnostics2 = checkOpmToml(text).map((p) => ({
45167
+ range: { start: doc.positionAt(p.from), end: doc.positionAt(p.to) },
45168
+ message: p.message,
45169
+ severity: p.severity === "error" ? import_vscode_languageserver.DiagnosticSeverity.Error : import_vscode_languageserver.DiagnosticSeverity.Warning,
45170
+ source: SOURCE,
45171
+ code: "opm-toml-" + p.code,
45172
+ tags: p.code === "deprecated" ? [
45173
+ 2
45174
+ /* Deprecated */
45175
+ ] : void 0
45176
+ }));
45177
+ void connection.sendDiagnostics({ uri, version, diagnostics: diagnostics2 });
45178
+ return;
45179
+ }
44273
45180
  const choice = choiceOf(doc);
44274
45181
  const key = choice ? `${choice.via} ${choice.url}` : "";
44275
45182
  if (announced.get(uri) !== key) {
@@ -44302,7 +45209,7 @@ function startServer(connection, host2) {
44302
45209
  clearTimeout(timers.get(uri));
44303
45210
  timers.set(uri, setTimeout(() => {
44304
45211
  timers.delete(uri);
44305
- check(uri).catch((err) => connection.console.error(`Checking ${uri} failed: ${err instanceof Error ? err.stack : err}`));
45212
+ check2(uri).catch((err) => connection.console.error(`Checking ${uri} failed: ${err instanceof Error ? err.stack : err}`));
44306
45213
  }, delay));
44307
45214
  }
44308
45215
  const recheckAll = () => {
@@ -44323,6 +45230,8 @@ function startServer(connection, host2) {
44323
45230
  connection.onCompletion(async ({ textDocument, position, context: context2 }) => {
44324
45231
  const doc = documents.get(textDocument.uri);
44325
45232
  if (!doc) return [];
45233
+ if (isOpmToml(doc.uri)) return tomlCompletion(doc, position);
45234
+ if (context2?.triggerCharacter && !XML_TRIGGERS.includes(context2.triggerCharacter)) return [];
44326
45235
  const { grammar } = await grammarOf(choiceOf(doc));
44327
45236
  if (!grammar) return [];
44328
45237
  const at = doc.offsetAt(position);
@@ -44359,9 +45268,39 @@ function startServer(connection, host2) {
44359
45268
  return item;
44360
45269
  });
44361
45270
  });
45271
+ function tomlCompletion(doc, position) {
45272
+ const r = completeOpmToml(doc.getText(), doc.offsetAt(position));
45273
+ if (!r) return [];
45274
+ const range = { start: doc.positionAt(r.from), end: doc.positionAt(r.to) };
45275
+ const KIND = { table: import_vscode_languageserver.CompletionItemKind.Module, key: import_vscode_languageserver.CompletionItemKind.Property, value: import_vscode_languageserver.CompletionItemKind.Value };
45276
+ return r.options.map((o, i) => {
45277
+ const snippet = o.cursor !== void 0 && o.cursor < o.apply.length;
45278
+ return {
45279
+ label: o.label,
45280
+ kind: KIND[o.kind],
45281
+ labelDetails: o.detail ? { description: o.detail } : void 0,
45282
+ detail: o.detail,
45283
+ documentation: o.info ? { kind: import_vscode_languageserver.MarkupKind.PlainText, value: o.info } : void 0,
45284
+ sortText: String(i).padStart(5, "0"),
45285
+ filterText: doc.getText(range).startsWith('"') ? o.label : o.label.replace(/^\[+/, ""),
45286
+ insertTextFormat: snippet ? import_vscode_languageserver.InsertTextFormat.Snippet : import_vscode_languageserver.InsertTextFormat.PlainText,
45287
+ textEdit: { range, newText: snippet ? snippetEscape(o.apply.slice(0, o.cursor)) + "$0" + snippetEscape(o.apply.slice(o.cursor)) : o.apply }
45288
+ };
45289
+ });
45290
+ }
45291
+ connection.onHover(({ textDocument, position }) => {
45292
+ const doc = documents.get(textDocument.uri);
45293
+ if (!doc || !isOpmToml(doc.uri)) return null;
45294
+ const h = describeOpmToml(doc.getText(), doc.offsetAt(position));
45295
+ if (!h) return null;
45296
+ return {
45297
+ range: { start: doc.positionAt(h.from), end: doc.positionAt(h.to) },
45298
+ contents: { kind: import_vscode_languageserver.MarkupKind.Markdown, value: `**${h.title}**: ${h.detail}${h.info ? "\n\n" + h.info : ""}` }
45299
+ };
45300
+ });
44362
45301
  connection.languages.onLinkedEditingRange(({ textDocument, position }) => {
44363
45302
  const doc = documents.get(textDocument.uri);
44364
- if (!doc) return null;
45303
+ if (!doc || isOpmToml(doc.uri)) return null;
44365
45304
  const ranges = matchingTags(doc.getText(), doc.offsetAt(position));
44366
45305
  if (!ranges) return null;
44367
45306
  return {
@@ -44373,6 +45312,7 @@ function startServer(connection, host2) {
44373
45312
  const doc = documents.get(textDocument.uri);
44374
45313
  if (!doc) return [];
44375
45314
  const text = doc.getText();
45315
+ if (isOpmToml(doc.uri)) return tomlOutline(doc);
44376
45316
  let symbols;
44377
45317
  try {
44378
45318
  symbols = isOdd(doc.uri) ? oddOutline(text) : vocabulary(text) === "tei" ? teiOutline(text) : elementOutline(text);
@@ -44389,9 +45329,32 @@ function startServer(connection, host2) {
44389
45329
  });
44390
45330
  return symbols.map(convert);
44391
45331
  });
45332
+ function tomlOutline(doc) {
45333
+ const text = doc.getText(), scan = scanToml(text);
45334
+ const range = (from, to) => ({ start: doc.positionAt(from), end: doc.positionAt(to) });
45335
+ const tables = scan.tables.map((t, n) => {
45336
+ const end = n + 1 < scan.tables.length ? scan.tables[n + 1].from : text.length;
45337
+ const keys2 = scan.keys.filter((k) => k.from > t.from && k.from < end);
45338
+ const last2 = keys2.length ? keys2[keys2.length - 1].valueTo : t.to;
45339
+ return {
45340
+ name: tableName(t.path),
45341
+ kind: t.array ? import_vscode_languageserver.SymbolKind.Array : import_vscode_languageserver.SymbolKind.Module,
45342
+ range: range(t.from, last2),
45343
+ selectionRange: range(t.from, t.to),
45344
+ children: keys2.map((k) => ({
45345
+ name: text.slice(k.from, k.to),
45346
+ kind: import_vscode_languageserver.SymbolKind.Property,
45347
+ range: range(k.from, k.valueTo),
45348
+ selectionRange: range(k.from, k.to)
45349
+ }))
45350
+ };
45351
+ });
45352
+ return tables;
45353
+ }
44392
45354
  connection.onSelectionRanges(({ textDocument, positions }) => {
44393
45355
  const doc = documents.get(textDocument.uri);
44394
45356
  if (!doc) return [];
45357
+ if (isOpmToml(doc.uri)) return positions.map((position) => ({ range: { start: position, end: position } }));
44395
45358
  const text = doc.getText();
44396
45359
  return positions.map((position) => {
44397
45360
  const at = doc.offsetAt(position);