@takumi-rs/helpers 0.7.2

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/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @takumi-rs/helpers
2
+
3
+ Types and helper functions for [takumi](https://github.com/kane50613/takumi).
4
+
5
+ ## Example
6
+
7
+ ```ts
8
+ import { container, text, image, style } from "@takumi-rs/helpers";
9
+
10
+ const root = container({
11
+ width: 1200,
12
+ height: 630,
13
+ children: [
14
+ text(
15
+ style({
16
+ font_size: 24,
17
+ font_weight: 700,
18
+ color: 0xffffff,
19
+ }),
20
+ "Hello, world!"
21
+ ),
22
+ ],
23
+ });
24
+
25
+ // Fetch takumi server or with @takumi-rs/core
26
+ ```
@@ -0,0 +1,368 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /**
4
+ * Defines how flex items are aligned along the cross axis.
5
+ *
6
+ * This enum determines how flex items are aligned within the flex container
7
+ * along the cross axis (perpendicular to the main axis).
8
+ */
9
+ export type AlignItems = "start" | "end" | "flex-start" | "flex-end" | "center" | "baseline" | "stretch";
10
+ /**
11
+ * Represents a color in various formats with support for RGB, RGBA, and integer RGB values.
12
+ *
13
+ * The enum supports three color formats:
14
+ * - `Rgb`: RGB color with 8-bit components (r, g, b)
15
+ * - `Rgba`: RGBA color with 8-bit RGB components and 32-bit float alpha (r, g, b, a)
16
+ * - `RgbInt`: Single 32-bit integer containing RGB values
17
+ */
18
+ export type Color = [
19
+ number,
20
+ number,
21
+ number
22
+ ] | [
23
+ number,
24
+ number,
25
+ number,
26
+ number
27
+ ] | number;
28
+ /**
29
+ * Represents a gradient with color steps and an angle for directional gradients.
30
+ */
31
+ export type Gradient = {
32
+ /**
33
+ * The color stops that make up the gradient
34
+ */
35
+ stops: Array<Color>;
36
+ /**
37
+ * The angle in degrees for the gradient direction (0-360)
38
+ */
39
+ angle: number;
40
+ };
41
+ /**
42
+ * Represents a color input that can be either a color or a gradient.
43
+ */
44
+ export type ColorInput = Color | Gradient;
45
+ /**
46
+ * Represents a value that can be a specific length, percentage, or automatic.
47
+ *
48
+ * This corresponds to CSS values that can be specified as pixels, percentages,
49
+ * or the 'auto' keyword for automatic sizing.
50
+ */
51
+ export type LengthUnit = "auto" | {
52
+ "percentage": number;
53
+ } | {
54
+ "rem": number;
55
+ } | {
56
+ "em": number;
57
+ } | {
58
+ "vh": number;
59
+ } | {
60
+ "vw": number;
61
+ } | number;
62
+ /**
63
+ * Defines a box shadow for an element.
64
+ *
65
+ * This struct contains the properties for a box shadow, including color,
66
+ * offset, blur radius, spread radius, and inset flag.
67
+ */
68
+ export type BoxShadow = {
69
+ /**
70
+ * Color of the box shadow
71
+ */
72
+ color: ColorInput;
73
+ /**
74
+ * Horizontal offset of the box shadow
75
+ */
76
+ offset_x: LengthUnit;
77
+ /**
78
+ * Vertical offset of the box shadow
79
+ */
80
+ offset_y: LengthUnit;
81
+ /**
82
+ * Blur radius of the box shadow (must be non-negative)
83
+ */
84
+ blur_radius: LengthUnit;
85
+ /**
86
+ * Spread radius of the box shadow
87
+ */
88
+ spread_radius: LengthUnit;
89
+ /**
90
+ * Whether the shadow is inset (inside the element)
91
+ */
92
+ inset: boolean;
93
+ };
94
+ /**
95
+ * Defines a box shadow for an element.
96
+ *
97
+ * This enum allows for flexible specification of box shadows, including
98
+ * a single shadow or multiple shadows.
99
+ */
100
+ export type BoxShadowInput = BoxShadow | Array<BoxShadow>;
101
+ /**
102
+ * Defines the direction of flex items within a flex container.
103
+ *
104
+ * This enum determines how flex items are laid out along the main axis.
105
+ */
106
+ export type FlexDirection = "row" | "column" | "row-reverse" | "column-reverse";
107
+ /**
108
+ * Defines how flex items should wrap.
109
+ *
110
+ * This enum determines how flex items should wrap within the flex container.
111
+ */
112
+ export type FlexWrap = "no-wrap" | "wrap" | "wrap-reverse";
113
+ /**
114
+ * Represents font weight as a numeric value.
115
+ *
116
+ * This wraps a u16 value that corresponds to CSS font-weight values
117
+ * (e.g., 100 for thin, 400 for normal, 700 for bold, 900 for black).
118
+ */
119
+ export type FontWeight = number;
120
+ /**
121
+ * Represents spacing between flex items.
122
+ *
123
+ * Can be either a single value applied to both axes, or separate values
124
+ * for horizontal and vertical spacing.
125
+ */
126
+ export type Gap = LengthUnit | [
127
+ LengthUnit,
128
+ LengthUnit
129
+ ];
130
+ /**
131
+ * Defines how flex items are aligned along the main axis.
132
+ *
133
+ * This enum determines how space is distributed between and around flex items
134
+ * along the main axis of the flex container.
135
+ */
136
+ export type JustifyContent = "start" | "end" | "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "space-evenly";
137
+ /**
138
+ * Defines how an image should be resized to fit its container.
139
+ *
140
+ * Similar to CSS object-fit property.
141
+ */
142
+ export type ObjectFit = "contain" | "cover" | "fill" | "scale-down" | "none";
143
+ /**
144
+ * Defines the positioning method for an element.
145
+ *
146
+ * This enum determines how an element is positioned within its containing element.
147
+ */
148
+ export type Position = "static" | "relative" | "absolute" | "fixed" | "sticky";
149
+ /**
150
+ * Represents values that can be applied to all sides of an element.
151
+ *
152
+ * This enum allows for flexible specification of values like padding, margin,
153
+ * or border sizes using either a single value for all sides, separate values
154
+ * for vertical/horizontal axes, or individual values for each side.
155
+ */
156
+ export type SidesValue<T> = T | [
157
+ T,
158
+ T
159
+ ] | [
160
+ T,
161
+ T,
162
+ T,
163
+ T
164
+ ];
165
+ /**
166
+ * Text alignment options for text rendering.
167
+ *
168
+ * Corresponds to CSS text-align property values.
169
+ */
170
+ export type TextAlign = "left" | "right" | "center" | "justify" | "start" | "end";
171
+ /**
172
+ * Main styling structure that contains all layout and visual properties.
173
+ *
174
+ * This structure combines both layout properties (like width, height, padding)
175
+ * and inheritable properties (like font settings, colors) that can be passed
176
+ * down to child elements.
177
+ */
178
+ export type Style = {
179
+ /**
180
+ * Width of the element
181
+ */
182
+ width: LengthUnit;
183
+ /**
184
+ * Height of the element
185
+ */
186
+ height: LengthUnit;
187
+ /**
188
+ * Max width of the element
189
+ */
190
+ max_width: LengthUnit;
191
+ /**
192
+ * Max height of the element
193
+ */
194
+ max_height: LengthUnit;
195
+ /**
196
+ * Min width of the element
197
+ */
198
+ min_width: LengthUnit;
199
+ /**
200
+ * Min height of the element
201
+ */
202
+ min_height: LengthUnit;
203
+ /**
204
+ * Aspect ratio of the element
205
+ */
206
+ aspect_ratio?: number;
207
+ /**
208
+ * Internal spacing around the element's content
209
+ */
210
+ padding: SidesValue<LengthUnit>;
211
+ /**
212
+ * External spacing around the element
213
+ */
214
+ margin: SidesValue<LengthUnit>;
215
+ /**
216
+ * Positioning offset from the element's normal position
217
+ */
218
+ inset: SidesValue<LengthUnit>;
219
+ /**
220
+ * Direction of flex layout (row or column)
221
+ */
222
+ flex_direction: FlexDirection;
223
+ /**
224
+ * How flex items are aligned along the main axis
225
+ */
226
+ justify_content?: JustifyContent;
227
+ /**
228
+ * How flex items are aligned along the cross axis
229
+ */
230
+ align_items?: AlignItems;
231
+ /**
232
+ * How flex items should wrap
233
+ */
234
+ flex_wrap: FlexWrap;
235
+ /**
236
+ * The initial size of the flex item
237
+ */
238
+ flex_basis: LengthUnit;
239
+ /**
240
+ * Positioning method (relative, absolute, etc.)
241
+ */
242
+ position: Position;
243
+ /**
244
+ * Spacing between flex items
245
+ */
246
+ gap: Gap;
247
+ /**
248
+ * How much the element should grow relative to other flex items
249
+ */
250
+ flex_grow: number;
251
+ /**
252
+ * How much the element should shrink relative to other flex items
253
+ */
254
+ flex_shrink: number;
255
+ /**
256
+ * Width of the element's border
257
+ */
258
+ border_width: SidesValue<LengthUnit>;
259
+ /**
260
+ * How images should be fitted within their container
261
+ */
262
+ object_fit: ObjectFit;
263
+ /**
264
+ * Element's background color
265
+ */
266
+ background_color?: ColorInput;
267
+ /**
268
+ * Box shadow for the element
269
+ */
270
+ box_shadow?: BoxShadowInput;
271
+ /**
272
+ * Color of the element's border
273
+ */
274
+ border_color?: ColorInput;
275
+ /**
276
+ * Text color for child text elements
277
+ */
278
+ color?: ColorInput;
279
+ /**
280
+ * Font size in pixels for text rendering
281
+ */
282
+ font_size?: LengthUnit;
283
+ /**
284
+ * Font family name for text rendering
285
+ */
286
+ font_family?: string;
287
+ /**
288
+ * Line height multiplier for text spacing
289
+ */
290
+ line_height?: LengthUnit;
291
+ /**
292
+ * Font weight for text rendering
293
+ */
294
+ font_weight?: FontWeight;
295
+ /**
296
+ * Maximum number of lines for text before truncation
297
+ */
298
+ line_clamp?: number;
299
+ /**
300
+ * Corner radius for rounded borders in pixels
301
+ */
302
+ border_radius?: SidesValue<LengthUnit>;
303
+ /**
304
+ * Text alignment within the element
305
+ */
306
+ text_align?: TextAlign;
307
+ /**
308
+ * Letter spacing for text rendering
309
+ * Value is measured in EM units
310
+ */
311
+ letter_spacing?: number;
312
+ };
313
+ /**
314
+ * Represents a value that can be a specific length, percentage, or automatic.
315
+ *
316
+ * This corresponds to CSS values that can be specified as pixels, percentages,
317
+ * or the 'auto' keyword for automatic sizing.
318
+ */
319
+ export type ValuePercentageAuto = "auto" | {
320
+ "percentage": number;
321
+ } | number;
322
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
323
+ [key: string]: JsonValue;
324
+ };
325
+ export type AnyNode = {
326
+ type: string;
327
+ [key: string]: JsonValue;
328
+ };
329
+ export type StyleInput = Partial<Style>;
330
+ export type Node = ContainerNode | TextNode | ImageNode | AnyNode;
331
+ export type ContainerNode = StyleInput & {
332
+ type: "container";
333
+ children: Node[];
334
+ };
335
+ export type TextNode = StyleInput & {
336
+ type: "text";
337
+ text: string;
338
+ };
339
+ export type ImageNode = StyleInput & {
340
+ type: "image";
341
+ src: string;
342
+ };
343
+ export declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
344
+ export declare function text(text: string, style?: StyleInput): TextNode;
345
+ export declare function image(src: string, style?: StyleInput): ImageNode;
346
+ export declare function style(style: StyleInput): Partial<Style>;
347
+ /**
348
+ * Convert a number to a percentage struct.
349
+ * @param percentage - The percentage to convert (0.0 - 100.0).
350
+ * @returns The percentage struct.
351
+ */
352
+ export declare function percentage(percentage: number): {
353
+ percentage: number;
354
+ };
355
+ export declare function vw(vw: number): {
356
+ vw: number;
357
+ };
358
+ export declare function vh(vh: number): {
359
+ vh: number;
360
+ };
361
+ export declare function em(em: number): {
362
+ em: number;
363
+ };
364
+ export declare function rem(rem: number): {
365
+ rem: number;
366
+ };
367
+
368
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ function b(e){return{type:"container",...e}}function c(e,t){return{...t,type:"text",text:e}}function A(e,t){return{...t,type:"image",src:e}}function T(e){return e}function w(e){return{percentage:e}}function S(e){return{vw:e}}function D(e){return{vh:e}}function v(e){return{em:e}}function R(e){return{rem:e}}export{S as vw,D as vh,c as text,T as style,R as rem,w as percentage,A as image,v as em,b as container};
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@takumi-rs/helpers",
3
+ "version": "0.7.2",
4
+ "author": {
5
+ "email": "me@kane.tw",
6
+ "name": "Kane Wang",
7
+ "url": "https://kane.tw"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "package.json",
12
+ "README.md",
13
+ "tsconfig.json"
14
+ ],
15
+ "scripts": {
16
+ "build": "bun build.ts"
17
+ },
18
+ "repository": {
19
+ "url": "git+https://github.com/kane50613/takumi.git"
20
+ },
21
+ "devDependencies": {
22
+ "@types/bun": "latest",
23
+ "@types/react": "^19.1.8",
24
+ "bun-plugin-dts": "^0.3.0"
25
+ },
26
+ "peerDependencies": {
27
+ "typescript": "^5"
28
+ },
29
+ "exports": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "license": "MIT",
34
+ "type": "module"
35
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+
10
+ // Bundler mode
11
+ "moduleResolution": "bundler",
12
+ "allowImportingTsExtensions": true,
13
+ "verbatimModuleSyntax": true,
14
+ "noEmit": true,
15
+
16
+ // Best practices
17
+ "strict": true,
18
+ "skipLibCheck": true,
19
+ "noFallthroughCasesInSwitch": true,
20
+ "noUncheckedIndexedAccess": true,
21
+ "noImplicitOverride": true,
22
+
23
+ // Some stricter flags (disabled by default)
24
+ "noUnusedLocals": false,
25
+ "noUnusedParameters": false,
26
+ "noPropertyAccessFromIndexSignature": false
27
+ }
28
+ }