import BaseDrawing from"../../../common/documents/drawing.mjs";import ServerDocumentMixin from"../backend/server-document.mjs";import{setProperty}from"../../../common/utils/_module.mjs";export default class Drawing extends(ServerDocumentMixin(BaseDrawing)){static _migrationRegistry=[...super._migrationRegistry,{fn:migrateV10Fields,version:12},{fn:migrateNullValues,version:12},{fn:migrateZToElevation,version:12},{fn:migrateInterface,version:"12.317"},{fn:migrateInvisible,version:"13.351"}]}function migrateV10Fields(e){const t={t:"r",f:"p"},i=Drawing._addDataFieldMigration(e,"type","shape.type",e=>t[e.type]??e.type),r=Drawing._addDataFieldMigration(e,"width","shape.width"),n=Drawing._addDataFieldMigration(e,"height","shape.height"),a=Drawing._addDataFieldMigration(e,"points","shape.points",e=>Array.isArray(e.points)?e.points.flat():e.points);return i||r||n||a}function migrateNullValues(e){let t=!1;return null===e.fillColor&&(e.fillColor="#ffffff",t=!0),null===e.fontSize&&(e.fontSize=48,t=!0),null===e.strokeColor&&(e.strokeColor="#ffffff",t=!0),null===e.strokeWidth&&(e.strokeWidth=0,t=!0),null===e.textColor&&(e.textColor="#ffffff",t=!0),t}function migrateInvisible(e){let t=!1,{text:i,textAlpha:r,fillType:n,fillAlpha:a,strokeWidth:o,strokeAlpha:s}=e;i??="",r??=1,n??=CONST.DRAWING_FILL_TYPES.NONE,a??=1,o??=8,s??=1;const l=""!==i&&r>0,f=n!==CONST.DRAWING_FILL_TYPES.NONE&&a>0;l||f||o>0&&s>0||(e.strokeWidth=o=8,e.strokeColor="#ffffff",e.strokeAlpha=1,t=!0);let{type:p,width:d,height:h,radius:g,points:u}=e.shape??{};switch(p??="r",d??=null,h??=null,g??=null,u??=[],p){case"r":case"e":d<=o&&(d=o+1,setProperty(e,"shape.width",o+1),t=!0),h<=o&&(setProperty(e,"shape.height",o+1),t=!0);break;case"p":if(0===d&&0===h&&(d=1,setProperty(e,"shape.width",d),t=!0),u.length<2)setProperty(e,"shape.points",[0,0,1,0]),t=!0;else if(u.length<4){const[i,r]=u;setProperty(e,"shape.points",[i,r,i+1,r]),t=!0}break;case"c":g<=o/2&&(setProperty(e,"shape.radius",o/2+1),t=!0)}return t}function migrateZToElevation(e){return Drawing._addDataFieldMigration(e,"z","elevation")}function migrateInterface(e){return e.interface=!!e.text,!0}