import tplAudio from 'templates/audio.js'; import tplGif from 'templates/gif.js'; import tplImage from 'templates/image.js'; import tplVideo from 'templates/video.js'; import { Directive, directive } from 'lit/directive.js'; import { api, log } from '@converse/headless'; import { getEmojiMarkup } from './chat/utils.js'; import { getHyperlinkTemplate } from '../utils/html.js'; import { getMediaURLs } from '@converse/headless/shared/chat/utils.js'; import { getMediaURLsMetadata } from '@converse/headless/shared/parsers.js'; import { html } from 'lit'; import { until } from 'lit/directives/until.js'; import { convertASCII2Emoji, getCodePointReferences, getShortnameReferences } from '@converse/headless/plugins/emoji/utils.js'; import { filterQueryParamsFromURL, isAudioURL, isGIFURL, isImageURL, isVideoURL, } from '@converse/headless/utils/url.js'; import { shouldRenderMediaFromURL } from 'utils/url.js'; /** * @class RichText * A String subclass that is used to render rich text (i.e. text that contains * hyperlinks, images, mentions, styling etc.). * * The "rich" parts of the text is represented by lit TemplateResult * objects which are added via the {@link RichText.addTemplateResult} * method and saved as metadata. * * By default Converse adds TemplateResults to support emojis, hyperlinks, * images, map URIs and mentions. * * 3rd party plugins can listen for the `beforeMessageBodyTransformed` * and/or `afterMessageBodyTransformed` events and then call * `addTemplateResult` on the RichText instance in order to add their own * rich features. */ export class RichText extends String { /** * Create a new {@link RichText} instance. * @param {string} text - The text to be annotated * @param {number} offset - The offset of this particular piece of text * from the start of the original message text. This is necessary because * RichText instances can be nested when templates call directives * which create new RichText instances (as happens with XEP-393 styling directives). * @param {Object} [options] * @param {string} [options.nick] - The current user's nickname (only relevant if the message is in a XEP-0045 MUC) * @param {boolean} [options.render_styling] - Whether XEP-0393 message styling should be applied to the message * @param {boolean} [options.embed_audio] - Whether audio URLs should be rendered as