@wordpress/components
Version:
UI components for WordPress.
1 lines • 15.6 kB
Source Map (JSON)
{"version":3,"file":"hook.cjs","names":["useContextSystem","styles","getPaddingBySize"],"sources":["../../../../style-runtime/src/index.ts","../../../src/card/style.module.scss","../../../src/card/card-body/hook.ts"],"sourcesContent":["type GlobalScopeWithStyleRuntime = typeof globalThis & {\n\t// This global is shared by separately bundled copies of this package.\n\t// Keep its shape backward compatible after release.\n\t__wpStyleRuntime?: {\n\t\tdocuments: Map< Document, number >;\n\t\tstyles: Map< string, string >;\n\t\tinjectedStyles: WeakMap< Document, Set< string > >;\n\t};\n};\n\nconst STYLE_HASH_ATTRIBUTE = 'data-wp-hash';\n\n/**\n * Returns the shared style runtime registry.\n *\n * The registry is stored on `globalThis` so separately bundled copies of this\n * package can coordinate through the same document and style maps.\n *\n * @return The shared runtime registry.\n */\nfunction getRuntime() {\n\tconst globalScope = globalThis as GlobalScopeWithStyleRuntime;\n\n\tif ( globalScope.__wpStyleRuntime ) {\n\t\treturn globalScope.__wpStyleRuntime;\n\t}\n\n\tglobalScope.__wpStyleRuntime = {\n\t\tdocuments: new Map(),\n\t\tstyles: new Map(),\n\t\tinjectedStyles: new WeakMap(),\n\t};\n\n\tif ( typeof document !== 'undefined' ) {\n\t\tregisterDocument( document );\n\t}\n\n\treturn globalScope.__wpStyleRuntime;\n}\n\n/**\n * Checks whether a document already contains a style tag for a hash.\n *\n * @param targetDocument Document to inspect.\n * @param hash Stable hash for the transformed CSS.\n *\n * @return Whether the style hash already exists in the document.\n */\nfunction documentContainsStyleHash(\n\ttargetDocument: Document,\n\thash: string\n): boolean {\n\tif ( ! targetDocument.head ) {\n\t\treturn false;\n\t}\n\n\tfor ( const style of targetDocument.head.querySelectorAll(\n\t\t`style[${ STYLE_HASH_ATTRIBUTE }]`\n\t) ) {\n\t\tif ( style.getAttribute( STYLE_HASH_ATTRIBUTE ) === hash ) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Injects a registered style into a document, unless that document already\n * contains a style tag for the same hash.\n *\n * @param targetDocument Document to inject the style into.\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nfunction injectStyle( targetDocument: Document, hash: string, css: string ) {\n\tif ( ! targetDocument.head ) {\n\t\treturn;\n\t}\n\n\tconst runtime = getRuntime();\n\tlet injectedStyles = runtime.injectedStyles.get( targetDocument );\n\n\tif ( ! injectedStyles ) {\n\t\tinjectedStyles = new Set();\n\t\truntime.injectedStyles.set( targetDocument, injectedStyles );\n\t}\n\n\tif ( injectedStyles.has( hash ) ) {\n\t\treturn;\n\t}\n\n\t// Older generated CSS module output can still inject matching style tags\n\t// after this document's cache is created, so keep the DOM as the fallback\n\t// source of truth on cache misses.\n\tif ( documentContainsStyleHash( targetDocument, hash ) ) {\n\t\tinjectedStyles.add( hash );\n\t\treturn;\n\t}\n\n\tconst style = targetDocument.createElement( 'style' );\n\tstyle.setAttribute( STYLE_HASH_ATTRIBUTE, hash );\n\tstyle.appendChild( targetDocument.createTextNode( css ) );\n\ttargetDocument.head.appendChild( style );\n\tinjectedStyles.add( hash );\n}\n\n/**\n * Registers a document as a style injection target.\n *\n * Existing registered styles are replayed into the document immediately.\n * Documents are reference-counted so multiple providers can safely register the\n * same document without one cleanup removing it while another registration is\n * still active.\n *\n * @param targetDocument Document to receive registered styles.\n * @return Cleanup function that unregisters this document registration.\n */\nexport function registerDocument( targetDocument: Document ) {\n\tconst runtime = getRuntime();\n\n\truntime.documents.set(\n\t\ttargetDocument,\n\t\t( runtime.documents.get( targetDocument ) ?? 0 ) + 1\n\t);\n\n\tfor ( const [ hash, css ] of runtime.styles ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n\n\treturn () => {\n\t\tconst count = runtime.documents.get( targetDocument );\n\n\t\tif ( count === undefined ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( count <= 1 ) {\n\t\t\truntime.documents.delete( targetDocument );\n\t\t\treturn;\n\t\t}\n\n\t\truntime.documents.set( targetDocument, count - 1 );\n\t};\n}\n\n/**\n * Registers a style and injects it into all registered documents.\n *\n * The hash is used as the deduplication key, so calling this repeatedly with\n * the same hash will not add duplicate style tags to a document.\n * Registered styles are retained for the lifetime of the page so they can be\n * replayed into documents that are registered later.\n *\n * @param hash Stable hash for the transformed CSS.\n * @param css CSS text to inject.\n */\nexport function registerStyle( hash: string, css: string ) {\n\tconst runtime = getRuntime();\n\n\truntime.styles.set( hash, css );\n\n\tfor ( const targetDocument of runtime.documents.keys() ) {\n\t\tinjectStyle( targetDocument, hash, css );\n\t}\n}\n","import { registerStyle } from '@wordpress/style-runtime';\nif (typeof process === 'undefined' || process.env.NODE_ENV !== 'test') {\n\tregisterStyle(\"fc4ee5131a\", \"._258c1ce2d4e16874__card{box-shadow:0 0 0 var(--wpds-border-width-xs,1px) var(--wpds-color-stroke-surface-neutral,#dbdbdb);outline:none}._42c9e5f64a3fb269__card-borderless{box-shadow:none}.b64e8d4efff00058__is-rounded{border-radius:max(0px,var(--wpds-border-radius-lg,8px) - var(--wpds-border-width-xs,1px))}.d797cd7f1fd46312__content{height:100%}._115fc6b628947900__header{border-bottom:var(--wpds-border-width-xs,1px) solid var(--wpds-color-stroke-surface-neutral,#dbdbdb);border-color:var(--wpds-color-stroke-surface-neutral,#dbdbdb);box-sizing:border-box}._115fc6b628947900__header:last-child{border-bottom:none}._7269faf6c95b0762__footer{border-top:var(--wpds-border-width-xs,1px) solid var(--wpds-color-stroke-surface-neutral,#dbdbdb);border-color:var(--wpds-color-stroke-surface-neutral,#dbdbdb);box-sizing:border-box}._7269faf6c95b0762__footer:first-of-type{border-top:none}.e01b9e3e951a7d13__body{box-sizing:border-box;height:auto;max-height:100%}._9a163c498b5de7d8__is-scrollable{height:100%}._81765b2289fa1461__media{box-sizing:border-box;overflow:hidden}._81765b2289fa1461__media>iframe,._81765b2289fa1461__media>img{display:block;height:auto;max-width:100%;width:100%}._115fc6b628947900__header:first-of-type,._7269faf6c95b0762__footer:first-of-type,._81765b2289fa1461__media:first-of-type,.e01b9e3e951a7d13__body:first-of-type{border-start-end-radius:max(0px,var(--wpds-border-radius-lg,8px) - var(--wpds-border-width-xs,1px));border-start-start-radius:max(0px,var(--wpds-border-radius-lg,8px) - var(--wpds-border-width-xs,1px))}._115fc6b628947900__header:last-of-type,._7269faf6c95b0762__footer:last-of-type,._81765b2289fa1461__media:last-of-type,.e01b9e3e951a7d13__body:last-of-type{border-end-end-radius:max(0px,var(--wpds-border-radius-lg,8px) - var(--wpds-border-width-xs,1px));border-end-start-radius:max(0px,var(--wpds-border-radius-lg,8px) - var(--wpds-border-width-xs,1px))}._67309c75691cb06e__divider._67309c75691cb06e__divider{--_wp-components-divider-border-width:var(--wpds-border-width-xs,1px);border-color:var(--wpds-color-stroke-surface-neutral,#dbdbdb);box-sizing:border-box;display:block;width:100%}._0737e0d02ce50a60__section-borderless{border:none}._0c62836e2455867c__is-shady{background-color:var(--wp-components-color-gray-100,var(--wpds-color-background-surface-neutral,#fcfcfc))}.f81bbb6338f6c1cc__padding-none{padding:0}._9effffc1b0e250eb__padding-x-small{padding:var(--wpds-dimension-padding-sm,8px)}._397f1b1b1183f5eb__padding-small{padding:var(--wpds-dimension-padding-lg,16px)}._6c9d36c046b7cbb4__padding-medium{padding:var(--wpds-dimension-padding-lg,16px) var(--wpds-dimension-padding-2xl,24px)}._1b850e5f88c05181__padding-large{padding:var(--wpds-dimension-padding-2xl,24px) var(--wpds-dimension-padding-3xl,32px)}.dac29efbc1e0a342__padding-block-start-none{padding-block-start:0}._7911a5ed70dd0454__padding-block-start-x-small{padding-block-start:var(--wpds-dimension-padding-sm,8px)}._105b22e497345ed9__padding-block-start-small{padding-block-start:var(--wpds-dimension-padding-lg,16px)}._4bea5996d0e8808d__padding-block-start-medium{padding-block-start:var(--wpds-dimension-padding-2xl,24px)}.a9bed7cfe29148ea__padding-block-start-large{padding-block-start:var(--wpds-dimension-padding-3xl,32px)}.faa4d8781487cdb9__padding-block-end-none{padding-block-end:0}._59d7036134a4077d__padding-block-end-x-small{padding-block-end:var(--wpds-dimension-padding-sm,8px)}.ba0f51a7d38005b3__padding-block-end-small{padding-block-end:var(--wpds-dimension-padding-lg,16px)}._64c618b6d8247db6__padding-block-end-medium{padding-block-end:var(--wpds-dimension-padding-2xl,24px)}.a1204142117f795d__padding-block-end-large{padding-block-end:var(--wpds-dimension-padding-3xl,32px)}.b5c8dd48cd3e52da__padding-inline-start-none{padding-inline-start:0}._32e9274059a97f16__padding-inline-start-x-small{padding-inline-start:var(--wpds-dimension-padding-sm,8px)}.c1a2d6a93b5d9e4f__padding-inline-start-small{padding-inline-start:var(--wpds-dimension-padding-lg,16px)}._7fbe71e16a09d777__padding-inline-start-medium{padding-inline-start:var(--wpds-dimension-padding-2xl,24px)}._7302b4da797b4293__padding-inline-start-large{padding-inline-start:var(--wpds-dimension-padding-3xl,32px)}._645cf5620059df75__padding-inline-end-none{padding-inline-end:0}._65f785a54d92961e__padding-inline-end-x-small{padding-inline-end:var(--wpds-dimension-padding-sm,8px)}._2c809d7e946fd61a__padding-inline-end-small{padding-inline-end:var(--wpds-dimension-padding-lg,16px)}.b83dda04e1b53ccb__padding-inline-end-medium{padding-inline-end:var(--wpds-dimension-padding-2xl,24px)}.da9b6af297e2b763__padding-inline-end-large{padding-inline-end:var(--wpds-dimension-padding-3xl,32px)}\");\n}\nexport default {\"card\":\"_258c1ce2d4e16874__card\",\"card-borderless\":\"_42c9e5f64a3fb269__card-borderless\",\"is-rounded\":\"b64e8d4efff00058__is-rounded\",\"content\":\"d797cd7f1fd46312__content\",\"header\":\"_115fc6b628947900__header\",\"footer\":\"_7269faf6c95b0762__footer\",\"body\":\"e01b9e3e951a7d13__body\",\"is-scrollable\":\"_9a163c498b5de7d8__is-scrollable\",\"media\":\"_81765b2289fa1461__media\",\"divider\":\"_67309c75691cb06e__divider\",\"section-borderless\":\"_0737e0d02ce50a60__section-borderless\",\"is-shady\":\"_0c62836e2455867c__is-shady\",\"padding-none\":\"f81bbb6338f6c1cc__padding-none\",\"padding-x-small\":\"_9effffc1b0e250eb__padding-x-small\",\"padding-small\":\"_397f1b1b1183f5eb__padding-small\",\"padding-medium\":\"_6c9d36c046b7cbb4__padding-medium\",\"padding-large\":\"_1b850e5f88c05181__padding-large\",\"padding-block-start-none\":\"dac29efbc1e0a342__padding-block-start-none\",\"padding-block-start-x-small\":\"_7911a5ed70dd0454__padding-block-start-x-small\",\"padding-block-start-small\":\"_105b22e497345ed9__padding-block-start-small\",\"padding-block-start-medium\":\"_4bea5996d0e8808d__padding-block-start-medium\",\"padding-block-start-large\":\"a9bed7cfe29148ea__padding-block-start-large\",\"padding-block-end-none\":\"faa4d8781487cdb9__padding-block-end-none\",\"padding-block-end-x-small\":\"_59d7036134a4077d__padding-block-end-x-small\",\"padding-block-end-small\":\"ba0f51a7d38005b3__padding-block-end-small\",\"padding-block-end-medium\":\"_64c618b6d8247db6__padding-block-end-medium\",\"padding-block-end-large\":\"a1204142117f795d__padding-block-end-large\",\"padding-inline-start-none\":\"b5c8dd48cd3e52da__padding-inline-start-none\",\"padding-inline-start-x-small\":\"_32e9274059a97f16__padding-inline-start-x-small\",\"padding-inline-start-small\":\"c1a2d6a93b5d9e4f__padding-inline-start-small\",\"padding-inline-start-medium\":\"_7fbe71e16a09d777__padding-inline-start-medium\",\"padding-inline-start-large\":\"_7302b4da797b4293__padding-inline-start-large\",\"padding-inline-end-none\":\"_645cf5620059df75__padding-inline-end-none\",\"padding-inline-end-x-small\":\"_65f785a54d92961e__padding-inline-end-x-small\",\"padding-inline-end-small\":\"_2c809d7e946fd61a__padding-inline-end-small\",\"padding-inline-end-medium\":\"b83dda04e1b53ccb__padding-inline-end-medium\",\"padding-inline-end-large\":\"da9b6af297e2b763__padding-inline-end-large\"};\n","import clsx from 'clsx';\nimport type { WordPressComponentProps } from '../../context';\nimport { useContextSystem } from '../../context';\nimport styles from '../style.module.scss';\nimport type { BodyProps } from '../types';\nimport { getPaddingBySize } from '../get-padding-by-size';\n\nexport function useCardBody(\n\tprops: WordPressComponentProps< BodyProps, 'div' >\n) {\n\tconst {\n\t\tclassName,\n\t\tisScrollable = false,\n\t\tisShady = false,\n\t\tsize = 'medium',\n\t\t...otherProps\n\t} = useContextSystem( props, 'CardBody' );\n\n\tconst classes = clsx(\n\t\tstyles.body,\n\t\tgetPaddingBySize( size ),\n\t\t{\n\t\t\t[ styles[ 'is-scrollable' ] ]: isScrollable,\n\t\t\t[ styles[ 'is-shady' ] ]: isShady,\n\t\t},\n\t\t// This classname is added for legacy compatibility reasons.\n\t\t'components-card__body',\n\t\tclassName\n\t);\n\n\treturn {\n\t\t...otherProps,\n\t\tclassName: classes,\n\t\tisScrollable,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAM,uBAAuB;;;;;;;;;AAU7B,SAAS,aAAa;CACrB,MAAM,cAAc;CAEpB,IAAK,YAAY,kBAChB,OAAO,YAAY;CAGpB,YAAY,mBAAmB;EAC9B,2BAAW,IAAI,IAAI;EACnB,wBAAQ,IAAI,IAAI;EAChB,gCAAgB,IAAI,QAAQ;CAC7B;CAEA,IAAK,OAAO,aAAa,aACxB,iBAAkB,QAAS;CAG5B,OAAO,YAAY;AACpB;;;;;;;;;AAUA,SAAS,0BACR,gBACA,MACU;CACV,IAAK,CAAE,eAAe,MACrB,OAAO;CAGR,KAAM,MAAM,SAAS,eAAe,KAAK,iBACxC,SAAU,qBAAsB,EACjC,GACC,IAAK,MAAM,aAAc,oBAAqB,MAAM,MACnD,OAAO;CAIT,OAAO;AACR;;;;;;;;;AAUA,SAAS,YAAa,gBAA0B,MAAc,KAAc;CAC3E,IAAK,CAAE,eAAe,MACrB;CAGD,MAAM,UAAU,WAAW;CAC3B,IAAI,iBAAiB,QAAQ,eAAe,IAAK,cAAe;CAEhE,IAAK,CAAE,gBAAiB;EACvB,iCAAiB,IAAI,IAAI;EACzB,QAAQ,eAAe,IAAK,gBAAgB,cAAe;CAC5D;CAEA,IAAK,eAAe,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