mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-25 12:38:57 +02:00
2 lines
No EOL
16 KiB
JavaScript
2 lines
No EOL
16 KiB
JavaScript
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["1790"],{55701:function(e,n,i){i.d(n,{Z:()=>r});let r={tabItem:"tabItem_pnkT"}},93195:function(e,n,i){i.d(n,{Z:()=>r});let r={tabList:"tabList_Qoir",tabItem:"tabItem_AQgk"}},5759:function(e,n,i){i.d(n,{Z:()=>r});let r={apiTable:"apiTable_e8hp"}},46403:function(e,n,i){i.r(n),i.d(n,{assets:()=>u,contentTitle:()=>c,default:()=>m,frontMatter:()=>o,metadata:()=>r,toc:()=>h});var r=i(96283),t=i(85893),l=i(80980),s=i(4575),a=i(54636),d=i(7450);let o={sidebar_position:8,slug:"/api/plugins/@docusaurus/plugin-ideal-image"},c="\uD83D\uDCE6 plugin-ideal-image",u={},h=[{value:"Installation",id:"installation",level:2},{value:"Usage",id:"usage",level:2},{value:"Configuration",id:"configuration",level:2},{value:"Example configuration",id:"ex-config",level:3}];function p(e){let n={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,l.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n.header,{children:(0,t.jsx)(n.h1,{id:"-plugin-ideal-image",children:"\uD83D\uDCE6 plugin-ideal-image"})}),"\n","\n",(0,t.jsx)(n.p,{children:"Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder)."}),"\n",(0,t.jsx)(n.admonition,{type:"info",children:(0,t.jsxs)(n.p,{children:["By default, the plugin is ",(0,t.jsx)(n.strong,{children:"inactive in development"})," so you could always view full-scale images. If you want to debug the ideal image behavior, you could set the ",(0,t.jsx)(n.a,{href:"#disableInDev",children:(0,t.jsx)(n.code,{children:"disableInDev"})})," option to ",(0,t.jsx)(n.code,{children:"false"}),"."]})}),"\n",(0,t.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,t.jsxs)(s.Z,{groupId:"npm2yarn",children:[(0,t.jsx)(a.Z,{value:"npm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"npm install --save @docusaurus/plugin-ideal-image\n"})})}),(0,t.jsx)(a.Z,{value:"yarn",label:"Yarn",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"yarn add @docusaurus/plugin-ideal-image\n"})})}),(0,t.jsx)(a.Z,{value:"pnpm",label:"pnpm",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"pnpm add @docusaurus/plugin-ideal-image\n"})})}),(0,t.jsx)(a.Z,{value:"bun",label:"Bun",children:(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-bash",children:"bun add @docusaurus/plugin-ideal-image\n"})})})]}),"\n",(0,t.jsx)(n.h2,{id:"usage",children:"Usage"}),"\n",(0,t.jsx)(n.p,{children:"This plugin supports the PNG and JPG formats only."}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-jsx",children:"import Image from '@theme/IdealImage';\nimport thumbnail from './path/to/img.png';\n\n// your React code\n<Image img={thumbnail} />\n\n// or\n<Image img={require('./path/to/img.png')} />\n"})}),"\n",(0,t.jsxs)(n.admonition,{type:"warning",children:[(0,t.jsxs)(n.p,{children:["This plugin registers a ",(0,t.jsx)(n.a,{href:"https://webpack.js.org/loaders/",children:"Webpack loader"})," that changes the type of imported/require images:"]}),(0,t.jsxs)(n.ul,{children:["\n",(0,t.jsxs)(n.li,{children:["Before: ",(0,t.jsx)(n.code,{children:"string"})]}),"\n",(0,t.jsxs)(n.li,{children:["After: ",(0,t.jsx)(n.code,{children:'{preSrc: string, src: import("@theme/IdealImage").SrcImage}'})]}),"\n"]})]}),"\n",(0,t.jsxs)(n.admonition,{title:"For pnpm users",type:"warning",children:[(0,t.jsxs)(n.p,{children:["Starting with ",(0,t.jsx)(n.a,{href:"https://github.com/pnpm/pnpm/releases/tag/v10.0.0",children:"pnpm 10"}),", running ",(0,t.jsx)(n.code,{children:"pnpm install"})," won't run dependency install scripts by default. You'll need additional pnpm configuration (",(0,t.jsx)(n.a,{href:"https://github.com/lovell/sharp/issues/4343",children:"issue"}),") for our ",(0,t.jsx)(n.code,{children:"sharp"})," image resizing dependency to install correctly, such as:"]}),(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-json",metastring:'title="package.json"',children:'{\n "pnpm": {\n "onlyBuiltDependencies": ["fsevents"]\n }\n}\n'})})]}),"\n",(0,t.jsx)(n.h2,{id:"configuration",children:"Configuration"}),"\n",(0,t.jsx)(n.p,{children:"Accepted fields:"}),"\n",(0,t.jsx)(d.Z,{children:(0,t.jsxs)(n.table,{children:[(0,t.jsx)(n.thead,{children:(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.th,{children:"Option"}),(0,t.jsx)(n.th,{children:"Type"}),(0,t.jsx)(n.th,{children:"Default"}),(0,t.jsx)(n.th,{children:"Description"})]})}),(0,t.jsxs)(n.tbody,{children:[(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"name"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"string"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"ideal-img/[name].[hash:hex:7].[width].[ext]"})}),(0,t.jsx)(n.td,{children:"Filename template for output files."})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"sizes"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"number[]"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.em,{children:"original size"})}),(0,t.jsx)(n.td,{children:"Specify all widths you want to use. If a specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up)."})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"size"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"number"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.em,{children:"original size"})}),(0,t.jsx)(n.td,{children:"Specify one width you want to use; if the specified size exceeds the original image's width, the latter will be used (i.e. images won't be scaled up)"})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"min"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"number"})}),(0,t.jsx)(n.td,{}),(0,t.jsxs)(n.td,{children:["As an alternative to manually specifying ",(0,t.jsx)(n.code,{children:"sizes"}),", you can specify ",(0,t.jsx)(n.code,{children:"min"}),", ",(0,t.jsx)(n.code,{children:"max"})," and ",(0,t.jsx)(n.code,{children:"steps"}),", and the sizes will be generated for you."]})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"max"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"number"})}),(0,t.jsx)(n.td,{}),(0,t.jsxs)(n.td,{children:["See ",(0,t.jsx)(n.code,{children:"min"})," above"]})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"steps"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"number"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"4"})}),(0,t.jsxs)(n.td,{children:["Configure the number of images generated between ",(0,t.jsx)(n.code,{children:"min"})," and ",(0,t.jsx)(n.code,{children:"max"})," (inclusive)"]})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"quality"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"number"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"85"})}),(0,t.jsx)(n.td,{children:"JPEG compression quality"})]}),(0,t.jsxs)(n.tr,{children:[(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"disableInDev"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"boolean"})}),(0,t.jsx)(n.td,{children:(0,t.jsx)(n.code,{children:"true"})}),(0,t.jsxs)(n.td,{children:["You can test ideal image behavior in dev mode by setting this to ",(0,t.jsx)(n.code,{children:"false"}),". ",(0,t.jsx)(n.strong,{children:"Tip"}),": use ",(0,t.jsx)(n.a,{href:"https://www.browserstack.com/guide/how-to-perform-network-throttling-in-chrome",children:"network throttling"})," in your browser to simulate slow networks."]})]})]})]})}),"\n",(0,t.jsx)(n.h3,{id:"ex-config",children:"Example configuration"}),"\n",(0,t.jsx)(n.p,{children:"Here's an example configuration:"}),"\n",(0,t.jsx)(n.pre,{children:(0,t.jsx)(n.code,{className:"language-js",metastring:'title="docusaurus.config.js"',children:"export default {\n plugins: [\n [\n '@docusaurus/plugin-ideal-image',\n // highlight-start\n {\n quality: 70,\n max: 1030, // max resized image's size.\n min: 640, // min resized image's size. if original is lower, use that size.\n steps: 2, // the max number of images generated between min and max (inclusive)\n disableInDev: false,\n },\n // highlight-end\n ],\n ],\n};\n"})})]})}function m(e={}){let{wrapper:n}={...(0,l.a)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(p,{...e})}):p(e)}},54636:function(e,n,i){i.d(n,{Z:()=>s});var r=i(85893);i(67294);var t=i(90496),l=i(55701);function s(e){let{children:n,hidden:i,className:s}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,t.Z)(l.Z.tabItem,s),hidden:i,children:n})}},4575:function(e,n,i){i.d(n,{Z:()=>p});var r=i(85893),t=i(67294),l=i(90496),s=i(54947),a=i(30623),d=i(71607),o=i(93195);function c(e){let{className:n,block:i,selectedValue:t,selectValue:a,tabValues:d}=e,c=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.o5)(),h=e=>{let n=e.currentTarget,i=d[c.indexOf(n)].value;i!==t&&(u(n),a(i))},p=e=>{let n=null;switch(e.key){case"Enter":h(e);break;case"ArrowRight":{let i=c.indexOf(e.currentTarget)+1;n=c[i]??c[0];break}case"ArrowLeft":{let i=c.indexOf(e.currentTarget)-1;n=c[i]??c[c.length-1]}}n?.focus()};return(0,r.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,l.Z)("tabs",{"tabs--block":i},n),children:d.map(e=>{let{value:n,label:i,attributes:s}=e;return(0,r.jsx)("li",{role:"tab",tabIndex:t===n?0:-1,"aria-selected":t===n,ref:e=>{c.push(e)},onKeyDown:p,onClick:h,...s,className:(0,l.Z)("tabs__item",o.Z.tabItem,s?.className,{"tabs__item--active":t===n}),children:i??n},n)})})}function u(e){let{lazy:n,children:i,selectedValue:s}=e,a=(Array.isArray(i)?i:[i]).filter(Boolean);if(n){let e=a.find(e=>e.props.value===s);return e?(0,t.cloneElement)(e,{className:(0,l.Z)("margin-top--md",e.props.className)}):null}return(0,r.jsx)("div",{className:"margin-top--md",children:a.map((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==s}))})}function h(e){let n=(0,a.Y)(e);return(0,r.jsxs)("div",{className:(0,l.Z)("tabs-container",o.Z.tabList),children:[(0,r.jsx)(c,{...n,...e}),(0,r.jsx)(u,{...n,...e})]})}function p(e){let n=(0,d.Z)();return(0,r.jsx)(h,{...e,children:(0,a.h)(e.children)},String(n))}},30623:function(e,n,i){i.d(n,{Y:()=>u,h:()=>o});var r=i(67294),t=i(3620),l=i(844),s=i(97486),a=i(32263),d=i(16971);function o(e){return r.Children.toArray(e).filter(e=>"\n"!==e).map(e=>{if(!e||(0,r.isValidElement)(e)&&function(e){let{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return e;throw Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})?.filter(Boolean)??[]}function c(e){let{value:n,tabValues:i}=e;return i.some(e=>e.value===n)}function u(e){let{defaultValue:n,queryString:i=!1,groupId:u}=e,h=function(e){let{values:n,children:i}=e;return(0,r.useMemo)(()=>{let e=n??o(i).map(e=>{let{props:{value:n,label:i,attributes:r,default:t}}=e;return{value:n,label:i,attributes:r,default:t}}),r=(0,a.lx)(e,(e,n)=>e.value===n.value);if(r.length>0)throw Error(`Docusaurus error: Duplicate values "${r.map(e=>e.value).join(", ")}" found in <Tabs>. Every value needs to be unique.`);return e},[n,i])}(e),[p,m]=(0,r.useState)(()=>(function(e){let{defaultValue:n,tabValues:i}=e;if(0===i.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(n){if(!c({value:n,tabValues:i}))throw Error(`Docusaurus error: The <Tabs> has a defaultValue "${n}" but none of its children has the corresponding value. Available values are: ${i.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return n}let r=i.find(e=>e.default)??i[0];if(!r)throw Error("Unexpected error: 0 tabValues");return r.value})({defaultValue:n,tabValues:h})),[g,x]=function(e){let{queryString:n=!1,groupId:i}=e,l=(0,t.k6)(),a=function(e){let{queryString:n=!1,groupId:i}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!i)throw Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return i??null}({queryString:n,groupId:i});return[(0,s._X)(a),(0,r.useCallback)(e=>{if(!a)return;let n=new URLSearchParams(l.location.search);n.set(a,e),l.replace({...l.location,search:n.toString()})},[a,l])]}({queryString:i,groupId:u}),[j,f]=function(e){let{groupId:n}=e,i=n?`docusaurus.tab.${n}`:null,[t,l]=(0,d.Nk)(i);return[t,(0,r.useCallback)(e=>{i&&l.set(e)},[i,l])]}({groupId:u}),b=(()=>{let e=g??j;return c({value:e,tabValues:h})?e:null})();return(0,l.Z)(()=>{b&&m(b)},[b]),{selectedValue:p,selectValue:(0,r.useCallback)(e=>{if(!c({value:e,tabValues:h}))throw Error(`Can't select invalid tab value=${e}`);m(e),x(e),f(e)},[x,f,h]),tabValues:h}}},7450:function(e,n,i){i.d(n,{Z:()=>o});var r=i(85893),t=i(67294),l=i(30576),s=i(3620),a=i(5759);let d=t.forwardRef(function(e,n){let{name:i,children:a}=e,d=function(e){let n=e;for(;(0,t.isValidElement)(n);)[n]=t.Children.toArray(n.props.children);if("string"!=typeof n)throw Error(`Could not extract APITable row name from JSX tree:
|
|
${JSON.stringify(e,null,2)}`);return n}(a),o=i?`${i}-${d}`:d,c=`#${o}`,u=(0,s.k6)();return(0,l.Z)().collectAnchor(o),(0,r.jsx)("tr",{id:o,tabIndex:0,ref:u.location.hash===c?n:void 0,onClick:e=>{let n="TD"===e.target.tagName.toUpperCase(),i=!!window.getSelection()?.toString();n&&!i&&u.push(c)},onKeyDown:e=>{"Enter"===e.key&&u.push(c)},children:a.props.children})});function o(e){let{children:n,name:i}=e;if("table"!==n.type)throw Error("Bad usage of APITable component.\nIt is probably that your Markdown table is malformed.\nMake sure to double-check you have the appropriate number of columns for each table row.");let[l,s]=t.Children.toArray(n.props.children),o=(0,t.useRef)(null);(0,t.useEffect)(()=>{o.current?.focus()},[o]);let c=t.Children.map(s.props.children,e=>(0,r.jsx)(d,{name:i,ref:o,children:e}));return(0,r.jsxs)("table",{className:a.Z.apiTable,children:[l,(0,r.jsx)("tbody",{children:c})]})}},80980:function(e,n,i){i.d(n,{Z:()=>a,a:()=>s});var r=i(67294);let t={},l=r.createContext(t);function s(e){let n=r.useContext(l);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),r.createElement(l.Provider,{value:n},e.children)}},96283:function(e){e.exports=JSON.parse('{"id":"api/plugins/plugin-ideal-image","title":"\uD83D\uDCE6 plugin-ideal-image","description":"Docusaurus Plugin to generate an almost ideal image (responsive, lazy-loading, and low quality placeholder).","source":"@site/docs/api/plugins/plugin-ideal-image.mdx","sourceDirName":"api/plugins","slug":"/api/plugins/@docusaurus/plugin-ideal-image","permalink":"/docs/api/plugins/@docusaurus/plugin-ideal-image","draft":false,"unlisted":false,"editUrl":"https://github.com/facebook/docusaurus/edit/main/website/docs/api/plugins/plugin-ideal-image.mdx","tags":[],"version":"current","lastUpdatedBy":"S\xe9bastien Lorber","lastUpdatedAt":1751542800000,"sidebarPosition":8,"frontMatter":{"sidebar_position":8,"slug":"/api/plugins/@docusaurus/plugin-ideal-image"},"sidebar":"api","previous":{"title":"\uD83D\uDCE6 plugin-google-tag-manager","permalink":"/docs/api/plugins/@docusaurus/plugin-google-tag-manager"},"next":{"title":"\uD83D\uDCE6 plugin-css-cascade-layers","permalink":"/docs/api/plugins/@docusaurus/plugin-css-cascade-layers"}}')}}]); |