@trebco/treb 37.0.0 → 37.1.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/build/package.json +119 -0
- package/build/treb-base-types/src/api_types.d.ts +11 -0
- package/build/treb-base-types/src/api_types.js +22 -0
- package/build/treb-base-types/src/api_types.js.map +1 -0
- package/build/treb-base-types/src/area-utils.d.ts +9 -0
- package/build/treb-base-types/src/area-utils.js +50 -0
- package/build/treb-base-types/src/area-utils.js.map +1 -0
- package/build/treb-base-types/src/area.d.ts +182 -0
- package/build/treb-base-types/src/area.js +715 -0
- package/build/treb-base-types/src/area.js.map +1 -0
- package/build/treb-base-types/src/basic_types.d.ts +20 -0
- package/build/treb-base-types/src/basic_types.js +22 -0
- package/build/treb-base-types/src/basic_types.js.map +1 -0
- package/build/treb-base-types/src/cell.d.ts +167 -0
- package/build/treb-base-types/src/cell.js +432 -0
- package/build/treb-base-types/src/cell.js.map +1 -0
- package/build/treb-base-types/src/cells.d.ts +251 -0
- package/build/treb-base-types/src/cells.js +1136 -0
- package/build/treb-base-types/src/cells.js.map +1 -0
- package/build/treb-base-types/src/color.d.ts +35 -0
- package/build/treb-base-types/src/color.js +162 -0
- package/build/treb-base-types/src/color.js.map +1 -0
- package/build/treb-base-types/src/dom-utilities.d.ts +70 -0
- package/build/treb-base-types/src/dom-utilities.js +144 -0
- package/build/treb-base-types/src/dom-utilities.js.map +1 -0
- package/build/treb-base-types/src/evaluate-options.d.ts +35 -0
- package/build/treb-base-types/src/evaluate-options.js +22 -0
- package/build/treb-base-types/src/evaluate-options.js.map +1 -0
- package/build/treb-base-types/src/font-stack.d.ts +37 -0
- package/build/treb-base-types/src/font-stack.js +93 -0
- package/build/treb-base-types/src/font-stack.js.map +1 -0
- package/build/treb-base-types/src/gradient.d.ts +18 -0
- package/build/treb-base-types/src/gradient.js +86 -0
- package/build/treb-base-types/src/gradient.js.map +1 -0
- package/build/treb-base-types/src/import.d.ts +48 -0
- package/build/treb-base-types/src/import.js +22 -0
- package/build/treb-base-types/src/import.js.map +1 -0
- package/build/treb-base-types/src/index-standalone.d.ts +6 -0
- package/build/treb-base-types/src/index-standalone.js +27 -0
- package/build/treb-base-types/src/index-standalone.js.map +1 -0
- package/build/treb-base-types/src/index.d.ts +22 -0
- package/build/treb-base-types/src/index.js +45 -0
- package/build/treb-base-types/src/index.js.map +1 -0
- package/build/treb-base-types/src/layout.d.ts +22 -0
- package/build/treb-base-types/src/layout.js +22 -0
- package/build/treb-base-types/src/layout.js.map +1 -0
- package/build/treb-base-types/src/localization.d.ts +37 -0
- package/build/treb-base-types/src/localization.js +157 -0
- package/build/treb-base-types/src/localization.js.map +1 -0
- package/build/treb-base-types/src/rectangle.d.ts +51 -0
- package/build/treb-base-types/src/rectangle.js +123 -0
- package/build/treb-base-types/src/rectangle.js.map +1 -0
- package/build/treb-base-types/src/render_text.d.ts +34 -0
- package/build/treb-base-types/src/render_text.js +22 -0
- package/build/treb-base-types/src/render_text.js.map +1 -0
- package/build/treb-base-types/src/style.d.ts +214 -0
- package/build/treb-base-types/src/style.js +373 -0
- package/build/treb-base-types/src/style.js.map +1 -0
- package/build/treb-base-types/src/table.d.ts +58 -0
- package/build/treb-base-types/src/table.js +27 -0
- package/build/treb-base-types/src/table.js.map +1 -0
- package/build/treb-base-types/src/text_part.d.ts +26 -0
- package/build/treb-base-types/src/text_part.js +47 -0
- package/build/treb-base-types/src/text_part.js.map +1 -0
- package/build/treb-base-types/src/theme.d.ts +120 -0
- package/build/treb-base-types/src/theme.js +460 -0
- package/build/treb-base-types/src/theme.js.map +1 -0
- package/build/treb-base-types/src/union.d.ts +73 -0
- package/build/treb-base-types/src/union.js +61 -0
- package/build/treb-base-types/src/union.js.map +1 -0
- package/build/treb-base-types/src/value-type.d.ts +86 -0
- package/build/treb-base-types/src/value-type.js +168 -0
- package/build/treb-base-types/src/value-type.js.map +1 -0
- package/build/treb-base-types/src/worker-proxy.d.ts +95 -0
- package/build/treb-base-types/src/worker-proxy.js +221 -0
- package/build/treb-base-types/src/worker-proxy.js.map +1 -0
- package/build/treb-calculator/src/calculator.d.ts +249 -0
- package/build/treb-calculator/src/calculator.js +2755 -0
- package/build/treb-calculator/src/calculator.js.map +1 -0
- package/build/treb-calculator/src/complex-math.d.ts +75 -0
- package/build/treb-calculator/src/complex-math.js +559 -0
- package/build/treb-calculator/src/complex-math.js.map +1 -0
- package/build/treb-calculator/src/dag/array-vertex.d.ts +71 -0
- package/build/treb-calculator/src/dag/array-vertex.js +156 -0
- package/build/treb-calculator/src/dag/array-vertex.js.map +1 -0
- package/build/treb-calculator/src/dag/calculation_leaf_vertex.d.ts +48 -0
- package/build/treb-calculator/src/dag/calculation_leaf_vertex.js +84 -0
- package/build/treb-calculator/src/dag/calculation_leaf_vertex.js.map +1 -0
- package/build/treb-calculator/src/dag/graph.d.ts +134 -0
- package/build/treb-calculator/src/dag/graph.js +842 -0
- package/build/treb-calculator/src/dag/graph.js.map +1 -0
- package/build/treb-calculator/src/dag/spreadsheet_vertex.d.ts +58 -0
- package/build/treb-calculator/src/dag/spreadsheet_vertex.js +232 -0
- package/build/treb-calculator/src/dag/spreadsheet_vertex.js.map +1 -0
- package/build/treb-calculator/src/dag/spreadsheet_vertex_base.d.ts +20 -0
- package/build/treb-calculator/src/dag/spreadsheet_vertex_base.js +25 -0
- package/build/treb-calculator/src/dag/spreadsheet_vertex_base.js.map +1 -0
- package/build/treb-calculator/src/dag/state_leaf_vertex.d.ts +43 -0
- package/build/treb-calculator/src/dag/state_leaf_vertex.js +81 -0
- package/build/treb-calculator/src/dag/state_leaf_vertex.js.map +1 -0
- package/build/treb-calculator/src/dag/vertex.d.ts +71 -0
- package/build/treb-calculator/src/dag/vertex.js +274 -0
- package/build/treb-calculator/src/dag/vertex.js.map +1 -0
- package/build/treb-calculator/src/descriptors.d.ts +189 -0
- package/build/treb-calculator/src/descriptors.js +22 -0
- package/build/treb-calculator/src/descriptors.js.map +1 -0
- package/build/treb-calculator/src/expression-calculator.d.ts +127 -0
- package/build/treb-calculator/src/expression-calculator.js +1033 -0
- package/build/treb-calculator/src/expression-calculator.js.map +1 -0
- package/build/treb-calculator/src/function-error.d.ts +35 -0
- package/build/treb-calculator/src/function-error.js +85 -0
- package/build/treb-calculator/src/function-error.js.map +1 -0
- package/build/treb-calculator/src/function-library.d.ts +22 -0
- package/build/treb-calculator/src/function-library.js +96 -0
- package/build/treb-calculator/src/function-library.js.map +1 -0
- package/build/treb-calculator/src/functions/base-functions.d.ts +7 -0
- package/build/treb-calculator/src/functions/base-functions.js +2611 -0
- package/build/treb-calculator/src/functions/base-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/beta.d.ts +17 -0
- package/build/treb-calculator/src/functions/beta.js +201 -0
- package/build/treb-calculator/src/functions/beta.js.map +1 -0
- package/build/treb-calculator/src/functions/checkbox.d.ts +3 -0
- package/build/treb-calculator/src/functions/checkbox.js +128 -0
- package/build/treb-calculator/src/functions/checkbox.js.map +1 -0
- package/build/treb-calculator/src/functions/complex-functions.d.ts +2 -0
- package/build/treb-calculator/src/functions/complex-functions.js +217 -0
- package/build/treb-calculator/src/functions/complex-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/date-utils.d.ts +3 -0
- package/build/treb-calculator/src/functions/date-utils.js +59 -0
- package/build/treb-calculator/src/functions/date-utils.js.map +1 -0
- package/build/treb-calculator/src/functions/finance-functions.d.ts +2 -0
- package/build/treb-calculator/src/functions/finance-functions.js +547 -0
- package/build/treb-calculator/src/functions/finance-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/fp.d.ts +2 -0
- package/build/treb-calculator/src/functions/fp.js +463 -0
- package/build/treb-calculator/src/functions/fp.js.map +1 -0
- package/build/treb-calculator/src/functions/function-utilities.d.ts +2 -0
- package/build/treb-calculator/src/functions/function-utilities.js +36 -0
- package/build/treb-calculator/src/functions/function-utilities.js.map +1 -0
- package/build/treb-calculator/src/functions/gamma.d.ts +20 -0
- package/build/treb-calculator/src/functions/gamma.js +142 -0
- package/build/treb-calculator/src/functions/gamma.js.map +1 -0
- package/build/treb-calculator/src/functions/information-functions.d.ts +2 -0
- package/build/treb-calculator/src/functions/information-functions.js +71 -0
- package/build/treb-calculator/src/functions/information-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/lambda-functions.d.ts +2 -0
- package/build/treb-calculator/src/functions/lambda-functions.js +85 -0
- package/build/treb-calculator/src/functions/lambda-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/matrix-functions.d.ts +2 -0
- package/build/treb-calculator/src/functions/matrix-functions.js +144 -0
- package/build/treb-calculator/src/functions/matrix-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/normal.d.ts +2 -0
- package/build/treb-calculator/src/functions/normal.js +32 -0
- package/build/treb-calculator/src/functions/normal.js.map +1 -0
- package/build/treb-calculator/src/functions/regex-functions.d.ts +2 -0
- package/build/treb-calculator/src/functions/regex-functions.js +188 -0
- package/build/treb-calculator/src/functions/regex-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/sparkline.d.ts +37 -0
- package/build/treb-calculator/src/functions/sparkline.js +264 -0
- package/build/treb-calculator/src/functions/sparkline.js.map +1 -0
- package/build/treb-calculator/src/functions/statistics-functions.d.ts +6 -0
- package/build/treb-calculator/src/functions/statistics-functions.js +989 -0
- package/build/treb-calculator/src/functions/statistics-functions.js.map +1 -0
- package/build/treb-calculator/src/functions/students-t.d.ts +3 -0
- package/build/treb-calculator/src/functions/students-t.js +64 -0
- package/build/treb-calculator/src/functions/students-t.js.map +1 -0
- package/build/treb-calculator/src/functions/text-functions.d.ts +3 -0
- package/build/treb-calculator/src/functions/text-functions.js +320 -0
- package/build/treb-calculator/src/functions/text-functions.js.map +1 -0
- package/build/treb-calculator/src/index.d.ts +2 -0
- package/build/treb-calculator/src/index.js +22 -0
- package/build/treb-calculator/src/index.js.map +1 -0
- package/build/treb-calculator/src/notifier-types.d.ts +26 -0
- package/build/treb-calculator/src/notifier-types.js +22 -0
- package/build/treb-calculator/src/notifier-types.js.map +1 -0
- package/build/treb-calculator/src/primitives.d.ts +15 -0
- package/build/treb-calculator/src/primitives.js +398 -0
- package/build/treb-calculator/src/primitives.js.map +1 -0
- package/build/treb-calculator/src/utilities.d.ts +68 -0
- package/build/treb-calculator/src/utilities.js +324 -0
- package/build/treb-calculator/src/utilities.js.map +1 -0
- package/build/treb-charts/src/chart-functions.d.ts +8 -0
- package/build/treb-charts/src/chart-functions.js +209 -0
- package/build/treb-charts/src/chart-functions.js.map +1 -0
- package/build/treb-charts/src/chart-types.d.ts +233 -0
- package/build/treb-charts/src/chart-types.js +57 -0
- package/build/treb-charts/src/chart-types.js.map +1 -0
- package/build/treb-charts/src/chart-utils.d.ts +106 -0
- package/build/treb-charts/src/chart-utils.js +1060 -0
- package/build/treb-charts/src/chart-utils.js.map +1 -0
- package/build/treb-charts/src/chart.d.ts +23 -0
- package/build/treb-charts/src/chart.js +94 -0
- package/build/treb-charts/src/chart.js.map +1 -0
- package/build/treb-charts/src/default-chart-renderer.d.ts +16 -0
- package/build/treb-charts/src/default-chart-renderer.js +533 -0
- package/build/treb-charts/src/default-chart-renderer.js.map +1 -0
- package/build/treb-charts/src/index.d.ts +5 -0
- package/build/treb-charts/src/index.js +24 -0
- package/build/treb-charts/src/index.js.map +1 -0
- package/build/treb-charts/src/main.d.ts +1 -0
- package/build/treb-charts/src/main.js +34 -0
- package/build/treb-charts/src/main.js.map +1 -0
- package/build/treb-charts/src/quicksort.d.ts +1 -0
- package/build/treb-charts/src/quicksort.js +49 -0
- package/build/treb-charts/src/quicksort.js.map +1 -0
- package/build/treb-charts/src/rectangle.d.ts +18 -0
- package/build/treb-charts/src/rectangle.js +41 -0
- package/build/treb-charts/src/rectangle.js.map +1 -0
- package/build/treb-charts/src/renderer-type.d.ts +24 -0
- package/build/treb-charts/src/renderer-type.js +22 -0
- package/build/treb-charts/src/renderer-type.js.map +1 -0
- package/build/treb-charts/src/renderer.d.ts +127 -0
- package/build/treb-charts/src/renderer.js +1518 -0
- package/build/treb-charts/src/renderer.js.map +1 -0
- package/build/treb-charts/src/util.d.ts +18 -0
- package/build/treb-charts/src/util.js +71 -0
- package/build/treb-charts/src/util.js.map +1 -0
- package/build/treb-data-model/src/annotation.d.ts +167 -0
- package/build/treb-data-model/src/annotation.js +120 -0
- package/build/treb-data-model/src/annotation.js.map +1 -0
- package/build/treb-data-model/src/conditional_format.d.ts +155 -0
- package/build/treb-data-model/src/conditional_format.js +62 -0
- package/build/treb-data-model/src/conditional_format.js.map +1 -0
- package/build/treb-data-model/src/data-validation.d.ts +28 -0
- package/build/treb-data-model/src/data-validation.js +22 -0
- package/build/treb-data-model/src/data-validation.js.map +1 -0
- package/build/treb-data-model/src/data_model.d.ts +173 -0
- package/build/treb-data-model/src/data_model.js +637 -0
- package/build/treb-data-model/src/data_model.js.map +1 -0
- package/build/treb-data-model/src/index.d.ts +13 -0
- package/build/treb-data-model/src/index.js +28 -0
- package/build/treb-data-model/src/index.js.map +1 -0
- package/build/treb-data-model/src/language-model.d.ts +22 -0
- package/build/treb-data-model/src/language-model.js +22 -0
- package/build/treb-data-model/src/language-model.js.map +1 -0
- package/build/treb-data-model/src/named.d.ts +124 -0
- package/build/treb-data-model/src/named.js +372 -0
- package/build/treb-data-model/src/named.js.map +1 -0
- package/build/treb-data-model/src/serialize_options.d.ts +49 -0
- package/build/treb-data-model/src/serialize_options.js +22 -0
- package/build/treb-data-model/src/serialize_options.js.map +1 -0
- package/build/treb-data-model/src/sheet.d.ts +499 -0
- package/build/treb-data-model/src/sheet.js +2904 -0
- package/build/treb-data-model/src/sheet.js.map +1 -0
- package/build/treb-data-model/src/sheet_collection.d.ts +58 -0
- package/build/treb-data-model/src/sheet_collection.js +112 -0
- package/build/treb-data-model/src/sheet_collection.js.map +1 -0
- package/build/treb-data-model/src/sheet_selection.d.ts +42 -0
- package/build/treb-data-model/src/sheet_selection.js +39 -0
- package/build/treb-data-model/src/sheet_selection.js.map +1 -0
- package/build/treb-data-model/src/sheet_types.d.ts +104 -0
- package/build/treb-data-model/src/sheet_types.js +22 -0
- package/build/treb-data-model/src/sheet_types.js.map +1 -0
- package/build/treb-data-model/src/types.d.ts +59 -0
- package/build/treb-data-model/src/types.js +22 -0
- package/build/treb-data-model/src/types.js.map +1 -0
- package/build/treb-embed/src/custom-element/spreadsheet-constructor.d.ts +75 -0
- package/build/treb-embed/src/custom-element/spreadsheet-constructor.js +1144 -0
- package/build/treb-embed/src/custom-element/spreadsheet-constructor.js.map +1 -0
- package/build/treb-embed/src/custom-element/treb-global.d.ts +36 -0
- package/build/treb-embed/src/custom-element/treb-global.js +64 -0
- package/build/treb-embed/src/custom-element/treb-global.js.map +1 -0
- package/build/treb-embed/src/custom-element/treb-spreadsheet-element.d.ts +1 -0
- package/build/treb-embed/src/custom-element/treb-spreadsheet-element.js +61 -0
- package/build/treb-embed/src/custom-element/treb-spreadsheet-element.js.map +1 -0
- package/build/treb-embed/src/embedded-spreadsheet.d.ts +1358 -0
- package/build/treb-embed/src/embedded-spreadsheet.js +5205 -0
- package/build/treb-embed/src/embedded-spreadsheet.js.map +1 -0
- package/build/treb-embed/src/index.d.ts +12 -0
- package/build/treb-embed/src/index.js +34 -0
- package/build/treb-embed/src/index.js.map +1 -0
- package/build/treb-embed/src/options.d.ts +266 -0
- package/build/treb-embed/src/options.js +56 -0
- package/build/treb-embed/src/options.js.map +1 -0
- package/build/treb-embed/src/plugin.d.ts +9 -0
- package/build/treb-embed/src/plugin.js +22 -0
- package/build/treb-embed/src/plugin.js.map +1 -0
- package/build/treb-embed/src/progress-dialog.d.ts +49 -0
- package/build/treb-embed/src/progress-dialog.js +178 -0
- package/build/treb-embed/src/progress-dialog.js.map +1 -0
- package/build/treb-embed/src/selection-state.d.ts +15 -0
- package/build/treb-embed/src/selection-state.js +22 -0
- package/build/treb-embed/src/selection-state.js.map +1 -0
- package/build/treb-embed/src/spinner.d.ts +8 -0
- package/build/treb-embed/src/spinner.js +40 -0
- package/build/treb-embed/src/spinner.js.map +1 -0
- package/build/treb-embed/src/toolbar-message.d.ts +72 -0
- package/build/treb-embed/src/toolbar-message.js +22 -0
- package/build/treb-embed/src/toolbar-message.js.map +1 -0
- package/build/treb-embed/src/types.d.ts +185 -0
- package/build/treb-embed/src/types.js +45 -0
- package/build/treb-embed/src/types.js.map +1 -0
- package/build/treb-embed/tsconfig.tsbuildinfo +1 -0
- package/build/treb-export/src/address-type.d.ts +34 -0
- package/build/treb-export/src/address-type.js +53 -0
- package/build/treb-export/src/address-type.js.map +1 -0
- package/build/treb-export/src/base-template.d.ts +1 -0
- package/build/treb-export/src/base-template.js +22 -0
- package/build/treb-export/src/base-template.js.map +1 -0
- package/build/treb-export/src/column-width.d.ts +2 -0
- package/build/treb-export/src/column-width.js +80 -0
- package/build/treb-export/src/column-width.js.map +1 -0
- package/build/treb-export/src/drawing/bubble-chart-template.d.ts +514 -0
- package/build/treb-export/src/drawing/bubble-chart-template.js +544 -0
- package/build/treb-export/src/drawing/bubble-chart-template.js.map +1 -0
- package/build/treb-export/src/drawing/chart-template-components2.d.ts +365 -0
- package/build/treb-export/src/drawing/chart-template-components2.js +386 -0
- package/build/treb-export/src/drawing/chart-template-components2.js.map +1 -0
- package/build/treb-export/src/drawing/chart.d.ts +26 -0
- package/build/treb-export/src/drawing/chart.js +247 -0
- package/build/treb-export/src/drawing/chart.js.map +1 -0
- package/build/treb-export/src/drawing/column-chart-template2.d.ts +490 -0
- package/build/treb-export/src/drawing/column-chart-template2.js +518 -0
- package/build/treb-export/src/drawing/column-chart-template2.js.map +1 -0
- package/build/treb-export/src/drawing/donut-chart-template2.d.ts +272 -0
- package/build/treb-export/src/drawing/donut-chart-template2.js +293 -0
- package/build/treb-export/src/drawing/donut-chart-template2.js.map +1 -0
- package/build/treb-export/src/drawing/drawing.d.ts +49 -0
- package/build/treb-export/src/drawing/drawing.js +193 -0
- package/build/treb-export/src/drawing/drawing.js.map +1 -0
- package/build/treb-export/src/drawing/embedded-image.d.ts +12 -0
- package/build/treb-export/src/drawing/embedded-image.js +54 -0
- package/build/treb-export/src/drawing/embedded-image.js.map +1 -0
- package/build/treb-export/src/drawing/scatter-chart-template2.d.ts +520 -0
- package/build/treb-export/src/drawing/scatter-chart-template2.js +551 -0
- package/build/treb-export/src/drawing/scatter-chart-template2.js.map +1 -0
- package/build/treb-export/src/export.d.ts +72 -0
- package/build/treb-export/src/export.js +2039 -0
- package/build/treb-export/src/export.js.map +1 -0
- package/build/treb-export/src/import-export-messages.d.ts +31 -0
- package/build/treb-export/src/import-export-messages.js +22 -0
- package/build/treb-export/src/import-export-messages.js.map +1 -0
- package/build/treb-export/src/import.d.ts +33 -0
- package/build/treb-export/src/import.js +1258 -0
- package/build/treb-export/src/import.js.map +1 -0
- package/build/treb-export/src/index.worker.d.ts +1 -0
- package/build/treb-export/src/index.worker.js +93 -0
- package/build/treb-export/src/index.worker.js.map +1 -0
- package/build/treb-export/src/metadata.d.ts +51 -0
- package/build/treb-export/src/metadata.js +153 -0
- package/build/treb-export/src/metadata.js.map +1 -0
- package/build/treb-export/src/ooxml.d.ts +7 -0
- package/build/treb-export/src/ooxml.js +41 -0
- package/build/treb-export/src/ooxml.js.map +1 -0
- package/build/treb-export/src/relationship.d.ts +8 -0
- package/build/treb-export/src/relationship.js +27 -0
- package/build/treb-export/src/relationship.js.map +1 -0
- package/build/treb-export/src/shared-strings.d.ts +11 -0
- package/build/treb-export/src/shared-strings.js +105 -0
- package/build/treb-export/src/shared-strings.js.map +1 -0
- package/build/treb-export/src/template-2.d.ts +1 -0
- package/build/treb-export/src/template-2.js +22 -0
- package/build/treb-export/src/template-2.js.map +1 -0
- package/build/treb-export/src/unescape_xml.d.ts +1 -0
- package/build/treb-export/src/unescape_xml.js +61 -0
- package/build/treb-export/src/unescape_xml.js.map +1 -0
- package/build/treb-export/src/workbook-sheet.d.ts +75 -0
- package/build/treb-export/src/workbook-sheet.js +128 -0
- package/build/treb-export/src/workbook-sheet.js.map +1 -0
- package/build/treb-export/src/workbook-style.d.ts +110 -0
- package/build/treb-export/src/workbook-style.js +1134 -0
- package/build/treb-export/src/workbook-style.js.map +1 -0
- package/build/treb-export/src/workbook-theme.d.ts +13 -0
- package/build/treb-export/src/workbook-theme.js +85 -0
- package/build/treb-export/src/workbook-theme.js.map +1 -0
- package/build/treb-export/src/workbook.d.ts +123 -0
- package/build/treb-export/src/workbook.js +644 -0
- package/build/treb-export/src/workbook.js.map +1 -0
- package/build/treb-export/src/xml-test.d.ts +9 -0
- package/build/treb-export/src/xml-test.js +52 -0
- package/build/treb-export/src/xml-test.js.map +1 -0
- package/build/treb-export/src/xml-utils.d.ts +76 -0
- package/build/treb-export/src/xml-utils.js +223 -0
- package/build/treb-export/src/xml-utils.js.map +1 -0
- package/build/treb-export/src/zip-wrapper.d.ts +22 -0
- package/build/treb-export/src/zip-wrapper.js +93 -0
- package/build/treb-export/src/zip-wrapper.js.map +1 -0
- package/build/treb-format/src/format.d.ts +130 -0
- package/build/treb-format/src/format.js +805 -0
- package/build/treb-format/src/format.js.map +1 -0
- package/build/treb-format/src/format_cache.d.ts +55 -0
- package/build/treb-format/src/format_cache.js +166 -0
- package/build/treb-format/src/format_cache.js.map +1 -0
- package/build/treb-format/src/format_parser.d.ts +70 -0
- package/build/treb-format/src/format_parser.js +618 -0
- package/build/treb-format/src/format_parser.js.map +1 -0
- package/build/treb-format/src/index.d.ts +4 -0
- package/build/treb-format/src/index.js +25 -0
- package/build/treb-format/src/index.js.map +1 -0
- package/build/treb-format/src/number_format_section.d.ts +58 -0
- package/build/treb-format/src/number_format_section.js +78 -0
- package/build/treb-format/src/number_format_section.js.map +1 -0
- package/build/treb-format/src/value_parser.d.ts +48 -0
- package/build/treb-format/src/value_parser.js +244 -0
- package/build/treb-format/src/value_parser.js.map +1 -0
- package/build/treb-grid/src/editors/autocomplete.d.ts +39 -0
- package/build/treb-grid/src/editors/autocomplete.js +316 -0
- package/build/treb-grid/src/editors/autocomplete.js.map +1 -0
- package/build/treb-grid/src/editors/autocomplete_matcher.d.ts +74 -0
- package/build/treb-grid/src/editors/autocomplete_matcher.js +212 -0
- package/build/treb-grid/src/editors/autocomplete_matcher.js.map +1 -0
- package/build/treb-grid/src/editors/editor.d.ts +214 -0
- package/build/treb-grid/src/editors/editor.js +879 -0
- package/build/treb-grid/src/editors/editor.js.map +1 -0
- package/build/treb-grid/src/editors/external_editor.d.ts +11 -0
- package/build/treb-grid/src/editors/external_editor.js +118 -0
- package/build/treb-grid/src/editors/external_editor.js.map +1 -0
- package/build/treb-grid/src/editors/formula_bar.d.ts +85 -0
- package/build/treb-grid/src/editors/formula_bar.js +444 -0
- package/build/treb-grid/src/editors/formula_bar.js.map +1 -0
- package/build/treb-grid/src/editors/overlay_editor.d.ts +85 -0
- package/build/treb-grid/src/editors/overlay_editor.js +353 -0
- package/build/treb-grid/src/editors/overlay_editor.js.map +1 -0
- package/build/treb-grid/src/index.d.ts +12 -0
- package/build/treb-grid/src/index.js +28 -0
- package/build/treb-grid/src/index.js.map +1 -0
- package/build/treb-grid/src/layout/base_layout.d.ts +346 -0
- package/build/treb-grid/src/layout/base_layout.js +2050 -0
- package/build/treb-grid/src/layout/base_layout.js.map +1 -0
- package/build/treb-grid/src/layout/grid_layout.d.ts +19 -0
- package/build/treb-grid/src/layout/grid_layout.js +235 -0
- package/build/treb-grid/src/layout/grid_layout.js.map +1 -0
- package/build/treb-grid/src/layout/mock-layout.d.ts +10 -0
- package/build/treb-grid/src/layout/mock-layout.js +37 -0
- package/build/treb-grid/src/layout/mock-layout.js.map +1 -0
- package/build/treb-grid/src/render/selection-renderer.d.ts +97 -0
- package/build/treb-grid/src/render/selection-renderer.js +315 -0
- package/build/treb-grid/src/render/selection-renderer.js.map +1 -0
- package/build/treb-grid/src/render/svg_header_overlay.d.ts +20 -0
- package/build/treb-grid/src/render/svg_header_overlay.js +76 -0
- package/build/treb-grid/src/render/svg_header_overlay.js.map +1 -0
- package/build/treb-grid/src/render/svg_selection_block.d.ts +27 -0
- package/build/treb-grid/src/render/svg_selection_block.js +106 -0
- package/build/treb-grid/src/render/svg_selection_block.js.map +1 -0
- package/build/treb-grid/src/render/tile_renderer.d.ts +121 -0
- package/build/treb-grid/src/render/tile_renderer.js +1609 -0
- package/build/treb-grid/src/render/tile_renderer.js.map +1 -0
- package/build/treb-grid/src/types/border_constants.d.ts +9 -0
- package/build/treb-grid/src/types/border_constants.js +34 -0
- package/build/treb-grid/src/types/border_constants.js.map +1 -0
- package/build/treb-grid/src/types/clipboard_data.d.ts +11 -0
- package/build/treb-grid/src/types/clipboard_data.js +22 -0
- package/build/treb-grid/src/types/clipboard_data.js.map +1 -0
- package/build/treb-grid/src/types/clipboard_data2.d.ts +46 -0
- package/build/treb-grid/src/types/clipboard_data2.js +22 -0
- package/build/treb-grid/src/types/clipboard_data2.js.map +1 -0
- package/build/treb-grid/src/types/drag_mask.d.ts +10 -0
- package/build/treb-grid/src/types/drag_mask.js +78 -0
- package/build/treb-grid/src/types/drag_mask.js.map +1 -0
- package/build/treb-grid/src/types/external_editor_config.d.ts +33 -0
- package/build/treb-grid/src/types/external_editor_config.js +22 -0
- package/build/treb-grid/src/types/external_editor_config.js.map +1 -0
- package/build/treb-grid/src/types/grid.d.ts +806 -0
- package/build/treb-grid/src/types/grid.js +6410 -0
- package/build/treb-grid/src/types/grid.js.map +1 -0
- package/build/treb-grid/src/types/grid_base.d.ts +442 -0
- package/build/treb-grid/src/types/grid_base.js +3523 -0
- package/build/treb-grid/src/types/grid_base.js.map +1 -0
- package/build/treb-grid/src/types/grid_command.d.ts +408 -0
- package/build/treb-grid/src/types/grid_command.js +75 -0
- package/build/treb-grid/src/types/grid_command.js.map +1 -0
- package/build/treb-grid/src/types/grid_events.d.ts +93 -0
- package/build/treb-grid/src/types/grid_events.js +36 -0
- package/build/treb-grid/src/types/grid_events.js.map +1 -0
- package/build/treb-grid/src/types/grid_options.d.ts +50 -0
- package/build/treb-grid/src/types/grid_options.js +34 -0
- package/build/treb-grid/src/types/grid_options.js.map +1 -0
- package/build/treb-grid/src/types/scale-control.d.ts +21 -0
- package/build/treb-grid/src/types/scale-control.js +148 -0
- package/build/treb-grid/src/types/scale-control.js.map +1 -0
- package/build/treb-grid/src/types/set_range_options.d.ts +24 -0
- package/build/treb-grid/src/types/set_range_options.js +22 -0
- package/build/treb-grid/src/types/set_range_options.js.map +1 -0
- package/build/treb-grid/src/types/tab_bar.d.ts +84 -0
- package/build/treb-grid/src/types/tab_bar.js +426 -0
- package/build/treb-grid/src/types/tab_bar.js.map +1 -0
- package/build/treb-grid/src/types/tile.d.ts +29 -0
- package/build/treb-grid/src/types/tile.js +22 -0
- package/build/treb-grid/src/types/tile.js.map +1 -0
- package/build/treb-grid/src/types/update_flags.d.ts +48 -0
- package/build/treb-grid/src/types/update_flags.js +22 -0
- package/build/treb-grid/src/types/update_flags.js.map +1 -0
- package/build/treb-grid/src/util/fontmetrics.d.ts +21 -0
- package/build/treb-grid/src/util/fontmetrics.js +82 -0
- package/build/treb-grid/src/util/fontmetrics.js.map +1 -0
- package/build/treb-grid/src/util/ua.d.ts +33 -0
- package/build/treb-grid/src/util/ua.js +86 -0
- package/build/treb-grid/src/util/ua.js.map +1 -0
- package/build/treb-parser/src/csv-parser.d.ts +13 -0
- package/build/treb-parser/src/csv-parser.js +107 -0
- package/build/treb-parser/src/csv-parser.js.map +1 -0
- package/build/treb-parser/src/index.d.ts +4 -0
- package/build/treb-parser/src/index.js +25 -0
- package/build/treb-parser/src/index.js.map +1 -0
- package/build/treb-parser/src/md-parser.d.ts +97 -0
- package/build/treb-parser/src/md-parser.js +403 -0
- package/build/treb-parser/src/md-parser.js.map +1 -0
- package/build/treb-parser/src/parser-types.d.ts +345 -0
- package/build/treb-parser/src/parser-types.js +53 -0
- package/build/treb-parser/src/parser-types.js.map +1 -0
- package/build/treb-parser/src/parser.d.ts +422 -0
- package/build/treb-parser/src/parser.js +2418 -0
- package/build/treb-parser/src/parser.js.map +1 -0
- package/build/treb-utils/src/event_source.d.ts +34 -0
- package/build/treb-utils/src/event_source.js +110 -0
- package/build/treb-utils/src/event_source.js.map +1 -0
- package/build/treb-utils/src/ievent_source.d.ts +9 -0
- package/build/treb-utils/src/ievent_source.js +22 -0
- package/build/treb-utils/src/ievent_source.js.map +1 -0
- package/build/treb-utils/src/index.d.ts +6 -0
- package/build/treb-utils/src/index.js +30 -0
- package/build/treb-utils/src/index.js.map +1 -0
- package/build/treb-utils/src/measurement.d.ts +42 -0
- package/build/treb-utils/src/measurement.js +145 -0
- package/build/treb-utils/src/measurement.js.map +1 -0
- package/build/treb-utils/src/scale.d.ts +16 -0
- package/build/treb-utils/src/scale.js +106 -0
- package/build/treb-utils/src/scale.js.map +1 -0
- package/build/treb-utils/src/serialize_html.d.ts +5 -0
- package/build/treb-utils/src/serialize_html.js +128 -0
- package/build/treb-utils/src/serialize_html.js.map +1 -0
- package/build/treb-utils/src/validate_uri.d.ts +20 -0
- package/build/treb-utils/src/validate_uri.js +55 -0
- package/build/treb-utils/src/validate_uri.js.map +1 -0
- package/dist/{chunk-XD5PEZBZ.mjs → chunk-A2NJA5VB.mjs} +1 -1
- package/dist/treb-export-worker.mjs +2 -2
- package/dist/treb-spreadsheet.mjs +4 -4
- package/dist/treb.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,805 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file is part of TREB.
|
|
3
|
+
*
|
|
4
|
+
* TREB is free software: you can redistribute it and/or modify it under the
|
|
5
|
+
* terms of the GNU General Public License as published by the Free Software
|
|
6
|
+
* Foundation, either version 3 of the License, or (at your option) any
|
|
7
|
+
* later version.
|
|
8
|
+
*
|
|
9
|
+
* TREB is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
10
|
+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
11
|
+
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
12
|
+
* details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU General Public License along
|
|
15
|
+
* with TREB. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
*
|
|
17
|
+
* Copyright 2022-2026 trebco, llc.
|
|
18
|
+
* info@treb.app
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
/* eslint-disable no-irregular-whitespace */
|
|
22
|
+
import { FormatParser } from './format_parser';
|
|
23
|
+
import { NumberFormatSection } from './number_format_section';
|
|
24
|
+
import { Localization, TextPartFlag, IsDimensionedQuantity, } from 'treb-base-types';
|
|
25
|
+
//
|
|
26
|
+
// excel time is explicitly universal, so we need all dates in and out
|
|
27
|
+
// to be UTC. we can't use local time because of daylight savings (which
|
|
28
|
+
// excel ignores)
|
|
29
|
+
//
|
|
30
|
+
// the actual epoch is "January 0" -- I suppose that === Dec 31?
|
|
31
|
+
//
|
|
32
|
+
// const base_date = -2209075200000; // new Date('1899-12-31 00:00:00 Z').getTime();
|
|
33
|
+
//
|
|
34
|
+
// excel time is 1 == 1 day, so relative to js time (millis), we need
|
|
35
|
+
// to scale by 1000 * 60 * 60 * 24
|
|
36
|
+
//
|
|
37
|
+
// const date_scale = 86400000;
|
|
38
|
+
//
|
|
39
|
+
// one last thing -- Excel incorrectly treats 1900 as a leap year. this was
|
|
40
|
+
// for compatibility with Lotus 1-2-3, which handled it incorrectly. we will
|
|
41
|
+
// join the party and treat it incorrectly as well.
|
|
42
|
+
//
|
|
43
|
+
// ref:
|
|
44
|
+
// https://docs.microsoft.com/en-us/office/troubleshoot/excel/wrongly-assumes-1900-is-leap-year
|
|
45
|
+
//
|
|
46
|
+
// what about backwards?
|
|
47
|
+
//
|
|
48
|
+
// OK, I can answer that now: Excel just doesn't handle dates before 1900
|
|
49
|
+
// at all. can't parse them; can't handle negative numbers as dates.
|
|
50
|
+
/** convert cell value -> date, using the rules above */
|
|
51
|
+
export const LotusDate = (value) => {
|
|
52
|
+
if (value >= 60)
|
|
53
|
+
value--; // March 1, 1900
|
|
54
|
+
return new Date(-2209075200000 + 86400000 * value);
|
|
55
|
+
};
|
|
56
|
+
/** convert date (as number, utc millis) -> lotus date value */
|
|
57
|
+
export const UnlotusDate = (value, local = true) => {
|
|
58
|
+
// if the passed value is local, we need to convert it to UTC
|
|
59
|
+
if (local) {
|
|
60
|
+
const local_date = new Date(value);
|
|
61
|
+
const utc_date = new Date(local_date.getFullYear(), local_date.getMonth(), local_date.getDate(), local_date.getHours(), local_date.getMinutes(), local_date.getSeconds(), local_date.getMilliseconds());
|
|
62
|
+
// console.info("Converting local", utc_date.toUTCString());
|
|
63
|
+
value = utc_date.getTime();
|
|
64
|
+
}
|
|
65
|
+
value = (value + 2209075200000) / 86400000;
|
|
66
|
+
if (value >= 60) {
|
|
67
|
+
value++;
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* unifying date format and number format (really just bolting dates
|
|
73
|
+
* on the side). dates have only a single section, constant pattern, and
|
|
74
|
+
* are immutable.
|
|
75
|
+
*/
|
|
76
|
+
export class NumberFormat {
|
|
77
|
+
static grouping_regexp = /\d{1,3}(?=(\d{3})+(?!\d))/g;
|
|
78
|
+
static fraction_limits = [9, 99, 999, 9999];
|
|
79
|
+
/**
|
|
80
|
+
* this is now exposed so it can be changed, for rendering; some options are
|
|
81
|
+
*
|
|
82
|
+
* "i" - regular i, and the default
|
|
83
|
+
* "𝑖" - mathematical italic small i", U+1D456
|
|
84
|
+
* " 𝑖" - the same, with a leading hair space (U+200A)
|
|
85
|
+
*/
|
|
86
|
+
static imaginary_character = '𝑖'; // 'i';
|
|
87
|
+
/**
|
|
88
|
+
* also for complex rendering, the minus sign. there's a unicode
|
|
89
|
+
* symbol U+2212 which (at least in calibri) is wider than the regular minus
|
|
90
|
+
* sign/hyphen. I like this but it looks a bit odd if negative numbers are
|
|
91
|
+
* rendered using the other one.
|
|
92
|
+
*
|
|
93
|
+
* "-" - hyphen
|
|
94
|
+
* "−" - minus
|
|
95
|
+
*/
|
|
96
|
+
static minus_character = '-'; // hyphen
|
|
97
|
+
// public static minus_character = '−'; // minus
|
|
98
|
+
/* * for the "General" format, a magic decimal point */
|
|
99
|
+
// public magic_decimal = false;
|
|
100
|
+
/**
|
|
101
|
+
* (testing) transformer. this is not rendered or persisted, like magic
|
|
102
|
+
* decimal it needs to be applied in code. ATM this is only applied in
|
|
103
|
+
* formatting DQ, but it might turn out to be more universal...
|
|
104
|
+
*
|
|
105
|
+
* NOTE that atm this transforms value back into the same type; we don't
|
|
106
|
+
* cross types (at least for now). perhaps we should support that? that
|
|
107
|
+
* might mean switching in here and removing the "special" format calls
|
|
108
|
+
* for complex and DQ.
|
|
109
|
+
*/
|
|
110
|
+
transform_value;
|
|
111
|
+
// tslint:disable-next-line:variable-name
|
|
112
|
+
_pattern = '';
|
|
113
|
+
sections;
|
|
114
|
+
decimal_zero_regexp = [];
|
|
115
|
+
// this is a flag for string representation
|
|
116
|
+
cloned = [];
|
|
117
|
+
// NumberFormat.decimal_mark = Localization.decimal_separator;
|
|
118
|
+
// if (NumberFormat.decimal_mark === ',') NumberFormat.grouping_separator = ' ';
|
|
119
|
+
// public static decimal_mark: '.'|',' = Localization.decimal_separator;
|
|
120
|
+
// public static grouping_separator = (Localization.decimal_separator === '.') ? ',' : ' ';
|
|
121
|
+
get pattern() {
|
|
122
|
+
return this._pattern;
|
|
123
|
+
}
|
|
124
|
+
/** flag indicates if this is a date format */
|
|
125
|
+
get date_format() {
|
|
126
|
+
return this.sections[0] && this.sections[0].date_format;
|
|
127
|
+
}
|
|
128
|
+
constructor(pattern) {
|
|
129
|
+
this._pattern = pattern;
|
|
130
|
+
this.sections = FormatParser.Parse(pattern);
|
|
131
|
+
// nothing?
|
|
132
|
+
if (!this.sections.length)
|
|
133
|
+
this.sections = [];
|
|
134
|
+
// check zero. we were previously assuming this stepped, but we
|
|
135
|
+
// now support gaps in format sections (although not at 0?)
|
|
136
|
+
if (!this.sections[0]) {
|
|
137
|
+
this.sections[0] = new NumberFormatSection(); // pretty sure this cannot happen atm
|
|
138
|
+
}
|
|
139
|
+
// do we have a negative section? if not, use the positive
|
|
140
|
+
// section and prepend a - sign.
|
|
141
|
+
if (!this.sections[1]) {
|
|
142
|
+
this.sections[1] = { ...this.sections[0] };
|
|
143
|
+
this.sections[1].prefix = JSON.parse(JSON.stringify(this.sections[1].prefix));
|
|
144
|
+
this.sections[1].suffix = JSON.parse(JSON.stringify(this.sections[1].suffix));
|
|
145
|
+
this.sections[1].prefix.push({ text: '-' }); // at end of prefix, before number
|
|
146
|
+
this.cloned[1] = true;
|
|
147
|
+
}
|
|
148
|
+
// do we have a zero section? if not, clone the positive section.
|
|
149
|
+
if (!this.sections[2]) {
|
|
150
|
+
this.sections[2] = { ...this.sections[0] };
|
|
151
|
+
this.cloned[2] = true;
|
|
152
|
+
}
|
|
153
|
+
// string section, default just reflects the string. we could perhaps
|
|
154
|
+
// skip this and just have default behavior if there's no section, which
|
|
155
|
+
// might simplify rendering
|
|
156
|
+
// UPDATE, special case: unless a string section is explicitly
|
|
157
|
+
// provided, we use a default '@' section (it's implicit). however,
|
|
158
|
+
// if there's a literatal '@' in the first section, we want to
|
|
159
|
+
// propogate that to all empty sections, including the string section.
|
|
160
|
+
// note that we should not support literal AND numeric sections in
|
|
161
|
+
// the same block... it will fail silently here... [FIXME: at least warn]
|
|
162
|
+
if (!this.sections[3]) {
|
|
163
|
+
for (const part of this.sections[0].prefix) {
|
|
164
|
+
if (part.flag === TextPartFlag.literal) {
|
|
165
|
+
this.sections[3] = { ...this.sections[0] };
|
|
166
|
+
this.sections[3].string_format = true;
|
|
167
|
+
this.cloned[3] = true;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/*
|
|
173
|
+
if (!this.sections[3]) {
|
|
174
|
+
this.sections[3] = new NumberFormatSection();
|
|
175
|
+
this.sections[3].string_format = true;
|
|
176
|
+
this.sections[3].prefix = [{ text: '@', flag: TextPartFlag.literal }];
|
|
177
|
+
|
|
178
|
+
// obviously not cloned, but we want the behavior. FIXME: change flag name
|
|
179
|
+
this.cloned[3] = true;
|
|
180
|
+
}
|
|
181
|
+
*/
|
|
182
|
+
this.decimal_zero_regexp = this.sections.map((section) => {
|
|
183
|
+
if (section.decimal_max_digits > section.decimal_min_digits) {
|
|
184
|
+
return new RegExp(`0{1,${section.decimal_max_digits - section.decimal_min_digits}}(?:$|e)`);
|
|
185
|
+
}
|
|
186
|
+
return undefined;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* render text parts to string
|
|
191
|
+
* FIXME: move
|
|
192
|
+
*/
|
|
193
|
+
static FormatPartsAsText(parts, text_width = 0) {
|
|
194
|
+
let padded = -1;
|
|
195
|
+
const formatted = parts.map((part, index) => {
|
|
196
|
+
switch (part.flag) {
|
|
197
|
+
case TextPartFlag.padded:
|
|
198
|
+
padded = index;
|
|
199
|
+
return part.text;
|
|
200
|
+
case TextPartFlag.hidden:
|
|
201
|
+
return part.text.replace(/./g, ' ');
|
|
202
|
+
case TextPartFlag.formatting:
|
|
203
|
+
return '';
|
|
204
|
+
default:
|
|
205
|
+
return part.text;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
if (padded >= 0 && text_width) {
|
|
209
|
+
const total_length = formatted.reduce((a, str, index) => (index === padded) ? a : a + str.length, 0);
|
|
210
|
+
let tmp = '';
|
|
211
|
+
for (let i = 0; i < text_width - total_length; i++) {
|
|
212
|
+
tmp += formatted[padded];
|
|
213
|
+
}
|
|
214
|
+
formatted[padded] = tmp;
|
|
215
|
+
}
|
|
216
|
+
return formatted.join('');
|
|
217
|
+
}
|
|
218
|
+
/** for decimal only, set an explicit number of digits */
|
|
219
|
+
SetDecimal(digits) {
|
|
220
|
+
for (const section of this.sections) {
|
|
221
|
+
if (!section.fraction_format) {
|
|
222
|
+
section.decimal_min_digits = digits;
|
|
223
|
+
section.decimal_max_digits = digits;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* mutate
|
|
229
|
+
* UPDATE: for fractional formats, increase the denominator digits
|
|
230
|
+
* (doing something weird with fixed denominators...)
|
|
231
|
+
*/
|
|
232
|
+
IncreaseDecimal() {
|
|
233
|
+
this.sections.forEach((section) => {
|
|
234
|
+
if (section.fraction_format) {
|
|
235
|
+
if (!section.fraction_denominator) {
|
|
236
|
+
section.fraction_denominator_digits = Math.min(section.fraction_denominator_digits + 1, 4);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
section.decimal_min_digits++;
|
|
241
|
+
section.decimal_max_digits = section.decimal_min_digits;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* mutate
|
|
247
|
+
* UPDATE: for fractional formats, decrease the denominator digits
|
|
248
|
+
* (doing something weird with fixed denominators...)
|
|
249
|
+
*/
|
|
250
|
+
DecreaseDecimal() {
|
|
251
|
+
this.sections.forEach((section) => {
|
|
252
|
+
if (section.fraction_format) {
|
|
253
|
+
if (!section.fraction_denominator) {
|
|
254
|
+
section.fraction_denominator_digits = Math.max(section.fraction_denominator_digits - 1, 1);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
section.decimal_min_digits = Math.max(0, section.decimal_min_digits - 1);
|
|
259
|
+
section.decimal_max_digits = section.decimal_min_digits;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/** mutate */
|
|
264
|
+
AddGrouping() {
|
|
265
|
+
this.sections.forEach((section) => {
|
|
266
|
+
section.grouping = true;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/** mutate */
|
|
270
|
+
RemoveGrouping() {
|
|
271
|
+
this.sections.forEach((section) => {
|
|
272
|
+
section.grouping = false;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/** mutate */
|
|
276
|
+
ToggleGrouping() {
|
|
277
|
+
// set all to ! the value of the first one
|
|
278
|
+
const grouping = !this.sections[0].grouping;
|
|
279
|
+
this.sections.forEach((section) => {
|
|
280
|
+
section.grouping = grouping;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* generates a string representation. we use this because we are (now)
|
|
285
|
+
* allowing mutation of formats; therefore we need to serialize them back
|
|
286
|
+
* to the basic format.
|
|
287
|
+
*/
|
|
288
|
+
toString() {
|
|
289
|
+
if (this.sections[0].date_format) {
|
|
290
|
+
return this._pattern; // immutable
|
|
291
|
+
}
|
|
292
|
+
return this.sections.filter((section, i) => {
|
|
293
|
+
return !this.cloned[i];
|
|
294
|
+
}).map((section) => {
|
|
295
|
+
let nf = '';
|
|
296
|
+
let i = 0;
|
|
297
|
+
if (section.fraction_format) {
|
|
298
|
+
if (section.fraction_integer) {
|
|
299
|
+
nf += '? ';
|
|
300
|
+
}
|
|
301
|
+
let pattern = '';
|
|
302
|
+
for (let j = 0; j < section.fraction_denominator_digits; j++) {
|
|
303
|
+
pattern += '#';
|
|
304
|
+
}
|
|
305
|
+
nf += pattern;
|
|
306
|
+
nf += '/';
|
|
307
|
+
if (section.fraction_denominator) {
|
|
308
|
+
nf += section.fraction_denominator;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
nf += pattern;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else if (section.has_number_format) {
|
|
315
|
+
for (i = 0; i < section.integer_min_digits; i++) {
|
|
316
|
+
nf += '0';
|
|
317
|
+
}
|
|
318
|
+
if (section.grouping) {
|
|
319
|
+
if (nf.length < 4)
|
|
320
|
+
nf = ('####' + nf).slice(-4);
|
|
321
|
+
nf = nf.replace(/[\d#]{1,3}(?=([\d#]{3})+(?![\d#]))/g, '$&' + ','); // Localization.grouping_separator);
|
|
322
|
+
}
|
|
323
|
+
if (section.decimal_max_digits || section.decimal_min_digits) {
|
|
324
|
+
nf += '.'; // Localization.decimal_separator;
|
|
325
|
+
for (i = 0; i < section.decimal_min_digits; i++) {
|
|
326
|
+
nf += '0';
|
|
327
|
+
}
|
|
328
|
+
for (; i < section.decimal_max_digits; i++) {
|
|
329
|
+
nf += '#';
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (section.scaling) {
|
|
333
|
+
const count = Math.log10(section.scaling) / 3;
|
|
334
|
+
for (i = 0; i < count; i++) {
|
|
335
|
+
nf += ',';
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
if (section.exponential) {
|
|
339
|
+
nf += 'e';
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return section.prefix.map((part) => {
|
|
343
|
+
if (part.flag === TextPartFlag.hidden) {
|
|
344
|
+
return part.text === '0' ? '?' : '_' + part.text;
|
|
345
|
+
}
|
|
346
|
+
else if (part.flag === TextPartFlag.padded) {
|
|
347
|
+
return '*' + part.text;
|
|
348
|
+
}
|
|
349
|
+
else if (part.flag === TextPartFlag.formatting) {
|
|
350
|
+
return '[' + part.text + ']';
|
|
351
|
+
}
|
|
352
|
+
return part.text;
|
|
353
|
+
}).join('') + nf +
|
|
354
|
+
section.suffix.map((part) => {
|
|
355
|
+
if (part.flag === TextPartFlag.hidden) {
|
|
356
|
+
return part.text === '0' ? '?' : '_' + part.text;
|
|
357
|
+
}
|
|
358
|
+
else if (part.flag === TextPartFlag.padded) {
|
|
359
|
+
return '*' + part.text;
|
|
360
|
+
}
|
|
361
|
+
return part.text;
|
|
362
|
+
}).join('');
|
|
363
|
+
}).join(';');
|
|
364
|
+
}
|
|
365
|
+
/** also temporary? why not switch in here? */
|
|
366
|
+
FormatDimensionedQuantity(value) {
|
|
367
|
+
if (this.transform_value) {
|
|
368
|
+
const result = this.transform_value(value);
|
|
369
|
+
if (IsDimensionedQuantity(result)) {
|
|
370
|
+
value = result;
|
|
371
|
+
}
|
|
372
|
+
else if (typeof result === 'string') {
|
|
373
|
+
// so this is new, but we want string semantics here; rendering
|
|
374
|
+
// is different because strings can wrap
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
// could be a complex (not likely now, but things change), in which
|
|
379
|
+
// case this is not the right method -- we need a method that checks
|
|
380
|
+
// and switches.
|
|
381
|
+
return this.FormatParts(result);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
const parts = this.FormatParts(value.value || 0);
|
|
385
|
+
// anything fancy we want to do in here...
|
|
386
|
+
if (value.unit) {
|
|
387
|
+
parts.push({ text: ' ' }, {
|
|
388
|
+
text: value.unit
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
return parts;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* temporary
|
|
395
|
+
*
|
|
396
|
+
* FIXME: merge with FormatParts, use a test to check if it's complex?
|
|
397
|
+
* OTOH that adds a test to every format which is probably wasteful...
|
|
398
|
+
* although we can check for 'number' first
|
|
399
|
+
*
|
|
400
|
+
*/
|
|
401
|
+
FormatComplex(value) {
|
|
402
|
+
// formatting complex value (note for searching)
|
|
403
|
+
// this needs some work. some thoughts:
|
|
404
|
+
//
|
|
405
|
+
// (1) allow fractions and decimals, but not percent or exponential notation
|
|
406
|
+
// (2) change default for General to have fewer decimal places
|
|
407
|
+
// (3) use the section's integer specification to decide on whether to
|
|
408
|
+
// write "1i" or just "i"
|
|
409
|
+
// (4) drop either real or imaginary part (but not both) if it renders as
|
|
410
|
+
// all zeros
|
|
411
|
+
// (5) change default fraction to #/## (actually we should do that always)
|
|
412
|
+
if (value.imaginary === Infinity || value.imaginary === -Infinity ||
|
|
413
|
+
value.real === Infinity || value.real === -Infinity) {
|
|
414
|
+
return [
|
|
415
|
+
{
|
|
416
|
+
text: 'Infinity',
|
|
417
|
+
}
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
// check if the imaginary format will render as 0.00i -- we want to
|
|
421
|
+
// handle this differently.
|
|
422
|
+
let imaginary_format = [];
|
|
423
|
+
let real_format = [];
|
|
424
|
+
let drop_imaginary_coefficient = false;
|
|
425
|
+
let has_imaginary_value = !!value.imaginary;
|
|
426
|
+
if (has_imaginary_value) {
|
|
427
|
+
imaginary_format = this.FormatParts(value.imaginary);
|
|
428
|
+
has_imaginary_value = imaginary_format.some(element => /[1-9]/.test(element.text));
|
|
429
|
+
// special case: if the integer is not required and the value is
|
|
430
|
+
// either "1" or "-1", drop the integer. do this for integer length
|
|
431
|
+
// <= 1, because you want 0, i, 2i, 3i, &c.
|
|
432
|
+
if (imaginary_format.length === 1 &&
|
|
433
|
+
this.sections[0].integer_min_digits <= 1 &&
|
|
434
|
+
imaginary_format[0].text === '1') {
|
|
435
|
+
imaginary_format[0].text = '';
|
|
436
|
+
drop_imaginary_coefficient = true;
|
|
437
|
+
}
|
|
438
|
+
else if (imaginary_format.length === 1 &&
|
|
439
|
+
this.sections[1].integer_min_digits <= 1 &&
|
|
440
|
+
imaginary_format[0].text === '-1') {
|
|
441
|
+
imaginary_format[0].text = '-';
|
|
442
|
+
drop_imaginary_coefficient = true;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
let has_real_value = !!value.real;
|
|
446
|
+
if (has_real_value) {
|
|
447
|
+
real_format = this.FormatParts(value.real);
|
|
448
|
+
has_real_value = real_format.some(element => /[1-9]/.test(element.text));
|
|
449
|
+
}
|
|
450
|
+
const parts = [];
|
|
451
|
+
if (has_real_value || (!has_real_value && !has_imaginary_value)) {
|
|
452
|
+
// has real part, or is === 0
|
|
453
|
+
parts.push(...real_format);
|
|
454
|
+
if (has_imaginary_value) {
|
|
455
|
+
// also has imaginary part
|
|
456
|
+
// const i = Math.abs(value.imaginary);
|
|
457
|
+
parts.push({ text: value.imaginary < 0 ? ` ${NumberFormat.minus_character} ` : ' + ' });
|
|
458
|
+
const reformatted_imaginary = drop_imaginary_coefficient ?
|
|
459
|
+
[] : this.FormatParts(Math.abs(value.imaginary));
|
|
460
|
+
parts.push(...reformatted_imaginary, { text: NumberFormat.imaginary_character });
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else if (has_imaginary_value) {
|
|
464
|
+
// only imaginary part
|
|
465
|
+
parts.push(...imaginary_format, { text: NumberFormat.imaginary_character });
|
|
466
|
+
}
|
|
467
|
+
return parts;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* this method composes the format as a set of parts with various
|
|
471
|
+
* states. it's intended for graphical representation where things
|
|
472
|
+
* like hidden characters and padding require multiple passes or measurement.
|
|
473
|
+
*/
|
|
474
|
+
FormatParts(value) {
|
|
475
|
+
// new, shortcut
|
|
476
|
+
if (typeof value !== 'number' && !this.sections[3]) {
|
|
477
|
+
// NOTE: that note (next line) seems to be incorrect, not sure why
|
|
478
|
+
// ofc if that was true there'd be no point to this block...
|
|
479
|
+
return [{ text: (value ?? '').toString() }]; // unreachable because we ensure 4 sections
|
|
480
|
+
}
|
|
481
|
+
const { parts, section } = this.BaseFormat(value);
|
|
482
|
+
let text_parts = [];
|
|
483
|
+
if (section.date_format || section.string_format) {
|
|
484
|
+
for (const part of parts) {
|
|
485
|
+
if (typeof part === 'string') {
|
|
486
|
+
text_parts.push({ text: part });
|
|
487
|
+
}
|
|
488
|
+
else
|
|
489
|
+
text_parts.push(part);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
/*
|
|
494
|
+
if (this.magic_decimal && parts[1] === '') {
|
|
495
|
+
parts.splice(1, 1);
|
|
496
|
+
}
|
|
497
|
+
*/
|
|
498
|
+
text_parts = [
|
|
499
|
+
...(section.prefix.map((text_part) => {
|
|
500
|
+
return { ...text_part };
|
|
501
|
+
})),
|
|
502
|
+
{ text: section.has_number_format ? parts.join(Localization.decimal_separator) : '' },
|
|
503
|
+
...(section.suffix.map((text_part) => {
|
|
504
|
+
return { ...text_part };
|
|
505
|
+
})),
|
|
506
|
+
];
|
|
507
|
+
}
|
|
508
|
+
for (let i = 1; i < text_parts.length; i++) {
|
|
509
|
+
if (text_parts[i].flag === text_parts[i - 1].flag) {
|
|
510
|
+
text_parts[i].text = text_parts[i - 1].text + text_parts[i].text;
|
|
511
|
+
text_parts[i - 1].text = '';
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return text_parts.filter((text_part) => text_part.text); // remove empty
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* formats a number as text.
|
|
518
|
+
*
|
|
519
|
+
* this method will use a single space to replace hidden (leading-underscore)
|
|
520
|
+
* characters. if a text width is provided, it will use that for padding;
|
|
521
|
+
* otherwise the padding character (we only allow a single padding character)
|
|
522
|
+
* is rendered once.
|
|
523
|
+
*
|
|
524
|
+
* FIXME: date, string (this is lagging)
|
|
525
|
+
* UPDATE: unifying, basing this on the text part functionality
|
|
526
|
+
*/
|
|
527
|
+
Format(value, text_width = 0) {
|
|
528
|
+
/*
|
|
529
|
+
const parts = this.FormatParts(value);
|
|
530
|
+
let padded = -1;
|
|
531
|
+
|
|
532
|
+
const formatted = parts.map((part, index) => {
|
|
533
|
+
switch (part.flag) {
|
|
534
|
+
case TextPartFlag.padded:
|
|
535
|
+
padded = index;
|
|
536
|
+
return part.text;
|
|
537
|
+
|
|
538
|
+
case TextPartFlag.hidden:
|
|
539
|
+
return part.text.replace(/./g, ' ');
|
|
540
|
+
|
|
541
|
+
case TextPartFlag.formatting:
|
|
542
|
+
return '';
|
|
543
|
+
|
|
544
|
+
default:
|
|
545
|
+
return part.text;
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
if (padded >= 0 && text_width) {
|
|
550
|
+
const total_length = formatted.reduce((a, str, index) => (index === padded) ? a : a + str.length, 0);
|
|
551
|
+
let tmp = '';
|
|
552
|
+
for (let i = 0; i < text_width - total_length; i++){
|
|
553
|
+
tmp += formatted[padded];
|
|
554
|
+
}
|
|
555
|
+
formatted[padded] = tmp;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return formatted.join('');
|
|
559
|
+
*/
|
|
560
|
+
return NumberFormat.FormatPartsAsText(this.FormatParts(value), text_width);
|
|
561
|
+
}
|
|
562
|
+
ZeroPad(text, length) {
|
|
563
|
+
while (text.length < length)
|
|
564
|
+
text = '0' + text;
|
|
565
|
+
return text;
|
|
566
|
+
}
|
|
567
|
+
DateFormat(value) {
|
|
568
|
+
const date = LotusDate(value);
|
|
569
|
+
const section = this.sections[0];
|
|
570
|
+
let hours = date.getUTCHours();
|
|
571
|
+
if (section.twelve_hour) {
|
|
572
|
+
if (hours > 12)
|
|
573
|
+
hours -= 12;
|
|
574
|
+
if (hours === 0)
|
|
575
|
+
hours = 12;
|
|
576
|
+
}
|
|
577
|
+
const parts = section.prefix.map((part) => {
|
|
578
|
+
if (part.flag === TextPartFlag.date_component_minutes) {
|
|
579
|
+
if (part.text === 'mm') {
|
|
580
|
+
return { text: this.ZeroPad((date.getUTCMinutes()).toString(), 2) };
|
|
581
|
+
}
|
|
582
|
+
return { text: this.ZeroPad((date.getUTCMinutes()).toString(), 1) };
|
|
583
|
+
}
|
|
584
|
+
else if (part.flag === TextPartFlag.date_component) {
|
|
585
|
+
switch (part.text.toLowerCase()) {
|
|
586
|
+
case 'am/pm':
|
|
587
|
+
case 'a/p':
|
|
588
|
+
{
|
|
589
|
+
const elements = part.text.split('/');
|
|
590
|
+
return { text: date.getUTCHours() > 12 ? elements[1] : elements[0] };
|
|
591
|
+
}
|
|
592
|
+
case 'mmmmm':
|
|
593
|
+
return { text: Localization.date_components.long_months[date.getUTCMonth()][0] };
|
|
594
|
+
case 'mmmm':
|
|
595
|
+
if (part.text === 'MMMM') {
|
|
596
|
+
return { text: Localization.date_components.long_months[date.getUTCMonth()].toUpperCase() };
|
|
597
|
+
}
|
|
598
|
+
return { text: Localization.date_components.long_months[date.getUTCMonth()] };
|
|
599
|
+
case 'mmm':
|
|
600
|
+
if (part.text === 'MMM') {
|
|
601
|
+
return { text: Localization.date_components.short_months[date.getUTCMonth()].toUpperCase() };
|
|
602
|
+
}
|
|
603
|
+
return { text: Localization.date_components.short_months[date.getUTCMonth()] };
|
|
604
|
+
case 'mm':
|
|
605
|
+
return { text: this.ZeroPad((date.getUTCMonth() + 1).toString(), 2) };
|
|
606
|
+
case 'm':
|
|
607
|
+
return { text: this.ZeroPad((date.getUTCMonth() + 1).toString(), 1) };
|
|
608
|
+
case 'ddddd':
|
|
609
|
+
case 'dddd':
|
|
610
|
+
if (part.text === 'DDDDD' || part.text === 'DDDD') {
|
|
611
|
+
return { text: Localization.date_components.long_days[date.getUTCDay()].toUpperCase() };
|
|
612
|
+
}
|
|
613
|
+
return { text: Localization.date_components.long_days[date.getUTCDay()] };
|
|
614
|
+
case 'ddd':
|
|
615
|
+
if (part.text === 'DDD') {
|
|
616
|
+
return { text: Localization.date_components.short_days[date.getUTCDay()].toUpperCase() };
|
|
617
|
+
}
|
|
618
|
+
return { text: Localization.date_components.short_days[date.getUTCDay()] };
|
|
619
|
+
case 'dd':
|
|
620
|
+
return { text: this.ZeroPad((date.getUTCDate()).toString(), 2) };
|
|
621
|
+
case 'd':
|
|
622
|
+
return { text: this.ZeroPad((date.getUTCDate()).toString(), 1) };
|
|
623
|
+
case 'yyyy':
|
|
624
|
+
case 'yyy':
|
|
625
|
+
return { text: date.getUTCFullYear().toString() };
|
|
626
|
+
case 'yy':
|
|
627
|
+
case 'y':
|
|
628
|
+
// return { text: (date.getUTCFullYear() % 100).toString() };
|
|
629
|
+
return { text: this.ZeroPad((date.getUTCFullYear() % 100).toString(), 2) };
|
|
630
|
+
case 'hh':
|
|
631
|
+
return { text: this.ZeroPad(hours.toString(), 2) };
|
|
632
|
+
case 'h':
|
|
633
|
+
return { text: this.ZeroPad(hours.toString(), 1) };
|
|
634
|
+
case 'ss':
|
|
635
|
+
return { text: this.ZeroPad((date.getUTCSeconds()).toString(), 2) };
|
|
636
|
+
case 's':
|
|
637
|
+
return { text: this.ZeroPad((date.getUTCSeconds()).toString(), 1) };
|
|
638
|
+
}
|
|
639
|
+
const match = part.text.match(/^(s+)\.(0+)$/);
|
|
640
|
+
if (match) {
|
|
641
|
+
return {
|
|
642
|
+
text: this.ZeroPad(date.getUTCSeconds().toString(), match[1].length) +
|
|
643
|
+
Localization.decimal_separator +
|
|
644
|
+
(date.getUTCMilliseconds() / 1000).toFixed(match[2].length).substr(2),
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return { ...part }; // text: part.text, state: part.state};
|
|
649
|
+
});
|
|
650
|
+
return { parts, section };
|
|
651
|
+
}
|
|
652
|
+
StringFormat(value, section) {
|
|
653
|
+
const parts = [];
|
|
654
|
+
for (const part of section.prefix) {
|
|
655
|
+
if (part.flag === TextPartFlag.literal) {
|
|
656
|
+
parts.push({ text: value });
|
|
657
|
+
}
|
|
658
|
+
else
|
|
659
|
+
parts.push({ ...part });
|
|
660
|
+
}
|
|
661
|
+
return {
|
|
662
|
+
parts, section,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
/*
|
|
666
|
+
public DecimalAdjustRound(value: number, exp: number) {
|
|
667
|
+
|
|
668
|
+
if (!exp) { return Math.round(value); }
|
|
669
|
+
|
|
670
|
+
value = +value;
|
|
671
|
+
// exp = +exp;
|
|
672
|
+
|
|
673
|
+
// Shift
|
|
674
|
+
let values = value.toString().split('e');
|
|
675
|
+
value = Math.round(+(values[0] + 'e' + (values[1] ? (+values[1] - exp) : -exp)));
|
|
676
|
+
|
|
677
|
+
// Shift back
|
|
678
|
+
values = value.toString().split('e');
|
|
679
|
+
return +(values[0] + 'e' + (values[1] ? (+values[1] + exp) : exp));
|
|
680
|
+
|
|
681
|
+
}
|
|
682
|
+
*/
|
|
683
|
+
Round2(value, digits) {
|
|
684
|
+
const m = Math.pow(10, digits);
|
|
685
|
+
return Math.round(m * value) / m;
|
|
686
|
+
}
|
|
687
|
+
FormatFraction(value, section) {
|
|
688
|
+
if (section.percent) {
|
|
689
|
+
value *= 100;
|
|
690
|
+
}
|
|
691
|
+
let candidate = {
|
|
692
|
+
denominator: 1,
|
|
693
|
+
numerator: Math.round(value),
|
|
694
|
+
error: Math.abs(Math.round(value) - value),
|
|
695
|
+
};
|
|
696
|
+
if (section.fraction_denominator) {
|
|
697
|
+
candidate.denominator = section.fraction_denominator;
|
|
698
|
+
candidate.numerator = Math.round(value * candidate.denominator);
|
|
699
|
+
}
|
|
700
|
+
else {
|
|
701
|
+
if (candidate.error) {
|
|
702
|
+
const limit = NumberFormat.fraction_limits[section.fraction_denominator_digits - 1] || NumberFormat.fraction_limits[0];
|
|
703
|
+
for (let denominator = 2; denominator <= limit; denominator++) {
|
|
704
|
+
const numerator = Math.round(value * denominator);
|
|
705
|
+
const error = Math.abs(numerator / denominator - value);
|
|
706
|
+
if (error < candidate.error) {
|
|
707
|
+
candidate = {
|
|
708
|
+
numerator, denominator, error,
|
|
709
|
+
};
|
|
710
|
+
if (!error) {
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
const text = [];
|
|
718
|
+
if (section.fraction_integer) {
|
|
719
|
+
const integer = Math.floor(candidate.numerator / candidate.denominator);
|
|
720
|
+
candidate.numerator %= candidate.denominator;
|
|
721
|
+
if (integer || !candidate.numerator) {
|
|
722
|
+
text.push(integer.toString());
|
|
723
|
+
if (candidate.numerator) {
|
|
724
|
+
text.push(' ');
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
else if (!candidate.numerator) {
|
|
729
|
+
text.push('0');
|
|
730
|
+
}
|
|
731
|
+
if (candidate.numerator) {
|
|
732
|
+
text.push(candidate.numerator.toString());
|
|
733
|
+
text.push('/');
|
|
734
|
+
text.push(candidate.denominator.toString());
|
|
735
|
+
}
|
|
736
|
+
return text.join('');
|
|
737
|
+
}
|
|
738
|
+
BaseFormat(value) {
|
|
739
|
+
if (this.sections[0].date_format) {
|
|
740
|
+
return this.DateFormat(Number(value));
|
|
741
|
+
}
|
|
742
|
+
if (typeof value !== 'number') {
|
|
743
|
+
return this.StringFormat((value ?? '').toString(), this.sections[3]);
|
|
744
|
+
}
|
|
745
|
+
let section = this.sections[0];
|
|
746
|
+
let zero_regexp = this.decimal_zero_regexp[0];
|
|
747
|
+
if (value < 0) {
|
|
748
|
+
section = this.sections[1];
|
|
749
|
+
}
|
|
750
|
+
const max_digits = section.percent ?
|
|
751
|
+
section.decimal_max_digits + 2 :
|
|
752
|
+
section.decimal_max_digits;
|
|
753
|
+
const epsilon = Math.pow(10, -max_digits) / 2;
|
|
754
|
+
let abs_value = Math.abs(value);
|
|
755
|
+
if (abs_value < epsilon) {
|
|
756
|
+
section = this.sections[2];
|
|
757
|
+
zero_regexp = this.decimal_zero_regexp[2];
|
|
758
|
+
}
|
|
759
|
+
// there's kind of a weird thing here where we might have
|
|
760
|
+
// a non-zero number but scaling turns it into zero...
|
|
761
|
+
if (section.scaling) {
|
|
762
|
+
abs_value /= section.scaling;
|
|
763
|
+
if (abs_value < epsilon) {
|
|
764
|
+
section = this.sections[2];
|
|
765
|
+
zero_regexp = this.decimal_zero_regexp[2];
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
if (section.string_format) {
|
|
769
|
+
return this.StringFormat(value.toString(), section);
|
|
770
|
+
}
|
|
771
|
+
let representation = '';
|
|
772
|
+
// special handling for fractions skips most of the other bits
|
|
773
|
+
if (section.fraction_format) {
|
|
774
|
+
return { parts: [this.FormatFraction(abs_value, section)], section };
|
|
775
|
+
}
|
|
776
|
+
if (section.exponential) {
|
|
777
|
+
representation = abs_value.toExponential(section.decimal_max_digits);
|
|
778
|
+
}
|
|
779
|
+
else {
|
|
780
|
+
if (section.percent) {
|
|
781
|
+
abs_value *= 100;
|
|
782
|
+
}
|
|
783
|
+
representation = this.Round2(abs_value, section.decimal_max_digits).toFixed(section.decimal_max_digits);
|
|
784
|
+
}
|
|
785
|
+
if (zero_regexp) {
|
|
786
|
+
representation = representation.replace(zero_regexp, '');
|
|
787
|
+
}
|
|
788
|
+
const parts = representation.split('.');
|
|
789
|
+
if (parts.length === 2 && parts[1] === '' && section.decimal_min_digits === 0) {
|
|
790
|
+
parts.splice(1, 1);
|
|
791
|
+
}
|
|
792
|
+
while (parts[0].length < section.integer_min_digits) {
|
|
793
|
+
// this is sloppy
|
|
794
|
+
parts[0] = ('0000000000000000' + parts[0]).slice(-section.integer_min_digits);
|
|
795
|
+
}
|
|
796
|
+
if (section.integer_min_digits === 0 && parts[0] === '0') {
|
|
797
|
+
parts[0] = ''; // not sure why anyone would want that
|
|
798
|
+
}
|
|
799
|
+
if (section.grouping) {
|
|
800
|
+
parts[0] = parts[0].replace(NumberFormat.grouping_regexp, '$&' + Localization.grouping_separator);
|
|
801
|
+
}
|
|
802
|
+
return { parts, section };
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
//# sourceMappingURL=format.js.map
|