@takumi-rs/helpers 0.12.2 → 0.14.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/index.d.ts CHANGED
@@ -48,7 +48,7 @@ export type ColorInput = Color | Gradient;
48
48
  * This corresponds to CSS values that can be specified as pixels, percentages,
49
49
  * or the 'auto' keyword for automatic sizing.
50
50
  */
51
- export type LengthUnit = "auto" | {
51
+ export type LengthUnit = "auto" | "min-content" | "max-content" | {
52
52
  "percentage": number;
53
53
  } | {
54
54
  "rem": number;
@@ -98,6 +98,10 @@ export type BoxShadow = {
98
98
  * a single shadow or multiple shadows.
99
99
  */
100
100
  export type BoxShadowInput = BoxShadow | Array<BoxShadow>;
101
+ /**
102
+ * This enum determines the layout algorithm used for the children of a node.
103
+ */
104
+ export type Display = "block" | "flex" | "grid" | "none";
101
105
  /**
102
106
  * Defines the direction of flex items within a flex container.
103
107
  *
@@ -109,7 +113,7 @@ export type FlexDirection = "row" | "column" | "row-reverse" | "column-reverse";
109
113
  *
110
114
  * This enum determines how flex items should wrap within the flex container.
111
115
  */
112
- export type FlexWrap = "no-wrap" | "wrap" | "wrap-reverse";
116
+ export type FlexWrap = "nowrap" | "wrap" | "wrap-reverse";
113
117
  /**
114
118
  * Represents font weight as a numeric value.
115
119
  *
@@ -127,13 +131,42 @@ export type Gap = LengthUnit | [
127
131
  LengthUnit,
128
132
  LengthUnit
129
133
  ];
134
+ /**
135
+ * Represents the grid auto flow with serde support
136
+ */
137
+ export type GridAutoFlow = "row" | "column" | "row-dense" | "column-dense";
138
+ /**
139
+ * Represents a grid placement with serde support
140
+ */
141
+ export type GridPlacement = "auto" | {
142
+ "span": number;
143
+ } | number | string;
144
+ /**
145
+ * Represents a grid line placement with serde support
146
+ */
147
+ export type GridLine = {
148
+ /**
149
+ * The start line placement
150
+ */
151
+ start: GridPlacement | null;
152
+ /**
153
+ * The end line placement
154
+ */
155
+ end: GridPlacement | null;
156
+ };
157
+ /**
158
+ * Represents a grid track sizing function with serde support
159
+ */
160
+ export type GridTrackSize = {
161
+ "fr": number;
162
+ } | LengthUnit;
130
163
  /**
131
164
  * Defines how flex items are aligned along the main axis.
132
165
  *
133
166
  * This enum determines how space is distributed between and around flex items
134
167
  * along the main axis of the flex container.
135
168
  */
136
- export type JustifyContent = "start" | "end" | "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "space-evenly";
169
+ export type JustifyContent = "start" | "end" | "flex-start" | "flex-end" | "center" | "stretch" | "space-between" | "space-evenly" | "space-around";
137
170
  /**
138
171
  * Defines how an image should be resized to fit its container.
139
172
  *
@@ -145,7 +178,7 @@ export type ObjectFit = "contain" | "cover" | "fill" | "scale-down" | "none";
145
178
  *
146
179
  * This enum determines how an element is positioned within its containing element.
147
180
  */
148
- type Position$1 = "static" | "relative" | "absolute" | "fixed" | "sticky";
181
+ type Position$1 = "relative" | "absolute";
149
182
  /**
150
183
  * Represents values that can be applied to all sides of an element.
151
184
  *
@@ -174,6 +207,21 @@ export type TextAlign = "left" | "right" | "center" | "justify" | "start" | "end
174
207
  * This enum determines how text should be handled when it exceeds the container width.
175
208
  */
176
209
  export type TextOverflow = "ellipsis" | "clip";
210
+ /**
211
+ * Represents a grid track repetition pattern
212
+ */
213
+ export type GridTrackRepetition = "auto-fill" | "auto-fit" | number;
214
+ /**
215
+ * Represents a track sizing function
216
+ */
217
+ export type TrackSizingFunction = {
218
+ "single": GridTrackSize;
219
+ } | {
220
+ "repeat": [
221
+ GridTrackRepetition,
222
+ Array<GridTrackSize>
223
+ ];
224
+ };
177
225
  /**
178
226
  * Main styling structure that contains all layout and visual properties.
179
227
  *
@@ -182,6 +230,10 @@ export type TextOverflow = "ellipsis" | "clip";
182
230
  * down to child elements.
183
231
  */
184
232
  export type Style = {
233
+ /**
234
+ * Display algorithm to use for the element
235
+ */
236
+ display: Display;
185
237
  /**
186
238
  * Width of the element
187
239
  */
@@ -230,6 +282,14 @@ export type Style = {
230
282
  * How flex items are aligned along the main axis
231
283
  */
232
284
  justify_content?: JustifyContent;
285
+ /**
286
+ * How flex items are aligned along the cross axis when there's extra space
287
+ */
288
+ align_content?: JustifyContent;
289
+ /**
290
+ * How grid items are aligned along the inline (row) axis
291
+ */
292
+ justify_items?: AlignItems;
233
293
  /**
234
294
  * How flex items are aligned along the cross axis
235
295
  */
@@ -239,7 +299,7 @@ export type Style = {
239
299
  */
240
300
  flex_wrap: FlexWrap;
241
301
  /**
242
- * The initial size of the flex item
302
+ * The initial size of the flex item before growing or shrinking
243
303
  */
244
304
  flex_basis: LengthUnit;
245
305
  /**
@@ -247,19 +307,19 @@ export type Style = {
247
307
  */
248
308
  position: Position$1;
249
309
  /**
250
- * Spacing between flex items
310
+ * Spacing between flex items or grid tracks
251
311
  */
252
312
  gap: Gap;
253
313
  /**
254
- * How much the element should grow relative to other flex items
314
+ * How much the element should grow relative to other flex items (0.0 = no growth)
255
315
  */
256
316
  flex_grow: number;
257
317
  /**
258
- * How much the element should shrink relative to other flex items
318
+ * How much the element should shrink relative to other flex items (0.0 = no shrinking)
259
319
  */
260
320
  flex_shrink: number;
261
321
  /**
262
- * Width of the element's border
322
+ * Width of the element's border on each side
263
323
  */
264
324
  border_width: SidesValue<LengthUnit>;
265
325
  /**
@@ -274,6 +334,34 @@ export type Style = {
274
334
  * Box shadow for the element
275
335
  */
276
336
  box_shadow?: BoxShadowInput;
337
+ /**
338
+ * Controls the size of implicitly-created grid columns
339
+ */
340
+ grid_auto_columns?: Array<GridTrackSize>;
341
+ /**
342
+ * Controls the size of implicitly-created grid rows
343
+ */
344
+ grid_auto_rows?: Array<GridTrackSize>;
345
+ /**
346
+ * Controls how auto-placed items are inserted in the grid
347
+ */
348
+ grid_auto_flow?: GridAutoFlow;
349
+ /**
350
+ * Specifies a grid item's size and location within the grid column
351
+ */
352
+ grid_column?: GridLine;
353
+ /**
354
+ * Specifies a grid item's size and location within the grid row
355
+ */
356
+ grid_row?: GridLine;
357
+ /**
358
+ * Defines the line names and track sizing functions of the grid columns
359
+ */
360
+ grid_template_columns?: Array<TrackSizingFunction>;
361
+ /**
362
+ * Defines the line names and track sizing functions of the grid rows
363
+ */
364
+ grid_template_rows?: Array<TrackSizingFunction>;
277
365
  /**
278
366
  * How text should be overflowed
279
367
  */
@@ -318,7 +406,60 @@ export type Style = {
318
406
  * Letter spacing for text rendering
319
407
  * Value is measured in EM units
320
408
  */
321
- letter_spacing?: number;
409
+ letter_spacing?: LengthUnit;
410
+ };
411
+ /**
412
+ * Style properties that can be inherited by child elements.
413
+ *
414
+ * These properties are typically passed down from parent to child elements
415
+ * in the layout hierarchy, such as font settings and colors.
416
+ */
417
+ export type InheritableStyle = {
418
+ /**
419
+ * How text should be overflowed
420
+ */
421
+ text_overflow?: TextOverflow;
422
+ /**
423
+ * Color of the element's border
424
+ */
425
+ border_color?: ColorInput;
426
+ /**
427
+ * Text color for child text elements
428
+ */
429
+ color?: ColorInput;
430
+ /**
431
+ * Font size in pixels for text rendering
432
+ */
433
+ font_size?: LengthUnit;
434
+ /**
435
+ * Font family name for text rendering
436
+ */
437
+ font_family?: string;
438
+ /**
439
+ * Line height multiplier for text spacing
440
+ */
441
+ line_height?: LengthUnit;
442
+ /**
443
+ * Font weight for text rendering
444
+ */
445
+ font_weight?: FontWeight;
446
+ /**
447
+ * Maximum number of lines for text before truncation
448
+ */
449
+ line_clamp?: number;
450
+ /**
451
+ * Corner radius for rounded borders in pixels
452
+ */
453
+ border_radius?: SidesValue<LengthUnit>;
454
+ /**
455
+ * Text alignment within the element
456
+ */
457
+ text_align?: TextAlign;
458
+ /**
459
+ * Letter spacing for text rendering
460
+ * Value is measured in EM units
461
+ */
462
+ letter_spacing?: LengthUnit;
322
463
  };
323
464
  /**
324
465
  * Represents a value that can be a specific length, percentage, or automatic.
@@ -336,24 +477,27 @@ export type AnyNode = {
336
477
  type: string;
337
478
  [key: string]: JsonValue;
338
479
  };
339
- export type StyleInput = Partial<Style>;
340
- export type Node = ContainerNode | TextNode | ImageNode | AnyNode;
341
- export type ContainerNode = StyleInput & {
480
+ export type PartialStyle = Partial<Style>;
481
+ export type JsxParsedStyle = {
482
+ [key in keyof Style]: Style[key] | undefined;
483
+ };
484
+ type Node$1 = ContainerNode | TextNode | ImageNode | AnyNode;
485
+ export type ContainerNode = PartialStyle & {
342
486
  type: "container";
343
- children?: Node[];
487
+ children?: Node$1[];
344
488
  };
345
- export type TextNode = StyleInput & {
489
+ export type TextNode = PartialStyle & {
346
490
  type: "text";
347
491
  text: string;
348
492
  };
349
- export type ImageNode = StyleInput & {
493
+ export type ImageNode = PartialStyle & {
350
494
  type: "image";
351
495
  src: string;
352
496
  };
353
497
  export declare function container(props: Omit<ContainerNode, "type">): ContainerNode;
354
- export declare function text(text: string, style?: StyleInput): TextNode;
355
- export declare function image(src: string, style?: StyleInput): ImageNode;
356
- export declare function style(style: StyleInput): Partial<Style>;
498
+ export declare function text(text: string, style?: PartialStyle): TextNode;
499
+ export declare function image(src: string, style?: PartialStyle): ImageNode;
500
+ export declare function style(style: PartialStyle): Partial<Style>;
357
501
  /**
358
502
  * Convert a number to a percentage struct.
359
503
  * @param percentage - The percentage to convert (0.0 - 100.0).
@@ -374,6 +518,9 @@ export declare function em(em: number): {
374
518
  export declare function rem(rem: number): {
375
519
  rem: number;
376
520
  };
521
+ export declare function fr(fr: number): {
522
+ fr: number;
523
+ };
377
524
  export declare function gradient(from: ColorInput, to: ColorInput, angle?: number): {
378
525
  from: ColorInput;
379
526
  to: ColorInput;
@@ -381,6 +528,7 @@ export declare function gradient(from: ColorInput, to: ColorInput, angle?: numbe
381
528
  };
382
529
 
383
530
  export {
531
+ Node$1 as Node,
384
532
  Position$1 as Position,
385
533
  };
386
534
 
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function i(e){return{type:"container",...e}}function s(e,t){return{...t,type:"text",text:e}}function r(e,t){return{...t,type:"image",src:e}}function n(e){return e}function a(e){return{percentage:e}}function l(e){return{vw:e}}function p(e){return{vh:e}}function h(e){return{em:e}}function m(e){return{rem:e}}function f(e,t,o=0){return{from:e,to:t,angle:o}}export{l as vw,p as vh,s as text,n as style,m as rem,a as percentage,r as image,f as gradient,h as em,i as container};
1
+ function r(e){return{type:"container",...e}}function i(e,t){return{...t,type:"text",text:e}}function s(e,t){return{...t,type:"image",src:e}}function a(e){return e}function n(e){return{percentage:e}}function l(e){return{vw:e}}function p(e){return{vh:e}}function h(e){return{em:e}}function m(e){return{rem:e}}function f(e){return{fr:e}}function u(e,t,o=0){return{from:e,to:t,angle:o}}export{l as vw,p as vh,i as text,a as style,m as rem,n as percentage,s as image,u as gradient,f as fr,h as em,r as container};
package/package.json CHANGED
@@ -1,20 +1,11 @@
1
1
  {
2
2
  "name": "@takumi-rs/helpers",
3
- "version": "0.12.2",
3
+ "version": "0.14.0",
4
4
  "author": {
5
5
  "email": "me@kane.tw",
6
6
  "name": "Kane Wang",
7
7
  "url": "https://kane.tw"
8
8
  },
9
- "files": [
10
- "dist",
11
- "package.json",
12
- "README.md",
13
- "tsconfig.json"
14
- ],
15
- "scripts": {
16
- "build": "bun build.ts"
17
- },
18
9
  "repository": {
19
10
  "url": "git+https://github.com/kane50613/takumi.git"
20
11
  },
@@ -22,12 +13,23 @@
22
13
  "@types/bun": "catalog:",
23
14
  "@types/react": "^19.1.8",
24
15
  "bun-plugin-dts": "^0.3.0",
16
+ "csstype": "^3.1.3",
17
+ "react": "^19.1.0",
25
18
  "typescript": "catalog:"
26
19
  },
27
20
  "exports": {
28
21
  "types": "./dist/index.d.ts",
29
22
  "default": "./dist/index.js"
30
23
  },
24
+ "files": [
25
+ "dist",
26
+ "package.json",
27
+ "README.md",
28
+ "tsconfig.json"
29
+ ],
31
30
  "license": "MIT",
31
+ "scripts": {
32
+ "build": "bun build.ts"
33
+ },
32
34
  "type": "module"
33
35
  }
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  // Environment setup & latest features
4
- "lib": ["ESNext"],
4
+ "lib": ["ESNext", "DOM"],
5
5
  "target": "ESNext",
6
6
  "module": "Preserve",
7
7
  "moduleDetection": "force",