docusaurus/assets/js/492798ca.60bbc570.js
2025-12-05 15:44:48 +00:00

2 lines
16 KiB
JavaScript

"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([["82201"],{41452:function(e,n,i){i.d(n,{A:()=>r});let r={tabItem:"tabItem_pnkT"}},18416:function(e,n,i){i.d(n,{A:()=>r});let r={tabList:"tabList_Qoir",tabItem:"tabItem_AQgk"}},11344:function(e,n,i){i.d(n,{A:()=>r});let r={apiTable:"apiTable_e8hp"}},54323: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(24521),t=i(74848),a=i(56151),s=i(14729),l=i(13899),d=i(6125);let o={sidebar_position:8,slug:"/api/plugins/@docusaurus/plugin-ideal-image"},c="\u{1F4E6} 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,a.R)(),...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:"\u{1F4E6} 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.A,{groupId:"npm2yarn",children:[(0,t.jsx)(l.A,{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)(l.A,{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)(l.A,{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)(l.A,{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.A,{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,a.R)(),...e.components};return n?(0,t.jsx)(n,{...e,children:(0,t.jsx)(p,{...e})}):p(e)}},13899:function(e,n,i){i.d(n,{A:()=>s});var r=i(74848);i(96540);var t=i(11118),a=i(41452);function s({children:e,hidden:n,className:i}){return(0,r.jsx)("div",{role:"tabpanel",className:(0,t.A)(a.A.tabItem,i),hidden:n,children:e})}},14729:function(e,n,i){i.d(n,{A:()=>m});var r=i(74848),t=i(96540),a=i(11118),s=i(85208),l=i(31191),d=i(17060),o=i(30926),c=i(18416);function u({className:e,block:n,selectedValue:i,selectValue:t,tabValues:s}){let d=[],{blockElementScrollPositionUntilNextRender:o}=(0,l.a_)(),u=e=>{let n=e.currentTarget,r=s[d.indexOf(n)].value;r!==i&&(o(n),t(r))},h=e=>{let n=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{let i=d.indexOf(e.currentTarget)+1;n=d[i]??d[0];break}case"ArrowLeft":{let i=d.indexOf(e.currentTarget)-1;n=d[i]??d[d.length-1]}}n?.focus()};return(0,r.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":n},e),children:s.map(({value:e,label:n,attributes:t})=>(0,r.jsx)("li",{role:"tab",tabIndex:i===e?0:-1,"aria-selected":i===e,ref:e=>{d.push(e)},onKeyDown:h,onClick:u,...t,className:(0,a.A)("tabs__item",c.A.tabItem,t?.className,{"tabs__item--active":i===e}),children:n??e},e))})}function h({lazy:e,children:n,selectedValue:i}){let s=(Array.isArray(n)?n:[n]).filter(Boolean);if(e){let e=s.find(e=>e.props.value===i);return e?(0,t.cloneElement)(e,{className:(0,a.A)("margin-top--md",e.props.className)}):null}return(0,r.jsx)("div",{className:"margin-top--md",children:s.map((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==i}))})}function p(e){let n=(0,d.u)(e);return(0,r.jsxs)("div",{className:(0,a.A)(s.G.tabs.container,"tabs-container",c.A.tabList),children:[(0,r.jsx)(u,{...n,...e}),(0,r.jsx)(h,{...n,...e})]})}function m(e){let n=(0,o.A)();return(0,r.jsx)(p,{...e,children:(0,d.v)(e.children)},String(n))}},17060:function(e,n,i){i.d(n,{u:()=>u,v:()=>o});var r=i(96540),t=i(49519),a=i(57190),s=i(11864),l=i(84329),d=i(34123);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({value:e,tabValues:n}){return n.some(n=>n.value===e)}function u(e){let n,{defaultValue:i,queryString:u=!1,groupId:h}=e,p=function(e){let{values:n,children:i}=e;return(0,r.useMemo)(()=>{let e=n??o(i).map(({props:{value:e,label:n,attributes:i,default:r}})=>({value:e,label:n,attributes:i,default:r})),r=(0,l.XI)(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),[m,g]=(0,r.useState)(()=>(function({defaultValue:e,tabValues:n}){if(0===n.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!c({value:e,tabValues:n}))throw Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${n.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}let i=n.find(e=>e.default)??n[0];if(!i)throw Error("Unexpected error: 0 tabValues");return i.value})({defaultValue:i,tabValues:p})),[x,j]=function({queryString:e=!1,groupId:n}){let i=(0,t.W6)(),a=function({queryString:e=!1,groupId:n}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!n)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 n??null}({queryString:e,groupId:n});return[(0,s.aZ)(a),(0,r.useCallback)(e=>{if(!a)return;let n=new URLSearchParams(i.location.search);n.set(a,e),i.replace({...i.location,search:n.toString()})},[a,i])]}({queryString:u,groupId:h}),[f,b]=function({groupId:e}){let n=e?`docusaurus.tab.${e}`:null,[i,t]=(0,d.Dv)(n);return[i,(0,r.useCallback)(e=>{n&&t.set(e)},[n,t])]}({groupId:h}),v=c({value:n=x??f,tabValues:p})?n:null;return(0,a.A)(()=>{v&&g(v)},[v]),{selectedValue:m,selectValue:(0,r.useCallback)(e=>{if(!c({value:e,tabValues:p}))throw Error(`Can't select invalid tab value=${e}`);g(e),j(e),b(e)},[j,b,p]),tabValues:p}}},6125:function(e,n,i){i.d(n,{A:()=>o});var r=i(74848),t=i(96540),a=i(79024),s=i(49519),l=i(11344);let d=t.forwardRef(function({name:e,children:n},i){let l=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}(n),d=e?`${e}-${l}`:l,o=`#${d}`,c=(0,s.W6)();return(0,a.A)().collectAnchor(d),(0,r.jsx)("tr",{id:d,tabIndex:0,ref:c.location.hash===o?i:void 0,onClick:e=>{let n="TD"===e.target.tagName.toUpperCase(),i=!!window.getSelection()?.toString();n&&!i&&c.push(o)},onKeyDown:e=>{"Enter"===e.key&&c.push(o)},children:n.props.children})});function o({children:e,name:n}){if("table"!==e.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[i,a]=t.Children.toArray(e.props.children),s=(0,t.useRef)(null);(0,t.useEffect)(()=>{s.current?.focus()},[s]);let o=t.Children.map(a.props.children,e=>(0,r.jsx)(d,{name:n,ref:s,children:e}));return(0,r.jsxs)("table",{className:l.A.apiTable,children:[i,(0,r.jsx)("tbody",{children:o})]})}},56151:function(e,n,i){i.d(n,{R:()=>s,x:()=>l});var r=i(96540);let t={},a=r.createContext(t);function s(e){let n=r.useContext(a);return r.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(t):e.components||t:s(e.components),r.createElement(a.Provider,{value:n},e.children)}},24521:function(e){e.exports=JSON.parse('{"id":"api/plugins/plugin-ideal-image","title":"\u{1F4E6} 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":1764949318000,"sidebarPosition":8,"frontMatter":{"sidebar_position":8,"slug":"/api/plugins/@docusaurus/plugin-ideal-image"},"sidebar":"api","previous":{"title":"\u{1F4E6} plugin-google-tag-manager","permalink":"/docs/api/plugins/@docusaurus/plugin-google-tag-manager"},"next":{"title":"\u{1F4E6} plugin-css-cascade-layers","permalink":"/docs/api/plugins/@docusaurus/plugin-css-cascade-layers"}}')}}]);