/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{CIMSymbolUnits as t}from"../../../../../../../symbols/cim/types.js";import{spritePadding as e,gradientTextureExternalPadding as r}from"../../../definitions.js";import{AFillMeshWriter as i}from"./AFillMeshWriter.js";import{fillVertexSpec as s}from"./FillMeshWriter.js";import{gradientFillMethods as a,bitset as o}from"./gradientFillConstants.js";import{getGradientSizeHelper as n}from"./GradientSizeHelper.js";import{getBitMask as l}from"./meshWriterUtils.js";import{DataType as c}from"../../../../../../webgl/enums.js";const p={createComputedParams:t=>t,optionalAttributes:s.optionalAttributes,attributes:{...s.attributes,bitset:{type:c.UNSIGNED_BYTE,count:1,pack:({gradientSizeUnits:e,gradientType:r})=>{let i=0;return e===t.Absolute&&(i|=l(o.isAbsolute)),"discrete"===r.toLowerCase()&&(i|=l(o.isDiscrete)),i}},tlbr:{count:4,type:c.UNSIGNED_SHORT,pack:({sprite:t})=>{const{rect:i,width:s,height:a}=t,o=i.x+e+r,n=i.y+e;return[o,n,o+s-2*r,n+a]}},relativePosition:{count:2,type:c.HALF_FLOAT,packTessellation:({gradientStats:t},e,r,i)=>t?.getRelativePosition(r,i)??[0,0]},relativeGradientSize:{count:2,type:c.HALF_FLOAT,packTessellation:({gradientStats:t})=>t?.relativeSize??[1,1]},gradientMethod:{count:1,type:c.UNSIGNED_BYTE,pack:({gradientMethod:t})=>{switch(t.toLowerCase()){case"rectangular":return a.rectangular;case"circular":return a.circular;default:return a.linear}}}}};class u extends i{constructor(){super(...arguments),this.vertexSpec=p}get _preventEffectClipping(){return!0}createTesselationParams(t){return{gradientStats:n(this._unclippedGeometry,this.evaluatedMeshParams)}}_write(t,e,r){const i=r?.asOptimized()??e.readGeometryForDisplay();this._unclippedGeometry=i;const s=this._clip(i);if(!s)return void(this._unclippedGeometry=null);const a=this.evaluatedMeshParams.sprite?.textureBinding;t.recordStart(this.instanceId,this.attributeLayout,a),this._writeGeometry(t,e,s),this._unclippedGeometry=null,t.recordEnd()}}export{u as GradientFillMeshWriter,p as gradientFillVertexSpec};
