UNPKG

fabric

Version:

Object model for HTML5 canvas, and SVG-to-canvas parser. Backed by jsdom and node-canvas.

1 lines 4.43 kB
{"version":3,"file":"HueRotation.mjs","sources":["../../../src/filters/HueRotation.ts"],"sourcesContent":["import { cos } from '../util/misc/cos';\nimport { sin } from '../util/misc/sin';\nimport { ColorMatrix } from './ColorMatrix';\nimport type { TWebGLPipelineState, T2DPipelineState } from './typedefs';\nimport { classRegistry } from '../ClassRegistry';\n\nexport type HueRotationOwnProps = {\n rotation: number;\n};\n\nexport const hueRotationDefaultValues: HueRotationOwnProps = {\n rotation: 0,\n};\n\n/**\n * HueRotation filter class\n * @example\n * const filter = new HueRotation({\n * rotation: -0.5\n * });\n * object.filters.push(filter);\n * object.applyFilters();\n */\nexport class HueRotation extends ColorMatrix<\n 'HueRotation',\n HueRotationOwnProps\n> {\n /**\n * HueRotation value, from -1 to 1.\n */\n declare rotation: HueRotationOwnProps['rotation'];\n\n static type = 'HueRotation';\n\n static defaults = hueRotationDefaultValues;\n\n calculateMatrix() {\n const rad = this.rotation * Math.PI,\n cosine = cos(rad),\n sine = sin(rad),\n aThird = 1 / 3,\n aThirdSqtSin = Math.sqrt(aThird) * sine,\n OneMinusCos = 1 - cosine;\n this.matrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];\n this.matrix[0] = cosine + OneMinusCos / 3;\n this.matrix[1] = aThird * OneMinusCos - aThirdSqtSin;\n this.matrix[2] = aThird * OneMinusCos + aThirdSqtSin;\n this.matrix[5] = aThird * OneMinusCos + aThirdSqtSin;\n this.matrix[6] = cosine + aThird * OneMinusCos;\n this.matrix[7] = aThird * OneMinusCos - aThirdSqtSin;\n this.matrix[10] = aThird * OneMinusCos - aThirdSqtSin;\n this.matrix[11] = aThird * OneMinusCos + aThirdSqtSin;\n this.matrix[12] = cosine + aThird * OneMinusCos;\n }\n\n isNeutralState() {\n return this.rotation === 0;\n }\n\n applyTo(options: TWebGLPipelineState | T2DPipelineState) {\n this.calculateMatrix();\n super.applyTo(options);\n }\n\n //@ts-expect-error TS and classes with different methods\n toObject(): { type: 'HueRotation'; rotation: number } {\n return {\n type: this.type,\n rotation: this.rotation,\n };\n }\n}\n\nclassRegistry.setClass(HueRotation);\n"],"names":["hueRotationDefaultValues","rotation","HueRotation","ColorMatrix","calculateMatrix","rad","Math","PI","cosine","cos","sine","sin","aThird","aThirdSqtSin","sqrt","OneMinusCos","matrix","isNeutralState","applyTo","options","toObject","type","_defineProperty","classRegistry","setClass"],"mappings":";;;;;;AAUO,MAAMA,wBAA6C,GAAG;AAC3DC,EAAAA,QAAQ,EAAE,CAAA;AACZ,EAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,WAAW,SAASC,WAAW,CAG1C;AAUAC,EAAAA,eAAeA,GAAG;IAChB,MAAMC,GAAG,GAAG,IAAI,CAACJ,QAAQ,GAAGK,IAAI,CAACC,EAAE;AACjCC,MAAAA,MAAM,GAAGC,GAAG,CAACJ,GAAG,CAAC;AACjBK,MAAAA,IAAI,GAAGC,GAAG,CAACN,GAAG,CAAC;MACfO,MAAM,GAAG,CAAC,GAAG,CAAC;MACdC,YAAY,GAAGP,IAAI,CAACQ,IAAI,CAACF,MAAM,CAAC,GAAGF,IAAI;MACvCK,WAAW,GAAG,CAAC,GAAGP,MAAM,CAAA;AAC1B,IAAA,IAAI,CAACQ,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAC1E,IAAI,CAACA,MAAM,CAAC,CAAC,CAAC,GAAGR,MAAM,GAAGO,WAAW,GAAG,CAAC,CAA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