{"version":3,"file":"obliczeniowo-elementary-hex-color.mjs","sources":["../../../../projects/components/hex-color/components/hex-color/hex-color.component.ts","../../../../projects/components/hex-color/components/hex-color/hex-color.component.html","../../../../projects/components/hex-color/components/hex-colors/hex-colors.component.ts","../../../../projects/components/hex-color/components/hex-colors/hex-colors.component.html","../../../../projects/components/hex-color/hex-color.module.ts","../../../../projects/components/hex-color/obliczeniowo-elementary-hex-color.ts"],"sourcesContent":["import { ColorRGB } from '@obliczeniowo/elementary/classes';\nimport { Component, Output, EventEmitter, HostListener, ChangeDetectionStrategy, input, computed } from '@angular/core';\n\nexport interface HexColor {\n  color: ColorRGB | string;\n  x: number | string;\n  y: number | string;\n}\n\n@Component({\n    selector: 'g[obl-hex-color]',\n    templateUrl: './hex-color.component.html',\n    styleUrls: ['./hex-color.component.scss'],\n    changeDetection: ChangeDetectionStrategy.OnPush,\n    standalone: false\n})\nexport class HexColorComponent {\n  /** hex element ray */\n  ray = input<number>(10);\n  /** x pos can be css style like calc(50% + 10px) */\n  x = input<number | string>(0);\n  /** y pos can be css style like calc(50% + 10px) */\n  y = input<number | string>(0);\n  /** fill color as ColorRGB object or string color as one of:\n   * #ffffff\n   * rgb(255, 255, 255)\n   * rgba(255, 255, 255, 0.5)\n   * named color format, for example: red, blue, green ... */\n  fill = input<ColorRGB | string>(new ColorRGB(0, 0, 0, 255));\n\n  strokeWidth = input<number>(0);\n  /** stroke color as ColorRGB object or string color as one of:\n   * #ffffff\n   * rgb(255, 255, 255)\n   * rgba(255, 255, 255, 0.5)\n   * named color format, for example: red, blue, green ... */\n  strokeColor = input<ColorRGB | string>(new ColorRGB(0, 0, 0, 0));\n\n  @Output() clicked: EventEmitter<HexColor> = new EventEmitter<HexColor>();\n\n  protected fillHover = computed<ColorRGB | string>(() => typeof this.fill() === 'string' && this.fill() || (this.fill() as ColorRGB).multiply(0.8));\n\n  hover = false;\n\n  protected points = computed(() => this.recalc())\n\n  @HostListener('click') onClick() {\n    this.clicked.emit({\n      color: this.fill(),\n      x: this.x(),\n      y: this.y()\n    })\n  }\n\n  protected recalc() {\n    const n = 6\n    const offset = Math.PI / n;\n    return new Array(n).fill(0).map((_, index: number) => {\n      const angle = index * Math.PI / (n / 2) + offset;\n      return [\n        this.ray() * Math.sin(angle),\n        this.ray() * Math.cos(angle)\n      ].join(',')\n    }).join(' ');\n  }\n}\n","<svg:polygon\n  [attr.points]=\"points()\"\n  [style.transform]=\"'translate(' + x() + ', ' + y() + ')'\"\n  [style.fill]=\"hover ? fillHover().toString() : fill().toString()\"\n  [style.stroke]=\"strokeColor().toString()\"\n  [style.strokeWidth]=\"strokeWidth()\"\n  (mouseenter)=\"hover = true\"\n  (mouseleave)=\"hover = false\"\n  class=\"clickable\"\n></svg:polygon>\n","import { HexColor } from './../hex-color/hex-color.component';\nimport { ColorRGB, ColorHSV, Point2D } from '@obliczeniowo/elementary/classes';\nimport { Component, ChangeDetectionStrategy, input, computed, model } from '@angular/core';\n\n@Component({\n    selector: 'obl-hex-colors',\n    templateUrl: './hex-colors.component.html',\n    styleUrls: ['./hex-colors.component.scss'],\n    changeDetection: ChangeDetectionStrategy.OnPush,\n    standalone: false\n})\nexport class HexColorsComponent {\n  /** hex element ray */\n  ray = input(10, {\n    transform: (value: number) => value < 5 ? 5 : value\n  });\n\n  /** Number of levels */\n  rounds = input(6, {\n      transform: (rounds: number) => rounds < 1 ? 1 : rounds\n    }\n  );\n\n  /** color to select if exist on palette of colors */\n  color = model<string>('#ffffff');\n\n  protected width = computed<number>(() => (1.5 * (this.rounds() - 1) + 1) * this.ray() * 2 + 6);\n\n  protected height = computed<number>(() => (this.h * (this.rounds() - 1) * 2 + this.h) * this.ray() * 2 + 6);\n\n  readonly h = Math.sqrt(3) / 2;\n\n  readonly rayTranslate = new Point2D(0, this.h * 2);\n  readonly move = new Point2D(1.5, -this.h);\n\n  elements = computed<{ pos: Point2D; color: ColorRGB }[]>(() => {\n    const elements = [];\n\n    elements.push({\n      pos: new Point2D(),\n      color: new ColorRGB(255, 255, 255, 255)\n    });\n\n    for (let dAngle = 0; dAngle < 6; dAngle++) {\n      const angle = Math.PI / 3 * dAngle;\n      for (let dRay = 1; dRay < this.rounds(); dRay++) {\n        const total = 6 * dRay;\n        const ray = this.rayTranslate.multiply(this.ray() * dRay).rotate(angle);\n        for (let dMove = 0; dMove < dRay; dMove++) {\n          const move = this.move.multiply(this.ray() * dMove).rotate(angle);\n          elements.push({\n            pos: ray.add(move),\n            color: (\n              ColorHSV.createColorHSV(\n                360 * (1 - (dAngle * dRay - dMove) / total),\n                dRay / this.rounds(),\n                255\n              )).convertToRGB()\n          });\n        }\n      }\n    }\n\n    return elements;\n  });\n\n  strokeColor: ColorRGB | string = new ColorRGB(255, 255, 255, 255);\n\n  selected = computed<undefined | HexColor>(() => {\n    if (this.elements) {\n      const found = this.elements().find(c => c.color.toString() === this.color());\n      if (found) {\n        return {\n          x: `calc(50% + ${found.pos.x}px)`,\n          y: `calc(50% + ${found.pos.y}px)`,\n          color: found.color\n        };\n      }\n    }\n    return undefined;\n  });\n\n  selectedColor: ColorRGB = new ColorRGB(0, 0, 0);\n\n  onChange(selected: HexColor) {\n    this.color.set(selected.color.toString());\n  }\n}\n","<svg [attr.width]=\"width()\" [attr.height]=\"height()\">\n  @for (element of elements(); track $index) {\n    <g\n      obl-hex-color\n      [x]=\"'calc(50% + ' + element.pos.x + 'px)'\"\n      [y]=\"'calc(50% + ' + element.pos.y + 'px)'\"\n      [fill]=\"element.color\"\n      [strokeColor]=\"strokeColor\"\n      [strokeWidth]=\"1\"\n      [ray]=\"ray()\"\n      (clicked)=\"onChange($event)\"\n    ></g>\n  }\n\n  @if (selected()) {\n    <g\n      obl-hex-color\n      [ray]=\"ray() + 1\"\n      [x]=\"selected()!.x\"\n      [y]=\"selected()!.y\"\n      [fill]=\"'none'\"\n      [strokeWidth]=\"6\"\n      [strokeColor]=\"'white'\"\n    ></g>\n    <g\n      obl-hex-color\n      [ray]=\"ray()\"\n      [x]=\"selected()!.x\"\n      [y]=\"selected()!.y\"\n      [fill]=\"'none'\"\n      [strokeWidth]=\"1\"\n      [strokeColor]=\"selectedColor\"\n    ></g>\n  }\n</svg>\n","import { NgModule } from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { HexColorComponent } from './components/hex-color/hex-color.component';\nimport { HexColorsComponent } from './components/hex-colors/hex-colors.component';\n\n@NgModule({\n  declarations: [\n    HexColorComponent,\n    HexColorsComponent\n  ],\n  imports: [\n    CommonModule,\n  ],\n  exports: [\n    HexColorsComponent\n  ]\n})\nexport class HexColorModule { }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.HexColorComponent"],"mappings":";;;;;MAgBa,iBAAiB,CAAA;;AAE5B,IAAA,GAAG,GAAG,KAAK,CAAS,EAAE,CAAC;;AAEvB,IAAA,CAAC,GAAG,KAAK,CAAkB,CAAC,CAAC;;AAE7B,IAAA,CAAC,GAAG,KAAK,CAAkB,CAAC,CAAC;AAC7B;;;;AAI2D;AAC3D,IAAA,IAAI,GAAG,KAAK,CAAoB,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAE3D,IAAA,WAAW,GAAG,KAAK,CAAS,CAAC,CAAC;AAC9B;;;;AAI2D;AAC3D,IAAA,WAAW,GAAG,KAAK,CAAoB,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEtD,IAAA,OAAO,GAA2B,IAAI,YAAY,EAAY;AAE9D,IAAA,SAAS,GAAG,QAAQ,CAAoB,MAAM,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,EAAE,IAAK,IAAI,CAAC,IAAI,EAAe,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAElJ,KAAK,GAAG,KAAK;IAEH,MAAM,GAAG,QAAQ,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAA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