{"version":3,"sources":["style.ts"],"sourcesContent":["import { getCallerFile } from \"datex-core-legacy/utils/caller_metadata.ts\";\nimport { Component } from \"../components/Component.ts\";\nimport { jsxInputGenerator } from \"./template.ts\";\n\n/**\n * \\@style decorator\n * \n * Can be used to define an inline style generator for a component:\n * \n * ```tsx\n * ;@style<{color:string}>(({color}) => SCSS `\n *   #main {\n *     background-color: ${color};\n *   }\n * `)\n * class MyComponent extends Component {...}\n * ```\n * @param styleGenerator \n */\nexport function style<\n\tOptions extends Record<string, any> = {}, \n\tChildren = JSX.childrenOrChildrenPromise|JSX.childrenOrChildrenPromise[], \n\tContext extends typeof HTMLElement = typeof HTMLElement\n>(\n\tstyleGenerator:jsxInputGenerator<CSSStyleSheet, Options, never, false, false, InstanceType<Context>>\n): jsxInputGenerator<CSSStyleSheet, Options, Children>&((cl: Context, context: ClassDecoratorContext<Context>)=>any)\n\n/**\n * \\@style decorator\n * \n * Can be used to define inline styles for a component:\n * \n * ```tsx\n * ;@style(SCSS `\n *   #main {\n *     background-color: magenta;\n *   }\n * `)\n * class MyComponent extends Component {...}\n * ```\n * @param styleGenerator \n */\nexport function style(...stylesheets:CSSStyleSheet[]):((cl:typeof HTMLElement, context: ClassDecoratorContext)=>any)\n\n/**\n * \\@style decorator\n * \n * Can be used to define an external style sheet for a component:\n *\n * ```tsx\n * ;@style(\"./my-style.scss\")\n * class MyComponent extends Component {...}\n * ```\n * @param styleGenerator \n */\nexport function style(file:string|URL):((cl:typeof HTMLElement, context: ClassDecoratorContext)=>any)\n\n\nexport function style(templateOrGenerator:string|URL|CSSStyleSheet|jsxInputGenerator<CSSStyleSheet, any, any, any>) {\n\tlet generator:any;\n\tconst module = getCallerFile();\n\n\tconst args = [...arguments]\n\n\t// string to url\n\tif (typeof templateOrGenerator == \"string\") templateOrGenerator = new URL(templateOrGenerator, module)\n\n\t// generator function\n\tif (typeof templateOrGenerator == \"function\") generator = function(propsOrClass:any, context?:any) {\n\t\t// decorator\n\t\tif (Component.isPrototypeOf(propsOrClass)) {\n\t\t\tpropsOrClass._init_module = module;\n\t\t\tif (!propsOrClass.style_templates) propsOrClass.style_templates = new Set()\n\t\t\tpropsOrClass.style_templates.add(generator)\n\t\t}\n\t\t// evaluate\n\t\telse {\n\t\t\tif (context && (templateOrGenerator as Function).call) return (templateOrGenerator as Function).call(context, propsOrClass, propsOrClass)\n\t\t\telse return (templateOrGenerator as Function)(propsOrClass, propsOrClass);\n\t\t}\n\t}\n\n\t// CSSStyleSheet or URL/string\n\telse generator = function (propsOrClass:any) {\n\n\t\t// decorator\n\t\tif (Component.isPrototypeOf(propsOrClass)) {\n\t\t\tpropsOrClass._init_module = module;\n\t\t\tif (!propsOrClass.style_templates) propsOrClass.style_templates = new Set()\n\t\t\tpropsOrClass.style_templates.add(generator)\n\t\t}\n\t\t// evaluate (use arguments because multiple stylesheets can be passed to @style)\n\t\telse {\n\t\t\treturn args as CSSStyleSheet[];\n\t\t}\n\t}\n\n\treturn generator;\n}"],"names":["getCallerFile","Component","style","templateOrGenerator","generator","module","args","arguments","URL","propsOrClass","context","isPrototypeOf","call","_init_module","style_templates","Set","add"],"mappings":"AAAA,SAASA,aAAa,QAAQ,6CAA6C;AAC3E,SAASC,SAAS,QAAQ,6BAA6B;AAyDvD,OAAO,SAASC,MAAMC,mBAA4F;QAC7GC;IACJ,IAAMC,SAASL,iBAETM,OAAO;WAAIC;KAAU;IAmC3B,OAhCkC,YAA9B,OAAOJ,uBAAiCA,CAAAA,sBAAsB,IAAIK,IAAIL,qBAAqBE,OAAM,GAGvDD,YAA1C,AAA8B,cAA9B,OAAOD,sBAA+C,SAASM,YAAgB,EAAEC,OAAY;QAEhG,KAAIT,UAAUU,aAAa,CAACF,sBAO3B,AAAIC,WAAW,AAACP,oBAAiCS,IAAI,GAAS,AAACT,oBAAiCS,IAAI,CAACF,SAASD,cAAcA,gBAChH,AAACN,oBAAiCM,cAAcA;QAP5DA,aAAaI,YAAY,GAAGR,QACvBI,aAAaK,eAAe,IAAEL,CAAAA,aAAaK,eAAe,GAAG,IAAIC,KAAI,GAC1EN,aAAaK,eAAe,CAACE,GAAG,CAACZ;IAOnC,IAGiB,SAAUK,YAAgB;QAG1C,KAAIR,UAAUU,aAAa,CAACF,eAO3B,OAAOH;QANPG,aAAaI,YAAY,GAAGR,QACvBI,aAAaK,eAAe,IAAEL,CAAAA,aAAaK,eAAe,GAAG,IAAIC,KAAI,GAC1EN,aAAaK,eAAe,CAACE,GAAG,CAACZ;IAMnC;AAGD","sourceRoot":"/lib/uix-0.4.39/src/html/","file":"style.ts"}