1 Star 2 Fork 0

LvHuaiSheng / leafer-x-ruler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

leafer-x-ruler

标尺线插件

show

cover

运行

npm run start # 开始运行项目

npm run build # 打包插件代码,同时会创建types

npm run test # 自动化测试

usage

install

npm i leafer-x-ruler  

use

import { App } from 'leafer-ui'
import { Ruler } from 'leafer-x-ruler'

const app = new App({
  view: window,
  tree: {},
  editor: {},
})
const ruler = new Ruler(app)

// 添加自定义主题  
ruler.addTheme('custom1', {
  backgroundColor: '#6cb0ab',
  textColor: '#a45454',
  borderColor: '#6f4593',
  highlightColor: 'rgba(22,93,255,0.75)'
})

// 切换主题  
ruler.changeTheme('custom1')

// 启用、禁用  
ruler.enabled = false

QA

// 如果使用侧边栏的伸缩时标尺宽高并未同步更新,或许是因为画布的大小并未改变无法触发resize事件;如果想改变画布的大小并使标尺同步,需要自行监听窗口大小变化,并触发leafer-ui的resize事件,以下是在vue3中使用的示例: 
<template>
  <div ref="divRef"></div>
</template>
<script lang="ts" setup>
  import {useResizeObserver} from "@vueuse/core";

  const divRef = ref()

  onMounted(() => {
      useResizeObserver(divRef, (entries) => {
        const [entry] = entries
        const { width, height } = entry.contentRect
        // 这步是为了触发leafer-ui的resize事件,标尺在监听到resize事件后会重新渲染
        leafer.app.resize({ width, height })
      })
  })
</script>

内置属性

属性 说明 操作方式 类型 示例值 默认
enabled 启用、禁用 get / set boolean true true
theme 使用主题名称 get / set string dark light
rulerLeafer 标尺线层Leafer get Leafer - -
config 标尺设置 set RulerConfig - -
options 属性配置 set RulerOptions - -

内置方法

方法 说明 参数类型 示例值
changeEnabled 启用、禁用 (boolean) true
addTheme 添加自定义主题 (string,ThemeOption) -
removeTheme 移除自定义主题 (string) -
changeTheme 切换主题 (string) -
forceRender 强制渲染 -

RulerConfig

type RulerConfig = {
  /**
   * 是否启用标尺线
   */
  enabled: boolean
  /**
   * 标尺线主题,默认light,可选(light:明亮,dark:暗黑)
   */
  theme: string
}

RulerOptions

type RulerOptions = {
  ruleSize?: number; // 标尺宽高
  fontSize?: number; // 字体大小
  themes?: Map<string, ThemeOption>; // 主题,默认存在明亮(light)、暗黑(dark)主题,可覆盖
}

ThemeOption

type ThemeOption = {
  backgroundColor: string, // 背景色
  textColor: string, // 文字颜色
  borderColor: string, // 边框颜色
  highlightColor: string // 高亮颜色
}
The MIT License (MIT) Copyright (c) 2023-present, Lv Huai Sheng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

leafer-ui的标尺线插件 展开 收起
TypeScript 等 5 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/sourcenet/leafer-x-ruler.git
git@gitee.com:sourcenet/leafer-x-ruler.git
sourcenet
leafer-x-ruler
leafer-x-ruler
master

搜索帮助