{"version":3,"file":"polymorphic-element.cjs","names":["forwardRef"],"sources":["../../src/utils/polymorphic-element.tsx"],"sourcesContent":["import type * as React from 'react';\nimport { forwardRef } from '@wordpress/element';\n\ntype PolymorphicElementProps< T extends React.ElementType > = Omit<\n\tReact.ComponentPropsWithoutRef< T >,\n\t'as'\n> & {\n\tas?: T;\n};\n\ntype PolymorphicElementRef< T extends React.ElementType > =\n\tReact.ComponentPropsWithRef< T >[ 'ref' ];\n\nconst customAttributeRegExp = /^(data|aria|x)-/i;\nconst eventHandlerRegExp = /^on[A-Z]/;\n\n// Derived from @emotion/is-prop-valid's React prop allowlist, but split by\n// element type so SVG-only props are intentionally filtered from HTML elements.\n// The event-handler check is also deliberately stricter than Emotion's\n// charCode-based `on*` fallback.\nconst svgElementNames = new Set(\n\t`animate animateMotion animateTransform circle clipPath defs desc ellipse\n\tfeBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix\n\tfeDiffuseLighting feDisplacementMap feDistantLight feDropShadow feFlood\n\tfeFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode\n\tfeMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile\n\tfeTurbulence filter foreignObject g image line linearGradient marker mask\n\tmetadata mpath path pattern polygon polyline radialGradient rect set stop svg\n\tswitch symbol text textPath tspan use view`.split( /\\s+/ )\n);\n\nconst baseElementProps = new Set(\n\t`children dangerouslySetInnerHTML key autoFocus defaultValue defaultChecked\n\tinnerHTML suppressContentEditableWarning suppressHydrationWarning valueLink\n\tabbr accept acceptCharset accessKey action allow allowUserMedia\n\tallowPaymentRequest allowFullScreen allowTransparency alt async autoComplete\n\tautoPlay capture cellPadding cellSpacing challenge charSet checked cite classID\n\tclassName cols colSpan content contentEditable contextMenu controls controlsList\n\tcoords crossOrigin data dateTime decoding default defer dir disabled\n\tdisablePictureInPicture disableRemotePlayback download draggable encType\n\tenterKeyHint fetchpriority fetchPriority form formAction formEncType formMethod\n\tformNoValidate formTarget frameBorder headers height hidden high href hrefLang\n\thtmlFor httpEquiv id inputMode integrity is keyParams keyType kind label lang\n\tlist loading loop low marginHeight marginWidth max maxLength media mediaGroup\n\tmethod min minLength multiple muted name nonce noValidate open optimum pattern\n\tplaceholder playsInline popover popoverTarget popoverTargetAction poster\n\tpreload profile radioGroup readOnly referrerPolicy rel required reversed role\n\trows rowSpan sandbox scope scoped scrolling seamless selected shape size sizes\n\tslot span spellCheck src srcDoc srcLang srcSet start step style summary\n\ttabIndex target title translate type useMap value width wmode wrap about\n\tdatatype inlist prefix property resource typeof vocab autoCapitalize\n\tautoCorrect autoSave color incremental fallback inert itemProp itemScope\n\titemType itemID itemRef on option results security unselectable`.split( /\\s+/ )\n);\n\nconst svgElementProps = new Set(\n\t`accentHeight accumulate additive alignmentBaseline allowReorder alphabetic\n\tamplitude arabicForm ascent attributeName attributeType autoReverse azimuth\n\tbaseFrequency baselineShift baseProfile bbox begin bias by calcMode capHeight\n\tclip clipPathUnits clipPath clipRule colorInterpolation\n\tcolorInterpolationFilters colorProfile colorRendering contentScriptType\n\tcontentStyleType cursor cx cy d decelerate descent diffuseConstant direction\n\tdisplay divisor dominantBaseline dur dx dy edgeMode elevation enableBackground\n\tend exponent externalResourcesRequired fill fillOpacity fillRule filter\n\tfilterRes filterUnits floodColor floodOpacity focusable fontFamily fontSize\n\tfontSizeAdjust fontStretch fontStyle fontVariant fontWeight format from fr fx\n\tfy g1 g2 glyphName glyphOrientationHorizontal glyphOrientationVertical\n\tglyphRef gradientTransform gradientUnits hanging horizAdvX horizOriginX\n\tideographic imageRendering in in2 intercept k k1 k2 k3 k4 kernelMatrix\n\tkernelUnitLength kerning keyPoints keySplines keyTimes lengthAdjust\n\tletterSpacing lightingColor limitingConeAngle local markerEnd markerMid\n\tmarkerStart markerHeight markerUnits markerWidth mask maskContentUnits\n\tmaskUnits mathematical mode numOctaves offset opacity operator order orient\n\torientation origin overflow overlinePosition overlineThickness panose1\n\tpaintOrder pathLength patternContentUnits patternTransform patternUnits\n\tpointerEvents points pointsAtX pointsAtY pointsAtZ preserveAlpha\n\tpreserveAspectRatio primitiveUnits r radius refX refY renderingIntent\n\trepeatCount repeatDur requiredExtensions requiredFeatures restart result rotate\n\trx ry scale seed shapeRendering slope spacing specularConstant\n\tspecularExponent speed spreadMethod startOffset stdDeviation stemh stemv\n\tstitchTiles stopColor stopOpacity strikethroughPosition strikethroughThickness\n\tstring stroke strokeDasharray strokeDashoffset strokeLinecap strokeLinejoin\n\tstrokeMiterlimit strokeOpacity strokeWidth surfaceScale systemLanguage\n\ttableValues targetX targetY textAnchor textDecoration textRendering textLength\n\tto transform u1 u2 underlinePosition underlineThickness unicode unicodeBidi\n\tunicodeRange unitsPerEm vAlphabetic vHanging vIdeographic vMathematical values\n\tvectorEffect version vertAdvY vertOriginX vertOriginY viewBox viewTarget\n\tvisibility widths wordSpacing writingMode x xHeight x1 x2 xChannelSelector\n\txlinkActuate xlinkArcrole xlinkHref xlinkRole xlinkShow xlinkTitle xlinkType\n\txmlBase xmlns xmlnsXlink xmlLang xmlSpace y y1 y2 yChannelSelector z\n\tzoomAndPan`.split( /\\s+/ )\n);\n\nconst compatElementProps = new Set( [ 'autofocus', 'class', 'for' ] );\n\nfunction isValidIntrinsicElementProp( prop: string, element: string ) {\n\tif (\n\t\tcustomAttributeRegExp.test( prop ) ||\n\t\teventHandlerRegExp.test( prop )\n\t) {\n\t\treturn true;\n\t}\n\n\tif ( baseElementProps.has( prop ) || compatElementProps.has( prop ) ) {\n\t\treturn true;\n\t}\n\n\treturn svgElementNames.has( element ) && svgElementProps.has( prop );\n}\n\nfunction filterIntrinsicElementProps(\n\tprops: PolymorphicElementProps< React.ElementType >,\n\telement: string\n) {\n\treturn Object.fromEntries(\n\t\tObject.entries( props ).filter( ( [ prop ] ) =>\n\t\t\tisValidIntrinsicElementProp( prop, element )\n\t\t)\n\t);\n}\n\nfunction UnforwardedPolymorphicElement(\n\t{ as, ...props }: PolymorphicElementProps< React.ElementType >,\n\tref: React.ForwardedRef< unknown >\n) {\n\tconst Element = as || 'div';\n\tconst forwardedProps =\n\t\ttypeof Element === 'string'\n\t\t\t? filterIntrinsicElementProps( props, Element )\n\t\t\t: props;\n\n\treturn <Element ref={ ref } { ...forwardedProps } />;\n}\n\n/**\n * Internal utility for components that need Emotion-compatible `as` behavior\n * while rendering with plain React elements.\n */\nexport const PolymorphicElement = forwardRef(\n\tUnforwardedPolymorphicElement\n) as < T extends React.ElementType = 'div' >(\n\tprops: PolymorphicElementProps< T > & {\n\t\tref?: PolymorphicElementRef< T >;\n\t}\n) => React.ReactElement | null;\n"],"mappings":";;;;;;;;AAaA,MAAM,wBAAwB;AAC9B,MAAM,qBAAqB;AAM3B,MAAM,kBAAkB,IAAI,IAC3B;;;;;;;6CAO4C,MAAO,KAAM,CAC1D;AAEA,MAAM,mBAAmB,IAAI,IAC5B;;;;;;;;;;;;;;;;;;;;kEAoBiE,MAAO,KAAM,CAC/E;AAEA,MAAM,kBAAkB,IAAI,IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAkCY,MAAO,KAAM,CAC1B;AAEA,MAAM,qCAAqB,IAAI,IAAK;CAAE;CAAa;CAAS;AAAM,CAAE;AAEpE,SAAS,4BAA6B,MAAc,SAAkB;CACrE,IACC,sBAAsB,KAAM,IAAK,KACjC,mBAAmB,KAAM,IAAK,GAE9B,OAAO;CAGR,IAAK,iBAAiB,IAAK,IAAK,KAAK,mBAAmB,IAAK,IAAK,GACjE,OAAO;CAGR,OAAO,gBAAgB,IAAK,OAAQ,KAAK,gBAAgB,IAAK,IAAK;AACpE;AAEA,SAAS,4BACR,OACA,SACC;CACD,OAAO,OAAO,YACb,OAAO,QAAS,KAAM,CAAC,CAAC,QAAU,CAAE,UACnC,4BAA6B,MAAM,OAAQ,CAC5C,CACD;AACD;AAEA,SAAS,8BACR,EAAE,IAAI,GAAG,SACT,KACC;CACD,MAAM,UAAU,MAAM;CACtB,MAAM,iBACL,OAAO,YAAY,WAChB,4BAA6B,OAAO,OAAQ,IAC5C;CAEJ,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAC,SAAD;EAAe;EAAM,GAAK;CAAkB,CAAA;AACpD;;;;;AAMA,MAAa,sBAAA,GAAqBA,mBAAAA,WAAAA,CACjC,6BACD"}