diff --git a/Packages/API_DOC/index.md b/Packages/API_DOC/index.md index a554188..96071d5 100644 --- a/Packages/API_DOC/index.md +++ b/Packages/API_DOC/index.md @@ -1,19 +1,22 @@ -# API详解 +# API 详解 ## normalizeVNode -child == null 或者child是布尔值,创建并返回Comment类型VNode。 -child为数组类型,创建并返回Fragment类型VNnode,child作为子VNode。 +child == null 或者 child 是布尔值,创建并返回 Comment 类型 VNode。 -child为其他类型,创建并返回Text类型VNode,child作为子VNode。 +child 为数组类型,创建并返回 Fragment 类型 VNnode,child 作为子 VNode。 + +child 为其他类型,创建并返回 Text 类型 VNode,child 作为子 VNode。。。 #### 语法 + ```typescript export function normalizeVNode(child: VNodeChild): VNode { if (child == null || typeof child === 'boolean') { // empty placeholder return createVNode(Comment) - } else if (isArray(child)) { // [h('div, 'one'), two] 数组就是fragment了 normalizeVnode 来进行vnode的转换 其实也就是 type 为 fragment child 为那个数组罢了 + } else if (isArray(child)) { + // [h('div, 'one'), two] 数组就是fragment了 normalizeVnode 来进行vnode的转换 其实也就是 type 为 fragment child 为那个数组罢了 // fragment return createVNode(Fragment, null, child) } else if (typeof child === 'object') { @@ -28,17 +31,19 @@ export function normalizeVNode(child: VNodeChild): VNode { ``` #### 参数(选填) + child,VNodeChild #### 返回值 -VNode类型 - +VNode 类型 ## getFallthroughAttrs -遍历attrs,返回,过滤掉键不为'class'或者'style'或者正则匹配为on开头的键值对,并返回。 + +遍历 attrs,返回,过滤掉键不为'class'或者'style'或者正则匹配为 on 开头的键值对,并返回。 #### 代码 + ```typescript type Data = { [key: string]: unknown } @@ -54,13 +59,12 @@ const getFallthroughAttrs = (attrs: Data): Data | undefined => { ``` #### 返回值 -undefined | Data - +undefined | Data ## defineComponent -在创建组件的时候,使用该方法可以使用typescript的类型检测,参数补充。 +在创建组件的时候,使用该方法可以使用 typescript 的类型检测,参数补充。 #### 代码 @@ -117,8 +121,8 @@ interface LegacyOptions< #### 参数 -options,Funtion类型或者LegacyOptions类型 +options,Funtion 类型或者 LegacyOptions 类型 #### 返回值 -LegacyOptions | { setup: Function } \ No newline at end of file +LegacyOptions | { setup: Function } diff --git a/book/gitbook/gitbook-plugin-fontsettings/fontsettings.js b/book/gitbook/gitbook-plugin-fontsettings/fontsettings.js deleted file mode 100644 index ff7be71..0000000 --- a/book/gitbook/gitbook-plugin-fontsettings/fontsettings.js +++ /dev/null @@ -1,240 +0,0 @@ -require(['gitbook', 'jquery'], function(gitbook, $) { - // Configuration - var MAX_SIZE = 4, - MIN_SIZE = 0, - BUTTON_ID; - - // Current fontsettings state - var fontState; - - // Default themes - var THEMES = [ - { - config: 'white', - text: 'White', - id: 0 - }, - { - config: 'sepia', - text: 'Sepia', - id: 1 - }, - { - config: 'night', - text: 'Night', - id: 2 - } - ]; - - // Default font families - var FAMILIES = [ - { - config: 'serif', - text: 'Serif', - id: 0 - }, - { - config: 'sans', - text: 'Sans', - id: 1 - } - ]; - - // Return configured themes - function getThemes() { - return THEMES; - } - - // Modify configured themes - function setThemes(themes) { - THEMES = themes; - updateButtons(); - } - - // Return configured font families - function getFamilies() { - return FAMILIES; - } - - // Modify configured font families - function setFamilies(families) { - FAMILIES = families; - updateButtons(); - } - - // Save current font settings - function saveFontSettings() { - gitbook.storage.set('fontState', fontState); - update(); - } - - // Increase font size - function enlargeFontSize(e) { - e.preventDefault(); - if (fontState.size >= MAX_SIZE) return; - - fontState.size++; - saveFontSettings(); - } - - // Decrease font size - function reduceFontSize(e) { - e.preventDefault(); - if (fontState.size <= MIN_SIZE) return; - - fontState.size--; - saveFontSettings(); - } - - // Change font family - function changeFontFamily(configName, e) { - if (e && e instanceof Event) { - e.preventDefault(); - } - - var familyId = getFontFamilyId(configName); - fontState.family = familyId; - saveFontSettings(); - } - - // Change type of color theme - function changeColorTheme(configName, e) { - if (e && e instanceof Event) { - e.preventDefault(); - } - - var $book = gitbook.state.$book; - - // Remove currently applied color theme - if (fontState.theme !== 0) - $book.removeClass('color-theme-'+fontState.theme); - - // Set new color theme - var themeId = getThemeId(configName); - fontState.theme = themeId; - if (fontState.theme !== 0) - $book.addClass('color-theme-'+fontState.theme); - - saveFontSettings(); - } - - // Return the correct id for a font-family config key - // Default to first font-family - function getFontFamilyId(configName) { - // Search for plugin configured font family - var configFamily = $.grep(FAMILIES, function(family) { - return family.config == configName; - })[0]; - // Fallback to default font family - return (!!configFamily)? configFamily.id : 0; - } - - // Return the correct id for a theme config key - // Default to first theme - function getThemeId(configName) { - // Search for plugin configured theme - var configTheme = $.grep(THEMES, function(theme) { - return theme.config == configName; - })[0]; - // Fallback to default theme - return (!!configTheme)? configTheme.id : 0; - } - - function update() { - var $book = gitbook.state.$book; - - $('.font-settings .font-family-list li').removeClass('active'); - $('.font-settings .font-family-list li:nth-child('+(fontState.family+1)+')').addClass('active'); - - $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); - $book.addClass('font-size-'+fontState.size); - $book.addClass('font-family-'+fontState.family); - - if(fontState.theme !== 0) { - $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); - $book.addClass('color-theme-'+fontState.theme); - } - } - - function init(config) { - // Search for plugin configured font family - var configFamily = getFontFamilyId(config.family), - configTheme = getThemeId(config.theme); - - // Instantiate font state object - fontState = gitbook.storage.get('fontState', { - size: config.size || 2, - family: configFamily, - theme: configTheme - }); - - update(); - } - - function updateButtons() { - // Remove existing fontsettings buttons - if (!!BUTTON_ID) { - gitbook.toolbar.removeButton(BUTTON_ID); - } - - // Create buttons in toolbar - BUTTON_ID = gitbook.toolbar.createButton({ - icon: 'fa fa-font', - label: 'Font Settings', - className: 'font-settings', - dropdown: [ - [ - { - text: 'A', - className: 'font-reduce', - onClick: reduceFontSize - }, - { - text: 'A', - className: 'font-enlarge', - onClick: enlargeFontSize - } - ], - $.map(FAMILIES, function(family) { - family.onClick = function(e) { - return changeFontFamily(family.config, e); - }; - - return family; - }), - $.map(THEMES, function(theme) { - theme.onClick = function(e) { - return changeColorTheme(theme.config, e); - }; - - return theme; - }) - ] - }); - } - - // Init configuration at start - gitbook.events.bind('start', function(e, config) { - var opts = config.fontsettings; - - // Generate buttons at start - updateButtons(); - - // Init current settings - init(opts); - }); - - // Expose API - gitbook.fontsettings = { - enlargeFontSize: enlargeFontSize, - reduceFontSize: reduceFontSize, - setTheme: changeColorTheme, - setFamily: changeFontFamily, - getThemes: getThemes, - setThemes: setThemes, - getFamilies: getFamilies, - setFamilies: setFamilies - }; -}); - -