HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/node_modules/@ckeditor/ckeditor5-ckbox/src/ckboximageedit/utils.js
/**
 * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
 */
/**
 * @module ckbox/ckboximageedit/utils
 */
import { global } from 'ckeditor5/src/utils';
/**
 * @internal
 */
export function createEditabilityChecker(allowExternalImagesEditing) {
    const checkUrl = createUrlChecker(allowExternalImagesEditing);
    return element => {
        const isImageElement = element.is('element', 'imageInline') ||
            element.is('element', 'imageBlock');
        if (!isImageElement) {
            return false;
        }
        if (element.hasAttribute('ckboxImageId')) {
            return true;
        }
        if (element.hasAttribute('src')) {
            return checkUrl(element.getAttribute('src'));
        }
        return false;
    };
}
function createUrlChecker(allowExternalImagesEditing) {
    if (Array.isArray(allowExternalImagesEditing)) {
        const urlMatchers = allowExternalImagesEditing.map(createUrlChecker);
        return src => urlMatchers.some(matcher => matcher(src));
    }
    if (allowExternalImagesEditing == 'origin') {
        const origin = global.window.location.origin;
        return src => new URL(src, global.document.baseURI).origin == origin;
    }
    if (typeof allowExternalImagesEditing == 'function') {
        return allowExternalImagesEditing;
    }
    if (allowExternalImagesEditing instanceof RegExp) {
        return src => !!(src.match(allowExternalImagesEditing) ||
            src.replace(/^https?:\/\//, '').match(allowExternalImagesEditing));
    }
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const shouldBeUndefned = allowExternalImagesEditing;
    return () => false;
}