import e from"../../utils/isStandardSyntaxComment.mjs";import t from"../../utils/isWhitespace.mjs";import s from"../../utils/report.mjs";import n from"../../utils/ruleMessages.mjs";import r from"../../utils/validateOptions.mjs";const i="comment-whitespace-inside",l=n(i,{expectedOpening:'Expected whitespace after "/*"',rejectedOpening:'Unexpected whitespace after "/*"',expectedClosing:'Expected whitespace before "*/"',rejectedClosing:'Unexpected whitespace before "*/"'});function a(e){e.text.startsWith("*")?e.text=e.text.replace(/^(\*+)/,"$1 "):e.raws.left=" "}function o(e){"*"===e.text[e.text.length-1]?e.text=e.text.replace(/(\*+)$/," $1"):e.raws.right=" "}const c=n=>(c,p)=>{r(p,i,{actual:n,possible:["always","never"]})&&c.walkComments(r=>{if(!e(r))return;const c=r.toString(),m=c.slice(0,4);if(/^\/\*[#!]\s/.test(m))return;const d=c.match(/(^\/\*+)(\s*)/);if(null==d||null==d[1])throw new Error(`Invalid comment: "${c}"`);const g=c.match(/(\s*)(\*+\/)$/);if(null==g||null==g[2])throw new Error(`Invalid comment: "${c}"`);const h=d[1],f=d[2]??"",u=f.charAt(0),x=g[1]??"",w=x.charAt(0),j=g[2];if("never"===n&&""!==u){const e=h.length,t=e+f.length;$(l.rejectedOpening,e,t)}if("always"!==n||t(u)||$(l.expectedOpening,h.length),"never"===n&&""!==w){const e=c.length-j.length,t=e-x.length;$(l.rejectedClosing,t,e)}function $(e,t,c=t){s({message:e,messageArgs:[],index:t,endIndex:c,result:p,ruleName:i,node:r,fix:{apply:()=>{if("never"===n)r.raws.left="",r.raws.right="",r.text=r.text.replace(/^(\*+)(\s+)?/,"$1").replace(/(\s+)?(\*+)$/,"$2");else{(e===l.expectedClosing?o:a)(r)}},node:r}})}"always"!==n||t(w)||$(l.expectedClosing,c.length-j.length-1)})};c.ruleName=i,c.messages=l,c.meta={url:"https://stylelint.io/user-guide/rules/comment-whitespace-inside",fixable:!0};export{c as default};