@lichess-org/pgn-viewer 2.5.2 → 2.5.3

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.
@@ -917,8 +917,8 @@ var Position = class {
917
917
  return this.board[color].size() <= 2 && this.board[opposite(color)].diff(this.board.king).diff(this.board.queen).isEmpty();
918
918
  }
919
919
  if (this.board[color].intersects(this.board.bishop)) {
920
- const sameColor = !this.board.bishop.intersects(SquareSet.darkSquares()) || !this.board.bishop.intersects(SquareSet.lightSquares());
921
- return sameColor && this.board.pawn.isEmpty() && this.board.knight.isEmpty();
920
+ const sameColor2 = !this.board.bishop.intersects(SquareSet.darkSquares()) || !this.board.bishop.intersects(SquareSet.lightSquares());
921
+ return sameColor2 && this.board.pawn.isEmpty() && this.board.knight.isEmpty();
922
922
  }
923
923
  return true;
924
924
  }
@@ -2698,12 +2698,12 @@ var defaultTranslations = {
2698
2698
  "san.shortCastling": "short castling"
2699
2699
  };
2700
2700
 
2701
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/types.js
2701
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/types.js
2702
2702
  var colors = ["white", "black"];
2703
2703
  var files = ["a", "b", "c", "d", "e", "f", "g", "h"];
2704
2704
  var ranks = ["1", "2", "3", "4", "5", "6", "7", "8"];
2705
2705
 
2706
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/util.js
2706
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/util.js
2707
2707
  var invRanks = [...ranks].reverse();
2708
2708
  var allKeys = files.flatMap((f) => ranks.map((r) => f + r));
2709
2709
  var pos2key = (pos) => pos.every((x) => x >= 0 && x <= 7) ? allKeys[8 * pos[0] + pos[1]] : void 0;
@@ -2772,7 +2772,8 @@ var eventPosition = (e) => {
2772
2772
  return [e.targetTouches[0].clientX, e.targetTouches[0].clientY];
2773
2773
  return;
2774
2774
  };
2775
- var isRightButton = (e) => e.button === 2;
2775
+ var isFireMac = memo(() => !("ontouchstart" in window) && ["macintosh", "firefox"].every((x) => navigator.userAgent.toLowerCase().includes(x)));
2776
+ var isRightButton = (e) => e.button === 2 && !(e.ctrlKey && isFireMac());
2776
2777
  var createEl = (tagName2, className) => {
2777
2778
  const el = document.createElement(tagName2);
2778
2779
  if (className)
@@ -3082,7 +3083,7 @@ var PgnViewer = class {
3082
3083
  }
3083
3084
  };
3084
3085
 
3085
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/premove.js
3086
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/premove.js
3086
3087
  var isDestOccupiedByFriendly = (ctx) => ctx.friendlies.has(ctx.dest.key);
3087
3088
  var isDestOccupiedByEnemy = (ctx) => ctx.enemies.has(ctx.dest.key);
3088
3089
  var anyPieceBetween = (orig, dest, pieces) => squaresBetween(...orig, ...dest).some((s) => pieces.has(s));
@@ -3200,7 +3201,7 @@ function premove(state, key) {
3200
3201
  return allPosAndKey.filter((dest) => mobility({ ...partialCtx, dest })).map((pk) => pk.key);
3201
3202
  }
3202
3203
 
3203
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/board.js
3204
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/board.js
3204
3205
  function callUserFunction(f, ...args) {
3205
3206
  if (f)
3206
3207
  setTimeout(() => f(...args), 1);
@@ -3489,7 +3490,7 @@ function getSnappedKeyAtDomPos(orig, pos, asWhite, bounds) {
3489
3490
  }
3490
3491
  var whitePov = (s) => s.orientation === "white";
3491
3492
 
3492
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/fen.js
3493
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/fen.js
3493
3494
  var initial = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR";
3494
3495
  var roles = {
3495
3496
  p: "pawn",
@@ -3564,7 +3565,7 @@ function write(pieces) {
3564
3565
  }).join("")).join("/").replace(/1{2,}/g, (s) => s.length.toString());
3565
3566
  }
3566
3567
 
3567
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/config.js
3568
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/config.js
3568
3569
  function applyAnimation(state, config) {
3569
3570
  if (config.animation) {
3570
3571
  deepMerge(state.animation, config.animation);
@@ -3615,7 +3616,7 @@ function isPlainObject(o) {
3615
3616
  return proto === Object.prototype || proto === null;
3616
3617
  }
3617
3618
 
3618
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/anim.js
3619
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/anim.js
3619
3620
  var anim = (mutation, state) => state.animation.enabled ? animate(mutation, state) : render(mutation, state);
3620
3621
  function render(mutation, state) {
3621
3622
  const result = mutation(state);
@@ -3706,7 +3707,7 @@ function animate(mutation, state) {
3706
3707
  }
3707
3708
  var easing = (t) => t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
3708
3709
 
3709
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/draw.js
3710
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/draw.js
3710
3711
  var brushes = ["green", "red", "blue", "yellow"];
3711
3712
  function start(state, e) {
3712
3713
  if (e.touches && e.touches.length > 1)
@@ -3768,17 +3769,18 @@ function clear(state) {
3768
3769
  onChange(state.drawable);
3769
3770
  }
3770
3771
  }
3772
+ var sameEndpoints = (s1, s2) => s1.orig === s2.orig && s1.dest === s2.dest;
3773
+ var sameColor = (s1, s2) => s1.brush === s2.brush;
3771
3774
  function eventBrush(e) {
3772
3775
  const modA = (e.shiftKey || e.ctrlKey) && isRightButton(e);
3773
3776
  const modB = e.altKey || e.metaKey || e.getModifierState?.("AltGraph");
3774
3777
  return brushes[(modA ? 1 : 0) + (modB ? 2 : 0)];
3775
3778
  }
3776
3779
  function addShape(drawable, cur) {
3777
- const sameShape = (s) => s.orig === cur.orig && s.dest === cur.dest;
3778
- const similar = drawable.shapes.find(sameShape);
3780
+ const similar = drawable.shapes.find((s) => sameEndpoints(s, cur));
3779
3781
  if (similar)
3780
- drawable.shapes = drawable.shapes.filter((s) => !sameShape(s));
3781
- if (!similar || similar.brush !== cur.brush)
3782
+ drawable.shapes = drawable.shapes.filter((s) => !sameEndpoints(s, cur));
3783
+ if (!similar || !sameColor(similar, cur))
3782
3784
  drawable.shapes.push({
3783
3785
  orig: cur.orig,
3784
3786
  dest: cur.dest,
@@ -3791,7 +3793,7 @@ function onChange(drawable) {
3791
3793
  drawable.onChange(drawable.shapes);
3792
3794
  }
3793
3795
 
3794
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/drag.js
3796
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/drag.js
3795
3797
  function start2(s, e) {
3796
3798
  if (!(s.trustAllEvents || e.isTrusted))
3797
3799
  return;
@@ -3805,7 +3807,7 @@ function start2(s, e) {
3805
3807
  const piece = s.pieces.get(orig);
3806
3808
  const previouslySelected = s.selected;
3807
3809
  if (!previouslySelected && s.drawable.enabled && (s.drawable.eraseOnMovablePieceClick || !piece || piece.color !== s.turnColor))
3808
- s.pixelCoordsOfMouchDownToMaybeClearShapes = position;
3810
+ clear(s);
3809
3811
  if (e.cancelable !== false && (!e.touches || s.blockTouchScroll || piece || previouslySelected || pieceCloseTo(s, position)))
3810
3812
  e.preventDefault();
3811
3813
  else if (e.touches)
@@ -3916,10 +3918,6 @@ function move2(s, e) {
3916
3918
  }
3917
3919
  }
3918
3920
  function end2(s, e) {
3919
- const position = eventPosition(e);
3920
- if (position && s.pixelCoordsOfMouchDownToMaybeClearShapes && samePos(position, s.pixelCoordsOfMouchDownToMaybeClearShapes))
3921
- clear(s);
3922
- s.pixelCoordsOfMouchDownToMaybeClearShapes = void 0;
3923
3921
  const cur = s.draggable.current;
3924
3922
  if (!cur)
3925
3923
  return;
@@ -3981,7 +3979,7 @@ function pieceElementByKey(s, key) {
3981
3979
  return;
3982
3980
  }
3983
3981
 
3984
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/explosion.js
3982
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/explosion.js
3985
3983
  function explosion(state, keys) {
3986
3984
  state.exploding = { stage: 1, keys };
3987
3985
  state.dom.redraw();
@@ -4000,7 +3998,7 @@ function setStage(state, stage) {
4000
3998
  }
4001
3999
  }
4002
4000
 
4003
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/api.js
4001
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/api.js
4004
4002
  function start3(state, redrawAll) {
4005
4003
  function toggleOrientation2() {
4006
4004
  toggleOrientation(state);
@@ -4091,7 +4089,7 @@ function start3(state, redrawAll) {
4091
4089
  };
4092
4090
  }
4093
4091
 
4094
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/state.js
4092
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/state.js
4095
4093
  function defaults() {
4096
4094
  return {
4097
4095
  pieces: read(initial),
@@ -4187,7 +4185,7 @@ function defaults() {
4187
4185
  };
4188
4186
  }
4189
4187
 
4190
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/svg.js
4188
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/svg.js
4191
4189
  function createDefs() {
4192
4190
  const defs = createElement("defs");
4193
4191
  const filter = setAttributes(createElement("filter"), { id: "cg-filter-blur" });
@@ -4205,18 +4203,22 @@ function renderSvg(state, els) {
4205
4203
  dests.set(s.dest, sources);
4206
4204
  }
4207
4205
  const shapes = [];
4208
- for (const s of d.shapes.concat(nonPieceAutoShapes)) {
4206
+ const pendingEraseIdx = cur ? d.shapes.findIndex((s) => sameEndpoints(s, cur) && sameColor(s, cur)) : -1;
4207
+ for (const [idx, s] of d.shapes.concat(nonPieceAutoShapes).entries()) {
4208
+ const isPendingErase = pendingEraseIdx !== -1 && pendingEraseIdx === idx;
4209
4209
  shapes.push({
4210
4210
  shape: s,
4211
4211
  current: false,
4212
- hash: shapeHash(s, isShort(s.dest, dests), false, bounds)
4212
+ pendingErase: isPendingErase,
4213
+ hash: shapeHash(s, isShort(s.dest, dests), false, bounds, isPendingErase)
4213
4214
  });
4214
4215
  }
4215
- if (cur)
4216
+ if (cur && pendingEraseIdx === -1)
4216
4217
  shapes.push({
4217
4218
  shape: cur,
4218
4219
  current: true,
4219
- hash: shapeHash(cur, isShort(cur.dest, dests), true, bounds)
4220
+ hash: shapeHash(cur, isShort(cur.dest, dests), true, bounds, false),
4221
+ pendingErase: false
4220
4222
  });
4221
4223
  const fullHash = shapes.map((sc) => sc.hash).join(";");
4222
4224
  if (fullHash === state.drawable.prevSvgHash)
@@ -4283,11 +4285,12 @@ function syncShapes(shapes, els, renderShape3) {
4283
4285
  }
4284
4286
  }
4285
4287
  }
4286
- function shapeHash({ orig, dest, brush, piece, modifiers, customSvg, label, below }, shorten, current, bounds) {
4288
+ function shapeHash({ orig, dest, brush, piece, modifiers, customSvg, label, below }, shorten, current, bounds, pendingErase) {
4287
4289
  return [
4288
4290
  bounds.width,
4289
4291
  bounds.height,
4290
4292
  current,
4293
+ pendingErase && "pendingErase",
4291
4294
  orig,
4292
4295
  dest,
4293
4296
  brush,
@@ -4312,15 +4315,15 @@ function textHash(s) {
4312
4315
  }
4313
4316
  return h2.toString();
4314
4317
  }
4315
- function renderShape(state, { shape, current, hash: hash2 }, brushes2, dests, bounds) {
4318
+ function renderShape(state, { shape, current, pendingErase, hash: hash2 }, brushes2, dests, bounds) {
4316
4319
  const from = pos2user(orient(key2pos(shape.orig), state.orientation), bounds), to = shape.dest ? pos2user(orient(key2pos(shape.dest), state.orientation), bounds) : from, brush = shape.brush && makeCustomBrush(brushes2[shape.brush], shape.modifiers), slots = dests.get(shape.dest), svgs = [];
4317
4320
  if (brush) {
4318
4321
  const el = setAttributes(createElement("g"), { cgHash: hash2 });
4319
4322
  svgs.push({ el });
4320
4323
  if (from[0] !== to[0] || from[1] !== to[1])
4321
- el.appendChild(renderArrow(shape, brush, from, to, current, isShort(shape.dest, dests)));
4324
+ el.appendChild(renderArrow(shape, brush, from, to, current, isShort(shape.dest, dests), pendingErase));
4322
4325
  else
4323
- el.appendChild(renderCircle(brushes2[shape.brush], from, current, bounds));
4326
+ el.appendChild(renderCircle(brushes2[shape.brush], from, current, bounds, pendingErase));
4324
4327
  }
4325
4328
  if (shape.label) {
4326
4329
  const label = shape.label;
@@ -4337,19 +4340,19 @@ function renderShape(state, { shape, current, hash: hash2 }, brushes2, dests, bo
4337
4340
  }
4338
4341
  return svgs;
4339
4342
  }
4340
- function renderCircle(brush, at, current, bounds) {
4343
+ function renderCircle(brush, at, current, bounds, pendingErase) {
4341
4344
  const widths = circleWidth(), radius = (bounds.width + bounds.height) / (4 * Math.max(bounds.width, bounds.height));
4342
4345
  return setAttributes(createElement("circle"), {
4343
4346
  stroke: brush.color,
4344
4347
  "stroke-width": widths[current ? 0 : 1],
4345
4348
  fill: "none",
4346
- opacity: opacity(brush, current),
4349
+ opacity: opacity(brush, current, pendingErase),
4347
4350
  cx: at[0],
4348
4351
  cy: at[1],
4349
4352
  r: radius - widths[1] / 2
4350
4353
  });
4351
4354
  }
4352
- function renderArrow(s, brush, from, to, current, shorten) {
4355
+ function renderArrow(s, brush, from, to, current, shorten, pendingErase) {
4353
4356
  function renderLine(isHilite) {
4354
4357
  const m = arrowMargin(shorten && !current), dx = to[0] - from[0], dy = to[1] - from[1], angle = Math.atan2(dy, dx), xo = Math.cos(angle) * m, yo = Math.sin(angle) * m;
4355
4358
  const hilite = hiliteOf(s);
@@ -4358,7 +4361,7 @@ function renderArrow(s, brush, from, to, current, shorten) {
4358
4361
  "stroke-width": lineWidth(brush, current) * (isHilite ? 1.14 : 1),
4359
4362
  "stroke-linecap": "round",
4360
4363
  "marker-end": `url(#arrowhead-${isHilite ? hilite.key : brush.key})`,
4361
- opacity: s.modifiers?.hilite ? 1 : opacity(brush, current),
4364
+ opacity: s.modifiers?.hilite && !pendingErase ? 1 : opacity(brush, current, pendingErase),
4362
4365
  x1: from[0],
4363
4366
  y1: from[1],
4364
4367
  x2: to[0] - xo,
@@ -4450,8 +4453,8 @@ function hiliteOf(shape) {
4450
4453
  const hilite = shape.modifiers?.hilite;
4451
4454
  return { key: hilite && `hilite-${hilite.replace("#", "")}`, color: hilite };
4452
4455
  }
4453
- function opacity(brush, current) {
4454
- return (brush.opacity || 1) * (current ? 0.9 : 1);
4456
+ function opacity(brush, current, pendingErase) {
4457
+ return (brush.opacity || 1) * (pendingErase ? 0.6 : current ? 0.9 : 1);
4455
4458
  }
4456
4459
  function arrowMargin(shorten) {
4457
4460
  return (shorten ? 20 : 10) / 64;
@@ -4499,7 +4502,7 @@ function labelCoords(from, to, slots) {
4499
4502
  return [from[0] - Math.cos(angle) * mag, from[1] - Math.sin(angle) * mag].map((c) => c + 0.5);
4500
4503
  }
4501
4504
 
4502
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/wrap.js
4505
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/wrap.js
4503
4506
  function renderWrap(element, s) {
4504
4507
  element.innerHTML = "";
4505
4508
  element.classList.add("cg-wrap");
@@ -4566,7 +4569,7 @@ function renderCoords(elems, className) {
4566
4569
  return el;
4567
4570
  }
4568
4571
 
4569
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/drop.js
4572
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/drop.js
4570
4573
  function drop(s, e) {
4571
4574
  if (!s.dropmode.active)
4572
4575
  return;
@@ -4583,7 +4586,7 @@ function drop(s, e) {
4583
4586
  s.dom.redraw();
4584
4587
  }
4585
4588
 
4586
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/events.js
4589
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/events.js
4587
4590
  function bindBoard(s, onResize) {
4588
4591
  const boardEl = s.dom.elements.board;
4589
4592
  if ("ResizeObserver" in window)
@@ -4645,7 +4648,7 @@ var dragOrDraw = (s, withDrag, withDraw) => (e) => {
4645
4648
  withDrag(s, e);
4646
4649
  };
4647
4650
 
4648
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/render.js
4651
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/render.js
4649
4652
  function render2(s) {
4650
4653
  const asWhite = whitePov(s), posToTranslate2 = posToTranslate(s.dom.bounds()), boardEl = s.dom.elements.board, pieces = s.pieces, curAnim = s.animation.current, anims = curAnim ? curAnim.plan.anims : /* @__PURE__ */ new Map(), fadings = curAnim ? curAnim.plan.fadings : /* @__PURE__ */ new Map(), curDrag = s.draggable.current, squares = computeSquareClasses(s), samePieces = /* @__PURE__ */ new Set(), sameSquares = /* @__PURE__ */ new Set(), movedPieces = /* @__PURE__ */ new Map(), movedSquares = /* @__PURE__ */ new Map();
4651
4654
  let k, el, pieceAtKey, elPieceName, anim2, fading, pMvdset, pMvd, sMvdset, sMvd;
@@ -4850,7 +4853,7 @@ function appendValue(map, key, value) {
4850
4853
  map.set(key, [value]);
4851
4854
  }
4852
4855
 
4853
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/sync.js
4856
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/sync.js
4854
4857
  function syncShapes2(shapes, root, renderShape3) {
4855
4858
  const hashesInDom = /* @__PURE__ */ new Map(), toRemove = [];
4856
4859
  for (const sc of shapes)
@@ -4872,14 +4875,15 @@ function syncShapes2(shapes, root, renderShape3) {
4872
4875
  }
4873
4876
  }
4874
4877
 
4875
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/autoPieces.js
4878
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/autoPieces.js
4876
4879
  function render3(state, autoPieceEl) {
4877
4880
  const autoPieces = state.drawable.autoShapes.filter((autoShape) => autoShape.piece);
4878
4881
  const autoPieceShapes = autoPieces.map((s) => {
4879
4882
  return {
4880
4883
  shape: s,
4881
4884
  hash: hash(s),
4882
- current: false
4885
+ current: false,
4886
+ pendingErase: false
4883
4887
  };
4884
4888
  });
4885
4889
  syncShapes2(autoPieceShapes, autoPieceEl, (shape) => renderShape2(state, shape, state.dom.bounds()));
@@ -4906,7 +4910,7 @@ function renderShape2(state, { shape, hash: hash2 }, bounds) {
4906
4910
  }
4907
4911
  var hash = (autoPiece) => [autoPiece.orig, autoPiece.piece?.role, autoPiece.piece?.color, autoPiece.piece?.scale].join(",");
4908
4912
 
4909
- // node_modules/.pnpm/@lichess-org+chessground@9.8.2/node_modules/@lichess-org/chessground/dist/chessground.js
4913
+ // node_modules/.pnpm/@lichess-org+chessground@9.8.5/node_modules/@lichess-org/chessground/dist/chessground.js
4910
4914
  function Chessground(element, config) {
4911
4915
  const maybeState = defaults();
4912
4916
  configure(maybeState, config || {});