videobook-engine 2.0.1 → 5.0.1
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/README.md +99 -68
- package/dist/artifacts.d.ts +4 -9
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js +78 -138
- package/dist/artifacts.js.map +1 -1
- package/dist/books.d.ts +1 -1
- package/dist/books.d.ts.map +1 -1
- package/dist/books.js +18 -10
- package/dist/books.js.map +1 -1
- package/dist/cas.d.ts +27 -1
- package/dist/cas.d.ts.map +1 -1
- package/dist/cas.js +78 -6
- package/dist/cas.js.map +1 -1
- package/dist/catalog-metadata.d.ts +56 -0
- package/dist/catalog-metadata.d.ts.map +1 -0
- package/dist/catalog-metadata.js +42 -0
- package/dist/catalog-metadata.js.map +1 -0
- package/dist/communications.js +4 -2
- package/dist/communications.js.map +1 -1
- package/dist/context.d.ts +9 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +42 -51
- package/dist/context.js.map +1 -1
- package/dist/domain.d.ts +39 -2
- package/dist/domain.d.ts.map +1 -1
- package/dist/domain.js +846 -64
- package/dist/domain.js.map +1 -1
- package/dist/edit-policy.d.ts +3 -0
- package/dist/edit-policy.d.ts.map +1 -0
- package/dist/edit-policy.js +6 -0
- package/dist/edit-policy.js.map +1 -0
- package/dist/edits.d.ts +10 -0
- package/dist/edits.d.ts.map +1 -0
- package/dist/edits.js +1392 -0
- package/dist/edits.js.map +1 -0
- package/dist/engine-types.d.ts +171 -86
- package/dist/engine-types.d.ts.map +1 -1
- package/dist/engine-types.js +32 -0
- package/dist/engine-types.js.map +1 -1
- package/dist/engine.d.ts +89 -26
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +27 -21
- package/dist/engine.js.map +1 -1
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +32 -28
- package/dist/files.js.map +1 -1
- package/dist/fork.d.ts +148 -0
- package/dist/fork.d.ts.map +1 -0
- package/dist/fork.js +602 -0
- package/dist/fork.js.map +1 -0
- package/dist/generations.d.ts +9 -0
- package/dist/generations.d.ts.map +1 -0
- package/dist/generations.js +175 -0
- package/dist/generations.js.map +1 -0
- package/dist/history.d.ts +2 -5
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +183 -640
- package/dist/history.js.map +1 -1
- package/dist/index.d.ts +21 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -5
- package/dist/index.js.map +1 -1
- package/dist/job-queue.d.ts +2 -0
- package/dist/job-queue.d.ts.map +1 -1
- package/dist/job-queue.js +29 -2
- package/dist/job-queue.js.map +1 -1
- package/dist/media.d.ts +3 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +6 -5
- package/dist/media.js.map +1 -1
- package/dist/merge-policy.d.ts +83 -0
- package/dist/merge-policy.d.ts.map +1 -0
- package/dist/merge-policy.js +203 -0
- package/dist/merge-policy.js.map +1 -0
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js +17 -23
- package/dist/metadata.js.map +1 -1
- package/dist/migration.d.ts +9 -0
- package/dist/migration.d.ts.map +1 -0
- package/dist/migration.js +564 -0
- package/dist/migration.js.map +1 -0
- package/dist/mvp-contract-fixtures.d.ts +244 -0
- package/dist/mvp-contract-fixtures.d.ts.map +1 -0
- package/dist/mvp-contract-fixtures.js +556 -0
- package/dist/mvp-contract-fixtures.js.map +1 -0
- package/dist/mvp-contracts.d.ts +761 -0
- package/dist/mvp-contracts.d.ts.map +1 -0
- package/dist/mvp-contracts.js +59 -0
- package/dist/mvp-contracts.js.map +1 -0
- package/dist/mvp-time.d.ts +54 -0
- package/dist/mvp-time.d.ts.map +1 -0
- package/dist/mvp-time.js +148 -0
- package/dist/mvp-time.js.map +1 -0
- package/dist/notebook/types.d.ts +85 -8
- package/dist/notebook/types.d.ts.map +1 -1
- package/dist/notebook-grid.d.ts +37 -0
- package/dist/notebook-grid.d.ts.map +1 -0
- package/dist/notebook-grid.js +160 -0
- package/dist/notebook-grid.js.map +1 -0
- package/dist/notebook-media-artifact.d.ts +23 -0
- package/dist/notebook-media-artifact.d.ts.map +1 -0
- package/dist/notebook-media-artifact.js +67 -0
- package/dist/notebook-media-artifact.js.map +1 -0
- package/dist/notebook-mentions.d.ts +20 -0
- package/dist/notebook-mentions.d.ts.map +1 -0
- package/dist/notebook-mentions.js +53 -0
- package/dist/notebook-mentions.js.map +1 -0
- package/dist/order-keys.d.ts +22 -0
- package/dist/order-keys.d.ts.map +1 -0
- package/dist/order-keys.js +262 -0
- package/dist/order-keys.js.map +1 -0
- package/dist/runtime-services.js +8 -11
- package/dist/runtime-services.js.map +1 -1
- package/dist/schema.d.ts +8 -5
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +624 -141
- package/dist/schema.js.map +1 -1
- package/dist/search-benchmark.d.ts +4 -0
- package/dist/search-benchmark.d.ts.map +1 -0
- package/dist/search-benchmark.js +144 -0
- package/dist/search-benchmark.js.map +1 -0
- package/dist/sequences.d.ts +20 -0
- package/dist/sequences.d.ts.map +1 -0
- package/dist/sequences.js +825 -0
- package/dist/sequences.js.map +1 -0
- package/dist/similarity.js +10 -10
- package/dist/similarity.js.map +1 -1
- package/dist/status.js +8 -10
- package/dist/status.js.map +1 -1
- package/dist/storage.d.ts +3 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +388 -7
- package/dist/storage.js.map +1 -1
- package/dist/store.d.ts +64 -3
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +354 -68
- package/dist/store.js.map +1 -1
- package/dist/streams.d.ts +10 -0
- package/dist/streams.d.ts.map +1 -0
- package/dist/streams.js +183 -0
- package/dist/streams.js.map +1 -0
- package/dist/temporal-models.d.ts +48 -0
- package/dist/temporal-models.d.ts.map +1 -0
- package/dist/temporal-models.js +278 -0
- package/dist/temporal-models.js.map +1 -0
- package/dist/temporal-search.d.ts +29 -0
- package/dist/temporal-search.d.ts.map +1 -0
- package/dist/temporal-search.js +1551 -0
- package/dist/temporal-search.js.map +1 -0
- package/dist/transcripts.d.ts +16 -0
- package/dist/transcripts.d.ts.map +1 -0
- package/dist/transcripts.js +519 -0
- package/dist/transcripts.js.map +1 -0
- package/docs/engine-layout.md +345 -110
- package/docs/mvp-prd.md +918 -0
- package/fixtures/media/vancat.mp4 +0 -0
- package/fixtures/media/vancat_profile.jpg +0 -0
- package/fixtures/v5/contract-fixtures.json +1532 -0
- package/package.json +42 -5
- package/dist/history-types.d.ts +0 -74
- package/dist/history-types.d.ts.map +0 -1
- package/dist/history-types.js +0 -2
- package/dist/history-types.js.map +0 -1
- package/dist/resolver.d.ts +0 -15
- package/dist/resolver.d.ts.map +0 -1
- package/dist/resolver.js +0 -81
- package/dist/resolver.js.map +0 -1
- package/dist/timeline.d.ts +0 -9
- package/dist/timeline.d.ts.map +0 -1
- package/dist/timeline.js +0 -236
- package/dist/timeline.js.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { NOTEBOOK_GRID_ADDRESS_PATTERN } from "./notebook-mentions.js";
|
|
2
|
+
export const NOTEBOOK_GRID_ROW_COUNT = 26;
|
|
3
|
+
export const NOTEBOOK_GRID_COLUMN_COUNT = 13;
|
|
4
|
+
export const NOTEBOOK_GRID_CAPACITY = NOTEBOOK_GRID_ROW_COUNT * NOTEBOOK_GRID_COLUMN_COUNT;
|
|
5
|
+
export const NOTEBOOK_GRID_FULL_ERROR = "Notebook grid is full";
|
|
6
|
+
export function isNotebookGridSlot(slot) {
|
|
7
|
+
return Number.isInteger(slot.row)
|
|
8
|
+
&& slot.row >= 0
|
|
9
|
+
&& slot.row < NOTEBOOK_GRID_ROW_COUNT
|
|
10
|
+
&& Number.isInteger(slot.column)
|
|
11
|
+
&& slot.column >= 0
|
|
12
|
+
&& slot.column < NOTEBOOK_GRID_COLUMN_COUNT;
|
|
13
|
+
}
|
|
14
|
+
export function assertNotebookGridSlot(slot, label = "Notebook grid slot") {
|
|
15
|
+
if (!isNotebookGridSlot(slot)) {
|
|
16
|
+
throw new Error(`${label} must be within @a1-@z13`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function notebookGridAddress(slot) {
|
|
20
|
+
assertNotebookGridSlot(slot);
|
|
21
|
+
return `${String.fromCharCode(97 + slot.row)}${slot.column + 1}`;
|
|
22
|
+
}
|
|
23
|
+
export function notebookGridTag(slot) {
|
|
24
|
+
return `@${notebookGridAddress(slot)}`;
|
|
25
|
+
}
|
|
26
|
+
export function parseNotebookGridAddress(value) {
|
|
27
|
+
const match = NOTEBOOK_GRID_ADDRESS_PATTERN.exec(value.trim());
|
|
28
|
+
if (!match)
|
|
29
|
+
return undefined;
|
|
30
|
+
const address = match[1];
|
|
31
|
+
return {
|
|
32
|
+
row: address[0].toLowerCase().charCodeAt(0) - 97,
|
|
33
|
+
column: Number(address.slice(1)) - 1,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function occupiedNotebookGridKeys(occupied) {
|
|
37
|
+
const occupiedKeys = new Set();
|
|
38
|
+
for (const slot of occupied) {
|
|
39
|
+
assertNotebookGridSlot(slot);
|
|
40
|
+
occupiedKeys.add(`${slot.row}:${slot.column}`);
|
|
41
|
+
}
|
|
42
|
+
return occupiedKeys;
|
|
43
|
+
}
|
|
44
|
+
export function firstEmptyNotebookGridSlot(occupied) {
|
|
45
|
+
return firstEmptyNotebookGridSlots(occupied, 1)[0];
|
|
46
|
+
}
|
|
47
|
+
export function firstEmptyNotebookGridSlots(occupied, count) {
|
|
48
|
+
if (!Number.isInteger(count) || count < 0) {
|
|
49
|
+
throw new Error("Notebook grid slot count must be a nonnegative integer");
|
|
50
|
+
}
|
|
51
|
+
if (count === 0)
|
|
52
|
+
return [];
|
|
53
|
+
const occupiedKeys = occupiedNotebookGridKeys(occupied);
|
|
54
|
+
const result = [];
|
|
55
|
+
for (let row = 0; row < NOTEBOOK_GRID_ROW_COUNT; row += 1) {
|
|
56
|
+
for (let column = 0; column < NOTEBOOK_GRID_COLUMN_COUNT; column += 1) {
|
|
57
|
+
if (occupiedKeys.has(`${row}:${column}`))
|
|
58
|
+
continue;
|
|
59
|
+
result.push({ row, column });
|
|
60
|
+
if (result.length === count)
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (result.length === count)
|
|
65
|
+
return result;
|
|
66
|
+
throw new Error(NOTEBOOK_GRID_FULL_ERROR);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Free slot minimizing Manhattan distance from @a1.
|
|
70
|
+
* Ties break by lower row, then lower column (address order among equals).
|
|
71
|
+
*/
|
|
72
|
+
export function nearestOriginNotebookGridSlot(occupied) {
|
|
73
|
+
const occupiedKeys = occupiedNotebookGridKeys(occupied);
|
|
74
|
+
let best = null;
|
|
75
|
+
let bestDistance = Number.POSITIVE_INFINITY;
|
|
76
|
+
for (let row = 0; row < NOTEBOOK_GRID_ROW_COUNT; row += 1) {
|
|
77
|
+
for (let column = 0; column < NOTEBOOK_GRID_COLUMN_COUNT; column += 1) {
|
|
78
|
+
if (occupiedKeys.has(`${row}:${column}`))
|
|
79
|
+
continue;
|
|
80
|
+
const distance = row + column;
|
|
81
|
+
if (best === null
|
|
82
|
+
|| distance < bestDistance
|
|
83
|
+
|| (distance === bestDistance
|
|
84
|
+
&& (row < best.row
|
|
85
|
+
|| (row === best.row && column < best.column)))) {
|
|
86
|
+
best = { row, column };
|
|
87
|
+
bestDistance = distance;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!best)
|
|
92
|
+
throw new Error(NOTEBOOK_GRID_FULL_ERROR);
|
|
93
|
+
return best;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Next free slot scanning down the letter axis from `anchor` (inclusive).
|
|
97
|
+
* Same column first; when exhausted, spill rightward column-by-column from
|
|
98
|
+
* the anchor row; then origin-proximity fallback.
|
|
99
|
+
*/
|
|
100
|
+
export function nextVerticalSlotFrom(anchor, occupied) {
|
|
101
|
+
assertNotebookGridSlot(anchor);
|
|
102
|
+
const occupiedKeys = occupiedNotebookGridKeys(occupied);
|
|
103
|
+
for (let row = anchor.row; row < NOTEBOOK_GRID_ROW_COUNT; row += 1) {
|
|
104
|
+
if (!occupiedKeys.has(`${row}:${anchor.column}`)) {
|
|
105
|
+
return { row, column: anchor.column };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (let column = anchor.column + 1; column < NOTEBOOK_GRID_COLUMN_COUNT; column += 1) {
|
|
109
|
+
for (let row = anchor.row; row < NOTEBOOK_GRID_ROW_COUNT; row += 1) {
|
|
110
|
+
if (!occupiedKeys.has(`${row}:${column}`)) {
|
|
111
|
+
return { row, column };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return nearestOriginNotebookGridSlot(occupied);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Next free slot scanning right along the number axis from `anchor` (inclusive).
|
|
119
|
+
* Same row first; when exhausted, spill downward row-by-row from the anchor
|
|
120
|
+
* column; then origin-proximity fallback.
|
|
121
|
+
*/
|
|
122
|
+
export function nextHorizontalSlotFrom(anchor, occupied) {
|
|
123
|
+
assertNotebookGridSlot(anchor);
|
|
124
|
+
const occupiedKeys = occupiedNotebookGridKeys(occupied);
|
|
125
|
+
for (let column = anchor.column; column < NOTEBOOK_GRID_COLUMN_COUNT; column += 1) {
|
|
126
|
+
if (!occupiedKeys.has(`${anchor.row}:${column}`)) {
|
|
127
|
+
return { row: anchor.row, column };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (let row = anchor.row + 1; row < NOTEBOOK_GRID_ROW_COUNT; row += 1) {
|
|
131
|
+
for (let column = anchor.column; column < NOTEBOOK_GRID_COLUMN_COUNT; column += 1) {
|
|
132
|
+
if (!occupiedKeys.has(`${row}:${column}`)) {
|
|
133
|
+
return { row, column };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return nearestOriginNotebookGridSlot(occupied);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Wave placement for generation tiles: scan `waveRow` left-to-right from
|
|
141
|
+
* `startColumn` for a slot whose below-neighbor is also free (room for the
|
|
142
|
+
* tile's output cell directly beneath), advancing row by row while both stay
|
|
143
|
+
* within the board; origin-proximity fallback when no pair fits.
|
|
144
|
+
*/
|
|
145
|
+
export function nextWaveTileSlot(waveRow, startColumn, occupied) {
|
|
146
|
+
const occupiedKeys = occupiedNotebookGridKeys(occupied);
|
|
147
|
+
const firstRow = Math.min(Math.max(0, Math.trunc(waveRow)), NOTEBOOK_GRID_ROW_COUNT - 1);
|
|
148
|
+
const firstColumn = Math.min(Math.max(0, Math.trunc(startColumn)), NOTEBOOK_GRID_COLUMN_COUNT - 1);
|
|
149
|
+
for (let row = firstRow; row + 1 < NOTEBOOK_GRID_ROW_COUNT; row += 1) {
|
|
150
|
+
for (let column = firstColumn; column < NOTEBOOK_GRID_COLUMN_COUNT; column += 1) {
|
|
151
|
+
if (occupiedKeys.has(`${row}:${column}`))
|
|
152
|
+
continue;
|
|
153
|
+
if (occupiedKeys.has(`${row + 1}:${column}`))
|
|
154
|
+
continue;
|
|
155
|
+
return { row, column };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return nearestOriginNotebookGridSlot(occupied);
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=notebook-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook-grid.js","sourceRoot":"","sources":["../src/notebook-grid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wBAAwB,CAAC;AAEvE,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAC7C,MAAM,CAAC,MAAM,sBAAsB,GACjC,uBAAuB,GAAG,0BAA0B,CAAC;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,uBAAuB,CAAC;A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AAW,EACxB,MAAM,GAAG,0BAA0B,EACnC,MAAM,IAAI,CAAC,EACX,CAAC;YACD,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC;gBAAE,SAAS;YACnD,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC;gBAAE,SAAS;YACvD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;IACD,OAAO,6BAA6B,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { NotebookCell, NotebookDocument, NotebookEdge } from "./notebook/types.js";
|
|
2
|
+
type NotebookGraph = Pick<NotebookDocument, "cells" | "edges">;
|
|
3
|
+
export declare function findGenerateVideoOutputCell(document: NotebookGraph, generateVideoCellId: string): {
|
|
4
|
+
outputCell: NotebookCell;
|
|
5
|
+
outputEdge: NotebookEdge;
|
|
6
|
+
} | null;
|
|
7
|
+
export declare function findGenerateImageOutputCell(document: NotebookGraph, generateImageCellId: string): {
|
|
8
|
+
outputCell: NotebookCell;
|
|
9
|
+
outputEdge: NotebookEdge;
|
|
10
|
+
} | null;
|
|
11
|
+
export declare function findGenerateAudioOutputCell(document: NotebookGraph, generateAudioCellId: string): {
|
|
12
|
+
outputCell: NotebookCell;
|
|
13
|
+
outputEdge: NotebookEdge;
|
|
14
|
+
} | null;
|
|
15
|
+
/**
|
|
16
|
+
* Resolve media artifact for a notebook cell.
|
|
17
|
+
* generate_video / generate_image / generate_audio prefer a dedicated output
|
|
18
|
+
* cell, then fall back to legacy inline outputArtifactId / outputEntityId.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveNotebookCellArtifactId(document: NotebookGraph, cell: NotebookCell): string | undefined;
|
|
21
|
+
export declare function resolveGeneratedVideoArtifact(document: NotebookGraph, cell: NotebookCell): string | undefined;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=notebook-media-artifact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook-media-artifact.d.ts","sourceRoot":"","sources":["../src/notebook-media-artifact.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACb,MAAM,qBAAqB,CAAC;AAE7B,KAAK,aAAa,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC;AAwC/D,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,aAAa,EACvB,mBAAmB,EAAE,MAAM,GAC1B;IAAE,UAAU,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,YAAY,CAAA;CAAE,GAAG,IAAI,CAO/D;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,aAAa,EACvB,mBAAmB,EAAE,MAAM,GAC1B;IAAE,UAAU,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,YAAY,CAAA;CAAE,GAAG,IAAI,CAO/D;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,aAAa,EACvB,mBAAmB,EAAE,MAAM,GAC1B;IAAE,UAAU,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,YAAY,CAAA;CAAE,GAAG,IAAI,CAO/D;AAyBD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,YAAY,GACjB,MAAM,GAAG,SAAS,CAEpB;AAED,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE,YAAY,GACjB,MAAM,GAAG,SAAS,CAEpB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function findGenerationOutputCell(document, producerCellId, outputType, mediaRole) {
|
|
2
|
+
for (const edge of document.edges) {
|
|
3
|
+
if (edge.source !== producerCellId || edge.targetInput !== "media") {
|
|
4
|
+
continue;
|
|
5
|
+
}
|
|
6
|
+
const outputCell = document.cells.find((cell) => cell.id === edge.target);
|
|
7
|
+
if (outputCell?.type === outputType
|
|
8
|
+
&& outputCell.inputs?.mediaRole === mediaRole) {
|
|
9
|
+
return { outputCell, outputEdge: edge };
|
|
10
|
+
}
|
|
11
|
+
if (outputCell?.type === outputType
|
|
12
|
+
&& outputCell.inputs?.producerCellId === producerCellId) {
|
|
13
|
+
return { outputCell, outputEdge: edge };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const edge of document.edges) {
|
|
17
|
+
if (edge.source !== producerCellId || edge.targetInput !== "media") {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const outputCell = document.cells.find((cell) => cell.id === edge.target);
|
|
21
|
+
if (outputCell?.type === outputType) {
|
|
22
|
+
return { outputCell, outputEdge: edge };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
export function findGenerateVideoOutputCell(document, generateVideoCellId) {
|
|
28
|
+
return findGenerationOutputCell(document, generateVideoCellId, "video", "generate-video-output");
|
|
29
|
+
}
|
|
30
|
+
export function findGenerateImageOutputCell(document, generateImageCellId) {
|
|
31
|
+
return findGenerationOutputCell(document, generateImageCellId, "image", "generate-image-output");
|
|
32
|
+
}
|
|
33
|
+
export function findGenerateAudioOutputCell(document, generateAudioCellId) {
|
|
34
|
+
return findGenerationOutputCell(document, generateAudioCellId, "audio", "generate-audio-output");
|
|
35
|
+
}
|
|
36
|
+
function inlineCellArtifactId(cell) {
|
|
37
|
+
if (typeof cell.outputArtifactId === "string")
|
|
38
|
+
return cell.outputArtifactId;
|
|
39
|
+
if (typeof cell.outputEntityId === "string")
|
|
40
|
+
return cell.outputEntityId;
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
function outputCellArtifactId(document, cell) {
|
|
44
|
+
const output = cell.type === "generate_video"
|
|
45
|
+
? findGenerateVideoOutputCell(document, cell.id)
|
|
46
|
+
: cell.type === "generate_image"
|
|
47
|
+
? findGenerateImageOutputCell(document, cell.id)
|
|
48
|
+
: cell.type === "generate_audio"
|
|
49
|
+
? findGenerateAudioOutputCell(document, cell.id)
|
|
50
|
+
: null;
|
|
51
|
+
if (typeof output?.outputCell.outputArtifactId === "string") {
|
|
52
|
+
return output.outputCell.outputArtifactId;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolve media artifact for a notebook cell.
|
|
58
|
+
* generate_video / generate_image / generate_audio prefer a dedicated output
|
|
59
|
+
* cell, then fall back to legacy inline outputArtifactId / outputEntityId.
|
|
60
|
+
*/
|
|
61
|
+
export function resolveNotebookCellArtifactId(document, cell) {
|
|
62
|
+
return outputCellArtifactId(document, cell) ?? inlineCellArtifactId(cell);
|
|
63
|
+
}
|
|
64
|
+
export function resolveGeneratedVideoArtifact(document, cell) {
|
|
65
|
+
return resolveNotebookCellArtifactId(document, cell);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=notebook-media-artifact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook-media-artifact.js","sourceRoot":"","sources":["../src/notebook-media-artifact.ts"],"names":[],"mappings":"AAUA,SAAS,wBAAwB,CAC/B,QAAuB,EACvB,cAAsB,EACtB,UAAgC,EAChC,SAAiB;IAEjB,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,MAAM,KAAK,cAAc,IAAI,IAAI,CAAC,WAAW,KAAK,OAAO,EAAE,CAAC;YACnE,SAAS;QACX,CAAC;QACD,MAAM,UAAU,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1E,IACE,UAAU,EAAE,IAAI,KAAK,UAAU;eAC5B,UAAU,CAAC,MAAM,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_ADDRESS_SOURCE = "[a-z](?:1[0-3]|[1-9])";
|
|
2
|
+
export declare const NOTEBOOK_GRID_ADDRESS_PATTERN: RegExp;
|
|
3
|
+
export declare const NOTEBOOK_MENTION_PATTERN: RegExp;
|
|
4
|
+
export interface NotebookMention {
|
|
5
|
+
raw: string;
|
|
6
|
+
reference: string;
|
|
7
|
+
index: number;
|
|
8
|
+
end: number;
|
|
9
|
+
}
|
|
10
|
+
export interface NotebookMentionReplacement {
|
|
11
|
+
reference: string;
|
|
12
|
+
replacement: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function normalizeNotebookReference(value: string): string;
|
|
15
|
+
export declare function isNotebookGridAddress(value: string): boolean;
|
|
16
|
+
export declare function scanNotebookMentions(input: string): NotebookMention[];
|
|
17
|
+
export declare function notebookMentionPrefixAtEnd(input: string): string | undefined;
|
|
18
|
+
export declare function replaceNotebookMentions(input: string, replacements: readonly NotebookMentionReplacement[]): string;
|
|
19
|
+
export declare function stripNotebookMentions(input: string, references: readonly string[]): string;
|
|
20
|
+
//# sourceMappingURL=notebook-mentions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook-mentions.d.ts","sourceRoot":"","sources":["../src/notebook-mentions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,4BAA4B,0BAA0B,CAAC;AAEpE,eAAO,MAAM,6BAA6B,QAGzC,CAAC;AACF,eAAO,MAAM,wBAAwB,QAGpC,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,EAAE,CAUrE;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG5E;AAMD,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,SAAS,0BAA0B,EAAE,GAClD,MAAM,CAgBR;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,MAAM,CAaR"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const NOTEBOOK_GRID_ADDRESS_SOURCE = "[a-z](?:1[0-3]|[1-9])";
|
|
2
|
+
export const NOTEBOOK_GRID_ADDRESS_PATTERN = new RegExp(`^@?(${NOTEBOOK_GRID_ADDRESS_SOURCE})$`, "iu");
|
|
3
|
+
export const NOTEBOOK_MENTION_PATTERN = new RegExp(`@(${NOTEBOOK_GRID_ADDRESS_SOURCE})(?![\\w-])`, "giu");
|
|
4
|
+
export function normalizeNotebookReference(value) {
|
|
5
|
+
return value.trim().replace(/^@/u, "").toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
export function isNotebookGridAddress(value) {
|
|
8
|
+
return NOTEBOOK_GRID_ADDRESS_PATTERN.test(normalizeNotebookReference(value));
|
|
9
|
+
}
|
|
10
|
+
export function scanNotebookMentions(input) {
|
|
11
|
+
return [...input.matchAll(NOTEBOOK_MENTION_PATTERN)].map((match) => {
|
|
12
|
+
const raw = match[0];
|
|
13
|
+
return {
|
|
14
|
+
raw,
|
|
15
|
+
reference: normalizeNotebookReference(match[1] ?? raw),
|
|
16
|
+
index: match.index,
|
|
17
|
+
end: match.index + raw.length,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function notebookMentionPrefixAtEnd(input) {
|
|
22
|
+
const match = input.match(/@([a-z0-9]*)$/iu);
|
|
23
|
+
return match ? normalizeNotebookReference(match[1] ?? "") : undefined;
|
|
24
|
+
}
|
|
25
|
+
function escapePattern(value) {
|
|
26
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
27
|
+
}
|
|
28
|
+
export function replaceNotebookMentions(input, replacements) {
|
|
29
|
+
let output = input;
|
|
30
|
+
const ordered = [...replacements]
|
|
31
|
+
.map(({ reference, replacement }) => ({
|
|
32
|
+
reference: normalizeNotebookReference(reference),
|
|
33
|
+
replacement,
|
|
34
|
+
}))
|
|
35
|
+
.filter(({ reference }) => reference.length > 0)
|
|
36
|
+
.sort((left, right) => right.reference.length - left.reference.length);
|
|
37
|
+
for (const { reference, replacement } of ordered) {
|
|
38
|
+
output = output.replace(new RegExp(`@${escapePattern(reference)}(?![\\w-])`, "giu"), replacement);
|
|
39
|
+
}
|
|
40
|
+
return output;
|
|
41
|
+
}
|
|
42
|
+
export function stripNotebookMentions(input, references) {
|
|
43
|
+
let output = input;
|
|
44
|
+
const ordered = references
|
|
45
|
+
.map(normalizeNotebookReference)
|
|
46
|
+
.filter((reference) => reference.length > 0)
|
|
47
|
+
.sort((left, right) => right.length - left.length);
|
|
48
|
+
for (const reference of ordered) {
|
|
49
|
+
output = output.replace(new RegExp(` ?@${escapePattern(reference)}(?![\\w-])`, "giu"), "");
|
|
50
|
+
}
|
|
51
|
+
return output;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=notebook-mentions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notebook-mentions.js","sourceRoot":"","sources":["../src/notebook-mentions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,4BAA4B,GAAG,uBAAuB,CAAC;AAEpE,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,MAAM,CACrD,OAAO,4BAA4B,IAAI,EACvC,IAAI,CACL,CAAC;AACF,MAAM,CAAC,MAAM,wBAAwB,GAAG,I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AC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function isOrderKey(key: string): boolean;
|
|
2
|
+
export declare function assertOrderKey(key: string, label: string): void;
|
|
3
|
+
/**
|
|
4
|
+
* Returns a key that sorts strictly between `before` and `after`
|
|
5
|
+
* (either side may be null for an open end).
|
|
6
|
+
*/
|
|
7
|
+
export declare function orderKeyBetween(before: string | null, after: string | null): string;
|
|
8
|
+
/** Key sorting immediately after `key` (or the first key when null). */
|
|
9
|
+
export declare function orderKeyAfter(key: string | null): string;
|
|
10
|
+
/** Dense initial keys for a freshly created ordered list. */
|
|
11
|
+
export declare function initialOrderKeys(count: number): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Reconciles an ordered list of row identities with their stored keys,
|
|
14
|
+
* reusing existing keys for every row whose relative order is unchanged
|
|
15
|
+
* (a longest increasing subsequence) and minting midpoint keys only for
|
|
16
|
+
* new or genuinely reordered rows. Untouched rows keep their stored key,
|
|
17
|
+
* so merges with forks that appended elsewhere stay row-local.
|
|
18
|
+
*
|
|
19
|
+
* Returns the key for every desired id, in desired order.
|
|
20
|
+
*/
|
|
21
|
+
export declare function reconcileOrderKeys<I>(desired: readonly I[], existing: ReadonlyMap<I, string>): Map<I, string>;
|
|
22
|
+
//# sourceMappingURL=order-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-keys.d.ts","sourceRoot":"","sources":["../src/order-keys.ts"],"names":[],"mappings":"AAiCA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAS/C;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAE/D;AA+DD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,EACrB,KAAK,EAAE,MAAM,GAAG,IAAI,GACnB,MAAM,CA2BR;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAExD;AAED,6DAA6D;AAC7D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CASxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,OAAO,EAAE,SAAS,CAAC,EAAE,EACrB,QAAQ,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,GAC/B,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CA6ChB"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fractional/lexicographic order keys for engine-maintained orderings
|
|
3
|
+
* (sequence tracks).
|
|
4
|
+
*
|
|
5
|
+
* Format (compatible with the "fractional-indexing" key scheme):
|
|
6
|
+
* - A key is an integer part followed by an optional fractional part.
|
|
7
|
+
* - Digits are base-62: 0-9 A-Z a-z, in ASCII (byte) order, so keys sort
|
|
8
|
+
* correctly under SQLite's default BINARY text collation.
|
|
9
|
+
* - The integer part's first character encodes its length: 'a'..'z' for
|
|
10
|
+
* non-negative integers (2..27 chars), 'A'..'Z' for negative integers
|
|
11
|
+
* (2..27 chars). Zero is "a0".
|
|
12
|
+
* - The fractional part refines the order within one integer bucket.
|
|
13
|
+
*
|
|
14
|
+
* Keys are never unique by construction: two forks can independently mint
|
|
15
|
+
* the same key. Readers always break ties by the row's stable UUID.
|
|
16
|
+
*/
|
|
17
|
+
const DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
18
|
+
const INTEGER_ZERO = "a0";
|
|
19
|
+
const LAST_DIGIT = DIGITS[DIGITS.length - 1];
|
|
20
|
+
const MID_DIGIT = DIGITS[DIGITS.length >> 1];
|
|
21
|
+
function integerLength(head) {
|
|
22
|
+
const code = head.charCodeAt(0);
|
|
23
|
+
if (head >= "a" && head <= "z")
|
|
24
|
+
return code - 97 + 2;
|
|
25
|
+
if (head >= "A" && head <= "Z")
|
|
26
|
+
return 90 - code + 2;
|
|
27
|
+
throw new Error(`Invalid order key: unexpected head character: ${head}`);
|
|
28
|
+
}
|
|
29
|
+
function integerPart(key) {
|
|
30
|
+
if (key.length === 0)
|
|
31
|
+
throw new Error("Invalid order key: empty key");
|
|
32
|
+
return key.slice(0, integerLength(key[0]));
|
|
33
|
+
}
|
|
34
|
+
export function isOrderKey(key) {
|
|
35
|
+
if (!/^[A-Za-z][0-9A-Za-z]*$/.test(key))
|
|
36
|
+
return false;
|
|
37
|
+
try {
|
|
38
|
+
const integer = integerPart(key);
|
|
39
|
+
if (integer.length !== integerLength(integer[0]))
|
|
40
|
+
return false;
|
|
41
|
+
return !key.slice(integer.length).endsWith(DIGITS[0]);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function assertOrderKey(key, label) {
|
|
48
|
+
if (!isOrderKey(key))
|
|
49
|
+
throw new Error(`${label} is not a valid order key: ${key}`);
|
|
50
|
+
}
|
|
51
|
+
function incrementInteger(integer) {
|
|
52
|
+
const head = integer[0];
|
|
53
|
+
const digits = integer.slice(1).split("");
|
|
54
|
+
let carry = true;
|
|
55
|
+
for (let index = digits.length - 1; carry && index >= 0; index -= 1) {
|
|
56
|
+
const value = DIGITS.indexOf(digits[index]) + 1;
|
|
57
|
+
if (value === DIGITS.length) {
|
|
58
|
+
digits[index] = DIGITS[0];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
digits[index] = DIGITS[value];
|
|
62
|
+
carry = false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!carry)
|
|
66
|
+
return head + digits.join("");
|
|
67
|
+
if (head === "Z")
|
|
68
|
+
return INTEGER_ZERO;
|
|
69
|
+
if (head === "z")
|
|
70
|
+
return null;
|
|
71
|
+
const next = String.fromCharCode(head.charCodeAt(0) + 1);
|
|
72
|
+
return next + DIGITS[0].repeat(integerLength(next) - 1);
|
|
73
|
+
}
|
|
74
|
+
function decrementInteger(integer) {
|
|
75
|
+
const head = integer[0];
|
|
76
|
+
const digits = integer.slice(1).split("");
|
|
77
|
+
let borrow = true;
|
|
78
|
+
for (let index = digits.length - 1; borrow && index >= 0; index -= 1) {
|
|
79
|
+
const value = DIGITS.indexOf(digits[index]) - 1;
|
|
80
|
+
if (value === -1) {
|
|
81
|
+
digits[index] = LAST_DIGIT;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
digits[index] = DIGITS[value];
|
|
85
|
+
borrow = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (!borrow)
|
|
89
|
+
return head + digits.join("");
|
|
90
|
+
if (head === "a")
|
|
91
|
+
return `Z${LAST_DIGIT}`;
|
|
92
|
+
if (head === "A")
|
|
93
|
+
return null;
|
|
94
|
+
const previous = String.fromCharCode(head.charCodeAt(0) - 1);
|
|
95
|
+
return previous + LAST_DIGIT.repeat(integerLength(previous) - 1);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Fractional midpoint strictly between `a` and `b` (both digit strings,
|
|
99
|
+
* `b === null` means "no upper bound"). Precondition: a < b.
|
|
100
|
+
*/
|
|
101
|
+
function midpoint(a, b) {
|
|
102
|
+
if (b === null) {
|
|
103
|
+
if (a === "")
|
|
104
|
+
return MID_DIGIT;
|
|
105
|
+
const head = a[0];
|
|
106
|
+
if (head !== LAST_DIGIT)
|
|
107
|
+
return DIGITS[DIGITS.indexOf(head) + 1];
|
|
108
|
+
return head + midpoint(a.slice(1), null);
|
|
109
|
+
}
|
|
110
|
+
const digitA = a === "" ? 0 : DIGITS.indexOf(a[0]);
|
|
111
|
+
const digitB = b === "" ? 0 : DIGITS.indexOf(b[0]);
|
|
112
|
+
if (digitB - digitA > 1)
|
|
113
|
+
return DIGITS[(digitA + digitB + 1) >> 1];
|
|
114
|
+
if (digitB - digitA === 1) {
|
|
115
|
+
return DIGITS[digitA] + midpoint(a.slice(1), null);
|
|
116
|
+
}
|
|
117
|
+
if (b === "")
|
|
118
|
+
throw new Error("No room between order keys");
|
|
119
|
+
return DIGITS[digitA] + midpoint(a.slice(1), b.slice(1));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns a key that sorts strictly between `before` and `after`
|
|
123
|
+
* (either side may be null for an open end).
|
|
124
|
+
*/
|
|
125
|
+
export function orderKeyBetween(before, after) {
|
|
126
|
+
if (before !== null)
|
|
127
|
+
assertOrderKey(before, "Before order key");
|
|
128
|
+
if (after !== null)
|
|
129
|
+
assertOrderKey(after, "After order key");
|
|
130
|
+
if (before !== null && after !== null && before >= after) {
|
|
131
|
+
throw new Error(`Order keys out of order: ${before} !< ${after}`);
|
|
132
|
+
}
|
|
133
|
+
if (before === null) {
|
|
134
|
+
if (after === null)
|
|
135
|
+
return INTEGER_ZERO;
|
|
136
|
+
const integer = integerPart(after);
|
|
137
|
+
const decremented = decrementInteger(integer);
|
|
138
|
+
if (decremented !== null)
|
|
139
|
+
return decremented;
|
|
140
|
+
return integer + midpoint("", after.slice(integer.length));
|
|
141
|
+
}
|
|
142
|
+
const beforeInteger = integerPart(before);
|
|
143
|
+
const beforeFraction = before.slice(beforeInteger.length);
|
|
144
|
+
if (after === null) {
|
|
145
|
+
const incremented = incrementInteger(beforeInteger);
|
|
146
|
+
if (incremented !== null)
|
|
147
|
+
return incremented;
|
|
148
|
+
return beforeInteger + midpoint(beforeFraction, null);
|
|
149
|
+
}
|
|
150
|
+
const afterInteger = integerPart(after);
|
|
151
|
+
if (beforeInteger === afterInteger) {
|
|
152
|
+
return beforeInteger + midpoint(beforeFraction, after.slice(afterInteger.length));
|
|
153
|
+
}
|
|
154
|
+
const incremented = incrementInteger(beforeInteger);
|
|
155
|
+
if (incremented !== null && incremented < after)
|
|
156
|
+
return incremented;
|
|
157
|
+
return beforeInteger + midpoint(beforeFraction, null);
|
|
158
|
+
}
|
|
159
|
+
/** Key sorting immediately after `key` (or the first key when null). */
|
|
160
|
+
export function orderKeyAfter(key) {
|
|
161
|
+
return orderKeyBetween(key, null);
|
|
162
|
+
}
|
|
163
|
+
/** Dense initial keys for a freshly created ordered list. */
|
|
164
|
+
export function initialOrderKeys(count) {
|
|
165
|
+
const keys = [];
|
|
166
|
+
let previous = null;
|
|
167
|
+
for (let index = 0; index < count; index += 1) {
|
|
168
|
+
const key = orderKeyAfter(previous);
|
|
169
|
+
keys.push(key);
|
|
170
|
+
previous = key;
|
|
171
|
+
}
|
|
172
|
+
return keys;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Reconciles an ordered list of row identities with their stored keys,
|
|
176
|
+
* reusing existing keys for every row whose relative order is unchanged
|
|
177
|
+
* (a longest increasing subsequence) and minting midpoint keys only for
|
|
178
|
+
* new or genuinely reordered rows. Untouched rows keep their stored key,
|
|
179
|
+
* so merges with forks that appended elsewhere stay row-local.
|
|
180
|
+
*
|
|
181
|
+
* Returns the key for every desired id, in desired order.
|
|
182
|
+
*/
|
|
183
|
+
export function reconcileOrderKeys(desired, existing) {
|
|
184
|
+
const survivors = desired.filter((id) => existing.has(id));
|
|
185
|
+
const byKey = [...survivors].sort((left, right) => {
|
|
186
|
+
const leftKey = existing.get(left);
|
|
187
|
+
const rightKey = existing.get(right);
|
|
188
|
+
return leftKey === rightKey ? 0 : leftKey < rightKey ? -1 : 1;
|
|
189
|
+
});
|
|
190
|
+
// Rows that share a stored key (possible after a merge) form one group;
|
|
191
|
+
// the kept set is a longest strictly increasing subsequence of group
|
|
192
|
+
// ranks, so kept keys always leave room for midpoint insertion.
|
|
193
|
+
const distinctKeys = [...new Set(byKey.map((id) => existing.get(id)))];
|
|
194
|
+
const groupRank = new Map(distinctKeys.map((key, rank) => [key, rank]));
|
|
195
|
+
const keptIndices = longestIncreasingSubsequence(survivors.map((id) => groupRank.get(existing.get(id))));
|
|
196
|
+
const kept = new Set();
|
|
197
|
+
for (const index of keptIndices)
|
|
198
|
+
kept.add(survivors[index]);
|
|
199
|
+
const keptInOrder = byKey.filter((id) => kept.has(id));
|
|
200
|
+
const result = new Map();
|
|
201
|
+
let keptIndex = 0;
|
|
202
|
+
let previous = null;
|
|
203
|
+
for (const id of desired) {
|
|
204
|
+
if (kept.has(id)) {
|
|
205
|
+
const key = existing.get(id);
|
|
206
|
+
result.set(id, key);
|
|
207
|
+
previous = key;
|
|
208
|
+
keptIndex += 1;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
// Duplicate stored keys (possible after a merge) can leave no room
|
|
212
|
+
// before the next kept neighbor; skip ahead to the first kept key
|
|
213
|
+
// that is strictly greater than the previously assigned key.
|
|
214
|
+
let next = null;
|
|
215
|
+
for (let index = keptIndex; index < keptInOrder.length; index += 1) {
|
|
216
|
+
const candidate = existing.get(keptInOrder[index]);
|
|
217
|
+
if (previous === null || candidate > previous) {
|
|
218
|
+
next = candidate;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const key = orderKeyBetween(previous, next);
|
|
223
|
+
result.set(id, key);
|
|
224
|
+
previous = key;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
/** Indices of a longest strictly increasing subsequence of `sequence`. */
|
|
230
|
+
function longestIncreasingSubsequence(sequence) {
|
|
231
|
+
const tails = [];
|
|
232
|
+
const previousIndex = Array.from({ length: sequence.length }, () => -1);
|
|
233
|
+
for (let index = 0; index < sequence.length; index += 1) {
|
|
234
|
+
let low = 0;
|
|
235
|
+
let high = tails.length;
|
|
236
|
+
while (low < high) {
|
|
237
|
+
const middle = (low + high) >> 1;
|
|
238
|
+
if (sequence[tails[middle]] < sequence[index]) {
|
|
239
|
+
low = middle + 1;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
high = middle;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (low > 0)
|
|
246
|
+
previousIndex[index] = tails[low - 1];
|
|
247
|
+
if (low === tails.length) {
|
|
248
|
+
tails.push(index);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
tails[low] = index;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const result = new Set();
|
|
255
|
+
let index = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
256
|
+
while (index >= 0) {
|
|
257
|
+
result.add(index);
|
|
258
|
+
index = previousIndex[index];
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=order-keys.js.map
|