extra.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. var __pow = Math.pow;
  2. (function(global, factory) {
  3. typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@pixi/graphics"), require("@pixi/text"), require("@pixi/math")) : typeof define === "function" && define.amd ? define(["exports", "@pixi/graphics", "@pixi/text", "@pixi/math"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory((global.PIXI = global.PIXI || {}, global.PIXI.live2d = global.PIXI.live2d || {}), global.PIXI, global.PIXI, global.PIXI));
  4. })(this, function(exports2, graphics, text, math) {
  5. "use strict";
  6. const tempBounds = new math.Rectangle();
  7. class HitAreaFrames extends graphics.Graphics {
  8. constructor() {
  9. super();
  10. this.initialized = false;
  11. this.texts = [];
  12. this.strokeWidth = 4;
  13. this.normalColor = 14883354;
  14. this.activeColor = 2017330;
  15. this.interactive = true;
  16. this.on("added", this.init).on("pointermove", this.onPointerMove);
  17. }
  18. init() {
  19. const internalModel = this.parent.internalModel;
  20. const textStyle = new text.TextStyle({
  21. fontSize: 24,
  22. fill: "#ffffff",
  23. stroke: "#000000",
  24. strokeThickness: 4
  25. });
  26. this.texts = Object.keys(internalModel.hitAreas).map((hitAreaName) => {
  27. const text$1 = new text.Text(hitAreaName, textStyle);
  28. text$1.visible = false;
  29. this.addChild(text$1);
  30. return text$1;
  31. });
  32. }
  33. onPointerMove(e) {
  34. const hitAreaNames = this.parent.hitTest(e.data.global.x, e.data.global.y);
  35. this.texts.forEach((text2) => {
  36. text2.visible = hitAreaNames.includes(text2.text);
  37. });
  38. }
  39. _render(renderer) {
  40. const internalModel = this.parent.internalModel;
  41. const scale = 1 / Math.sqrt(__pow(this.transform.worldTransform.a, 2) + __pow(this.transform.worldTransform.b, 2));
  42. this.texts.forEach((text2) => {
  43. this.lineStyle({
  44. width: this.strokeWidth * scale,
  45. color: text2.visible ? this.activeColor : this.normalColor
  46. });
  47. const bounds = internalModel.getDrawableBounds(internalModel.hitAreas[text2.text].index, tempBounds);
  48. const transform = internalModel.localTransform;
  49. bounds.x = bounds.x * transform.a + transform.tx;
  50. bounds.y = bounds.y * transform.d + transform.ty;
  51. bounds.width = bounds.width * transform.a;
  52. bounds.height = bounds.height * transform.d;
  53. this.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
  54. text2.x = bounds.x + this.strokeWidth * scale;
  55. text2.y = bounds.y + this.strokeWidth * scale;
  56. text2.scale.set(scale);
  57. });
  58. super._render(renderer);
  59. this.clear();
  60. }
  61. }
  62. exports2.HitAreaFrames = HitAreaFrames;
  63. Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
  64. });