{"version":3,"sources":["jsdelivr-header.js","/npm/@stencil/react-output-target@1.4.2/src/utils/string-utils.ts","/npm/@stencil/react-output-target@1.4.2/src/create-es-modules-components-file.ts","/npm/@stencil/react-output-target@1.4.2/src/create-stencil-react-components.ts","/npm/@stencil/react-output-target@1.4.2/src/create-tag-transformer.ts","/npm/@stencil/react-output-target@1.4.2/src/create-component-wrappers.ts","/npm/@stencil/react-output-target@1.4.2/src/index.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,yFCNa,MAAA,EAAqB,GAChC,EACG,cACA,MAAM,KACN,KAAK,GAAY,EAAQ,OAAO,GAAG,cAAgB,EAAQ,MAAM,KACjE,KAAK,IAEG,EAAoB,GAAgB,EAAI,QAAQ,cAAc,CAAC,EAAG,IAAW,EAAO,gBAE3F,EAAsB,GAAgB,EAAI,QAAQ,cAAc,CAAC,EAAG,IAAW,EAAO,gBAE/E,EAAqB,IAC1B,MAAA,EAAmB,EAAmB,GACrC,OAAA,EAAiB,MAAM,IAAkB,EAOrC,EAAuB,GAClC,EACG,QAAQ,YAAa,IACrB,QAAQ,MAAO,KACf,QAAQ,UAAW,KACnB,OCpBQ,EAAgC,OAC3C,aACA,UACA,aAMA,MAAM,EAAY,GAAW,IAAI,EAAQ,CAAE,uBAAuB,IAM5D,EAAU,EAAK,KAAK,GAAU,GAAI,iBAClC,EAAa,EAAU,iBAAiB,EAAS,sNAAsC,CAC3F,WAAW,IAGb,UAAW,KAAa,EAAY,CAClC,MAAM,EAAU,EAAU,QACpB,EAAe,EAAkB,GACjC,EAAW,EAAU,QAC3B,EAAW,qBAAqB,CAC9B,gBAAiB,KAAK,OACtB,aAAc,CAAC,IAChB,CAGH,OAAA,EAAW,kBACX,EAAW,mBACL,EAAW,OAEV,GC5BI,EAA+B,EAC1C,aACA,qBACA,oBACA,gBACA,eACA,sBACA,mBAUA,MAAM,EAAU,IAAI,EAAQ,CAAE,uBAAuB,IAc/C,EAAwB,EAC1B,CAF4B,EA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AAS,IAE9E,MAAM,IAAI,MACR,QAAQ,gBAA0B,yEAA6F,sCAInI,GAAoB,MAAhB,EACF,MAAM,IAAI,MACR,QAAQ,iIAA2I,mBAEvJ,CAMF,QAA2B,IAAvB,EAAkC,CAChC,GAAA,EAAO,KAAO,EAAO,oBAAqB,CAC5C,MAAQ,KAAM,GAAgB,KAAK,MAAM,EAAO,IAAI,aAAa,EAAO,oBAAqB,SACxE,EAAA,CAAA,CAGvB,IAAK,EACH,MAAM,IAAI,MACR,6DAA6D,EAAO,8EAA8E,mBAEtJ,CAEJ,EACA,eAAM,CAAU,EAAS,EAAa,GACpC,MAAM,EAAW,EAAS,eAAe,YAAY,aAAuB,GAEtE,EAAa,EAAS,WACtB,EAAU,IAAI,EAEd,QAAoB,EAAwB,CAChD,SACA,aACA,qBACA,oBACA,oBACA,WAAyB,IAAd,EACX,UACA,gBACA,eACA,gCACA,sBACA,uBAGI,QAAQ,IACZ,EAAY,KAAK,GAAe,EAAY,GAAG,UAAU,EAAW,cAAe,EAAW,kBAGvF,EAAA,OAAO,YAAY,aAC9B,EACA,gCAAA,IACS,EAEX,S","file":"/npm/@stencil/react-output-target@1.4.2/dist/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@stencil/react-output-target@1.4.2/dist/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","export const kebabToPascalCase = (str: string) =>\n  str\n    .toLowerCase()\n    .split('-')\n    .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))\n    .join('');\n\nexport const kebabToCamelCase = (str: string) => str.replace(/-([_a-z])/g, (_, letter) => letter.toUpperCase());\n\nconst slashesToCamelCase = (str: string) => str.replace(/\\/([a-z])/g, (_, letter) => letter.toUpperCase());\n\nexport const eventListenerName = (eventName: string) => {\n  const slashesConverted = slashesToCamelCase(eventName);\n  return kebabToCamelCase(`on-${slashesConverted}`);\n};\n\n/**\n * Normalizes a type string by removing single-line comments and collapsing whitespace.\n * This is necessary because multiline types with comments would break when collapsed to a single line.\n */\nexport const normalizeTypeString = (type: string) =>\n  type\n    .replace(/\\/\\/.*$/gm, '') // Remove single-line comments\n    .replace(/\\n/g, ' ') // Replace newlines with spaces\n    .replace(/\\s{2,}/g, ' ') // Collapse multiple spaces\n    .trim();\n","import type { ComponentCompilerMeta } from '@stencil/core/internal';\nimport path from 'node:path';\nimport { Project } from 'ts-morph';\nimport { kebabToPascalCase } from './utils/string-utils.js';\n\nexport const createEsModulesComponentsFile = async ({\n  components,\n  project,\n  outDir,\n}: {\n  components: ComponentCompilerMeta[];\n  project?: Project;\n  outDir?: string;\n}) => {\n  const tsProject = project || new Project({ useInMemoryFileSystem: true });\n  const disableEslint = `/* eslint-disable */\\n`;\n  const autogeneratedComment = `/**\n * This file was automatically generated by the Stencil React Output Target.\n * Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.\n */\\n\\n`;\n  const outFile = path.join(outDir || '', 'components.ts');\n  const sourceFile = tsProject.createSourceFile(outFile, autogeneratedComment + disableEslint, {\n    overwrite: true,\n  });\n\n  for (const component of components) {\n    const tagName = component.tagName;\n    const reactTagName = kebabToPascalCase(tagName);\n    const fileName = component.tagName;\n    sourceFile.addExportDeclaration({\n      moduleSpecifier: `./${fileName}.js`,\n      namedExports: [reactTagName],\n    });\n  }\n\n  sourceFile.organizeImports();\n  sourceFile.formatText();\n  await sourceFile.save();\n\n  return sourceFile;\n};\n","import type { ComponentCompilerMeta } from '@stencil/core/internal';\nimport { Project, VariableDeclarationKind } from 'ts-morph';\nimport { eventListenerName, kebabToPascalCase, normalizeTypeString } from './utils/string-utils.js';\nimport type { RenderToStringOptions } from './runtime/ssr.js';\n\ninterface ReactEvent {\n  originalName: string;\n  name: string;\n  type: string;\n}\n\nexport const createStencilReactComponents = ({\n  components,\n  stencilPackageName,\n  customElementsDir,\n  hydrateModule,\n  clientModule,\n  serializeShadowRoot,\n  transformTag,\n}: {\n  components: ComponentCompilerMeta[];\n  stencilPackageName: string;\n  customElementsDir: string;\n  hydrateModule?: string;\n  clientModule?: string;\n  serializeShadowRoot?: RenderToStringOptions['serializeShadowRoot'];\n  transformTag?: boolean;\n}) => {\n  const project = new Project({ useInMemoryFileSystem: true });\n\n  /**\n   * automatically attach the `use client` directive if we are not generating\n   * server side rendering components.\n   */\n  const useClientDirective = `'use client';\\n\\n`;\n  const autogeneratedComment = `/**\n * This file was automatically generated by the Stencil React Output Target.\n * Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.\n */\\n\\n`;\n\n  const disableEslint = `/* eslint-disable */\\n`;\n  const getTagTransformerImport = transformTag ? `import { getTagTransformer } from './tag-transformer.js';\\n` : '';\n  const createComponentImport = hydrateModule\n    ? [\n        getTagTransformerImport,\n        `import { createComponent, type SerializeShadowRootOptions, type HydrateModule, type ReactWebComponent } from '@stencil/react-output-target/ssr';`,\n      ]\n        .filter(Boolean)\n        .join('\\n')\n    : `import { createComponent } from '@stencil/react-output-target/runtime';`;\n  // transformTag should be imported from tag-transformer for both client and server\n  const transformTagImport = transformTag ? `import { transformTag } from './tag-transformer.js';\\n` : '';\n  const sourceFile = project.createSourceFile(\n    'component.ts',\n    `${useClientDirective}${autogeneratedComment}${disableEslint}\nimport React from 'react';\n${createComponentImport}\nimport type { EventName, StencilReactComponent } from '@stencil/react-output-target/runtime';\n${transformTagImport}\n  `\n  );\n\n  /**\n   * Add the `clientComponents` import if hydrateModule is provided.\n   * This import needs a @ts-ignore comment, which will be added after organizeImports().\n   */\n  if (hydrateModule && clientModule) {\n    sourceFile.addImportDeclaration({\n      moduleSpecifier: clientModule,\n      namespaceImport: 'clientComponents',\n    });\n  }\n\n  /**\n   * Add the `serializeShadowRoot` variable to the file if the hydrateModule is provided.\n   */\n  if (hydrateModule) {\n    sourceFile.addVariableStatement({\n      isExported: true,\n      declarationKind: VariableDeclarationKind.Const,\n      declarations: [\n        {\n          name: 'serializeShadowRoot',\n          type: 'SerializeShadowRootOptions',\n          initializer: serializeShadowRoot\n            ? JSON.stringify(serializeShadowRoot)\n            : '{ default: \"declarative-shadow-dom\" }',\n        },\n      ],\n    });\n  }\n\n  for (const component of components) {\n    const tagName = component.tagName;\n    const reactTagName = kebabToPascalCase(tagName);\n    const componentElement = `${reactTagName}Element`;\n    const componentCustomEvent = `${reactTagName}CustomEvent`;\n\n    sourceFile.addImportDeclaration({\n      moduleSpecifier: `${stencilPackageName}/${customElementsDir}/${tagName}.js`,\n      namedImports: [\n        {\n          name: reactTagName,\n          alias: componentElement,\n        },\n        {\n          name: 'defineCustomElement',\n          alias: `define${reactTagName}`,\n        },\n      ],\n    });\n\n    const publicEvents = (component.events || []).filter((e) => e.internal === false);\n    const events: ReactEvent[] = [];\n    const importedEventDetailTypes = new Set<string>();\n    let importedComponentCustomEvent = false;\n\n    for (const event of publicEvents) {\n      /**\n       * Import the referenced types from the component library.\n       * Stencil will automatically re-export type definitions from the components,\n       * if they are used in the component's property or event types.\n       */\n      if (Object.keys(event.complexType.references).length > 0) {\n        for (const referenceKey of Object.keys(event.complexType.references)) {\n          const reference = event.complexType.references[referenceKey];\n          const isGlobalType = reference.location === 'global';\n\n          /**\n           * Global type references should not have an explicit import.\n           * The type should be available globally.\n           */\n          if (!isGlobalType && !importedEventDetailTypes.has(referenceKey)) {\n            importedEventDetailTypes.add(referenceKey);\n            sourceFile.addImportDeclaration({\n              moduleSpecifier: stencilPackageName,\n              namedImports: [\n                {\n                  name: referenceKey,\n                  isTypeOnly: true,\n                },\n              ],\n            });\n          }\n        }\n      }\n\n      /**\n       * Import the CustomEvent type for the web component from the Stencil package.\n       *\n       * For example:\n       * ```\n       * import type { ComponentCustomEvent } from 'my-component-library';\n       * ```\n       */\n      if (!importedComponentCustomEvent) {\n        importedComponentCustomEvent = true;\n        sourceFile.addImportDeclaration({\n          moduleSpecifier: stencilPackageName,\n          namedImports: [\n            {\n              name: componentCustomEvent,\n              isTypeOnly: true,\n            },\n          ],\n        });\n      }\n\n      // Always type events using the Stencil per-component CustomEvent type.\n      events.push({\n        originalName: event.name,\n        name: eventListenerName(event.name),\n        type: `EventName<${componentCustomEvent}<${normalizeTypeString(event.complexType.original)}>>`,\n      });\n    }\n\n    const componentEventNamesType = `${reactTagName}Events`;\n\n    sourceFile.addTypeAlias({\n      isExported: true,\n      name: componentEventNamesType,\n      type: events.length > 0 ? `{ ${events.map((e) => `${e.name}: ${e.type}`).join(',\\n')} }` : 'NonNullable<unknown>',\n    });\n\n    const transformTagParam = transformTag ? ',\\n    transformTag' : '';\n    const clientComponentCall = `/*@__PURE__*/ createComponent<${componentElement}, ${componentEventNamesType}>({\n    tagName: '${tagName}',\n    elementClass: ${componentElement},\n    // @ts-ignore - ignore potential React type mismatches between the Stencil Output Target and your project.\n    react: React,\n    events: {${events.map((e) => `${e.name}: '${e.originalName}'`).join(',\\n')}} as ${componentEventNamesType},\n    defineCustomElement: define${reactTagName}${transformTagParam}\n  })`;\n\n    const getTagTransformerParam = transformTag ? ',\\n    getTagTransformer' : '';\n    const serverComponentCall = `/*@__PURE__*/ createComponent<${componentElement}, ${componentEventNamesType}>({\n    tagName: '${tagName}',\n    properties: {${component.properties\n      /**\n       * Filter out properties that don't have an attribute.\n       * These are properties with complex types and can't be serialized.\n       */\n      .filter((prop) => Boolean(prop.attribute))\n      .map((e) => `${e.name}: '${e.attribute}'`)\n      .join(',\\n')}},\n    hydrateModule: import('${hydrateModule}') as Promise<HydrateModule>,\n    clientModule: clientComponents.${reactTagName} as ReactWebComponent<${componentElement}, ${componentEventNamesType}>,\n    serializeShadowRoot${getTagTransformerParam}\n  })`;\n\n    sourceFile.addVariableStatement({\n      isExported: true,\n      declarationKind: VariableDeclarationKind.Const,\n      // React as never is a hack to by-pass a @types/react issue.\n      declarations: [\n        {\n          name: reactTagName,\n          type: `StencilReactComponent<${componentElement}, ${componentEventNamesType}>`,\n          initializer: hydrateModule ? serverComponentCall : clientComponentCall,\n        },\n      ],\n    });\n  }\n\n  sourceFile.organizeImports();\n\n  /**\n   * Add the @ts-ignore comment to the clientComponents import after organizeImports()\n   * to ensure the comment stays attached to the correct import.\n   */\n  if (hydrateModule && clientModule) {\n    const clientComponentsImport = sourceFile\n      .getImportDeclarations()\n      .find((imp) => imp.getNamespaceImport()?.getText() === 'clientComponents');\n\n    if (clientComponentsImport) {\n      sourceFile.insertText(\n        clientComponentsImport.getStart(),\n        '// @ts-ignore - ignore potential type issues as the project is importing itself\\n'\n      );\n    }\n  }\n\n  sourceFile.formatText();\n\n  return sourceFile.getFullText();\n};\n","export const createTagTransformer = ({\n  stencilPackageName,\n  customElementsDir,\n}: {\n  stencilPackageName: string;\n  customElementsDir: string;\n}) => {\n  return `/* eslint-disable */\n/* tslint:disable */\nimport { setTagTransformer as clientSetTagTransformer } from '${stencilPackageName}/${customElementsDir}/index.js';\n\nlet tagTransformer: ((tagName: string) => string) | undefined;\n\nexport const setTagTransformer = (transformer: (tagName: string) => string) => {\n  clientSetTagTransformer(transformer);\n  tagTransformer = transformer;\n};\n\nexport const transformTag = (tag: string): string => {\n  return tagTransformer ? tagTransformer(tag) : tag;\n};\n\nexport const getTagTransformer = () => tagTransformer;\n`;\n};\n","import type { ComponentCompilerMeta } from '@stencil/core/internal';\nimport path from 'node:path';\nimport { Project, SourceFile } from 'ts-morph';\nimport { createEsModulesComponentsFile } from './create-es-modules-components-file.js';\nimport { createStencilReactComponents } from './create-stencil-react-components.js';\nimport { createTagTransformer } from './create-tag-transformer.js';\nimport type { RenderToStringOptions } from './runtime/ssr.js';\n\nexport const createComponentWrappers = async ({\n  stencilPackageName,\n  components,\n  outDir,\n  esModules,\n  customElementsDir,\n  excludeComponents,\n  project,\n  hydrateModule,\n  clientModule,\n  excludeServerSideRenderingFor,\n  serializeShadowRoot,\n  transformTag,\n}: {\n  stencilPackageName: string;\n  components: ComponentCompilerMeta[];\n  customElementsDir: string;\n  outDir: string;\n  esModules?: boolean;\n  excludeComponents?: string[];\n  project: Project;\n  hydrateModule?: string;\n  clientModule?: string;\n  excludeServerSideRenderingFor?: string[];\n  serializeShadowRoot?: RenderToStringOptions['serializeShadowRoot'];\n  transformTag?: boolean;\n}) => {\n  const sourceFiles: SourceFile[] = [];\n\n  const filteredComponents = components.filter((c) => {\n    if (c.internal === true) {\n      /**\n       * Skip internal components\n       */\n      return false;\n    }\n    if (excludeComponents?.includes(c.tagName)) {\n      /**\n       * Skip excluded components\n       */\n      return false;\n    }\n\n    return true;\n  });\n\n  if (filteredComponents.length === 0) {\n    return [];\n  }\n\n  const fileContents: Record<string, string> = {};\n\n  /**\n   * create a single file with all components or a separate file for each component\n   * @param components - the components to create the file for\n   * @param filename - the filename of the file to create\n   */\n  function createComponentFile(components: ComponentCompilerMeta[], filename = 'components') {\n    /**\n     * create a single file with all components\n     */\n    const outputPath = path.join(outDir, `${filename}.ts`);\n\n    /**\n     * create a client side component\n     */\n    const stencilReactComponent = createStencilReactComponents({\n      components,\n      stencilPackageName,\n      customElementsDir,\n      transformTag,\n    });\n    fileContents[outputPath] = stencilReactComponent;\n\n    /**\n     * create tag-transformer file (for both client and server)\n     */\n    if (transformTag) {\n      const tagTransformerPath = path.join(outDir, 'tag-transformer.ts');\n      fileContents[tagTransformerPath] = createTagTransformer({ stencilPackageName, customElementsDir });\n    }\n\n    /**\n     * create a server side component\n     */\n    if (hydrateModule) {\n      const outputPath = path.join(outDir, `${filename}.server.ts`);\n      const stencilReactComponent = createStencilReactComponents({\n        components: components.filter(\n          (c) => !excludeServerSideRenderingFor || !excludeServerSideRenderingFor.includes(c.tagName)\n        ),\n        stencilPackageName,\n        customElementsDir,\n        hydrateModule,\n        clientModule,\n        serializeShadowRoot,\n        transformTag,\n      });\n      fileContents[outputPath] = stencilReactComponent;\n    }\n  }\n\n  if (esModules) {\n    /**\n     * create a separate file for each component\n     */\n    for (const component of filteredComponents) {\n      createComponentFile([component], component.tagName);\n    }\n    const componentsSource = await createEsModulesComponentsFile({ components: filteredComponents, project, outDir });\n    sourceFiles.push(componentsSource);\n  } else {\n    createComponentFile(filteredComponents);\n  }\n\n  await Promise.all(\n    Object.entries(fileContents).map(async ([outputPath, content]) => {\n      const sourceFile = project.createSourceFile(outputPath, content, { overwrite: true });\n      await sourceFile.save();\n      sourceFiles.push(sourceFile);\n    })\n  );\n\n  return sourceFiles;\n};\n","import type { BuildCtx, OutputTargetCustom, OutputTargetDistCustomElements } from '@stencil/core/internal';\nimport { Project } from 'ts-morph';\nimport { createComponentWrappers } from './create-component-wrappers.js';\nimport type { RenderToStringOptions } from './runtime/ssr.js';\n\nexport interface ReactOutputTargetOptions {\n  /**\n   * Specify the output directory or path where the generated React components will be saved.\n   */\n  outDir: string;\n  /**\n   * Specify the components that should be excluded from the React output target.\n   */\n  excludeComponents?: string[];\n  /**\n   * The package name of the Stencil project.\n   *\n   * This value is automatically detected from the package.json file of the Stencil project.\n   * If the validation fails, you can manually assign the package name.\n   */\n  stencilPackageName?: string;\n  /**\n   * The directory where the custom elements are saved.\n   *\n   * This value is automatically detected from the Stencil configuration file for the dist-custom-elements output target.\n   * If you are working in an environment that uses absolute paths, consider setting this value manually.\n   */\n  customElementsDir?: string;\n  /**\n   * To enable server side rendering, provide the path to the hydrate module, e.g. `my-component/hydrate`.\n   * By default this value is undefined and server side rendering is disabled.\n   */\n  hydrateModule?: string;\n  /**\n   * The name of the package that exports all React wrapped Stencil components for client side rendering.\n   * This options is required when `hydrateModule` is set for server side rendering to work.\n   */\n  clientModule?: string;\n  /**\n   * Specify the components that should be excluded from server side rendering.\n   */\n  excludeServerSideRenderingFor?: string[];\n  /**\n   * If `true`, the output target will generate a separate ES module for each React component wrapper (better for tree-shaking).\n   * @default false\n   */\n  esModules?: boolean;\n  /**\n   * Configure how Stencil serializes the components shadow root.\n   * - If set to `declarative-shadow-dom` the component will be rendered within a Declarative Shadow DOM.\n   * - If set to `scoped` Stencil will render the contents of the shadow root as a `scoped: true` component\n   *   and the shadow DOM will be created during client-side hydration.\n   * - Alternatively you can mix and match the two by providing an object with `declarative-shadow-dom` and `scoped` keys,\n   * the value arrays containing the tag names of the components that should be rendered in that mode.\n   *\n   * Examples:\n   * - `{ 'declarative-shadow-dom': ['my-component-1', 'another-component'], default: 'scoped' }`\n   * Render all components as `scoped` apart from `my-component-1` and `another-component`\n   * -  `{ 'scoped': ['an-option-component'], default: 'declarative-shadow-dom' }`\n   * Render all components within `declarative-shadow-dom` apart from `an-option-component`\n   * - `'scoped'` Render all components as `scoped`\n   * - `false` disables shadow root serialization\n   *\n   * *NOTE* `true` has been deprecated in favor of `declarative-shadow-dom` and `scoped`\n   * @default 'declarative-shadow-dom'\n   */\n  serializeShadowRoot?: RenderToStringOptions['serializeShadowRoot'];\n  /**\n   * Use `transformTag` to enable runtime tag name transformation for your components.\n   * When enabled, the output target will import `transformTag` from your component library\n   * and apply it when rendering components.\n   *\n   * You must export `transformTag` from the root entry of your component library:\n   * ```ts\n   * // src/index.ts\n   * export { transformTag } from '@stencil/core';\n   * ```\n   *\n   * @default false\n   */\n  transformTag?: boolean;\n}\n\nconst PLUGIN_NAME = 'react-output-target';\n\nconst DIST_CUSTOM_ELEMENTS_DEFAULT_DIR = 'dist/components';\nconst DIST_CUSTOM_ELEMENTS = 'dist-custom-elements';\nconst HYDRATE_OUTPUT_TARGET = 'dist-hydrate-script';\n\ninterface ReactOutputTarget extends OutputTargetCustom {\n  __internal_getCustomElementsDir: () => string;\n}\n\n/**\n * Creates an output target for binding Stencil components to be used in a React context\n * @public\n * @param outputTarget the user-defined output target defined in a Stencil configuration file\n * @returns an output target that can be used by the Stencil compiler\n */\nexport const reactOutputTarget = ({\n  outDir,\n  esModules,\n  stencilPackageName,\n  excludeComponents,\n  customElementsDir: customElementsDirOverride,\n  hydrateModule,\n  clientModule,\n  excludeServerSideRenderingFor,\n  serializeShadowRoot,\n  transformTag,\n}: ReactOutputTargetOptions): ReactOutputTarget => {\n  let customElementsDir = DIST_CUSTOM_ELEMENTS_DEFAULT_DIR;\n  return {\n    type: 'custom',\n    name: PLUGIN_NAME,\n    validate(config) {\n      /**\n       * Validate the configuration to ensure that the dist-custom-elements\n       * output target is defined in the Stencil configuration.\n       *\n       * This context is used to detect a customized output path.\n       */\n      if (customElementsDirOverride) {\n        customElementsDir = customElementsDirOverride;\n      } else {\n        const customElementsOutputTarget = (config.outputTargets || []).find(\n          (o) => o.type === DIST_CUSTOM_ELEMENTS\n        ) as OutputTargetDistCustomElements;\n        if (customElementsOutputTarget == null) {\n          throw new Error(\n            `The '${PLUGIN_NAME}' requires '${DIST_CUSTOM_ELEMENTS}' output target. Add { type: '${DIST_CUSTOM_ELEMENTS}' }, to the outputTargets config.`\n          );\n        }\n        if (customElementsOutputTarget.dir !== undefined) {\n          /**\n           * If the developer has configured a custom output path for the Stencil components,\n           * we need to use that path when importing the components in the React components.\n           */\n          customElementsDir = customElementsOutputTarget.dir;\n        }\n\n        /**\n         * Validate the configuration for `dist-custom-elements` output target to ensure that\n         * the bundle generates its own runtime. This is important because we need to ensure that\n         * the Stencil runtime has hydration flags set which the default Stencil runtime does not have.\n         */\n        if (customElementsOutputTarget.externalRuntime !== false) {\n          throw new Error(\n            `The '${PLUGIN_NAME}' requires the '${DIST_CUSTOM_ELEMENTS}' output target to have 'externalRuntime: false' set in its configuration.`\n          );\n        }\n      }\n\n      /**\n       * Validate the configuration to ensure that the dist-hydrate-script\n       * output target is defined in the Stencil configuration if the hydrateModule is provided.\n       */\n      if (hydrateModule) {\n        const hydrateOutputTarget = (config.outputTargets || []).find((o) => o.type === HYDRATE_OUTPUT_TARGET);\n        if (hydrateOutputTarget == null) {\n          throw new Error(\n            `The '${PLUGIN_NAME}' requires '${HYDRATE_OUTPUT_TARGET}' output target when the 'hydrateModule' option is set. Add { type: '${HYDRATE_OUTPUT_TARGET}' }, to the outputTargets config.`\n          );\n        }\n\n        if (clientModule == null) {\n          throw new Error(\n            `The '${PLUGIN_NAME}' requires the 'clientModule' option when the 'hydrateModule' option is set. Please provide the clientModule manually to the ${PLUGIN_NAME} output target.`\n          );\n        }\n      }\n\n      /**\n       * Validate the configuration to detect the package name of the Stencil project.\n       */\n      if (stencilPackageName === undefined) {\n        if (config.sys && config.packageJsonFilePath) {\n          const { name: packageName } = JSON.parse(config.sys.readFileSync(config.packageJsonFilePath, 'utf8'));\n          stencilPackageName = packageName;\n        }\n\n        if (!stencilPackageName) {\n          throw new Error(\n            `Unable to find the package name in the package.json file: ${config.packageJsonFilePath}. Please provide the stencilPackageName manually to the ${PLUGIN_NAME} output target.`\n          );\n        }\n      }\n    },\n    async generator(_config, compilerCtx, buildCtx: BuildCtx) {\n      const timespan = buildCtx.createTimeSpan(`generate ${PLUGIN_NAME} started`, true);\n\n      const components = buildCtx.components;\n      const project = new Project();\n\n      const sourceFiles = await createComponentWrappers({\n        outDir,\n        components,\n        stencilPackageName: stencilPackageName!,\n        customElementsDir,\n        excludeComponents,\n        esModules: esModules === true,\n        project,\n        hydrateModule,\n        clientModule,\n        excludeServerSideRenderingFor,\n        serializeShadowRoot,\n        transformTag,\n      });\n\n      await Promise.all(\n        sourceFiles.map((sourceFile) => compilerCtx.fs.writeFile(sourceFile.getFilePath(), sourceFile.getFullText()))\n      );\n\n      timespan.finish(`generate ${PLUGIN_NAME} finished`);\n    },\n    __internal_getCustomElementsDir() {\n      return customElementsDir;\n    },\n  };\n};\n"]}