@reforma/components 0.1.5 → 0.2.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/dist/Scrollable/Scrollable.d.ts +1 -2
- package/dist/Scrollable/Scrollable.d.ts.map +1 -1
- package/dist/Scrollable/Scrollable.js +45 -38
- package/dist/Scrollable/Scrollable.js.map +1 -1
- package/dist/Scrollable/useScrollChrome.d.ts +1 -2
- package/dist/Scrollable/useScrollChrome.d.ts.map +1 -1
- package/dist/Scrollable/useScrollChrome.js +125 -110
- package/dist/Scrollable/useScrollChrome.js.map +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.d.ts +2 -1
- package/dist/chat/ComposerBanner/ComposerBanner.d.ts.map +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.js +37 -29
- package/dist/chat/ComposerBanner/ComposerBanner.js.map +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.module.css +1 -1
- package/dist/chat/ComposerBanner/ComposerBanner.module.css.js +5 -3
- package/dist/chat/ComposerBanner/ComposerBanner.module.css.js.map +1 -1
- package/dist/chat/Tool/agent/AgentTool.d.ts.map +1 -1
- package/dist/chat/Tool/agent/AgentTool.js +89 -90
- package/dist/chat/Tool/agent/AgentTool.js.map +1 -1
- package/dist/chat/Tool/edit/EditTool.js +1 -1
- package/dist/chat/Tool/edit/EditTool.js.map +1 -1
- package/dist/node_modules/zod/v4/classic/errors.js +38 -0
- package/dist/node_modules/zod/v4/classic/errors.js.map +1 -0
- package/dist/node_modules/zod/v4/classic/parse.js +21 -0
- package/dist/node_modules/zod/v4/classic/parse.js.map +1 -0
- package/dist/node_modules/zod/v4/classic/schemas.js +822 -0
- package/dist/node_modules/zod/v4/classic/schemas.js.map +1 -0
- package/dist/node_modules/zod/v4/core/api.js +561 -0
- package/dist/node_modules/zod/v4/core/api.js.map +1 -0
- package/dist/node_modules/zod/v4/core/checks.js +262 -0
- package/dist/node_modules/zod/v4/core/checks.js.map +1 -0
- package/dist/node_modules/zod/v4/core/core.js +97 -0
- package/dist/node_modules/zod/v4/core/core.js.map +1 -0
- package/dist/node_modules/zod/v4/core/doc.js +35 -0
- package/dist/node_modules/zod/v4/core/doc.js.map +1 -0
- package/dist/node_modules/zod/v4/core/errors.js +79 -0
- package/dist/node_modules/zod/v4/core/errors.js.map +1 -0
- package/dist/node_modules/zod/v4/core/json-schema-processors.js +308 -0
- package/dist/node_modules/zod/v4/core/json-schema-processors.js.map +1 -0
- package/dist/node_modules/zod/v4/core/memoizer.js +203 -0
- package/dist/node_modules/zod/v4/core/memoizer.js.map +1 -0
- package/dist/node_modules/zod/v4/core/parse.js +113 -0
- package/dist/node_modules/zod/v4/core/parse.js.map +1 -0
- package/dist/node_modules/zod/v4/core/regexes.js +59 -0
- package/dist/node_modules/zod/v4/core/regexes.js.map +1 -0
- package/dist/node_modules/zod/v4/core/registries.js +41 -0
- package/dist/node_modules/zod/v4/core/registries.js.map +1 -0
- package/dist/node_modules/zod/v4/core/schemas.js +1104 -0
- package/dist/node_modules/zod/v4/core/schemas.js.map +1 -0
- package/dist/node_modules/zod/v4/core/to-json-schema.js +380 -0
- package/dist/node_modules/zod/v4/core/to-json-schema.js.map +1 -0
- package/dist/node_modules/zod/v4/core/util.js +465 -0
- package/dist/node_modules/zod/v4/core/util.js.map +1 -0
- package/dist/node_modules/zod/v4/core/versions.js +9 -0
- package/dist/node_modules/zod/v4/core/versions.js.map +1 -0
- package/dist/node_modules/zod/v4/locales/en.js +97 -0
- package/dist/node_modules/zod/v4/locales/en.js.map +1 -0
- package/dist/openui/actions.d.ts +16 -0
- package/dist/openui/actions.d.ts.map +1 -0
- package/dist/openui/actions.js +58 -0
- package/dist/openui/actions.js.map +1 -0
- package/dist/openui/components/controls.d.ts +34 -0
- package/dist/openui/components/controls.d.ts.map +1 -0
- package/dist/openui/components/controls.js +40 -0
- package/dist/openui/components/controls.js.map +1 -0
- package/dist/openui/components/layout.d.ts +74 -0
- package/dist/openui/components/layout.d.ts.map +1 -0
- package/dist/openui/components/layout.js +154 -0
- package/dist/openui/components/layout.js.map +1 -0
- package/dist/openui/components/list.d.ts +17 -0
- package/dist/openui/components/list.d.ts.map +1 -0
- package/dist/openui/components/list.js +96 -0
- package/dist/openui/components/list.js.map +1 -0
- package/dist/openui/components/svg.d.ts +100 -0
- package/dist/openui/components/svg.d.ts.map +1 -0
- package/dist/openui/components/svg.js +246 -0
- package/dist/openui/components/svg.js.map +1 -0
- package/dist/openui/components/table.d.ts +6 -0
- package/dist/openui/components/table.d.ts.map +1 -0
- package/dist/openui/components/table.js +54 -0
- package/dist/openui/components/table.js.map +1 -0
- package/dist/openui/components/text.d.ts +89 -0
- package/dist/openui/components/text.d.ts.map +1 -0
- package/dist/openui/components/text.js +181 -0
- package/dist/openui/components/text.js.map +1 -0
- package/dist/openui/functions/colors.d.ts +12 -0
- package/dist/openui/functions/colors.d.ts.map +1 -0
- package/dist/openui/functions/colors.js +32 -0
- package/dist/openui/functions/colors.js.map +1 -0
- package/dist/openui/functions/data.d.ts +170 -0
- package/dist/openui/functions/data.d.ts.map +1 -0
- package/dist/openui/functions/data.js +308 -0
- package/dist/openui/functions/data.js.map +1 -0
- package/dist/openui/functions/dates.d.ts +57 -0
- package/dist/openui/functions/dates.d.ts.map +1 -0
- package/dist/openui/functions/dates.js +184 -0
- package/dist/openui/functions/dates.js.map +1 -0
- package/dist/openui/functions/index.d.ts +136 -0
- package/dist/openui/functions/index.d.ts.map +1 -0
- package/dist/openui/functions/index.js +11 -0
- package/dist/openui/functions/index.js.map +1 -0
- package/dist/openui/functions/lists.d.ts +102 -0
- package/dist/openui/functions/lists.d.ts.map +1 -0
- package/dist/openui/functions/lists.js +305 -0
- package/dist/openui/functions/lists.js.map +1 -0
- package/dist/openui/functions/numbers.d.ts +72 -0
- package/dist/openui/functions/numbers.d.ts.map +1 -0
- package/dist/openui/functions/numbers.js +201 -0
- package/dist/openui/functions/numbers.js.map +1 -0
- package/dist/openui/functions/shared.d.ts +28 -0
- package/dist/openui/functions/shared.d.ts.map +1 -0
- package/dist/openui/functions/shared.js +69 -0
- package/dist/openui/functions/shared.js.map +1 -0
- package/dist/openui/functions/text.d.ts +97 -0
- package/dist/openui/functions/text.d.ts.map +1 -0
- package/dist/openui/functions/text.js +223 -0
- package/dist/openui/functions/text.js.map +1 -0
- package/dist/openui/index.d.ts +5 -0
- package/dist/openui/index.d.ts.map +1 -0
- package/dist/openui/index.js +14 -0
- package/dist/openui/index.js.map +1 -0
- package/dist/openui/library.d.ts +8 -0
- package/dist/openui/library.d.ts.map +1 -0
- package/dist/openui/library.js +37 -0
- package/dist/openui/library.js.map +1 -0
- package/dist/openui/schema.d.ts +36 -0
- package/dist/openui/schema.d.ts.map +1 -0
- package/dist/openui/schema.js +24 -0
- package/dist/openui/schema.js.map +1 -0
- package/package.json +4 -2
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const Pow: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
3
|
+
base: z.ZodNumber;
|
|
4
|
+
exponent: z.ZodNumber;
|
|
5
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
6
|
+
export declare const Sqrt: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
7
|
+
number: z.ZodNumber;
|
|
8
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
9
|
+
export declare const Random: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
10
|
+
min: z.ZodNumber;
|
|
11
|
+
max: z.ZodNumber;
|
|
12
|
+
integer: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
14
|
+
export declare const Clamp: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
15
|
+
number: z.ZodNumber;
|
|
16
|
+
min: z.ZodNumber;
|
|
17
|
+
max: z.ZodNumber;
|
|
18
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
19
|
+
export declare const Percent: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
20
|
+
part: z.ZodNumber;
|
|
21
|
+
total: z.ZodNumber;
|
|
22
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
23
|
+
export declare const Lerp: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
24
|
+
a: z.ZodNumber;
|
|
25
|
+
b: z.ZodNumber;
|
|
26
|
+
t: z.ZodNumber;
|
|
27
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
28
|
+
export declare const Allocate: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
29
|
+
total: z.ZodNumber;
|
|
30
|
+
weights: z.ZodArray<z.ZodNumber>;
|
|
31
|
+
decimals: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
}, z.core.$strip>, z.ZodArray<z.ZodNumber>>;
|
|
33
|
+
export declare const Payment: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
34
|
+
principal: z.ZodNumber;
|
|
35
|
+
rate: z.ZodNumber;
|
|
36
|
+
periods: z.ZodNumber;
|
|
37
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
38
|
+
export declare const Convert: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
39
|
+
value: z.ZodNumber;
|
|
40
|
+
from: z.ZodString;
|
|
41
|
+
to: z.ZodString;
|
|
42
|
+
}, z.core.$strip>, z.ZodNumber>;
|
|
43
|
+
export declare const numberFunctions: (import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
44
|
+
base: z.ZodNumber;
|
|
45
|
+
exponent: z.ZodNumber;
|
|
46
|
+
}, z.core.$strip>, z.ZodNumber> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
47
|
+
number: z.ZodNumber;
|
|
48
|
+
}, z.core.$strip>, z.ZodNumber> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
49
|
+
min: z.ZodNumber;
|
|
50
|
+
max: z.ZodNumber;
|
|
51
|
+
integer: z.ZodOptional<z.ZodBoolean>;
|
|
52
|
+
}, z.core.$strip>, z.ZodNumber> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
53
|
+
part: z.ZodNumber;
|
|
54
|
+
total: z.ZodNumber;
|
|
55
|
+
}, z.core.$strip>, z.ZodNumber> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
56
|
+
a: z.ZodNumber;
|
|
57
|
+
b: z.ZodNumber;
|
|
58
|
+
t: z.ZodNumber;
|
|
59
|
+
}, z.core.$strip>, z.ZodNumber> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
60
|
+
total: z.ZodNumber;
|
|
61
|
+
weights: z.ZodArray<z.ZodNumber>;
|
|
62
|
+
decimals: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
}, z.core.$strip>, z.ZodArray<z.ZodNumber>> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
64
|
+
principal: z.ZodNumber;
|
|
65
|
+
rate: z.ZodNumber;
|
|
66
|
+
periods: z.ZodNumber;
|
|
67
|
+
}, z.core.$strip>, z.ZodNumber> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
68
|
+
value: z.ZodNumber;
|
|
69
|
+
from: z.ZodString;
|
|
70
|
+
to: z.ZodString;
|
|
71
|
+
}, z.core.$strip>, z.ZodNumber>)[];
|
|
72
|
+
//# sourceMappingURL=numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../../../src/openui/functions/numbers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAG3B,eAAO,MAAM,GAAG;;;+BAMd,CAAC;AAEH,eAAO,MAAM,IAAI;;+BAMf,CAAC;AAEH,eAAO,MAAM,MAAM;;;;+BAcjB,CAAC;AAEH,eAAO,MAAM,KAAK;;;;+BAMhB,CAAC;AAEH,eAAO,MAAM,OAAO;;;+BAMlB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;+BAMf,CAAC;AAEH,eAAO,MAAM,QAAQ;;;;2CAwBnB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;+BAUlB,CAAC;AAgBH,eAAO,MAAM,OAAO;;;;+BAalB,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAAwE,CAAC"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { defineFunction as c } from "@openuidev/react-lang";
|
|
2
|
+
import { finite as u, numbers as w } from "./shared.js";
|
|
3
|
+
import { number as n, object as l, boolean as k, array as v, string as d } from "../../node_modules/zod/v4/classic/schemas.js";
|
|
4
|
+
const x = c({
|
|
5
|
+
name: "Pow",
|
|
6
|
+
description: "base raised to exponent",
|
|
7
|
+
params: l({
|
|
8
|
+
base: n(),
|
|
9
|
+
exponent: n()
|
|
10
|
+
}),
|
|
11
|
+
returns: n(),
|
|
12
|
+
fn: ({
|
|
13
|
+
base: e,
|
|
14
|
+
exponent: t
|
|
15
|
+
}) => u(Math.pow(e, t))
|
|
16
|
+
}), y = c({
|
|
17
|
+
name: "Sqrt",
|
|
18
|
+
description: "Square root; null for a negative number",
|
|
19
|
+
params: l({
|
|
20
|
+
number: n()
|
|
21
|
+
}),
|
|
22
|
+
returns: n(),
|
|
23
|
+
fn: ({
|
|
24
|
+
number: e
|
|
25
|
+
}) => u(Math.sqrt(e))
|
|
26
|
+
}), P = c({
|
|
27
|
+
name: "Random",
|
|
28
|
+
description: "Random number from min to max (integer true: a whole number, max included); draws anew each time, so call it inside @Set",
|
|
29
|
+
params: l({
|
|
30
|
+
min: n(),
|
|
31
|
+
max: n(),
|
|
32
|
+
integer: k().optional()
|
|
33
|
+
}),
|
|
34
|
+
returns: n(),
|
|
35
|
+
fn: ({
|
|
36
|
+
min: e,
|
|
37
|
+
max: t,
|
|
38
|
+
integer: a
|
|
39
|
+
}) => {
|
|
40
|
+
const o = Math.min(e, t), s = Math.max(e, t);
|
|
41
|
+
if (!a) return o + Math.random() * (s - o);
|
|
42
|
+
const m = Math.ceil(o), i = Math.floor(s);
|
|
43
|
+
if (m > i) throw new Error("no whole number between min and max");
|
|
44
|
+
return m + Math.floor(Math.random() * (i - m + 1));
|
|
45
|
+
}
|
|
46
|
+
}), C = c({
|
|
47
|
+
name: "Clamp",
|
|
48
|
+
description: "number kept between min and max",
|
|
49
|
+
params: l({
|
|
50
|
+
number: n(),
|
|
51
|
+
min: n(),
|
|
52
|
+
max: n()
|
|
53
|
+
}),
|
|
54
|
+
returns: n(),
|
|
55
|
+
fn: ({
|
|
56
|
+
number: e,
|
|
57
|
+
min: t,
|
|
58
|
+
max: a
|
|
59
|
+
}) => Math.min(Math.max(e, Math.min(t, a)), Math.max(t, a))
|
|
60
|
+
}), S = c({
|
|
61
|
+
name: "Percent",
|
|
62
|
+
description: "part / total * 100, e.g. @Percent(3, 4) is 75; 0 when total is 0",
|
|
63
|
+
params: l({
|
|
64
|
+
part: n(),
|
|
65
|
+
total: n()
|
|
66
|
+
}),
|
|
67
|
+
returns: n(),
|
|
68
|
+
fn: ({
|
|
69
|
+
part: e,
|
|
70
|
+
total: t
|
|
71
|
+
}) => t === 0 ? 0 : u(e / t * 100)
|
|
72
|
+
}), q = c({
|
|
73
|
+
name: "Lerp",
|
|
74
|
+
description: "The value a fraction t of the way from a to b",
|
|
75
|
+
params: l({
|
|
76
|
+
a: n(),
|
|
77
|
+
b: n(),
|
|
78
|
+
t: n()
|
|
79
|
+
}),
|
|
80
|
+
returns: n(),
|
|
81
|
+
fn: ({
|
|
82
|
+
a: e,
|
|
83
|
+
b: t,
|
|
84
|
+
t: a
|
|
85
|
+
}) => u(e + (t - e) * a)
|
|
86
|
+
}), z = c({
|
|
87
|
+
name: "Allocate",
|
|
88
|
+
description: "Splits total in proportion to weights, rounded to decimals (default 2), so the parts add up to exactly total, e.g. @Allocate(100, [1, 1, 1]) is [33.34, 33.33, 33.33]",
|
|
89
|
+
params: l({
|
|
90
|
+
total: n(),
|
|
91
|
+
weights: w(),
|
|
92
|
+
decimals: n().optional()
|
|
93
|
+
}),
|
|
94
|
+
returns: v(n()),
|
|
95
|
+
fn: ({
|
|
96
|
+
total: e,
|
|
97
|
+
weights: t,
|
|
98
|
+
decimals: a
|
|
99
|
+
}) => {
|
|
100
|
+
const o = t.reduce((r, p) => r + p, 0);
|
|
101
|
+
if (!t.length || t.some((r) => !Number.isFinite(r) || r < 0)) throw new Error("weights must be zero or more");
|
|
102
|
+
if (o === 0) return t.map(() => 0);
|
|
103
|
+
const s = 10 ** Math.min(6, Math.max(0, Math.round(a ?? 2))), m = Math.round(Math.abs(e) * s), i = t.map((r) => m * r / o), h = i.map(Math.floor);
|
|
104
|
+
let f = m - h.reduce((r, p) => r + p, 0);
|
|
105
|
+
const M = i.map((r, p) => ({
|
|
106
|
+
i: p,
|
|
107
|
+
rest: r - Math.floor(r)
|
|
108
|
+
})).sort((r, p) => p.rest - r.rest || r.i - p.i);
|
|
109
|
+
for (const {
|
|
110
|
+
i: r
|
|
111
|
+
} of M) {
|
|
112
|
+
if (f <= 0) break;
|
|
113
|
+
h[r] += 1, f -= 1;
|
|
114
|
+
}
|
|
115
|
+
return h.map((r) => (e < 0 ? -r : r) / s);
|
|
116
|
+
}
|
|
117
|
+
}), E = c({
|
|
118
|
+
name: "Payment",
|
|
119
|
+
description: "Payment per period that repays principal over periods at rate percent per period, e.g. a 30-year loan at 6% a year: @Payment(300000, 6 / 12, 360)",
|
|
120
|
+
params: l({
|
|
121
|
+
principal: n(),
|
|
122
|
+
rate: n(),
|
|
123
|
+
periods: n()
|
|
124
|
+
}),
|
|
125
|
+
returns: n(),
|
|
126
|
+
fn: ({
|
|
127
|
+
principal: e,
|
|
128
|
+
rate: t,
|
|
129
|
+
periods: a
|
|
130
|
+
}) => {
|
|
131
|
+
if (!(a > 0)) throw new Error("periods must be positive");
|
|
132
|
+
const o = t / 100;
|
|
133
|
+
return u(o === 0 ? e / a : e * o / (1 - Math.pow(1 + o, -a)));
|
|
134
|
+
}
|
|
135
|
+
}), b = {
|
|
136
|
+
mm: ["length", 1e-3],
|
|
137
|
+
cm: ["length", 0.01],
|
|
138
|
+
m: ["length", 1],
|
|
139
|
+
km: ["length", 1e3],
|
|
140
|
+
in: ["length", 0.0254],
|
|
141
|
+
ft: ["length", 0.3048],
|
|
142
|
+
yd: ["length", 0.9144],
|
|
143
|
+
mi: ["length", 1609.344],
|
|
144
|
+
mg: ["mass", 1e-6],
|
|
145
|
+
g: ["mass", 1e-3],
|
|
146
|
+
kg: ["mass", 1],
|
|
147
|
+
oz: ["mass", 0.028349523125],
|
|
148
|
+
lb: ["mass", 0.45359237],
|
|
149
|
+
st: ["mass", 6.35029318],
|
|
150
|
+
ml: ["volume", 1e-3],
|
|
151
|
+
l: ["volume", 1],
|
|
152
|
+
tsp: ["volume", 0.00492892159375],
|
|
153
|
+
tbsp: ["volume", 0.0147867647812],
|
|
154
|
+
floz: ["volume", 0.0295735295625],
|
|
155
|
+
cup: ["volume", 0.2365882365],
|
|
156
|
+
pt: ["volume", 0.473176473],
|
|
157
|
+
qt: ["volume", 0.946352946],
|
|
158
|
+
gal: ["volume", 3.785411784],
|
|
159
|
+
"m/s": ["speed", 1],
|
|
160
|
+
"km/h": ["speed", 1 / 3.6],
|
|
161
|
+
mph: ["speed", 0.44704],
|
|
162
|
+
kn: ["speed", 0.514444],
|
|
163
|
+
m2: ["area", 1],
|
|
164
|
+
km2: ["area", 1e6],
|
|
165
|
+
ft2: ["area", 0.09290304],
|
|
166
|
+
ha: ["area", 1e4],
|
|
167
|
+
acre: ["area", 4046.8564224]
|
|
168
|
+
}, g = ["c", "f", "k"], L = (e, t) => t === "f" ? (e - 32) * 5 / 9 : t === "k" ? e - 273.15 : e, A = (e, t) => t === "f" ? e * 9 / 5 + 32 : t === "k" ? e + 273.15 : e, F = c({
|
|
169
|
+
name: "Convert",
|
|
170
|
+
description: "value from one unit to another: mm cm m km in ft yd mi; mg g kg oz lb st; ml l tsp tbsp floz cup pt qt gal (US); m/s km/h mph kn; m2 km2 ft2 ha acre; c f k",
|
|
171
|
+
params: l({
|
|
172
|
+
value: n(),
|
|
173
|
+
from: d(),
|
|
174
|
+
to: d()
|
|
175
|
+
}),
|
|
176
|
+
returns: n(),
|
|
177
|
+
fn: ({
|
|
178
|
+
value: e,
|
|
179
|
+
from: t,
|
|
180
|
+
to: a
|
|
181
|
+
}) => {
|
|
182
|
+
const [o, s] = [t.trim().toLowerCase(), a.trim().toLowerCase()];
|
|
183
|
+
if (g.includes(o) && g.includes(s)) return u(A(L(e, o), s));
|
|
184
|
+
const [m, i] = [b[o], b[s]];
|
|
185
|
+
if (!m || !i || m[0] !== i[0]) throw new Error(`cannot convert ${t} to ${a}`);
|
|
186
|
+
return u(e * m[1] / i[1]);
|
|
187
|
+
}
|
|
188
|
+
}), U = [x, y, P, C, S, q, z, E, F];
|
|
189
|
+
export {
|
|
190
|
+
z as Allocate,
|
|
191
|
+
C as Clamp,
|
|
192
|
+
F as Convert,
|
|
193
|
+
q as Lerp,
|
|
194
|
+
E as Payment,
|
|
195
|
+
S as Percent,
|
|
196
|
+
x as Pow,
|
|
197
|
+
P as Random,
|
|
198
|
+
y as Sqrt,
|
|
199
|
+
U as numberFunctions
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers.js","sources":["../../../src/openui/functions/numbers.ts"],"sourcesContent":["import { defineFunction } from \"@openuidev/react-lang\";\nimport { z } from \"zod/v4\";\nimport { finite, numbers } from \"./shared\";\n\nexport const Pow = defineFunction({\n name: \"Pow\",\n description: \"base raised to exponent\",\n params: z.object({ base: z.number(), exponent: z.number() }),\n returns: z.number(),\n fn: ({ base, exponent }) => finite(Math.pow(base, exponent)),\n});\n\nexport const Sqrt = defineFunction({\n name: \"Sqrt\",\n description: \"Square root; null for a negative number\",\n params: z.object({ number: z.number() }),\n returns: z.number(),\n fn: ({ number }) => finite(Math.sqrt(number)),\n});\n\nexport const Random = defineFunction({\n name: \"Random\",\n description: \"Random number from min to max (integer true: a whole number, max included); draws anew each time, so call it inside @Set\",\n params: z.object({ min: z.number(), max: z.number(), integer: z.boolean().optional() }),\n returns: z.number(),\n fn: ({ min, max, integer }) => {\n const lo = Math.min(min, max);\n const hi = Math.max(min, max);\n if (!integer) return lo + Math.random() * (hi - lo);\n const a = Math.ceil(lo);\n const b = Math.floor(hi);\n if (a > b) throw new Error(\"no whole number between min and max\");\n return a + Math.floor(Math.random() * (b - a + 1));\n },\n});\n\nexport const Clamp = defineFunction({\n name: \"Clamp\",\n description: \"number kept between min and max\",\n params: z.object({ number: z.number(), min: z.number(), max: z.number() }),\n returns: z.number(),\n fn: ({ number, min, max }) => Math.min(Math.max(number, Math.min(min, max)), Math.max(min, max)),\n});\n\nexport const Percent = defineFunction({\n name: \"Percent\",\n description: \"part / total * 100, e.g. @Percent(3, 4) is 75; 0 when total is 0\",\n params: z.object({ part: z.number(), total: z.number() }),\n returns: z.number(),\n fn: ({ part, total }) => (total === 0 ? 0 : finite((part / total) * 100)),\n});\n\nexport const Lerp = defineFunction({\n name: \"Lerp\",\n description: \"The value a fraction t of the way from a to b\",\n params: z.object({ a: z.number(), b: z.number(), t: z.number() }),\n returns: z.number(),\n fn: ({ a, b, t }) => finite(a + (b - a) * t),\n});\n\nexport const Allocate = defineFunction({\n name: \"Allocate\",\n description: \"Splits total in proportion to weights, rounded to decimals (default 2), so the parts add up to exactly total, e.g. @Allocate(100, [1, 1, 1]) is [33.34, 33.33, 33.33]\",\n params: z.object({ total: z.number(), weights: numbers(), decimals: z.number().optional() }),\n returns: z.array(z.number()),\n fn: ({ total, weights, decimals }) => {\n const sum = weights.reduce((a, b) => a + b, 0);\n if (!weights.length || weights.some((w) => !Number.isFinite(w) || w < 0)) throw new Error(\"weights must be zero or more\");\n // All-zero weights (a day with nothing to split across) give all zeros\n if (sum === 0) return weights.map(() => 0);\n // Whole units (cents for 2 decimals); the leftover units go to the largest remainders\n const scale = 10 ** Math.min(6, Math.max(0, Math.round(decimals ?? 2)));\n const units = Math.round(Math.abs(total) * scale);\n const exact = weights.map((w) => (units * w) / sum);\n const parts = exact.map(Math.floor);\n let left = units - parts.reduce((a, b) => a + b, 0);\n const order = exact.map((x, i) => ({ i, rest: x - Math.floor(x) })).sort((a, b) => b.rest - a.rest || a.i - b.i);\n for (const { i } of order) {\n if (left <= 0) break;\n parts[i] += 1;\n left -= 1;\n }\n return parts.map((p) => (total < 0 ? -p : p) / scale);\n },\n});\n\nexport const Payment = defineFunction({\n name: \"Payment\",\n description: \"Payment per period that repays principal over periods at rate percent per period, e.g. a 30-year loan at 6% a year: @Payment(300000, 6 / 12, 360)\",\n params: z.object({ principal: z.number(), rate: z.number(), periods: z.number() }),\n returns: z.number(),\n fn: ({ principal, rate, periods }) => {\n if (!(periods > 0)) throw new Error(\"periods must be positive\");\n const r = rate / 100;\n return finite(r === 0 ? principal / periods : (principal * r) / (1 - Math.pow(1 + r, -periods)));\n },\n});\n\n// Units per kind, as the factor to the kind's base unit (m, kg, l, m/s)\nconst UNITS: Record<string, [string, number]> = {\n mm: [\"length\", 0.001], cm: [\"length\", 0.01], m: [\"length\", 1], km: [\"length\", 1000],\n in: [\"length\", 0.0254], ft: [\"length\", 0.3048], yd: [\"length\", 0.9144], mi: [\"length\", 1609.344],\n mg: [\"mass\", 1e-6], g: [\"mass\", 0.001], kg: [\"mass\", 1], oz: [\"mass\", 0.028349523125], lb: [\"mass\", 0.45359237], st: [\"mass\", 6.35029318],\n ml: [\"volume\", 0.001], l: [\"volume\", 1], tsp: [\"volume\", 0.00492892159375], tbsp: [\"volume\", 0.0147867647812], floz: [\"volume\", 0.0295735295625],\n cup: [\"volume\", 0.2365882365], pt: [\"volume\", 0.473176473], qt: [\"volume\", 0.946352946], gal: [\"volume\", 3.785411784],\n \"m/s\": [\"speed\", 1], \"km/h\": [\"speed\", 1 / 3.6], mph: [\"speed\", 0.44704], kn: [\"speed\", 0.514444],\n m2: [\"area\", 1], km2: [\"area\", 1e6], ft2: [\"area\", 0.09290304], ha: [\"area\", 10000], acre: [\"area\", 4046.8564224],\n};\nconst TEMPS = [\"c\", \"f\", \"k\"];\nconst toCelsius = (v: number, u: string) => (u === \"f\" ? ((v - 32) * 5) / 9 : u === \"k\" ? v - 273.15 : v);\nconst fromCelsius = (v: number, u: string) => (u === \"f\" ? (v * 9) / 5 + 32 : u === \"k\" ? v + 273.15 : v);\n\nexport const Convert = defineFunction({\n name: \"Convert\",\n description:\n \"value from one unit to another: mm cm m km in ft yd mi; mg g kg oz lb st; ml l tsp tbsp floz cup pt qt gal (US); m/s km/h mph kn; m2 km2 ft2 ha acre; c f k\",\n params: z.object({ value: z.number(), from: z.string(), to: z.string() }),\n returns: z.number(),\n fn: ({ value, from, to }) => {\n const [a, b] = [from.trim().toLowerCase(), to.trim().toLowerCase()];\n if (TEMPS.includes(a) && TEMPS.includes(b)) return finite(fromCelsius(toCelsius(value, a), b));\n const [ua, ub] = [UNITS[a], UNITS[b]];\n if (!ua || !ub || ua[0] !== ub[0]) throw new Error(`cannot convert ${from} to ${to}`);\n return finite((value * ua[1]) / ub[1]);\n },\n});\n\nexport const numberFunctions = [Pow, Sqrt, Random, Clamp, Percent, Lerp, Allocate, Payment, Convert];\n"],"names":["Pow","defineFunction","z.object","z.number","base","exponent","finite","Sqrt","number","Random","z.boolean","min","max","integer","lo","hi","a","b","Clamp","Percent","part","total","Lerp","t","Allocate","numbers","z.array","weights","decimals","sum","w","scale","units","exact","parts","left","order","x","i","p","Payment","principal","rate","periods","r","UNITS","TEMPS","toCelsius","v","u","fromCelsius","Convert","z.string","value","from","to","ua","ub","numberFunctions"],"mappings":";;;AAGO,MAAMA,IAAMC,EAAe;AAAA,EAChC,MAAM;AAAA,EACN,aAAa;AAAA,EACb,QAAQC,EAAS;AAAA,IACf,MAAMC,EAAE;AAAA,IACR,UAAUA,EAAE;AAAA,EA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WAAOjD,EAAO+C,IAAQG,EAAG,CAAC,IAAIC,EAAG,CAAC,CAAC;AAAA,EACrC;AACF,CAAC,GACYC,IAAkB,CAAC1D,GAAKO,GAAME,GAAQS,GAAOC,GAASG,GAAME,GAAUgB,GAASW,CAAO;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const list: () => z.ZodArray<z.ZodAny>;
|
|
3
|
+
export declare const numbers: () => z.ZodArray<z.ZodNumber>;
|
|
4
|
+
export declare const date: () => z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
5
|
+
export declare const agg: () => z.ZodEnum<{
|
|
6
|
+
avg: "avg";
|
|
7
|
+
count: "count";
|
|
8
|
+
max: "max";
|
|
9
|
+
min: "min";
|
|
10
|
+
sum: "sum";
|
|
11
|
+
}>;
|
|
12
|
+
/** Reads `field` from a row, with dot paths; "" is the item itself, like @Filter. */
|
|
13
|
+
export declare function read(item: unknown, field: string): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Equality by value: lists and objects compare item by item, and a number
|
|
16
|
+
* matches its string form (ids from inputs are often strings).
|
|
17
|
+
*/
|
|
18
|
+
export declare function same(a: unknown, b: unknown): boolean;
|
|
19
|
+
/** A finite number or a thrown error, which the runtime turns into null. */
|
|
20
|
+
export declare function finite(value: number): number;
|
|
21
|
+
export declare function toNum(value: unknown): number | null;
|
|
22
|
+
export type Agg = "sum" | "avg" | "count" | "min" | "max";
|
|
23
|
+
/** Aggregates the numbers read from rows; count counts rows. */
|
|
24
|
+
export declare function aggregate(rows: unknown[], field: string | undefined, how: Agg): number;
|
|
25
|
+
/** Groups items by a key in first-seen order. */
|
|
26
|
+
export declare function groups(rows: unknown[], key: string): Map<string | number, unknown[]>;
|
|
27
|
+
export declare const MAX_ITEMS = 10000;
|
|
28
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/openui/functions/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,eAAO,MAAM,IAAI,4BAAyB,CAAC;AAC3C,eAAO,MAAM,OAAO,+BAA4B,CAAC;AACjD,eAAO,MAAM,IAAI,uDAA0C,CAAC;AAC5D,eAAO,MAAM,GAAG;;;;;;EAAsD,CAAC;AAEvE,qFAAqF;AACrF,wBAAgB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAQ1D;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAUpD;AAED,4EAA4E;AAC5E,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAOnD;AAED,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,KAAK,GAAG,KAAK,CAAC;AAE1D,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,CActF;AAED,iDAAiD;AACjD,wBAAgB,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,CAAC,CAUpF;AAED,eAAO,MAAM,SAAS,QAAQ,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { array as c, union as l, enum as g, any as y, string as a, number as f } from "../../node_modules/zod/v4/classic/schemas.js";
|
|
2
|
+
const b = () => c(y()), A = () => c(f()), d = () => l([a(), f()]), j = () => g(["sum", "avg", "count", "min", "max"]);
|
|
3
|
+
function m(n, t) {
|
|
4
|
+
if (!t) return n;
|
|
5
|
+
let u = n;
|
|
6
|
+
for (const r of t.split(".")) {
|
|
7
|
+
if (u == null || typeof u != "object") return;
|
|
8
|
+
u = u[r];
|
|
9
|
+
}
|
|
10
|
+
return u;
|
|
11
|
+
}
|
|
12
|
+
function s(n, t) {
|
|
13
|
+
if (n === t) return !0;
|
|
14
|
+
if (typeof n == "number" && typeof t == "string" || typeof n == "string" && typeof t == "number") return String(n) === String(t);
|
|
15
|
+
if (n === null || t === null || typeof n != "object" || typeof t != "object" || Array.isArray(n) !== Array.isArray(t)) return !1;
|
|
16
|
+
if (Array.isArray(n)) return n.length === t.length && n.every((i, o) => s(i, t[o]));
|
|
17
|
+
const r = Object.keys(n), e = Object.keys(t);
|
|
18
|
+
return r.length === e.length && r.every((i) => Object.hasOwn(t, i) && s(n[i], t[i]));
|
|
19
|
+
}
|
|
20
|
+
function k(n) {
|
|
21
|
+
if (!Number.isFinite(n)) throw new Error("result is not a finite number");
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
function p(n) {
|
|
25
|
+
if (typeof n == "number") return Number.isFinite(n) ? n : null;
|
|
26
|
+
if (typeof n == "string" && n.trim() !== "") {
|
|
27
|
+
const t = Number(n);
|
|
28
|
+
return Number.isFinite(t) ? t : null;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
function w(n, t, u) {
|
|
33
|
+
if (u === "count") return n.length;
|
|
34
|
+
const r = n.map((e) => p(m(e, t ?? ""))).filter((e) => e !== null);
|
|
35
|
+
if (!r.length) return 0;
|
|
36
|
+
switch (u) {
|
|
37
|
+
case "sum":
|
|
38
|
+
return r.reduce((e, i) => e + i, 0);
|
|
39
|
+
case "avg":
|
|
40
|
+
return r.reduce((e, i) => e + i, 0) / r.length;
|
|
41
|
+
case "min":
|
|
42
|
+
return Math.min(...r);
|
|
43
|
+
case "max":
|
|
44
|
+
return Math.max(...r);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function x(n, t) {
|
|
48
|
+
const u = /* @__PURE__ */ new Map();
|
|
49
|
+
for (const r of n) {
|
|
50
|
+
const e = m(r, t), i = typeof e == "number" ? e : e == null || e === "" ? "Unknown" : String(e), o = u.get(i);
|
|
51
|
+
o ? o.push(r) : u.set(i, [r]);
|
|
52
|
+
}
|
|
53
|
+
return u;
|
|
54
|
+
}
|
|
55
|
+
const M = 1e4;
|
|
56
|
+
export {
|
|
57
|
+
M as MAX_ITEMS,
|
|
58
|
+
j as agg,
|
|
59
|
+
w as aggregate,
|
|
60
|
+
d as date,
|
|
61
|
+
k as finite,
|
|
62
|
+
x as groups,
|
|
63
|
+
b as list,
|
|
64
|
+
A as numbers,
|
|
65
|
+
m as read,
|
|
66
|
+
s as same,
|
|
67
|
+
p as toNum
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sources":["../../../src/openui/functions/shared.ts"],"sourcesContent":["import { z } from \"zod/v4\";\n\nexport const list = () => z.array(z.any());\nexport const numbers = () => z.array(z.number());\nexport const date = () => z.union([z.string(), z.number()]);\nexport const agg = () => z.enum([\"sum\", \"avg\", \"count\", \"min\", \"max\"]);\n\n/** Reads `field` from a row, with dot paths; \"\" is the item itself, like @Filter. */\nexport function read(item: unknown, field: string): unknown {\n if (!field) return item;\n let cur: unknown = item;\n for (const key of field.split(\".\")) {\n if (cur == null || typeof cur !== \"object\") return undefined;\n cur = (cur as Record<string, unknown>)[key];\n }\n return cur;\n}\n\n/**\n * Equality by value: lists and objects compare item by item, and a number\n * matches its string form (ids from inputs are often strings).\n */\nexport function same(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n const mixed = (typeof a === \"number\" && typeof b === \"string\") || (typeof a === \"string\" && typeof b === \"number\");\n if (mixed) return String(a) === String(b);\n if (a === null || b === null || typeof a !== \"object\" || typeof b !== \"object\") return false;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n if (Array.isArray(a)) return a.length === (b as unknown[]).length && a.every((x, i) => same(x, (b as unknown[])[i]));\n const ka = Object.keys(a);\n const kb = Object.keys(b);\n return ka.length === kb.length && ka.every((k) => Object.hasOwn(b, k) && same((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]));\n}\n\n/** A finite number or a thrown error, which the runtime turns into null. */\nexport function finite(value: number): number {\n if (!Number.isFinite(value)) throw new Error(\"result is not a finite number\");\n return value;\n}\n\nexport function toNum(value: unknown): number | null {\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"string\" && value.trim() !== \"\") {\n const n = Number(value);\n return Number.isFinite(n) ? n : null;\n }\n return null;\n}\n\nexport type Agg = \"sum\" | \"avg\" | \"count\" | \"min\" | \"max\";\n\n/** Aggregates the numbers read from rows; count counts rows. */\nexport function aggregate(rows: unknown[], field: string | undefined, how: Agg): number {\n if (how === \"count\") return rows.length;\n const values = rows.map((r) => toNum(read(r, field ?? \"\"))).filter((v): v is number => v !== null);\n if (!values.length) return 0;\n switch (how) {\n case \"sum\":\n return values.reduce((a, b) => a + b, 0);\n case \"avg\":\n return values.reduce((a, b) => a + b, 0) / values.length;\n case \"min\":\n return Math.min(...values);\n case \"max\":\n return Math.max(...values);\n }\n}\n\n/** Groups items by a key in first-seen order. */\nexport function groups(rows: unknown[], key: string): Map<string | number, unknown[]> {\n const out = new Map<string | number, unknown[]>();\n for (const row of rows) {\n const raw = read(row, key);\n const k = typeof raw === \"number\" ? raw : raw == null || raw === \"\" ? \"Unknown\" : String(raw);\n const bucket = out.get(k);\n if (bucket) bucket.push(row);\n else out.set(k, [row]);\n }\n return out;\n}\n\nexport const MAX_ITEMS = 10000;\n"],"names":["list","z.array","z.any","numbers","z.number","date","z.union","z.string","agg","z.enum","read","item","field","cur","key","same","a","b","x","i","ka","kb","k","finite","value","toNum","n","aggregate","rows","how","values","r","v","groups","out","row","raw","bucket","MAX_ITEMS"],"mappings":";AACO,M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AY;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
export declare const Format: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
3
|
+
value: z.ZodNumber;
|
|
4
|
+
kind: z.ZodOptional<z.ZodEnum<{
|
|
5
|
+
compact: "compact";
|
|
6
|
+
currency: "currency";
|
|
7
|
+
number: "number";
|
|
8
|
+
percent: "percent";
|
|
9
|
+
}>>;
|
|
10
|
+
decimals: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, z.core.$strip>, z.ZodString>;
|
|
13
|
+
export declare const Join: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
14
|
+
list: z.ZodArray<z.ZodAny>;
|
|
15
|
+
sep: z.ZodOptional<z.ZodString>;
|
|
16
|
+
field: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, z.core.$strip>, z.ZodString>;
|
|
18
|
+
export declare const Plural: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
19
|
+
n: z.ZodNumber;
|
|
20
|
+
word: z.ZodString;
|
|
21
|
+
plural: z.ZodOptional<z.ZodString>;
|
|
22
|
+
}, z.core.$strip>, z.ZodString>;
|
|
23
|
+
export declare const Pad: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
24
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
25
|
+
length: z.ZodNumber;
|
|
26
|
+
char: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>, z.ZodString>;
|
|
28
|
+
export declare const Upper: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
29
|
+
text: z.ZodString;
|
|
30
|
+
}, z.core.$strip>, z.ZodString>;
|
|
31
|
+
export declare const Lower: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
32
|
+
text: z.ZodString;
|
|
33
|
+
}, z.core.$strip>, z.ZodString>;
|
|
34
|
+
export declare const Trim: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
35
|
+
text: z.ZodString;
|
|
36
|
+
}, z.core.$strip>, z.ZodString>;
|
|
37
|
+
export declare const Capitalize: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
38
|
+
text: z.ZodString;
|
|
39
|
+
}, z.core.$strip>, z.ZodString>;
|
|
40
|
+
export declare const Split: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
41
|
+
text: z.ZodString;
|
|
42
|
+
sep: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$strip>, z.ZodArray<z.ZodString>>;
|
|
44
|
+
export declare const Replace: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
45
|
+
text: z.ZodString;
|
|
46
|
+
find: z.ZodString;
|
|
47
|
+
replacement: z.ZodString;
|
|
48
|
+
}, z.core.$strip>, z.ZodString>;
|
|
49
|
+
export declare const Duration: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
50
|
+
seconds: z.ZodNumber;
|
|
51
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
52
|
+
clock: "clock";
|
|
53
|
+
short: "short";
|
|
54
|
+
}>>;
|
|
55
|
+
}, z.core.$strip>, z.ZodString>;
|
|
56
|
+
export declare const Default: import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
57
|
+
value: z.ZodOptional<z.ZodAny>;
|
|
58
|
+
fallback: z.ZodAny;
|
|
59
|
+
}, z.core.$strip>, z.ZodAny>;
|
|
60
|
+
export declare const textFunctions: (import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
61
|
+
value: z.ZodNumber;
|
|
62
|
+
kind: z.ZodOptional<z.ZodEnum<{
|
|
63
|
+
compact: "compact";
|
|
64
|
+
currency: "currency";
|
|
65
|
+
number: "number";
|
|
66
|
+
percent: "percent";
|
|
67
|
+
}>>;
|
|
68
|
+
decimals: z.ZodOptional<z.ZodNumber>;
|
|
69
|
+
currency: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strip>, z.ZodString> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
71
|
+
list: z.ZodArray<z.ZodAny>;
|
|
72
|
+
sep: z.ZodOptional<z.ZodString>;
|
|
73
|
+
field: z.ZodOptional<z.ZodString>;
|
|
74
|
+
}, z.core.$strip>, z.ZodString> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
75
|
+
n: z.ZodNumber;
|
|
76
|
+
word: z.ZodString;
|
|
77
|
+
plural: z.ZodOptional<z.ZodString>;
|
|
78
|
+
}, z.core.$strip>, z.ZodString> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
79
|
+
value: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
80
|
+
length: z.ZodNumber;
|
|
81
|
+
char: z.ZodOptional<z.ZodString>;
|
|
82
|
+
}, z.core.$strip>, z.ZodString> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
83
|
+
text: z.ZodString;
|
|
84
|
+
}, z.core.$strip>, z.ZodString> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
85
|
+
text: z.ZodString;
|
|
86
|
+
sep: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>, z.ZodArray<z.ZodString>> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
88
|
+
seconds: z.ZodNumber;
|
|
89
|
+
style: z.ZodOptional<z.ZodEnum<{
|
|
90
|
+
clock: "clock";
|
|
91
|
+
short: "short";
|
|
92
|
+
}>>;
|
|
93
|
+
}, z.core.$strip>, z.ZodString> | import("@openuidev/lang-core").DefinedFunction<z.ZodObject<{
|
|
94
|
+
value: z.ZodOptional<z.ZodAny>;
|
|
95
|
+
fallback: z.ZodAny;
|
|
96
|
+
}, z.core.$strip>, z.ZodAny>)[];
|
|
97
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/openui/functions/text.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAmB3B,eAAO,MAAM,MAAM;;;;;;;;;;+BAkCjB,CAAC;AAEH,eAAO,MAAM,IAAI;;;;+BAWf,CAAC;AAEH,eAAO,MAAM,MAAM;;;;+BAMjB,CAAC;AAEH,eAAO,MAAM,GAAG;;;;+BAMd,CAAC;AAEH,eAAO,MAAM,KAAK;;+BAMhB,CAAC;AAEH,eAAO,MAAM,KAAK;;+BAMhB,CAAC;AAEH,eAAO,MAAM,IAAI;;+BAMf,CAAC;AAEH,eAAO,MAAM,UAAU;;+BAMrB,CAAC;AAEH,eAAO,MAAM,KAAK;;;2CAUhB,CAAC;AAEH,eAAO,MAAM,OAAO;;;;+BAMlB,CAAC;AAEH,eAAO,MAAM,QAAQ;;;;;;+BAgBnB,CAAC;AAEH,eAAO,MAAM,OAAO;;;4BAOlB,CAAC;AAEH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAAiG,CAAC"}
|