import React, { useEffect, createContext, useState, useMemo } from 'react'; import { Link, Navigate, Route, Routes, useLocation } from 'react-router-dom'; import classnames from 'classnames'; import hljs from 'highlight.js/lib/core'; import typescript from 'highlight.js/lib/languages/typescript'; import vim from 'highlight.js/lib/languages/vim'; import API from './views/api'; import Introduction from './views/introduction'; import { IconButton } from './components'; import { loadImage } from './utils'; import useUploader from './hooks/use-uploader'; import styles from './style.less'; hljs.registerLanguage('vim', vim); hljs.registerLanguage('typescript', typescript); export const DEFAULT_PLACEHOLDER = './resources/images/block.png'; export const DocsContext = createContext<{ placeholder: HTMLImageElement | undefined; setPlaceholder: React.Dispatch>; }>({ placeholder: undefined, setPlaceholder: () => {}, }); const Docs = () => { const [uploadUrl, setUploadUrl] = useState(); const [placeholder, setPlaceholder] = useState(); const [outlineVisible, setOutlineVisible] = useState(false); const location = useLocation(); const uploader = useUploader(); // 当前页面大纲 const outline = useMemo< { title: string; anchor: string; group?: boolean; children?: { title: string; anchor: string; }[]; }[] >(() => { if (location.pathname === '/') { return [ { title: '功能演示', anchor: 'demonstration' }, { title: '快速开始', anchor: 'quick-start' }, { title: '更多配置', anchor: 'more-configuration' }, { title: '进阶使用', anchor: 'advanced-usage' }, { title: '使用注意', anchor: 'usage-notes' }, ]; } else if (location.pathname === '/documentation') { return [ { title: '核心类', anchor: 'core-class', group: true, children: [{ title: 'Texture', anchor: 'class%3A-texture' }], }, { title: '实用工具类', anchor: 'utils-class', group: true, children: [ { title: 'FabricTexture', anchor: 'class%3A-fabrictexture' }, { title: 'AbstractMode', anchor: 'class%3A-abstract-abstractmode' }, ], }, { title: '内置模式类', anchor: 'inbuilt-modes-class', group: true, children: [ { title: 'Skew', anchor: 'class%3A-skew' }, { title: 'Perspective', anchor: 'class%3A-perspective' }, { title: 'Warp', anchor: 'class%3A-warp' }, ], }, ]; } else { return []; } }, [location]); // 加载占位图 useEffect(() => { loadImage(DEFAULT_PLACEHOLDER).then(setPlaceholder); }, []); // 如果有锚点,自动滚动到该锚点 useEffect(() => { window.onload = function () { const anchor = window.location.hash; if (anchor) { const element = document.querySelector(anchor); if (element) { element.scrollIntoView({ behavior: 'smooth' }); } } }; }, []); return (

Fabric Texture

帮助你在 Canvas 2D 上高效实现图像扭曲变形效果。

} /> } /> } />
); }; export default Docs;