@drincs/pixi-vn
Version:
Pixi'VN is a npm package that provides various features for creating visual novels.
1 lines • 4.14 kB
Source Map (JSON)
{"version":3,"sources":["../../src/functions/TextureUtility.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAOA,SAAsB,WAAW,QAA2C,EAAA;AAAA,EAAA,OAAA,OAAA,CAAA,IAAA,EAAA,IAAA,EAAA,aAAA;AACxE,IAAA,IAAI,MAAO,CAAA,KAAA,CAAM,GAAI,CAAA,QAAQ,CAAG,EAAA;AAC5B,MAAO,OAAA,MAAA,CAAO,IAAI,QAAQ,CAAA,CAAA;AAAA,KAC9B;AACA,IAAA,OAAO,OAAO,IAAK,CAAA,QAAQ,CACtB,CAAA,IAAA,CAAK,CAAC,OAAY,KAAA;AACf,MAAA,IAAI,CAAC,OAAS,EAAA;AACV,QAAQ,OAAA,CAAA,KAAA,CAAM,+BAA+B,QAAQ,CAAA,CAAA;AACrD,QAAA,OAAA;AAAA,OACJ;AAEA,MAAI,IAAA,EAAE,mBAAmB,OAAU,CAAA,EAAA;AAC/B,QAAQ,OAAA,CAAA,KAAA,CAAM,iCAAiC,QAAQ,CAAA,CAAA;AACvD,QAAA,OAAA;AAAA,OACJ;AAEA,MAAO,OAAA,OAAA,CAAA;AAAA,KACV,CAAA,CACA,KAAM,CAAA,CAAC,CAAM,KAAA;AACV,MAAQ,OAAA,CAAA,KAAA,CAAM,iCAAiC,CAAC,CAAA,CAAA;AAChD,MAAA,OAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACT,CAAA,CAAA;AAAA,CAAA;AAEA,SAAS,0BAAA,CAA2B,MAA8D,QAA2B,EAAA;AACzH,EAAI,IAAA,EAAE,gBAAgB,MAAS,CAAA,EAAA;AAC3B,IAAO,OAAA,IAAA,CAAA;AAAA,GACX;AAEA,EAAA,OAAA,CAAQ,IAAK,CAAA,CAAA,2BAAA,EAA8B,QAAQ,CAAA,6DAAA,CAAA,EAAiE,IAAI,CAAA,CAAA;AACxH,EAAO,OAAA,KAAA,CAAA,CAAA;AACX,CAAA;AAEO,SAAS,aAAa,KAAoC,EAAA;AAC7D,EAAO,OAAA;AAAA,IACH,OAAO,KAAM,CAAA,KAAA;AAAA,IACb,YAAY,KAAM,CAAA,UAAA;AAAA,IAClB,YAAY,KAAM,CAAA,UAAA;AAAA,IAClB,IAAM,EAAA,0BAAA,CAA2B,KAAM,CAAA,MAAA,EAAQ,MAAM,CAAA;AAAA,IACrD,YAAY,KAAM,CAAA,UAAA;AAAA,IAClB,UAAU,KAAM,CAAA,QAAA;AAAA,IAChB,WAAW,KAAM,CAAA,SAAA;AAAA,IACjB,aAAa,KAAM,CAAA,WAAA;AAAA,IACnB,YAAY,KAAM,CAAA,UAAA;AAAA,IAClB,SAAS,KAAM,CAAA,OAAA;AAAA,IACf,eAAe,KAAM,CAAA,aAAA;AAAA,IACrB,YAAY,KAAM,CAAA,UAAA;AAAA,IAClB,SAAS,KAAM,CAAA,OAAA;AAAA,IACf,MAAQ,EAAA,0BAAA,CAA2B,KAAM,CAAA,MAAA,EAAQ,QAAQ,CAAA;AAAA,IACzD,cAAc,KAAM,CAAA,YAAA;AAAA,IACpB,MAAM,KAAM,CAAA,IAAA;AAAA,IACZ,YAAY,KAAM,CAAA,UAAA;AAAA,IAClB,UAAU,KAAM,CAAA,QAAA;AAAA,IAChB,eAAe,KAAM,CAAA,aAAA;AAAA,GACzB,CAAA;AACJ","file":"TextureUtility.mjs","sourcesContent":["import { Assets, ColorSource, FillGradient, FillPattern, StrokeStyle, TextStyle, TextStyleOptions, Texture } from 'pixi.js';\n\n/**\n * Get a texture from a url.\n * @param imageUrl is the url of the image.\n * @returns the texture of the image, or a text with the error.\n */\nexport async function getTexture(imageUrl: string): Promise<Texture | void> {\n if (Assets.cache.has(imageUrl)) {\n return Assets.get(imageUrl)\n }\n return Assets.load(imageUrl)\n .then((texture) => {\n if (!texture) {\n console.error(\"[Pixi'VN] Texture not found\", imageUrl)\n return\n }\n // if texture not is a Texture, then it is a TextureResource\n if (!(texture instanceof Texture)) {\n console.error(\"[Pixi'VN] File not is a image\", imageUrl)\n return\n }\n\n return texture\n })\n .catch((e) => {\n console.error(\"[Pixi'VN] Error loading image\", e)\n return\n })\n}\n\nfunction getFillGradientFillPattern(prop: ColorSource | FillGradient | FillPattern | StrokeStyle, propName: keyof TextStyle) {\n if (!(prop instanceof Object)) {\n return prop\n }\n // TODO: FillGradient and FillPattern are not supported yet\n console.warn(`[Pixi'VN] CanvasText.style.${propName} is a FillGradient or FillPattern, this is not supported yet.`, prop)\n return undefined\n}\n\nexport function getTextStyle(style: TextStyle): TextStyleOptions {\n return {\n align: style.align,\n breakWords: style.breakWords,\n dropShadow: style.dropShadow,\n fill: getFillGradientFillPattern(style.stroke, \"fill\"),\n fontFamily: style.fontFamily,\n fontSize: style.fontSize,\n fontStyle: style.fontStyle,\n fontVariant: style.fontVariant,\n fontWeight: style.fontWeight,\n leading: style.leading,\n letterSpacing: style.letterSpacing,\n lineHeight: style.lineHeight,\n padding: style.padding,\n stroke: getFillGradientFillPattern(style.stroke, \"stroke\"),\n textBaseline: style.textBaseline,\n trim: style.trim,\n whiteSpace: style.whiteSpace,\n wordWrap: style.wordWrap,\n wordWrapWidth: style.wordWrapWidth,\n }\n}\n"]}