@qratilabs/qrati-connect 2.19.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/element/-uMLlqBc.js +2 -0
  3. package/element/ApyjFWKp.js +1 -0
  4. package/element/B4hg-Jzn.js +1 -0
  5. package/element/B8wY2BB-.js +3 -0
  6. package/element/BeYymwyj.js +4 -0
  7. package/element/CVV1-SpK.js +19 -0
  8. package/element/{B3PnczgW.js → CjX00Gkn.js} +3 -3
  9. package/element/CoFGfneL.js +1 -0
  10. package/element/Cx7fRstJ.js +3 -0
  11. package/element/DKsx0Y8e.js +1 -0
  12. package/element/DRvEkh_Q.js +8 -0
  13. package/element/DagK3kTO.js +1 -0
  14. package/element/DjmdQPk0.js +4 -0
  15. package/element/cP0JEJfS.js +8 -0
  16. package/element/h5ayNw6S.js +46 -0
  17. package/element/web.es.js +426 -421
  18. package/package.json +1 -1
  19. package/react/{BqXlcEUy.js → BNa8-_2x.js} +1 -1
  20. package/react/{B-2DDVYT.js → BWhJS_45.js} +1 -1
  21. package/react/{BquInWJV.js → BWxkj9As.js} +1 -1
  22. package/react/{A--57d8I.js → B_KzP4r-.js} +1 -1
  23. package/react/{DCXtW9qz.js → BdOUN6H_.js} +1 -1
  24. package/react/{DVXalHm5.js → BfQxUZ0J.js} +1 -1
  25. package/react/{DVSPOKgN.js → BgbYxvAG.js} +1 -1
  26. package/react/{EHEuvqs8.js → Bnv453PP.js} +1 -1
  27. package/react/{QvDJYu5_.js → C4byNc5q.js} +1 -1
  28. package/react/CS1Kg8-a.js +1 -0
  29. package/react/CWGMt62d.js +1 -0
  30. package/react/{BqkodWNb.js → CnvASFmW.js} +1 -1
  31. package/react/Cqdhu1W9.js +1 -0
  32. package/react/{jnuTAcnJ.js → CuZJVIKY.js} +1 -1
  33. package/react/{Dmc8pfx-.js → Cv1wuK5j.js} +1 -1
  34. package/react/{DVHopcEy.js → D16FFwT7.js} +1 -1
  35. package/react/{1jCdh7RC.js → DDAabcWl.js} +1 -1
  36. package/react/DI13WO77.js +1 -0
  37. package/react/{CybQW90i.js → DM06aQTo.js} +19 -11
  38. package/react/DSiikjS9.js +1 -0
  39. package/react/{CiT4o63a.js → DyMH2oz_.js} +1 -1
  40. package/react/K73cs4am.js +1 -0
  41. package/react/{BhV55-yN.js → KsnrAVz9.js} +1 -1
  42. package/react/RkYXaQ5u.js +1 -0
  43. package/react/{yv7A6fzU.js → f9e52Yxy.js} +1 -1
  44. package/react/index.cjs +1 -1
  45. package/react/index.mjs +117 -112
  46. package/react/{CPHleA8G.js → lh7wQOsu.js} +3 -3
  47. package/react/{DoEAn-0B.js → mnlJJuSr.js} +1 -1
  48. package/react/{Dk1n-dCc.js → smVbZ37h.js} +1 -1
  49. package/umd/web.umd.js +1 -1
  50. package/element/BJKp8z_Y.js +0 -2
  51. package/element/BWpGYu6o.js +0 -1
  52. package/element/C2wSnFgo.js +0 -3
  53. package/element/DF6wxpU6.js +0 -8
  54. package/element/DQpZuO_g.js +0 -38
  55. package/element/DeIGxYF9.js +0 -8
  56. package/element/DqcL5k27.js +0 -4
  57. package/element/cFiX5XpH.js +0 -3
  58. package/element/iwsjnFxy.js +0 -4
  59. package/element/s-uFfVs8.js +0 -19
  60. package/react/YdJqOiJV.js +0 -1
  61. /package/element/{CMbOX_GS.js → BAMB7Uoo.js} +0 -0
  62. /package/element/{C6TX_i0I.js → BzIJspY1.js} +0 -0
  63. /package/element/{DgGPkDRT.js → CjmNvKgB.js} +0 -0
  64. /package/element/{BxbCvlCo.js → D1zX23l-.js} +0 -0
  65. /package/element/{CzSmu5XM.js → DUJAMyRv.js} +0 -0
  66. /package/element/{CIcND0Dg.js → PPVqva_9.js} +0 -0
  67. /package/element/{Cdux6g1i.js → tPk8Ov5I.js} +0 -0
  68. /package/react/{Cdux6g1i.js → BJ85RnFv.js} +0 -0
  69. /package/react/{BvVjd_UK.js → Bp3BRlhW.js} +0 -0
  70. /package/react/{BCc5Yj_f.js → BszowxAR.js} +0 -0
  71. /package/react/{BH8UJKb5.js → BtTYXVAR.js} +0 -0
  72. /package/react/{DJTeOMQR.js → BvT0jQ3V.js} +0 -0
  73. /package/react/{BAKN93OB.js → Byq3TC8k.js} +0 -0
  74. /package/react/{qy2OAEht.js → C5dmblnS.js} +0 -0
  75. /package/react/{fwmxAw7l.js → D2h6qyms.js} +0 -0
  76. /package/react/{DlCuoz_e.js → D7BzZEsL.js} +0 -0
  77. /package/react/{C8D6WaBQ.js → DSaIeQ30.js} +0 -0
  78. /package/react/{DiysJlOc.js → DYeIUbVU.js} +0 -0
  79. /package/react/{I7IwY3sd.js → Y-mDLYqW.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## [2.19.1](https://github.com/qrati-labs/qrati-connect-ts/compare/v2.19.0...v2.19.1) (2026-05-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add padding to EventCard component for improved layout ([6dd6725](https://github.com/qrati-labs/qrati-connect-ts/commit/6dd6725002821d0aefa6b759acdcc2b737cde0d4))
7
+ * update sidebar references to right for consistency in layout and configuration ([7868cbf](https://github.com/qrati-labs/qrati-connect-ts/commit/7868cbf78af137bbb14fe46f2f5c4ade71dc581f))
8
+
9
+ # [2.19.0](https://github.com/qrati-labs/qrati-connect-ts/compare/v2.18.0...v2.19.0) (2026-05-12)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * uncomment localized login button for improved accessibility ([cfbb22a](https://github.com/qrati-labs/qrati-connect-ts/commit/cfbb22a9664a3b8d49fd662a9ce68936294591a6))
15
+
16
+
17
+ ### Features
18
+
19
+ * add Mapbox and Maplibre CSS imports for improved styling in map components ([6c71f13](https://github.com/qrati-labs/qrati-connect-ts/commit/6c71f133b74ed03942db7afd51ddd921572ae313))
20
+
1
21
  # [2.18.0](https://github.com/qrati-labs/qrati-connect-ts/compare/v2.17.0...v2.18.0) (2026-05-12)
2
22
 
3
23
 
@@ -0,0 +1,2 @@
1
+ import{g as t,j as e,o as r,t as o,w as n,y as s}from"./CoFGfneL.js";import{h as a}from"./h5ayNw6S.js";var i=({as:e="div",className:r,threshold:s=.5,rootMargin:a="0px",triggerOnce:i,onChange:l,onClick:h,children:c})=>{const u=t(null),d=t(!1);return n(()=>{const t=u.current;if(!t)return;const e=new IntersectionObserver(t=>{t.forEach(t=>{i&&d.current||(t.isIntersecting&&(d.current=!0),l?.(t.isIntersecting))})},{threshold:s,rootMargin:a});return e.observe(t),()=>e.disconnect()},[s,a,l,i]),/* @__PURE__ */o(e,{ref:u,className:r,onClick:h,children:c})},l=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","*","+",",","-",".",":",";","=","?","@","[","]","^","_","{","|","}","~"],h=t=>{let e=0;for(let r=0;r<t.length;r++){let o=t[r];e=83*e+l.indexOf(o)}return e},c=t=>{let e=t/255;return e<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)},u=t=>{let e=Math.max(0,Math.min(1,t));return e<=.0031308?Math.trunc(12.92*e*255+.5):Math.trunc(255*(1.055*Math.pow(e,.4166666666666667)-.055)+.5)},d=(t,e)=>(t=>t<0?-1:1)(t)*Math.pow(Math.abs(t),e),p=class extends Error{constructor(t){super(t),this.name="ValidationError",this.message=t}},f=t=>{let e=t>>8&255,r=255&t;return[c(t>>16),c(e),c(r)]},g=(t,e)=>{let r=Math.floor(t/361),o=Math.floor(t/19)%19,n=t%19;return[d((r-9)/9,2)*e,d((o-9)/9,2)*e,d((n-9)/9,2)*e]},m=(t,e,r,o)=>{(t=>{if(!t||t.length<6)throw new p("The blurhash string must be at least 6 characters");let e=h(t[0]),r=Math.floor(e/9)+1,o=e%9+1;if(t.length!==4+2*o*r)throw new p(`blurhash length mismatch: length is ${t.length} but it should be ${4+2*o*r}`)})(t),o|=1;let n=h(t[0]),s=Math.floor(n/9)+1,a=n%9+1,i=(h(t[1])+1)/166,l=new Array(a*s);for(let u=0;u<l.length;u++)l[u]=0===u?f(h(t.substring(2,6))):g(h(t.substring(4+2*u,6+2*u)),i*o);let c=4*e,d=new Uint8ClampedArray(c*r);for(let h=0;h<r;h++)for(let t=0;t<e;t++){let o=0,n=0,i=0;for(let c=0;c<s;c++)for(let s=0;s<a;s++){let u=Math.cos(Math.PI*t*s/e)*Math.cos(Math.PI*h*c/r),d=l[s+c*a];o+=d[0]*u,n+=d[1]*u,i+=d[2]*u}let p=u(o),f=u(n),g=u(i);d[4*t+0+h*c]=p,d[4*t+1+h*c]=f,d[4*t+2+h*c]=g,d[4*t+3+h*c]=255}return d},b=Object.defineProperty,w=Object.defineProperties,v=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,O=(t,e,r)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,x=(t,e)=>{for(var r in e||(e={}))M.call(e,r)&&O(t,r,e[r]);if(y)for(var r of y(e))j.call(e,r)&&O(t,r,e[r]);return t},C=(t,e)=>w(t,v(e)),P=(t,e)=>{var r={};for(var o in t)M.call(t,o)&&e.indexOf(o)<0&&(r[o]=t[o]);if(null!=t&&y)for(var o of y(t))e.indexOf(o)<0&&j.call(t,o)&&(r[o]=t[o]);return r},I=class extends r{constructor(){super(...arguments),this.canvas=null,this.handleRef=t=>{this.canvas=t,this.draw()},this.draw=()=>{let{hash:t,height:e,punch:r,width:o}=this.props;if(this.canvas){let n=m(t,o,e,r),s=this.canvas.getContext("2d"),a=s.createImageData(o,e);a.data.set(n),s.putImageData(a,0,0)}}}componentDidUpdate(){this.draw()}render(){let t=this.props,{hash:r,height:o,width:n}=t,s=P(t,["hash","height","width"]);return e("canvas",C(x({},s),{height:o,width:n,ref:this.handleRef}))}};I.defaultProps={height:128,width:128};var N={position:"absolute",top:0,bottom:0,left:0,right:0,width:"100%",height:"100%"};(class extends r{componentDidUpdate(){if(this.props.resolutionX<=0)throw new Error("resolutionX must be larger than zero");if(this.props.resolutionY<=0)throw new Error("resolutionY must be larger than zero")}render(){let t=this.props,{hash:r,height:o,width:n,punch:s,resolutionX:a,resolutionY:i,style:l}=t,h=P(t,["hash","height","width","punch","resolutionX","resolutionY","style"]);return e("div",C(x({},h),{style:C(x({display:"inline-block",height:o,width:n},l),{position:"relative"})}),e(I,{hash:r,height:i,width:a,punch:s,style:N}))}}).defaultProps={height:128,width:128,resolutionX:32,resolutionY:32};var k=I,E=({src:e,alt:r,threshold:l=.1,rootMargin:h="200px 0px",blurhash:c,containerClassName:u="size-full",wrapperClassName:d,imgClassName:p="",sizeMode:f="cover",position:g="center",delayMs:m=100,delayTime:b,onClick:w})=>{const v=c&&c.length>=6?c:"LEHV6nWB2yk8pyo0adR*.7kCMdnj",[y,M]=s(!1),[j,O]=s(!1),[x,C]=s(!1),P=t(null),I="number"==typeof b?b:m,N=d??u;n(()=>{if(!y)return x?P.current=window.setTimeout(()=>{O(!0)},I):P.current&&(clearTimeout(P.current),P.current=null),()=>{P.current&&clearTimeout(P.current)}},[x,y,I]);const E=j&&x||y;/* @__PURE__ */
2
+ return o(i,{as:"div",className:a(N,"relative overflow-hidden"),threshold:l,rootMargin:h,onChange:t=>C(t),children:[!y&&/* @__PURE__ */o(k,{className:"size-full blur-2xl",hash:v}),E&&e&&/* @__PURE__ */o("img",{alt:r,src:e,onLoad:()=>M(!0),className:a("absolute top-0 left-0 size-full object-center transition-all duration-300",y?"scale-100 opacity-100":"scale-95 opacity-0","contain"===f?"object-contain":"object-cover","top"===g?"object-top":"bottom"===g?"object-bottom":"object-center",p),onClick:t=>w?.(t)})]})};export{m as n,i as r,E as t};
@@ -0,0 +1 @@
1
+ import{r as e}from"./hOIsfHC7.js";var n=[{id:"underwater-correction",name:"Underwater Color Correction",description:"Reference underwater correction filter using hue-shifted red histogram normalization",category:"color-correction",script:"-- Underwater Color Correction\nfunction getColorMatrix(stats, pixels, width, height)\n local numOfPixels = width * height\n local thresholdRatio = 2000\n local thresholdLevel = numOfPixels / thresholdRatio\n local minAvgRed = 60\n local maxHueShift = 120\n local blueMagicValue = 1.2\n\n local hist = { r = {}, g = {}, b = {} }\n local normalize = { r = {}, g = {}, b = {} }\n local adjust = { r = {}, g = {}, b = {} }\n local hueShift = 0\n\n for i = 0, 255 do\n hist.r[i] = 0\n hist.g[i] = 0\n hist.b[i] = 0\n end\n\n local avg = calculateAverageColor(pixels, width, height)\n\n local newAvgRed = avg.r\n while newAvgRed < minAvgRed do\n local shifted = hueShiftRed(avg.r, avg.g, avg.b, hueShift)\n newAvgRed = shifted.r + shifted.g + shifted.b\n hueShift = hueShift + 1\n if hueShift > maxHueShift then\n newAvgRed = 60\n end\n end\n\n for y = 0, height - 1 do\n for x = 0, width * 4 - 4, 4 do\n local pos = x + (width * 4) * y\n\n local red = math.floor((pixels[pos] or 0) + 0.5)\n local green = math.floor((pixels[pos + 1] or 0) + 0.5)\n local blue = math.floor((pixels[pos + 2] or 0) + 0.5)\n\n local shifted = hueShiftRed(red, green, blue, hueShift)\n red = shifted.r + shifted.g + shifted.b\n red = math.min(255, math.max(0, red))\n red = math.floor(red + 0.5)\n\n hist.r[red] = (hist.r[red] or 0) + 1\n hist.g[green] = (hist.g[green] or 0) + 1\n hist.b[blue] = (hist.b[blue] or 0) + 1\n end\n end\n\n normalize.r[#normalize.r + 1] = 0\n normalize.g[#normalize.g + 1] = 0\n normalize.b[#normalize.b + 1] = 0\n\n for i = 0, 255 do\n if (hist.r[i] or 0) - thresholdLevel < 2 then normalize.r[#normalize.r + 1] = i end\n if (hist.g[i] or 0) - thresholdLevel < 2 then normalize.g[#normalize.g + 1] = i end\n if (hist.b[i] or 0) - thresholdLevel < 2 then normalize.b[#normalize.b + 1] = i end\n end\n\n normalize.r[#normalize.r + 1] = 255\n normalize.g[#normalize.g + 1] = 255\n normalize.b[#normalize.b + 1] = 255\n\n adjust.r = normalizingInterval(normalize.r)\n adjust.g = normalizingInterval(normalize.g)\n adjust.b = normalizingInterval(normalize.b)\n\n local shifted = hueShiftRed(1, 1, 1, hueShift)\n\n local redGain = 256 / (adjust.r.high - adjust.r.low)\n local greenGain = 256 / (adjust.g.high - adjust.g.low)\n local blueGain = 256 / (adjust.b.high - adjust.b.low)\n\n local redOffset = (-adjust.r.low / 256) * redGain\n local greenOffset = (-adjust.g.low / 256) * greenGain\n local blueOffset = (-adjust.b.low / 256) * blueGain\n\n local adjstRed = shifted.r * redGain\n local adjstRedGreen = shifted.g * redGain\n local adjstRedBlue = shifted.b * redGain * blueMagicValue\n\n return {\n adjstRed, adjstRedGreen, adjstRedBlue, 0, redOffset,\n 0, greenGain, 0, 0, greenOffset,\n 0, 0, blueGain, 0, blueOffset,\n 0, 0, 0, 1, 0,\n }\nend\n\nfunction calculateAverageColor(pixels, width, height)\n local avg = { r = 0, g = 0, b = 0 }\n\n for y = 0, height - 1 do\n for x = 0, width * 4 - 4, 4 do\n local pos = x + (width * 4) * y\n avg.r = avg.r + (pixels[pos] or 0)\n avg.g = avg.g + (pixels[pos + 1] or 0)\n avg.b = avg.b + (pixels[pos + 2] or 0)\n end\n end\n\n avg.r = avg.r / (width * height)\n avg.g = avg.g / (width * height)\n avg.b = avg.b / (width * height)\n\n return avg\nend\n\nfunction hueShiftRed(r, g, b, h)\n local U = math.cos(h * math.pi / 180)\n local W = math.sin(h * math.pi / 180)\n\n r = (0.299 + 0.701 * U + 0.168 * W) * r\n g = (0.587 - 0.587 * U + 0.330 * W) * g\n b = (0.114 - 0.114 * U - 0.497 * W) * b\n\n return { r = r, g = g, b = b }\nend\n\nfunction normalizingInterval(normArray)\n local high = 255\n local low = 0\n local maxDist = 0\n\n for i = 2, #normArray do\n local dist = normArray[i] - normArray[i - 1]\n if dist > maxDist then\n maxDist = dist\n high = normArray[i]\n low = normArray[i - 1]\n end\n end\n\n return { low = low, high = high }\nend",defaultVariables:{},variableSchema:[]},{id:"vignette",name:"Vignette Effect",description:"Darken image corners for dramatic effect",category:"stylistic",script:"-- Vignette Effect\n-- Darkens corners of the image\n\nfunction processPixel(r, g, b, a, x, y, width, height)\n -- Calculate distance from center (normalized 0-1)\n local cx = width / 2\n local cy = height / 2\n local dx = (x - cx) / cx\n local dy = (y - cy) / cy\n local distance = math.sqrt(dx * dx + dy * dy)\n\n -- Vignette strength\n local strength = vignette_strength or 0.5\n local radius = vignette_radius or 0.8\n\n -- Calculate vignette factor\n local factor = 1.0\n if distance > radius then\n factor = 1.0 - ((distance - radius) / (1 - radius)) * strength\n factor = math.max(0.2, factor) -- Don't go completely black\n end\n\n -- Apply vignette\n r = r * factor\n g = g * factor\n b = b * factor\n\n return r, g, b, a\nend",defaultVariables:{vignette_strength:.5,vignette_radius:.7},variableSchema:[{key:"vignette_strength",type:"number",label:"Vignette strength",min:0,max:1,step:.05,default:.5},{key:"vignette_radius",type:"number",label:"Vignette radius",min:0,max:1,step:.05,default:.7}]},{id:"sepia",name:"Sepia Tone",description:"Apply warm sepia tone for vintage look",category:"stylistic",script:"-- Sepia Tone\n-- Applies vintage sepia coloring\n\nfunction processPixel(r, g, b, a, x, y, width, height)\n local intensity = sepia_intensity or 1.0\n\n -- Convert to grayscale first\n local gray = (r * 0.299 + g * 0.587 + b * 0.114)\n\n -- Apply sepia tone\n local newR = math.min(255, gray + (40 * intensity))\n local newG = math.min(255, gray + (20 * intensity))\n local newB = math.max(0, gray - (30 * intensity))\n\n -- Blend with original based on intensity\n r = r * (1 - intensity) + newR * intensity\n g = g * (1 - intensity) + newG * intensity\n b = b * (1 - intensity) + newB * intensity\n\n return r, g, b, a\nend",defaultVariables:{sepia_intensity:.8},variableSchema:[{key:"sepia_intensity",type:"number",label:"Sepia intensity",min:0,max:1,step:.05,default:.8}]},{id:"auto-white-balance",name:"Auto White Balance",description:"Simple grey-world white balance algorithm",category:"color-correction",script:"-- Auto White Balance (Grey World)\n-- Assumes average color of image should be grey\n-- Note: This is a simplified version\n\nfunction processPixel(r, g, b, a, x, y, width, height)\n -- These would ideally be calculated from image histogram\n -- For per-pixel processing, we use approximate multipliers\n local avgR = avg_red or 128\n local avgG = avg_green or 128\n local avgB = avg_blue or 128\n\n -- Calculate gain to make averages equal\n local avgGray = (avgR + avgG + avgB) / 3\n\n if avgR > 0 then\n r = math.min(255, r * (avgGray / avgR))\n end\n if avgG > 0 then\n g = math.min(255, g * (avgGray / avgG))\n end\n if avgB > 0 then\n b = math.min(255, b * (avgGray / avgB))\n end\n\n return r, g, b, a\nend",defaultVariables:{avg_red:128,avg_green:128,avg_blue:128},variableSchema:[{key:"avg_red",type:"number",label:"Average red",min:1,max:255,step:1,default:128},{key:"avg_green",type:"number",label:"Average green",min:1,max:255,step:1,default:128},{key:"avg_blue",type:"number",label:"Average blue",min:1,max:255,step:1,default:128}]},{id:"custom-script",name:"Custom Script",description:"Start with a blank template",category:"custom",script:"-- Custom Filter Script\n-- Available: math functions, pixel coordinates\n-- Input: r, g, b, a (0-255), x, y, width, height\n-- Output: r, g, b, a\n\nfunction processPixel(r, g, b, a, x, y, width, height)\n -- Your custom logic here\n -- Example: Invert colors\n -- r = 255 - r\n -- g = 255 - g\n -- b = 255 - b\n\n return r, g, b, a\nend",defaultVariables:{},variableSchema:[]}],a={"Underwater Color Correction":"underwater-correction"};function t(e,t){const r=function(e,n){return e.templateId?e.templateId:n?a[n]:void 0}(e,t);if(!r)return e;const i=(l=r,n.find(e=>e.id===l));var l;return i?{...e,templateId:r,script:i.script,variables:{...i.defaultVariables,...e.variables||{}}}:e}var r=800;async function i(n,a,t){const r=await import("./B4hg-Jzn.js").then(n=>/* @__PURE__ */e(n.default,1)),{lua:i,lauxlib:l,lualib:o}=r,s=r.to_luastring,u=l.luaL_newstate();if(o.luaL_openlibs(u),function(e,n,a,t){const r=a.to_luastring;for(const i of["io","os","package","debug","load","loadfile","dofile","require"])n.lua_pushnil(e),n.lua_setglobal(e,r(i));n.lua_pushjsfunction(e,()=>0),n.lua_setglobal(e,r("print"));for(const[i,l]of Object.entries(t)){if("number"==typeof l)n.lua_pushnumber(e,l);else if("string"==typeof l)n.lua_pushstring(e,r(l));else{if("boolean"!=typeof l)continue;n.lua_pushboolean(e,l?1:0)}n.lua_setglobal(e,r(i))}}(u,i,r,a),l.luaL_dostring(u,s(n))!==i.LUA_OK){const e=i.lua_tojsstring(u,-1);return i.lua_close(u),{data:t,error:`Load error: ${e}`}}i.lua_getglobal(u,s("getColorMatrix"));const h=i.lua_isfunction(u,-1);if(i.lua_pop(u,1),h){const e=function(e){const{data:n,width:a,height:t}=e,r=a*t,i=new Array(256).fill(0),l=new Array(256).fill(0),o=new Array(256).fill(0),s=new Array(256).fill(0);let u=0,h=0,g=0,c=0;for(let d=0;d<n.length;d+=4)i[n[d]]++,l[n[d+1]]++,o[n[d+2]]++,s[n[d+3]]++,u+=n[d],h+=n[d+1],g+=n[d+2],c+=n[d+3];return{averages:{r:u/r,g:h/r,b:g/r,a:c/r},histograms:{r:i,g:l,b:o,a:s}}}(t);if(i.lua_getglobal(u,s("getColorMatrix")),function(e,n,a,t){n.lua_createtable(e,0,2),n.lua_pushstring(e,a("averages")),n.lua_createtable(e,0,4);for(const[r,i]of Object.entries(t.averages))n.lua_pushstring(e,a(r)),n.lua_pushnumber(e,i),n.lua_settable(e,-3);n.lua_settable(e,-3),n.lua_pushstring(e,a("histograms")),n.lua_createtable(e,0,4);for(const[r,i]of Object.entries(t.histograms))n.lua_pushstring(e,a(r)),n.lua_createtable(e,i.length,0),i.forEach((a,t)=>{n.lua_pushnumber(e,t),n.lua_pushnumber(e,a),n.lua_settable(e,-3)}),n.lua_settable(e,-3);n.lua_settable(e,-3)}(u,i,s,e),function(e,n,a){n.lua_createtable(e,a.data.length,0),a.data.forEach((a,t)=>{n.lua_pushnumber(e,t),n.lua_pushnumber(e,a),n.lua_settable(e,-3)})}(u,i,t),i.lua_pushnumber(u,t.width),i.lua_pushnumber(u,t.height),i.lua_pcall(u,4,1,0)!==i.LUA_OK){const e=i.lua_tojsstring(u,-1);return i.lua_close(u),{data:t,error:`Runtime error: ${e}`}}const n=function(e,n){const a=[];n.lua_rawgeti(e,-1,1);const t=n.lua_type(e,-1)===n.LUA_TNUMBER;if(n.lua_pop(e,1),t){for(let t=0;t<4;t++){const r=[];for(let a=0;a<5;a++)n.lua_rawgeti(e,-1,5*t+a+1),r.push(n.lua_tonumber(e,-1)),n.lua_pop(e,1);a.push(r)}return a}for(let r=0;r<4;r++){n.lua_rawgeti(e,-1,r+1);const t=[];for(let a=0;a<5;a++)n.lua_rawgeti(e,-1,a+1),t.push(n.lua_tonumber(e,-1)),n.lua_pop(e,1);a.push(t),n.lua_pop(e,1)}return a}(u,i);i.lua_pop(u,1),i.lua_close(u);const{data:a,width:r,height:l}=t,o=new Uint8ClampedArray(a.length),[h,g,c,d,m]=n[0],[f,p,b,v,_]=n[1],[w,y,x,R,A]=n[2],[M,j,z,S,G]=n[3];for(let t=0;t<a.length;t+=4){const e=a[t],n=a[t+1],r=a[t+2],i=a[t+3];o[t]=Math.min(255,Math.max(0,Math.round(h*e+g*n+c*r+d*i+255*m))),o[t+1]=Math.min(255,Math.max(0,Math.round(f*e+p*n+b*r+v*i+255*_))),o[t+2]=Math.min(255,Math.max(0,Math.round(w*e+y*n+x*r+R*i+255*A))),o[t+3]=Math.min(255,Math.max(0,Math.round(M*e+j*n+z*r+S*i+255*G)))}return{data:new ImageData(o,r,l)}}i.lua_getglobal(u,s("processPixel"));const g=i.lua_isfunction(u,-1);if(i.lua_pop(u,1),!g)return i.lua_close(u),{data:t,error:"Script must define one of: processPixel(r,g,b,a,x,y,w,h), processImage(ctx, stats), or getColorMatrix(ctx, stats)"};const{data:c,width:d,height:m}=t,f=new Uint8ClampedArray(c.length),p=Date.now();for(let e=0;e<c.length;e+=4){if(e%(40*d)==0&&Date.now()-p>2e4)return i.lua_close(u),{data:t,error:"Execution timeout"};const n=e/4,a=n%d,r=Math.floor(n/d);if(i.lua_getglobal(u,s("processPixel")),i.lua_pushnumber(u,c[e]),i.lua_pushnumber(u,c[e+1]),i.lua_pushnumber(u,c[e+2]),i.lua_pushnumber(u,c[e+3]),i.lua_pushnumber(u,a),i.lua_pushnumber(u,r),i.lua_pushnumber(u,d),i.lua_pushnumber(u,m),i.lua_pcall(u,8,4,0)!==i.LUA_OK){const e=i.lua_tojsstring(u,-1);return i.lua_close(u),{data:t,error:`Runtime error at pixel ${n}: ${e}`}}const l=i.lua_tonumber(u,-1),o=i.lua_tonumber(u,-2),h=i.lua_tonumber(u,-3),g=i.lua_tonumber(u,-4);i.lua_pop(u,4),f[e]=Math.min(255,Math.max(0,Math.round(g))),f[e+1]=Math.min(255,Math.max(0,Math.round(h))),f[e+2]=Math.min(255,Math.max(0,Math.round(o))),f[e+3]=Math.min(255,Math.max(0,Math.round(l)))}return i.lua_close(u),{data:new ImageData(f,d,m)}}async function l(e,n){const a=Date.now(),l=[],o=[],{canvas:s,w:u,h:h}=function(e){let n=e.naturalWidth,a=e.naturalHeight;if(n>r||a>r){const e=Math.min(r/n,r/a);n=Math.round(n*e),a=Math.round(a*e)}const t=document.createElement("canvas");return t.width=n,t.height=a,t.getContext("2d").drawImage(e,0,0,n,a),{canvas:t,w:n,h:a}}(await function(e){return new Promise((n,a)=>{const t=new Image,r=URL.createObjectURL(e);t.onload=()=>{URL.revokeObjectURL(r),n(t)},t.onerror=()=>{URL.revokeObjectURL(r),a(/* @__PURE__ */new Error("Failed to load image"))},t.src=r})}(e)),g=s.toDataURL("image/jpeg",.92),c=document.createElement("canvas");c.width=u,c.height=h;const d=c.getContext("2d");d.drawImage(s,0,0);const m=n.filter(e=>e.enabled);for(const r of m){const e=t(r.config,r.name);if(!e?.script){o.push({id:r.id,error:"No Lua script provided"});continue}const n=d.getImageData(0,0,u,h),{data:a,error:s}=await i(e.script,e.variables||{},n);s?o.push({id:r.id,error:s}):(d.putImageData(a,0,0),l.push(r.id))}return{original:g,processed:c.toDataURL("image/jpeg",.92),appliedFilters:l,failedFilters:o,totalExecutionTime:Date.now()-a}}export{l as runClientLuaPreview};