@obliczeniowo/elementary
Version:
Library made in Angular version 19
1 lines • 13.6 kB
Source Map (JSON)
{"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';\r\nimport { Component, Output, EventEmitter, HostListener, ChangeDetectionStrategy, input, computed } from '@angular/core';\r\n\r\nexport interface HexColor {\r\n color: ColorRGB | string;\r\n x: number | string;\r\n y: number | string;\r\n}\r\n\r\n@Component({\r\n selector: 'g[obl-hex-color]',\r\n templateUrl: './hex-color.component.html',\r\n styleUrls: ['./hex-color.component.scss'],\r\n changeDetection: ChangeDetectionStrategy.OnPush,\r\n standalone: false\r\n})\r\nexport class HexColorComponent {\r\n /** hex element ray */\r\n ray = input<number>(10);\r\n /** x pos can be css style like calc(50% + 10px) */\r\n x = input<number | string>(0);\r\n /** y pos can be css style like calc(50% + 10px) */\r\n y = input<number | string>(0);\r\n /** fill color as ColorRGB object or string color as one of:\r\n * #ffffff\r\n * rgb(255, 255, 255)\r\n * rgba(255, 255, 255, 0.5)\r\n * named color format, for example: red, blue, green ... */\r\n fill = input<ColorRGB | string>(new ColorRGB(0, 0, 0, 255));\r\n\r\n strokeWidth = input<number>(0);\r\n /** stroke color as ColorRGB object or string color as one of:\r\n * #ffffff\r\n * rgb(255, 255, 255)\r\n * rgba(255, 255, 255, 0.5)\r\n * named color format, for example: red, blue, green ... */\r\n strokeColor = input<ColorRGB | string>(new ColorRGB(0, 0, 0, 0));\r\n\r\n @Output() clicked: EventEmitter<HexColor> = new EventEmitter<HexColor>();\r\n\r\n protected fillHover = computed<ColorRGB | string>(() => typeof this.fill() === 'string' && this.fill() || (this.fill() as ColorRGB).multiply(0.8));\r\n\r\n hover = false;\r\n\r\n protected points = computed(() => this.recalc())\r\n\r\n @HostListener('click') onClick() {\r\n this.clicked.emit({\r\n color: this.fill(),\r\n x: this.x(),\r\n y: this.y()\r\n })\r\n }\r\n\r\n protected recalc() {\r\n const n = 6\r\n const offset = Math.PI / n;\r\n return new Array(n).fill(0).map((_, index: number) => {\r\n const angle = index * Math.PI / (n / 2) + offset;\r\n return [\r\n this.ray() * Math.sin(angle),\r\n this.ray() * Math.cos(angle)\r\n ].join(',')\r\n }).join(' ');\r\n }\r\n}\r\n","<svg:polygon\r\n [attr.points]=\"points()\"\r\n [style.transform]=\"'translate(' + x() + ', ' + y() + ')'\"\r\n [style.fill]=\"hover ? fillHover().toString() : fill().toString()\"\r\n [style.stroke]=\"strokeColor().toString()\"\r\n [style.strokeWidth]=\"strokeWidth()\"\r\n (mouseenter)=\"hover = true\"\r\n (mouseleave)=\"hover = false\"\r\n class=\"clickable\"\r\n></svg:polygon>\r\n","import { HexColor } from './../hex-color/hex-color.component';\r\nimport { ColorRGB, ColorHSV, Point2D } from '@obliczeniowo/elementary/classes';\r\nimport { Component, ChangeDetectionStrategy, input, computed, model } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'obl-hex-colors',\r\n templateUrl: './hex-colors.component.html',\r\n styleUrls: ['./hex-colors.component.scss'],\r\n changeDetection: ChangeDetectionStrategy.OnPush,\r\n standalone: false\r\n})\r\nexport class HexColorsComponent {\r\n /** hex element ray */\r\n ray = input(10, {\r\n transform: (value: number) => value < 5 ? 5 : value\r\n });\r\n\r\n /** Number of levels */\r\n rounds = input(6, {\r\n transform: (rounds: number) => rounds < 1 ? 1 : rounds\r\n }\r\n );\r\n\r\n /** color to select if exist on palette of colors */\r\n color = model<string>('#ffffff');\r\n\r\n protected width = computed<number>(() => (1.5 * (this.rounds() - 1) + 1) * this.ray() * 2 + 6);\r\n\r\n protected height = computed<number>(() => (this.h * (this.rounds() - 1) * 2 + this.h) * this.ray() * 2 + 6);\r\n\r\n readonly h = Math.sqrt(3) / 2;\r\n\r\n readonly rayTranslate = new Point2D(0, this.h * 2);\r\n readonly move = new Point2D(1.5, -this.h);\r\n\r\n elements = computed<{ pos: Point2D; color: ColorRGB }[]>(() => {\r\n const elements = [];\r\n\r\n elements.push({\r\n pos: new Point2D(),\r\n color: new ColorRGB(255, 255, 255, 255)\r\n });\r\n\r\n for (let dAngle = 0; dAngle < 6; dAngle++) {\r\n const angle = Math.PI / 3 * dAngle;\r\n for (let dRay = 1; dRay < this.rounds(); dRay++) {\r\n const total = 6 * dRay;\r\n const ray = this.rayTranslate.multiply(this.ray() * dRay).rotate(angle);\r\n for (let dMove = 0; dMove < dRay; dMove++) {\r\n const move = this.move.multiply(this.ray() * dMove).rotate(angle);\r\n elements.push({\r\n pos: ray.add(move),\r\n color: (\r\n ColorHSV.createColorHSV(\r\n 360 * (1 - (dAngle * dRay - dMove) / total),\r\n dRay / this.rounds(),\r\n 255\r\n )).convertToRGB()\r\n });\r\n }\r\n }\r\n }\r\n\r\n return elements;\r\n });\r\n\r\n strokeColor: ColorRGB | string = new ColorRGB(255, 255, 255, 255);\r\n\r\n selected = computed<undefined | HexColor>(() => {\r\n if (this.elements) {\r\n const found = this.elements().find(c => c.color.toString() === this.color());\r\n if (found) {\r\n return {\r\n x: `calc(50% + ${found.pos.x}px)`,\r\n y: `calc(50% + ${found.pos.y}px)`,\r\n color: found.color\r\n };\r\n }\r\n }\r\n return undefined;\r\n });\r\n\r\n selectedColor: ColorRGB = new ColorRGB(0, 0, 0);\r\n\r\n onChange(selected: HexColor) {\r\n this.color.set(selected.color.toString());\r\n }\r\n}\r\n","<svg [attr.width]=\"width()\" [attr.height]=\"height()\">\r\n @for (element of elements(); track $index) {\r\n <g\r\n obl-hex-color\r\n [x]=\"'calc(50% + ' + element.pos.x + 'px)'\"\r\n [y]=\"'calc(50% + ' + element.pos.y + 'px)'\"\r\n [fill]=\"element.color\"\r\n [strokeColor]=\"strokeColor\"\r\n [strokeWidth]=\"1\"\r\n [ray]=\"ray()\"\r\n (clicked)=\"onChange($event)\"\r\n ></g>\r\n }\r\n\r\n @if (selected()) {\r\n <g\r\n obl-hex-color\r\n [ray]=\"ray() + 1\"\r\n [x]=\"selected()!.x\"\r\n [y]=\"selected()!.y\"\r\n [fill]=\"'none'\"\r\n [strokeWidth]=\"6\"\r\n [strokeColor]=\"'white'\"\r\n ></g>\r\n <g\r\n obl-hex-color\r\n [ray]=\"ray()\"\r\n [x]=\"selected()!.x\"\r\n [y]=\"selected()!.y\"\r\n [fill]=\"'none'\"\r\n [strokeWidth]=\"1\"\r\n [strokeColor]=\"selectedColor\"\r\n ></g>\r\n }\r\n</svg>\r\n","import { NgModule } from '@angular/core';\r\nimport { CommonModule } from '@angular/common';\r\nimport { HexColorComponent } from './components/hex-color/hex-color.component';\r\nimport { HexColorsComponent } from './components/hex-colors/hex-colors.component';\r\n\r\n@NgModule({\r\n declarations: [\r\n HexColorComponent,\r\n HexColorsComponent\r\n ],\r\n imports: [\r\n CommonModule,\r\n ],\r\n exports: [\r\n HexColorsComponent\r\n ]\r\n})\r\nexport class HexColorModule { }\r\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,Q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