notations 1.0.2 → 1.0.4
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/dist/notations.umd.js +3933 -12155
- package/dist/notations.umd.min.js +2 -3
- package/dist/notations.umd.min.js.map +1 -1
- package/lib/cjs/parser.js +1 -1
- package/lib/cjs/parser.js.map +1 -1
- package/lib/cjs/web/components/DockViewPlayground.d.ts +51 -0
- package/lib/cjs/web/components/DockViewPlayground.js +364 -0
- package/lib/cjs/web/components/DockViewPlayground.js.map +1 -0
- package/lib/cjs/web/components/NotationBlock.d.ts +35 -0
- package/lib/cjs/web/components/NotationBlock.js +219 -0
- package/lib/cjs/web/components/NotationBlock.js.map +1 -0
- package/lib/cjs/web/components/NotebookCell.d.ts +41 -0
- package/lib/cjs/web/components/NotebookCell.js +269 -0
- package/lib/cjs/web/components/NotebookCell.js.map +1 -0
- package/lib/cjs/web/components/NotebookView.d.ts +37 -0
- package/lib/cjs/web/components/NotebookView.js +379 -0
- package/lib/cjs/web/components/NotebookView.js.map +1 -0
- package/lib/cjs/web/components/SideBySideEditor.d.ts +47 -0
- package/lib/cjs/web/components/SideBySideEditor.js +171 -0
- package/lib/cjs/web/components/SideBySideEditor.js.map +1 -0
- package/lib/cjs/web/dockview.d.ts +2 -0
- package/lib/cjs/web/dockview.js +11 -0
- package/lib/cjs/web/dockview.js.map +1 -0
- package/lib/cjs/web/index.d.ts +8 -0
- package/lib/cjs/web/index.js +34 -0
- package/lib/cjs/web/index.js.map +1 -0
- package/lib/cjs/web/types/notebook.d.ts +64 -0
- package/lib/cjs/web/types/notebook.js +56 -0
- package/lib/cjs/web/types/notebook.js.map +1 -0
- package/lib/cjs/web/utils/cellFactory.d.ts +16 -0
- package/lib/cjs/web/utils/cellFactory.js +137 -0
- package/lib/cjs/web/utils/cellFactory.js.map +1 -0
- package/lib/cjs/web/utils/sourceSerializer.d.ts +19 -0
- package/lib/cjs/web/utils/sourceSerializer.js +162 -0
- package/lib/cjs/web/utils/sourceSerializer.js.map +1 -0
- package/lib/esm/parser.js +1 -1
- package/lib/esm/parser.js.map +1 -1
- package/lib/esm/web/components/DockViewPlayground.d.ts +51 -0
- package/lib/esm/web/components/DockViewPlayground.js +358 -0
- package/lib/esm/web/components/DockViewPlayground.js.map +1 -0
- package/lib/esm/web/components/NotationBlock.d.ts +35 -0
- package/lib/esm/web/components/NotationBlock.js +216 -0
- package/lib/esm/web/components/NotationBlock.js.map +1 -0
- package/lib/esm/web/components/NotebookCell.d.ts +41 -0
- package/lib/esm/web/components/NotebookCell.js +266 -0
- package/lib/esm/web/components/NotebookCell.js.map +1 -0
- package/lib/esm/web/components/NotebookView.d.ts +37 -0
- package/lib/esm/web/components/NotebookView.js +376 -0
- package/lib/esm/web/components/NotebookView.js.map +1 -0
- package/lib/esm/web/components/SideBySideEditor.d.ts +47 -0
- package/lib/esm/web/components/SideBySideEditor.js +168 -0
- package/lib/esm/web/components/SideBySideEditor.js.map +1 -0
- package/lib/esm/web/dockview.d.ts +2 -0
- package/lib/esm/web/dockview.js +3 -0
- package/lib/esm/web/dockview.js.map +1 -0
- package/lib/esm/web/index.d.ts +8 -0
- package/lib/esm/web/index.js +9 -0
- package/lib/esm/web/index.js.map +1 -0
- package/lib/esm/web/types/notebook.d.ts +64 -0
- package/lib/esm/web/types/notebook.js +50 -0
- package/lib/esm/web/types/notebook.js.map +1 -0
- package/lib/esm/web/utils/cellFactory.d.ts +16 -0
- package/lib/esm/web/utils/cellFactory.js +127 -0
- package/lib/esm/web/utils/cellFactory.js.map +1 -0
- package/lib/esm/web/utils/sourceSerializer.d.ts +19 -0
- package/lib/esm/web/utils/sourceSerializer.js +154 -0
- package/lib/esm/web/utils/sourceSerializer.js.map +1 -0
- package/package.json +41 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { isBlock, isLine, isRawBlock } from "../../block";
|
|
2
|
+
const DEFAULT_OPTIONS = {
|
|
3
|
+
indent: " ",
|
|
4
|
+
lineSeparator: "\n",
|
|
5
|
+
preserveUnmodified: true,
|
|
6
|
+
};
|
|
7
|
+
export function serializeCells(cells, options = {}) {
|
|
8
|
+
const opts = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
|
|
9
|
+
const parts = [];
|
|
10
|
+
for (const cell of cells) {
|
|
11
|
+
const serialized = serializeCell(cell, 0, opts);
|
|
12
|
+
if (serialized) {
|
|
13
|
+
parts.push(serialized);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return parts.join(opts.lineSeparator + opts.lineSeparator);
|
|
17
|
+
}
|
|
18
|
+
export function serializeCell(cell, depth, options) {
|
|
19
|
+
const indent = options.indent.repeat(depth);
|
|
20
|
+
if (options.preserveUnmodified && cell.source && !cell.state.hasError) {
|
|
21
|
+
if (depth === 0) {
|
|
22
|
+
return cell.source;
|
|
23
|
+
}
|
|
24
|
+
return cell.source
|
|
25
|
+
.split("\n")
|
|
26
|
+
.map((line) => indent + line)
|
|
27
|
+
.join(options.lineSeparator);
|
|
28
|
+
}
|
|
29
|
+
return serializeBlockItem(cell.blockItem, depth, options);
|
|
30
|
+
}
|
|
31
|
+
export function serializeBlockItem(item, depth, options) {
|
|
32
|
+
if (isRawBlock(item)) {
|
|
33
|
+
return serializeRawBlock(item, depth, options);
|
|
34
|
+
}
|
|
35
|
+
if (isLine(item)) {
|
|
36
|
+
return serializeLine(item, depth, options);
|
|
37
|
+
}
|
|
38
|
+
if (isBlock(item)) {
|
|
39
|
+
return serializeBlock(item, depth, options);
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
function serializeRawBlock(rawBlock, depth, options) {
|
|
44
|
+
const indent = options.indent.repeat(depth);
|
|
45
|
+
const content = rawBlock.content;
|
|
46
|
+
if (rawBlock.contentType === "md") {
|
|
47
|
+
return `${indent}---${options.lineSeparator}${content}${options.lineSeparator}${indent}---`;
|
|
48
|
+
}
|
|
49
|
+
if (rawBlock.contentType === "metadata") {
|
|
50
|
+
return `${indent}@@${content}`;
|
|
51
|
+
}
|
|
52
|
+
return content
|
|
53
|
+
.split("\n")
|
|
54
|
+
.map((line) => indent + line)
|
|
55
|
+
.join(options.lineSeparator);
|
|
56
|
+
}
|
|
57
|
+
function serializeLine(line, depth, options) {
|
|
58
|
+
const indent = options.indent.repeat(depth);
|
|
59
|
+
return `${indent}; [Line serialization not fully implemented]`;
|
|
60
|
+
}
|
|
61
|
+
function serializeBlock(block, depth, options) {
|
|
62
|
+
const indent = options.indent.repeat(depth);
|
|
63
|
+
const childIndent = options.indent.repeat(depth + 1);
|
|
64
|
+
const parts = [];
|
|
65
|
+
const header = serializeBlockHeader(block);
|
|
66
|
+
parts.push(`${indent}${header} {`);
|
|
67
|
+
for (const child of block.blockItems) {
|
|
68
|
+
const childSource = serializeBlockItem(child, depth + 1, options);
|
|
69
|
+
if (childSource) {
|
|
70
|
+
parts.push(childSource);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
parts.push(`${indent}}`);
|
|
74
|
+
return parts.join(options.lineSeparator);
|
|
75
|
+
}
|
|
76
|
+
function serializeBlockHeader(block) {
|
|
77
|
+
var _a;
|
|
78
|
+
const type = block.blockType;
|
|
79
|
+
switch (type) {
|
|
80
|
+
case "section":
|
|
81
|
+
return `\\section("${block.name || ""}")`;
|
|
82
|
+
case "repeat": {
|
|
83
|
+
const repeatCount = (_a = block.repeatCount) !== null && _a !== void 0 ? _a : 1;
|
|
84
|
+
return `\\repeat(${repeatCount})`;
|
|
85
|
+
}
|
|
86
|
+
case "cycle":
|
|
87
|
+
if (block.localCycle) {
|
|
88
|
+
return `\\cycle("${block.localCycle.toString()}")`;
|
|
89
|
+
}
|
|
90
|
+
return "\\cycle()";
|
|
91
|
+
case "beatduration":
|
|
92
|
+
if (block.localAtomsPerBeat !== null) {
|
|
93
|
+
return `\\beatDuration(${block.localAtomsPerBeat})`;
|
|
94
|
+
}
|
|
95
|
+
return "\\beatDuration(1)";
|
|
96
|
+
case "breaks":
|
|
97
|
+
if (block.localBreaks) {
|
|
98
|
+
return `\\breaks(${block.localBreaks.join(", ")})`;
|
|
99
|
+
}
|
|
100
|
+
return "\\breaks()";
|
|
101
|
+
case "role": {
|
|
102
|
+
const roleName = Array.from(block.localRoles.keys())[0] || "";
|
|
103
|
+
return `\\role("${roleName}")`;
|
|
104
|
+
}
|
|
105
|
+
case "group":
|
|
106
|
+
if (block.name) {
|
|
107
|
+
return `\\group("${block.name}")`;
|
|
108
|
+
}
|
|
109
|
+
return "\\group()";
|
|
110
|
+
case "notation":
|
|
111
|
+
return "";
|
|
112
|
+
default:
|
|
113
|
+
return `\\${type}()`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function updateCellSource(cell, newSource) {
|
|
117
|
+
return Object.assign(Object.assign({}, cell), { source: newSource });
|
|
118
|
+
}
|
|
119
|
+
export function validateCellSource(source) {
|
|
120
|
+
let braceCount = 0;
|
|
121
|
+
for (const char of source) {
|
|
122
|
+
if (char === "{")
|
|
123
|
+
braceCount++;
|
|
124
|
+
if (char === "}")
|
|
125
|
+
braceCount--;
|
|
126
|
+
if (braceCount < 0) {
|
|
127
|
+
return {
|
|
128
|
+
isValid: false,
|
|
129
|
+
error: "Unmatched closing brace",
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (braceCount !== 0) {
|
|
134
|
+
return {
|
|
135
|
+
isValid: false,
|
|
136
|
+
error: "Unmatched opening brace",
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return { isValid: true };
|
|
140
|
+
}
|
|
141
|
+
export function findCellSourceRange(cell, fullSource) {
|
|
142
|
+
if (isRawBlock(cell.blockItem)) {
|
|
143
|
+
const rawBlock = cell.blockItem;
|
|
144
|
+
const start = fullSource.indexOf(rawBlock.content);
|
|
145
|
+
if (start >= 0) {
|
|
146
|
+
return {
|
|
147
|
+
start,
|
|
148
|
+
end: start + rawBlock.content.length,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=sourceSerializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceSerializer.js","sourceRoot":"","sources":["../../../../src/web/utils/sourceSerializer.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA0B1D,MAAM,eAAe,GAAsB;IACzC,MAAM,EAAE,IAAI;IACZ,aAAa,EAAE,IAAI;IACnB,kBAAkB,EAAE,IAAI;CACzB,CAAC;AASF,MAAM,UAAU,cAAc,CAAC,KAAkB,EAAE,UAA6B,EAAE;IAChF,MAAM,IAAI,mCAAQ,eAAe,GAAK,OAAO,CAAE,CAAC;IAChD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QAChD,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAc,GAAG,IAAI,CAAC,aAAc,CAAC,CAAC;AAC/D,CAAC;AAUD,MAAM,UAAU,aAAa,CAAC,IAAe,EAAE,KAAa,EAAE,OAA0B;IACtF,MAAM,MAAM,GAAG,OAAO,CAAC,MAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAG7C,IAAI,OAAO,CAAC,kBAAkB,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAEtE,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;QAED,OAAO,IAAI,CAAC,MAAM;aACf,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U,gBAAgB,CAAC,IAAe,EAAE,SAAiB;IACjE,uCACK,IAAI,KACP,MAAM,EAAE,SAAS,IACjB;AACJ,CAAC;AAQD,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAQ/C,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,IAAI,IAAI,KAAK,GAAG;YAAE,UAAU,EAAE,CAAC;QAC/B,IAAI,IAAI,KAAK,GAAG;YAAE,UAAU,EAAE,CAAC;QAC/B,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACnB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,yBAAyB;aACjC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,yBAAyB;SACjC,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC;AAWD,MAAM,UAAU,mBAAmB,CAAC,IAAe,EAAE,UAAkB;IAIrE,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAqB,CAAC;QAC5C,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACnD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;YACf,OAAO;gBACL,KAAK;gBACL,GAAG,EAAE,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM;aACrC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["/**\n * Source serializer for converting CellModel trees back to notation source.\n *\n * This module handles serializing edited cells back into notation source text,\n * preserving formatting and structure where possible.\n */\n\nimport type { BlockItem, Block, RawBlock } from \"../../block\";\nimport type { Line } from \"../../core\";\nimport { isBlock, isLine, isRawBlock } from \"../../block\";\nimport { CellModel } from \"../types/notebook\";\n\n/**\n * Options for source serialization.\n */\nexport interface SerializerOptions {\n /**\n * Indentation string to use for nested blocks.\n * @default \" \" (two spaces)\n */\n indent?: string;\n\n /**\n * Line separator.\n * @default \"\\n\"\n */\n lineSeparator?: string;\n\n /**\n * Whether to preserve original source for unmodified cells.\n * @default true\n */\n preserveUnmodified?: boolean;\n}\n\nconst DEFAULT_OPTIONS: SerializerOptions = {\n indent: \" \",\n lineSeparator: \"\\n\",\n preserveUnmodified: true,\n};\n\n/**\n * Serializes a cell tree back to notation source.\n *\n * @param cells The cell models to serialize\n * @param options Serialization options\n * @returns The serialized notation source\n */\nexport function serializeCells(cells: CellModel[], options: SerializerOptions = {}): string {\n const opts = { ...DEFAULT_OPTIONS, ...options };\n const parts: string[] = [];\n\n for (const cell of cells) {\n const serialized = serializeCell(cell, 0, opts);\n if (serialized) {\n parts.push(serialized);\n }\n }\n\n return parts.join(opts.lineSeparator! + opts.lineSeparator!);\n}\n\n/**\n * Serializes a single cell to source.\n *\n * @param cell The cell to serialize\n * @param depth The current nesting depth\n * @param options Serialization options\n * @returns The serialized source\n */\nexport function serializeCell(cell: CellModel, depth: number, options: SerializerOptions): string {\n const indent = options.indent!.repeat(depth);\n\n // If preserving unmodified and cell has source, use it directly\n if (options.preserveUnmodified && cell.source && !cell.state.hasError) {\n // For top-level cells, return source as-is\n if (depth === 0) {\n return cell.source;\n }\n // For nested cells, indent each line\n return cell.source\n .split(\"\\n\")\n .map((line) => indent + line)\n .join(options.lineSeparator!);\n }\n\n // Otherwise, serialize from the block item\n return serializeBlockItem(cell.blockItem, depth, options);\n}\n\n/**\n * Serializes a BlockItem to source.\n *\n * @param item The block item to serialize\n * @param depth The current nesting depth\n * @param options Serialization options\n * @returns The serialized source\n */\nexport function serializeBlockItem(item: BlockItem, depth: number, options: SerializerOptions): string {\n if (isRawBlock(item)) {\n return serializeRawBlock(item as RawBlock, depth, options);\n }\n\n if (isLine(item)) {\n return serializeLine(item as Line, depth, options);\n }\n\n if (isBlock(item)) {\n return serializeBlock(item as Block, depth, options);\n }\n\n return \"\";\n}\n\n/**\n * Serializes a RawBlock to source.\n */\nfunction serializeRawBlock(rawBlock: RawBlock, depth: number, options: SerializerOptions): string {\n const indent = options.indent!.repeat(depth);\n const content = rawBlock.content;\n\n // Determine wrapper based on content type\n if (rawBlock.contentType === \"md\") {\n // Markdown content uses triple backtick or raw syntax\n return `${indent}---${options.lineSeparator}${content}${options.lineSeparator}${indent}---`;\n }\n\n if (rawBlock.contentType === \"metadata\") {\n // Metadata reference\n return `${indent}@@${content}`;\n }\n\n // Default: plain text or other content\n return content\n .split(\"\\n\")\n .map((line) => indent + line)\n .join(options.lineSeparator!);\n}\n\n/**\n * Serializes a Line to source.\n *\n * Note: This is a simplified serialization. Full Line serialization\n * would need to reconstruct atoms, spaces, embellishments, etc.\n */\nfunction serializeLine(line: Line, depth: number, options: SerializerOptions): string {\n const indent = options.indent!.repeat(depth);\n\n // For now, return a placeholder\n // Full implementation would iterate through line.atoms and serialize each\n // This would require significant work to reconstruct the DSL syntax\n return `${indent}; [Line serialization not fully implemented]`;\n}\n\n/**\n * Serializes a Block to source.\n */\nfunction serializeBlock(block: Block, depth: number, options: SerializerOptions): string {\n const indent = options.indent!.repeat(depth);\n const childIndent = options.indent!.repeat(depth + 1);\n const parts: string[] = [];\n\n // Block header\n const header = serializeBlockHeader(block);\n parts.push(`${indent}${header} {`);\n\n // Children\n for (const child of block.blockItems) {\n const childSource = serializeBlockItem(child, depth + 1, options);\n if (childSource) {\n parts.push(childSource);\n }\n }\n\n // Closing brace\n parts.push(`${indent}}`);\n\n return parts.join(options.lineSeparator!);\n}\n\n/**\n * Serializes a block header (command with parameters).\n */\nfunction serializeBlockHeader(block: Block): string {\n const type = block.blockType;\n\n switch (type) {\n case \"section\":\n return `\\\\section(\"${block.name || \"\"}\")`;\n\n case \"repeat\": {\n // RepeatBlock has repeatCount property\n const repeatCount = (block as any).repeatCount ?? 1;\n return `\\\\repeat(${repeatCount})`;\n }\n\n case \"cycle\":\n // CycleBlock has localCycle\n if (block.localCycle) {\n return `\\\\cycle(\"${block.localCycle.toString()}\")`;\n }\n return \"\\\\cycle()\";\n\n case \"beatduration\":\n if (block.localAtomsPerBeat !== null) {\n return `\\\\beatDuration(${block.localAtomsPerBeat})`;\n }\n return \"\\\\beatDuration(1)\";\n\n case \"breaks\":\n if (block.localBreaks) {\n return `\\\\breaks(${block.localBreaks.join(\", \")})`;\n }\n return \"\\\\breaks()\";\n\n case \"role\": {\n // Get first role name from localRoles\n const roleName = Array.from(block.localRoles.keys())[0] || \"\";\n return `\\\\role(\"${roleName}\")`;\n }\n\n case \"group\":\n if (block.name) {\n return `\\\\group(\"${block.name}\")`;\n }\n return \"\\\\group()\";\n\n case \"notation\":\n // Root notation block has no header\n return \"\";\n\n default:\n return `\\\\${type}()`;\n }\n}\n\n/**\n * Updates a cell's source and marks it as modified.\n *\n * @param cell The cell to update\n * @param newSource The new source text\n * @returns A new CellModel with updated source\n */\nexport function updateCellSource(cell: CellModel, newSource: string): CellModel {\n return {\n ...cell,\n source: newSource,\n };\n}\n\n/**\n * Validates cell source by attempting to parse it.\n *\n * @param source The source to validate\n * @returns Object with isValid flag and optional error message\n */\nexport function validateCellSource(source: string): {\n isValid: boolean;\n error?: string;\n} {\n // For now, just check for basic syntax issues\n // Full validation would require the notation parser\n\n // Check for balanced braces\n let braceCount = 0;\n for (const char of source) {\n if (char === \"{\") braceCount++;\n if (char === \"}\") braceCount--;\n if (braceCount < 0) {\n return {\n isValid: false,\n error: \"Unmatched closing brace\",\n };\n }\n }\n\n if (braceCount !== 0) {\n return {\n isValid: false,\n error: \"Unmatched opening brace\",\n };\n }\n\n return { isValid: true };\n}\n\n/**\n * Extracts the source range for a cell from full notation source.\n * This is a best-effort function that tries to find the cell's content\n * in the original source.\n *\n * @param cell The cell to find\n * @param fullSource The full notation source\n * @returns Source range or null if not found\n */\nexport function findCellSourceRange(cell: CellModel, fullSource: string): { start: number; end: number } | null {\n // This is a simplified implementation\n // Full implementation would need source position tracking in the parser\n\n if (isRawBlock(cell.blockItem)) {\n const rawBlock = cell.blockItem as RawBlock;\n const start = fullSource.indexOf(rawBlock.content);\n if (start >= 0) {\n return {\n start,\n end: start + rawBlock.content.length,\n };\n }\n }\n\n return null;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notations",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"author": "Sriram Panyam",
|
|
5
5
|
"description": "A package for modelling, parsing, laying out carnatic musical notation",
|
|
6
6
|
"homepage": "https://github.com/panyam/notations#readme",
|
|
@@ -8,6 +8,25 @@
|
|
|
8
8
|
"main": "./lib/cjs/index.js",
|
|
9
9
|
"module": "./lib/esm/index.js",
|
|
10
10
|
"types": "lib/cjs/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/esm/index.d.ts",
|
|
14
|
+
"import": "./lib/esm/index.js",
|
|
15
|
+
"require": "./lib/cjs/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./web": {
|
|
18
|
+
"types": "./lib/esm/web/index.d.ts",
|
|
19
|
+
"import": "./lib/esm/web/index.js",
|
|
20
|
+
"require": "./lib/cjs/web/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./web/dockview": {
|
|
23
|
+
"types": "./lib/esm/web/dockview.d.ts",
|
|
24
|
+
"import": "./lib/esm/web/dockview.js",
|
|
25
|
+
"require": "./lib/cjs/web/dockview.js"
|
|
26
|
+
},
|
|
27
|
+
"./styles/*": "./styles/*",
|
|
28
|
+
"./dist/*": "./dist/*"
|
|
29
|
+
},
|
|
11
30
|
"files": [
|
|
12
31
|
"lib/",
|
|
13
32
|
"styles/",
|
|
@@ -29,12 +48,22 @@
|
|
|
29
48
|
"@lume/kiwi": "^0.4.4",
|
|
30
49
|
"@panyam/tsutils": "*",
|
|
31
50
|
"galore": "*",
|
|
51
|
+
"tlex": "*",
|
|
32
52
|
"yaml": "^2.8.2"
|
|
33
53
|
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"dockview-core": "^4.0.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"dockview-core": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
34
62
|
"devDependencies": {
|
|
35
63
|
"@babel/core": "^7.26.10",
|
|
36
64
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
37
65
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
66
|
+
"@babel/preset-env": "^7.23.0",
|
|
38
67
|
"@babel/preset-flow": "^7.25.9",
|
|
39
68
|
"@babel/preset-typescript": "^7.27.0",
|
|
40
69
|
"@eslint/js": "^9.39.2",
|
|
@@ -49,11 +78,15 @@
|
|
|
49
78
|
"babel-loader": "^10.0.0",
|
|
50
79
|
"babel-preset-env": "^1.7.0",
|
|
51
80
|
"browserify": "17.0.1",
|
|
81
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
52
82
|
"codecov": "^3.8.3",
|
|
83
|
+
"css-loader": "^7.1.2",
|
|
84
|
+
"dockview-core": "^4.13.1",
|
|
53
85
|
"eslint": "^9.39.2",
|
|
54
86
|
"eslint-config-prettier": "^10.1.8",
|
|
55
87
|
"eslint-plugin-prettier": "^5.5.4",
|
|
56
88
|
"highlight.js": "11.11.1",
|
|
89
|
+
"html-webpack-plugin": "^5.5.3",
|
|
57
90
|
"jest": "^29.7.0",
|
|
58
91
|
"jest-each": "^29.7.0",
|
|
59
92
|
"jest-environment-jsdom": "^29.7.0",
|
|
@@ -64,7 +97,11 @@
|
|
|
64
97
|
"pre-commit": "^1.2.2",
|
|
65
98
|
"prettier": "^3.5.3",
|
|
66
99
|
"sass": "^1.97.1",
|
|
100
|
+
"sass-loader": "^16.0.6",
|
|
101
|
+
"stream-browserify": "^3.0.0",
|
|
102
|
+
"style-loader": "^4.0.0",
|
|
67
103
|
"ts-jest": "^29.3.1",
|
|
104
|
+
"ts-loader": "^9.5.0",
|
|
68
105
|
"typedoc": "^0.28.2",
|
|
69
106
|
"typescript": "^5.8.3",
|
|
70
107
|
"typescript-eslint": "^8.51.0",
|
|
@@ -86,6 +123,9 @@
|
|
|
86
123
|
"buildbase": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
|
|
87
124
|
"build:css": "mkdir -p dist && sass styles/NotationView.scss dist/NotationView.css --style=expanded && sass styles/NotationView.scss dist/NotationView.min.css --style=compressed",
|
|
88
125
|
"build:umd": "webpack --mode=development && webpack --mode=production",
|
|
126
|
+
"build:docs": "webpack --config docs/webpack.config.js --mode production",
|
|
127
|
+
"build:docs:dev": "webpack --config docs/webpack.config.js --mode development",
|
|
128
|
+
"build:docs:watch": "webpack --config docs/webpack.config.js --mode development --watch",
|
|
89
129
|
"build": "npm run builddocs && npm run buildbase && npm run build:css && npm run build:umd",
|
|
90
130
|
"test": "jest --coverage --runInBand",
|
|
91
131
|
"lint": "eslint src --quiet",
|