"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { customElementJetBrainsPlugin: () => customElementJetBrainsPlugin, generateJetBrainsWebTypes: () => generateJetBrainsWebTypes, getWebTypesData: () => getWebTypesData }); module.exports = __toCommonJS(src_exports); // src/web-types-generator.ts var import_fs2 = __toESM(require("fs"), 1); // ../../tools/utilities/src/utilities.ts var toKebabCase = (value) => value.replace(/([a-z0–9])([A-Z])/g, "$1-$2").toLowerCase(); function has(arr) { return Array.isArray(arr) && arr.length > 0; } // ../../tools/cem-utils/src/cem-utilities.ts function getComponentDescription(component, descriptionSrc) { var _a; let description = ((_a = descriptionSrc ? component[descriptionSrc] : component.summary || component.description) == null ? void 0 : _a.replace(/\\n/g, "\n")) || ""; if (component.deprecated) { const deprecation = typeof component.deprecated === "string" ? `@deprecated ${component.deprecated}` : "@deprecated"; description = `${deprecation} ${description}`; } return description; } function getComponents(customElementsManifest, exclude) { var _a; return (((_a = customElementsManifest.modules) == null ? void 0 : _a.map( (mod) => { var _a2; return ((_a2 = mod == null ? void 0 : mod.declarations) == null ? void 0 : _a2.filter( (dec) => !(exclude == null ? void 0 : exclude.includes(dec.name)) && (dec.customElement || dec.tagName) )) || []; } )) || []).flat(); } function getComponentMethods(component) { var _a; return (_a = component.members) == null ? void 0 : _a.filter( (member) => { var _a2; return member.kind === "method" && member.privacy !== "private" && ((_a2 = member.description) == null ? void 0 : _a2.length) && !member.name.startsWith("#"); } ); } // ../../tools/cem-utils/src/description-templates.ts function getComponentDetailsTemplate(component, options, isComment = false) { var _a, _b, _c, _d, _e; const slots = getSlotsTemplate( component == null ? void 0 : component.slots, options == null ? void 0 : options.hideSlotDocs, (_a = options == null ? void 0 : options.labels) == null ? void 0 : _a.slots ); const events = getEventsTemplate( component == null ? void 0 : component.events, options == null ? void 0 : options.hideEventDocs, (_b = options == null ? void 0 : options.labels) == null ? void 0 : _b.events ); const cssProps = getCssPropsTemplate( component == null ? void 0 : component.cssProperties, options == null ? void 0 : options.hideCssPropertiesDocs, (_c = options == null ? void 0 : options.labels) == null ? void 0 : _c.cssProperties ); const parts = getPartsTemplate( component == null ? void 0 : component.cssParts, options == null ? void 0 : options.hideCssPartsDocs, (_d = options == null ? void 0 : options.labels) == null ? void 0 : _d.cssParts ); const methods = getMethodsTemplate( getComponentMethods(component), options == null ? void 0 : options.hideMethodDocs, (_e = options == null ? void 0 : options.labels) == null ? void 0 : _e.methods ); let description = getComponentDescription(component, options == null ? void 0 : options.descriptionSrc) + "\n---\n" + events + methods + slots + cssProps + parts; if (isComment) { description = description.split("\n").map((x) => ` * ${x}`).join("\n"); } return description; } function getSlotsTemplate(slots, hide, label = "Slots") { return has(slots) && !hide ? ` ### **${label}:** ${getSlotDocs(slots)}` : ""; } function getEventsTemplate(events, hide, label = "Events") { return has(events) && !hide ? ` ### **${label}:** ${getEventDocs(events)}` : ""; } function getCssPropsTemplate(cssProperties, hide, label = "CSS Properties") { return has(cssProperties) && !hide ? ` ### **${label}:** ${getCssPropertyDocs(cssProperties)}` : ""; } function getPartsTemplate(cssParts, hide, label = "CSS Parts") { return has(cssParts) && !hide ? ` ### **${label}:** ${getCssPartsDocs(cssParts)}` : ""; } function getMethodsTemplate(methods, hide, label = "Methods") { return has(methods) && !hide ? ` ### **${label}:** ${getMethodDocs(methods)}` : ""; } function getEventDocs(events) { return events == null ? void 0 : events.filter((event) => event.name !== null && event.name !== void 0).map( (event) => `- **${event.name}**${event.description ? ` - ${event.description}` : ""}` ).join("\n"); } function getCssPropertyDocs(properties) { return properties == null ? void 0 : properties.map( (prop) => `- **${prop.name}** - ${prop.description} _(default: ${prop.default})_` ).join("\n"); } function getCssPartsDocs(parts) { return parts == null ? void 0 : parts.map((part) => `- **${part.name}** - ${part.description}`).join("\n"); } function getSlotDocs(slots) { return slots == null ? void 0 : slots.map( (slot) => `- ${slot.name ? `**${slot.name}**` : "_default_"} - ${slot.description}` ).join("\n"); } function getMethodDocs(methods) { return methods == null ? void 0 : methods.map((method) => { var _a; if (method.privacy === "private" || method.privacy === "protected") { return; } return `- **${method.name}${getParameters(method.parameters)}${method.return ? `: _${(_a = method.return.type) == null ? void 0 : _a.text}_` : ""}** - ${getMemberDescription(method.description, method.deprecated)}`; }).join("\n"); } function getParameters(parameters) { return parameters ? "(" + parameters.map( (x) => { var _a, _b; return `${x.name + (((_a = x == null ? void 0 : x.type) == null ? void 0 : _a.text) ? `: _${(_b = x == null ? void 0 : x.type) == null ? void 0 : _b.text}_` : "")}`; } ).join(", ") + ")" : "()"; } function getMemberDescription(description, deprecated) { if (!deprecated) { return description || ""; } const desc = description ? ` - ${description}` : ""; return typeof deprecated === "string" ? `@deprecated ${deprecated}${desc}` : `@deprecated${desc}`; } // src/cem-utilities.ts function getCssPropertyList(components) { return ((components == null ? void 0 : components.map((component) => { var _a; return ((_a = component.cssProperties) == null ? void 0 : _a.map((prop) => { return { name: prop.name, description: prop.description }; })) || []; })) || []).flat(); } function getCssPartList(components) { return ((components == null ? void 0 : components.map((component) => { var _a; return ((_a = component.cssParts) == null ? void 0 : _a.map((prop) => { return { name: `part(${prop.name})`, description: prop.description }; })) || []; })) || []).flat(); } function getComponentAttributes(component, typeSrc = "type") { var _a; const attributes = []; (_a = component == null ? void 0 : component.attributes) == null ? void 0 : _a.forEach((attr) => { var _a2, _b; const existingAttr = attributes.find( (x) => x.name === attr.name || x.name === attr.fieldName ); if (existingAttr) { return; } attributes.push({ name: attr.name || attr.fieldName, description: attr.description, value: { type: ((_a2 = attr[`${typeSrc}`]) == null ? void 0 : _a2.text) || ((_b = attr.type) == null ? void 0 : _b.text) || "string", default: attr.default } }); }); return attributes; } // ../../tools/integrations/src/files.ts var import_fs = __toESM(require("fs"), 1); var import_path = __toESM(require("path"), 1); var import_sync = __toESM(require("@prettier/sync"), 1); function createOutDir(outDir) { if (outDir !== "./" && !import_fs.default.existsSync(outDir)) { import_fs.default.mkdirSync(outDir, { recursive: true }); } } function saveFile(outDir, fileName, contents, parser = "json", printWidth = 80) { const outputPath = import_path.default.join(outDir, fileName); import_fs.default.writeFileSync( outputPath, import_sync.default.format(contents, { parser, printWidth }) ); return outputPath; } // ../../tools/integrations/src/logs.ts function log(message, skip, color = "\x1B[30m%s\x1B[0m") { if (skip) { return; } console.log(color, message); } function logRed(message, skip) { log(message, skip, "\x1B[31m%s\x1B[0m"); } function logGreen(message, skip) { log(message, skip, "\x1B[32m%s\x1B[0m"); } function logYellow(message, skip) { log(message, skip, "\x1B[33m%s\x1B[0m"); } // ../../tools/configurations/src/config.ts var baseConfig = { outdir: "./", exclude: [], descriptionSrc: void 0, hideSlotDocs: false, hideEventDocs: false, hideCssPropertiesDocs: false, hideCssPartsDocs: false, hideMethodDocs: false, labels: { slots: "Slots", events: "Events", cssProperties: "CSS Properties", cssParts: "CSS Parts", methods: "Methods" } }; function updateConfig(params) { const config = { ...baseConfig, ...params }; config.labels = { ...baseConfig.labels, ...params == null ? void 0 : params.labels }; return config; } // src/web-types-generator.ts var packageJson = JSON.parse(import_fs2.default.readFileSync("package.json", "utf8")); function getTagList(components, options) { return components.map((component) => { var _a; const reference = options.referenceTemplate ? options.referenceTemplate(component.name, component.tagName) : void 0; return { name: `${options.prefix}${component.tagName || toKebabCase(component.name)}${options.suffix}`, description: getComponentDetailsTemplate(component, options), ["doc-url"]: (reference == null ? void 0 : reference.url) || "", attributes: getComponentAttributes(component, options.typesSrc), slots: (_a = component.slots) == null ? void 0 : _a.map((slot) => { return { name: slot.name, description: slot.description }; }), events: getWebTypeEvents(component), js: getJsProperties(component, options.typesSrc) }; }); } function getJsProperties(component, typesSrc) { return { properties: getWebTypeProperties(component, typesSrc), events: getWebTypeEvents(component) }; } function isPublicProperty(field) { return field.static !== true && (field.privacy === "public" || field.privacy === void 0); } function getWebTypeProperties(component, typesSrc = "type") { var _a, _b; return ((_b = (_a = component.members) == null ? void 0 : _a.filter((member) => member.kind === "field")) == null ? void 0 : _b.filter(isPublicProperty).map((field) => { var _a2, _b2; return { name: field.name, description: field.description, type: ((_a2 = field[typesSrc]) == null ? void 0 : _a2.text) || ((_b2 = field.type) == null ? void 0 : _b2.text) }; })) || []; } function getWebTypeEvents(component) { var _a; return ( // The CEM analyzer will generate a custom event without a name if it is dispatched inside the // custom element using a predefined constructor, but JetBrains IDEs seemingly can't do anything // with unnamed Web Type events, so ignore them. ((_a = component.events) == null ? void 0 : _a.filter((event) => event.name !== void 0 && event.name !== null).map((event) => { var _a2; return { name: event.name, type: (_a2 = event.type) == null ? void 0 : _a2.text, description: event.description }; })) || [] ); } function generateJetBrainsWebTypes(customElementsManifest, options) { if (options == null ? void 0 : options.skip) { logYellow("[jet-brains-web-type-generator] - Skipped", options.hideLogs); return; } log( "[jet-brains-web-type-generator] - Updating Custom Elements Manifest...", options == null ? void 0 : options.hideLogs ); options = getOptions(options); const components = getComponents( customElementsManifest, options.exclude ).filter((x) => x.tagName); if (!components.length) { logRed( "[jet-brains-web-type-generator] - No components found in custom-elements.json" ); return; } const elements = options.webTypesFileName ? getTagList(components, options) : []; const cssProperties = getCssPropertyList(components); const cssParts = getCssPartList(components); const outputPath = saveWebTypeFile( elements, cssProperties, cssParts, options ); logGreen(`[jet-brains-web-type-generator] - Generated "${outputPath}".`); } function getWebTypesData(customElementsManifest, options) { options = getOptions(options); const components = getComponents( customElementsManifest, options.exclude ).filter((x) => x.tagName); const elements = getTagList(components, options); const cssProperties = getCssPropertyList(components); const cssParts = getCssPartList(components); return getWebTypesFileContents(elements, cssProperties, cssParts, options); } function getOptions(options) { options = updateConfig(options); options.webTypesFileName = options.webTypesFileName === void 0 ? "web-types.json" : options.webTypesFileName; options.prefix = options.prefix === void 0 ? "" : options.prefix; options.suffix = options.suffix === void 0 ? "" : options.suffix; return options; } function saveWebTypeFile(tags, cssProperties, parts, options) { createOutDir(options.outdir); if (options.webTypesFileName) { if (options.packageJson) { savePackageJson(packageJson, options); } return saveFile( options.outdir, options.webTypesFileName, getWebTypesFileContents(tags, cssProperties, parts, options) ); } return ""; } function savePackageJson(packageJson2, options) { var _a; packageJson2["web-types"] = (!((_a = options.outdir) == null ? void 0 : _a.endsWith("/")) ? options.outdir + "/" : options.outdir || "") + options.webTypesFileName; saveFile("./", "package.json", JSON.stringify(packageJson2, null, 2)); } function getWebTypesFileContents(tags, cssProperties, parts, options) { return `{ "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json", "name": "${packageJson.name}", "version": "${packageJson.version}", "description-markup": "markdown",${options.defaultIcon ? ` "default-icon": "${options.defaultIcon}", ` : ""} "contributions": { ${options.excludeHtml ? "" : `"html": { "elements": ${JSON.stringify(tags)} },`} ${options.excludeCss ? "" : `"css": { "properties": ${JSON.stringify(cssProperties)}, "pseudo-elements": ${JSON.stringify(parts)} }`} } }`; } // src/cem-analyzer-plugin.ts function customElementJetBrainsPlugin(options = {}) { return { name: "custom-element-jet-brains-integration", packageLinkPhase({ customElementsManifest }) { generateJetBrainsWebTypes(customElementsManifest, options); } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { customElementJetBrainsPlugin, generateJetBrainsWebTypes, getWebTypesData });