@luckylillia-dev/luckylillia 0.0.0-stage → 9.0.1
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/chunks/preload-helper-D5R8FHQt.js +342 -0
- package/chunks/preload-helper-D5R8FHQt.js.map +1 -0
- package/default_config.json +83 -0
- package/llbot-core.js +35013 -0
- package/llbot-core.js.map +1 -0
- package/llbot.js +138 -0
- package/llbot.js.map +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/commands.d.ts +86 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/commands.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/config.d.ts +14 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/config.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/ffmpeg.d.ts +41 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/ffmpeg.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/http.d.ts +88 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/http.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/index.d.ts +17 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/index.js +6 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/internal.d.ts +430 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/internal.js +7 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/manifest.d.ts +68 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/manifest.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/server.d.ts +23 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/server.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/storage.d.ts +21 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/storage.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/testing.d.ts +71 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/testing.js +1123 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/universal.d.ts +299 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/universal.js +1 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/webui.d.ts +762 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/lib/webui.js +9 -0
- package/node_modules/@luckylillia-dev/plugin-sdk/package.json +63 -0
- package/node_modules/@satorijs/element/jsx-dev-runtime.d.ts +3 -0
- package/node_modules/@satorijs/element/jsx-runtime.d.ts +3 -0
- package/node_modules/@satorijs/element/lib/index.cjs +447 -0
- package/node_modules/@satorijs/element/lib/index.d.ts +116 -0
- package/node_modules/@satorijs/element/lib/index.mjs +455 -0
- package/node_modules/@satorijs/element/package.json +60 -0
- package/node_modules/@satorijs/element/src/index.ts +559 -0
- package/node_modules/@satorijs/protocol/lib/index.cjs +187 -0
- package/node_modules/@satorijs/protocol/lib/index.d.ts +328 -0
- package/node_modules/@satorijs/protocol/lib/index.mjs +148 -0
- package/node_modules/@satorijs/protocol/package.json +44 -0
- package/node_modules/@satorijs/protocol/src/index.ts +513 -0
- package/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/node_modules/@standard-schema/spec/README.md +198 -0
- package/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/node_modules/@standard-schema/spec/dist/index.d.cts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.d.ts +119 -0
- package/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/node_modules/@standard-schema/spec/package.json +52 -0
- package/node_modules/cordis/README.md +10 -0
- package/node_modules/cordis/bin.js +16 -0
- package/node_modules/cordis/lib/context.d.ts +32 -0
- package/node_modules/cordis/lib/events.d.ts +62 -0
- package/node_modules/cordis/lib/fiber.d.ts +85 -0
- package/node_modules/cordis/lib/index.d.ts +7 -0
- package/node_modules/cordis/lib/index.js +1577 -0
- package/node_modules/cordis/lib/logger.d.ts +74 -0
- package/node_modules/cordis/lib/reflect.d.ts +54 -0
- package/node_modules/cordis/lib/registry.d.ts +78 -0
- package/node_modules/cordis/lib/service.d.ts +19 -0
- package/node_modules/cordis/lib/utils.d.ts +50 -0
- package/node_modules/cordis/package.json +49 -0
- package/node_modules/cosmokit/LICENSE +21 -0
- package/node_modules/cosmokit/README.md +24 -0
- package/node_modules/cosmokit/lib/index.cjs +419 -0
- package/node_modules/cosmokit/lib/index.cjs.map +6 -0
- package/node_modules/cosmokit/lib/index.d.ts +142 -0
- package/node_modules/cosmokit/lib/index.mjs +357 -0
- package/node_modules/cosmokit/lib/index.mjs.map +6 -0
- package/node_modules/cosmokit/package.json +57 -0
- package/node_modules/cosmokit/src/array.ts +35 -0
- package/node_modules/cosmokit/src/index.ts +5 -0
- package/node_modules/cosmokit/src/misc.ts +57 -0
- package/node_modules/cosmokit/src/string.ts +101 -0
- package/node_modules/cosmokit/src/time.ts +91 -0
- package/node_modules/cosmokit/src/types.ts +131 -0
- package/node_modules/schemastery/README.md +342 -0
- package/node_modules/schemastery/lib/index.cjs +648 -0
- package/node_modules/schemastery/lib/index.cjs.map +6 -0
- package/node_modules/schemastery/lib/index.d.ts +138 -0
- package/node_modules/schemastery/lib/index.mjs +656 -0
- package/node_modules/schemastery/lib/index.mjs.map +6 -0
- package/node_modules/schemastery/package.json +32 -0
- package/node_modules/schemastery/src/index.ts +841 -0
- package/node_modules/undici/LICENSE +21 -0
- package/node_modules/undici/README.md +741 -0
- package/node_modules/undici/docs/docs/api/Agent.md +84 -0
- package/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
- package/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
- package/node_modules/undici/docs/docs/api/CacheStore.md +164 -0
- package/node_modules/undici/docs/docs/api/Client.md +290 -0
- package/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
- package/node_modules/undici/docs/docs/api/Connector.md +115 -0
- package/node_modules/undici/docs/docs/api/ContentType.md +57 -0
- package/node_modules/undici/docs/docs/api/Cookies.md +128 -0
- package/node_modules/undici/docs/docs/api/Debug.md +62 -0
- package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +317 -0
- package/node_modules/undici/docs/docs/api/Dispatcher.md +1393 -0
- package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
- package/node_modules/undici/docs/docs/api/Errors.md +49 -0
- package/node_modules/undici/docs/docs/api/EventSource.md +45 -0
- package/node_modules/undici/docs/docs/api/Fetch.md +60 -0
- package/node_modules/undici/docs/docs/api/GlobalInstallation.md +139 -0
- package/node_modules/undici/docs/docs/api/H2CClient.md +263 -0
- package/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
- package/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
- package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/node_modules/undici/docs/docs/api/MockClient.md +81 -0
- package/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
- package/node_modules/undici/docs/docs/api/MockPool.md +555 -0
- package/node_modules/undici/docs/docs/api/Pool.md +84 -0
- package/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
- package/node_modules/undici/docs/docs/api/ProxyAgent.md +229 -0
- package/node_modules/undici/docs/docs/api/RedirectHandler.md +93 -0
- package/node_modules/undici/docs/docs/api/RetryAgent.md +50 -0
- package/node_modules/undici/docs/docs/api/RetryHandler.md +118 -0
- package/node_modules/undici/docs/docs/api/RoundRobinPool.md +145 -0
- package/node_modules/undici/docs/docs/api/SnapshotAgent.md +616 -0
- package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +275 -0
- package/node_modules/undici/docs/docs/api/Util.md +25 -0
- package/node_modules/undici/docs/docs/api/WebSocket.md +141 -0
- package/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
- package/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
- package/node_modules/undici/docs/docs/best-practices/crawling.md +58 -0
- package/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
- package/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
- package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +224 -0
- package/node_modules/undici/docs/docs/best-practices/writing-tests.md +63 -0
- package/node_modules/undici/index-fetch.js +65 -0
- package/node_modules/undici/index.d.ts +3 -0
- package/node_modules/undici/index.js +234 -0
- package/node_modules/undici/lib/api/abort-signal.js +59 -0
- package/node_modules/undici/lib/api/api-connect.js +110 -0
- package/node_modules/undici/lib/api/api-pipeline.js +252 -0
- package/node_modules/undici/lib/api/api-request.js +214 -0
- package/node_modules/undici/lib/api/api-stream.js +209 -0
- package/node_modules/undici/lib/api/api-upgrade.js +111 -0
- package/node_modules/undici/lib/api/index.js +7 -0
- package/node_modules/undici/lib/api/readable.js +580 -0
- package/node_modules/undici/lib/cache/memory-cache-store.js +279 -0
- package/node_modules/undici/lib/cache/sqlite-cache-store.js +467 -0
- package/node_modules/undici/lib/core/connect.js +159 -0
- package/node_modules/undici/lib/core/constants.js +143 -0
- package/node_modules/undici/lib/core/diagnostics.js +227 -0
- package/node_modules/undici/lib/core/errors.js +477 -0
- package/node_modules/undici/lib/core/request.js +485 -0
- package/node_modules/undici/lib/core/socks5-client.js +422 -0
- package/node_modules/undici/lib/core/socks5-utils.js +212 -0
- package/node_modules/undici/lib/core/symbols.js +76 -0
- package/node_modules/undici/lib/core/tree.js +160 -0
- package/node_modules/undici/lib/core/util.js +992 -0
- package/node_modules/undici/lib/dispatcher/agent.js +162 -0
- package/node_modules/undici/lib/dispatcher/balanced-pool.js +221 -0
- package/node_modules/undici/lib/dispatcher/client-h1.js +1744 -0
- package/node_modules/undici/lib/dispatcher/client-h2.js +1056 -0
- package/node_modules/undici/lib/dispatcher/client.js +669 -0
- package/node_modules/undici/lib/dispatcher/dispatcher-base.js +196 -0
- package/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
- package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +146 -0
- package/node_modules/undici/lib/dispatcher/fixed-queue.js +135 -0
- package/node_modules/undici/lib/dispatcher/h2c-client.js +51 -0
- package/node_modules/undici/lib/dispatcher/pool-base.js +214 -0
- package/node_modules/undici/lib/dispatcher/pool.js +118 -0
- package/node_modules/undici/lib/dispatcher/proxy-agent.js +319 -0
- package/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
- package/node_modules/undici/lib/dispatcher/round-robin-pool.js +137 -0
- package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +260 -0
- package/node_modules/undici/lib/encoding/index.js +33 -0
- package/node_modules/undici/lib/global.js +59 -0
- package/node_modules/undici/lib/handler/cache-handler.js +824 -0
- package/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
- package/node_modules/undici/lib/handler/decorator-handler.js +67 -0
- package/node_modules/undici/lib/handler/deduplication-handler.js +504 -0
- package/node_modules/undici/lib/handler/redirect-handler.js +245 -0
- package/node_modules/undici/lib/handler/retry-handler.js +504 -0
- package/node_modules/undici/lib/handler/unwrap-handler.js +106 -0
- package/node_modules/undici/lib/handler/wrap-handler.js +105 -0
- package/node_modules/undici/lib/interceptor/cache.js +621 -0
- package/node_modules/undici/lib/interceptor/decompress.js +561 -0
- package/node_modules/undici/lib/interceptor/deduplicate.js +117 -0
- package/node_modules/undici/lib/interceptor/dns.js +571 -0
- package/node_modules/undici/lib/interceptor/dump.js +99 -0
- package/node_modules/undici/lib/interceptor/redirect.js +21 -0
- package/node_modules/undici/lib/interceptor/response-error.js +95 -0
- package/node_modules/undici/lib/interceptor/retry.js +19 -0
- package/node_modules/undici/lib/llhttp/constants.d.ts +195 -0
- package/node_modules/undici/lib/llhttp/constants.js +531 -0
- package/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
- package/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
- package/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
- package/node_modules/undici/lib/llhttp/utils.js +12 -0
- package/node_modules/undici/lib/mock/mock-agent.js +232 -0
- package/node_modules/undici/lib/mock/mock-call-history.js +248 -0
- package/node_modules/undici/lib/mock/mock-client.js +68 -0
- package/node_modules/undici/lib/mock/mock-errors.js +29 -0
- package/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
- package/node_modules/undici/lib/mock/mock-pool.js +68 -0
- package/node_modules/undici/lib/mock/mock-symbols.js +32 -0
- package/node_modules/undici/lib/mock/mock-utils.js +486 -0
- package/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
- package/node_modules/undici/lib/mock/snapshot-agent.js +353 -0
- package/node_modules/undici/lib/mock/snapshot-recorder.js +588 -0
- package/node_modules/undici/lib/mock/snapshot-utils.js +158 -0
- package/node_modules/undici/lib/util/cache.js +676 -0
- package/node_modules/undici/lib/util/date.js +670 -0
- package/node_modules/undici/lib/util/promise.js +28 -0
- package/node_modules/undici/lib/util/runtime-features.js +124 -0
- package/node_modules/undici/lib/util/stats.js +32 -0
- package/node_modules/undici/lib/util/timers.js +425 -0
- package/node_modules/undici/lib/web/cache/cache.js +864 -0
- package/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
- package/node_modules/undici/lib/web/cache/util.js +45 -0
- package/node_modules/undici/lib/web/cookies/constants.js +12 -0
- package/node_modules/undici/lib/web/cookies/index.js +201 -0
- package/node_modules/undici/lib/web/cookies/parse.js +315 -0
- package/node_modules/undici/lib/web/cookies/util.js +371 -0
- package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +575 -0
- package/node_modules/undici/lib/web/eventsource/eventsource.js +504 -0
- package/node_modules/undici/lib/web/eventsource/util.js +29 -0
- package/node_modules/undici/lib/web/fetch/LICENSE +21 -0
- package/node_modules/undici/lib/web/fetch/body.js +509 -0
- package/node_modules/undici/lib/web/fetch/constants.js +131 -0
- package/node_modules/undici/lib/web/fetch/data-url.js +596 -0
- package/node_modules/undici/lib/web/fetch/formdata-parser.js +586 -0
- package/node_modules/undici/lib/web/fetch/formdata.js +259 -0
- package/node_modules/undici/lib/web/fetch/global.js +40 -0
- package/node_modules/undici/lib/web/fetch/headers.js +719 -0
- package/node_modules/undici/lib/web/fetch/index.js +2413 -0
- package/node_modules/undici/lib/web/fetch/request.js +1115 -0
- package/node_modules/undici/lib/web/fetch/response.js +641 -0
- package/node_modules/undici/lib/web/fetch/util.js +1522 -0
- package/node_modules/undici/lib/web/infra/index.js +243 -0
- package/node_modules/undici/lib/web/subresource-integrity/Readme.md +9 -0
- package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +307 -0
- package/node_modules/undici/lib/web/webidl/index.js +1006 -0
- package/node_modules/undici/lib/web/websocket/connection.js +339 -0
- package/node_modules/undici/lib/web/websocket/constants.js +126 -0
- package/node_modules/undici/lib/web/websocket/events.js +331 -0
- package/node_modules/undici/lib/web/websocket/frame.js +133 -0
- package/node_modules/undici/lib/web/websocket/permessage-deflate.js +105 -0
- package/node_modules/undici/lib/web/websocket/receiver.js +520 -0
- package/node_modules/undici/lib/web/websocket/sender.js +109 -0
- package/node_modules/undici/lib/web/websocket/stream/websocketerror.js +104 -0
- package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +496 -0
- package/node_modules/undici/lib/web/websocket/util.js +347 -0
- package/node_modules/undici/lib/web/websocket/websocket.js +758 -0
- package/node_modules/undici/package.json +152 -0
- package/node_modules/undici/scripts/strip-comments.js +10 -0
- package/node_modules/undici/types/README.md +6 -0
- package/node_modules/undici/types/agent.d.ts +32 -0
- package/node_modules/undici/types/api.d.ts +43 -0
- package/node_modules/undici/types/balanced-pool.d.ts +30 -0
- package/node_modules/undici/types/cache-interceptor.d.ts +179 -0
- package/node_modules/undici/types/cache.d.ts +36 -0
- package/node_modules/undici/types/client-stats.d.ts +15 -0
- package/node_modules/undici/types/client.d.ts +153 -0
- package/node_modules/undici/types/connector.d.ts +36 -0
- package/node_modules/undici/types/content-type.d.ts +21 -0
- package/node_modules/undici/types/cookies.d.ts +30 -0
- package/node_modules/undici/types/diagnostics-channel.d.ts +74 -0
- package/node_modules/undici/types/dispatcher.d.ts +275 -0
- package/node_modules/undici/types/env-http-proxy-agent.d.ts +22 -0
- package/node_modules/undici/types/errors.d.ts +177 -0
- package/node_modules/undici/types/eventsource.d.ts +66 -0
- package/node_modules/undici/types/fetch.d.ts +231 -0
- package/node_modules/undici/types/formdata.d.ts +114 -0
- package/node_modules/undici/types/global-dispatcher.d.ts +9 -0
- package/node_modules/undici/types/global-origin.d.ts +7 -0
- package/node_modules/undici/types/h2c-client.d.ts +73 -0
- package/node_modules/undici/types/handlers.d.ts +14 -0
- package/node_modules/undici/types/header.d.ts +160 -0
- package/node_modules/undici/types/index.d.ts +91 -0
- package/node_modules/undici/types/interceptors.d.ts +82 -0
- package/node_modules/undici/types/mock-agent.d.ts +68 -0
- package/node_modules/undici/types/mock-call-history.d.ts +111 -0
- package/node_modules/undici/types/mock-client.d.ts +27 -0
- package/node_modules/undici/types/mock-errors.d.ts +12 -0
- package/node_modules/undici/types/mock-interceptor.d.ts +94 -0
- package/node_modules/undici/types/mock-pool.d.ts +27 -0
- package/node_modules/undici/types/patch.d.ts +29 -0
- package/node_modules/undici/types/pool-stats.d.ts +19 -0
- package/node_modules/undici/types/pool.d.ts +41 -0
- package/node_modules/undici/types/proxy-agent.d.ts +29 -0
- package/node_modules/undici/types/readable.d.ts +68 -0
- package/node_modules/undici/types/retry-agent.d.ts +8 -0
- package/node_modules/undici/types/retry-handler.d.ts +125 -0
- package/node_modules/undici/types/round-robin-pool.d.ts +41 -0
- package/node_modules/undici/types/snapshot-agent.d.ts +109 -0
- package/node_modules/undici/types/socks5-proxy-agent.d.ts +25 -0
- package/node_modules/undici/types/util.d.ts +18 -0
- package/node_modules/undici/types/utility.d.ts +7 -0
- package/node_modules/undici/types/webidl.d.ts +347 -0
- package/node_modules/undici/types/websocket.d.ts +188 -0
- package/node_modules/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +22 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +19 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +530 -0
- package/node_modules/ws/lib/receiver.js +743 -0
- package/node_modules/ws/lib/sender.js +607 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +562 -0
- package/node_modules/ws/lib/websocket.js +1407 -0
- package/node_modules/ws/package.json +74 -0
- package/node_modules/ws/wrapper.mjs +21 -0
- package/package.json +17 -4
- package/webui/assets/group-bot-profile-CYK81678.jpg +0 -0
- package/webui/assets/group-bot-settings-BBQBbfgh.jpg +0 -0
- package/webui/assets/index-CuH0UYYo.js +28 -0
- package/webui/assets/index-DjbPiYmB.css +2 -0
- package/webui/favicon.ico +0 -0
- package/webui/index.html +26 -0
- package/webui/logo-128.webp +0 -0
- package/webui/logo-192.webp +0 -0
- package/webui/logo-256.webp +0 -0
- package/webui/logo-64.webp +0 -0
- package/webui/logo.jpg +0 -0
- package/webui/plugin-shared/plugin-sdk-webui.js +3 -0
- package/webui/plugin-shared/react-dom.js +3 -0
- package/webui/plugin-shared/react-jsx-runtime.js +3 -0
- package/webui/plugin-shared/react.js +3 -0
- package//344/275/277/347/224/250/350/257/264/346/230/216.txt +6 -0
- package//346/233/264/346/226/260/346/227/245/345/277/227.txt +1091 -0
- package/README.md +0 -3
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
import { Awaitable, Binary, camelize, defineProperty, Dict, hyphenate, is, isNonNullable, isNullable, makeArray } from 'cosmokit'
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
namespace JSX {
|
|
5
|
+
interface IntrinsicElements {
|
|
6
|
+
[key: string]: any
|
|
7
|
+
message: {
|
|
8
|
+
id?: string
|
|
9
|
+
forward?: boolean
|
|
10
|
+
children?: any
|
|
11
|
+
}
|
|
12
|
+
quote: {
|
|
13
|
+
id?: string
|
|
14
|
+
name?: string
|
|
15
|
+
avatar?: string
|
|
16
|
+
children?: any
|
|
17
|
+
}
|
|
18
|
+
at: {
|
|
19
|
+
id?: string
|
|
20
|
+
name?: string
|
|
21
|
+
avatar?: string
|
|
22
|
+
role?: string
|
|
23
|
+
type?: string
|
|
24
|
+
}
|
|
25
|
+
sharp: {
|
|
26
|
+
id?: string
|
|
27
|
+
name?: string
|
|
28
|
+
avatar?: string
|
|
29
|
+
}
|
|
30
|
+
emoji: {
|
|
31
|
+
id?: string
|
|
32
|
+
name?: string
|
|
33
|
+
}
|
|
34
|
+
img: ResourceElement
|
|
35
|
+
audio: ResourceElement
|
|
36
|
+
video: ResourceElement
|
|
37
|
+
file: ResourceElement
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface ResourceElement {
|
|
41
|
+
[key: string]: any
|
|
42
|
+
src?: string
|
|
43
|
+
title?: string
|
|
44
|
+
width?: string | number
|
|
45
|
+
height?: string | number
|
|
46
|
+
duration?: string | number
|
|
47
|
+
poster?: string
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const kElement = Symbol.for('satori.element')
|
|
53
|
+
|
|
54
|
+
interface Element {
|
|
55
|
+
[kElement]: true
|
|
56
|
+
type: string
|
|
57
|
+
attrs: Dict
|
|
58
|
+
/** @deprecated use `attrs` instead */
|
|
59
|
+
data: Dict
|
|
60
|
+
children: Element[]
|
|
61
|
+
source?: string
|
|
62
|
+
toString(strip?: boolean): string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ElementConstructor extends Element { }
|
|
66
|
+
|
|
67
|
+
class ElementConstructor {
|
|
68
|
+
get data() {
|
|
69
|
+
return this.attrs
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getTagName() {
|
|
73
|
+
if (this.type === 'component') {
|
|
74
|
+
return this.attrs.is?.name ?? 'component'
|
|
75
|
+
} else {
|
|
76
|
+
return this.type
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
toAttrString() {
|
|
81
|
+
return Object.entries(this.attrs).map(([key, value]) => {
|
|
82
|
+
if (isNullable(value)) return ''
|
|
83
|
+
key = hyphenate(key)
|
|
84
|
+
if (value === true) return ` ${key}`
|
|
85
|
+
if (value === false) return ` no-${key}`
|
|
86
|
+
return ` ${key}="${Element.escape('' + value, true)}"`
|
|
87
|
+
}).join('')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
toString(strip = false) {
|
|
91
|
+
if (this.type === 'text' && 'content' in this.attrs) {
|
|
92
|
+
return strip ? this.attrs.content : Element.escape(this.attrs.content)
|
|
93
|
+
}
|
|
94
|
+
const inner = this.children.map(child => child.toString(strip)).join('')
|
|
95
|
+
if (strip) return inner
|
|
96
|
+
const attrs = this.toAttrString()
|
|
97
|
+
const tag = this.getTagName()
|
|
98
|
+
if (!this.children.length) return `<${tag}${attrs}/>`
|
|
99
|
+
return `<${tag}${attrs}>${inner}</${tag}>`
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
defineProperty(ElementConstructor, 'name', 'Element')
|
|
104
|
+
defineProperty(ElementConstructor.prototype, kElement, true)
|
|
105
|
+
|
|
106
|
+
type RenderFunction = Element.Render<Element.Fragment, Awaitable<Element.Fragment>>
|
|
107
|
+
|
|
108
|
+
function Element(type: string | RenderFunction, ...children: (Element.Fragment | undefined)[]): Element
|
|
109
|
+
function Element(type: string | RenderFunction, attrs: Dict, ...children: (Element.Fragment | undefined)[]): Element
|
|
110
|
+
function Element(type: string | RenderFunction, ...args: any[]) {
|
|
111
|
+
const el = Object.create(ElementConstructor.prototype)
|
|
112
|
+
const attrs: Dict = {}, children: Element[] = []
|
|
113
|
+
if (args[0] && typeof args[0] === 'object' && !Element.isElement(args[0]) && !Array.isArray(args[0])) {
|
|
114
|
+
const props = args.shift()
|
|
115
|
+
for (const [key, value] of Object.entries(props)) {
|
|
116
|
+
if (isNullable(value)) continue
|
|
117
|
+
// https://github.com/reactjs/rfcs/pull/107
|
|
118
|
+
if (key === 'children') {
|
|
119
|
+
args.push(...makeArray(value))
|
|
120
|
+
} else {
|
|
121
|
+
attrs[camelize(key)] = value
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const child of args) {
|
|
126
|
+
children.push(...Element.toElementArray(child))
|
|
127
|
+
}
|
|
128
|
+
if (typeof type === 'function') {
|
|
129
|
+
attrs.is = type
|
|
130
|
+
type = 'component'
|
|
131
|
+
}
|
|
132
|
+
return Object.assign(el, { type, attrs, children })
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// eslint-disable-next-line no-new-func
|
|
136
|
+
const evaluate = new Function('expr', 'context', `
|
|
137
|
+
try {
|
|
138
|
+
with (context) {
|
|
139
|
+
return eval(expr)
|
|
140
|
+
}
|
|
141
|
+
} catch {}
|
|
142
|
+
`) as ((expr: string, context: object) => string)
|
|
143
|
+
|
|
144
|
+
namespace Element {
|
|
145
|
+
export const jsx = Element
|
|
146
|
+
export const jsxs = Element
|
|
147
|
+
export const jsxDEV = Element
|
|
148
|
+
export const Fragment = 'template'
|
|
149
|
+
|
|
150
|
+
export type Fragment = string | Element | (string | Element)[]
|
|
151
|
+
export type Visit<T, S> = (element: Element, session: S) => T
|
|
152
|
+
export type Render<T, S> = (attrs: Dict, children: Element[], session: S) => T
|
|
153
|
+
export type SyncTransformer<S = never> = boolean | Fragment | Render<boolean | Fragment, S>
|
|
154
|
+
export type Transformer<S = never> = boolean | Fragment | Render<Awaitable<boolean | Fragment>, S>
|
|
155
|
+
|
|
156
|
+
type SyncVisitor<S> = Dict<SyncTransformer<S>> | Visit<boolean | Fragment, S>
|
|
157
|
+
type Visitor<S> = Dict<Transformer<S>> | Visit<Awaitable<boolean | Fragment>, S>
|
|
158
|
+
|
|
159
|
+
export function isElement(source: any): source is Element {
|
|
160
|
+
return source && typeof source === 'object' && source[kElement]
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function toElement(content: string | Element | undefined) {
|
|
164
|
+
if (typeof content === 'string' || typeof content === 'number' || typeof content === 'boolean') {
|
|
165
|
+
content = '' + content
|
|
166
|
+
if (content) return Element('text', { content })
|
|
167
|
+
} else if (isElement(content)) {
|
|
168
|
+
return content
|
|
169
|
+
} else if (!isNullable(content)) {
|
|
170
|
+
throw new TypeError(`Invalid content: ${content}`)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function toElementArray(content?: Element.Fragment) {
|
|
175
|
+
if (Array.isArray(content)) {
|
|
176
|
+
return content.map(toElement).filter(isNonNullable)
|
|
177
|
+
} else {
|
|
178
|
+
return [toElement(content)].filter(isNonNullable)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function normalize(source: Fragment, context?: any) {
|
|
183
|
+
return typeof source === 'string' ? parse(source, context) : toElementArray(source)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function escape(source: string, inline = false) {
|
|
187
|
+
const result
|
|
188
|
+
= (source ?? '').replace(/&/g, '&')
|
|
189
|
+
.replace(/</g, '<')
|
|
190
|
+
.replace(/>/g, '>')
|
|
191
|
+
return inline
|
|
192
|
+
? result.replace(/"/g, '"')
|
|
193
|
+
: result
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function unescape(source: string) {
|
|
197
|
+
return source
|
|
198
|
+
.replace(/</g, '<')
|
|
199
|
+
.replace(/>/g, '>')
|
|
200
|
+
.replace(/"/g, '"')
|
|
201
|
+
.replace(/&#(\d+);/g, (_, code) => code === '38' ? _ : String.fromCharCode(+code))
|
|
202
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, code) => code === '26' ? _ : String.fromCharCode(parseInt(code, 16)))
|
|
203
|
+
.replace(/&(amp|#38|#x26);/g, '&')
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface FindOptions {
|
|
207
|
+
type?: string
|
|
208
|
+
caret?: boolean
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** @deprecated use `Element.select()` instead */
|
|
212
|
+
export function from(source: string, options: FindOptions = {}): Element | undefined {
|
|
213
|
+
const elements = parse(source)
|
|
214
|
+
if (options.caret) {
|
|
215
|
+
if (options.type && elements[0]?.type !== options.type) return
|
|
216
|
+
return elements[0]
|
|
217
|
+
}
|
|
218
|
+
return select(elements, options.type || '*')[0]
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
type Combinator = ' ' | '>' | '+' | '~'
|
|
222
|
+
|
|
223
|
+
export interface Selector {
|
|
224
|
+
type: string
|
|
225
|
+
combinator: Combinator
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const combRegExp = / *([ >+~]) */g
|
|
229
|
+
|
|
230
|
+
export function parseSelector(input: string): Selector[][] {
|
|
231
|
+
return input.split(',').map((query) => {
|
|
232
|
+
const selectors: Selector[] = []
|
|
233
|
+
query = query.trim()
|
|
234
|
+
let combCap: RegExpExecArray | null, combinator: Combinator = ' '
|
|
235
|
+
while ((combCap = combRegExp.exec(query))) {
|
|
236
|
+
selectors.push({ type: query.slice(0, combCap.index), combinator })
|
|
237
|
+
combinator = combCap[1] as Combinator
|
|
238
|
+
query = query.slice(combCap.index + combCap[0].length)
|
|
239
|
+
}
|
|
240
|
+
selectors.push({ type: query, combinator })
|
|
241
|
+
return selectors
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function select(source: string | Element[], query: string | Selector[][]): Element[] {
|
|
246
|
+
if (!source || !query) return []
|
|
247
|
+
if (typeof source === 'string') source = parse(source)
|
|
248
|
+
if (typeof query === 'string') query = parseSelector(query)
|
|
249
|
+
if (!query.length) return []
|
|
250
|
+
let adjacent: Selector[][] = []
|
|
251
|
+
const results: Element[] = []
|
|
252
|
+
for (const [index, element] of source.entries()) {
|
|
253
|
+
const inner: Selector[][] = []
|
|
254
|
+
const local = [...query, ...adjacent]
|
|
255
|
+
adjacent = []
|
|
256
|
+
let matched = false
|
|
257
|
+
for (const group of local) {
|
|
258
|
+
const { type, combinator } = group[0]
|
|
259
|
+
if (type === element.type || type === '*') {
|
|
260
|
+
if (group.length === 1) {
|
|
261
|
+
matched = true
|
|
262
|
+
} else if ([' ', '>'].includes(group[1].combinator)) {
|
|
263
|
+
inner.push(group.slice(1))
|
|
264
|
+
} else if (group[1].combinator === '+') {
|
|
265
|
+
adjacent.push(group.slice(1))
|
|
266
|
+
} else {
|
|
267
|
+
query.push(group.slice(1))
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (combinator === ' ') {
|
|
271
|
+
inner.push(group)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (matched) results.push(source[index])
|
|
275
|
+
results.push(...select(element.children, inner))
|
|
276
|
+
}
|
|
277
|
+
return results
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function interpolate(expr: string, context: any) {
|
|
281
|
+
expr = expr.trim()
|
|
282
|
+
if (!/^[\w.]+$/.test(expr)) {
|
|
283
|
+
return evaluate(expr, context) ?? ''
|
|
284
|
+
}
|
|
285
|
+
let value = context
|
|
286
|
+
for (const part of expr.split('.')) {
|
|
287
|
+
value = value[part]
|
|
288
|
+
if (isNullable(value)) return ''
|
|
289
|
+
}
|
|
290
|
+
return value ?? ''
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const tagRegExp1 = /(?<comment><!--[\s\S]*?-->)|(?<tag><(\/?)([^!\s>/]*)([^>]*?)\s*(\/?)>)/
|
|
294
|
+
const tagRegExp2 = /(?<comment><!--[\s\S]*?-->)|(?<tag><(\/?)([^!\s>/]*)([^>]*?)\s*(\/?)>)|(?<curly>\{(?<derivative>[@:/#][^\s}]*)?[\s\S]*?\})/
|
|
295
|
+
const attrRegExp1 = /([^\s=]+)(?:="(?<value1>[^"]*)"|='(?<value2>[^']*)')?/g
|
|
296
|
+
const attrRegExp2 = /([^\s=]+)(?:="(?<value1>[^"]*)"|='(?<value2>[^']*)'|=\{(?<curly>[^}]+)\})?/g
|
|
297
|
+
|
|
298
|
+
const enum Position {
|
|
299
|
+
OPEN,
|
|
300
|
+
CLOSE,
|
|
301
|
+
EMPTY,
|
|
302
|
+
CONTINUE,
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
interface Token {
|
|
306
|
+
type: 'angle' | 'curly'
|
|
307
|
+
name: string
|
|
308
|
+
position: Position
|
|
309
|
+
source: string
|
|
310
|
+
extra: string
|
|
311
|
+
children?: Dict<(string | Token)[]>
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function parse(source: string, context?: any) {
|
|
315
|
+
const tokens: (string | Token)[] = []
|
|
316
|
+
function pushText(content: string) {
|
|
317
|
+
if (content) tokens.push(content)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const tagRegExp = context ? tagRegExp2 : tagRegExp1
|
|
321
|
+
let tagCap: RegExpExecArray | null
|
|
322
|
+
let trimStart = true
|
|
323
|
+
while ((tagCap = tagRegExp.exec(source))) {
|
|
324
|
+
const { curly, comment, derivative } = tagCap.groups!
|
|
325
|
+
const trimEnd = !curly
|
|
326
|
+
parseContent(source.slice(0, tagCap.index), trimStart, trimEnd)
|
|
327
|
+
trimStart = trimEnd
|
|
328
|
+
source = source.slice(tagCap.index + tagCap[0].length)
|
|
329
|
+
const [_, , , close, type, extra, empty] = tagCap
|
|
330
|
+
if (comment) continue
|
|
331
|
+
if (curly) {
|
|
332
|
+
let name = '', position = Position.EMPTY
|
|
333
|
+
if (derivative) {
|
|
334
|
+
name = derivative.slice(1)
|
|
335
|
+
position = {
|
|
336
|
+
'@': Position.EMPTY,
|
|
337
|
+
'#': Position.OPEN,
|
|
338
|
+
'/': Position.CLOSE,
|
|
339
|
+
':': Position.CONTINUE,
|
|
340
|
+
}[derivative[0]]!
|
|
341
|
+
}
|
|
342
|
+
tokens.push({
|
|
343
|
+
type: 'curly',
|
|
344
|
+
name,
|
|
345
|
+
position,
|
|
346
|
+
source: curly,
|
|
347
|
+
extra: curly.slice(1 + (derivative ?? '').length, -1),
|
|
348
|
+
})
|
|
349
|
+
continue
|
|
350
|
+
}
|
|
351
|
+
tokens.push({
|
|
352
|
+
type: 'angle',
|
|
353
|
+
source: _,
|
|
354
|
+
name: type || Fragment,
|
|
355
|
+
position: close ? Position.CLOSE : empty ? Position.EMPTY : Position.OPEN,
|
|
356
|
+
extra,
|
|
357
|
+
})
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
parseContent(source, trimStart, true)
|
|
361
|
+
function parseContent(source: string, trimStart: boolean, trimEnd: boolean) {
|
|
362
|
+
source = unescape(source)
|
|
363
|
+
if (trimStart) source = source.replace(/^\s*\n\s*/, '')
|
|
364
|
+
if (trimEnd) source = source.replace(/\s*\n\s*$/, '')
|
|
365
|
+
pushText(source)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return parseTokens(foldTokens(tokens), context)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function foldTokens(tokens: (string | Token)[]) {
|
|
372
|
+
const stack: [Token, string][] = [[{
|
|
373
|
+
type: 'angle',
|
|
374
|
+
name: Fragment,
|
|
375
|
+
position: Position.OPEN,
|
|
376
|
+
source: '',
|
|
377
|
+
extra: '',
|
|
378
|
+
children: { default: [] },
|
|
379
|
+
}, 'default']]
|
|
380
|
+
|
|
381
|
+
function pushToken(...tokens: (string | Token)[]) {
|
|
382
|
+
const [token, slot] = stack[0]
|
|
383
|
+
token.children![slot].push(...tokens)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
for (const token of tokens) {
|
|
387
|
+
if (typeof token === 'string') {
|
|
388
|
+
pushToken(token)
|
|
389
|
+
continue
|
|
390
|
+
}
|
|
391
|
+
const { name, position } = token
|
|
392
|
+
if (position === Position.CLOSE) {
|
|
393
|
+
if (stack[0][0].name === name) {
|
|
394
|
+
stack.shift()
|
|
395
|
+
}
|
|
396
|
+
} else if (position === Position.CONTINUE) {
|
|
397
|
+
stack[0][0].children![name] = []
|
|
398
|
+
stack[0][1] = name
|
|
399
|
+
} else if (position === Position.OPEN) {
|
|
400
|
+
pushToken(token)
|
|
401
|
+
token.children = { default: [] }
|
|
402
|
+
stack.unshift([token, 'default'])
|
|
403
|
+
} else {
|
|
404
|
+
pushToken(token)
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return stack[stack.length - 1][0].children!.default
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function parseTokens(tokens: (string | Token)[], context?: any) {
|
|
412
|
+
const result: Element[] = []
|
|
413
|
+
for (const token of tokens) {
|
|
414
|
+
if (typeof token === 'string') {
|
|
415
|
+
result.push(Element('text', { content: token }))
|
|
416
|
+
} else if (token.type === 'angle') {
|
|
417
|
+
const attrs = {}
|
|
418
|
+
const attrRegExp = context ? attrRegExp2 : attrRegExp1
|
|
419
|
+
let attrCap: RegExpExecArray | null
|
|
420
|
+
while ((attrCap = attrRegExp.exec(token.extra))) {
|
|
421
|
+
const [, key, v1, v2 = v1, v3] = attrCap
|
|
422
|
+
if (v3) {
|
|
423
|
+
attrs[key] = interpolate(v3, context)
|
|
424
|
+
} else if (!isNullable(v2)) {
|
|
425
|
+
attrs[key] = unescape(v2)
|
|
426
|
+
} else if (key.startsWith('no-')) {
|
|
427
|
+
attrs[key.slice(3)] = false
|
|
428
|
+
} else {
|
|
429
|
+
attrs[key] = true
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
result.push(Element(token.name, attrs, token.children && parseTokens(token.children.default, context)))
|
|
433
|
+
} else if (!token.name) {
|
|
434
|
+
result.push(...toElementArray(interpolate(token.extra, context)))
|
|
435
|
+
} else if (token.name === 'if') {
|
|
436
|
+
if (evaluate(token.extra, context)) {
|
|
437
|
+
result.push(...parseTokens(token.children!.default, context))
|
|
438
|
+
} else {
|
|
439
|
+
result.push(...parseTokens(token.children!.else || [], context))
|
|
440
|
+
}
|
|
441
|
+
} else if (token.name === 'each') {
|
|
442
|
+
const [expr, ident] = token.extra.split(/\s+as\s+/)
|
|
443
|
+
const items = interpolate(expr, context)
|
|
444
|
+
if (!items || !items[Symbol.iterator]) continue
|
|
445
|
+
for (const item of items) {
|
|
446
|
+
result.push(...parseTokens(token.children!.default, { ...context, [ident]: item }))
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return result
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function visit<S>(element: Element, rules: Visitor<S>, session: S) {
|
|
454
|
+
const { type, attrs, children } = element
|
|
455
|
+
if (typeof rules === 'function') {
|
|
456
|
+
return rules(element, session)
|
|
457
|
+
} else {
|
|
458
|
+
let result: any = rules[typeof type === 'string' ? type : ''] ?? rules.default ?? true
|
|
459
|
+
if (typeof result === 'function') {
|
|
460
|
+
result = result(attrs, children, session)
|
|
461
|
+
}
|
|
462
|
+
return result
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
type Rest<T> = [T] extends [never] ? [session?: T] : [session: T]
|
|
467
|
+
|
|
468
|
+
export function transform<S = never>(source: string, rules: SyncVisitor<S>, ...rest: Rest<S>): string
|
|
469
|
+
export function transform<S = never>(source: Element[], rules: SyncVisitor<S>, ...rest: Rest<S>): Element[]
|
|
470
|
+
export function transform<S>(source: string | Element[], rules: SyncVisitor<S>, session: S) {
|
|
471
|
+
const elements = typeof source === 'string' ? parse(source) : source
|
|
472
|
+
const output: Element[] = []
|
|
473
|
+
elements.forEach((element) => {
|
|
474
|
+
const { type, attrs, children } = element
|
|
475
|
+
const result = visit(element, rules, session)
|
|
476
|
+
if (result === true) {
|
|
477
|
+
output.push(Element(type, attrs, transform(children, rules, session)))
|
|
478
|
+
} else if (result !== false) {
|
|
479
|
+
output.push(...toElementArray(result))
|
|
480
|
+
}
|
|
481
|
+
})
|
|
482
|
+
return typeof source === 'string' ? output.join('') : output
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export async function transformAsync<S = never>(source: string, rules: Visitor<S>, ...rest: Rest<S>): Promise<string>
|
|
486
|
+
export async function transformAsync<S = never>(source: Element[], rules: Visitor<S>, ...rest: Rest<S>): Promise<Element[]>
|
|
487
|
+
export async function transformAsync<S>(source: string | Element[], rules: Visitor<S>, session: S) {
|
|
488
|
+
const elements = typeof source === 'string' ? parse(source) : source
|
|
489
|
+
const children = (await Promise.all(elements.map(async (element) => {
|
|
490
|
+
const { type, attrs, children } = element
|
|
491
|
+
const result = await visit(element, rules, session)
|
|
492
|
+
if (result === true) {
|
|
493
|
+
return [Element(type, attrs, await transformAsync(children, rules, session))]
|
|
494
|
+
} else if (result !== false) {
|
|
495
|
+
return toElementArray(result)
|
|
496
|
+
} else {
|
|
497
|
+
return []
|
|
498
|
+
}
|
|
499
|
+
}))).flat(1)
|
|
500
|
+
return typeof source === 'string' ? children.join('') : children
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export type Factory<R extends any[]> = (...args: [...rest: R, attrs?: Dict]) => Element
|
|
504
|
+
|
|
505
|
+
function createFactory<R extends any[] = any[]>(type: string, ...keys: string[]): Factory<R> {
|
|
506
|
+
return (...args: any[]) => {
|
|
507
|
+
const element = Element(type)
|
|
508
|
+
keys.forEach((key, index) => {
|
|
509
|
+
if (!isNullable(args[index])) {
|
|
510
|
+
element.attrs[key] = args[index]
|
|
511
|
+
}
|
|
512
|
+
})
|
|
513
|
+
if (args[keys.length]) {
|
|
514
|
+
Object.assign(element.attrs, args[keys.length])
|
|
515
|
+
}
|
|
516
|
+
return element
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// eslint-disable-next-line prefer-const
|
|
521
|
+
export let warn: (message: string) => void = () => { }
|
|
522
|
+
|
|
523
|
+
function createAssetFactory(type: string): Factory<[data: string] | [data: Buffer | ArrayBuffer | ArrayBufferView, type: string]> {
|
|
524
|
+
return (src, ...args) => {
|
|
525
|
+
let prefix = 'base64://'
|
|
526
|
+
if (typeof args[0] === 'string') {
|
|
527
|
+
prefix = `data:${args.shift()};base64,`
|
|
528
|
+
}
|
|
529
|
+
if (is('Buffer', src)) {
|
|
530
|
+
src = prefix + src.toString('base64')
|
|
531
|
+
} else if (is('ArrayBuffer', src)) {
|
|
532
|
+
src = prefix + Binary.toBase64(src)
|
|
533
|
+
} else if (ArrayBuffer.isView(src)) {
|
|
534
|
+
src = prefix + Binary.toBase64(src.buffer)
|
|
535
|
+
}
|
|
536
|
+
if (src.startsWith('base64://')) {
|
|
537
|
+
warn(`protocol "base64:" is deprecated and will be removed in the future, please use "data:" instead`)
|
|
538
|
+
}
|
|
539
|
+
return Element(type, { ...args[0] as {}, src })
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export const text = createFactory<[content: any]>('text', 'content')
|
|
544
|
+
export const at = createFactory<[id: any]>('at', 'id')
|
|
545
|
+
export const sharp = createFactory<[id: any]>('sharp', 'id')
|
|
546
|
+
export const quote = createFactory<[id: any]>('quote', 'id')
|
|
547
|
+
export const emoji = createFactory<[id: any]>('emoji', 'id')
|
|
548
|
+
export const image = createAssetFactory('img')
|
|
549
|
+
export const img = createAssetFactory('img')
|
|
550
|
+
export const video = createAssetFactory('video')
|
|
551
|
+
export const audio = createAssetFactory('audio')
|
|
552
|
+
export const file = createAssetFactory('file')
|
|
553
|
+
|
|
554
|
+
export function i18n(path: string | Dict, children?: any[]) {
|
|
555
|
+
return Element('i18n', typeof path === 'string' ? { path } : path, children)
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export = Element
|