@pixi/utils
Version:
Collection of utilities used by PixiJS
1 lines • 2.38 kB
Source Map (JSON)
{"version":3,"file":"determineCrossOrigin.mjs","sources":["../../src/network/determineCrossOrigin.ts"],"sourcesContent":["import { url as _url } from '../url';\n\nlet tempAnchor: HTMLAnchorElement | undefined;\n\n/**\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 if (!tempAnchor)\n {\n tempAnchor = document.createElement('a');\n }\n\n // let the browser determine the full href for the url of this resource and then\n // parse with the node url lib, we can't use the properties of the anchor element\n // because they don't work in IE9 :(\n tempAnchor.href = url;\n const parsedUrl = _url.parse(tempAnchor.href);\n\n const samePort = (!parsedUrl.port && loc.port === '') || (parsedUrl.port === loc.port);\n\n // if cross origin\n if (parsedUrl.hostname !== loc.hostname || !samePort || parsedUrl.protocol !== loc.protocol)\n {\n return 'anonymous';\n }\n\n return '';\n}\n"],"names":["url","_url"],"mappings":";;AAEA,IAAI,UAAA,CAAA;AAYiC,SAAA,oBAAA,CAAAA,KAAA,EAAa,GAAgB,GAAA,UAAA,CAAW,QAC7E,EAAA;AAEI,EAAI,IAAAA,KAAA,CAAI,UAAW,CAAA,OAAO,CAC1B,EAAA;AACI,IAAO,OAAA,EAAA,CAAA;AAAA,GACX;AAGA,EAAA,GAAA,GAAM,OAAO,UAAW,CAAA,QAAA,CAAA;AAExB,EAAA,IAAI,CAAC,UACL,EAAA;AACI,IAAa,UAAA,GAAA,QAAA,CAAS,cAAc,GAAG,CAAA,CAAA;AAAA,GAC3C;AAKA,EAAA,UAAA,CAAW,IAAO,GAAAA,KAAA,CAAA;AAClB,EAAA,MAAM,SAAY,GAAAC,GAAA,CAAK,KAAM,CAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAE5C,EAAM,MAAA,QAAA,GAAY,CAAC,SAAU,CAAA,IAAA,IAAQ,IAAI,IAAS,KAAA,EAAA,IAAQ,SAAU,CAAA,IAAA,KAAS,GAAI,CAAA,IAAA,CAAA;AAGjF,EAAI,IAAA,SAAA,CAAU,aAAa,GAAI,CAAA,QAAA,IAAY,CAAC,QAAY,IAAA,SAAA,CAAU,QAAa,KAAA,GAAA,CAAI,QACnF,EAAA;AACI,IAAO,OAAA,WAAA,CAAA;AAAA,GACX;AAEA,EAAO,OAAA,EAAA,CAAA;AACX;;;;"}