line-flex-message-preview 0.0.0-stage → 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 +21 -0
- package/README.md +254 -2
- package/dist/define.d.ts +1 -0
- package/dist/define.js +4 -0
- package/dist/dom.d.ts +15 -0
- package/dist/dom.js +38 -0
- package/dist/element.d.ts +44 -0
- package/dist/element.js +174 -0
- package/dist/flex-message.bundle.js +132 -0
- package/dist/html.d.ts +30 -0
- package/dist/html.js +86 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +7 -0
- package/dist/profile.d.ts +75 -0
- package/dist/profile.js +86 -0
- package/dist/styles.d.ts +4 -0
- package/dist/styles.js +152 -0
- package/dist/tree.d.ts +29 -0
- package/dist/tree.js +503 -0
- package/dist/types.d.ts +174 -0
- package/dist/types.js +9 -0
- package/dist/validate.d.ts +46 -0
- package/dist/validate.js +473 -0
- package/dist/values.d.ts +24 -0
- package/dist/values.js +78 -0
- package/docs/measurements.md +119 -0
- package/package.json +62 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
export type Keyword = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
|
|
2
|
+
export type SizeKeyword = 'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | '3xl' | '4xl' | '5xl';
|
|
3
|
+
export type BubbleSize = 'nano' | 'micro' | 'deca' | 'hecto' | 'kilo' | 'mega' | 'giga';
|
|
4
|
+
export type BorderWidthKeyword = 'none' | 'light' | 'normal' | 'medium' | 'semi-bold' | 'bold';
|
|
5
|
+
/** `"12px"` */
|
|
6
|
+
export type Px = `${number}px`;
|
|
7
|
+
/** `"50%"` */
|
|
8
|
+
export type Percent = `${number}%`;
|
|
9
|
+
/** An action object. The renderer never executes actions; it only reports them. */
|
|
10
|
+
export interface FlexAction {
|
|
11
|
+
type: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface FlexMessage {
|
|
16
|
+
type: 'flex';
|
|
17
|
+
altText: string;
|
|
18
|
+
contents: FlexContainer;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
export type FlexContainer = FlexBubble | FlexCarousel;
|
|
22
|
+
export interface FlexBlockStyle {
|
|
23
|
+
backgroundColor?: string;
|
|
24
|
+
separator?: boolean;
|
|
25
|
+
separatorColor?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface FlexBubbleStyles {
|
|
28
|
+
header?: FlexBlockStyle;
|
|
29
|
+
hero?: FlexBlockStyle;
|
|
30
|
+
body?: FlexBlockStyle;
|
|
31
|
+
footer?: FlexBlockStyle;
|
|
32
|
+
}
|
|
33
|
+
export interface FlexBubble {
|
|
34
|
+
type: 'bubble';
|
|
35
|
+
size?: BubbleSize;
|
|
36
|
+
direction?: 'ltr' | 'rtl';
|
|
37
|
+
header?: FlexBox;
|
|
38
|
+
hero?: FlexBox | FlexImage | FlexVideo;
|
|
39
|
+
body?: FlexBox;
|
|
40
|
+
footer?: FlexBox;
|
|
41
|
+
styles?: FlexBubbleStyles;
|
|
42
|
+
action?: FlexAction;
|
|
43
|
+
}
|
|
44
|
+
export interface FlexCarousel {
|
|
45
|
+
type: 'carousel';
|
|
46
|
+
contents: FlexBubble[];
|
|
47
|
+
}
|
|
48
|
+
export type FlexComponent = FlexBox | FlexButton | FlexImage | FlexVideo | FlexIcon | FlexText | FlexSpan | FlexSeparator | FlexFiller | FlexSpacer;
|
|
49
|
+
interface Positioned {
|
|
50
|
+
position?: 'relative' | 'absolute';
|
|
51
|
+
offsetTop?: Keyword | Px | Percent;
|
|
52
|
+
offsetBottom?: Keyword | Px | Percent;
|
|
53
|
+
offsetStart?: Keyword | Px | Percent;
|
|
54
|
+
offsetEnd?: Keyword | Px | Percent;
|
|
55
|
+
}
|
|
56
|
+
export interface FlexLinearGradient {
|
|
57
|
+
type: 'linearGradient';
|
|
58
|
+
angle: string;
|
|
59
|
+
startColor: string;
|
|
60
|
+
endColor: string;
|
|
61
|
+
centerColor?: string;
|
|
62
|
+
centerPosition?: Percent;
|
|
63
|
+
}
|
|
64
|
+
export interface FlexBox extends Positioned {
|
|
65
|
+
type: 'box';
|
|
66
|
+
layout: 'horizontal' | 'vertical' | 'baseline';
|
|
67
|
+
contents: FlexComponent[];
|
|
68
|
+
backgroundColor?: string;
|
|
69
|
+
borderColor?: string;
|
|
70
|
+
borderWidth?: BorderWidthKeyword | Px;
|
|
71
|
+
cornerRadius?: Keyword | Px;
|
|
72
|
+
width?: Px | Percent;
|
|
73
|
+
maxWidth?: Px | Percent;
|
|
74
|
+
height?: Px | Percent;
|
|
75
|
+
maxHeight?: Px | Percent;
|
|
76
|
+
flex?: number;
|
|
77
|
+
spacing?: Keyword | Px;
|
|
78
|
+
margin?: Keyword | Px;
|
|
79
|
+
paddingAll?: Keyword | Px | Percent;
|
|
80
|
+
paddingTop?: Keyword | Px | Percent;
|
|
81
|
+
paddingBottom?: Keyword | Px | Percent;
|
|
82
|
+
paddingStart?: Keyword | Px | Percent;
|
|
83
|
+
paddingEnd?: Keyword | Px | Percent;
|
|
84
|
+
action?: FlexAction;
|
|
85
|
+
justifyContent?: 'flex-start' | 'center' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly';
|
|
86
|
+
alignItems?: 'flex-start' | 'center' | 'flex-end';
|
|
87
|
+
background?: FlexLinearGradient;
|
|
88
|
+
}
|
|
89
|
+
export interface FlexButton extends Positioned {
|
|
90
|
+
type: 'button';
|
|
91
|
+
action: FlexAction;
|
|
92
|
+
flex?: number;
|
|
93
|
+
margin?: Keyword | Px;
|
|
94
|
+
height?: 'sm' | 'md';
|
|
95
|
+
style?: 'primary' | 'secondary' | 'link';
|
|
96
|
+
color?: string;
|
|
97
|
+
gravity?: 'top' | 'bottom' | 'center';
|
|
98
|
+
adjustMode?: 'shrink-to-fit';
|
|
99
|
+
scaling?: boolean;
|
|
100
|
+
}
|
|
101
|
+
export interface FlexImage extends Positioned {
|
|
102
|
+
type: 'image';
|
|
103
|
+
url: string;
|
|
104
|
+
flex?: number;
|
|
105
|
+
margin?: Keyword | Px;
|
|
106
|
+
align?: 'start' | 'end' | 'center';
|
|
107
|
+
gravity?: 'top' | 'bottom' | 'center';
|
|
108
|
+
size?: SizeKeyword | 'full' | Px | Percent;
|
|
109
|
+
aspectRatio?: string;
|
|
110
|
+
aspectMode?: 'fit' | 'cover';
|
|
111
|
+
backgroundColor?: string;
|
|
112
|
+
action?: FlexAction;
|
|
113
|
+
animated?: boolean;
|
|
114
|
+
}
|
|
115
|
+
export interface FlexVideo {
|
|
116
|
+
type: 'video';
|
|
117
|
+
url: string;
|
|
118
|
+
previewUrl: string;
|
|
119
|
+
altContent: FlexBox | FlexImage;
|
|
120
|
+
aspectRatio?: string;
|
|
121
|
+
action?: FlexAction;
|
|
122
|
+
}
|
|
123
|
+
export interface FlexIcon extends Positioned {
|
|
124
|
+
type: 'icon';
|
|
125
|
+
url: string;
|
|
126
|
+
margin?: Keyword | Px;
|
|
127
|
+
size?: SizeKeyword | Px;
|
|
128
|
+
aspectRatio?: string;
|
|
129
|
+
scaling?: boolean;
|
|
130
|
+
}
|
|
131
|
+
export interface FlexText extends Positioned {
|
|
132
|
+
type: 'text';
|
|
133
|
+
text?: string;
|
|
134
|
+
contents?: FlexSpan[];
|
|
135
|
+
adjustMode?: 'shrink-to-fit';
|
|
136
|
+
flex?: number;
|
|
137
|
+
margin?: Keyword | Px;
|
|
138
|
+
size?: SizeKeyword | Px;
|
|
139
|
+
align?: 'start' | 'end' | 'center';
|
|
140
|
+
gravity?: 'top' | 'bottom' | 'center';
|
|
141
|
+
wrap?: boolean;
|
|
142
|
+
lineSpacing?: Px;
|
|
143
|
+
weight?: 'regular' | 'bold';
|
|
144
|
+
color?: string;
|
|
145
|
+
action?: FlexAction;
|
|
146
|
+
style?: 'normal' | 'italic';
|
|
147
|
+
decoration?: 'none' | 'underline' | 'line-through';
|
|
148
|
+
maxLines?: number;
|
|
149
|
+
scaling?: boolean;
|
|
150
|
+
}
|
|
151
|
+
export interface FlexSpan {
|
|
152
|
+
type: 'span';
|
|
153
|
+
text?: string;
|
|
154
|
+
color?: string;
|
|
155
|
+
size?: SizeKeyword | Px;
|
|
156
|
+
weight?: 'regular' | 'bold';
|
|
157
|
+
style?: 'normal' | 'italic';
|
|
158
|
+
decoration?: 'none' | 'underline' | 'line-through';
|
|
159
|
+
}
|
|
160
|
+
export interface FlexSeparator {
|
|
161
|
+
type: 'separator';
|
|
162
|
+
margin?: Keyword | Px;
|
|
163
|
+
color?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface FlexFiller {
|
|
166
|
+
type: 'filler';
|
|
167
|
+
flex?: number;
|
|
168
|
+
}
|
|
169
|
+
/** Deprecated, and absent from LINE's OpenAPI document, but still accepted by LINE. */
|
|
170
|
+
export interface FlexSpacer {
|
|
171
|
+
type: 'spacer';
|
|
172
|
+
size?: Exclude<Keyword, 'none'>;
|
|
173
|
+
}
|
|
174
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Types for LINE Flex Message JSON.
|
|
2
|
+
//
|
|
3
|
+
// Structure follows the Flex* schemas of LINE's OpenAPI document
|
|
4
|
+
// (github.com/line/line-openapi, messaging-api.yml). That document types most
|
|
5
|
+
// values as plain `string`; the narrower unions here come from the Messaging
|
|
6
|
+
// API reference. `spec/flex-schemas.json` is a snapshot of the upstream
|
|
7
|
+
// property lists, and tests/spec.test.ts fails when upstream gains a property
|
|
8
|
+
// these types do not know.
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type IssueSeverity = 'error' | 'warning';
|
|
2
|
+
export interface Issue {
|
|
3
|
+
/** JSON Pointer into the validated input. `""` is the input itself. */
|
|
4
|
+
path: string;
|
|
5
|
+
severity: IssueSeverity;
|
|
6
|
+
/** Stable machine-readable identifier. */
|
|
7
|
+
code: 'invalid-json' | 'invalid-type' | 'missing-property' | 'unknown-property' | 'unknown-component' | 'invalid-value' | 'misplaced-component' | 'too-deep' | 'deprecated' | 'not-rendered';
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
type Rule = {
|
|
11
|
+
kind: 'enum';
|
|
12
|
+
values: readonly string[];
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'length';
|
|
15
|
+
keywords?: readonly string[];
|
|
16
|
+
percent?: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'color';
|
|
19
|
+
} | {
|
|
20
|
+
kind: 'url';
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'ratio';
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'integer';
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'boolean';
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'string';
|
|
29
|
+
}
|
|
30
|
+
/** Checked by dedicated code (children, actions, gradients). */
|
|
31
|
+
| {
|
|
32
|
+
kind: 'structure';
|
|
33
|
+
};
|
|
34
|
+
/** Every property each component accepts, and the shape of its value. */
|
|
35
|
+
export declare const COMPONENT_RULES: Readonly<Record<string, Readonly<Record<string, Rule>>>>;
|
|
36
|
+
/** Component types LINE accepts that its OpenAPI document does not list. */
|
|
37
|
+
export declare const UNDOCUMENTED_COMPONENTS: readonly string[];
|
|
38
|
+
export declare const BUBBLE_PROPERTIES: readonly ['type', 'size', 'direction', 'header', 'hero', 'body', 'footer', 'styles', 'action'];
|
|
39
|
+
export declare const BLOCK_STYLE_PROPERTIES: readonly ['backgroundColor', 'separator', 'separatorColor'];
|
|
40
|
+
/**
|
|
41
|
+
* Checks a Flex message (`{ type: "flex", altText, contents }`) or a bare
|
|
42
|
+
* bubble / carousel. A string is parsed as JSON first. Returns every problem
|
|
43
|
+
* found; an empty array means nothing was found, not that LINE will accept it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function validate(input: unknown): Issue[];
|
|
46
|
+
export {};
|