UNPKG

@kotori-bot/core

Version:
98 lines (97 loc) 3.49 kB
/** * @Package @kotori-bot/core * @Version 1.7.0 * @Author Arimura Sena <me@hotaru.icu> * @Copyright 2024-2025 Hotaru. All rights reserved. * @License BAN-ZHINESE-USING * @Link https://github.com/kotorijs/kotori * @Date 17:26:09 */ "use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var jsx_exports = {}; __export(jsx_exports, { hRes: () => hRes, hTs: () => hTs }); module.exports = __toCommonJS(jsx_exports); var import_factory = require("../utils/factory"); var import_messages = require("../components/messages"); const Fragment = Symbol("Fragment"); function hTs(type, props, ...children) { if (type === Fragment) return hTs("list", props, ...children); if (typeof type === "function") return type(Object.assign({}, props, { children })); const flattenedChildren = children.flat(Number.MAX_SAFE_INTEGER).filter((child) => child != null && child !== false && child !== true); switch (type) { case "text": return import_messages.Messages.text(flattenedChildren.map((child) => String(child)).join("")); case "mention": return import_messages.Messages.mention(props.userId); case "mentionAll": return import_messages.Messages.mentionAll(); case "reply": return import_messages.Messages.reply(props.messageId); case "image": return import_messages.Messages.image(props.src); case "audio": return import_messages.Messages.audio(props.src); case "video": return import_messages.Messages.video(props.src); case "file": return import_messages.Messages.file(props.src); case "location": const locationProps = props; return import_messages.Messages.location( locationProps.latitude, locationProps.longitude, locationProps.title, locationProps.content ); case "seg": return (0, import_messages.Messages)( ...flattenedChildren.map( (child) => child instanceof import_messages.MessageSingle || child instanceof import_messages.MessageList ? child : child && typeof child === "object" && "type" in child ? hTs(child.type, child.props, child.children) : String(child) ) ); case "br": return hTs("text", {}, "\n"); case "format": return (0, import_factory.formatFactory)()( props.template, flattenedChildren ); default: throw new Error(`Unknown element type: ${type}`); } } function hRes(type, props) { return hTs( type, props, ..."children" in props ? Array.isArray(props.children) ? props.children : [props.children] : [] ); } ; globalThis.kotoriHTs = hTs; globalThis.kotoriHRes = hRes; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { hRes, hTs });