@singapore-editor/minimap 0.1.1 → 0.2.12

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.
Files changed (53) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +27 -10
  3. package/dist/assets/{minimap.worker-i4S59IOV.js → minimap.worker-C_eNmhCg.js} +114 -35
  4. package/dist/assets/minimap.worker-C_eNmhCg.js.map +1 -0
  5. package/dist/color.js +1 -2
  6. package/dist/decorationMerge.js +2 -3
  7. package/dist/decorationMerge.js.map +1 -1
  8. package/dist/documentSource.d.ts +42 -0
  9. package/dist/documentSource.d.ts.map +1 -0
  10. package/dist/documentSource.js +170 -0
  11. package/dist/documentSource.js.map +1 -0
  12. package/dist/index.d.ts +0 -1
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +1 -3
  15. package/dist/layout.js +0 -1
  16. package/dist/minimapCharRenderer.d.ts.map +1 -1
  17. package/dist/minimapCharRendererFactory.d.ts.map +1 -1
  18. package/dist/minimapCharSheet.d.ts.map +1 -1
  19. package/dist/minimapCharSheet.js +1 -2
  20. package/dist/options.js +1 -2
  21. package/dist/plugin.d.ts +1 -0
  22. package/dist/plugin.d.ts.map +1 -1
  23. package/dist/plugin.js +18 -5
  24. package/dist/plugin.js.map +1 -1
  25. package/dist/raster.d.ts.map +1 -1
  26. package/dist/renderer.d.ts +4 -1
  27. package/dist/renderer.d.ts.map +1 -1
  28. package/dist/sourceIdentity.d.ts +4 -0
  29. package/dist/sourceIdentity.d.ts.map +1 -0
  30. package/dist/sourceIdentity.js +10 -0
  31. package/dist/sourceIdentity.js.map +1 -0
  32. package/dist/sourceProtocol.d.ts +16 -0
  33. package/dist/sourceProtocol.d.ts.map +1 -0
  34. package/dist/style.css +1 -1
  35. package/dist/summary.d.ts +21 -0
  36. package/dist/summary.d.ts.map +1 -0
  37. package/dist/summary.js +174 -0
  38. package/dist/summary.js.map +1 -0
  39. package/dist/types.d.ts +27 -17
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js +1 -2
  42. package/dist/types.js.map +1 -1
  43. package/dist/viewportGeometry.js +1 -2
  44. package/dist/workerClient.d.ts +21 -50
  45. package/dist/workerClient.d.ts.map +1 -1
  46. package/dist/workerClient.js +175 -680
  47. package/dist/workerClient.js.map +1 -1
  48. package/dist/workerOwner.d.ts +34 -0
  49. package/dist/workerOwner.d.ts.map +1 -0
  50. package/dist/workerOwner.js +168 -0
  51. package/dist/workerOwner.js.map +1 -0
  52. package/package.json +26 -8
  53. package/dist/assets/minimap.worker-i4S59IOV.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaul Lavo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @singapore-editor/minimap
2
2
 
3
- Worker-backed minimap plugin for `@singapore-editor/core`.
3
+ A worker-rendered file overview with scroll controls for the Singapore editor.
4
+
5
+ Part of [Singapore](https://singapore.shaulavo.dev/). A code editor for the browser that keeps every version.
4
6
 
5
7
  ## Install
6
8
 
@@ -13,17 +15,32 @@ npm install @singapore-editor/core @singapore-editor/minimap
13
15
  ```ts
14
16
  import { Editor } from '@singapore-editor/core/editor'
15
17
  import { createMinimapPlugin } from '@singapore-editor/minimap'
16
- import '@singapore-editor/core/style.css'
17
- import '@singapore-editor/minimap/style.css'
18
18
 
19
- const editor = new Editor(document.querySelector('#editor')!, {
20
- plugins: [createMinimapPlugin()],
19
+ const host = document.createElement('div')
20
+ host.style.height = '400px'
21
+ document.body.append(host)
22
+
23
+ const editor = new Editor(host, {
24
+ plugins: [createMinimapPlugin({ side: 'right', showSlider: 'always' })],
21
25
  })
26
+ editor.setText('const value = 1\n')
22
27
  ```
23
28
 
24
- ## Exports
29
+ ## API highlights
30
+
31
+ - `createMinimapPlugin()` adds the overview.
32
+ - `side` chooses its edge.
33
+ - `showSlider` controls the viewport marker.
34
+
35
+ [Generated API reference](https://singapore.shaulavo.dev/docs/reference/api/minimap/overview/)
36
+
37
+ ## In the Singapore family
38
+
39
+ `@singapore-editor/core` owns the editor view. Add this plugin for a file overview beside the text.
40
+ Use a bundler that serves the package worker and data assets. See the [hosting guide](https://singapore.shaulavo.dev/docs/guides/bundling/).
41
+
42
+ [Singapore README](https://github.com/ShaulLavo/singapore/blob/main/README.md) · [Documentation](https://singapore.shaulavo.dev/docs/start-here/introduction/)
43
+
44
+ ## License
25
45
 
26
- - `createMinimapPlugin` adds the minimap view contribution.
27
- - `EditorMinimapOptions` configures side, size, autohide behavior, slider visibility, and section
28
- headers.
29
- - `@singapore-editor/minimap/style.css` contains the minimap stylesheet.
46
+ MIT. [License](https://github.com/ShaulLavo/singapore/blob/main/LICENSE)
@@ -1,4 +1,4 @@
1
- //#region ../editor/dist/logging/evlog.js
1
+ // ../editor/dist/logging/errors.js
2
2
  var evlogErrorInternalKey = Symbol.for("editor.evlog.error.internal");
3
3
  var EditorEvlogError = class extends Error {
4
4
  [evlogErrorInternalKey];
@@ -76,8 +76,7 @@ function evlogErrorLines(error) {
76
76
  if (error.cause instanceof Error) lines.push(`Caused by: ${error.cause.message}`);
77
77
  return lines;
78
78
  }
79
- //#endregion
80
- //#region src/color.ts
79
+ // src/color.ts
81
80
  const RGBA_EMPTY = {
82
81
  r: 0,
83
82
  g: 0,
@@ -157,8 +156,7 @@ function linearRgb(value) {
157
156
  if (value <= .04045) return value / 12.92;
158
157
  return ((value + .055) / 1.055) ** 2.4;
159
158
  }
160
- //#endregion
161
- //#region src/minimapCharSheet.ts
159
+ // src/minimapCharSheet.ts
162
160
  let Constants = /* @__PURE__ */ function(Constants) {
163
161
  Constants[Constants["START_CH_CODE"] = 32] = "START_CH_CODE";
164
162
  Constants[Constants["END_CH_CODE"] = 126] = "END_CH_CODE";
@@ -184,8 +182,7 @@ const getCharIndex = (chCode, fontScale) => {
184
182
  if (fontScale <= 2) return (index + 96) % 96;
185
183
  return 95;
186
184
  };
187
- //#endregion
188
- //#region src/types.ts
185
+ // src/types.ts
189
186
  let RenderMinimap = /* @__PURE__ */ function(RenderMinimap) {
190
187
  RenderMinimap[RenderMinimap["None"] = 0] = "None";
191
188
  RenderMinimap[RenderMinimap["Text"] = 1] = "Text";
@@ -296,8 +293,7 @@ function computeMinimapWidth(options) {
296
293
  const proportionalWidth = Math.floor((availableWidth - 2) * options.charWidth / (options.characterWidth + options.charWidth));
297
294
  return Math.min(minimapMaxWidth, Math.max(0, proportionalWidth) + 2 + 8);
298
295
  }
299
- //#endregion
300
- //#region src/minimapCharRenderer.ts
296
+ // src/minimapCharRenderer.ts
301
297
  var MinimapCharRenderer = class MinimapCharRenderer {
302
298
  scale;
303
299
  charDataNormal;
@@ -439,8 +435,7 @@ function writeBlockRow(dest, row, width, color, alpha) {
439
435
  dest[column++] = alpha;
440
436
  }
441
437
  }
442
- //#endregion
443
- //#region src/minimapCharRendererFactory.ts
438
+ // src/minimapCharRendererFactory.ts
444
439
  /**
445
440
  * Creates minimap character renderers by sampling a normal canvas once and
446
441
  * downsampling the glyph data for tiny minimap text rendering.
@@ -542,8 +537,7 @@ function boostIntensity(result, brightest) {
542
537
  const adjust = 255 / brightest;
543
538
  for (let index = 0; index < result.length; index += 1) result[index] = clamp8(result[index] * adjust);
544
539
  }
545
- //#endregion
546
- //#region src/raster.ts
540
+ // src/raster.ts
547
541
  var RasterBuffer = class {
548
542
  imageData;
549
543
  pixels;
@@ -562,8 +556,7 @@ var RasterBuffer = class {
562
556
  this.pixels.copyWithin(destination * width, source * width, (source + count) * width);
563
557
  }
564
558
  };
565
- //#endregion
566
- //#region src/sectionHeaders.ts
559
+ // src/sectionHeaders.ts
567
560
  const CHUNK_SIZE = 100;
568
561
  function findSectionHeaderDecorations(lines, options) {
569
562
  if (!options.showMarkSectionHeaders) return [];
@@ -652,8 +645,7 @@ function regExpLeadsToEndlessLoop(regexp) {
652
645
  regexp.lastIndex = 0;
653
646
  return match !== null && match[0].length === 0;
654
647
  }
655
- //#endregion
656
- //#region src/renderer.ts
648
+ // src/renderer.ts
657
649
  const EMPTY_DOCUMENT = {
658
650
  textLength: 0,
659
651
  lineStarts: [0],
@@ -709,6 +701,22 @@ var MinimapWorkerRenderer = class {
709
701
  applyEdit(edit, document) {
710
702
  this.applyEdits([edit], document);
711
703
  }
704
+ applySourceSummary(summary) {
705
+ this.requireState();
706
+ this.setDocument({
707
+ ...summary,
708
+ tokens: [],
709
+ selections: [],
710
+ decorations: []
711
+ });
712
+ }
713
+ applySourcePatch(edits, summaryPatch) {
714
+ const state = this.requireState();
715
+ this.applyEdits(edits, {
716
+ summaryPatch,
717
+ selections: state.document.selections
718
+ });
719
+ }
712
720
  applyEdits(edits, document) {
713
721
  if (!this.state) return;
714
722
  if (edits.length === 0) {
@@ -960,7 +968,7 @@ var MinimapWorkerRenderer = class {
960
968
  }
961
969
  renderMinimapDecorations(layout, frame, context) {
962
970
  const state = this.requireState();
963
- const decorations = state.document.decorations.filter((decoration) => !decoration.sectionHeaderStyle).toSorted((left, right) => (left.zIndex ?? 0) - (right.zIndex ?? 0));
971
+ const decorations = state.document.decorations.filter((decoration) => !decoration.sectionHeaderStyle).sort((left, right) => (left.zIndex ?? 0) - (right.zIndex ?? 0));
964
972
  for (const decoration of decorations) {
965
973
  context.fillStyle = rgbaToCss(transparent(parseCssColor(decoration.color, state.styles.selection), .5));
966
974
  fillDecorationRange(context, layout, frame, decoration);
@@ -1476,9 +1484,75 @@ function previousCodePointStart(text, offset) {
1476
1484
  const previousCodeUnit = text.charCodeAt(beforePrevious);
1477
1485
  return previousCodeUnit >= 55296 && previousCodeUnit <= 56319 ? beforePrevious : previous;
1478
1486
  }
1479
- //#endregion
1480
- //#region src/minimap.worker.ts
1487
+ // src/sourceIdentity.ts
1488
+ function sourceIdentitiesEqual(left, right) {
1489
+ return left.documentId === right.documentId && left.documentGeneration === right.documentGeneration && left.endpointGeneration === right.endpointGeneration && left.registrationId === right.registrationId;
1490
+ }
1491
+ function sourcePointsEqual(left, right) {
1492
+ return Boolean(left && left.segment === right.segment && left.revision === right.revision && left.textVersion === right.textVersion);
1493
+ }
1494
+ // src/sourceProtocol.ts
1495
+ var MinimapSourceProtocol = class {
1496
+ renderer;
1497
+ accepted = null;
1498
+ constructor(renderer) {
1499
+ this.renderer = renderer;
1500
+ }
1501
+ apply(request) {
1502
+ if (!this.matchesBase(request)) throw sourceMismatch(request);
1503
+ const projection = request.projection;
1504
+ if (projection.kind === "reset") this.renderer.applySourceSummary(projection.summary);
1505
+ else this.renderer.applySourcePatch(projection.edits, projection.summary);
1506
+ this.accepted = {
1507
+ kind: "applied",
1508
+ identity: request.identity,
1509
+ base: request.base,
1510
+ target: request.target
1511
+ };
1512
+ return this.accepted;
1513
+ }
1514
+ release(identity) {
1515
+ if (!this.accepted || !sourceIdentitiesEqual(identity, this.accepted.identity)) return;
1516
+ this.accepted = null;
1517
+ this.renderer.setDocument({
1518
+ textLength: 0,
1519
+ lineStarts: [0],
1520
+ lines: [{
1521
+ text: "",
1522
+ length: 0
1523
+ }],
1524
+ tokens: [],
1525
+ selections: [],
1526
+ decorations: []
1527
+ });
1528
+ }
1529
+ current() {
1530
+ return this.accepted;
1531
+ }
1532
+ accepts(receipt) {
1533
+ return Boolean(this.accepted && sourceIdentitiesEqual(receipt.identity, this.accepted.identity) && sourcePointsEqual(receipt.target, this.accepted.target));
1534
+ }
1535
+ matchesBase(request) {
1536
+ if (!this.accepted) return request.base === null && request.projection.kind === "reset";
1537
+ return sourceIdentitiesEqual(request.identity, this.accepted.identity) && sourcePointsEqual(request.base, this.accepted.target);
1538
+ }
1539
+ };
1540
+ function sourceMismatch(request) {
1541
+ return createError({
1542
+ code: "minimap.SOURCE_BASE_MISMATCH",
1543
+ message: "Minimap source baseline changed",
1544
+ why: "The requested patch names another source scope or baseline.",
1545
+ fix: "Release the stale source operation and reconnect the document projection.",
1546
+ internal: {
1547
+ requestId: request.requestId,
1548
+ endpointGeneration: request.identity.endpointGeneration,
1549
+ revision: request.target.revision
1550
+ }
1551
+ });
1552
+ }
1553
+ // src/minimap.worker.ts
1481
1554
  const renderer = new MinimapWorkerRenderer();
1555
+ const source = new MinimapSourceProtocol(renderer);
1482
1556
  globalThis.onmessage = (event) => {
1483
1557
  const request = event.data;
1484
1558
  try {
@@ -1503,16 +1577,6 @@ function handleRequest(request) {
1503
1577
  case "updateBaseStyles":
1504
1578
  renderer.setBaseStyles(request.baseStyles);
1505
1579
  return;
1506
- case "openDocument":
1507
- case "replaceDocument":
1508
- renderer.setDocument(request.document);
1509
- return;
1510
- case "applyEdit":
1511
- renderer.applyEdit(request.edit, request.document);
1512
- return;
1513
- case "applyEdits":
1514
- renderer.applyEdits(request.edits, request.document);
1515
- return;
1516
1580
  case "updateTokens":
1517
1581
  renderer.setTokens(request.tokens);
1518
1582
  return;
@@ -1547,20 +1611,36 @@ function handleRequest(request) {
1547
1611
  return;
1548
1612
  }
1549
1613
  case "render":
1614
+ if (!source.accepts(request.source)) {
1615
+ post({
1616
+ type: "renderSkipped",
1617
+ sequence: request.sequence
1618
+ });
1619
+ return;
1620
+ }
1550
1621
  postRender(request.sequence);
1551
1622
  return;
1552
- case "dispose":
1553
- renderer.dispose();
1554
- post({ type: "disposed" });
1623
+ case "projectSource":
1624
+ post({
1625
+ type: "sourceApplied",
1626
+ requestId: request.requestId,
1627
+ receipt: source.apply(request)
1628
+ });
1629
+ return;
1630
+ case "releaseSource":
1631
+ source.release(request.identity);
1555
1632
  return;
1556
1633
  }
1557
1634
  }
1558
1635
  function postRender(sequence) {
1636
+ const receipt = source.current();
1637
+ if (!receipt) return;
1559
1638
  const result = renderer.render();
1560
1639
  if (!result) return;
1561
1640
  post({
1562
1641
  type: "rendered",
1563
1642
  sequence,
1643
+ source: receipt,
1564
1644
  sliderNeeded: result.sliderNeeded,
1565
1645
  sliderTop: result.sliderTop,
1566
1646
  sliderHeight: result.sliderHeight,
@@ -1611,6 +1691,5 @@ function minimapWorkerDiagnosticGlobal() {
1611
1691
  function nowMs() {
1612
1692
  return globalThis.performance?.now() ?? Date.now();
1613
1693
  }
1614
- //#endregion
1615
1694
 
1616
- //# sourceMappingURL=minimap.worker-i4S59IOV.js.map
1695
+ //# sourceMappingURL=minimap.worker-C_eNmhCg.js.map