alemonjs 2.1.22 → 2.1.24

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.
@@ -25,7 +25,7 @@ export declare const useMessage: <T extends EventKeys>(event: Events[T]) => read
25
25
  addLink(val: string, options?: {
26
26
  style?: "none" | "bold" | "block" | "strikethrough" | "boldItalic" | "italic";
27
27
  }): any;
28
- addImage(val: Buffer<ArrayBufferLike>): any;
28
+ addImage(val: string | Buffer<ArrayBufferLike>): any;
29
29
  addImageFile(val: string): any;
30
30
  addImageURL(val: string): any;
31
31
  addMention(UserId?: string, options?: {
package/lib/app/index.js CHANGED
@@ -19,4 +19,4 @@ export { onState, unState, useState } from './hook-use-state.js';
19
19
  export { useObserver, useSubscribe } from './hook-use-subscribe.js';
20
20
  export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './message-api.js';
21
21
  export { Format, createEvent } from './message-format.js';
22
- export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './message-format-old.js';
22
+ export { Ark, Attachment, Audio, BT, Custom, Image, ImageFile, ImageURL, Link, MD, Markdown, Mention, Text, Video } from './message-format-old.js';
@@ -1,10 +1,11 @@
1
- import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode } from '../types';
1
+ import { DataMention, DataImage, DataText, DataImageURL, DataImageFile, ButtonRow, DataButtonGroup, DataButton, DataArkList, DataArkListTip, DataArkListContent, DataArkListItem, DataArkCard, DataArkBigCard, DataMarkdownTemplate, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownBold, DataMarkdownItalic, DataMarkdownItalicStar, DataMarkdownStrikethrough, DataMarkdownLink, DataMarkdownImage, DataMarkdownList, DataMarkdownListItem, DataMarkdownBlockquote, DataMarkdownDivider, DataMarkdownNewline, DataLink, DataMarkdownText, DataButtonTemplate, DataMarkdownCode, DataCustom, DataMarkdownOriginal, DataAttachment, DataAudio, DataVideo } from '../types';
2
+ export declare const Custom: (value: DataCustom["value"], options?: DataCustom["options"], type?: DataCustom["type"]) => DataCustom;
2
3
  export declare const Text: (val: DataText["value"], options?: DataText["options"]) => DataText;
3
4
  export declare const Link: (val: DataLink["value"], options?: DataText["options"]) => DataText;
4
5
  export declare const ImageURL: (val: DataImageURL["value"]) => DataImageURL;
5
6
  export declare const ImageFile: (val: DataImageFile["value"]) => DataImageFile;
6
7
  declare const Image: {
7
- (val: Buffer): DataImage;
8
+ (val: Buffer | string): DataImage;
8
9
  url: (val: DataImageURL["value"]) => DataImageURL;
9
10
  file: (val: DataImageFile["value"]) => DataImageFile;
10
11
  };
@@ -48,3 +49,7 @@ declare const MD: {
48
49
  code(value: DataMarkdownCode["value"], options?: DataMarkdownCode["options"]): DataMarkdownCode;
49
50
  };
50
51
  export { MD };
52
+ export declare const Markdown: (val: string) => DataMarkdownOriginal;
53
+ export declare const Attachment: (val: string, options?: DataAttachment["options"]) => DataAttachment;
54
+ export declare const Audio: (val: string) => DataAudio;
55
+ export declare const Video: (val: string) => DataVideo;
@@ -1,3 +1,10 @@
1
+ const Custom = (value, options, type) => {
2
+ return {
3
+ type: type,
4
+ value,
5
+ options
6
+ };
7
+ };
1
8
  const Text = (val, options) => {
2
9
  return {
3
10
  type: 'Text',
@@ -27,7 +34,7 @@ const ImageFile = (val) => {
27
34
  const Image = (val) => {
28
35
  return {
29
36
  type: 'Image',
30
- value: val.toString('base64')
37
+ value: typeof val === 'string' ? val : `base64://${val.toString('base64')}`
31
38
  };
32
39
  };
33
40
  Image.url = ImageURL;
@@ -213,5 +220,30 @@ MD.code = (value, options) => {
213
220
  options: options
214
221
  };
215
222
  };
223
+ const Markdown = (val) => {
224
+ return {
225
+ type: 'MarkdownOriginal',
226
+ value: val
227
+ };
228
+ };
229
+ const Attachment = (val, options) => {
230
+ return {
231
+ type: 'Attachment',
232
+ value: val,
233
+ options
234
+ };
235
+ };
236
+ const Audio = (val) => {
237
+ return {
238
+ type: 'Audio',
239
+ value: val
240
+ };
241
+ };
242
+ const Video = (val) => {
243
+ return {
244
+ type: 'Video',
245
+ value: val
246
+ };
247
+ };
216
248
 
217
- export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text };
249
+ export { Ark, Attachment, Audio, BT, Custom, Image, ImageFile, ImageURL, Link, MD, Markdown, Mention, Text, Video };
@@ -1,5 +1,5 @@
1
1
  import { DataButtonGroup, DataMarkDown, DataEnums, EventKeys, Events } from '../types';
2
- import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD } from './message-format-old.js';
2
+ import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD, Markdown, Attachment, Audio, Video, Custom } from './message-format-old.js';
3
3
  export * from './message-format-old.js';
4
4
  declare class FormatButtonGroup {
5
5
  #private;
@@ -45,6 +45,11 @@ export declare class Format {
45
45
  addButtonGroup(...args: Parameters<typeof BT.group>): this;
46
46
  addMarkdown(md: FormatMarkDown): this;
47
47
  addMarkdown(...args: Parameters<typeof MD>): this;
48
+ addMarkdownOriginal(...args: Parameters<typeof Markdown>): this;
49
+ addAttachment(...args: Parameters<typeof Attachment>): this;
50
+ addAudio(...args: Parameters<typeof Audio>): this;
51
+ addVideo(...args: Parameters<typeof Video>): this;
52
+ addCustom(...args: Parameters<typeof Custom>): this;
48
53
  clear(): this;
49
54
  }
50
55
  export declare function createEvent<T extends EventKeys>(options: {
@@ -1,4 +1,4 @@
1
- import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD } from './message-format-old.js';
1
+ import { Text, Link, Image, ImageFile, ImageURL, Mention, BT, MD, Markdown, Attachment, Audio, Video, Custom } from './message-format-old.js';
2
2
  export { Ark } from './message-format-old.js';
3
3
 
4
4
  class FormatButtonGroup {
@@ -162,6 +162,26 @@ class Format {
162
162
  }
163
163
  return this;
164
164
  }
165
+ addMarkdownOriginal(...args) {
166
+ this.#data.push(Markdown(...args));
167
+ return this;
168
+ }
169
+ addAttachment(...args) {
170
+ this.#data.push(Attachment(...args));
171
+ return this;
172
+ }
173
+ addAudio(...args) {
174
+ this.#data.push(Audio(...args));
175
+ return this;
176
+ }
177
+ addVideo(...args) {
178
+ this.#data.push(Video(...args));
179
+ return this;
180
+ }
181
+ addCustom(...args) {
182
+ this.#data.push(Custom(...args));
183
+ return this;
184
+ }
165
185
  clear() {
166
186
  this.#data = [];
167
187
  return this;
@@ -192,4 +212,4 @@ function createEvent(options) {
192
212
  return { ...event, ...o };
193
213
  }
194
214
 
195
- export { BT, Format, Image, ImageFile, ImageURL, Link, MD, Mention, Text, createEvent };
215
+ export { Attachment, Audio, BT, Custom, Format, Image, ImageFile, ImageURL, Link, MD, Markdown, Mention, Text, Video, createEvent };
@@ -1,19 +1,21 @@
1
1
  import type { Package } from '../types';
2
- export declare class ConfigCore {
2
+ type ConfigValue = {
3
+ [key: string]: any;
4
+ };
5
+ type ConfigListener<T extends ConfigValue = ConfigValue> = (value: T) => void;
6
+ declare class ConfigCore<T extends ConfigValue = ConfigValue> {
3
7
  #private;
4
8
  constructor(dir: string);
5
- get value(): null | {
6
- [key: string]: any;
7
- };
8
- saveValue(value: {
9
- [key: string]: any;
10
- }): void;
11
- get package(): null | Package;
9
+ get value(): T | null;
10
+ saveValue(value: T): void;
11
+ onWatch(listener: ConfigListener<T>): () => void;
12
+ dispose(): void;
13
+ get package(): Package | null;
12
14
  get argv(): {
13
15
  [key: string]: string;
14
16
  };
15
17
  }
16
- export declare const getConfig: () => typeof ConfigCore.prototype;
17
- export declare const getConfigValue: () => {
18
- [key: string]: any;
19
- };
18
+ export declare const getConfig: <T extends ConfigValue = ConfigValue>() => ConfigCore<T>;
19
+ export declare const getConfigValue: <T extends ConfigValue = ConfigValue>() => T;
20
+ export declare const onWatchConfigValue: <T extends ConfigValue = ConfigValue>(callback: ConfigListener<T>) => (() => void);
21
+ export {};
@@ -1,38 +1,31 @@
1
- import { existsSync, readFileSync, watch, mkdirSync, writeFileSync } from 'fs';
1
+ import { readFileSync, existsSync, watch, mkdirSync, writeFileSync } from 'fs';
2
2
  import { join, dirname } from 'path';
3
3
  import YAML from 'yaml';
4
4
  import { ResultCode } from './variable.js';
5
5
 
6
6
  class ConfigCore {
7
- #dir = null;
8
7
  #value = null;
9
8
  #mergedValue = null;
10
9
  #watcher = null;
11
- #initValue = {
12
- gui: {
13
- port: 17127
14
- }
15
- };
10
+ #listeners = new Set();
11
+ #debounceTimer = null;
12
+ #debounceDelay = 100;
13
+ #argvProxy = null;
14
+ #resolvedDir = null;
15
+ #initValue = {};
16
16
  constructor(dir) {
17
- this.#dir = dir;
17
+ this.#resolvedDir = join(process.cwd(), dir);
18
18
  }
19
19
  #invalidateMergedCache() {
20
20
  this.#mergedValue = null;
21
21
  }
22
- #update() {
23
- if (!this.#dir) {
24
- return this.#value;
25
- }
26
- const dir = join(process.cwd(), this.#dir);
27
- if (!existsSync(dir)) {
28
- this.saveValue(this.#initValue);
29
- return this.#value;
22
+ #readConfig() {
23
+ if (!this.#resolvedDir) {
24
+ return null;
30
25
  }
31
26
  try {
32
- const data = readFileSync(dir, 'utf-8');
33
- const d = YAML.parse(data);
34
- this.#value = d;
35
- this.#invalidateMergedCache();
27
+ const data = readFileSync(this.#resolvedDir, 'utf-8');
28
+ return YAML.parse(data);
36
29
  }
37
30
  catch (err) {
38
31
  logger.error({
@@ -40,31 +33,69 @@ class ConfigCore {
40
33
  message: 'Config file parse error',
41
34
  data: err
42
35
  });
36
+ return null;
43
37
  }
44
- if (this.#watcher) {
45
- this.#watcher.close();
46
- this.#watcher = null;
38
+ }
39
+ #applyValue(newValue) {
40
+ if (newValue === null) {
41
+ return;
42
+ }
43
+ this.#value = newValue;
44
+ this.#invalidateMergedCache();
45
+ }
46
+ #notifyListeners() {
47
+ if (this.#debounceTimer) {
48
+ clearTimeout(this.#debounceTimer);
47
49
  }
48
- this.#watcher = watch(dir, () => {
49
- try {
50
- const data = readFileSync(dir, 'utf-8');
51
- const d = YAML.parse(data);
52
- this.#value = d;
53
- this.#invalidateMergedCache();
50
+ this.#debounceTimer = setTimeout(() => {
51
+ this.#debounceTimer = null;
52
+ const val = this.value;
53
+ if (!val) {
54
+ return;
55
+ }
56
+ for (const listener of this.#listeners) {
57
+ try {
58
+ listener(val);
59
+ }
60
+ catch (err) {
61
+ logger.error({
62
+ code: ResultCode.FailInternal,
63
+ message: 'Config listener error',
64
+ data: err
65
+ });
66
+ }
54
67
  }
55
- catch (err) {
56
- logger.error({
57
- code: ResultCode.FailInternal,
58
- message: 'Config file parse error',
59
- data: err
60
- });
68
+ }, this.#debounceDelay);
69
+ }
70
+ #ensureWatcher() {
71
+ if (this.#watcher || !this.#resolvedDir) {
72
+ return;
73
+ }
74
+ if (!existsSync(this.#resolvedDir)) {
75
+ return;
76
+ }
77
+ this.#watcher = watch(this.#resolvedDir, () => {
78
+ const newValue = this.#readConfig();
79
+ if (newValue !== null) {
80
+ this.#applyValue(newValue);
81
+ this.#notifyListeners();
61
82
  }
62
83
  });
63
- return this.#value;
84
+ }
85
+ #init() {
86
+ if (!this.#resolvedDir) {
87
+ return;
88
+ }
89
+ if (!existsSync(this.#resolvedDir)) {
90
+ this.saveValue(this.#initValue);
91
+ return;
92
+ }
93
+ this.#applyValue(this.#readConfig());
94
+ this.#ensureWatcher();
64
95
  }
65
96
  get value() {
66
97
  if (!this.#value) {
67
- this.#update();
98
+ this.#init();
68
99
  }
69
100
  if (this.#mergedValue) {
70
101
  return this.#mergedValue;
@@ -76,15 +107,40 @@ class ConfigCore {
76
107
  return this.#mergedValue;
77
108
  }
78
109
  saveValue(value) {
79
- if (!this.#dir) {
110
+ if (!this.#resolvedDir) {
80
111
  return;
81
112
  }
82
- const dir = join(process.cwd(), this.#dir);
83
- if (!existsSync(dir)) {
84
- mkdirSync(dirname(dir), { recursive: true });
113
+ const dirPath = dirname(this.#resolvedDir);
114
+ if (!existsSync(this.#resolvedDir)) {
115
+ mkdirSync(dirPath, { recursive: true });
85
116
  }
86
117
  const data = YAML.stringify(value);
87
- writeFileSync(dir, data, 'utf-8');
118
+ writeFileSync(this.#resolvedDir, data, 'utf-8');
119
+ this.#applyValue(value);
120
+ this.#ensureWatcher();
121
+ }
122
+ onWatch(listener) {
123
+ this.#listeners.add(listener);
124
+ if (!this.#value) {
125
+ this.#init();
126
+ }
127
+ else {
128
+ this.#ensureWatcher();
129
+ }
130
+ return () => {
131
+ this.#listeners.delete(listener);
132
+ };
133
+ }
134
+ dispose() {
135
+ if (this.#watcher) {
136
+ this.#watcher.close();
137
+ this.#watcher = null;
138
+ }
139
+ if (this.#debounceTimer) {
140
+ clearTimeout(this.#debounceTimer);
141
+ this.#debounceTimer = null;
142
+ }
143
+ this.#listeners.clear();
88
144
  }
89
145
  #package = null;
90
146
  get package() {
@@ -100,8 +156,8 @@ class ConfigCore {
100
156
  });
101
157
  return null;
102
158
  }
103
- const data = readFileSync(dir, 'utf-8');
104
159
  try {
160
+ const data = readFileSync(dir, 'utf-8');
105
161
  this.#package = JSON.parse(data);
106
162
  }
107
163
  catch (err) {
@@ -115,8 +171,10 @@ class ConfigCore {
115
171
  return this.#package;
116
172
  }
117
173
  get argv() {
118
- const argv = {};
119
- return new Proxy(argv, {
174
+ if (this.#argvProxy) {
175
+ return this.#argvProxy;
176
+ }
177
+ this.#argvProxy = new Proxy({}, {
120
178
  get(_target, key) {
121
179
  if (typeof key === 'symbol') {
122
180
  return undefined;
@@ -132,6 +190,7 @@ class ConfigCore {
132
190
  return null;
133
191
  }
134
192
  });
193
+ return this.#argvProxy;
135
194
  }
136
195
  }
137
196
  const getConfig = () => {
@@ -142,6 +201,11 @@ const getConfig = () => {
142
201
  global.__config = new ConfigCore(configDir);
143
202
  return global.__config;
144
203
  };
145
- const getConfigValue = () => getConfig()?.value || {};
204
+ const getConfigValue = () => {
205
+ return (getConfig()?.value || {});
206
+ };
207
+ const onWatchConfigValue = (callback) => {
208
+ return getConfig().onWatch(callback);
209
+ };
146
210
 
147
- export { ConfigCore, getConfig, getConfigValue };
211
+ export { getConfig, getConfigValue, onWatchConfigValue };
package/lib/core/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { ResultCode } from './variable.js';
2
- export { ConfigCore, getConfig, getConfigValue } from './config.js';
2
+ export { getConfig, getConfigValue, onWatchConfigValue } from './config.js';
3
3
  export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './utils.js';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export { ActionsEventEnum } from './types/event/actions.js';
2
2
  export { ResultCode } from './core/variable.js';
3
- export { ConfigCore, getConfig, getConfigValue } from './core/config.js';
3
+ export { getConfig, getConfigValue, onWatchConfigValue } from './core/config.js';
4
4
  export { createEventName, createHash, createResult, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
5
5
  export { cbpClient } from './cbp/connects/client.js';
6
6
  export { cbpPlatform } from './cbp/connects/platform.js';
@@ -27,4 +27,4 @@ export { useObserver, useSubscribe } from './app/hook-use-subscribe.js';
27
27
  export { createDataFormat, createEventValue, format, getMessageIntent, sendToChannel, sendToUser } from './app/message-api.js';
28
28
  export { Format, createEvent } from './app/message-format.js';
29
29
  export { start } from './main.js';
30
- export { Ark, BT, Image, ImageFile, ImageURL, Link, MD, Mention, Text } from './app/message-format-old.js';
30
+ export { Ark, Attachment, Audio, BT, Custom, Image, ImageFile, ImageURL, Link, MD, Markdown, Mention, Text, Video } from './app/message-format-old.js';
@@ -0,0 +1,105 @@
1
+ import { DataText, DataLink, DataImage, DataImageURL, DataImageFile, DataMention, DataButton, ButtonRow, DataButtonGroup, DataMarkDown, DataMarkdownTitle, DataMarkdownSubtitle, DataMarkdownText, DataMarkdownBold, DataMarkdownCode } from '../types/index.js';
2
+ export interface FormatProps {
3
+ name?: string;
4
+ children?: any;
5
+ [key: string]: any;
6
+ }
7
+ export interface TextProps {
8
+ children?: any;
9
+ style?: DataText['options']['style'];
10
+ }
11
+ export interface LinkProps {
12
+ children?: any;
13
+ link: string;
14
+ }
15
+ export interface ImageProps {
16
+ children?: Buffer;
17
+ }
18
+ export interface ImageURLProps {
19
+ children?: string;
20
+ }
21
+ export interface ImageFileProps {
22
+ children?: string;
23
+ }
24
+ export interface MentionProps {
25
+ children?: string;
26
+ belong?: 'user' | 'guild' | 'channel' | 'everyone';
27
+ payload?: any;
28
+ }
29
+ export interface ButtonProps {
30
+ children?: any;
31
+ data?: DataButton['options']['data'];
32
+ command?: string;
33
+ toolTip?: string;
34
+ autoEnter?: boolean;
35
+ showList?: boolean;
36
+ type?: 'command' | 'link' | 'call';
37
+ }
38
+ export interface RowProps {
39
+ children?: any;
40
+ }
41
+ export interface ButtonGroupProps {
42
+ children?: any;
43
+ }
44
+ export interface MarkdownProps {
45
+ children?: any;
46
+ }
47
+ export interface MarkdownTitleProps {
48
+ children?: any;
49
+ }
50
+ export interface MarkdownSubtitleProps {
51
+ children?: any;
52
+ }
53
+ export interface MarkdownTextProps {
54
+ children?: any;
55
+ }
56
+ export interface MarkdownBoldProps {
57
+ children?: any;
58
+ }
59
+ export interface MarkdownCodeProps {
60
+ children?: any;
61
+ language?: string;
62
+ }
63
+ export interface CustomProps {
64
+ name: string;
65
+ children?: any;
66
+ [key: string]: any;
67
+ }
68
+ declare function FormatComponent(props: FormatProps): any;
69
+ declare namespace FormatComponent {
70
+ var Text: typeof FormatText;
71
+ var Link: typeof FormatLink;
72
+ var Image: typeof FormatImage;
73
+ var ImageURL: typeof FormatImageURL;
74
+ var ImageFile: typeof FormatImageFile;
75
+ var Mention: typeof FormatMention;
76
+ var Button: typeof FormatButton;
77
+ var Row: typeof FormatRow;
78
+ var ButtonGroup: typeof FormatButtonGroup;
79
+ var Markdown: typeof FormatMarkdown;
80
+ var Custom: typeof FormatCustomComponent;
81
+ }
82
+ declare function FormatText(props: TextProps): DataText;
83
+ declare function FormatLink(props: LinkProps): DataLink;
84
+ declare function FormatImage(props: ImageProps): DataImage;
85
+ declare function FormatImageURL(props: ImageURLProps): DataImageURL;
86
+ declare function FormatImageFile(props: ImageFileProps): DataImageFile;
87
+ declare function FormatMention(props: MentionProps): DataMention;
88
+ declare function FormatButton(props: ButtonProps): DataButton;
89
+ declare function FormatRow(props: RowProps): ButtonRow;
90
+ declare function FormatButtonGroup(props: ButtonGroupProps): DataButtonGroup;
91
+ declare function FormatMarkdownTitle(props: MarkdownTitleProps): DataMarkdownTitle;
92
+ declare function FormatMarkdownSubtitle(props: MarkdownSubtitleProps): DataMarkdownSubtitle;
93
+ declare function FormatMarkdownText(props: MarkdownTextProps): DataMarkdownText;
94
+ declare function FormatMarkdownBold(props: MarkdownBoldProps): DataMarkdownBold;
95
+ declare function FormatMarkdownCode(props: MarkdownCodeProps): DataMarkdownCode;
96
+ declare function FormatMarkdown(props: MarkdownProps): DataMarkDown;
97
+ declare namespace FormatMarkdown {
98
+ var Title: typeof FormatMarkdownTitle;
99
+ var Subtitle: typeof FormatMarkdownSubtitle;
100
+ var Text: typeof FormatMarkdownText;
101
+ var Bold: typeof FormatMarkdownBold;
102
+ var Code: typeof FormatMarkdownCode;
103
+ }
104
+ declare function FormatCustomComponent(props: CustomProps): any;
105
+ export { FormatComponent as Component, FormatCustomComponent as Custom };
@@ -0,0 +1,211 @@
1
+ function childrenToString(children) {
2
+ if (children === null || children === undefined) {
3
+ return '';
4
+ }
5
+ if (typeof children === 'string') {
6
+ return children;
7
+ }
8
+ if (typeof children === 'number' || typeof children === 'boolean') {
9
+ return String(children);
10
+ }
11
+ if (Array.isArray(children)) {
12
+ return children.map(childrenToString).join('');
13
+ }
14
+ return String(children);
15
+ }
16
+ function flattenChildren(children) {
17
+ if (children === null || children === undefined) {
18
+ return [];
19
+ }
20
+ if (Array.isArray(children)) {
21
+ const result = [];
22
+ for (const child of children) {
23
+ if (Array.isArray(child)) {
24
+ result.push(...flattenChildren(child));
25
+ }
26
+ else if (child !== null && child !== undefined && typeof child === 'object' && 'type' in child) {
27
+ result.push(child);
28
+ }
29
+ }
30
+ return result;
31
+ }
32
+ if (typeof children === 'object' && children !== null && children !== undefined && 'type' in children) {
33
+ return [children];
34
+ }
35
+ return [];
36
+ }
37
+ function collectChildren(children, typeCheck) {
38
+ const flat = flattenChildren(children);
39
+ return flat.filter(c => c.type === typeCheck);
40
+ }
41
+ function extractOptions(props, excludeKeys = []) {
42
+ const exclude = new Set(['children', ...excludeKeys]);
43
+ const options = {};
44
+ let hasKeys = false;
45
+ for (const key of Object.keys(props)) {
46
+ if (!exclude.has(key)) {
47
+ options[key] = props[key];
48
+ hasKeys = true;
49
+ }
50
+ }
51
+ return hasKeys ? options : undefined;
52
+ }
53
+ function FormatComponent(props) {
54
+ if (props.name !== undefined) {
55
+ const { name, children, ...rest } = props;
56
+ const options = Object.keys(rest).length > 0 ? rest : undefined;
57
+ return {
58
+ type: name,
59
+ value: children !== null && children !== undefined ? childrenToString(children) : undefined,
60
+ options
61
+ };
62
+ }
63
+ return flattenChildren(props.children);
64
+ }
65
+ function FormatText(props) {
66
+ return {
67
+ type: 'Text',
68
+ value: childrenToString(props.children),
69
+ options: extractOptions(props)
70
+ };
71
+ }
72
+ function FormatLink(props) {
73
+ return {
74
+ type: 'Link',
75
+ value: childrenToString(props.children),
76
+ options: extractOptions(props)
77
+ };
78
+ }
79
+ function FormatImage(props) {
80
+ const buf = props.children;
81
+ return {
82
+ type: 'Image',
83
+ value: buf instanceof Buffer ? buf.toString('base64') : ''
84
+ };
85
+ }
86
+ function FormatImageURL(props) {
87
+ return {
88
+ type: 'ImageURL',
89
+ value: childrenToString(props.children)
90
+ };
91
+ }
92
+ function FormatImageFile(props) {
93
+ return {
94
+ type: 'ImageFile',
95
+ value: childrenToString(props.children)
96
+ };
97
+ }
98
+ function FormatMention(props) {
99
+ return {
100
+ type: 'Mention',
101
+ value: props.children !== null && props.children !== undefined ? childrenToString(props.children) : undefined,
102
+ options: extractOptions(props)
103
+ };
104
+ }
105
+ function FormatButton(props) {
106
+ const options = {};
107
+ if (props.command !== undefined) {
108
+ options.data = props.command;
109
+ options.type = 'command';
110
+ }
111
+ else {
112
+ if (props.data !== undefined) {
113
+ options.data = props.data;
114
+ }
115
+ if (props.type !== undefined) {
116
+ options.type = props.type;
117
+ }
118
+ }
119
+ if (props.toolTip !== undefined) {
120
+ options.toolTip = props.toolTip;
121
+ }
122
+ if (props.autoEnter !== undefined) {
123
+ options.autoEnter = props.autoEnter;
124
+ }
125
+ if (props.showList !== undefined) {
126
+ options.showList = props.showList;
127
+ }
128
+ return {
129
+ type: 'Button',
130
+ value: childrenToString(props.children),
131
+ options: Object.keys(options).length > 0 ? options : undefined
132
+ };
133
+ }
134
+ function FormatRow(props) {
135
+ return {
136
+ type: 'BT.row',
137
+ value: collectChildren(props.children, 'Button')
138
+ };
139
+ }
140
+ function FormatButtonGroup(props) {
141
+ return {
142
+ type: 'BT.group',
143
+ value: collectChildren(props.children, 'BT.row')
144
+ };
145
+ }
146
+ function FormatMarkdownTitle(props) {
147
+ return {
148
+ type: 'MD.title',
149
+ value: childrenToString(props.children)
150
+ };
151
+ }
152
+ function FormatMarkdownSubtitle(props) {
153
+ return {
154
+ type: 'MD.subtitle',
155
+ value: childrenToString(props.children)
156
+ };
157
+ }
158
+ function FormatMarkdownText(props) {
159
+ return {
160
+ type: 'MD.text',
161
+ value: childrenToString(props.children)
162
+ };
163
+ }
164
+ function FormatMarkdownBold(props) {
165
+ return {
166
+ type: 'MD.bold',
167
+ value: childrenToString(props.children)
168
+ };
169
+ }
170
+ function FormatMarkdownCode(props) {
171
+ return {
172
+ type: 'MD.code',
173
+ value: childrenToString(props.children),
174
+ options: extractOptions(props)
175
+ };
176
+ }
177
+ function FormatMarkdown(props) {
178
+ const flat = flattenChildren(props.children);
179
+ const items = flat.filter(c => typeof c.type === 'string' && c.type.startsWith('MD.'));
180
+ return {
181
+ type: 'Markdown',
182
+ value: items
183
+ };
184
+ }
185
+ FormatMarkdown.Title = FormatMarkdownTitle;
186
+ FormatMarkdown.Subtitle = FormatMarkdownSubtitle;
187
+ FormatMarkdown.Text = FormatMarkdownText;
188
+ FormatMarkdown.Bold = FormatMarkdownBold;
189
+ FormatMarkdown.Code = FormatMarkdownCode;
190
+ function FormatCustomComponent(props) {
191
+ const { name, children, ...rest } = props;
192
+ const options = Object.keys(rest).length > 0 ? rest : undefined;
193
+ return {
194
+ type: name,
195
+ value: children !== null && children !== undefined ? childrenToString(children) : undefined,
196
+ options
197
+ };
198
+ }
199
+ FormatComponent.Text = FormatText;
200
+ FormatComponent.Link = FormatLink;
201
+ FormatComponent.Image = FormatImage;
202
+ FormatComponent.ImageURL = FormatImageURL;
203
+ FormatComponent.ImageFile = FormatImageFile;
204
+ FormatComponent.Mention = FormatMention;
205
+ FormatComponent.Button = FormatButton;
206
+ FormatComponent.Row = FormatRow;
207
+ FormatComponent.ButtonGroup = FormatButtonGroup;
208
+ FormatComponent.Markdown = FormatMarkdown;
209
+ FormatComponent.Custom = FormatCustomComponent;
210
+
211
+ export { FormatComponent as Component, FormatCustomComponent as Custom };
@@ -0,0 +1,2 @@
1
+ export { jsx, jsxs, Fragment } from './jsx-runtime.js';
2
+ export type { JSX } from './jsx-runtime.js';
@@ -0,0 +1 @@
1
+ export { Fragment, jsx, jsxs } from './jsx-runtime.js';
@@ -0,0 +1,18 @@
1
+ type JsxChild = any;
2
+ type JsxProps = Record<string, any>;
3
+ type JsxComponent = (props: JsxProps) => any;
4
+ export declare function jsx(type: string | JsxComponent, props: JsxProps, _key?: string): any;
5
+ export declare function jsxs(type: string | JsxComponent, props: JsxProps, _key?: string): any;
6
+ export declare function Fragment(props: {
7
+ children?: JsxChild;
8
+ }): any[];
9
+ export declare namespace JSX {
10
+ type Element = any;
11
+ interface ElementChildrenAttribute {
12
+ children: object;
13
+ }
14
+ interface IntrinsicElements {
15
+ [elemName: string]: any;
16
+ }
17
+ }
18
+ export {};
@@ -0,0 +1,24 @@
1
+ function jsx(type, props, _key) {
2
+ if (typeof type === 'function') {
3
+ return type(props);
4
+ }
5
+ return { type, props };
6
+ }
7
+ function jsxs(type, props, _key) {
8
+ if (typeof type === 'function') {
9
+ return type(props);
10
+ }
11
+ return { type, props };
12
+ }
13
+ function Fragment(props) {
14
+ const { children } = props;
15
+ if (children === null || children === undefined) {
16
+ return [];
17
+ }
18
+ if (Array.isArray(children)) {
19
+ return children;
20
+ }
21
+ return [children];
22
+ }
23
+
24
+ export { Fragment, jsx, jsxs };
@@ -0,0 +1,7 @@
1
+ export type DataAttachment = {
2
+ type: 'Attachment';
3
+ value: string;
4
+ options?: {
5
+ filename?: string;
6
+ };
7
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ export type DataAudio = {
2
+ type: 'Audio';
3
+ value: string;
4
+ };
@@ -0,0 +1 @@
1
+
@@ -1,10 +1,14 @@
1
1
  import { DataButtonGroup, DataButtonTemplate } from './button';
2
2
  import { DataArkBigCard, DataArkCard, DataArkList } from './ark';
3
- import { DataMarkDown, DataMarkdownTemplate } from './markdown';
3
+ import { DataMarkDown, DataMarkdownTemplate, DataCustom } from './markdown';
4
4
  import { DataImage, DataImageFile, DataImageURL } from './image';
5
5
  import { DataText } from './text';
6
6
  import { DataMention } from './mention';
7
7
  import { DataLink } from './link';
8
+ import { DataAttachment } from './attachment';
9
+ import { DataAudio } from './audio';
10
+ import { DataVideo } from './video';
11
+ import { DataMarkdownOriginal } from './markdown-raw';
8
12
  export * from './text';
9
13
  export * from './link';
10
14
  export * from './mention';
@@ -12,5 +16,9 @@ export * from './image';
12
16
  export * from './button';
13
17
  export * from './ark';
14
18
  export * from './markdown';
15
- export type DataEnums = DataText | DataLink | DataImage | DataImageURL | DataImageFile | DataMention | DataButtonGroup | DataButtonTemplate | DataArkList | DataArkCard | DataArkBigCard | DataMarkDown | DataMarkdownTemplate;
19
+ export * from './markdown-raw';
20
+ export * from './attachment';
21
+ export * from './audio';
22
+ export * from './video';
23
+ export type DataEnums = DataText | DataLink | DataImage | DataImageURL | DataImageFile | DataMention | DataButtonGroup | DataButtonTemplate | DataArkList | DataArkCard | DataArkBigCard | DataMarkDown | DataMarkdownTemplate | DataMarkdownOriginal | DataAttachment | DataAudio | DataVideo | DataCustom;
16
24
  export type MessageDataFormat = DataEnums[];
@@ -0,0 +1,4 @@
1
+ export type DataMarkdownOriginal = {
2
+ type: 'MarkdownOriginal';
3
+ value: string;
4
+ };
@@ -0,0 +1 @@
1
+
@@ -79,7 +79,14 @@ export type DataMarkdownCode = {
79
79
  language?: string;
80
80
  };
81
81
  };
82
- type DataMarkDownBalue = DataMarkdownText | DataMarkdownTitle | DataMarkdownSubtitle | DataMarkdownBold | DataMarkdownItalic | DataMarkdownItalicStar | DataMarkdownStrikethrough | DataMarkdownLink | DataMarkdownImage | DataMarkdownList | DataMarkdownBlockquote | DataMarkdownDivider | DataMarkdownNewline | DataMarkdownCode;
82
+ export type DataCustom = {
83
+ type: string;
84
+ value: string;
85
+ options?: {
86
+ [key: string]: any;
87
+ };
88
+ };
89
+ type DataMarkDownBalue = DataMarkdownText | DataMarkdownTitle | DataMarkdownSubtitle | DataMarkdownBold | DataMarkdownItalic | DataMarkdownItalicStar | DataMarkdownStrikethrough | DataMarkdownLink | DataMarkdownImage | DataMarkdownList | DataMarkdownBlockquote | DataMarkdownDivider | DataMarkdownNewline | DataMarkdownCode | DataCustom;
83
90
  export type DataMarkDown = {
84
91
  type: 'Markdown';
85
92
  value: DataMarkDownBalue[];
@@ -0,0 +1,4 @@
1
+ export type DataVideo = {
2
+ type: 'Video';
3
+ value: string;
4
+ };
@@ -0,0 +1 @@
1
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.22",
3
+ "version": "2.1.24",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",