Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"mediaimage.min.js","sources":["../src/mediaimage.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * AI Modal for Tiny.\n *\n * @module      tiny_aiplacement/mediaimage\n * @copyright   2024 Matt Porritt <matt.porritt@moodle.com>\n * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {getString} from 'core/str';\nimport MediaImage from 'tiny_media/image';\nimport Notification from 'core/notification';\nimport {prefetchStrings} from 'core/prefetch';\nimport {MAX_LENGTH_ALT} from 'tiny_media/imagehelpers';\n\nprefetchStrings('core_ai', [\n    'contentwatermark',\n]);\n\nexport default class AiMediaImage extends MediaImage {\n    constructor(editor, url, alt) {\n        super(editor); // Call the parent class constructor\n        this.generatedImageUrl = url;\n        this.altText = alt;\n        getString('contentwatermark', 'core_ai').then((watermark) => {\n            this.watermark = watermark;\n            return;\n        }).catch(Notification.exception);\n    }\n\n    getSelectedImage() {\n        const imgElement = document.createElement('img');\n\n        // Set attributes for the img element\n        imgElement.src = this.generatedImageUrl;\n        imgElement.alt = this.truncateAltText(this.altText);\n\n        return imgElement;\n    }\n\n    /**\n     * Truncate the alt text if it is longer than the maximum length.\n     * @param {String} altText The alt text\n     * @return {string} The truncated alt text\n     */\n    truncateAltText(altText) {\n        const maximumAltTextLength = MAX_LENGTH_ALT;\n        const watermark = ' - ' + this.watermark;\n        const ellipsis = '...';\n\n        // Append the watermark to the alt text.\n        if (altText.length + watermark.length <= maximumAltTextLength) {\n            altText = altText + watermark;\n        } else {\n            const remainingLength = maximumAltTextLength - watermark.length - ellipsis.length;\n            altText = altText.substring(0, remainingLength) + ellipsis + watermark;\n        }\n        return altText;\n    }\n}\n"],"names":["AiMediaImage","MediaImage","constructor","editor","url","alt","generatedImageUrl","altText","then","watermark","catch","Notification","exception","getSelectedImage","imgElement","document","createElement","src","this","truncateAltText","maximumAltTextLength","MAX_LENGTH_ALT","length","remainingLength","substring"],"mappings":";;;;;;;6MA6BgB,UAAW,CACvB,2BAGiBA,qBAAqBC,eACtCC,YAAYC,OAAQC,IAAKC,WACfF,aACDG,kBAAoBF,SACpBG,QAAUF,uBACL,mBAAoB,WAAWG,MAAMC,iBACtCA,UAAYA,aAElBC,MAAMC,sBAAaC,WAG1BC,yBACUC,WAAaC,SAASC,cAAc,cAG1CF,WAAWG,IAAMC,KAAKZ,kBACtBQ,WAAWT,IAAMa,KAAKC,gBAAgBD,KAAKX,SAEpCO,WAQXK,gBAAgBZ,eACNa,qBAAuBC,6BACvBZ,UAAY,MAAQS,KAAKT,aAI3BF,QAAQe,OAASb,UAAUa,QAAUF,qBACrCb,SAAoBE,cACjB,OACGc,gBAAkBH,qBAAuBX,UAAUa,OAN5C,MAM8DA,OAC3Ef,QAAUA,QAAQiB,UAAU,EAAGD,iBAPlB,MAOgDd,iBAE1DF"}