openalgo-script 0.2.0 → 0.5.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.
- package/CHANGELOG.md +1198 -0
- package/README.md +127 -40
- package/dist/adapters/charts/driving.d.ts +50 -0
- package/dist/adapters/charts/driving.d.ts.map +1 -0
- package/dist/adapters/charts/driving.js +57 -0
- package/dist/adapters/charts/driving.js.map +1 -0
- package/dist/adapters/charts/run.d.ts +20 -0
- package/dist/adapters/charts/run.d.ts.map +1 -1
- package/dist/adapters/charts/run.js +83 -16
- package/dist/adapters/charts/run.js.map +1 -1
- package/dist/adapters/charts/surfaces.d.ts +17 -0
- package/dist/adapters/charts/surfaces.d.ts.map +1 -1
- package/dist/adapters/charts/tables.js +82 -0
- package/dist/adapters/charts/tables.js.map +1 -1
- package/dist/adapters/charts/venue.d.ts +73 -0
- package/dist/adapters/charts/venue.d.ts.map +1 -0
- package/dist/adapters/charts/venue.js +104 -0
- package/dist/adapters/charts/venue.js.map +1 -0
- package/dist/adapters/codemirror/commands.d.ts +14 -0
- package/dist/adapters/codemirror/commands.d.ts.map +1 -0
- package/dist/adapters/codemirror/commands.js +52 -0
- package/dist/adapters/codemirror/commands.js.map +1 -0
- package/dist/adapters/codemirror/completion.d.ts +15 -0
- package/dist/adapters/codemirror/completion.d.ts.map +1 -0
- package/dist/adapters/codemirror/completion.js +64 -0
- package/dist/adapters/codemirror/completion.js.map +1 -0
- package/dist/adapters/codemirror/contract.d.ts +156 -0
- package/dist/adapters/codemirror/contract.d.ts.map +1 -0
- package/dist/adapters/codemirror/contract.js +42 -0
- package/dist/adapters/codemirror/contract.js.map +1 -0
- package/dist/adapters/codemirror/index.d.ts +43 -0
- package/dist/adapters/codemirror/index.d.ts.map +1 -0
- package/dist/adapters/codemirror/index.js +8 -0
- package/dist/adapters/codemirror/index.js.map +1 -0
- package/dist/adapters/codemirror/lint.d.ts +17 -0
- package/dist/adapters/codemirror/lint.d.ts.map +1 -0
- package/dist/adapters/codemirror/lint.js +62 -0
- package/dist/adapters/codemirror/lint.js.map +1 -0
- package/dist/adapters/codemirror/positions.d.ts +16 -0
- package/dist/adapters/codemirror/positions.d.ts.map +1 -0
- package/dist/adapters/codemirror/positions.js +65 -0
- package/dist/adapters/codemirror/positions.js.map +1 -0
- package/dist/adapters/codemirror/stream.d.ts +23 -0
- package/dist/adapters/codemirror/stream.d.ts.map +1 -0
- package/dist/adapters/codemirror/stream.js +70 -0
- package/dist/adapters/codemirror/stream.js.map +1 -0
- package/dist/adapters/codemirror/tokens.d.ts +44 -0
- package/dist/adapters/codemirror/tokens.d.ts.map +1 -0
- package/dist/adapters/codemirror/tokens.js +34 -0
- package/dist/adapters/codemirror/tokens.js.map +1 -0
- package/dist/adapters/codemirror/tooltips.d.ts +35 -0
- package/dist/adapters/codemirror/tooltips.d.ts.map +1 -0
- package/dist/adapters/codemirror/tooltips.js +108 -0
- package/dist/adapters/codemirror/tooltips.js.map +1 -0
- package/dist/core/accounting/analysis.d.ts +111 -0
- package/dist/core/accounting/analysis.d.ts.map +1 -0
- package/dist/core/accounting/analysis.js +123 -0
- package/dist/core/accounting/analysis.js.map +1 -0
- package/dist/core/accounting/charges.d.ts +136 -0
- package/dist/core/accounting/charges.d.ts.map +1 -0
- package/dist/core/accounting/charges.js +362 -0
- package/dist/core/accounting/charges.js.map +1 -0
- package/dist/core/accounting/equity.d.ts +191 -0
- package/dist/core/accounting/equity.d.ts.map +1 -0
- package/dist/core/accounting/equity.js +167 -0
- package/dist/core/accounting/equity.js.map +1 -0
- package/dist/core/accounting/index.d.ts +46 -0
- package/dist/core/accounting/index.d.ts.map +1 -0
- package/dist/core/accounting/index.js +37 -0
- package/dist/core/accounting/index.js.map +1 -0
- package/dist/core/accounting/markers.d.ts +43 -0
- package/dist/core/accounting/markers.d.ts.map +1 -0
- package/dist/core/accounting/markers.js +64 -0
- package/dist/core/accounting/markers.js.map +1 -0
- package/dist/core/accounting/monthly.d.ts +52 -0
- package/dist/core/accounting/monthly.d.ts.map +1 -0
- package/dist/core/accounting/monthly.js +99 -0
- package/dist/core/accounting/monthly.js.map +1 -0
- package/dist/core/accounting/report.d.ts +41 -0
- package/dist/core/accounting/report.d.ts.map +1 -0
- package/dist/core/accounting/report.js +65 -0
- package/dist/core/accounting/report.js.map +1 -0
- package/dist/core/accounting/shapes.d.ts +70 -0
- package/dist/core/accounting/shapes.d.ts.map +1 -0
- package/dist/core/accounting/shapes.js +21 -0
- package/dist/core/accounting/shapes.js.map +1 -0
- package/dist/core/accounting/statistics.d.ts +87 -0
- package/dist/core/accounting/statistics.d.ts.map +1 -0
- package/dist/core/accounting/statistics.js +268 -0
- package/dist/core/accounting/statistics.js.map +1 -0
- package/dist/core/accounting/trades.d.ts +118 -0
- package/dist/core/accounting/trades.d.ts.map +1 -0
- package/dist/core/accounting/trades.js +186 -0
- package/dist/core/accounting/trades.js.map +1 -0
- package/dist/core/backtest/case.d.ts +60 -0
- package/dist/core/backtest/case.d.ts.map +1 -0
- package/dist/core/backtest/case.js +319 -0
- package/dist/core/backtest/case.js.map +1 -0
- package/dist/core/backtest/compare.d.ts +38 -0
- package/dist/core/backtest/compare.d.ts.map +1 -0
- package/dist/core/backtest/compare.js +191 -0
- package/dist/core/backtest/compare.js.map +1 -0
- package/dist/core/backtest/declaration.d.ts +52 -0
- package/dist/core/backtest/declaration.d.ts.map +1 -0
- package/dist/core/backtest/declaration.js +48 -0
- package/dist/core/backtest/declaration.js.map +1 -0
- package/dist/core/backtest/deliver.d.ts +93 -0
- package/dist/core/backtest/deliver.d.ts.map +1 -0
- package/dist/core/backtest/deliver.js +94 -0
- package/dist/core/backtest/deliver.js.map +1 -0
- package/dist/core/backtest/drive.d.ts +87 -0
- package/dist/core/backtest/drive.d.ts.map +1 -0
- package/dist/core/backtest/drive.js +312 -0
- package/dist/core/backtest/drive.js.map +1 -0
- package/dist/core/backtest/index.d.ts +58 -0
- package/dist/core/backtest/index.d.ts.map +1 -0
- package/dist/core/backtest/index.js +47 -0
- package/dist/core/backtest/index.js.map +1 -0
- package/dist/core/backtest/range.d.ts +84 -0
- package/dist/core/backtest/range.d.ts.map +1 -0
- package/dist/core/backtest/range.js +90 -0
- package/dist/core/backtest/range.js.map +1 -0
- package/dist/core/backtest/record.d.ts +299 -0
- package/dist/core/backtest/record.d.ts.map +1 -0
- package/dist/core/backtest/record.js +243 -0
- package/dist/core/backtest/record.js.map +1 -0
- package/dist/core/backtest/replay.d.ts +48 -0
- package/dist/core/backtest/replay.d.ts.map +1 -0
- package/dist/core/backtest/replay.js +137 -0
- package/dist/core/backtest/replay.js.map +1 -0
- package/dist/core/backtest/resting.d.ts +62 -0
- package/dist/core/backtest/resting.d.ts.map +1 -0
- package/dist/core/backtest/resting.js +59 -0
- package/dist/core/backtest/resting.js.map +1 -0
- package/dist/core/backtest/settings.d.ts +117 -0
- package/dist/core/backtest/settings.d.ts.map +1 -0
- package/dist/core/backtest/settings.js +207 -0
- package/dist/core/backtest/settings.js.map +1 -0
- package/dist/core/backtest/simulate.d.ts +258 -0
- package/dist/core/backtest/simulate.d.ts.map +1 -0
- package/dist/core/backtest/simulate.js +335 -0
- package/dist/core/backtest/simulate.js.map +1 -0
- package/dist/core/catalogue/catalogue.generated.d.ts +66 -0
- package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
- package/dist/core/catalogue/catalogue.generated.js +6 -0
- package/dist/core/catalogue/catalogue.generated.js.map +1 -1
- package/dist/core/catalogue/values.generated.d.ts +24 -0
- package/dist/core/catalogue/values.generated.d.ts.map +1 -1
- package/dist/core/check/index.d.ts +2 -1
- package/dist/core/check/index.d.ts.map +1 -1
- package/dist/core/check/index.js +1 -1
- package/dist/core/check/index.js.map +1 -1
- package/dist/core/check/library-orders.js +2 -2
- package/dist/core/check/library-orders.js.map +1 -1
- package/dist/core/check/library-prose.generated.d.ts +16 -0
- package/dist/core/check/library-prose.generated.d.ts.map +1 -0
- package/dist/core/check/library-prose.generated.js +353 -0
- package/dist/core/check/library-prose.generated.js.map +1 -0
- package/dist/core/check/surface.d.ts +24 -0
- package/dist/core/check/surface.d.ts.map +1 -1
- package/dist/core/check/surface.js +29 -0
- package/dist/core/check/surface.js.map +1 -1
- package/dist/core/emit/canonical.d.ts +22 -8
- package/dist/core/emit/canonical.d.ts.map +1 -1
- package/dist/core/emit/canonical.js +67 -6
- package/dist/core/emit/canonical.js.map +1 -1
- package/dist/core/emit/defaults.d.ts +35 -16
- package/dist/core/emit/defaults.d.ts.map +1 -1
- package/dist/core/emit/defaults.js +66 -0
- package/dist/core/emit/defaults.js.map +1 -1
- package/dist/core/emit/index.d.ts +2 -0
- package/dist/core/emit/index.d.ts.map +1 -1
- package/dist/core/emit/index.js +2 -0
- package/dist/core/emit/index.js.map +1 -1
- package/dist/core/engine/arithmetic.d.ts +6 -25
- package/dist/core/engine/arithmetic.d.ts.map +1 -1
- package/dist/core/engine/arithmetic.js +48 -3
- package/dist/core/engine/arithmetic.js.map +1 -1
- package/dist/core/engine/index.d.ts +2 -2
- package/dist/core/engine/index.d.ts.map +1 -1
- package/dist/core/engine/index.js +2 -2
- package/dist/core/engine/index.js.map +1 -1
- package/dist/core/engine/library/arrays.d.ts.map +1 -1
- package/dist/core/engine/library/arrays.js +8 -2
- package/dist/core/engine/library/arrays.js.map +1 -1
- package/dist/core/engine/library/code-points.d.ts +40 -0
- package/dist/core/engine/library/code-points.d.ts.map +1 -0
- package/dist/core/engine/library/code-points.js +74 -0
- package/dist/core/engine/library/code-points.js.map +1 -0
- package/dist/core/engine/library/index.d.ts +5 -0
- package/dist/core/engine/library/index.d.ts.map +1 -1
- package/dist/core/engine/library/index.js +5 -0
- package/dist/core/engine/library/index.js.map +1 -1
- package/dist/core/engine/library/text.d.ts.map +1 -1
- package/dist/core/engine/library/text.js +51 -34
- package/dist/core/engine/library/text.js.map +1 -1
- package/dist/core/engine/load.d.ts +35 -1
- package/dist/core/engine/load.d.ts.map +1 -1
- package/dist/core/engine/load.js +63 -0
- package/dist/core/engine/load.js.map +1 -1
- package/dist/core/engine/verify-tables.d.ts.map +1 -1
- package/dist/core/engine/verify-tables.js +41 -0
- package/dist/core/engine/verify-tables.js.map +1 -1
- package/dist/core/index.d.ts +43 -4
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +23 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/stdlib/index.d.ts +1 -1
- package/dist/core/stdlib/index.d.ts.map +1 -1
- package/dist/core/stdlib/index.js +1 -1
- package/dist/core/stdlib/index.js.map +1 -1
- package/dist/core/stdlib/maths/index.d.ts +1 -1
- package/dist/core/stdlib/maths/index.d.ts.map +1 -1
- package/dist/core/stdlib/maths/index.js +1 -1
- package/dist/core/stdlib/maths/index.js.map +1 -1
- package/dist/core/stdlib/maths/rounding.d.ts +5 -0
- package/dist/core/stdlib/maths/rounding.d.ts.map +1 -1
- package/dist/core/stdlib/maths/rounding.js +19 -1
- package/dist/core/stdlib/maths/rounding.js.map +1 -1
- package/dist/core/version/version.generated.d.ts +1 -1
- package/dist/core/version/version.generated.js +1 -1
- package/dist/editor/complete.d.ts +40 -0
- package/dist/editor/complete.d.ts.map +1 -0
- package/dist/editor/complete.js +206 -0
- package/dist/editor/complete.js.map +1 -0
- package/dist/editor/diagnose.d.ts +18 -0
- package/dist/editor/diagnose.d.ts.map +1 -0
- package/dist/editor/diagnose.js +70 -0
- package/dist/editor/diagnose.js.map +1 -0
- package/dist/editor/format.d.ts +11 -0
- package/dist/editor/format.d.ts.map +1 -0
- package/dist/editor/format.js +50 -0
- package/dist/editor/format.js.map +1 -0
- package/dist/editor/highlight.d.ts +28 -0
- package/dist/editor/highlight.d.ts.map +1 -0
- package/dist/editor/highlight.js +65 -0
- package/dist/editor/highlight.js.map +1 -0
- package/dist/editor/hover.d.ts +40 -0
- package/dist/editor/hover.d.ts.map +1 -0
- package/dist/editor/hover.js +147 -0
- package/dist/editor/hover.js.map +1 -0
- package/dist/editor/index.d.ts +60 -0
- package/dist/editor/index.d.ts.map +1 -0
- package/dist/editor/index.js +7 -0
- package/dist/editor/index.js.map +1 -0
- package/dist/editor/kinds.d.ts +27 -0
- package/dist/editor/kinds.d.ts.map +1 -0
- package/dist/editor/kinds.js +118 -0
- package/dist/editor/kinds.js.map +1 -0
- package/dist/editor/layout.d.ts +47 -0
- package/dist/editor/layout.d.ts.map +1 -0
- package/dist/editor/layout.js +135 -0
- package/dist/editor/layout.js.map +1 -0
- package/dist/editor/manifest.d.ts +47 -0
- package/dist/editor/manifest.d.ts.map +1 -0
- package/dist/editor/manifest.js +93 -0
- package/dist/editor/manifest.js.map +1 -0
- package/dist/editor/reading.d.ts +41 -0
- package/dist/editor/reading.d.ts.map +1 -0
- package/dist/editor/reading.js +51 -0
- package/dist/editor/reading.js.map +1 -0
- package/dist/editor/scan.d.ts +26 -0
- package/dist/editor/scan.d.ts.map +1 -0
- package/dist/editor/scan.js +139 -0
- package/dist/editor/scan.js.map +1 -0
- package/dist/editor/scope.d.ts +19 -0
- package/dist/editor/scope.d.ts.map +1 -0
- package/dist/editor/scope.js +99 -0
- package/dist/editor/scope.js.map +1 -0
- package/dist/editor/signature.d.ts +38 -0
- package/dist/editor/signature.d.ts.map +1 -0
- package/dist/editor/signature.js +112 -0
- package/dist/editor/signature.js.map +1 -0
- package/dist/editor/site.d.ts +46 -0
- package/dist/editor/site.d.ts.map +1 -0
- package/dist/editor/site.js +184 -0
- package/dist/editor/site.js.map +1 -0
- package/dist/editor/spacing.d.ts +29 -0
- package/dist/editor/spacing.d.ts.map +1 -0
- package/dist/editor/spacing.js +116 -0
- package/dist/editor/spacing.js.map +1 -0
- package/package.json +42 -3
- package/spec/README.md +2 -1
- package/spec/errors.json +141 -1
- package/src/adapters/charts/driving.ts +109 -0
- package/src/adapters/charts/run.ts +120 -28
- package/src/adapters/charts/surfaces.ts +17 -0
- package/src/adapters/charts/tables.ts +88 -0
- package/src/adapters/charts/venue.ts +132 -0
- package/src/adapters/codemirror/commands.ts +53 -0
- package/src/adapters/codemirror/completion.ts +74 -0
- package/src/adapters/codemirror/contract.ts +156 -0
- package/src/adapters/codemirror/index.ts +66 -0
- package/src/adapters/codemirror/lint.ts +66 -0
- package/src/adapters/codemirror/positions.ts +79 -0
- package/src/adapters/codemirror/stream.ts +87 -0
- package/src/adapters/codemirror/tokens.ts +64 -0
- package/src/adapters/codemirror/tooltips.ts +113 -0
- package/src/core/accounting/analysis.ts +188 -0
- package/src/core/accounting/charges.ts +452 -0
- package/src/core/accounting/equity.ts +314 -0
- package/src/core/accounting/index.ts +51 -0
- package/src/core/accounting/markers.ts +95 -0
- package/src/core/accounting/monthly.ts +137 -0
- package/src/core/accounting/report.ts +94 -0
- package/src/core/accounting/shapes.ts +73 -0
- package/src/core/accounting/statistics.ts +387 -0
- package/src/core/accounting/trades.ts +313 -0
- package/src/core/backtest/case.ts +395 -0
- package/src/core/backtest/compare.ts +246 -0
- package/src/core/backtest/declaration.ts +97 -0
- package/src/core/backtest/deliver.ts +161 -0
- package/src/core/backtest/drive.ts +468 -0
- package/src/core/backtest/index.ts +64 -0
- package/src/core/backtest/range.ts +137 -0
- package/src/core/backtest/record.ts +470 -0
- package/src/core/backtest/replay.ts +168 -0
- package/src/core/backtest/resting.ts +125 -0
- package/src/core/backtest/settings.ts +280 -0
- package/src/core/backtest/simulate.ts +499 -0
- package/src/core/catalogue/catalogue.generated.ts +6 -0
- package/src/core/catalogue/values.generated.ts +6 -0
- package/src/core/check/index.ts +3 -0
- package/src/core/check/library-orders.ts +2 -2
- package/src/core/check/library-prose.generated.ts +367 -0
- package/src/core/check/surface.ts +34 -0
- package/src/core/emit/canonical.ts +67 -9
- package/src/core/emit/defaults.ts +70 -0
- package/src/core/emit/index.ts +2 -0
- package/src/core/engine/arithmetic.ts +23 -3
- package/src/core/engine/index.ts +2 -2
- package/src/core/engine/library/arrays.ts +8 -2
- package/src/core/engine/library/code-points.ts +73 -0
- package/src/core/engine/library/index.ts +6 -0
- package/src/core/engine/library/text.ts +53 -35
- package/src/core/engine/load.ts +84 -2
- package/src/core/engine/verify-tables.ts +43 -0
- package/src/core/index.ts +100 -2
- package/src/core/stdlib/index.ts +1 -0
- package/src/core/stdlib/maths/index.ts +1 -0
- package/src/core/stdlib/maths/rounding.ts +23 -1
- package/src/core/version/version.generated.ts +1 -1
- package/src/editor/complete.ts +266 -0
- package/src/editor/diagnose.ts +71 -0
- package/src/editor/format.ts +85 -0
- package/src/editor/highlight.ts +110 -0
- package/src/editor/hover.ts +199 -0
- package/src/editor/index.ts +65 -0
- package/src/editor/kinds.ts +157 -0
- package/src/editor/layout.ts +189 -0
- package/src/editor/manifest.ts +119 -0
- package/src/editor/reading.ts +69 -0
- package/src/editor/scan.ts +162 -0
- package/src/editor/scope.ts +122 -0
- package/src/editor/signature.ts +150 -0
- package/src/editor/site.ts +233 -0
- package/src/editor/spacing.ts +132 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surfaces.d.ts","sourceRoot":"","sources":["../../../src/adapters/charts/surfaces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1F,2EAA2E;AAC3E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,EAAE,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpE;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,WAAW,GACX,YAAY,GACZ,cAAc,GACd,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,OAAO,GACP,MAAM,GACN,SAAS,GACT,WAAW,GACX,MAAM,CAAC;AAEX,sDAAsD;AACt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AAY,CAAC,CAAC,KAAK,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAChD,oBAAoB,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAChF"}
|
|
@@ -47,9 +47,91 @@ function oneTable(declared, lookup, written) {
|
|
|
47
47
|
position: CORNERS[position] ?? 'top-right',
|
|
48
48
|
borderWidth: numberField(declared.options.borderWidth, lookup, 0),
|
|
49
49
|
...(bgColour === undefined ? {} : { background: cssColour(bgColour) }),
|
|
50
|
+
...(cols > 0 ? { cellWidth: columnWidths(grid, cols) } : {}),
|
|
51
|
+
// The chart measures the text it is about to draw and shrinks it to fit,
|
|
52
|
+
// which is the half of this that cannot be done from here.
|
|
53
|
+
fontSize: 'auto',
|
|
50
54
|
},
|
|
51
55
|
};
|
|
52
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* How wide each column has to be, in media pixels.
|
|
59
|
+
*
|
|
60
|
+
* The chart's default is one width for every column, chosen without seeing the
|
|
61
|
+
* text, and a grid whose header says "Moving averages" over cells saying
|
|
62
|
+
* "RSI: 27.22" has one column bleeding into the next. Nothing downstream can
|
|
63
|
+
* choose better, because by the time the chart has the grid it has lost which
|
|
64
|
+
* cells belong together; and nothing upstream can, because the script declares
|
|
65
|
+
* a size and writes text, not a layout.
|
|
66
|
+
*
|
|
67
|
+
* **This is an estimate, and it is allowed to be.** A real width needs the font
|
|
68
|
+
* the chart will draw with, and only the chart has it. So the width is counted
|
|
69
|
+
* off the characters and the chart's own `fontSize: 'auto'` corrects whatever
|
|
70
|
+
* this gets wrong: too narrow and the type shrinks a little, too wide and the
|
|
71
|
+
* column is a little loose. Either is a table that reads. The failure this
|
|
72
|
+
* replaces was neither.
|
|
73
|
+
*
|
|
74
|
+
* Delete it when the chart can size a column from its own measurements. It
|
|
75
|
+
* exists because that is not a thing it can be asked to do yet.
|
|
76
|
+
*/
|
|
77
|
+
function columnWidths(grid, cols) {
|
|
78
|
+
const widths = [];
|
|
79
|
+
for (let col = 0; col < cols; col += 1) {
|
|
80
|
+
let widest = 0;
|
|
81
|
+
for (const row of grid) {
|
|
82
|
+
const text = row[col]?.text ?? '';
|
|
83
|
+
if (text.length > 0)
|
|
84
|
+
widest = Math.max(widest, textWidth(text));
|
|
85
|
+
}
|
|
86
|
+
widths.push(Math.min(MAX_COLUMN, Math.max(MIN_COLUMN, Math.ceil(widest) + CELL_PADDING * 2)));
|
|
87
|
+
}
|
|
88
|
+
return widths;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Roughly how wide a string is at the type size the chart starts from.
|
|
92
|
+
*
|
|
93
|
+
* Counted rather than measured, and counted in two weights rather than one: a
|
|
94
|
+
* column of "Histogram: -7.01" is half punctuation and narrow digits, and
|
|
95
|
+
* treating every character as an em-and-a-bit makes that column half again as
|
|
96
|
+
* wide as it needs to be while "Moving averages" stays too narrow. Two weights
|
|
97
|
+
* is not typography, but it is enough to tell those two apart.
|
|
98
|
+
*/
|
|
99
|
+
function textWidth(text) {
|
|
100
|
+
let width = 0;
|
|
101
|
+
for (const character of text) {
|
|
102
|
+
width += NARROW.has(character) ? BASE_SIZE * NARROW_EM : BASE_SIZE * WIDE_EM;
|
|
103
|
+
}
|
|
104
|
+
return width;
|
|
105
|
+
}
|
|
106
|
+
/** The characters that take noticeably less than an average advance. */
|
|
107
|
+
const NARROW = new Set([...' .,:;!|ijlt1IJfr()[]{}-']);
|
|
108
|
+
/**
|
|
109
|
+
* The type size the widths are counted at.
|
|
110
|
+
*
|
|
111
|
+
* The chart's own default row is 18 media pixels and it draws at 62% of the
|
|
112
|
+
* row, so this is the size a cell gets before anything shrinks it. Counting at
|
|
113
|
+
* a larger size would reserve room the text never uses.
|
|
114
|
+
*/
|
|
115
|
+
const BASE_SIZE = 11;
|
|
116
|
+
const NARROW_EM = 0.32;
|
|
117
|
+
const WIDE_EM = 0.56;
|
|
118
|
+
/** What the chart insets a cell's text by, on each side. */
|
|
119
|
+
const CELL_PADDING = 4;
|
|
120
|
+
/**
|
|
121
|
+
* The narrowest a column is drawn.
|
|
122
|
+
*
|
|
123
|
+
* A column of one-character cells sized to its content is a sliver, and a grid
|
|
124
|
+
* of slivers reads as a rendering fault rather than as a narrow column.
|
|
125
|
+
*/
|
|
126
|
+
const MIN_COLUMN = 56;
|
|
127
|
+
/**
|
|
128
|
+
* The widest a column is drawn.
|
|
129
|
+
*
|
|
130
|
+
* A cell holding a sentence would otherwise push the grid past the pane it is
|
|
131
|
+
* pinned inside, taking the chart with it. Past this the type shrinks instead,
|
|
132
|
+
* which is the chart's job and it is better at it.
|
|
133
|
+
*/
|
|
134
|
+
const MAX_COLUMN = 220;
|
|
53
135
|
/**
|
|
54
136
|
* One written cell, or none.
|
|
55
137
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/adapters/charts/tables.ts"],"names":[],"mappings":"AAoDA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AASpE,6DAA6D;AAC7D,MAAM,OAAO,GAAiD;IAC5D,OAAO,EAAE,UAAU;IACnB,QAAQ,EAAE,WAAW;IACrB,UAAU,EAAE,aAAa;IACzB,WAAW,EAAE,cAAc;CAC5B,CAAC;AAEF,MAAM,UAAU,GAAsB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAElE;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,OAAwB,EACxB,MAAmB,EACnB,OAAwB;IAExB,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3C,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,QAAQ,CAAC,QAAQ,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I,CAAC,KAAK,KAAK,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QAC7E,CAAC,CAAE,IAAI,CAAC,KAAwB;QAChC,CAAC,CAAC,MAAM,CAAC;IACX,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC;IACrD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;QAC9D,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;QACxD,KAAK;KACN,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,SAAS,KAAK,CAAC,IAAY;IACzB,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The destination a strategy runs against when a chart draws one.
|
|
3
|
+
*
|
|
4
|
+
* **Why a chart needs one at all.** A strategy asks a destination to do things
|
|
5
|
+
* and folds its position from what comes back. Handed no destination it is
|
|
6
|
+
* refused at load with OS6006, and handed one that answers nothing it runs but
|
|
7
|
+
* never learns it is in a position: every `close()` closes nothing, every entry
|
|
8
|
+
* is allowed again on the next signal, and the study draws a strategy that is
|
|
9
|
+
* wrong about itself while looking entirely normal. Measured on a stop and
|
|
10
|
+
* reverse script, that shape produced five buys and no sells.
|
|
11
|
+
*
|
|
12
|
+
* **It is the backtest's own venue, not a second one.** `Simulator` is what
|
|
13
|
+
* `backtest()` runs against, so a chart running a strategy through it fills the
|
|
14
|
+
* same orders at the same prices as the report the trader ran a moment ago. A
|
|
15
|
+
* venue written here to be simpler would be a second answer to "what would this
|
|
16
|
+
* have filled at", and the two would disagree the first time either changed:
|
|
17
|
+
* the chart would draw one set of trades and the report would list another.
|
|
18
|
+
*
|
|
19
|
+
* **What a chart supplies and what it invents.** The bars, the instrument and
|
|
20
|
+
* the declaration are the chart's own and are passed through. Money is not: a
|
|
21
|
+
* chart draws a strategy, it does not report one, so the currency, the point
|
|
22
|
+
* value and the rounding are stated here as the neutral values that make the
|
|
23
|
+
* accounting a no-op. Nothing a chart draws reads them, and a chart that
|
|
24
|
+
* guessed a point value would put a wrong profit in front of somebody.
|
|
25
|
+
*
|
|
26
|
+
* **Nothing here decides when a fill happens.** The declaration does, through
|
|
27
|
+
* `fillOn`, and the venue reads it. A market order priced at the next bar's
|
|
28
|
+
* open is known at that open; one that rested and traded inside a bar is known
|
|
29
|
+
* once the bar is complete. Both are what a venue could have told anybody at
|
|
30
|
+
* the time, and that is the whole reason the frames arrive between bars rather
|
|
31
|
+
* than inside the execution that sent them.
|
|
32
|
+
*/
|
|
33
|
+
import { Simulator } from '../../core/backtest/index.js';
|
|
34
|
+
import type { CompiledProgram } from '../../core/emit/index.js';
|
|
35
|
+
import type { Instrument, OrderFrame, ResolvedInput, RoutedEffect } from '../../core/engine/index.js';
|
|
36
|
+
import type { ChartBar } from './contract.js';
|
|
37
|
+
/**
|
|
38
|
+
* Whether this program needs a destination before it can run at all.
|
|
39
|
+
*
|
|
40
|
+
* Read from the program's own declared capabilities rather than from whether
|
|
41
|
+
* its source said `strategy()`, because `requires` is the same fact the engine
|
|
42
|
+
* tests at load. A strategy that places no orders needs none, and anything that
|
|
43
|
+
* does need one is refused without it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function needsVenue(program: CompiledProgram): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The venue for one chart run, or nothing where the program does not need one.
|
|
48
|
+
*
|
|
49
|
+
* `inputs` are the ones the engine resolved at load, because a declaration
|
|
50
|
+
* field may be written as an `input()`: a script whose `fillOn` comes from a
|
|
51
|
+
* setting would otherwise be filled the way its source happened to be written
|
|
52
|
+
* rather than the way the trader is running it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function venueFor(program: CompiledProgram, bars: readonly ChartBar[], inputs: readonly ResolvedInput[], instrument: Instrument | undefined): Simulator | null;
|
|
55
|
+
/**
|
|
56
|
+
* A venue that can be asked for frames, held across a chart's recomputes.
|
|
57
|
+
*
|
|
58
|
+
* The bars a `Simulator` prices against are the ones it was built with, so a
|
|
59
|
+
* chart that has grown a bar needs a venue that knows about it. `extend` is how
|
|
60
|
+
* the tail path says so without rebuilding the orders it is already holding.
|
|
61
|
+
*/
|
|
62
|
+
export interface HeldVenue {
|
|
63
|
+
readonly venue: Simulator;
|
|
64
|
+
/** Frames the venue answered for a bar, waiting to be delivered before the next. */
|
|
65
|
+
pending: readonly OrderFrame[];
|
|
66
|
+
}
|
|
67
|
+
/** What a venue has to say after one bar, which the next bar's engine reads. */
|
|
68
|
+
export declare function answersFor(held: HeldVenue, barIndex: number): void;
|
|
69
|
+
/** The route an engine is loaded with, pointing at a venue built after it. */
|
|
70
|
+
export declare function routeInto(holder: {
|
|
71
|
+
current: Simulator | null;
|
|
72
|
+
}): (effect: RoutedEffect, bar: number) => void;
|
|
73
|
+
//# sourceMappingURL=venue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"venue.d.ts","sourceRoot":"","sources":["../../../src/adapters/charts/venue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAgB,SAAS,EAAiB,MAAM,8BAA8B,CAAC;AAEtF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACtG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAE5D;AAeD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,SAAS,QAAQ,EAAE,EACzB,MAAM,EAAE,SAAS,aAAa,EAAE,EAChC,UAAU,EAAE,UAAU,GAAG,SAAS,GACjC,SAAS,GAAG,IAAI,CA0BlB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,oFAAoF;IACpF,OAAO,EAAE,SAAS,UAAU,EAAE,CAAC;CAChC;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAElE;AAED,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAO5G"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The destination a strategy runs against when a chart draws one.
|
|
3
|
+
*
|
|
4
|
+
* **Why a chart needs one at all.** A strategy asks a destination to do things
|
|
5
|
+
* and folds its position from what comes back. Handed no destination it is
|
|
6
|
+
* refused at load with OS6006, and handed one that answers nothing it runs but
|
|
7
|
+
* never learns it is in a position: every `close()` closes nothing, every entry
|
|
8
|
+
* is allowed again on the next signal, and the study draws a strategy that is
|
|
9
|
+
* wrong about itself while looking entirely normal. Measured on a stop and
|
|
10
|
+
* reverse script, that shape produced five buys and no sells.
|
|
11
|
+
*
|
|
12
|
+
* **It is the backtest's own venue, not a second one.** `Simulator` is what
|
|
13
|
+
* `backtest()` runs against, so a chart running a strategy through it fills the
|
|
14
|
+
* same orders at the same prices as the report the trader ran a moment ago. A
|
|
15
|
+
* venue written here to be simpler would be a second answer to "what would this
|
|
16
|
+
* have filled at", and the two would disagree the first time either changed:
|
|
17
|
+
* the chart would draw one set of trades and the report would list another.
|
|
18
|
+
*
|
|
19
|
+
* **What a chart supplies and what it invents.** The bars, the instrument and
|
|
20
|
+
* the declaration are the chart's own and are passed through. Money is not: a
|
|
21
|
+
* chart draws a strategy, it does not report one, so the currency, the point
|
|
22
|
+
* value and the rounding are stated here as the neutral values that make the
|
|
23
|
+
* accounting a no-op. Nothing a chart draws reads them, and a chart that
|
|
24
|
+
* guessed a point value would put a wrong profit in front of somebody.
|
|
25
|
+
*
|
|
26
|
+
* **Nothing here decides when a fill happens.** The declaration does, through
|
|
27
|
+
* `fillOn`, and the venue reads it. A market order priced at the next bar's
|
|
28
|
+
* open is known at that open; one that rested and traded inside a bar is known
|
|
29
|
+
* once the bar is complete. Both are what a venue could have told anybody at
|
|
30
|
+
* the time, and that is the whole reason the frames arrive between bars rather
|
|
31
|
+
* than inside the execution that sent them.
|
|
32
|
+
*/
|
|
33
|
+
import { DEFAULT_FILL, Simulator, declarationOf } from '../../core/backtest/index.js';
|
|
34
|
+
/**
|
|
35
|
+
* Whether this program needs a destination before it can run at all.
|
|
36
|
+
*
|
|
37
|
+
* Read from the program's own declared capabilities rather than from whether
|
|
38
|
+
* its source said `strategy()`, because `requires` is the same fact the engine
|
|
39
|
+
* tests at load. A strategy that places no orders needs none, and anything that
|
|
40
|
+
* does need one is refused without it.
|
|
41
|
+
*/
|
|
42
|
+
export function needsVenue(program) {
|
|
43
|
+
return program.requires.includes('orders');
|
|
44
|
+
}
|
|
45
|
+
/** One chart bar as the venue reads it. */
|
|
46
|
+
function recorded(bar) {
|
|
47
|
+
return {
|
|
48
|
+
time: bar.time,
|
|
49
|
+
open: bar.open,
|
|
50
|
+
high: bar.high,
|
|
51
|
+
low: bar.low,
|
|
52
|
+
close: bar.close,
|
|
53
|
+
volume: bar.volume ?? null,
|
|
54
|
+
oi: bar.oi ?? null,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The venue for one chart run, or nothing where the program does not need one.
|
|
59
|
+
*
|
|
60
|
+
* `inputs` are the ones the engine resolved at load, because a declaration
|
|
61
|
+
* field may be written as an `input()`: a script whose `fillOn` comes from a
|
|
62
|
+
* setting would otherwise be filled the way its source happened to be written
|
|
63
|
+
* rather than the way the trader is running it.
|
|
64
|
+
*/
|
|
65
|
+
export function venueFor(program, bars, inputs, instrument) {
|
|
66
|
+
if (!needsVenue(program))
|
|
67
|
+
return null;
|
|
68
|
+
const declared = declarationOf(program, inputs);
|
|
69
|
+
return new Simulator({
|
|
70
|
+
bars: bars.map(recorded),
|
|
71
|
+
contract: {
|
|
72
|
+
symbol: instrument?.symbol ?? null,
|
|
73
|
+
exchange: instrument?.exchange ?? null,
|
|
74
|
+
// Neutral money. A chart draws a strategy and does not report one, so
|
|
75
|
+
// nothing it puts on screen reads these; stating a point value a host
|
|
76
|
+
// never gave would be inventing the size of somebody's position.
|
|
77
|
+
currency: declared.currency,
|
|
78
|
+
tickSize: instrument?.tickSize ?? null,
|
|
79
|
+
lotSize: null,
|
|
80
|
+
pointValue: 1,
|
|
81
|
+
digits: 2,
|
|
82
|
+
},
|
|
83
|
+
fill: DEFAULT_FILL,
|
|
84
|
+
// The declaration's own, so slippage is applied the way the backtest
|
|
85
|
+
// applies it. Ticks, against the instrument's tick size.
|
|
86
|
+
slippageTicks: declared.slippage,
|
|
87
|
+
fillOn: declared.fillOn,
|
|
88
|
+
qtyType: declared.qtyType,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** What a venue has to say after one bar, which the next bar's engine reads. */
|
|
92
|
+
export function answersFor(held, barIndex) {
|
|
93
|
+
held.pending = held.venue.framesFor(barIndex);
|
|
94
|
+
}
|
|
95
|
+
/** The route an engine is loaded with, pointing at a venue built after it. */
|
|
96
|
+
export function routeInto(holder) {
|
|
97
|
+
// Late bound on purpose. The route is handed to `load`, and the venue cannot
|
|
98
|
+
// be built until `load` has resolved the inputs the declaration reads. The
|
|
99
|
+
// route is only ever called from inside an execution, which is after both.
|
|
100
|
+
return (effect, bar) => {
|
|
101
|
+
holder.current?.route(effect, bar);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=venue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"venue.js","sourceRoot":"","sources":["../../../src/adapters/charts/venue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAMtF;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,OAAwB;IACjD,OAAO,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC;AAED,2CAA2C;AAC3C,SAAS,QAAQ,CAAC,GAAa;IAC7B,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;QAC1B,EAAE,EAAE,GAAG,CAAC,EAAE,IAAI,IAAI;KACnB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CACtB,OAAwB,EACxB,IAAyB,EACzB,MAAgC,EAChC,UAAkC;IAElC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAEtC,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAEhD,OAAO,IAAI,SAAS,CAAC;QACnB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;QACxB,QAAQ,EAAE;YACR,MAAM,EAAE,UAAU,EAAE,MAAM,IAAI,IAAI;YAClC,QAAQ,EAAE,UAAU,EAAE,QAAQ,IAAI,IAAI;YACtC,sEAAsE;YACtE,sEAAsE;YACtE,iEAAiE;YACjE,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,UAAU,EAAE,QAAQ,IAAI,IAAI;YACtC,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,CAAC;YACb,MAAM,EAAE,CAAC;SACV;QACD,IAAI,EAAE,YAAY;QAClB,qEAAqE;QACrE,yDAAyD;QACzD,aAAa,EAAE,QAAQ,CAAC,QAAQ;QAChC,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;KAC1B,CAAC,CAAC;AACL,CAAC;AAeD,gFAAgF;AAChF,MAAM,UAAU,UAAU,CAAC,IAAe,EAAE,QAAgB;IAC1D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,SAAS,CAAC,MAAqC;IAC7D,6EAA6E;IAC7E,2EAA2E;IAC3E,2EAA2E;IAC3E,OAAO,CAAC,MAAoB,EAAE,GAAW,EAAE,EAAE;QAC3C,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EditorView } from './contract.js';
|
|
2
|
+
/**
|
|
3
|
+
* Lays the document out again, and says whether anything changed.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* keymap.of([{ key: "Shift-Alt-f", run: formatDocument }])
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* False where the document is already laid out, which is what an editor command
|
|
10
|
+
* returns when it has nothing to do: the key press then falls through to
|
|
11
|
+
* whatever else is bound to it rather than being swallowed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatDocument(view: EditorView): boolean;
|
|
14
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/commands.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGhD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAaxD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Laying a script out again, as an editor command.
|
|
3
|
+
*
|
|
4
|
+
* `format` is the tier's, and the guarantee it carries is the one that makes a
|
|
5
|
+
* format button safe to put in front of somebody holding a position: laying a
|
|
6
|
+
* script out again cannot change what it computes. Every example and every gate
|
|
7
|
+
* script in the repository is formatted, both texts compiled, and the compiled
|
|
8
|
+
* programs compared field for field; and every call checks itself against the
|
|
9
|
+
* lexer, so a rule that is wrong returns the source untouched rather than a
|
|
10
|
+
* changed program.
|
|
11
|
+
*
|
|
12
|
+
* The whole document is replaced rather than a minimal edit computed. It is the
|
|
13
|
+
* honest version: a diff would have to be trusted to be equivalent to the
|
|
14
|
+
* replacement, and a formatter that moved a line somewhere unintended would do
|
|
15
|
+
* it silently. The cursor is kept where it was in the new text, clamped, because
|
|
16
|
+
* a format that sends the caret to the top of the file is a format nobody
|
|
17
|
+
* presses twice.
|
|
18
|
+
*
|
|
19
|
+
* **A document with two character line endings comes back with one character
|
|
20
|
+
* ones**, because that is what `language.md` 3.1 normalises a file to before
|
|
21
|
+
* anything reads it and what every offset in this tier indexes. It is the one
|
|
22
|
+
* change to a file's bytes that formatting makes without being asked, and it is
|
|
23
|
+
* recorded in `spec/editor-narrowings.json`.
|
|
24
|
+
*/
|
|
25
|
+
import { format } from '../../editor/index.js';
|
|
26
|
+
import { documentOf, normalisedOffset } from './positions.js';
|
|
27
|
+
/**
|
|
28
|
+
* Lays the document out again, and says whether anything changed.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* keymap.of([{ key: "Shift-Alt-f", run: formatDocument }])
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* False where the document is already laid out, which is what an editor command
|
|
35
|
+
* returns when it has nothing to do: the key press then falls through to
|
|
36
|
+
* whatever else is bound to it rather than being swallowed.
|
|
37
|
+
*/
|
|
38
|
+
export function formatDocument(view) {
|
|
39
|
+
const raw = view.state.doc.toString();
|
|
40
|
+
const held = documentOf(raw);
|
|
41
|
+
const laid = format(held.text);
|
|
42
|
+
if (laid === raw)
|
|
43
|
+
return false;
|
|
44
|
+
const at = normalisedOffset(held, view.state.selection.main.head);
|
|
45
|
+
view.dispatch({
|
|
46
|
+
changes: { from: 0, to: view.state.doc.length, insert: laid },
|
|
47
|
+
selection: { anchor: Math.min(at, laid.length) },
|
|
48
|
+
scrollIntoView: true,
|
|
49
|
+
});
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/commands.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IAE/B,MAAM,EAAE,GAAG,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClE,IAAI,CAAC,QAAQ,CAAC;QACZ,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE;QAC7D,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE;QAChD,cAAc,EAAE,IAAI;KACrB,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EditorCompletionContext, EditorCompletionResult } from './contract.js';
|
|
2
|
+
/**
|
|
3
|
+
* Every completion for the position the editor is asking about.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* autocompletion({ override: [openscriptCompletion] })
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Nothing comes back for an empty list rather than an empty list, because the
|
|
10
|
+
* editor reads the two differently: an empty result closes the panel and null
|
|
11
|
+
* lets another source answer, and a host with a snippet source of its own should
|
|
12
|
+
* keep it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function openscriptCompletion(context: EditorCompletionContext): EditorCompletionResult | null;
|
|
15
|
+
//# sourceMappingURL=completion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion.d.ts","sourceRoot":"","sources":["../../../src/adapters/codemirror/completion.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAEV,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAmBvB;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,uBAAuB,GAC/B,sBAAsB,GAAG,IAAI,CAc/B"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Completions, as the editor's completion source.
|
|
3
|
+
*
|
|
4
|
+
* The whole of the work is done by `complete`, which reads the standard library
|
|
5
|
+
* manifest, the checker's bindings and the error catalogue. What is here is the
|
|
6
|
+
* translation: the editor wants a range to replace, a list of rows, and a note
|
|
7
|
+
* about whether the list is already filtered.
|
|
8
|
+
*
|
|
9
|
+
* **The list is already filtered**, by the word the writer has typed, compared
|
|
10
|
+
* exactly, because the language's names are case sensitive. So `filter` is false
|
|
11
|
+
* and the editor is told not to filter it again: its own matcher is fuzzy and
|
|
12
|
+
* case insensitive, and running it over a list that has already answered the
|
|
13
|
+
* question would put `EMA` in front of somebody as though it compiled.
|
|
14
|
+
*
|
|
15
|
+
* **A planned call is shown and marked.** `complete` carries the catalogue's own
|
|
16
|
+
* OS2020 sentence on a planned row, so that is what goes in the row's expanded
|
|
17
|
+
* note, and the row is pushed to the bottom of the list with the editor's own
|
|
18
|
+
* boost. A host that would rather not show them at all drops them with one
|
|
19
|
+
* field, which is why they are marked rather than filtered here.
|
|
20
|
+
*/
|
|
21
|
+
import { complete } from '../../editor/index.js';
|
|
22
|
+
import { COMPLETION_TYPES } from './tokens.js';
|
|
23
|
+
/** As far down the list as the editor will move a row. */
|
|
24
|
+
const PLANNED_BOOST = -99;
|
|
25
|
+
function rowOf(one) {
|
|
26
|
+
const info = one.refusal ?? one.summary;
|
|
27
|
+
const type = COMPLETION_TYPES[one.kind];
|
|
28
|
+
return {
|
|
29
|
+
label: one.label,
|
|
30
|
+
...(type === undefined ? {} : { type }),
|
|
31
|
+
detail: one.detail,
|
|
32
|
+
...(info === undefined ? {} : { info }),
|
|
33
|
+
...(one.insert === one.label ? {} : { apply: one.insert }),
|
|
34
|
+
...(one.planned ? { boost: PLANNED_BOOST } : {}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Every completion for the position the editor is asking about.
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* autocompletion({ override: [openscriptCompletion] })
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Nothing comes back for an empty list rather than an empty list, because the
|
|
45
|
+
* editor reads the two differently: an empty result closes the panel and null
|
|
46
|
+
* lets another source answer, and a host with a snippet source of its own should
|
|
47
|
+
* keep it.
|
|
48
|
+
*/
|
|
49
|
+
export function openscriptCompletion(context) {
|
|
50
|
+
const rows = complete(context.state.doc.toString(), context.pos);
|
|
51
|
+
// The first row carries the range every row replaces, so an empty list and a
|
|
52
|
+
// list whose first row is missing are one answer: nothing. Two guards for that
|
|
53
|
+
// would be one guard and a line no test can reach.
|
|
54
|
+
const first = rows[0];
|
|
55
|
+
if (first === undefined)
|
|
56
|
+
return null;
|
|
57
|
+
return {
|
|
58
|
+
from: first.replace.offset,
|
|
59
|
+
to: first.replace.offset + first.replace.length,
|
|
60
|
+
options: rows.map(rowOf),
|
|
61
|
+
filter: false,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=completion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completion.js","sourceRoot":"","sources":["../../../src/adapters/codemirror/completion.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAOjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,0DAA0D;AAC1D,MAAM,aAAa,GAAG,CAAC,EAAE,CAAC;AAE1B,SAAS,KAAK,CAAC,GAAe;IAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,C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AAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editor component's own shapes, as this adapter targets them.
|
|
3
|
+
*
|
|
4
|
+
* **Why they are declared here rather than imported.** The editor component is a
|
|
5
|
+
* peer dependency: a host that wants a text area installs it, and a host that
|
|
6
|
+
* wants only the language must not be made to. This repository therefore does
|
|
7
|
+
* not install it, cannot type check against it, and would fail its own layering
|
|
8
|
+
* check the moment a file here imported it. It is the same decision the chart
|
|
9
|
+
* adapter took, for the same reason, and `src/adapters/charts/contract.ts` says
|
|
10
|
+
* it at length.
|
|
11
|
+
*
|
|
12
|
+
* So the shapes this produces values for are declared below and the host's own
|
|
13
|
+
* build is where the two meet. Each one is a one line check that costs a host
|
|
14
|
+
* nothing and fails to compile if this file has drifted:
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import type { StreamParser } from "<the editor's language package>";
|
|
18
|
+
* import type { CompletionSource } from "<the editor's completion package>";
|
|
19
|
+
* import type { Diagnostic } from "<the editor's lint package>";
|
|
20
|
+
*
|
|
21
|
+
* const parser: StreamParser<unknown> = openscriptStream;
|
|
22
|
+
* const source: CompletionSource = openscriptCompletion;
|
|
23
|
+
* const linter: (view: EditorView) => Diagnostic[] = openscriptLint;
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* **That line catches a value of the wrong shape and not an argument of the
|
|
27
|
+
* wrong shape.** A method's parameters are compared in both directions, so a
|
|
28
|
+
* hook declared here as taking something the editor never passes still assigns.
|
|
29
|
+
* That is the failure the chart adapter has actually made, so every member below
|
|
30
|
+
* takes the editor's own argument, spelled as the editor spells it, and every
|
|
31
|
+
* test drives each one with the argument the editor passes rather than with one
|
|
32
|
+
* of its own.
|
|
33
|
+
*
|
|
34
|
+
* **A style name is not checked by any of those lines.** The names this adapter
|
|
35
|
+
* returns from `token` are looked up by the editor in its own table of
|
|
36
|
+
* highlighting tags at run time, and an unknown one is a warning on a console
|
|
37
|
+
* rather than a compile error. That is why the whole mapping is one exported
|
|
38
|
+
* record a host can replace in a line, and why it is recorded in
|
|
39
|
+
* `spec/editor-narrowings.json` as the one thing here a type cannot hold.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* One line of the document, as the editor's tokenizer sees it.
|
|
43
|
+
*
|
|
44
|
+
* The editor hands a tokenizer a line at a time and expects `pos` to have moved
|
|
45
|
+
* forward when `token` returns. Only the members this adapter reads are
|
|
46
|
+
* declared: a narrower shape is still assignable from the editor's wider one.
|
|
47
|
+
*/
|
|
48
|
+
export interface EditorStringStream {
|
|
49
|
+
/** The line's text, without its line ending. */
|
|
50
|
+
readonly string: string;
|
|
51
|
+
/** Where the tokenizer has got to, which this adapter moves. */
|
|
52
|
+
pos: number;
|
|
53
|
+
/** Where the current token began. */
|
|
54
|
+
readonly start: number;
|
|
55
|
+
/** Whether `pos` is at the end of the line. */
|
|
56
|
+
eol(): boolean;
|
|
57
|
+
/** Whether `pos` is at the start of the line. */
|
|
58
|
+
sol(): boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A tokenizer the editor drives one line at a time.
|
|
62
|
+
*
|
|
63
|
+
* `token` returns a style name, or null for text with no style of its own. The
|
|
64
|
+
* state is the tokenizer's to define, and the editor copies it at line
|
|
65
|
+
* boundaries so that it can restart mid document, which is why `copyState` is
|
|
66
|
+
* here.
|
|
67
|
+
*/
|
|
68
|
+
export interface EditorStreamParser<State> {
|
|
69
|
+
readonly name?: string;
|
|
70
|
+
startState?(indentUnit: number): State;
|
|
71
|
+
token(stream: EditorStringStream, state: State): string | null;
|
|
72
|
+
copyState?(state: State): State;
|
|
73
|
+
blankLine?(state: State, indentUnit: number): void;
|
|
74
|
+
readonly languageData?: Readonly<Record<string, unknown>>;
|
|
75
|
+
}
|
|
76
|
+
/** The document, which the editor holds as a rope rather than as a string. */
|
|
77
|
+
export interface EditorText {
|
|
78
|
+
readonly length: number;
|
|
79
|
+
toString(): string;
|
|
80
|
+
}
|
|
81
|
+
/** The part of the editor's state this adapter reads. */
|
|
82
|
+
export interface EditorState {
|
|
83
|
+
readonly doc: EditorText;
|
|
84
|
+
readonly selection: {
|
|
85
|
+
readonly main: {
|
|
86
|
+
readonly head: number;
|
|
87
|
+
readonly from: number;
|
|
88
|
+
readonly to: number;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** The part of the editor's view this adapter reads and dispatches to. */
|
|
93
|
+
export interface EditorView {
|
|
94
|
+
readonly state: EditorState;
|
|
95
|
+
dispatch(transaction: {
|
|
96
|
+
readonly changes: {
|
|
97
|
+
readonly from: number;
|
|
98
|
+
readonly to: number;
|
|
99
|
+
readonly insert: string;
|
|
100
|
+
};
|
|
101
|
+
readonly selection?: {
|
|
102
|
+
readonly anchor: number;
|
|
103
|
+
};
|
|
104
|
+
readonly scrollIntoView?: boolean;
|
|
105
|
+
}): void;
|
|
106
|
+
}
|
|
107
|
+
/** What the editor hands a completion source. */
|
|
108
|
+
export interface EditorCompletionContext {
|
|
109
|
+
readonly state: EditorState;
|
|
110
|
+
readonly pos: number;
|
|
111
|
+
/** Whether the writer asked for completions rather than merely typing. */
|
|
112
|
+
readonly explicit: boolean;
|
|
113
|
+
}
|
|
114
|
+
/** One row of the editor's completion list. */
|
|
115
|
+
export interface EditorCompletion {
|
|
116
|
+
readonly label: string;
|
|
117
|
+
/** The editor's own name for the icon beside a row. */
|
|
118
|
+
readonly type?: string;
|
|
119
|
+
readonly detail?: string;
|
|
120
|
+
readonly info?: string;
|
|
121
|
+
/** The text to insert, where it differs from the label. */
|
|
122
|
+
readonly apply?: string;
|
|
123
|
+
/** Moves a row up or down the list, from -99 to 99. */
|
|
124
|
+
readonly boost?: number;
|
|
125
|
+
}
|
|
126
|
+
export interface EditorCompletionResult {
|
|
127
|
+
readonly from: number;
|
|
128
|
+
readonly to?: number;
|
|
129
|
+
readonly options: readonly EditorCompletion[];
|
|
130
|
+
/** False when the list is already filtered, which this adapter's is. */
|
|
131
|
+
readonly filter?: boolean;
|
|
132
|
+
}
|
|
133
|
+
/** One squiggle in the editor's lint panel and gutter. */
|
|
134
|
+
export interface EditorDiagnostic {
|
|
135
|
+
readonly from: number;
|
|
136
|
+
readonly to: number;
|
|
137
|
+
readonly severity: 'hint' | 'info' | 'warning' | 'error';
|
|
138
|
+
readonly message: string;
|
|
139
|
+
/** Where the diagnostic came from, shown beside the message. */
|
|
140
|
+
readonly source?: string;
|
|
141
|
+
readonly actions?: readonly {
|
|
142
|
+
readonly name: string;
|
|
143
|
+
apply(view: EditorView, from: number, to: number): void;
|
|
144
|
+
}[];
|
|
145
|
+
}
|
|
146
|
+
/** What the editor shows over the text, and the element it shows. */
|
|
147
|
+
export interface EditorTooltipView {
|
|
148
|
+
readonly dom: unknown;
|
|
149
|
+
}
|
|
150
|
+
export interface EditorTooltip {
|
|
151
|
+
readonly pos: number;
|
|
152
|
+
readonly end?: number;
|
|
153
|
+
readonly above?: boolean;
|
|
154
|
+
create(view: EditorView): EditorTooltipView;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=contract.d.ts.map
|