@ohmyteeth/line-flex-message-renderer-core 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Oh my teeth, Co.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,326 @@
1
+ import React from "react";
2
+ //#region src/interfaces/actions/camera.d.ts
3
+ type CameraAction = {
4
+ type: "camera";
5
+ label: string;
6
+ };
7
+ //#endregion
8
+ //#region src/interfaces/actions/cameraroll.d.ts
9
+ type CameraRollAction = {
10
+ type: "cameraroll";
11
+ label: string;
12
+ };
13
+ //#endregion
14
+ //#region src/interfaces/actions/clipboard.d.ts
15
+ type ClipboardAction = {
16
+ type: "clipboard";
17
+ label?: string;
18
+ clipboardText: string;
19
+ };
20
+ //#endregion
21
+ //#region src/interfaces/actions/datetimepicker.d.ts
22
+ type DateTimePickerAction = {
23
+ type: "datetimepicker";
24
+ label?: string;
25
+ data: string;
26
+ mode: "date" | "time" | "datetime";
27
+ initial?: string;
28
+ max?: string;
29
+ min?: string;
30
+ };
31
+ //#endregion
32
+ //#region src/interfaces/actions/location.d.ts
33
+ type LocationAction = {
34
+ type: "location";
35
+ label: string;
36
+ };
37
+ //#endregion
38
+ //#region src/interfaces/actions/message.d.ts
39
+ type MessageAction = {
40
+ type: "message";
41
+ label?: string;
42
+ text: string;
43
+ };
44
+ //#endregion
45
+ //#region src/interfaces/actions/property-types.d.ts
46
+ type InputOption = "closeRichMenu" | "openRichMenu" | "openKeyboard" | "openVoice";
47
+ //#endregion
48
+ //#region src/interfaces/actions/postback.d.ts
49
+ type PostbackAction = {
50
+ type: "postback";
51
+ data: string;
52
+ displayText?: string;
53
+ text?: string;
54
+ inputOption?: InputOption;
55
+ fillInText?: string;
56
+ };
57
+ //#endregion
58
+ //#region src/interfaces/actions/richmenuswitch.d.ts
59
+ type RichMenuSwitchAction = {
60
+ type: "richmenuswitch";
61
+ label?: string;
62
+ richMenuAliasId: string;
63
+ data: string;
64
+ };
65
+ //#endregion
66
+ //#region src/interfaces/actions/uri.d.ts
67
+ type UriAction = {
68
+ type: "uri";
69
+ label?: string;
70
+ uri: string;
71
+ altUrl?: {
72
+ desktop: string;
73
+ };
74
+ };
75
+ //#endregion
76
+ //#region src/interfaces/actions/index.d.ts
77
+ type Action = CameraAction | CameraRollAction | ClipboardAction | DateTimePickerAction | LocationAction | MessageAction | PostbackAction | RichMenuSwitchAction | UriAction;
78
+ //#endregion
79
+ //#region src/interfaces/components/property-types.d.ts
80
+ type AlignItems = "flex-start" | "flex-end" | "center";
81
+ type AspectMode = "cover" | "fit";
82
+ type BorderWidth = `${number}px` | "none" | "light" | "normal" | "medium" | "semi-bold" | "bold";
83
+ type CornerRadius = "none" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
84
+ type Gravity = "top" | "bottom" | "center";
85
+ type FontWeight = "regular" | "bold";
86
+ type FontStyle = "normal" | "italic";
87
+ type IconSize = `${number}px` | "xxs" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "3xl" | "4xl" | "5xl";
88
+ type ImageSize = `${number}px` | `${number}%` | "xxs" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl" | "3xl" | "4xl" | "5xl" | "full";
89
+ type JustifyContent = "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "space-evenly";
90
+ type LineSpacing = `${number}px`;
91
+ type Margin = `${number}px` | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
92
+ type Offset = `${number}px` | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
93
+ type Padding = `${number}px` | `${number}%` | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
94
+ type Position = "relative" | "absolute";
95
+ type Spacing = `${number}px` | "none" | "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
96
+ type TextDecoration = "none" | "underline" | "line-through";
97
+ type TextHorizontalAlign = "start" | "end" | "center";
98
+ //#endregion
99
+ //#region src/interfaces/components/button.d.ts
100
+ type ButtonComponent = {
101
+ type: "button";
102
+ action: Action;
103
+ flex?: number;
104
+ margin?: Margin;
105
+ position?: Position;
106
+ offsetTop?: Offset;
107
+ offsetBottom?: Offset;
108
+ offsetStart?: Offset;
109
+ offsetEnd?: Offset;
110
+ height?: "sm" | "md";
111
+ style?: "primary" | "secondary" | "link";
112
+ color?: string;
113
+ gravity?: Gravity;
114
+ adjustMode?: "shrink-to-fit";
115
+ scaling?: boolean;
116
+ };
117
+ //#endregion
118
+ //#region src/interfaces/components/filler.d.ts
119
+ type FillerComponent = {
120
+ type: "filler";
121
+ flex?: number;
122
+ };
123
+ //#endregion
124
+ //#region src/interfaces/components/icon.d.ts
125
+ type IconComponent = {
126
+ type: "icon";
127
+ url: string;
128
+ margin?: Margin;
129
+ position?: Position;
130
+ offsetTop?: Offset;
131
+ offsetBottom?: Offset;
132
+ offsetStart?: Offset;
133
+ offsetEnd?: Offset;
134
+ size?: IconSize;
135
+ scaling?: boolean;
136
+ aspectRatio?: `${number}:${number}`;
137
+ };
138
+ //#endregion
139
+ //#region src/interfaces/components/image.d.ts
140
+ type ImageComponent = {
141
+ type: "image";
142
+ url: string;
143
+ flex?: number;
144
+ margin?: Margin;
145
+ position?: Position;
146
+ offsetTop?: Offset;
147
+ offsetBottom?: Offset;
148
+ offsetStart?: Offset;
149
+ offsetEnd?: Offset;
150
+ align?: TextHorizontalAlign;
151
+ gravity?: Gravity;
152
+ size?: ImageSize;
153
+ aspectRatio?: `${number}:${number}`;
154
+ aspectMode?: AspectMode;
155
+ backgroundColor?: string;
156
+ action?: Action;
157
+ animated?: boolean;
158
+ };
159
+ //#endregion
160
+ //#region src/interfaces/components/separator.d.ts
161
+ type SeparatorComponent = {
162
+ type: "separator";
163
+ margin?: Margin;
164
+ color?: string;
165
+ };
166
+ //#endregion
167
+ //#region src/interfaces/components/span.d.ts
168
+ type SpanComponent = {
169
+ type: "span";
170
+ text?: string;
171
+ color?: string;
172
+ size?: IconSize;
173
+ weight?: FontWeight;
174
+ style?: FontStyle;
175
+ decoration?: TextDecoration;
176
+ };
177
+ //#endregion
178
+ //#region src/interfaces/components/text.d.ts
179
+ type TextComponent = {
180
+ type: "text";
181
+ text?: string;
182
+ contents: SpanComponent[];
183
+ adjustMode?: "shrink-to-fit";
184
+ flex?: number;
185
+ margin?: Margin;
186
+ position?: Position;
187
+ offsetTop?: Offset;
188
+ offsetBottom?: Offset;
189
+ offsetStart?: Offset;
190
+ offsetEnd?: Offset;
191
+ size?: IconSize;
192
+ scaling?: boolean;
193
+ align?: TextHorizontalAlign;
194
+ gravity?: Gravity;
195
+ wrap?: boolean;
196
+ lineSpacing?: LineSpacing;
197
+ maxLines?: number;
198
+ weight?: FontWeight;
199
+ color?: string;
200
+ action?: Action;
201
+ style?: FontStyle;
202
+ decoration?: TextDecoration;
203
+ };
204
+ //#endregion
205
+ //#region src/interfaces/components/box.d.ts
206
+ interface BoxComponentBase {
207
+ backgroundColor?: string;
208
+ borderColor?: string;
209
+ borderWidth?: BorderWidth;
210
+ cornerRadius?: CornerRadius;
211
+ width?: `${number}px` | `${number}%`;
212
+ maxWidth?: `${number}px` | `${number}%`;
213
+ height?: `${number}px` | `${number}%`;
214
+ maxHeight?: `${number}px` | `${number}%`;
215
+ flex?: number;
216
+ spacing?: Spacing;
217
+ margin?: Margin;
218
+ paddingAll?: Padding;
219
+ paddingTop?: Padding;
220
+ paddingBottom?: Padding;
221
+ paddingStart?: Padding;
222
+ paddingEnd?: Padding;
223
+ position?: Position;
224
+ offsetTop?: Offset;
225
+ offsetBottom?: Offset;
226
+ offsetStart?: Offset;
227
+ offsetEnd?: Offset;
228
+ action?: Action;
229
+ justifyContent?: JustifyContent;
230
+ alignItems?: AlignItems;
231
+ background?: {
232
+ type?: "linearGradient";
233
+ angle?: `${number}deg`;
234
+ startColor?: string;
235
+ endColor?: string;
236
+ centerColor?: string;
237
+ centerPosition: `${number}%`;
238
+ };
239
+ }
240
+ type HorizontalBoxComponent = BoxComponentBase & {
241
+ type: "box";
242
+ layout: "horizontal";
243
+ contents: (BoxComponent | ButtonComponent | ImageComponent | TextComponent | SeparatorComponent | FillerComponent)[];
244
+ };
245
+ type VerticalBoxComponent = BoxComponentBase & {
246
+ type: "box";
247
+ layout: "vertical";
248
+ contents: (BoxComponent | ButtonComponent | ImageComponent | TextComponent | SeparatorComponent | FillerComponent)[];
249
+ };
250
+ type BaselineBoxComponent = BoxComponentBase & {
251
+ type: "box";
252
+ layout: "baseline";
253
+ contents: (IconComponent | TextComponent | FillerComponent)[];
254
+ };
255
+ type BoxComponent = HorizontalBoxComponent | VerticalBoxComponent | BaselineBoxComponent;
256
+ //#endregion
257
+ //#region src/interfaces/components/video.d.ts
258
+ type VideoComponent = {
259
+ type: "video";
260
+ url: string;
261
+ previewUrl: string;
262
+ altContent: string;
263
+ aspectRatio?: `${number}:${number}`;
264
+ action?: UriAction;
265
+ };
266
+ //#endregion
267
+ //#region src/interfaces/containers/bubble.d.ts
268
+ interface BlockStyle {
269
+ backgroundColor?: string;
270
+ separator?: boolean;
271
+ separatorColor?: string;
272
+ }
273
+ interface BubbleContainer {
274
+ type: "bubble";
275
+ size?: "nano" | "micro" | "deca" | "hecto" | "kilo" | "mega" | "giga";
276
+ direction?: "ltr" | "rtl";
277
+ header?: BoxComponent;
278
+ hero?: BoxComponent | ImageComponent | VideoComponent;
279
+ body?: BoxComponent;
280
+ footer?: BoxComponent;
281
+ style?: {
282
+ header?: BlockStyle;
283
+ hero?: BlockStyle;
284
+ body?: BlockStyle;
285
+ footer?: BlockStyle;
286
+ };
287
+ action?: Action;
288
+ }
289
+ //#endregion
290
+ //#region src/interfaces/containers/carousel.d.ts
291
+ interface CarouselContainer {
292
+ type: "carousel";
293
+ contents: BubbleContainer[];
294
+ }
295
+ //#endregion
296
+ //#region src/components.d.ts
297
+ type ClickHandler = (action: Action) => void;
298
+ type ComponentRegistrar = {
299
+ box?: (data: BoxComponent, onClick: ClickHandler) => React.ReactNode;
300
+ button?: (data: ButtonComponent, onClick: ClickHandler) => React.ReactNode;
301
+ filler?: (data: FillerComponent, onClick: ClickHandler) => React.ReactNode;
302
+ icon?: (data: IconComponent, onClick: ClickHandler) => React.ReactNode;
303
+ image?: (data: ImageComponent, onClick: ClickHandler) => React.ReactNode;
304
+ separator?: (data: SeparatorComponent, onClick: ClickHandler) => React.ReactNode;
305
+ span?: (data: SpanComponent, onClick: ClickHandler) => React.ReactNode;
306
+ text?: (data: TextComponent, onClick: ClickHandler) => React.ReactNode;
307
+ video?: (data: VideoComponent, onClick: ClickHandler) => React.ReactNode;
308
+ };
309
+ declare const registerComponents: (components: ComponentRegistrar) => void;
310
+ declare const renderComponent: (data: BoxComponent | ButtonComponent | FillerComponent | IconComponent | ImageComponent | SeparatorComponent | SpanComponent | TextComponent | VideoComponent, onClick?: (action: Action) => void) => React.ReactElement<any, string | React.JSXElementConstructor<any>>;
311
+ //#endregion
312
+ //#region src/utils/styles.d.ts
313
+ declare const getActualSize: (size?: `${number}px` | `${number}%`) => number | `${number}%` | undefined;
314
+ declare const getActualNumericSize: (size?: `${number}px` | `${number}%`) => number | undefined;
315
+ declare const getIconSize: (size?: IconSize) => `${number}px` | undefined;
316
+ declare const getMarginSize: (size?: Margin) => `${number}px` | undefined;
317
+ declare const getPaddingSize: (size?: Padding) => `${number}%` | `${number}px` | undefined;
318
+ declare const getOffset: (size?: Offset) => `${number}px` | undefined;
319
+ declare const getSpacingSize: (size?: Spacing) => `${number}px` | undefined;
320
+ declare const getButtonHeight: (size?: "sm" | "md") => "40px" | "48px";
321
+ declare const getImageSize: (size?: ImageSize) => "unset" | `${number}%` | `${number}px`;
322
+ declare const getBorderWidth: (size?: BorderWidth) => `${number}px` | undefined;
323
+ declare const getBorderRadius: (size?: CornerRadius) => "0px" | "12px" | "16px" | "20px" | "2px" | "4px" | "8px" | undefined;
324
+ //#endregion
325
+ export { Action, type BoxComponent, type BubbleContainer, type ButtonComponent, type CameraAction, type CameraRollAction, type CarouselContainer, ClickHandler, type ClipboardAction, type DateTimePickerAction, type FillerComponent, type IconComponent, type ImageComponent, type LocationAction, type MessageAction, type PostbackAction, type RichMenuSwitchAction, type SeparatorComponent, type SpanComponent, type TextComponent, type UriAction, type VideoComponent, getActualNumericSize, getActualSize, getBorderRadius, getBorderWidth, getButtonHeight, getIconSize, getImageSize, getMarginSize, getOffset, getPaddingSize, getSpacingSize, registerComponents, renderComponent };
326
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/interfaces/actions/camera.ts","../src/interfaces/actions/cameraroll.ts","../src/interfaces/actions/clipboard.ts","../src/interfaces/actions/datetimepicker.ts","../src/interfaces/actions/location.ts","../src/interfaces/actions/message.ts","../src/interfaces/actions/property-types.ts","../src/interfaces/actions/postback.ts","../src/interfaces/actions/richmenuswitch.ts","../src/interfaces/actions/uri.ts","../src/interfaces/actions/index.ts","../src/interfaces/components/property-types.ts","../src/interfaces/components/button.ts","../src/interfaces/components/filler.ts","../src/interfaces/components/icon.ts","../src/interfaces/components/image.ts","../src/interfaces/components/separator.ts","../src/interfaces/components/span.ts","../src/interfaces/components/text.ts","../src/interfaces/components/box.ts","../src/interfaces/components/video.ts","../src/interfaces/containers/bubble.ts","../src/interfaces/containers/carousel.ts","../src/components.ts","../src/utils/styles.ts"],"mappings":";;KAAY;EACV;EACA;;;;KCFU;EACV;EACA;;;;KCFU;EACV;EACA;EACA;;;;KCHU;EACV;EACA;EACA;EACA;EACA;EACA;EACA;;;;KCPU;EACV;EACA;;;;KCFU;EACV;EACA;EACA;;;;KCHU;;;KCEA;EACV;EACA;EACA;EACA;EACA,cAAc;EACd;;;;KCRU;EACV;EACA;EACA;EACA;;;;KCJU;EACV;EACA;EACA;EACA;IACE;;;;;KCiBQ,SACR,eACA,mBACA,kBACA,uBACA,iBACA,gBACA,iBACA,uBACA;;;KC/BQ;KAEA;KAEA;KASA;KAEA;KAEA;KAEA;KAEA;KAaA;KAeA;KAQA;KAEA;KAUA;KAUA;KAWA;KAEA;KAUA;KAEA;;;KCrGA;EACV;EACA,QAAQ;EACR;EACA,SAAS;EACT,WAAW;EACX,YAAY;EACZ,eAAe;EACf,cAAc;EACd,YAAY;EACZ;EACA;EACA;EACA,UAAU;EACV;EACA;;;;KClBU;EACV;EACA;;;;KCAU;EACV;EACA;EACA,SAAS;EACT,WAAW;EACX,YAAY;EACZ,eAAe;EACf,cAAc;EACd,YAAY;EACZ,OAAO;EACP;EACA;;;;KCFU;EACV;EACA;EACA;EACA,SAAS;EACT,WAAW;EACX,YAAY;EACZ,eAAe;EACf,cAAc;EACd,YAAY;EACZ,QAAQ;EACR,UAAU;EACV,OAAO;EACP;EACA,aAAa;EACb;EACA,SAAS;EACT;;;;KC1BU;EACV;EACA,SAAS;EACT;;;;KCEU;EACV;EACA;EACA;EACA,OAAO;EACP,SAAS;EACT,Q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MAAM,oBAAoB,SAAS,iBAAiB,MAAM;EACvE,QAAQ,MAAM,eAAe,SAAS,iBAAiB,MAAM;EAC7D,QAAQ,MAAM,eAAe,SAAS,iBAAiB,MAAM;EAC7D,SAAS,MAAM,gBAAgB,SAAS,iBAAiB,MAAM;;cAGpD,qBAAkB,YAAgB;cAQlC,kBAAe,MAEtB,eACA,kBACA,kBACA,gBACA,iBACA,qBACA,gBACA,gBACA,gBAAc,WACP,QAAQ,oBAAe,MAAA,2BAAA,MAAA;;;cCtCvB,gBAAa;cAgBb,uBAAoB;cAYpB,cAAW,OAAW;cAqCtB,gBAAa,OAAW;cA4BxB,iBAAc,OAAW;cA4BzB,YAAS,OAAW;cA4BpB,iBAAc,OAAW;cA4BzB,kBAAe;cAaf,eAAY,OAAW;cA6CvB,iBAAc,OAAW;cAyBzB,kBAAe,OAAW"}
package/dist/index.mjs ADDED
@@ -0,0 +1,146 @@
1
+ import React from "react";
2
+ //#region src/components.ts
3
+ const registry = /* @__PURE__ */ new Map();
4
+ const registerComponents = (components) => {
5
+ Object.entries(components).forEach(([key, component]) => {
6
+ if (component) registry.set(key, component);
7
+ });
8
+ };
9
+ const renderComponent = (data, onClick) => {
10
+ const componentType = data.type;
11
+ const component = registry.get(componentType);
12
+ if (!component) throw new Error(`Component type "${componentType}" is not registered.`);
13
+ const handleClick = (action) => {
14
+ if (onClick) onClick(action);
15
+ };
16
+ return React.createElement(component, {
17
+ ...data,
18
+ onClick: handleClick
19
+ });
20
+ };
21
+ //#endregion
22
+ //#region src/utils/styles.ts
23
+ const getActualSize = (size) => {
24
+ if (size === void 0) return;
25
+ if (size.endsWith("px")) return parseInt(size, 10);
26
+ if (size.endsWith("%")) return size;
27
+ };
28
+ const getActualNumericSize = (size) => {
29
+ if (size === void 0) return;
30
+ if (size.endsWith("px")) return parseInt(size, 10);
31
+ };
32
+ const getIconSize = (size) => {
33
+ switch (size) {
34
+ case "xxs": return "11px";
35
+ case "xs": return "13px";
36
+ case "sm": return "14px";
37
+ case "md": return "16px";
38
+ case "lg": return "19px";
39
+ case "xl": return "22px";
40
+ case "xxl": return "29px";
41
+ case "3xl": return "35px";
42
+ case "4xl": return "48px";
43
+ case "5xl": return "74px";
44
+ default: return size;
45
+ }
46
+ };
47
+ const getMarginSize = (size) => {
48
+ switch (size) {
49
+ case "none": return "0px";
50
+ case "xs": return "2px";
51
+ case "sm": return "4px";
52
+ case "md": return "8px";
53
+ case "lg": return "12px";
54
+ case "xl": return "16px";
55
+ case "xxl": return "20px";
56
+ default: return size;
57
+ }
58
+ };
59
+ const getPaddingSize = (size) => {
60
+ switch (size) {
61
+ case "none": return "0px";
62
+ case "xs": return "2px";
63
+ case "sm": return "4px";
64
+ case "md": return "8px";
65
+ case "lg": return "12px";
66
+ case "xl": return "16px";
67
+ case "xxl": return "20px";
68
+ default: return size;
69
+ }
70
+ };
71
+ const getOffset = (size) => {
72
+ switch (size) {
73
+ case "none": return "0px";
74
+ case "xs": return "2px";
75
+ case "sm": return "4px";
76
+ case "md": return "8px";
77
+ case "lg": return "12px";
78
+ case "xl": return "16px";
79
+ case "xxl": return "20px";
80
+ default: return size;
81
+ }
82
+ };
83
+ const getSpacingSize = (size) => {
84
+ switch (size) {
85
+ case "none": return "0px";
86
+ case "xs": return "2px";
87
+ case "sm": return "4px";
88
+ case "md": return "8px";
89
+ case "lg": return "12px";
90
+ case "xl": return "20px";
91
+ case "xxl": return "28px";
92
+ default: return size;
93
+ }
94
+ };
95
+ const getButtonHeight = (size) => {
96
+ switch (size) {
97
+ case "sm": return "40px";
98
+ case "md": return "48px";
99
+ default: return "40px";
100
+ }
101
+ };
102
+ const getImageSize = (size) => {
103
+ switch (size) {
104
+ case "xxs": return "40px";
105
+ case "xs": return "60px";
106
+ case "sm": return "80px";
107
+ case "md": return "100px";
108
+ case "lg": return "120px";
109
+ case "xl": return "140px";
110
+ case "xxl": return "160px";
111
+ case "3xl": return "180px";
112
+ case "4xl": return "200px";
113
+ case "5xl": return "220px";
114
+ case "full": return "100%";
115
+ default:
116
+ if (size?.endsWith("px") || size?.endsWith("%")) return size;
117
+ return "unset";
118
+ }
119
+ };
120
+ const getBorderWidth = (size) => {
121
+ switch (size) {
122
+ case "none": return "0px";
123
+ case "light": return "0.5px";
124
+ case "normal": return "1px";
125
+ case "medium": return "2px";
126
+ case "semi-bold": return "3px";
127
+ case "bold": return "4px";
128
+ default: return size;
129
+ }
130
+ };
131
+ const getBorderRadius = (size) => {
132
+ switch (size) {
133
+ case "none": return "0px";
134
+ case "xs": return "2px";
135
+ case "sm": return "4px";
136
+ case "md": return "8px";
137
+ case "lg": return "12px";
138
+ case "xl": return "16px";
139
+ case "xxl": return "20px";
140
+ default: return size;
141
+ }
142
+ };
143
+ //#endregion
144
+ export { getActualNumericSize, getActualSize, getBorderRadius, getBorderWidth, getButtonHeight, getIconSize, getImageSize, getMarginSize, getOffset, getPaddingSize, getSpacingSize, registerComponents, renderComponent };
145
+
146
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/components.ts","../src/utils/styles.ts"],"sourcesContent":["import React from \"react\";\r\nimport type {\r\n BoxComponent,\r\n ButtonComponent,\r\n FillerComponent,\r\n IconComponent,\r\n ImageComponent,\r\n SeparatorComponent,\r\n SpanComponent,\r\n TextComponent,\r\n VideoComponent,\r\n} from \"./interfaces/components/index.js\";\r\nimport type { Action } from \"./interfaces/index.js\";\r\n\r\nconst registry = new Map<string, (data: any, onClick: ClickHandler) => React.ReactNode>();\r\n\r\nexport type ClickHandler = (action: Action) => void;\r\n\r\ntype ComponentRegistrar = {\r\n box?: (data: BoxComponent, onClick: ClickHandler) => React.ReactNode;\r\n button?: (data: ButtonComponent, onClick: ClickHandler) => React.ReactNode;\r\n filler?: (data: FillerComponent, onClick: ClickHandler) => React.ReactNode;\r\n icon?: (data: IconComponent, onClick: ClickHandler) => React.ReactNode;\r\n image?: (data: ImageComponent, onClick: ClickHandler) => React.ReactNode;\r\n separator?: (data: SeparatorComponent, onClick: ClickHandler) => React.ReactNode;\r\n span?: (data: SpanComponent, onClick: ClickHandler) => React.ReactNode;\r\n text?: (data: TextComponent, onClick: ClickHandler) => React.ReactNode;\r\n video?: (data: VideoComponent, onClick: ClickHandler) => React.ReactNode;\r\n};\r\n\r\nexport const registerComponents = (components: ComponentRegistrar) => {\r\n Object.entries(components).forEach(([key, component]) => {\r\n if (component) {\r\n registry.set(key, component);\r\n }\r\n });\r\n};\r\n\r\nexport const renderComponent = (\r\n data:\r\n | BoxComponent\r\n | ButtonComponent\r\n | FillerComponent\r\n | IconComponent\r\n | ImageComponent\r\n | SeparatorComponent\r\n | SpanComponent\r\n | TextComponent\r\n | VideoComponent,\r\n onClick?: (action: Action) => void,\r\n) => {\r\n const componentType = data.type;\r\n const component = registry.get(componentType);\r\n if (!component) {\r\n throw new Error(`Component type \"${componentType}\" is not registered.`);\r\n }\r\n\r\n const handleClick = (action: Action) => {\r\n if (onClick) {\r\n onClick(action);\r\n }\r\n };\r\n\r\n // Must go through React.createElement (not a plain `component(data, handleClick)` call) so this\r\n // actually becomes its own component instance in React's tree. A plain call runs the registered\r\n // function's hooks as part of *this* caller's render pass instead of its own — breaking useState,\r\n // useContext (a child's `useContext` would read the value visible to its parent, not what the parent's\r\n // own JSX provides below it), and silently dropping `onClick` too, since these components declare a\r\n // single props parameter, not the `(data, onClick)` shape this was calling them with.\r\n return React.createElement(component as React.ComponentType<any>, { ...data, onClick: handleClick });\r\n};\r\n","import type {\r\n BorderWidth,\r\n CornerRadius,\r\n IconSize,\r\n ImageSize,\r\n Margin,\r\n Offset,\r\n Padding,\r\n Spacing,\r\n} from \"../interfaces/components/property-types.js\";\r\n\r\nexport const getActualSize = (size?: `${number}px` | `${number}%`): number | `${number}%` | undefined => {\r\n if (size === undefined) {\r\n return undefined;\r\n }\r\n\r\n if (size.endsWith(\"px\")) {\r\n return parseInt(size, 10);\r\n }\r\n\r\n if (size.endsWith(\"%\")) {\r\n return size as `${number}%`;\r\n }\r\n\r\n return undefined;\r\n};\r\n\r\nexport const getActualNumericSize = (size?: `${number}px` | `${number}%`): number | undefined => {\r\n if (size === undefined) {\r\n return undefined;\r\n }\r\n\r\n if (size.endsWith(\"px\")) {\r\n return parseInt(size, 10);\r\n }\r\n\r\n return undefined;\r\n};\r\n\r\nexport const getIconSize = (size?: IconSize) => {\r\n switch (size) {\r\n case \"xxs\":\r\n return \"11px\";\r\n\r\n case \"xs\":\r\n return \"13px\";\r\n\r\n case \"sm\":\r\n return \"14px\";\r\n\r\n case \"md\":\r\n return \"16px\";\r\n\r\n case \"lg\":\r\n return \"19px\";\r\n\r\n case \"xl\":\r\n return \"22px\";\r\n\r\n case \"xxl\":\r\n return \"29px\";\r\n\r\n case \"3xl\":\r\n return \"35px\";\r\n\r\n case \"4xl\":\r\n return \"48px\";\r\n\r\n case \"5xl\":\r\n return \"74px\";\r\n\r\n default:\r\n return size;\r\n }\r\n};\r\n\r\nexport const getMarginSize = (size?: Margin) => {\r\n switch (size) {\r\n case \"none\":\r\n return \"0px\";\r\n\r\n case \"xs\":\r\n return \"2px\";\r\n\r\n case \"sm\":\r\n return \"4px\";\r\n\r\n case \"md\":\r\n return \"8px\";\r\n\r\n case \"lg\":\r\n return \"12px\";\r\n\r\n case \"xl\":\r\n return \"16px\";\r\n\r\n case \"xxl\":\r\n return \"20px\";\r\n\r\n default:\r\n return size;\r\n }\r\n};\r\n\r\nexport const getPaddingSize = (size?: Padding) => {\r\n switch (size) {\r\n case \"none\":\r\n return \"0px\";\r\n\r\n case \"xs\":\r\n return \"2px\";\r\n\r\n case \"sm\":\r\n return \"4px\";\r\n\r\n case \"md\":\r\n return \"8px\";\r\n\r\n case \"lg\":\r\n return \"12px\";\r\n\r\n case \"xl\":\r\n return \"16px\";\r\n\r\n case \"xxl\":\r\n return \"20px\";\r\n\r\n default:\r\n return size;\r\n }\r\n};\r\n\r\nexport const getOffset = (size?: Offset) => {\r\n switch (size) {\r\n case \"none\":\r\n return \"0px\";\r\n\r\n case \"xs\":\r\n return \"2px\";\r\n\r\n case \"sm\":\r\n return \"4px\";\r\n\r\n case \"md\":\r\n return \"8px\";\r\n\r\n case \"lg\":\r\n return \"12px\";\r\n\r\n case \"xl\":\r\n return \"16px\";\r\n\r\n case \"xxl\":\r\n return \"20px\";\r\n\r\n default:\r\n return size;\r\n }\r\n};\r\n\r\nexport const getSpacingSize = (size?: Spacing) => {\r\n switch (size) {\r\n case \"none\":\r\n return \"0px\";\r\n\r\n case \"xs\":\r\n return \"2px\";\r\n\r\n case \"sm\":\r\n return \"4px\";\r\n\r\n case \"md\":\r\n return \"8px\";\r\n\r\n case \"lg\":\r\n return \"12px\";\r\n\r\n case \"xl\":\r\n return \"20px\";\r\n\r\n case \"xxl\":\r\n return \"28px\";\r\n\r\n default:\r\n return size;\r\n }\r\n};\r\n\r\nexport const getButtonHeight = (size?: \"sm\" | \"md\") => {\r\n switch (size) {\r\n case \"sm\":\r\n return \"40px\";\r\n\r\n case \"md\":\r\n return \"48px\";\r\n\r\n default:\r\n return \"40px\";\r\n }\r\n};\r\n\r\nexport const getImageSize = (size?: ImageSize) => {\r\n switch (size) {\r\n case \"xxs\":\r\n return \"40px\";\r\n\r\n case \"xs\":\r\n return \"60px\";\r\n\r\n case \"sm\":\r\n return \"80px\";\r\n\r\n case \"md\":\r\n return \"100px\";\r\n\r\n case \"lg\":\r\n return \"120px\";\r\n\r\n case \"xl\":\r\n return \"140px\";\r\n\r\n case \"xxl\":\r\n return \"160px\";\r\n\r\n case \"3xl\":\r\n return \"180px\";\r\n\r\n case \"4xl\":\r\n return \"200px\";\r\n\r\n case \"5xl\":\r\n return \"220px\";\r\n\r\n case \"full\":\r\n return \"100%\";\r\n\r\n default: {\r\n if (size?.endsWith(\"px\") || size?.endsWith(\"%\")) {\r\n return size;\r\n }\r\n\r\n return \"unset\";\r\n }\r\n }\r\n};\r\n\r\nexport const getBorderWidth = (size?: BorderWidth) => {\r\n switch (size) {\r\n case \"none\":\r\n return \"0px\";\r\n\r\n case \"light\":\r\n return \"0.5px\";\r\n\r\n case \"normal\":\r\n return \"1px\";\r\n\r\n case \"medium\":\r\n return \"2px\";\r\n\r\n case \"semi-bold\":\r\n return \"3px\";\r\n\r\n case \"bold\":\r\n return \"4px\";\r\n\r\n default:\r\n return size;\r\n }\r\n};\r\n\r\nexport const getBorderRadius = (size?: CornerRadius) => {\r\n switch (size) {\r\n case \"none\":\r\n return \"0px\";\r\n\r\n case \"xs\":\r\n return \"2px\";\r\n\r\n case \"sm\":\r\n return \"4px\";\r\n\r\n case \"md\":\r\n return \"8px\";\r\n\r\n case \"lg\":\r\n return \"12px\";\r\n\r\n case \"xl\":\r\n return \"16px\";\r\n\r\n case \"xxl\":\r\n return \"20px\";\r\n\r\n default:\r\n return size;\r\n }\r\n};"],"mappings":";;AAcA,MAAM,2BAAW,IAAI,IAAmE;AAgBxF,MAAa,sBAAsB,eAAmC;CACpE,OAAO,QAAQ,UAAU,CAAC,CAAC,SAAS,CAAC,KAAK,eAAe;EACvD,IAAI,WACF,SAAS,IAAI,KAAK,SAAS;CAE/B,CAAC;AACH;AAEA,MAAa,mBACX,MAUA,YACG;CACH,MAAM,gBAAgB,KAAK;CAC3B,MAAM,YAAY,SAAS,IAAI,aAAa;CAC5C,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,mBAAmB,cAAc,qBAAqB;CAGxE,MAAM,eAAe,WAAmB;EACtC,IAAI,SACF,QAAQ,MAAM;CAElB;CAQA,OAAO,MAAM,cAAc,WAAuC;EAAE,GAAG;EAAM,SAAS;CAAY,CAAC;AACrG;;;AC3DA,MAAa,iBAAiB,SAA2E;CACvG,IAAI,SAAS,KAAA,GACX;CAGF,IAAI,KAAK,SAAS,IAAI,GACpB,OAAO,SAAS,MAAM,EAAE;CAG1B,IAAI,KAAK,SAAS,GAAG,GACnB,OAAO;AAIX;AAEA,MAAa,wBAAwB,SAA4D;CAC/F,IAAI,SAAS,KAAA,GACX;CAGF,IAAI,KAAK,SAAS,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MAAa,mBAAmB,SAAuB;CACrD,QAAQ,MAAR;EACE,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,SACE,OAAO;CACX;AACF;AAEA,MAAa,gBAAgB,SAAqB;CAChD,QAAQ,MAAR;EACE,KAAK,OACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,OACH,OAAO;EAET,KAAK,OACH,OAAO;EAET,KAAK,OACH,OAAO;EAET,KAAK,OACH,OAAO;EAET,KAAK,QACH,OAAO;EAET;GACE,IAAI,MAAM,SAAS,IAAI,KAAK,MAAM,SAAS,GAAG,GAC5C,OAAO;GAGT,OAAO;CAEX;AACF;AAEA,MAAa,kBAAkB,SAAuB;CACpD,QAAQ,MAAR;EACE,KAAK,QACH,OAAO;EAET,KAAK,SACH,OAAO;EAET,KAAK,UACH,OAAO;EAET,KAAK,UACH,OAAO;EAET,KAAK,aACH,OAAO;EAET,KAAK,QACH,OAAO;EAET,SACE,OAAO;CACX;AACF;AAEA,MAAa,mBAAmB,SAAwB;CACtD,QAAQ,MAAR;EACE,KAAK,QACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,MACH,OAAO;EAET,KAAK,OACH,OAAO;EAET,SACE,OAAO;CACX;AACF"}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@ohmyteeth/line-flex-message-renderer-core",
3
+ "version": "0.1.0",
4
+ "description": "This is a core logic library for rendering LINE Flex Messages in React and React Native.",
5
+ "license": "MIT",
6
+ "author": "Oh my teeth, Co.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ohmyteeth/react-line-flex-message-renderer.git"
10
+ },
11
+ "homepage": "https://github.com/ohmyteeth/react-line-flex-message-renderer",
12
+ "bugs": {
13
+ "url": "https://github.com/ohmyteeth/react-line-flex-message-renderer/issues"
14
+ },
15
+ "keywords": [
16
+ "LINE",
17
+ "Flex Message",
18
+ "React",
19
+ "React Native"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
29
+ "type": "module",
30
+ "main": "./dist/index.mjs",
31
+ "types": "./dist/index.d.mts",
32
+ "exports": {
33
+ ".": {
34
+ "import": "./dist/index.mjs",
35
+ "types": "./dist/index.d.mts"
36
+ }
37
+ },
38
+ "devDependencies": {
39
+ "@oxfmt/binding-darwin-arm64": "^0.58.0",
40
+ "@oxfmt/binding-win32-x64-msvc": "^0.58.0",
41
+ "@oxlint/binding-darwin-arm64": "^1.73.0",
42
+ "@oxlint/binding-win32-x64-msvc": "^1.73.0",
43
+ "@types/node": "^26.1.1",
44
+ "@types/react": "^19.2.17",
45
+ "npm-run-all2": "^9.0.2",
46
+ "oxfmt": "^0.58.0",
47
+ "oxlint": "^1.73.0",
48
+ "react": "^19.2.7",
49
+ "tsdown": "^0.22.5",
50
+ "typescript": "^7.0.2",
51
+ "vitest": "^4.1.10"
52
+ },
53
+ "peerDependencies": {
54
+ "react": "^19.2.7"
55
+ },
56
+ "sideEffects": [
57
+ "*.css"
58
+ ],
59
+ "scripts": {
60
+ "dev": "run-p dev:*",
61
+ "dev:tsdown": "tsdown --watch",
62
+ "build": "tsdown",
63
+ "test": "vitest run",
64
+ "test:watch": "vitest watch",
65
+ "typecheck": "tsc -p tsconfig.json --noEmit"
66
+ }
67
+ }