@kerebron/extension-dev-toolkit 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +26 -11
  2. package/esm/editor/src/CoreEditor.d.ts +13 -4
  3. package/esm/editor/src/CoreEditor.d.ts.map +1 -1
  4. package/esm/editor/src/CoreEditor.js +64 -12
  5. package/esm/editor/src/Extension.d.ts +6 -1
  6. package/esm/editor/src/Extension.d.ts.map +1 -1
  7. package/esm/editor/src/Extension.js +21 -1
  8. package/esm/editor/src/ExtensionManager.d.ts +5 -6
  9. package/esm/editor/src/ExtensionManager.d.ts.map +1 -1
  10. package/esm/editor/src/ExtensionManager.js +43 -55
  11. package/esm/editor/src/Mark.d.ts +3 -0
  12. package/esm/editor/src/Mark.d.ts.map +1 -1
  13. package/esm/editor/src/Mark.js +11 -0
  14. package/esm/editor/src/Node.d.ts +5 -2
  15. package/esm/editor/src/Node.d.ts.map +1 -1
  16. package/esm/editor/src/Node.js +13 -2
  17. package/esm/editor/src/commands/CommandManager.d.ts +13 -6
  18. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -1
  19. package/esm/editor/src/commands/CommandManager.js +59 -2
  20. package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
  21. package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
  22. package/esm/editor/src/commands/baseCommandFactories.js +836 -0
  23. package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
  24. package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
  25. package/esm/editor/src/commands/keyCommandFactories.js +10 -0
  26. package/esm/editor/src/commands/mod.d.ts +5 -53
  27. package/esm/editor/src/commands/mod.d.ts.map +1 -1
  28. package/esm/editor/src/commands/mod.js +14 -821
  29. package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
  30. package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
  31. package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
  32. package/esm/editor/src/commands/types.d.ts +18 -0
  33. package/esm/editor/src/commands/types.d.ts.map +1 -0
  34. package/esm/editor/src/commands/types.js +1 -0
  35. package/esm/editor/src/mod.d.ts +2 -0
  36. package/esm/editor/src/mod.d.ts.map +1 -1
  37. package/esm/editor/src/mod.js +2 -0
  38. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
  39. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
  40. package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
  41. package/esm/editor/src/types.d.ts +19 -1
  42. package/esm/editor/src/types.d.ts.map +1 -1
  43. package/esm/editor/src/ui.d.ts +15 -0
  44. package/esm/editor/src/ui.d.ts.map +1 -0
  45. package/esm/editor/src/ui.js +16 -0
  46. package/esm/editor/src/utilities/SmartOutput.d.ts +9 -7
  47. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -1
  48. package/esm/editor/src/utilities/SmartOutput.js +35 -20
  49. package/package.json +1 -1
@@ -0,0 +1,3 @@
1
+ import type { CommandFactory } from './mod.js';
2
+ export declare const replaceCommandFactories: Record<string, CommandFactory>;
3
+ //# sourceMappingURL=replaceCommandFactories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replaceCommandFactories.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/commands/replaceCommandFactories.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,cAAc,EAAE,MAAM,UAAU,CAAC;AAwHxD,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAMlE,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { Fragment, Slice } from 'prosemirror-model';
2
+ const replaceRangeText = (range, text) => {
3
+ return (state, dispatch) => {
4
+ const tr = state.tr;
5
+ const from = tr.mapping.map(range.from);
6
+ const to = tr.mapping.map(range.to);
7
+ const frag = Fragment.from(state.schema.text(text));
8
+ const insert = new Slice(frag, 0, 0);
9
+ tr.replace(from, to, insert);
10
+ if (dispatch) {
11
+ dispatch(tr);
12
+ }
13
+ return true;
14
+ };
15
+ };
16
+ const replaceRangeSlice = (range, insert) => {
17
+ return (state, dispatch) => {
18
+ const tr = state.tr;
19
+ const from = tr.mapping.map(range.from);
20
+ const to = tr.mapping.map(range.to);
21
+ tr.replace(from, to, insert);
22
+ if (dispatch) {
23
+ dispatch(tr);
24
+ }
25
+ return true;
26
+ };
27
+ };
28
+ function getTopMostBlockStartForOffset(state, offset) {
29
+ const { doc } = state;
30
+ const $pos = doc.resolve(offset);
31
+ const blockPos = $pos.before($pos.depth);
32
+ if ($pos.depth === 1)
33
+ return blockPos;
34
+ return $pos.start(1);
35
+ }
36
+ function getTopMostBlockEndForOffset(state, offset) {
37
+ const { doc } = state;
38
+ const $pos = doc.resolve(offset);
39
+ return $pos.end(1);
40
+ }
41
+ function getAdjacentTopBlock(state, offset) {
42
+ const { doc } = state;
43
+ if (offset < 0 || offset > doc.content.size) {
44
+ throw new RangeError('Offset is outside the document');
45
+ }
46
+ const $pos = doc.resolve(offset);
47
+ const atBlockStart = $pos.pos === $pos.start($pos.depth);
48
+ if (atBlockStart) {
49
+ return getTopMostBlockStartForOffset(state, offset);
50
+ }
51
+ else {
52
+ return getTopMostBlockEndForOffset(state, offset);
53
+ }
54
+ }
55
+ const insertBlockBefore = (pos, insert) => {
56
+ return (state, dispatch) => {
57
+ const tr = state.tr;
58
+ const blockPos = getTopMostBlockStartForOffset(state, tr.mapping.map(pos));
59
+ tr.insert(blockPos, insert);
60
+ if (dispatch) {
61
+ dispatch(tr);
62
+ }
63
+ return true;
64
+ };
65
+ };
66
+ const insertBlockAfter = (pos, insert) => {
67
+ return (state, dispatch) => {
68
+ const tr = state.tr;
69
+ const blockPos = getTopMostBlockEndForOffset(state, tr.mapping.map(pos));
70
+ tr.insert(blockPos, insert);
71
+ if (dispatch) {
72
+ dispatch(tr);
73
+ }
74
+ return true;
75
+ };
76
+ };
77
+ const insertBlockSmart = (pos, insert) => {
78
+ return (state, dispatch) => {
79
+ const tr = state.tr;
80
+ const blockPos = getAdjacentTopBlock(state, tr.mapping.map(pos));
81
+ tr.insert(blockPos, insert);
82
+ if (dispatch) {
83
+ dispatch(tr);
84
+ }
85
+ return true;
86
+ };
87
+ };
88
+ export const replaceCommandFactories = {
89
+ replaceRangeText,
90
+ replaceRangeSlice,
91
+ insertBlockBefore,
92
+ insertBlockAfter,
93
+ insertBlockSmart,
94
+ };
@@ -0,0 +1,18 @@
1
+ import type { Command } from 'prosemirror-state';
2
+ export { Command };
3
+ export type CommandFactory = (...args: any[]) => Command;
4
+ export interface Commands {
5
+ [name: string]: Command;
6
+ }
7
+ export interface CommandFactories {
8
+ [name: string]: CommandFactory;
9
+ }
10
+ export type CommandShortcuts = {
11
+ [name: string]: string;
12
+ };
13
+ export type ChainedCommands = {
14
+ [Item in keyof Commands]: (...args: unknown[]) => ChainedCommands;
15
+ } & {
16
+ run: () => boolean;
17
+ };
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/commands/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC;AAEzD,MAAM,WAAW,QAAQ;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC/B,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAAC;CAChC;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,eAAe,GACvB;KACC,IAAI,IAAI,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,eAAe;CAClE,GACC;IACA,GAAG,EAAE,MAAM,OAAO,CAAC;CACpB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -4,4 +4,6 @@ export * from './Mark.js';
4
4
  export * from './Node.js';
5
5
  export * from './nodeToTreeString.js';
6
6
  export * from './types.js';
7
+ export * from './utilities/SmartOutput.js';
8
+ export * from './ui.js';
7
9
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/editor/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/editor/src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC"}
@@ -4,3 +4,5 @@ export * from './Mark.js';
4
4
  export * from './Node.js';
5
5
  export * from './nodeToTreeString.js';
6
6
  export * from './types.js';
7
+ export * from './utilities/SmartOutput.js';
8
+ export * from './ui.js';
@@ -0,0 +1,6 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import type { CoreEditor } from '../mod.js';
3
+ export declare class TrackSelecionPlugin extends Plugin {
4
+ constructor(editor: CoreEditor);
5
+ }
6
+ //# sourceMappingURL=TrackSelecionPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TrackSelecionPlugin.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/plugins/TrackSelecionPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,qBAAa,mBAAoB,SAAQ,MAAM;gBACjC,MAAM,EAAE,UAAU;CAsB/B"}
@@ -0,0 +1,24 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ export class TrackSelecionPlugin extends Plugin {
3
+ constructor(editor) {
4
+ super({
5
+ view(editorView) {
6
+ return {
7
+ update(view, prevState) {
8
+ const state = view.state;
9
+ const prevSelection = prevState.selection;
10
+ const selection = state.selection;
11
+ if (!prevSelection.eq(selection)) {
12
+ const event = new CustomEvent('selection', {
13
+ detail: {
14
+ selection,
15
+ },
16
+ });
17
+ editor.dispatchEvent(event);
18
+ }
19
+ },
20
+ };
21
+ },
22
+ });
23
+ }
24
+ }
@@ -7,11 +7,14 @@ export type AnyExtensionOrReq = AnyExtension | {
7
7
  requires: Array<AnyExtensionOrReq | string>;
8
8
  };
9
9
  export type Content = JSONContent | JSONContent[] | null;
10
- export interface EditorOptions {
10
+ export interface EditorConfig {
11
11
  element: HTMLElement;
12
12
  content: Content;
13
13
  parseOptions: ParseOptions;
14
14
  extensions: AnyExtensionOrReq[];
15
+ cdnUrl?: string;
16
+ uri?: string;
17
+ languageID?: string;
15
18
  topNode?: string;
16
19
  }
17
20
  export type JSONContent = {
@@ -31,4 +34,19 @@ export type Attribute<T> = {
31
34
  default: T;
32
35
  toDom?: (node: ProseMirrorNode) => T;
33
36
  };
37
+ export interface TextRange {
38
+ from: number;
39
+ to: number;
40
+ }
41
+ export interface RawTextMapEntry {
42
+ nodeIdx: number;
43
+ targetRow: number;
44
+ targetCol: number;
45
+ sourceCol?: number;
46
+ targetPos: number;
47
+ }
48
+ export interface RawTextResult {
49
+ content: string;
50
+ rawTextMap: Array<RawTextMapEntry>;
51
+ }
34
52
  //# sourceMappingURL=types.d.ts.map
@@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AG,CAAC,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,EAAE,CAAC;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,CAAC,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;CACpC"}
@@ -0,0 +1,15 @@
1
+ import type { CoreEditor } from './CoreEditor.js';
2
+ interface SelectParams {
3
+ anchor: number;
4
+ scrollIntoView: boolean;
5
+ userEvent: string;
6
+ }
7
+ export interface EditorUi {
8
+ showMessage(msg: string): void;
9
+ showError(err: Error): void;
10
+ focus(): void;
11
+ select(params: SelectParams): void;
12
+ }
13
+ export declare function defaultUi(editor: CoreEditor): EditorUi;
14
+ export {};
15
+ //# sourceMappingURL=ui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../../../src/editor/src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,UAAU,YAAY;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC;IAC5B,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;CACpC;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,QAAQ,CAmBtD"}
@@ -0,0 +1,16 @@
1
+ export function defaultUi(editor) {
2
+ return {
3
+ showMessage(msg) {
4
+ globalThis.alert(msg);
5
+ },
6
+ showError(err) {
7
+ globalThis.alert(err.message);
8
+ console.error(err);
9
+ },
10
+ focus() {
11
+ // editor.run.focus();
12
+ },
13
+ select({ anchor: number, scrollIntoView: boolean, userEvent: string, }) {
14
+ },
15
+ };
16
+ }
@@ -1,7 +1,8 @@
1
1
  export interface OutputMeta<K> {
2
+ pos: number;
2
3
  rowPos: number;
3
4
  colPos: number;
4
- item: K;
5
+ item?: K;
5
6
  }
6
7
  interface Mapping {
7
8
  sourceNo: number;
@@ -20,20 +21,21 @@ export interface SourceMap {
20
21
  export declare class SmartOutput<K> {
21
22
  private _rowPos;
22
23
  private _colPos;
24
+ private _pos;
23
25
  private chunks;
24
26
  private metas;
25
- log(text: string, item: K): void;
27
+ log(text: string, item?: K): void;
28
+ getMetas(): OutputMeta<K>[];
26
29
  get chunkPos(): number;
27
30
  rollback(pos: number): void;
28
31
  get rowPos(): number;
29
32
  get colPos(): number;
33
+ get pos(): number;
30
34
  endsWith(text: string): boolean;
31
35
  toString(): string;
32
- getSourceMap(mapper: (item: K, rowPos: number, colPos: number) => Mapping | void): SourceMap;
36
+ getSourceMap(mapper: (rowPos: number, colPos: number, pos: number, item?: K) => Mapping | void): SourceMap;
33
37
  }
34
- /** @param {string} string */
35
- export declare function decode(string: any): number[];
36
- /** @param {number | number[]} value */
37
- export declare function encode(value: any): string;
38
+ export declare function decode(string: string): number[];
39
+ export declare function encode(value: number | number[]): string;
38
40
  export {};
39
41
  //# sourceMappingURL=SmartOutput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SmartOutput.d.ts","sourceRoot":"","sources":["../../../../src/editor/src/utilities/SmartOutput.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;CACT;AAED,UAAU,OAAO;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,CAAC,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,WAAW,CAAC,CAAC;IACxB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAK;IAEpB,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,KAAK,CAA4B;IAEzC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAiBzB,IAAI,QAAQ,WAEX;IAED,QAAQ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,CAA4B;IAEzC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC;IAyB1B,QAAQ;IAIR,IAAI,QAAQ,WAEX;IAED,QAAQ,CAAC,GAAG,EAAE,MAAM;IAKpB,IAAI,MAAM,WAET;IAED,IAAI,MAAM,WAET;IAED,IAAI,GAAG,WAEN;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM;IAIrB,QAAQ;IAIR,YAAY,CACV,MAAM,EAAE,CACN,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,CAAC,KACL,OAAO,GAAG,IAAI,GAClB,SAAS;CA4Db;AAuDD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,YAoCpC;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,UAW9C"}
@@ -12,6 +12,12 @@ export class SmartOutput {
12
12
  writable: true,
13
13
  value: 0
14
14
  });
15
+ Object.defineProperty(this, "_pos", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: 0
20
+ });
15
21
  Object.defineProperty(this, "chunks", {
16
22
  enumerable: true,
17
23
  configurable: true,
@@ -26,8 +32,12 @@ export class SmartOutput {
26
32
  });
27
33
  }
28
34
  log(text, item) {
35
+ if (text.length === 0) {
36
+ return;
37
+ }
29
38
  this.chunks.push(text);
30
39
  this.metas.push({
40
+ pos: this._pos,
31
41
  colPos: this._colPos,
32
42
  rowPos: this._rowPos,
33
43
  item,
@@ -40,6 +50,10 @@ export class SmartOutput {
40
50
  this._rowPos += lines.length - 1;
41
51
  this._colPos = lines[lines.length - 1].length;
42
52
  }
53
+ this._pos += text.length;
54
+ }
55
+ getMetas() {
56
+ return this.metas;
43
57
  }
44
58
  get chunkPos() {
45
59
  return this.chunks.length;
@@ -54,6 +68,9 @@ export class SmartOutput {
54
68
  get colPos() {
55
69
  return this._colPos;
56
70
  }
71
+ get pos() {
72
+ return this._pos;
73
+ }
57
74
  endsWith(text) {
58
75
  return this.chunks.join('').endsWith(text);
59
76
  }
@@ -64,20 +81,31 @@ export class SmartOutput {
64
81
  const mappingRows = [];
65
82
  let lastRow = -1;
66
83
  let lastCol = -1;
84
+ let prevSourceNo = 0;
85
+ let prevSourceRowPos = 0;
86
+ let prevSourceColPos = 0;
87
+ let prevColPos = 0;
67
88
  for (const meta of this.metas) {
68
89
  while (meta.rowPos >= mappingRows.length) {
69
90
  mappingRows.push([]);
70
91
  }
71
92
  if (lastRow != meta.rowPos || lastCol != meta.colPos) {
72
93
  const currentRow = mappingRows[meta.rowPos];
73
- const mapping = mapper(meta.item, meta.rowPos, meta.colPos);
94
+ if (lastRow != meta.rowPos) {
95
+ prevColPos = 0;
96
+ }
97
+ const mapping = mapper(meta.rowPos, meta.colPos, meta.pos, meta.item);
74
98
  if (mapping) {
75
99
  currentRow.push([
76
- meta.colPos,
77
- mapping.sourceNo,
78
- mapping.sourceRowPos,
79
- mapping.sourceColPos,
100
+ meta.colPos - prevColPos,
101
+ mapping.sourceNo - prevSourceNo,
102
+ mapping.sourceRowPos - prevSourceRowPos,
103
+ mapping.sourceColPos - prevSourceColPos,
80
104
  ]);
105
+ prevColPos = meta.colPos;
106
+ prevSourceNo = mapping.sourceNo;
107
+ prevSourceRowPos = mapping.sourceRowPos;
108
+ prevSourceColPos = mapping.sourceColPos;
81
109
  }
82
110
  }
83
111
  lastRow = meta.rowPos;
@@ -87,13 +115,6 @@ export class SmartOutput {
87
115
  .map((row) => row.map((group) => encode(group))
88
116
  .join(','))
89
117
  .join(';');
90
- mappingRows.forEach((row, rowNo) => {
91
- // console.log('g', rowNo, row);
92
- row.forEach((group) => {
93
- const enc = encode(group);
94
- // console.log('g', rowNo, group, enc, decode(enc));
95
- });
96
- });
97
118
  return {
98
119
  version: 3,
99
120
  file: '',
@@ -139,19 +160,15 @@ function encodeVLQ(input) {
139
160
  }
140
161
  return result;
141
162
  }
142
- /** @type {Record<string, number>} */
143
- let char_to_integer = {};
144
- /** @type {Record<number, string>} */
145
- let integer_to_char = {};
163
+ const char_to_integer = {};
164
+ const integer_to_char = {};
146
165
  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
147
166
  .split('')
148
167
  .forEach(function (char, i) {
149
168
  char_to_integer[char] = i;
150
169
  integer_to_char[i] = char;
151
170
  });
152
- /** @param {string} string */
153
171
  export function decode(string) {
154
- /** @type {number[]} */
155
172
  let result = [];
156
173
  let shift = 0;
157
174
  let value = 0;
@@ -181,7 +198,6 @@ export function decode(string) {
181
198
  }
182
199
  return result;
183
200
  }
184
- /** @param {number | number[]} value */
185
201
  export function encode(value) {
186
202
  if (typeof value === 'number') {
187
203
  return encode_integer(value);
@@ -192,7 +208,6 @@ export function encode(value) {
192
208
  }
193
209
  return result;
194
210
  }
195
- /** @param {number} num */
196
211
  function encode_integer(num) {
197
212
  let result = '';
198
213
  if (num < 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/extension-dev-toolkit",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "module": "./esm/extension-dev-toolkit/src/mod.js",
6
6
  "exports": {