{"version":3,"file":"parser_template_helpers.js","sourceRoot":"","sources":["../../src/html/parser_template_helpers.ts"],"names":[],"mappings":";AAAA,0BAA0B;AAC1B,iFAAiF;AACjF,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;;AAWnB,kDAKC;AAED,kCAMC;AAED,0CAKC;AAuDD,wEAUC;AArFD,SAAgB,mBAAmB,CAAC,MAAc;IAChD,OAAO;QACL,MAAM;QACN,KAAK,EAAE,iBAAiB;KAChB,CAAA;AACZ,CAAC;AAED,SAAgB,WAAW,CAAC,MAA2B;IACrD,OAAO;QACL,MAAM;QACN,KAAK,EAAE,QAAQ;QACf,GAAG,MAAM;KACD,CAAA;AACZ,CAAC;AAED,SAAgB,eAAe,CAAC,MAAc;IAC5C,OAAO;QACL,MAAM;QACN,KAAK,EAAE,YAAY;KACX,CAAA;AACZ,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,KAAU;IACtC,6EAA6E;IAC7E,6EAA6E;IAC7E,8EAA8E;IAC9E,sCAAsC;IACtC,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7C,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC,IAAI,CAAA,GAAG,KAAK,EAAE,CAAA;IAC7B,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACxC,OAAO,EAAE,CAAA;IACX,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAA;IACzB,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,wBAAwB,CAAC,IAAY,EAAE,KAAe;IAC7D,iEAAiE;IACjE,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,OAAO,EAAE,CAAA;IACX,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;QACtC,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,IAAI,CAAA;QACb,CAAC;aAAM,CAAC;YACN,OAAO,EAAE,CAAA;QACX,CAAC;IACH,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC/F,OAAO,GAAG,IAAI,KAAK,KAAK,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAA;IACvF,CAAC;SAAM,IAAI,KAAK,CAAC,KAAK,KAAK,YAAY,EAAE,CAAC;QACxC,OAAO,GAAG,IAAI,KAAK,KAAK,CAAC,MAAM,GAAG,CAAA;IACpC,CAAC;SAAM,CAAC;QACN,+CAA+C;QAC/C,OAAO,GAAG,IAAI,2CAA2C,OAAO,KAAK,kBAAkB,CAAA;IACzF,CAAC;AACH,CAAC;AAED,SAAgB,8BAA8B;IAC5C,OAAO;QACL,mBAAmB;QACnB,WAAW;QACX,oBAAoB;QACpB,wBAAwB;QACxB,eAAe;KAChB;SACE,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC","sourcesContent":["/* istanbul ignore file */\n// This file needs to be ignored from code coverage, as Istanbul adds extra calls\n// to `cov_*` functions which are used to track coverage, but these functions\n// can't be resolved when executing the templates from the unit tests inside\n// `new Function()`\n\ndeclare const figma: { html: (template: TemplateStringsArray, ...args: any[]) => string }\n\nexport type FCCValue =\n | string\n | number\n | boolean\n | undefined\n | ReturnType\n\nexport function _fcc_templateString($value: string) {\n return {\n $value,\n $type: 'template-string',\n } as const\n}\n\nexport function _fcc_object($value: Record) {\n return {\n $value,\n $type: 'object',\n ...$value,\n } as const\n}\n\nexport function _fcc_identifier($value: string) {\n return {\n $value,\n $type: 'identifier',\n } as const\n}\n\n/**\n * Render a value to HTML, following sensible rules according to the type.\n *\n * @param value The value to render\n */\nfunction _fcc_renderHtmlValue(value: any): string {\n // If the value is an array, then it's an array of objects representing React\n // children (either of type INSTANCE for pills, or CODE for inline code). The\n // template string handler in the template API handles extracting the instance\n // objects in a way the UI can handle.\n const isComponentArray = Array.isArray(value)\n if (isComponentArray) {\n return figma.html`${value}`\n }\n\n if (typeof value === 'object') {\n return JSON.stringify(value)\n } else if (typeof value === 'undefined') {\n return ''\n } else {\n return value.toString()\n }\n}\n\n/**\n * Render a value as an HTML attribute. This renders as a string wrapped in\n * quotes, unless the value is a boolean, in which case we output just the\n * attribute name if the value is true, or nothing if the value is false or\n * undefined.\n *\n * @param name The name of the attribute\n * @param value The value of the attribute\n */\nfunction _fcc_renderHtmlAttribute(name: string, value: FCCValue) {\n // figma.boolean returns undefined instead of false in some cases\n if (typeof value === 'undefined') {\n return ''\n } else if (typeof value === 'boolean') {\n if (value) {\n return name\n } else {\n return ''\n }\n } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint') {\n return `${name}=\"${value.toString().replaceAll('\\n', '\\\\n').replaceAll('\"', '\\\\\"')}\"`\n } else if (value.$type === 'identifier') {\n return `${name}=\"${value.$value}\"`\n } else {\n // TODO make this show a proper error in the UI\n return `${name}=\"Code Connect Error: Unsupported type '${typeof value}' for attribute\"`\n }\n}\n\nexport function getParsedTemplateHelpersString() {\n return [\n _fcc_templateString,\n _fcc_object,\n _fcc_renderHtmlValue,\n _fcc_renderHtmlAttribute,\n _fcc_identifier,\n ]\n .map((fn) => fn.toString())\n .join('\\n')\n}\n"]}