UNPKG

@pixi/utils

Version:

Collection of utilities used by PixiJS

1 lines 1.38 kB
{"version":3,"file":"determineCrossOrigin.mjs","sources":["../../src/network/determineCrossOrigin.ts"],"sourcesContent":["/**\n * Sets the `crossOrigin` property for this resource based on if the url\n * for this resource is cross-origin. If crossOrigin was manually set, this\n * function does nothing.\n * Nipped from the resource loader!\n * @ignore\n * @param {string} url - The url to test.\n * @param {object} [loc=window.location] - The location object to test against.\n * @returns {string} The crossOrigin value to use (or empty string for none).\n */\nexport function determineCrossOrigin(url: string, loc: Location = globalThis.location): string\n{\n // data: and javascript: urls are considered same-origin\n if (url.startsWith('data:'))\n {\n return '';\n }\n\n // default is window.location\n loc = loc || globalThis.location;\n\n const parsedUrl = new URL(url, document.baseURI);\n\n // if cross origin\n if (parsedUrl.hostname !== loc.hostname || parsedUrl.port !== loc.port || parsedUrl.protocol !== loc.protocol)\n {\n return 'anonymous';\n }\n\n return '';\n}\n"],"names":[],"mappings":"AAUO,SAAS,qBAAqB,KAAa,MAAgB,WAAW,UAC7E;AAEQ,MAAA,IAAI,WAAW,OAAO;AAEf,WAAA;AAIX,QAAM,OAAO,WAAW;AAExB,QAAM,YAAY,IAAI,IAAI,KAAK,SAAS,OAAO;AAG/C,SAAI,UAAU,aAAa,IAAI,YAAY,UAAU,SAAS,IAAI,QAAQ,UAAU,aAAa,IAAI,WAE1F,cAGJ;AACX;"}