@riboseinc/anafero-cli 0.0.47 → 0.0.49

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/build-site.mjs CHANGED
@@ -9378,7 +9378,7 @@ var require_isomorphic_git = __commonJS({
9378
9378
  }
9379
9379
  function flatFileListToDirectoryStructure(files) {
9380
9380
  const inodes = /* @__PURE__ */ new Map();
9381
- const mkdir3 = function(name2) {
9381
+ const mkdir4 = function(name2) {
9382
9382
  if (!inodes.has(name2)) {
9383
9383
  const dir3 = {
9384
9384
  type: "tree",
@@ -9388,7 +9388,7 @@ var require_isomorphic_git = __commonJS({
9388
9388
  children: []
9389
9389
  };
9390
9390
  inodes.set(name2, dir3);
9391
- dir3.parent = mkdir3(dirname3(name2));
9391
+ dir3.parent = mkdir4(dirname3(name2));
9392
9392
  if (dir3.parent && dir3.parent !== dir3) dir3.parent.children.push(dir3);
9393
9393
  }
9394
9394
  return inodes.get(name2);
@@ -9401,7 +9401,7 @@ var require_isomorphic_git = __commonJS({
9401
9401
  basename: basename2(name2),
9402
9402
  metadata,
9403
9403
  // This recursively generates any missing parent folders.
9404
- parent: mkdir3(dirname3(name2)),
9404
+ parent: mkdir4(dirname3(name2)),
9405
9405
  children: []
9406
9406
  };
9407
9407
  if (file4.parent) file4.parent.children.push(file4);
@@ -9409,7 +9409,7 @@ var require_isomorphic_git = __commonJS({
9409
9409
  }
9410
9410
  return inodes.get(name2);
9411
9411
  };
9412
- mkdir3(".");
9412
+ mkdir4(".");
9413
9413
  for (const file4 of files) {
9414
9414
  mkfile(file4.path, file4);
9415
9415
  }
@@ -48933,8 +48933,8 @@ var require_react_reconciler_development = __commonJS({
48933
48933
  lastRenderedState: initialState3
48934
48934
  };
48935
48935
  hook.queue = queue;
48936
- var dispatch = queue.dispatch = dispatchReducerAction.bind(null, currentlyRenderingFiber$1, queue);
48937
- return [hook.memoizedState, dispatch];
48936
+ var dispatch2 = queue.dispatch = dispatchReducerAction.bind(null, currentlyRenderingFiber$1, queue);
48937
+ return [hook.memoizedState, dispatch2];
48938
48938
  }
48939
48939
  function updateReducer(reducer, initialArg, init) {
48940
48940
  var hook = updateWorkInProgressHook();
@@ -49034,8 +49034,8 @@ var require_react_reconciler_development = __commonJS({
49034
49034
  } else if (baseQueue === null) {
49035
49035
  queue.lanes = NoLanes;
49036
49036
  }
49037
- var dispatch = queue.dispatch;
49038
- return [hook.memoizedState, dispatch];
49037
+ var dispatch2 = queue.dispatch;
49038
+ return [hook.memoizedState, dispatch2];
49039
49039
  }
49040
49040
  function rerenderReducer(reducer, initialArg, init) {
49041
49041
  var hook = updateWorkInProgressHook();
@@ -49044,7 +49044,7 @@ var require_react_reconciler_development = __commonJS({
49044
49044
  throw new Error("Should have a queue. This is likely a bug in React. Please file an issue.");
49045
49045
  }
49046
49046
  queue.lastRenderedReducer = reducer;
49047
- var dispatch = queue.dispatch;
49047
+ var dispatch2 = queue.dispatch;
49048
49048
  var lastRenderPhaseUpdate = queue.pending;
49049
49049
  var newState = hook.memoizedState;
49050
49050
  if (lastRenderPhaseUpdate !== null) {
@@ -49065,7 +49065,7 @@ var require_react_reconciler_development = __commonJS({
49065
49065
  }
49066
49066
  queue.lastRenderedState = newState;
49067
49067
  }
49068
- return [newState, dispatch];
49068
+ return [newState, dispatch2];
49069
49069
  }
49070
49070
  function mountMutableSource(source, getSnapshot, subscribe4) {
49071
49071
  {
@@ -49227,8 +49227,8 @@ var require_react_reconciler_development = __commonJS({
49227
49227
  lastRenderedState: initialState3
49228
49228
  };
49229
49229
  hook.queue = queue;
49230
- var dispatch = queue.dispatch = dispatchSetState.bind(null, currentlyRenderingFiber$1, queue);
49231
- return [hook.memoizedState, dispatch];
49230
+ var dispatch2 = queue.dispatch = dispatchSetState.bind(null, currentlyRenderingFiber$1, queue);
49231
+ return [hook.memoizedState, dispatch2];
49232
49232
  }
49233
49233
  function updateState(initialState3) {
49234
49234
  return updateReducer(basicStateReducer);
@@ -59385,7 +59385,7 @@ var require_stack_utils = __commonJS({
59385
59385
  "use strict";
59386
59386
  init_cjs_shim();
59387
59387
  var escapeStringRegexp = require_escape_string_regexp();
59388
- var cwd2 = typeof process === "object" && process && typeof process.cwd === "function" ? process.cwd() : ".";
59388
+ var cwd3 = typeof process === "object" && process && typeof process.cwd === "function" ? process.cwd() : ".";
59389
59389
  var natives = [].concat(
59390
59390
  __require("module").builtinModules,
59391
59391
  "bootstrap_node",
@@ -59406,7 +59406,7 @@ var require_stack_utils = __commonJS({
59406
59406
  opts.internals = _StackUtils.nodeInternals();
59407
59407
  }
59408
59408
  if ("cwd" in opts === false) {
59409
- opts.cwd = cwd2;
59409
+ opts.cwd = cwd3;
59410
59410
  }
59411
59411
  this._cwd = opts.cwd.replace(/\\/g, "/");
59412
59412
  this._internals = [].concat(
@@ -59609,11 +59609,11 @@ var require_stack_utils = __commonJS({
59609
59609
  return res;
59610
59610
  }
59611
59611
  };
59612
- function setFile(result, filename, cwd3) {
59612
+ function setFile(result, filename, cwd4) {
59613
59613
  if (filename) {
59614
59614
  filename = filename.replace(/\\/g, "/");
59615
- if (filename.startsWith(`${cwd3}/`)) {
59616
- filename = filename.slice(cwd3.length + 1);
59615
+ if (filename.startsWith(`${cwd4}/`)) {
59616
+ filename = filename.slice(cwd4.length + 1);
59617
59617
  }
59618
59618
  result.file = filename;
59619
59619
  }
@@ -201280,7 +201280,7 @@ var require_react_dom_server_legacy_node_development = __commonJS({
201280
201280
  workInProgressHook = createWorkInProgressHook();
201281
201281
  if (isReRender) {
201282
201282
  var queue = workInProgressHook.queue;
201283
- var dispatch = queue.dispatch;
201283
+ var dispatch2 = queue.dispatch;
201284
201284
  if (renderPhaseUpdates !== null) {
201285
201285
  var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
201286
201286
  if (firstRenderPhaseUpdate !== void 0) {
@@ -201299,10 +201299,10 @@ var require_react_dom_server_legacy_node_development = __commonJS({
201299
201299
  update5 = update5.next;
201300
201300
  } while (update5 !== null);
201301
201301
  workInProgressHook.memoizedState = newState;
201302
- return [newState, dispatch];
201302
+ return [newState, dispatch2];
201303
201303
  }
201304
201304
  }
201305
- return [workInProgressHook.memoizedState, dispatch];
201305
+ return [workInProgressHook.memoizedState, dispatch2];
201306
201306
  } else {
201307
201307
  {
201308
201308
  isInHookUserCodeInDev = true;
@@ -206760,7 +206760,7 @@ var require_react_dom_server_node_development = __commonJS({
206760
206760
  workInProgressHook = createWorkInProgressHook();
206761
206761
  if (isReRender) {
206762
206762
  var queue = workInProgressHook.queue;
206763
- var dispatch = queue.dispatch;
206763
+ var dispatch2 = queue.dispatch;
206764
206764
  if (renderPhaseUpdates !== null) {
206765
206765
  var firstRenderPhaseUpdate = renderPhaseUpdates.get(queue);
206766
206766
  if (firstRenderPhaseUpdate !== void 0) {
@@ -206779,10 +206779,10 @@ var require_react_dom_server_node_development = __commonJS({
206779
206779
  update5 = update5.next;
206780
206780
  } while (update5 !== null);
206781
206781
  workInProgressHook.memoizedState = newState;
206782
- return [newState, dispatch];
206782
+ return [newState, dispatch2];
206783
206783
  }
206784
206784
  }
206785
- return [workInProgressHook.memoizedState, dispatch];
206785
+ return [workInProgressHook.memoizedState, dispatch2];
206786
206786
  } else {
206787
206787
  {
206788
206788
  isInHookUserCodeInDev = true;
@@ -228007,8 +228007,8 @@ var require_react_dom_development = __commonJS({
228007
228007
  lastRenderedState: initialState3
228008
228008
  };
228009
228009
  hook.queue = queue;
228010
- var dispatch = queue.dispatch = dispatchReducerAction.bind(null, currentlyRenderingFiber$1, queue);
228011
- return [hook.memoizedState, dispatch];
228010
+ var dispatch2 = queue.dispatch = dispatchReducerAction.bind(null, currentlyRenderingFiber$1, queue);
228011
+ return [hook.memoizedState, dispatch2];
228012
228012
  }
228013
228013
  function updateReducer(reducer, initialArg, init) {
228014
228014
  var hook = updateWorkInProgressHook();
@@ -228108,8 +228108,8 @@ var require_react_dom_development = __commonJS({
228108
228108
  } else if (baseQueue === null) {
228109
228109
  queue.lanes = NoLanes;
228110
228110
  }
228111
- var dispatch = queue.dispatch;
228112
- return [hook.memoizedState, dispatch];
228111
+ var dispatch2 = queue.dispatch;
228112
+ return [hook.memoizedState, dispatch2];
228113
228113
  }
228114
228114
  function rerenderReducer(reducer, initialArg, init) {
228115
228115
  var hook = updateWorkInProgressHook();
@@ -228118,7 +228118,7 @@ var require_react_dom_development = __commonJS({
228118
228118
  throw new Error("Should have a queue. This is likely a bug in React. Please file an issue.");
228119
228119
  }
228120
228120
  queue.lastRenderedReducer = reducer;
228121
- var dispatch = queue.dispatch;
228121
+ var dispatch2 = queue.dispatch;
228122
228122
  var lastRenderPhaseUpdate = queue.pending;
228123
228123
  var newState = hook.memoizedState;
228124
228124
  if (lastRenderPhaseUpdate !== null) {
@@ -228139,7 +228139,7 @@ var require_react_dom_development = __commonJS({
228139
228139
  }
228140
228140
  queue.lastRenderedState = newState;
228141
228141
  }
228142
- return [newState, dispatch];
228142
+ return [newState, dispatch2];
228143
228143
  }
228144
228144
  function mountMutableSource(source, getSnapshot, subscribe4) {
228145
228145
  {
@@ -228301,8 +228301,8 @@ var require_react_dom_development = __commonJS({
228301
228301
  lastRenderedState: initialState3
228302
228302
  };
228303
228303
  hook.queue = queue;
228304
- var dispatch = queue.dispatch = dispatchSetState.bind(null, currentlyRenderingFiber$1, queue);
228305
- return [hook.memoizedState, dispatch];
228304
+ var dispatch2 = queue.dispatch = dispatchSetState.bind(null, currentlyRenderingFiber$1, queue);
228305
+ return [hook.memoizedState, dispatch2];
228306
228306
  }
228307
228307
  function updateState(initialState3) {
228308
228308
  return updateReducer(basicStateReducer);
@@ -246248,7 +246248,7 @@ var import_isomorphic_git2 = __toESM(require_isomorphic_git(), 1);
246248
246248
  var import_util = __toESM(require_util(), 1);
246249
246249
  var import_isogit_lfs = __toESM(require_isogit_lfs(), 1);
246250
246250
  import { resolve as resolve3, dirname as dirname2, extname, join as join8 } from "node:path";
246251
- import { readFile as readFile4, writeFile as writeFile3, mkdir as mkdir2, stat as stat5 } from "node:fs/promises";
246251
+ import { readFile as readFile4, writeFile as writeFile4, mkdir as mkdir3, stat as stat5 } from "node:fs/promises";
246252
246252
  import { parse as parseURL } from "node:url";
246253
246253
  import { createServer } from "node:http";
246254
246254
  import { watch as watch3 } from "node:fs/promises";
@@ -275838,17 +275838,17 @@ function fromFileUrl(url3) {
275838
275838
  var resolve = function resolve2() {
275839
275839
  let resolvedPath = "";
275840
275840
  let resolvedAbsolute = false;
275841
- let cwd2 = void 0;
275841
+ let cwd3 = void 0;
275842
275842
  for (let i2 = arguments.length - 1; i2 >= -1 && !resolvedAbsolute; i2--) {
275843
275843
  let path3;
275844
275844
  if (i2 >= 0) {
275845
275845
  path3 = arguments[i2];
275846
275846
  } else {
275847
275847
  const process14 = globalThis.process;
275848
- if (cwd2 === void 0 && "process" in globalThis && typeof process14 === "object" && process14 !== null && typeof process14.cwd === "function") {
275849
- cwd2 = process14.cwd();
275848
+ if (cwd3 === void 0 && "process" in globalThis && typeof process14 === "object" && process14 !== null && typeof process14.cwd === "function") {
275849
+ cwd3 = process14.cwd();
275850
275850
  }
275851
- path3 = cwd2;
275851
+ path3 = cwd3;
275852
275852
  }
275853
275853
  if (path3.length === 0) {
275854
275854
  continue;
@@ -287269,7 +287269,7 @@ var image = (data, options3 = {}) => {
287269
287269
  return returnValue + ":" + Buffer.from(data).toString("base64") + BEL2;
287270
287270
  };
287271
287271
  var iTerm = {
287272
- setCwd: (cwd2 = cwdFunction()) => `${OSC}50;CurrentDir=${cwd2}${BEL2}`,
287272
+ setCwd: (cwd3 = cwdFunction()) => `${OSC}50;CurrentDir=${cwd3}${BEL2}`,
287273
287273
  annotation(message, options3 = {}) {
287274
287274
  let returnValue = `${OSC}1337;`;
287275
287275
  const hasX = options3.x !== void 0;
@@ -316486,6 +316486,76 @@ function processAttributes(el, locateResource, reverseResource, onIntegrityViola
316486
316486
 
316487
316487
  // ../anafero/ContentReader.mts
316488
316488
  init_cjs_shim();
316489
+
316490
+ // ../anafero/util/normalizePath.mts
316491
+ init_cjs_shim();
316492
+ var CHAR_DOT = 46;
316493
+ var CHAR_FORWARD_SLASH2 = 47;
316494
+ function normalizeString(path3, allowAboveRoot = false, separator = "/", isPathSeparator = (c2) => c2 === CHAR_FORWARD_SLASH2) {
316495
+ let res = "";
316496
+ let lastSegmentLength = 0;
316497
+ let lastSlash = -1;
316498
+ let dots = 0;
316499
+ let code2 = 0;
316500
+ let isAbsolute = isPathSeparator(path3.charCodeAt(0));
316501
+ for (let i2 = 0; i2 <= path3.length; ++i2) {
316502
+ if (i2 < path3.length) {
316503
+ code2 = path3.charCodeAt(i2);
316504
+ } else if (isPathSeparator(code2)) {
316505
+ break;
316506
+ } else {
316507
+ code2 = CHAR_FORWARD_SLASH2;
316508
+ }
316509
+ if (isPathSeparator(code2)) {
316510
+ if (lastSlash === i2 - 1 || dots === 1) {
316511
+ } else if (dots === 2) {
316512
+ if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) {
316513
+ if (res.length > 2) {
316514
+ const lastSlashIndex = res.lastIndexOf(separator);
316515
+ if (lastSlashIndex === -1) {
316516
+ res = "";
316517
+ lastSegmentLength = 0;
316518
+ } else {
316519
+ res = res.substring(0, lastSlashIndex);
316520
+ lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
316521
+ }
316522
+ lastSlash = i2;
316523
+ dots = 0;
316524
+ continue;
316525
+ } else if (res.length !== 0) {
316526
+ res = "";
316527
+ lastSegmentLength = 0;
316528
+ lastSlash = i2;
316529
+ dots = 0;
316530
+ continue;
316531
+ }
316532
+ }
316533
+ if (allowAboveRoot && !isAbsolute) {
316534
+ res += res.length > 0 ? `${separator}..` : "..";
316535
+ lastSegmentLength = 2;
316536
+ } else {
316537
+ throw new Error("Cannot step outside current directory or filesystem root");
316538
+ }
316539
+ } else {
316540
+ if (res.length > 0) {
316541
+ res += `${separator}${path3.substring(lastSlash + 1, i2)}`;
316542
+ } else {
316543
+ res = path3.substring(lastSlash + 1, i2);
316544
+ }
316545
+ lastSegmentLength = i2 - lastSlash - 1;
316546
+ }
316547
+ lastSlash = i2;
316548
+ dots = 0;
316549
+ } else if (code2 === CHAR_DOT && dots !== -1) {
316550
+ ++dots;
316551
+ } else {
316552
+ dots = -1;
316553
+ }
316554
+ }
316555
+ return isAbsolute ? `/${res}` : res;
316556
+ }
316557
+
316558
+ // ../anafero/ContentReader.mts
316489
316559
  var makeContentReader = async function(entryPointURI, storeAdapters, findContentAdapter, { fetchBlob, reportProgress, decodeXML, cache: cache3 }) {
316490
316560
  const canonicalURIs = {};
316491
316561
  const originalURIs = {};
@@ -316844,23 +316914,18 @@ var makeContentReader = async function(entryPointURI, storeAdapters, findContent
316844
316914
  function isValidPathComponent(val) {
316845
316915
  return val.indexOf("/") < 0 && val.indexOf(":") < 0 && val.indexOf("#") < 0;
316846
316916
  }
316847
- function unprefixLocalPath(filePath) {
316848
- return filePath.startsWith("./") ? filePath.split("./")[1] : filePath;
316849
- }
316850
316917
  function normalizeFileURI(fileURI, baseFileURI) {
316851
- const normalizedPath = unprefixLocalPath(fileURI.split("file:")[1]);
316852
- if (normalizedPath.startsWith("./") || normalizedPath.startsWith("../")) {
316853
- throw new Error("Malformed path in file URI");
316854
- }
316918
+ const rawPath = fileURI.split("file:")[1];
316919
+ const normalizedPath = normalizeString(rawPath);
316855
316920
  const normalizedURI = `file:${normalizedPath}`;
316856
316921
  if (baseFileURI === void 0) {
316857
316922
  return normalizedURI;
316858
316923
  }
316859
- const basePath = baseFileURI.startsWith("file:") ? unprefixLocalPath(baseFileURI.split("file:")[1]) : void 0;
316860
- if (!basePath) {
316924
+ const normalizedBasePath = baseFileURI.startsWith("file:") ? normalizeString(baseFileURI.split("file:")[1]) : void 0;
316925
+ if (!normalizedBasePath) {
316861
316926
  throw new Error("Trying to normalize a file: URI, but base URI is not using that scheme");
316862
316927
  }
316863
- const dirname3 = basePath.indexOf("/") >= 1 ? basePath.slice(0, basePath.lastIndexOf("/")) : "";
316928
+ const dirname3 = normalizedBasePath.indexOf("/") >= 1 ? normalizedBasePath.slice(0, normalizedBasePath.lastIndexOf("/")) : "";
316864
316929
  return normalizedPath.startsWith("/") ? normalizedURI : `file:${dirname3}${dirname3 ? "/" : ""}${normalizedPath}`;
316865
316930
  }
316866
316931
 
@@ -317367,7 +317432,7 @@ init_cjs_shim();
317367
317432
  var import_node = __toESM(require_node2(), 1);
317368
317433
  var import_isomorphic_git = __toESM(require_isomorphic_git(), 1);
317369
317434
  import { join as join7, basename } from "node:path";
317370
- import { rmdir, readFile as readFile3, cp as cp2, mkdtemp as mkdtemp2, stat as stat4 } from "node:fs/promises";
317435
+ import { readdir, rmdir, readFile as readFile3, cp as cp2, mkdtemp as mkdtemp2, stat as stat4, mkdir as mkdir2, writeFile as writeFile3 } from "node:fs/promises";
317371
317436
  import vm from "node:vm";
317372
317437
  import { tmpdir as tmpdir2 } from "node:os";
317373
317438
  import fs3 from "node:fs";
@@ -319865,21 +319930,21 @@ function addColumn(tr, { map: map38, tableStart, table: table3 }, col) {
319865
319930
  }
319866
319931
  return tr;
319867
319932
  }
319868
- function addColumnBefore(state, dispatch) {
319933
+ function addColumnBefore(state, dispatch2) {
319869
319934
  if (!isInTable(state))
319870
319935
  return false;
319871
- if (dispatch) {
319936
+ if (dispatch2) {
319872
319937
  const rect = selectedRect(state);
319873
- dispatch(addColumn(state.tr, rect, rect.left));
319938
+ dispatch2(addColumn(state.tr, rect, rect.left));
319874
319939
  }
319875
319940
  return true;
319876
319941
  }
319877
- function addColumnAfter(state, dispatch) {
319942
+ function addColumnAfter(state, dispatch2) {
319878
319943
  if (!isInTable(state))
319879
319944
  return false;
319880
- if (dispatch) {
319945
+ if (dispatch2) {
319881
319946
  const rect = selectedRect(state);
319882
- dispatch(addColumn(state.tr, rect, rect.right));
319947
+ dispatch2(addColumn(state.tr, rect, rect.right));
319883
319948
  }
319884
319949
  return true;
319885
319950
  }
@@ -319903,10 +319968,10 @@ function removeColumn(tr, { map: map38, table: table3, tableStart }, col) {
319903
319968
  row += attrs.rowspan;
319904
319969
  }
319905
319970
  }
319906
- function deleteColumn(state, dispatch) {
319971
+ function deleteColumn(state, dispatch2) {
319907
319972
  if (!isInTable(state))
319908
319973
  return false;
319909
- if (dispatch) {
319974
+ if (dispatch2) {
319910
319975
  const rect = selectedRect(state);
319911
319976
  const tr = state.tr;
319912
319977
  if (rect.left == 0 && rect.right == rect.map.width)
@@ -319922,7 +319987,7 @@ function deleteColumn(state, dispatch) {
319922
319987
  rect.table = table3;
319923
319988
  rect.map = TableMap.get(table3);
319924
319989
  }
319925
- dispatch(tr);
319990
+ dispatch2(tr);
319926
319991
  }
319927
319992
  return true;
319928
319993
  }
@@ -319962,21 +320027,21 @@ function addRow(tr, { map: map38, tableStart, table: table3 }, row) {
319962
320027
  tr.insert(rowPos, tableNodeTypes(table3.type.schema).row.create(null, cells));
319963
320028
  return tr;
319964
320029
  }
319965
- function addRowBefore(state, dispatch) {
320030
+ function addRowBefore(state, dispatch2) {
319966
320031
  if (!isInTable(state))
319967
320032
  return false;
319968
- if (dispatch) {
320033
+ if (dispatch2) {
319969
320034
  const rect = selectedRect(state);
319970
- dispatch(addRow(state.tr, rect, rect.top));
320035
+ dispatch2(addRow(state.tr, rect, rect.top));
319971
320036
  }
319972
320037
  return true;
319973
320038
  }
319974
- function addRowAfter(state, dispatch) {
320039
+ function addRowAfter(state, dispatch2) {
319975
320040
  if (!isInTable(state))
319976
320041
  return false;
319977
- if (dispatch) {
320042
+ if (dispatch2) {
319978
320043
  const rect = selectedRect(state);
319979
- dispatch(addRow(state.tr, rect, rect.bottom));
320044
+ dispatch2(addRow(state.tr, rect, rect.bottom));
319980
320045
  }
319981
320046
  return true;
319982
320047
  }
@@ -320013,10 +320078,10 @@ function removeRow(tr, { map: map38, table: table3, tableStart }, row) {
320013
320078
  }
320014
320079
  }
320015
320080
  }
320016
- function deleteRow(state, dispatch) {
320081
+ function deleteRow(state, dispatch2) {
320017
320082
  if (!isInTable(state))
320018
320083
  return false;
320019
- if (dispatch) {
320084
+ if (dispatch2) {
320020
320085
  const rect = selectedRect(state), tr = state.tr;
320021
320086
  if (rect.top == 0 && rect.bottom == rect.map.height)
320022
320087
  return false;
@@ -320031,7 +320096,7 @@ function deleteRow(state, dispatch) {
320031
320096
  rect.table = table3;
320032
320097
  rect.map = TableMap.get(rect.table);
320033
320098
  }
320034
- dispatch(tr);
320099
+ dispatch2(tr);
320035
320100
  }
320036
320101
  return true;
320037
320102
  }
@@ -320056,14 +320121,14 @@ function cellsOverlapRectangle({ width: width3, height, map: map38 }, rect) {
320056
320121
  }
320057
320122
  return false;
320058
320123
  }
320059
- function mergeCells(state, dispatch) {
320124
+ function mergeCells(state, dispatch2) {
320060
320125
  const sel = state.selection;
320061
320126
  if (!(sel instanceof CellSelection) || sel.$anchorCell.pos == sel.$headCell.pos)
320062
320127
  return false;
320063
320128
  const rect = selectedRect(state), { map: map38 } = rect;
320064
320129
  if (cellsOverlapRectangle(map38, rect))
320065
320130
  return false;
320066
- if (dispatch) {
320131
+ if (dispatch2) {
320067
320132
  const tr = state.tr;
320068
320133
  const seen = {};
320069
320134
  let content = Fragment.empty;
@@ -320106,18 +320171,18 @@ function mergeCells(state, dispatch) {
320106
320171
  tr.setSelection(
320107
320172
  new CellSelection(tr.doc.resolve(mergedPos + rect.tableStart))
320108
320173
  );
320109
- dispatch(tr);
320174
+ dispatch2(tr);
320110
320175
  }
320111
320176
  return true;
320112
320177
  }
320113
- function splitCell(state, dispatch) {
320178
+ function splitCell(state, dispatch2) {
320114
320179
  const nodeTypes = tableNodeTypes(state.schema);
320115
320180
  return splitCellWithType(({ node }) => {
320116
320181
  return nodeTypes[node.type.spec.tableRole];
320117
- })(state, dispatch);
320182
+ })(state, dispatch2);
320118
320183
  }
320119
320184
  function splitCellWithType(getCellType) {
320120
- return (state, dispatch) => {
320185
+ return (state, dispatch2) => {
320121
320186
  var _a;
320122
320187
  const sel = state.selection;
320123
320188
  let cellNode;
@@ -320139,7 +320204,7 @@ function splitCellWithType(getCellType) {
320139
320204
  if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {
320140
320205
  return false;
320141
320206
  }
320142
- if (dispatch) {
320207
+ if (dispatch2) {
320143
320208
  let baseAttrs = cellNode.attrs;
320144
320209
  const attrs = [];
320145
320210
  const colwidth = baseAttrs.colwidth;
@@ -320181,19 +320246,19 @@ function splitCellWithType(getCellType) {
320181
320246
  lastCell ? tr.doc.resolve(lastCell) : void 0
320182
320247
  )
320183
320248
  );
320184
- dispatch(tr);
320249
+ dispatch2(tr);
320185
320250
  }
320186
320251
  return true;
320187
320252
  };
320188
320253
  }
320189
320254
  function setCellAttr(name2, value5) {
320190
- return function(state, dispatch) {
320255
+ return function(state, dispatch2) {
320191
320256
  if (!isInTable(state))
320192
320257
  return false;
320193
320258
  const $cell = selectionCell(state);
320194
320259
  if ($cell.nodeAfter.attrs[name2] === value5)
320195
320260
  return false;
320196
- if (dispatch) {
320261
+ if (dispatch2) {
320197
320262
  const tr = state.tr;
320198
320263
  if (state.selection instanceof CellSelection)
320199
320264
  state.selection.forEachCell((node, pos) => {
@@ -320208,16 +320273,16 @@ function setCellAttr(name2, value5) {
320208
320273
  ...$cell.nodeAfter.attrs,
320209
320274
  [name2]: value5
320210
320275
  });
320211
- dispatch(tr);
320276
+ dispatch2(tr);
320212
320277
  }
320213
320278
  return true;
320214
320279
  };
320215
320280
  }
320216
320281
  function deprecated_toggleHeader(type2) {
320217
- return function(state, dispatch) {
320282
+ return function(state, dispatch2) {
320218
320283
  if (!isInTable(state))
320219
320284
  return false;
320220
- if (dispatch) {
320285
+ if (dispatch2) {
320221
320286
  const types3 = tableNodeTypes(state.schema);
320222
320287
  const rect = selectedRect(state), tr = state.tr;
320223
320288
  const cells = rect.map.cellsInRect(
@@ -320248,7 +320313,7 @@ function deprecated_toggleHeader(type2) {
320248
320313
  types3.header_cell,
320249
320314
  nodes[i2].attrs
320250
320315
  );
320251
- dispatch(tr);
320316
+ dispatch2(tr);
320252
320317
  }
320253
320318
  return true;
320254
320319
  };
@@ -320272,10 +320337,10 @@ function toggleHeader(type2, options3) {
320272
320337
  options3 = options3 || { useDeprecatedLogic: false };
320273
320338
  if (options3.useDeprecatedLogic)
320274
320339
  return deprecated_toggleHeader(type2);
320275
- return function(state, dispatch) {
320340
+ return function(state, dispatch2) {
320276
320341
  if (!isInTable(state))
320277
320342
  return false;
320278
- if (dispatch) {
320343
+ if (dispatch2) {
320279
320344
  const types3 = tableNodeTypes(state.schema);
320280
320345
  const rect = selectedRect(state), tr = state.tr;
320281
320346
  const isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types3);
@@ -320305,7 +320370,7 @@ function toggleHeader(type2, options3) {
320305
320370
  tr.setNodeMarkup(cellPos, newType, cell.attrs);
320306
320371
  }
320307
320372
  });
320308
- dispatch(tr);
320373
+ dispatch2(tr);
320309
320374
  }
320310
320375
  return true;
320311
320376
  };
@@ -320347,28 +320412,28 @@ function findNextCell($cell, dir3) {
320347
320412
  return null;
320348
320413
  }
320349
320414
  function goToNextCell(direction) {
320350
- return function(state, dispatch) {
320415
+ return function(state, dispatch2) {
320351
320416
  if (!isInTable(state))
320352
320417
  return false;
320353
320418
  const cell = findNextCell(selectionCell(state), direction);
320354
320419
  if (cell == null)
320355
320420
  return false;
320356
- if (dispatch) {
320421
+ if (dispatch2) {
320357
320422
  const $cell = state.doc.resolve(cell);
320358
- dispatch(
320423
+ dispatch2(
320359
320424
  state.tr.setSelection(TextSelection.between($cell, moveCellForward($cell))).scrollIntoView()
320360
320425
  );
320361
320426
  }
320362
320427
  return true;
320363
320428
  };
320364
320429
  }
320365
- function deleteTable(state, dispatch) {
320430
+ function deleteTable(state, dispatch2) {
320366
320431
  const $pos = state.selection.$anchor;
320367
320432
  for (let d = $pos.depth; d > 0; d--) {
320368
320433
  const node = $pos.node(d);
320369
320434
  if (node.type.spec.tableRole == "table") {
320370
- if (dispatch)
320371
- dispatch(
320435
+ if (dispatch2)
320436
+ dispatch2(
320372
320437
  state.tr.delete($pos.before(d), $pos.after(d)).scrollIntoView()
320373
320438
  );
320374
320439
  return true;
@@ -320376,11 +320441,11 @@ function deleteTable(state, dispatch) {
320376
320441
  }
320377
320442
  return false;
320378
320443
  }
320379
- function deleteCellSelection(state, dispatch) {
320444
+ function deleteCellSelection(state, dispatch2) {
320380
320445
  const sel = state.selection;
320381
320446
  if (!(sel instanceof CellSelection))
320382
320447
  return false;
320383
- if (dispatch) {
320448
+ if (dispatch2) {
320384
320449
  const tr = state.tr;
320385
320450
  const baseContent = tableNodeTypes(state.schema).cell.createAndFill().content;
320386
320451
  sel.forEachCell((cell, pos) => {
@@ -320392,7 +320457,7 @@ function deleteCellSelection(state, dispatch) {
320392
320457
  );
320393
320458
  });
320394
320459
  if (tr.docChanged)
320395
- dispatch(tr);
320460
+ dispatch2(tr);
320396
320461
  }
320397
320462
  return true;
320398
320463
  }
@@ -320606,7 +320671,7 @@ function isolateVertical(tr, map38, table3, start4, top, bottom, left3, mapFrom)
320606
320671
  }
320607
320672
  return found2;
320608
320673
  }
320609
- function insertCells(state, dispatch, tableStart, rect, cells) {
320674
+ function insertCells(state, dispatch2, tableStart, rect, cells) {
320610
320675
  let table3 = tableStart ? state.doc.nodeAt(tableStart - 1) : state.doc;
320611
320676
  if (!table3) {
320612
320677
  throw new Error("No table found");
@@ -320649,7 +320714,7 @@ function insertCells(state, dispatch, tableStart, rect, cells) {
320649
320714
  tr.doc.resolve(tableStart + map38.positionAt(bottom - 1, right3 - 1, table3))
320650
320715
  )
320651
320716
  );
320652
- dispatch(tr);
320717
+ dispatch2(tr);
320653
320718
  }
320654
320719
  var handleKeyDown = keydownHandler({
320655
320720
  ArrowLeft: arrow("horiz", -1),
@@ -320665,22 +320730,22 @@ var handleKeyDown = keydownHandler({
320665
320730
  Delete: deleteCellSelection,
320666
320731
  "Mod-Delete": deleteCellSelection
320667
320732
  });
320668
- function maybeSetSelection(state, dispatch, selection) {
320733
+ function maybeSetSelection(state, dispatch2, selection) {
320669
320734
  if (selection.eq(state.selection))
320670
320735
  return false;
320671
- if (dispatch)
320672
- dispatch(state.tr.setSelection(selection).scrollIntoView());
320736
+ if (dispatch2)
320737
+ dispatch2(state.tr.setSelection(selection).scrollIntoView());
320673
320738
  return true;
320674
320739
  }
320675
320740
  function arrow(axis, dir3) {
320676
- return (state, dispatch, view) => {
320741
+ return (state, dispatch2, view) => {
320677
320742
  if (!view)
320678
320743
  return false;
320679
320744
  const sel = state.selection;
320680
320745
  if (sel instanceof CellSelection) {
320681
320746
  return maybeSetSelection(
320682
320747
  state,
320683
- dispatch,
320748
+ dispatch2,
320684
320749
  Selection.near(sel.$headCell, dir3)
320685
320750
  );
320686
320751
  }
@@ -320692,7 +320757,7 @@ function arrow(axis, dir3) {
320692
320757
  if (axis == "horiz") {
320693
320758
  return maybeSetSelection(
320694
320759
  state,
320695
- dispatch,
320760
+ dispatch2,
320696
320761
  Selection.near(state.doc.resolve(sel.head + dir3), dir3)
320697
320762
  );
320698
320763
  } else {
@@ -320705,12 +320770,12 @@ function arrow(axis, dir3) {
320705
320770
  newSel = Selection.near(state.doc.resolve($cell.before(-1)), -1);
320706
320771
  else
320707
320772
  newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1);
320708
- return maybeSetSelection(state, dispatch, newSel);
320773
+ return maybeSetSelection(state, dispatch2, newSel);
320709
320774
  }
320710
320775
  };
320711
320776
  }
320712
320777
  function shiftArrow(axis, dir3) {
320713
- return (state, dispatch, view) => {
320778
+ return (state, dispatch2, view) => {
320714
320779
  if (!view)
320715
320780
  return false;
320716
320781
  const sel = state.selection;
@@ -320728,7 +320793,7 @@ function shiftArrow(axis, dir3) {
320728
320793
  return false;
320729
320794
  return maybeSetSelection(
320730
320795
  state,
320731
- dispatch,
320796
+ dispatch2,
320732
320797
  new CellSelection(cellSel.$anchorCell, $head)
320733
320798
  );
320734
320799
  };
@@ -321302,7 +321367,7 @@ function addListNodes(nodes, itemContent, listGroup) {
321302
321367
  });
321303
321368
  }
321304
321369
  function wrapInList(listType, attrs = null) {
321305
- return function(state, dispatch) {
321370
+ return function(state, dispatch2) {
321306
321371
  let { $from, $to } = state.selection;
321307
321372
  let range4 = $from.blockRange($to), doJoin = false, outerRange = range4;
321308
321373
  if (!range4)
@@ -321319,8 +321384,8 @@ function wrapInList(listType, attrs = null) {
321319
321384
  let wrap2 = findWrapping(outerRange, listType, attrs, range4);
321320
321385
  if (!wrap2)
321321
321386
  return false;
321322
- if (dispatch)
321323
- dispatch(doWrapInList(state.tr, range4, wrap2, doJoin, listType).scrollIntoView());
321387
+ if (dispatch2)
321388
+ dispatch2(doWrapInList(state.tr, range4, wrap2, doJoin, listType).scrollIntoView());
321324
321389
  return true;
321325
321390
  };
321326
321391
  }
@@ -321345,7 +321410,7 @@ function doWrapInList(tr, range4, wrappers, joinBefore, listType) {
321345
321410
  return tr;
321346
321411
  }
321347
321412
  function splitListItem(itemType, itemAttrs) {
321348
- return function(state, dispatch) {
321413
+ return function(state, dispatch2) {
321349
321414
  let { $from, $to, node } = state.selection;
321350
321415
  if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to))
321351
321416
  return false;
@@ -321355,7 +321420,7 @@ function splitListItem(itemType, itemAttrs) {
321355
321420
  if ($from.parent.content.size == 0 && $from.node(-1).childCount == $from.indexAfter(-1)) {
321356
321421
  if ($from.depth == 3 || $from.node(-3).type != itemType || $from.index(-2) != $from.node(-2).childCount - 1)
321357
321422
  return false;
321358
- if (dispatch) {
321423
+ if (dispatch2) {
321359
321424
  let wrap2 = Fragment.empty;
321360
321425
  let depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3;
321361
321426
  for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d--)
@@ -321373,7 +321438,7 @@ function splitListItem(itemType, itemAttrs) {
321373
321438
  });
321374
321439
  if (sel > -1)
321375
321440
  tr2.setSelection(Selection.near(tr2.doc.resolve(sel)));
321376
- dispatch(tr2.scrollIntoView());
321441
+ dispatch2(tr2.scrollIntoView());
321377
321442
  }
321378
321443
  return true;
321379
321444
  }
@@ -321382,37 +321447,37 @@ function splitListItem(itemType, itemAttrs) {
321382
321447
  let types3 = nextType ? [itemAttrs ? { type: itemType, attrs: itemAttrs } : null, { type: nextType }] : void 0;
321383
321448
  if (!canSplit(tr.doc, $from.pos, 2, types3))
321384
321449
  return false;
321385
- if (dispatch)
321386
- dispatch(tr.split($from.pos, 2, types3).scrollIntoView());
321450
+ if (dispatch2)
321451
+ dispatch2(tr.split($from.pos, 2, types3).scrollIntoView());
321387
321452
  return true;
321388
321453
  };
321389
321454
  }
321390
321455
  function splitListItemKeepMarks(itemType, itemAttrs) {
321391
321456
  let split4 = splitListItem(itemType, itemAttrs);
321392
- return (state, dispatch) => {
321393
- return split4(state, dispatch && ((tr) => {
321457
+ return (state, dispatch2) => {
321458
+ return split4(state, dispatch2 && ((tr) => {
321394
321459
  let marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks();
321395
321460
  if (marks)
321396
321461
  tr.ensureMarks(marks);
321397
- dispatch(tr);
321462
+ dispatch2(tr);
321398
321463
  }));
321399
321464
  };
321400
321465
  }
321401
321466
  function liftListItem(itemType) {
321402
- return function(state, dispatch) {
321467
+ return function(state, dispatch2) {
321403
321468
  let { $from, $to } = state.selection;
321404
321469
  let range4 = $from.blockRange($to, (node) => node.childCount > 0 && node.firstChild.type == itemType);
321405
321470
  if (!range4)
321406
321471
  return false;
321407
- if (!dispatch)
321472
+ if (!dispatch2)
321408
321473
  return true;
321409
321474
  if ($from.node(range4.depth - 1).type == itemType)
321410
- return liftToOuterList(state, dispatch, itemType, range4);
321475
+ return liftToOuterList(state, dispatch2, itemType, range4);
321411
321476
  else
321412
- return liftOutOfList(state, dispatch, range4);
321477
+ return liftOutOfList(state, dispatch2, range4);
321413
321478
  };
321414
321479
  }
321415
- function liftToOuterList(state, dispatch, itemType, range4) {
321480
+ function liftToOuterList(state, dispatch2, itemType, range4) {
321416
321481
  let tr = state.tr, end6 = range4.end, endOfList = range4.$to.end(range4.depth);
321417
321482
  if (end6 < endOfList) {
321418
321483
  tr.step(new ReplaceAroundStep(end6 - 1, endOfList, end6, endOfList, new Slice(Fragment.from(itemType.create(null, range4.parent.copy())), 1, 0), 1, true));
@@ -321425,10 +321490,10 @@ function liftToOuterList(state, dispatch, itemType, range4) {
321425
321490
  let after3 = tr.mapping.map(end6, -1) - 1;
321426
321491
  if (canJoin(tr.doc, after3))
321427
321492
  tr.join(after3);
321428
- dispatch(tr.scrollIntoView());
321493
+ dispatch2(tr.scrollIntoView());
321429
321494
  return true;
321430
321495
  }
321431
- function liftOutOfList(state, dispatch, range4) {
321496
+ function liftOutOfList(state, dispatch2, range4) {
321432
321497
  let tr = state.tr, list4 = range4.parent;
321433
321498
  for (let pos = range4.end, i2 = range4.endIndex - 1, e3 = range4.startIndex; i2 > e3; i2--) {
321434
321499
  pos -= list4.child(i2).nodeSize;
@@ -321443,11 +321508,11 @@ function liftOutOfList(state, dispatch, range4) {
321443
321508
  return false;
321444
321509
  let start4 = $start.pos, end6 = start4 + item.nodeSize;
321445
321510
  tr.step(new ReplaceAroundStep(start4 - (atStart ? 1 : 0), end6 + (atEnd ? 1 : 0), start4 + 1, end6 - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list4.copy(Fragment.empty))).append(atEnd ? Fragment.empty : Fragment.from(list4.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
321446
- dispatch(tr.scrollIntoView());
321511
+ dispatch2(tr.scrollIntoView());
321447
321512
  return true;
321448
321513
  }
321449
321514
  function sinkListItem(itemType) {
321450
- return function(state, dispatch) {
321515
+ return function(state, dispatch2) {
321451
321516
  let { $from, $to } = state.selection;
321452
321517
  let range4 = $from.blockRange($to, (node) => node.childCount > 0 && node.firstChild.type == itemType);
321453
321518
  if (!range4)
@@ -321458,12 +321523,12 @@ function sinkListItem(itemType) {
321458
321523
  let parent = range4.parent, nodeBefore = parent.child(startIndex - 1);
321459
321524
  if (nodeBefore.type != itemType)
321460
321525
  return false;
321461
- if (dispatch) {
321526
+ if (dispatch2) {
321462
321527
  let nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type == parent.type;
321463
321528
  let inner = Fragment.from(nestedBefore ? itemType.create() : null);
321464
321529
  let slice = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
321465
321530
  let before2 = range4.start, after3 = range4.end;
321466
- dispatch(state.tr.step(new ReplaceAroundStep(before2 - (nestedBefore ? 3 : 1), after3, before2, after3, slice, 1, true)).scrollIntoView());
321531
+ dispatch2(state.tr.step(new ReplaceAroundStep(before2 - (nestedBefore ? 3 : 1), after3, before2, after3, slice, 1, true)).scrollIntoView());
321467
321532
  }
321468
321533
  return true;
321469
321534
  };
@@ -321539,140 +321604,219 @@ function getDependencySupportingFiles() {
321539
321604
  }
321540
321605
  var decoder2 = new TextDecoder();
321541
321606
  var fetchDependency = async function fetchDependency2(moduleRef, onProgress) {
321542
- if (depRegistry[moduleRef]) {
321543
- return await depRegistry[moduleRef];
321544
- }
321545
- depRegistry[moduleRef] = async function resolveDep() {
321546
- let sourceDir;
321547
- const localPath = moduleRef.split("file:")[1];
321548
- if (!localPath) {
321549
- onProgress({ state: `fetching ${moduleRef} to ${localPath}` });
321550
- sourceDir = await fetchSourceFromGit(moduleRef, onProgress);
321551
- } else {
321552
- sourceDir = localPath;
321553
- }
321554
- const buildDir = await mkdtemp2(join7(
321555
- tmpRoot,
321556
- `anafero-dist-${moduleRef.replace(/[^a-z0-9]/gi, "_")}-`
321557
- ));
321558
- onProgress({ state: `copying into build dir ${buildDir}` });
321559
- await cp2(sourceDir, buildDir, { recursive: true });
321560
- onProgress({ state: "compiling" });
321561
- const result = await esbuild({
321562
- //entryPoints: [join(buildDir, 'index.mts')],
321563
- stdin: {
321564
- contents: await readFile3(join7(buildDir, "index.mts")),
321565
- loader: "ts",
321566
- // TODO: This means we use filesystem when resolving
321567
- // imports in the entry point. That’s not great, if we
321568
- // want to build e.g. in the browser.
321569
- // It may be possible to avoid this by writing a custom
321570
- // resolver plugin for esbuild. See
321571
- // - https://github.com/evanw/esbuild/issues/591#issuecomment-742962090
321572
- // - https://esbuild.github.io/plugins/#on-resolve-arguments
321573
- resolveDir: buildDir,
321574
- sourcefile: "index.mts"
321575
- },
321576
- loader: {
321577
- ".mts": "ts",
321578
- ".css": "local-css"
321579
- },
321580
- entryNames: "[dir]/[name]",
321581
- assetNames: "[dir]/[name]",
321582
- format: "esm",
321583
- target: ["es2022"],
321584
- tsconfigRaw: "{}",
321585
- //external: [],
321586
- packages: "external",
321587
- //plugins: [{
321588
- // name: 'plugin-resolver',
321589
- // setup(build) {
321590
- // build.onLoad({ filter: /^prosemirror-model-metanorma/ }, args => {
321591
- // return import(args.path);
321592
- // });
321593
- // },
321594
- //}],
321595
- minify: false,
321596
- platform: "browser",
321597
- write: false,
321598
- logLevel: "silent",
321599
- //logLevel: 'info',
321600
- sourcemap: true,
321601
- bundle: true,
321602
- outfile: "index.js",
321603
- treeShaking: true
321604
- //outfile,
321605
- });
321606
- const otherFiles = {};
321607
- const mainOutput = result.outputFiles.find(({ path: path3 }) => basename(path3) === "index.js")?.contents;
321608
- if (!mainOutput) {
321609
- throw new Error("Fetching dependency: no main output after building");
321610
- } else if (result.outputFiles.length > 1) {
321611
- for (const { path: path3, contents } of result.outputFiles) {
321612
- if (!path3.endsWith("/index.js")) {
321613
- otherFiles[basename(path3)] = contents;
321614
- }
321615
- }
321616
- }
321617
- const code2 = decoder2.decode(mainOutput);
321618
- onProgress({ state: "instantiating module" });
321619
- const context9 = vm.createContext({
321620
- Array,
321621
- Object,
321622
- crypto,
321623
- XPathResult,
321624
- document: getDoc(),
321625
- console,
321626
- Function,
321627
- setTimeout,
321628
- setInterval,
321629
- TextEncoder
321630
- });
321631
- const mod = new vm.SourceTextModule(code2, {
321632
- // TODO: Try moduleRef as VM module identifier?
321633
- // Take care of special characters, though.
321634
- identifier: "anafero-dependency",
321635
- context: context9
321636
- });
321637
- async function link4(specifier, referencingModule) {
321638
- if (specifier.startsWith("https://")) {
321639
- const url3 = new URL(
321640
- specifier,
321641
- referencingModule.identifier
321642
- ).toString();
321643
- const source = await (await fetch(url3)).text();
321644
- return new vm.SourceTextModule(source, {
321645
- identifier: url3,
321646
- context: referencingModule.context
321647
- });
321607
+ if (!depRegistry[moduleRef]) {
321608
+ depRegistry[moduleRef] = async function resolveDep() {
321609
+ let sourceDir;
321610
+ const localPath = moduleRef.split("file:")[1];
321611
+ if (!localPath) {
321612
+ onProgress({ state: `fetching ${moduleRef} to ${localPath}` });
321613
+ sourceDir = await fetchSourceFromGit(moduleRef, onProgress);
321648
321614
  } else {
321649
- const madeAvailable = preloaded[specifier] ? preloaded[specifier] : await import(specifier);
321650
- const exportNames = Object.keys(madeAvailable);
321651
- return new vm.SyntheticModule(
321652
- exportNames,
321653
- function() {
321654
- for (const name2 of exportNames) {
321655
- this.setExport(name2, madeAvailable[name2]);
321656
- }
321657
- },
321658
- {
321659
- identifier: specifier,
321615
+ sourceDir = localPath;
321616
+ }
321617
+ const [bundledCode, otherFiles] = await getDependencyAssets(
321618
+ moduleRef,
321619
+ sourceDir,
321620
+ onProgress
321621
+ );
321622
+ const code2 = decoder2.decode(bundledCode);
321623
+ onProgress({ state: "instantiating module" });
321624
+ const context9 = vm.createContext({
321625
+ Array,
321626
+ Object,
321627
+ crypto,
321628
+ XPathResult,
321629
+ document: getDoc(),
321630
+ console,
321631
+ Function,
321632
+ setTimeout,
321633
+ clearTimeout,
321634
+ setInterval,
321635
+ TextEncoder,
321636
+ TextDecoder,
321637
+ Blob,
321638
+ btoa,
321639
+ atob
321640
+ });
321641
+ const mod = new vm.SourceTextModule(code2, {
321642
+ // TODO: Try moduleRef as VM module identifier?
321643
+ // Take care of special characters, though.
321644
+ identifier: "anafero-dependency",
321645
+ context: context9
321646
+ });
321647
+ async function link4(specifier, referencingModule) {
321648
+ const isAbsoluteURL = specifier.startsWith("https://");
321649
+ let base2;
321650
+ try {
321651
+ new URL(referencingModule.identifier);
321652
+ base2 = referencingModule.identifier;
321653
+ } catch (e3) {
321654
+ base2 = void 0;
321655
+ }
321656
+ const isRelativePath = specifier.startsWith("/") || specifier.startsWith("./") || specifier.startsWith("../");
321657
+ const isRelativeURL = isRelativePath && base2 !== void 0;
321658
+ if (isAbsoluteURL || isRelativeURL) {
321659
+ if (isRelativeURL && base2 === void 0) {
321660
+ throw new Error("Unable to resolve relative specifier without a base");
321661
+ }
321662
+ const url3 = new URL(specifier, base2).toString();
321663
+ const source = await (await fetch(url3)).text();
321664
+ return new vm.SourceTextModule(source, {
321665
+ identifier: url3,
321660
321666
  context: referencingModule.context
321661
- }
321662
- );
321667
+ });
321668
+ } else {
321669
+ const madeAvailable = preloaded[specifier] ? preloaded[specifier] : await import(specifier);
321670
+ const exportNames = Object.keys(madeAvailable);
321671
+ return new vm.SyntheticModule(
321672
+ exportNames,
321673
+ function() {
321674
+ for (const name2 of exportNames) {
321675
+ this.setExport(name2, madeAvailable[name2]);
321676
+ }
321677
+ },
321678
+ {
321679
+ identifier: specifier,
321680
+ context: referencingModule.context
321681
+ }
321682
+ );
321683
+ }
321663
321684
  }
321664
- }
321665
- await mod.link(link4);
321666
- await mod.evaluate();
321667
- const defaultExport = mod.namespace.default;
321668
- onProgress({ state: `removing build dir ${buildDir}` });
321669
- await rmdir(buildDir, { recursive: true });
321670
- dependencySources[moduleRef] = code2;
321671
- dependencySupportingFiles[moduleRef] = otherFiles;
321672
- return defaultExport;
321673
- }();
321685
+ await mod.link(link4);
321686
+ await mod.evaluate();
321687
+ const defaultExport = mod.namespace.default;
321688
+ dependencySources[moduleRef] = code2;
321689
+ dependencySupportingFiles[moduleRef] = otherFiles;
321690
+ return defaultExport;
321691
+ }();
321692
+ }
321674
321693
  return await depRegistry[moduleRef];
321675
321694
  };
321695
+ async function getDependencyAssets(moduleRef, sourceDirPath, onProgress) {
321696
+ if (await isPreBuilt(sourceDirPath)) {
321697
+ console.debug("Using pre-built", moduleRef);
321698
+ return await readPreBuiltDependency(sourceDirPath);
321699
+ } else {
321700
+ return await buildDependency(moduleRef, sourceDirPath, onProgress);
321701
+ }
321702
+ }
321703
+ function getPreBuiltRoot(sourceDirPath) {
321704
+ return join7(sourceDirPath, "dist");
321705
+ }
321706
+ async function readPreBuiltJSBundle(sourceDirPath) {
321707
+ const bundlePath = join7(
321708
+ getPreBuiltRoot(sourceDirPath),
321709
+ PRE_BUILT_JS_BUNDLE_FILENAME
321710
+ );
321711
+ const bundleStat = await stat4(bundlePath);
321712
+ if (bundleStat.isFile()) {
321713
+ return await readFile3(bundlePath);
321714
+ } else {
321715
+ throw new Error("Pre-built entry point is not a file");
321716
+ }
321717
+ }
321718
+ var PRE_BUILT_JS_BUNDLE_FILENAME = "index.js";
321719
+ async function readPreBuiltAssets(sourceDirPath) {
321720
+ const distroot = getPreBuiltRoot(sourceDirPath);
321721
+ const filenames = await readdir(distroot);
321722
+ const assets = filenames.filter((fn3) => fn3 !== PRE_BUILT_JS_BUNDLE_FILENAME);
321723
+ return (await Promise.all(
321724
+ assets.map(async (fn3) => ({ [fn3]: await readFile3(join7(distroot, fn3)) }))
321725
+ )).reduce((prev, curr) => ({ ...prev, ...curr }), {});
321726
+ }
321727
+ async function writePreBuiltAssets(sourceDirPath, bundledCode, assets) {
321728
+ const distDir = getPreBuiltRoot(sourceDirPath);
321729
+ await mkdir2(distDir);
321730
+ console.debug("Writing index.js");
321731
+ await writeFile3(join7(distDir, PRE_BUILT_JS_BUNDLE_FILENAME), bundledCode);
321732
+ for (const [fn3, blob] of Object.entries(assets)) {
321733
+ console.debug("Writing asset", fn3);
321734
+ await writeFile3(join7(distDir, fn3), blob);
321735
+ }
321736
+ }
321737
+ async function isPreBuilt(sourceDirPath) {
321738
+ try {
321739
+ await readPreBuiltJSBundle(sourceDirPath);
321740
+ await readPreBuiltAssets(sourceDirPath);
321741
+ return true;
321742
+ } catch (e3) {
321743
+ return false;
321744
+ }
321745
+ }
321746
+ async function readPreBuiltDependency(sourceDirPath) {
321747
+ return [
321748
+ await readPreBuiltJSBundle(sourceDirPath),
321749
+ await readPreBuiltAssets(sourceDirPath)
321750
+ ];
321751
+ }
321752
+ async function buildDependency(moduleRef, sourceDir, onProgress) {
321753
+ const buildDir = await mkdtemp2(join7(
321754
+ tmpRoot,
321755
+ `anafero-dist-${moduleRef.replace(/[^a-z0-9]/gi, "_")}-`
321756
+ ));
321757
+ onProgress({ state: `copying into build dir ${buildDir}` });
321758
+ await cp2(sourceDir, buildDir, { recursive: true });
321759
+ onProgress({ state: "compiling" });
321760
+ const result = await esbuild({
321761
+ //entryPoints: [join(buildDir, 'index.mts')],
321762
+ stdin: {
321763
+ contents: await readFile3(join7(buildDir, "index.mts")),
321764
+ loader: "ts",
321765
+ // TODO: This means we use filesystem when resolving
321766
+ // imports in the entry point. That’s not great, if we
321767
+ // want to build e.g. in the browser.
321768
+ // It may be possible to avoid this by writing a custom
321769
+ // resolver plugin for esbuild. See
321770
+ // - https://github.com/evanw/esbuild/issues/591#issuecomment-742962090
321771
+ // - https://esbuild.github.io/plugins/#on-resolve-arguments
321772
+ resolveDir: buildDir,
321773
+ sourcefile: "index.mts"
321774
+ },
321775
+ loader: {
321776
+ ".mts": "ts",
321777
+ ".css": "local-css"
321778
+ },
321779
+ entryNames: "[dir]/[name]",
321780
+ assetNames: "[dir]/[name]",
321781
+ format: "esm",
321782
+ target: ["es2022"],
321783
+ tsconfigRaw: "{}",
321784
+ //external: [],
321785
+ packages: "external",
321786
+ //plugins: [{
321787
+ // name: 'plugin-resolver',
321788
+ // setup(build) {
321789
+ // build.onLoad({ filter: /^prosemirror-model-metanorma/ }, args => {
321790
+ // return import(args.path);
321791
+ // });
321792
+ // },
321793
+ //}],
321794
+ minify: false,
321795
+ platform: "browser",
321796
+ write: false,
321797
+ logLevel: "silent",
321798
+ //logLevel: 'info',
321799
+ sourcemap: true,
321800
+ bundle: true,
321801
+ outfile: "index.js",
321802
+ treeShaking: true
321803
+ //outfile,
321804
+ });
321805
+ onProgress({ state: `removing build dir ${buildDir}` });
321806
+ await rmdir(buildDir, { recursive: true });
321807
+ const otherFiles = {};
321808
+ const mainOutput = result.outputFiles.find(({ path: path3 }) => basename(path3) === "index.js")?.contents;
321809
+ if (!mainOutput) {
321810
+ throw new Error("Fetching dependency: no main output after building");
321811
+ } else if (result.outputFiles.length > 1) {
321812
+ for (const { path: path3, contents } of result.outputFiles) {
321813
+ if (!path3.endsWith("/index.js")) {
321814
+ otherFiles[basename(path3)] = contents;
321815
+ }
321816
+ }
321817
+ }
321818
+ return [mainOutput, otherFiles];
321819
+ }
321676
321820
 
321677
321821
  // util.mts
321678
321822
  init_cjs_shim();
@@ -321701,6 +321845,8 @@ global.window = { location: { host: "" } };
321701
321845
  var PACKAGE_ROOT = resolve3(join8(import.meta.url.split("file://")[1], ".."));
321702
321846
  console.debug("Package root", PACKAGE_ROOT);
321703
321847
  var decoder3 = new TextDecoder();
321848
+ var cwd2 = process.cwd();
321849
+ console.debug("Current working directory", cwd2);
321704
321850
  Effect_exports.suspend(() => main(process.argv)).pipe(
321705
321851
  Effect_exports.provide(NodeContext_exports.layer),
321706
321852
  NodeRuntime_exports.runMain
@@ -321708,8 +321854,38 @@ Effect_exports.suspend(() => main(process.argv)).pipe(
321708
321854
  function unpackOption(opt, df) {
321709
321855
  return Option_exports.isNone(opt) ? df : opt.value;
321710
321856
  }
321711
- var build2 = Command_exports2.make(
321712
- "build",
321857
+ var dispatch = Command_exports2.make(
321858
+ "npx --node-options='--experimental-vm-modules' -y @riboseinc/anafero-cli",
321859
+ {},
321860
+ () => Effect_exports.log("Pass --help for usage instructions")
321861
+ ).pipe(
321862
+ Command_exports2.withDescription("Anafero builder. Use with a subcommand.")
321863
+ );
321864
+ var buildPackage = Command_exports2.make("build-package", reportingOptions, () => Effect_exports.gen(function* (_) {
321865
+ const moduleRef = yield* _(
321866
+ Effect_exports.tryPromise(() => readFile4(join8(cwd2, "package.json"))),
321867
+ Effect_exports.flatMap((blob) => Effect_exports.try(() => decoder3.decode(blob))),
321868
+ Effect_exports.flatMap((pkgRaw) => Effect_exports.try(() => JSON.parse(pkgRaw))),
321869
+ Effect_exports.flatMap((pkg) => Effect_exports.succeed(pkg["name"]))
321870
+ );
321871
+ yield* _(Effect_exports.log(`Building package ${moduleRef}`));
321872
+ const [bundledCode, assets] = yield* _(Effect_exports.tryPromise(() => {
321873
+ return buildDependency(
321874
+ moduleRef,
321875
+ cwd2,
321876
+ (progress) => console.debug(JSON.stringify(progress))
321877
+ );
321878
+ }));
321879
+ yield* _(Effect_exports.tryPromise(() => writePreBuiltAssets(
321880
+ cwd2,
321881
+ bundledCode,
321882
+ assets
321883
+ )));
321884
+ })).pipe(
321885
+ Command_exports2.withDescription("For developers: builds adapter in current directory into `./dist`.")
321886
+ );
321887
+ var buildSite = Command_exports2.make(
321888
+ "build-site",
321713
321889
  {
321714
321890
  targetDirectoryPath: Options_exports.directory("target-dir"),
321715
321891
  pathPrefix: Options_exports.directory("path-prefix").pipe(Options_exports.optional),
@@ -321797,9 +321973,9 @@ var build2 = Command_exports2.make(
321797
321973
  ))
321798
321974
  )
321799
321975
  ).pipe(
321800
- Command_exports2.withDescription("build site")
321976
+ Command_exports2.withDescription("Builds a website using current directory as source.")
321801
321977
  );
321802
- var dev = Command_exports2.make(
321978
+ var devSite = Command_exports2.make(
321803
321979
  "develop",
321804
321980
  {
321805
321981
  pkg: Options_exports.directory("package").pipe(Options_exports.optional),
@@ -321812,10 +321988,10 @@ var dev = Command_exports2.make(
321812
321988
  // Options.withDefault(8080)),
321813
321989
  },
321814
321990
  ({ pkg, skipBuild }) => Effect_exports.gen(function* (_) {
321815
- const buildCfg = yield* _(build2);
321991
+ const buildCfg = yield* _(buildSite);
321816
321992
  const { targetDirectoryPath } = buildCfg;
321817
321993
  if (!skipBuild) {
321818
- yield* build2.handler(buildCfg);
321994
+ yield* buildSite.handler(buildCfg);
321819
321995
  }
321820
321996
  const packageDir = unpackOption(pkg);
321821
321997
  if (packageDir) {
@@ -321841,16 +322017,19 @@ var dev = Command_exports2.make(
321841
322017
  }
321842
322018
  })
321843
322019
  ).pipe(
321844
- Command_exports2.withDescription("dev mode (watching for changes & copying client-side JS)")
322020
+ Command_exports2.withDescription("Build site in dev mode (watching for changes & copying client-side JS).")
321845
322021
  );
321846
- var main = build2.pipe(
321847
- Command_exports2.withSubcommands([dev]),
322022
+ var main = dispatch.pipe(
322023
+ Command_exports2.withSubcommands([
322024
+ buildSite.pipe(Command_exports2.withSubcommands([devSite])),
322025
+ buildPackage
322026
+ ]),
321848
322027
  Command_exports2.run({
321849
322028
  name: "Anafero builder",
321850
322029
  version: "N/A"
321851
322030
  })
321852
322031
  );
321853
- var gitdir = join8(process.cwd(), ".git");
322032
+ var gitdir = join8(cwd2, ".git");
321854
322033
  async function areWeInGitRepoRoot() {
321855
322034
  const gitRepoStat = await stat5(gitdir);
321856
322035
  if (gitRepoStat.isDirectory()) {
@@ -322012,8 +322191,8 @@ async function* generateSite(revisionsToBuild, onProgress, cache3, opts) {
322012
322191
  async function writeBlobs(root, blobs) {
322013
322192
  await Promise.all(Object.entries(blobs).map(async ([filePath, fileBlob]) => {
322014
322193
  const fullPath = join8(root, filePath);
322015
- await mkdir2(dirname2(fullPath), { recursive: true });
322016
- await writeFile3(join8(root, filePath), fileBlob);
322194
+ await mkdir3(dirname2(fullPath), { recursive: true });
322195
+ await writeFile4(join8(root, filePath), fileBlob);
322017
322196
  }));
322018
322197
  }
322019
322198
  var copyBootstrapScript = (packagePath, outdir) => Effect_exports.gen(function* (_) {