@malloydata/render 0.0.435 → 0.0.437
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/format/index.cjs +1 -0
- package/dist/format/index.mjs +7395 -0
- package/dist/module/component/render-numeric-field.d.ts +2 -2
- package/dist/module/component/tag-configs.d.ts +2 -36
- package/dist/module/format/cell-format.d.ts +74 -0
- package/dist/module/format/index.d.ts +3 -0
- package/dist/module/format/number-format.d.ts +56 -0
- package/dist/module/format/time-format.d.ts +23 -0
- package/dist/module/html/duration.d.ts +3 -5
- package/dist/module/index.mjs +40280 -40075
- package/dist/module/index.umd.js +491 -487
- package/dist/module/util.d.ts +3 -74
- package/femto-config.motly +5 -2
- package/package.json +18 -5
- package/vite.config.format.mts +28 -0
package/dist/module/util.d.ts
CHANGED
|
@@ -1,84 +1,13 @@
|
|
|
1
|
-
import { DurationUnit } from './html/data_styles';
|
|
2
1
|
import { Cell, NestField, Field } from './data_tree';
|
|
3
|
-
export
|
|
2
|
+
export { NULL_SYMBOL } from './format/cell-format';
|
|
3
|
+
export * from './format/number-format';
|
|
4
|
+
export { formatTimeUnit, renderTimeString, type RenderTimeStringOptions, } from './format/time-format';
|
|
4
5
|
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
5
6
|
export declare function deepMerge<T extends Record<string, unknown>[]>(...sources: [...T]): UnionToIntersection<T[number]>;
|
|
6
7
|
export declare function getTextWidthCanvas(text: string, font: string, canvasToUse?: HTMLCanvasElement): number;
|
|
7
8
|
export declare function getTextWidthDOM(text: string, styles: Record<string, string>): number;
|
|
8
9
|
export declare function clamp(s: number, e: number, v: number): number;
|
|
9
10
|
export declare function getRangeSize(range: [number, number]): number;
|
|
10
|
-
export declare function formatTimeUnit(value: number, unit: DurationUnit, options?: {
|
|
11
|
-
numFormat?: string;
|
|
12
|
-
terse?: boolean;
|
|
13
|
-
}): string;
|
|
14
|
-
export declare function getText(field: Field, value: number, options: {
|
|
15
|
-
durationUnit?: string;
|
|
16
|
-
terse?: boolean;
|
|
17
|
-
}): string | null;
|
|
18
|
-
export interface RenderTimeStringOptions {
|
|
19
|
-
isDate?: boolean;
|
|
20
|
-
timeframe?: string;
|
|
21
|
-
extractFormat?: 'month-day' | 'quarter' | 'month' | 'week' | 'day';
|
|
22
|
-
timezone?: string;
|
|
23
|
-
}
|
|
24
|
-
export declare function renderTimeString(value: Date, options?: RenderTimeStringOptions): string;
|
|
25
11
|
export declare function valueToMalloy(value: Cell): string;
|
|
26
12
|
export declare function walkFields(e: NestField, cb: (f: Field) => void): void;
|
|
27
13
|
export declare function notUndefined<T>(x: T | undefined): x is T;
|
|
28
|
-
export declare function formatBigNumber(value: number): string;
|
|
29
|
-
export type ScaleKey = 'k' | 'm' | 'b' | 't' | 'q';
|
|
30
|
-
export type SuffixFormatKey = 'letter' | 'lower' | 'word' | 'short' | 'finance' | 'scientific' | 'none';
|
|
31
|
-
export interface FormatScaledNumberOptions {
|
|
32
|
-
scale?: ScaleKey | 'auto';
|
|
33
|
-
decimals?: number;
|
|
34
|
-
suffix?: SuffixFormatKey;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Formats a number with scaling and suffix options.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* formatScaledNumber(1234567, { scale: 'm', decimals: 1 }) // "1.2m"
|
|
41
|
-
* formatScaledNumber(1234567, { scale: 'auto' }) // "1.2m"
|
|
42
|
-
* formatScaledNumber(1234567, { scale: 'm', suffix: 'word' }) // "1.2 Million"
|
|
43
|
-
*/
|
|
44
|
-
export declare function formatScaledNumber(value: number, options?: FormatScaledNumberOptions): string;
|
|
45
|
-
export interface ParsedNumberFormat {
|
|
46
|
-
decimals?: number;
|
|
47
|
-
scale?: ScaleKey | 'auto';
|
|
48
|
-
isId?: boolean;
|
|
49
|
-
}
|
|
50
|
-
export interface ParsedCurrencyFormat extends ParsedNumberFormat {
|
|
51
|
-
currency: string;
|
|
52
|
-
symbol: string;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Parses a number shorthand format string.
|
|
56
|
-
* Pattern: {decimals}{scale} or "auto" or "id"
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* parseNumberShorthand("1k") // { decimals: 1, scale: 'k' }
|
|
60
|
-
* parseNumberShorthand("0m") // { decimals: 0, scale: 'm' }
|
|
61
|
-
* parseNumberShorthand("2") // { decimals: 2 }
|
|
62
|
-
* parseNumberShorthand("auto") // { scale: 'auto' }
|
|
63
|
-
* parseNumberShorthand("id") // { isId: true }
|
|
64
|
-
*
|
|
65
|
-
* Note: "big" is NOT handled here - it's a legacy format handled separately
|
|
66
|
-
* in renderNumberField to preserve backward compatibility with formatBigNumber.
|
|
67
|
-
*/
|
|
68
|
-
export declare function parseNumberShorthand(format: string): ParsedNumberFormat | null;
|
|
69
|
-
/**
|
|
70
|
-
* Parses a currency shorthand format string.
|
|
71
|
-
* Pattern: {currency}{decimals}{scale} e.g., "usd2m", "eur0k", "gbp1b"
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* parseCurrencyShorthand("usd2m") // { currency: 'usd', symbol: '$', decimals: 2, scale: 'm' }
|
|
75
|
-
* parseCurrencyShorthand("eur0k") // { currency: 'eur', symbol: '€', decimals: 0, scale: 'k' }
|
|
76
|
-
* parseCurrencyShorthand("usd") // { currency: 'usd', symbol: '$' }
|
|
77
|
-
*/
|
|
78
|
-
export declare function parseCurrencyShorthand(format: string): ParsedCurrencyFormat | null;
|
|
79
|
-
/**
|
|
80
|
-
* Normalizes a scale value to a ScaleKey.
|
|
81
|
-
* Supports single-letter scales: k, m, b, t, q, auto.
|
|
82
|
-
*/
|
|
83
|
-
export declare function normalizeScale(scale: string | undefined): ScaleKey | 'auto' | undefined;
|
|
84
|
-
export {};
|
package/femto-config.motly
CHANGED
|
@@ -6,14 +6,17 @@ build: {
|
|
|
6
6
|
"src/**/*.tsx",
|
|
7
7
|
"src/**/*.css",
|
|
8
8
|
"vite.config.mts",
|
|
9
|
+
"vite.config.format.mts",
|
|
9
10
|
"tsconfig.json",
|
|
10
11
|
"tsconfig.type-check.json"
|
|
11
12
|
]
|
|
12
|
-
outputs = ["dist/module/index.mjs"]
|
|
13
|
+
outputs = ["dist/module/index.mjs", "dist/format/index.mjs"]
|
|
13
14
|
commands = [
|
|
14
15
|
# vite bundles the renderer but its dts pass only PRINTS type errors (exit 0).
|
|
15
16
|
# Run a real tsc first so a type error fails the build. See tsconfig.type-check.json.
|
|
16
17
|
"npx tsc -p tsconfig.type-check.json",
|
|
17
|
-
"npx vite build --outDir 'dist/module' --config vite.config.mts"
|
|
18
|
+
"npx vite build --outDir 'dist/module' --config vite.config.mts",
|
|
19
|
+
# The headless single-value formatters: @malloydata/render/format.
|
|
20
|
+
"npx vite build --config vite.config.format.mts"
|
|
18
21
|
]
|
|
19
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.437",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/module/index.umd.js",
|
|
6
6
|
"types": "dist/module/index.d.ts",
|
|
@@ -18,6 +18,19 @@
|
|
|
18
18
|
"import": "./dist/module/index.mjs",
|
|
19
19
|
"require": "./dist/module/index.umd.js",
|
|
20
20
|
"default": "./dist/module/index.umd.js"
|
|
21
|
+
},
|
|
22
|
+
"./format": {
|
|
23
|
+
"types": "./dist/module/format/index.d.ts",
|
|
24
|
+
"import": "./dist/format/index.mjs",
|
|
25
|
+
"require": "./dist/format/index.cjs",
|
|
26
|
+
"default": "./dist/format/index.cjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"typesVersions": {
|
|
30
|
+
"*": {
|
|
31
|
+
"format": [
|
|
32
|
+
"./dist/module/format/index.d.ts"
|
|
33
|
+
]
|
|
21
34
|
}
|
|
22
35
|
},
|
|
23
36
|
"scripts": {
|
|
@@ -31,8 +44,8 @@
|
|
|
31
44
|
"generate-flow": "ts-node ../../scripts/gen-flow.ts"
|
|
32
45
|
},
|
|
33
46
|
"dependencies": {
|
|
34
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
35
|
-
"@malloydata/malloy-tag": "0.0.
|
|
47
|
+
"@malloydata/malloy-interfaces": "0.0.437",
|
|
48
|
+
"@malloydata/malloy-tag": "0.0.437",
|
|
36
49
|
"@tanstack/solid-virtual": "^3.13.33",
|
|
37
50
|
"lodash": "^4.18.1",
|
|
38
51
|
"luxon": "^3.7.2",
|
|
@@ -44,8 +57,8 @@
|
|
|
44
57
|
"vega-lite": "^5.2.0"
|
|
45
58
|
},
|
|
46
59
|
"devDependencies": {
|
|
47
|
-
"@malloydata/db-duckdb": "0.0.
|
|
48
|
-
"@malloydata/malloy": "0.0.
|
|
60
|
+
"@malloydata/db-duckdb": "0.0.437",
|
|
61
|
+
"@malloydata/malloy": "0.0.437",
|
|
49
62
|
"@storybook/addon-essentials": "^8.6.18",
|
|
50
63
|
"@storybook/addon-interactions": "^8.6.18",
|
|
51
64
|
"@storybook/addon-links": "^8.6.15",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// The headless `@malloydata/render/format` entry: single-value formatters
|
|
2
|
+
// with no Solid, no Vega and no DOM, so a server or a sandboxed frame can
|
|
3
|
+
// format a value exactly as the renderer would without loading the renderer.
|
|
4
|
+
// Self-contained like the main build (`external: []`): `ssf` is CommonJS-only
|
|
5
|
+
// and `lodash/startCase` an extensionless subpath, and neither imports cleanly
|
|
6
|
+
// from Node's ESM loader when left external. Its .d.ts files come from the
|
|
7
|
+
// main build, which already emits dist/module/format/*.d.ts.
|
|
8
|
+
import {defineConfig} from 'vite';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
resolve: {
|
|
13
|
+
alias: {'@': path.resolve(__dirname, './src')},
|
|
14
|
+
},
|
|
15
|
+
build: {
|
|
16
|
+
outDir: 'dist/format',
|
|
17
|
+
emptyOutDir: true,
|
|
18
|
+
lib: {
|
|
19
|
+
entry: 'src/format/index.ts',
|
|
20
|
+
formats: ['es', 'cjs'],
|
|
21
|
+
fileName: format => (format === 'es' ? 'index.mjs' : 'index.cjs'),
|
|
22
|
+
},
|
|
23
|
+
rollupOptions: {
|
|
24
|
+
external: [],
|
|
25
|
+
},
|
|
26
|
+
sourcemap: process.env.NODE_ENV === 'development',
|
|
27
|
+
},
|
|
28
|
+
});
|