repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
gzm-design | github_2023 | LvHuaiSheng | typescript | dialogClose | const dialogClose = () => {
dialog && dialog.close()
dialog = undefined
} | /**
* 关闭dialog
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/colorPicker/index.ts#L21-L24 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | $contextmenu | function $contextmenu(options: MenuOptions, customSlots?: Record<string, Slot>) {
const container = genContainer(options)
const component = initInstance(options, container.container, container.isNew, customSlots)
return (component as unknown as Record<string, unknown>).exposed as ContextMenuInstance
} | //Show global contextmenu | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/contextMenu/ContextMenuInstance.ts#L52-L56 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | getX | const getX = (index: number): number => {
const count = props.hasAroundGutter ? index + 1 : index
return props.gutter * count + colWidth.value * index + offsetX.value
} | // 获取对应y下标的x的值 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/use/useLayout.ts#L24-L27 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | initY | const initY = (): void => {
posY.value = new Array(cols.value).fill(props.hasAroundGutter ? props.gutter : 0)
} | // 初始y | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/use/useLayout.ts#L30-L32 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | layoutHandle | const layoutHandle = async(): Promise<boolean> => {
return new Promise((resolve) => {
// 初始化y集合
initY()
// 构造列表
const items: HTMLElement[] = []
if (waterfallWrapper && waterfallWrapper.value) {
waterfallWrapper.value.childNodes.forEach... | // 排版 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/use/useLayout.ts#L38-L92 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | addAnimation | function addAnimation(props: WaterfallProps) {
return (item: HTMLElement, callback?: () => void) => {
const content = item!.firstChild as HTMLElement
if (content && !hasClass(content, props.animationPrefix)) {
const durationSec = `${props.animationDuration / 1000}s`
const del... | // 动画 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/use/useLayout.ts#L101-L127 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy.mount | mount(el: HTMLImageElement, binding: string | ValueFormatterObject, callback: CallbackFunction): void {
const { src, loading, error } = this._valueFormatter(binding)
el.setAttribute('lazy', LifecycleEnum.LOADING)
el.setAttribute('src', loading || DEFAULT_LOADING)
if (!this.lazyActive) {
... | // mount | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L45-L61 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy.resize | resize(el: HTMLImageElement, callback: () => void) {
const lazy = el.getAttribute('lazy')
const src = el.getAttribute('src')
if (lazy && lazy === LifecycleEnum.LOADED && src) {
loadImage(src, this.crossOrigin).then((image) => {
const { width, height } = image
... | // resize | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L64-L77 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy.unmount | unmount(el: HTMLElement): void {
const imgItem = this._realObserver(el)
imgItem && imgItem.unobserve(el)
this._images.delete(el)
} | // unmount | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L80-L84 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy._setImageSrc | _setImageSrc(el: HTMLImageElement, src: string, callback: CallbackFunction, error?: string): void {
if (!src)
return
const preSrc = el.getAttribute('src')
if (preSrc === src)
return
loadImage(src, this.crossOrigin)
.then((image) => {
... | /**
* 设置img的src
* @param {*} el - img
* @param {*} src - 原图
* @param {*} error - 错误图片
* @param {*} callback - 完成的回调函数,通知组件刷新布局
* @returns
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L94-L129 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy._initIntersectionObserver | _initIntersectionObserver(el: HTMLImageElement, src: string, callback: CallbackFunction, error?: string): void {
const observerOptions = this.options.observerOptions
this._images.set(
el,
new IntersectionObserver((entries) => {
Array.prototype.forEach.call(entries... | /**
* 添加img和对应的observer到weakMap中
* 开启监听
* 当出现在可视区域后取消监听
* @param {*} el - img
* @param {*} src - 图片
* @param {*} error - 错误图片
* @param {*} callback - 完成的回调函数,通知组件刷新布局
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L144-L161 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy._valueFormatter | _valueFormatter(value: ValueFormatterObject | string): ValueFormatterObject {
let src = value as string
let loading = this.options.loading
let error = this.options.error
if (isObject(value)) {
src = (value as ValueFormatterObject).src
loading = (value as ValueForm... | // 格式化参数 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L164-L178 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy._log | _log(callback: () => void): void {
if (this.options.log)
callback()
} | // 日志 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L181-L184 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Lazy._realObserver | _realObserver(el: HTMLElement): IntersectionObserver | undefined {
return this._images.get(el)
} | // 在map中获取对应img的observer事件 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/Lazy.ts#L187-L189 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | assignSymbols | function assignSymbols(target: any, ...args: any[]) {
if (!isObject(target))
throw new TypeError('expected the first argument to be an object')
if (args.length === 0 || typeof Symbol !== 'function' || typeof getSymbols !== 'function')
return target
for (const arg of args) {
const n... | /**
* Assign the enumerable es6 Symbol properties from one
* or more objects to the first object passed on the arguments.
* Can be used as a supplement to other extend, assign or
* merge methods as a polyfill for the Symbols part of
* the es6 Object.assign method.
* https://github.com/jonschlinkert/assign-symbols... | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/components/vue-waterfall-plugin-next/utils/util.ts#L110-L126 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | initFonts | async function initFonts() {
let list = []
localStorage.getItem('FONTS_VERSION') !== '1' && localStorage.removeItem('FONTS')
const localFonts: any = localStorage.getItem('FONTS') ? JSON.parse(localStorage.getItem('FONTS') || '') : []
if (localFonts.length > 0) {
list.push(...... | /**
* 初始化部分字体
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/store/modules/font/font.ts#L28-L44 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | isWindow | function isWindow(obj: any) {
return obj && obj === obj.window;
} | /**
* 返回是否window对象
*
* @export
* @param {any} obj
* @returns
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/dom.ts#L143-L145 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | LinkedList.size | get size(): number {
return this._size
} | // } | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/linkedList.ts#L47-L49 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HSLA.fromRGBA | static fromRGBA(rgba: RGBA): HSLA {
const r = rgba.r / 255
const g = rgba.g / 255
const b = rgba.b / 255
const a = rgba.a
const max = Math.max(r, g, b)
const min = Math.min(r, g, b)
let h = 0
let s = 0
const l = (min + max) / 2
const chroma = max - min
if (chroma > 0) {
... | /**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h in the set [0, 360], s, and l in the set [0, 1].
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L90-L122 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HSLA.toRGBA | static toRGBA(hsla: HSLA): RGBA {
const h = hsla.h / 360
const { s, l, a } = hsla
let r: number, g: number, b: number
if (s === 0) {
r = g = b = l // achromatic
} else {
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
const p = 2 * l - q
r = HSLA._hue2rgb(p, q, h + 1 / 3)
... | /**
* Converts an HSL color value to RGB. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes h in the set [0, 360] s, and l are contained in the set [0, 1] and
* returns r, g, and b in the set [0, 255].
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L149-L165 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HSVA.fromRGBA | static fromRGBA(rgba: RGBA): HSVA {
const r = rgba.r / 255
const g = rgba.g / 255
const b = rgba.b / 255
const cmax = Math.max(r, g, b)
const cmin = Math.min(r, g, b)
const delta = cmax - cmin
const s = cmax === 0 ? 0 : delta / cmax
let m: number
if (delta === 0) {
m = 0
}... | // from http://www.rapidtables.com/convert/color/rgb-to-hsv.htm | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L203-L224 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HSVA.toRGBA | static toRGBA(hsva: HSVA): RGBA {
const { h, s, v, a } = hsva
const c = v * s
const x = c * (1 - Math.abs(((h / 60) % 2) - 1))
const m = v - c
let [r, g, b] = [0, 0, 0]
if (h < 60) {
r = c
g = x
} else if (h < 120) {
r = x
g = c
} else if (h < 180) {
g = c
... | // from http://www.rapidtables.com/convert/color/hsv-to-rgb.htm | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L227-L259 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Color.getRelativeLuminance | getRelativeLuminance(): number {
const R = Color._relativeLuminanceForComponent(this.rgba.r)
const G = Color._relativeLuminanceForComponent(this.rgba.g)
const B = Color._relativeLuminanceForComponent(this.rgba.b)
const luminance = 0.2126 * R + 0.7152 * G + 0.0722 * B
return roundFloat(luminance, 4)... | /**
* http://www.w3.org/TR/WCAG20/#relativeluminancedef
* Returns the number in the set [0, 1]. O => Darkest Black. 1 => Lightest white.
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L324-L331 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Color.getContrastRatio | getContrastRatio(another: Color): number {
const lum1 = this.getRelativeLuminance()
const lum2 = another.getRelativeLuminance()
return lum1 > lum2 ? (lum1 + 0.05) / (lum2 + 0.05) : (lum2 + 0.05) / (lum1 + 0.05)
} | /**
* http://www.w3.org/TR/WCAG20/#contrast-ratiodef
* Returns the contrast ration number in the set [1, 21].
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L342-L346 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Color.isDarker | isDarker(): boolean {
const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000
return yiq < 128
} | /**
* http://24ways.org/2010/calculating-color-contrast
* Return 'true' if darker color otherwise 'false'
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L352-L355 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Color.isLighter | isLighter(): boolean {
const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000
return yiq >= 128
} | /**
* http://24ways.org/2010/calculating-color-contrast
* Return 'true' if lighter color otherwise 'false'
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L361-L364 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | _toTwoDigitHex | function _toTwoDigitHex(n: number): string {
const r = n.toString(16)
return r.length !== 2 ? '0' + r : r
} | // eslint-disable-next-line no-inner-declarations | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L537-L540 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | _parseHexDigit | function _parseHexDigit(charCode: CharCode): number {
switch (charCode) {
case CharCode.Digit0:
return 0
case CharCode.Digit1:
return 1
case CharCode.Digit2:
return 2
case CharCode.Digit3:
return 3
case CharCode.Di... | // eslint-disable-next-line no-inner-declarations | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/color.ts#L633-L681 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | GColor.equals | equals(color: string): boolean {
return tinyColor.equals(this.rgba, color);
} | /**
* 判断输入色是否与当前色相同
* @param color
* @returns
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/g-color.ts#L401-L403 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | GColor.isValid | static isValid(color: string): boolean {
if (parseGradientString(color)) {
return true;
}
return tinyColor(color).isValid();
} | /**
* 校验输入色是否是一个有效颜色
* @param color
* @returns
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/g-color.ts#L410-L415 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | GColor.object2color | static object2color(object: any, format: string) {
if (format === 'CMYK') {
const {
c, m, y, k
} = object;
return `cmyk(${c}, ${m}, ${y}, ${k})`;
}
const color = tinyColor(object, {
format,
});
return color.toRgbStri... | /**
* 对象转颜色字符串
* @param object
* @param format
* @returns
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/g-color.ts#L447-L458 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | GColor.isGradientColor | static isGradientColor = (input: string) => !!isGradientColor(input) | /**
* 比较两个颜色是否相同
* @param color1
* @param color2
* @returns
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/g-color.ts | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | combineRegExp | const combineRegExp = (regexpList: (string | RegExp)[], flags: string): RegExp => {
let source = '';
for (let i = 0; i < regexpList.length; i++) {
if (isString(regexpList[i])) {
source += regexpList[i];
} else {
source += (regexpList[i] as RegExp).source;
}
}
return new RegExp(source, fl... | /**
* Utility combine multiple regular expressions.
*
* @param {RegExp[]|string[]} regexpList List of regular expressions or strings.
* @param {string} flags Normal RegExp flags.
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/gradient.ts#L16-L26 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | generateRegExp | const generateRegExp = (): RegExpLib => {
// Note any variables with "Capture" in name include capturing bracket set(s).
const searchFlags = 'gi'; // ignore case for angles, "rgb" etc
const rAngle = /(?:[+-]?\d*\.?\d+)(?:deg|grad|rad|turn)/; // Angle +ive, -ive and angle types
// optional 2nd part
const rSide... | /**
* Generate the required regular expressions once.
*
* Regular Expressions are easier to manage this way and can be well described.
*
* @result {object} Object containing regular expressions.
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/gradient.ts#L53-L90 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | parseGradient | const parseGradient = (regExpLib: RegExpLib, input: string) => {
let result: ParseGradientResult;
let matchColorStop: any;
let stopResult: ColorStop;
// reset search position, because we reuse regex.
regExpLib.gradientSearch.lastIndex = 0;
const matchGradient = regExpLib.gradientSearch.exec(input);
if (... | /**
* Actually parse the input gradient parameters string into an object for reusability.
*
*
* @note Really this only supports the standard syntax not historical versions, see MDN for details
* https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient
*
* @param regExpLib
* @param {string} input
... | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/color/gradient.ts#L103-L158 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | setTxtStyle | const setTxtStyle = (layer: Layer, text: Text) => {
const style = layer.text.style;
const scale = textUtil.getAverageScale(layer.text.transform);
// 文字间距
text.letterSpacing = {
type: 'px',
value: textUtil.getLetterSpacing(layer)
};
// 这里需要注意的是 leafer不支持同时存在删除线和下划线,两者都存在则只保留下划线
... | /**
* 设置文本 style(样式) 属性
* @param layer
* @param text
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/psd/parser/text.ts#L173-L200 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | setTxtParagraphStyle | const setTxtParagraphStyle = (paragraphStyle: ParagraphStyle, text: Text) => {
if (paragraphStyle) {
if (paragraphStyle.justification) {
text.textAlign = textUtil.mapJustificationToTextAlign(paragraphStyle.justification);
}
// 默认都是垂直居中对齐
text.verticalAlign = 'middle';
... | /**
* 设置文本段落 paragraphStyle(样式) 属性
* @param paragraphStyle
* @param text
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/psd/parser/text.ts#L207-L216 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | setTextEff | const setTextEff = (effects: LayerEffectsInfo, text: Text) => {
// 下面开始设置文字效果
if (effects) {
// 描边
if (effects.stroke && effects.stroke.length > 0) {
let strokeArr: any[] = []
effects.stroke.map(stroke => {
if (stroke.enabled) {
let typ... | /**
* 设置文本 effects(效果) 属性
* @param effects
* @param text
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/utils/psd/parser/text.ts#L223-L251 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | addObjects | const addObjects = (groupData: object) => {
const group = new Group(groupData)
// 粘贴到当前位置
if (currentLocation) {
const {x, y} = appInstance.editor.contextMenu?.pointer || this.pointer
const point = this.activeObj... | // 插入元素到画板内 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/clipboard.ts#L83-L104 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | ToolBar.setSelect | private setSelect() {
this.penDraw.stop()
this.canvas.app.config.move.drag = false
this.canvas.app.tree.hittable = true
this.canvas.app.editor.hittable = true
} | /**
* 使用选择工具(编辑器)
* @private
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/toolBar.ts#L100-L105 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | ToolBar.setNoSelect | private setNoSelect() {
this.penDraw.stop()
this.canvas.app.config.move.drag = false
this.canvas.app.tree.hittable = false
this.canvas.app.editor.hittable = false
} | /**
* 设置不可选中、不可拖动
* @private
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/toolBar.ts#L111-L116 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | ToolBar.setMove | private setMove() {
this.penDraw.stop()
// this.canvas.contentLayer.hitChildren = true
// this.canvas.contentFrame.hitChildren = false
this.canvas.app.config.move.drag = true
} | /**
* 设置仅拖动
* @private
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/toolBar.ts#L122-L127 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | ToolBar.switchPen | private switchPen() {
this.penDraw.start()
} | /**
* 钢笔
* @private
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/toolBar.ts#L135-L137 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | ToolBar.switchVector | private switchVector() {
} | /**
* Vector | Pen | Path
* L: lineto, absolute
* M: moveto, absolute
* C: bezierCurveTo, absolute
* Q: quadraticCurveTo, absolute
* Z: closepath
* getPointOnPath
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/toolBar.ts#L148-L150 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | EditorUndoRedoService.loadJson | private async loadJson(json: string) {
this.disabledPropertyChangeWatch()
const undoRedo = this.getUndoRedo()
if (!undoRedo) return
const {instantiation} = undoRedo
try {
instantiation.pause()
await this.canvas.importJsonToCurrentPage(JSON.parse(json))
... | // private async loadJson(json: IUIInputData) { | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/undoRedo/undoRedoService.ts#L165-L179 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | EditorUndoRedoService.initWorkspace | private initWorkspace() {
const currentId = this.workspacesService.getCurrentId()
this.workspacesService.all().forEach((workspace) => {
this.undoRedos.set(workspace.id, {
instantiation: new UndoRedoBase(),
lastState: this.pageId === currentId ? this.getJson() ... | // 工作区 | 页面管理 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/app/editor/undoRedo/undoRedoService.ts#L204-L224 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.initWorkspace | private initWorkspace() {
this.workspacesService.all().forEach((workspace) => {
this.setPageJSON(workspace.id, {
children: [],
})
})
this.eventbus.on('workspaceAddAfter', ({newId}) => {
this.setPageJSON(newId, {
children: [],
... | // 工作区 | 页面管理 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L209-L253 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.initPageEditor | initPageEditor() {
// 创建基础画板
const frame = new Frame({
id: uuidv4(),
name: BOTTOM_CANVAS_NAME,
width: this.contentLayer.width,
height: this.contentLayer.height,
fill:[{
type:'solid',
color:'#ffffff'
}... | // 页面元素编辑器 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L256-L308 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.getPageJSON | public getPageJSON(id: string): Page | undefined {
if (id === this.pageId) {
return {
...this.pages.get(id),
children: this.ref._children.value,
}
}
return this.pages.get(id)
} | /**
* 根据id获取页面的json数据
* 注意:getPageJSON必须在setCurrentId之后执行,否则要页面中的数据可能还未保存
* @param id 页面ID
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L326-L334 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.selectObject | public selectObject(target: IUI | null) {
if (this.activeTool === 'select') { // 选择器
console.log('选中:', target)
this.app.editor.target = target
console.log('Editor element:', this.app.editor.element)
this.setActiveObjectValue(this.app.editor.element)
}
... | /**
* 选中元素
* @param target
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L406-L413 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.discardActiveObject | public discardActiveObject() {
this.app.editor.target = null
this.setActiveObjectValue(this.contentFrame)
} | /**
* 取消选中元素
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L418-L421 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.add | public add(_child: IUI, _index?: number) {
if (this.objectIsTypes(_child,'Group','Box')){
this.bindDragDrop(_child)
}
if (!_child.zIndex){
const topLevel = this.hierarchyService.getTopLevel().zIndex;
_child.zIndex = topLevel + 1;
}
this.content... | /**
* 添加元素
* @param _child 元素
* @param _index 层级
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L428-L441 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.addMany | public addMany(..._children: IUI[]) {
this.contentFrame.addMany(..._children)
this.childrenEffect()
} | /**
* 添加元素
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L446-L449 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.reLoadFromJSON | public reLoadFromJSON(json: Partial<Page | IUIInputData | any>) {
this.importJsonToCurrentPage(json, true)
this.setZoom(json.scale)
} | /**
* 重新加载json数据(一般用于切换页面)
* @param json
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L455-L458 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.importJsonToCurrentPage | public importJsonToCurrentPage(json: any, clearHistory?: boolean) {
if (clearHistory) {
this.contentFrame.clear()
}
console.log('json', json)
if (json) {
this.contentFrame.set(json)
this.discardActiveObject()
useAppStore().activeTool = 'sel... | /**
* 导入JSON到当前页中
* @param json json
* @param clearHistory 是否清除历史画布数据
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L465-L477 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.importPages | public async importPages(json: any, clearHistory?: boolean) {
if (!json) {
return Promise.reject(new Error('`json` is undefined'))
}
if (clearHistory) {
this.contentFrame.clear()
}
const serialized = typeof json === 'string' ? JSON.parse(json) : json
... | /**
* 导入JSON(多页)
* importPages
* @param pages 多页面json
* @param clearHistory 是否清除历史画布数据
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L499-L534 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.childrenEffect | public childrenEffect() {
this.ref._children.value = []
this.ref._children.value = this.contentFrame.children
} | /**
* 执行调度器 更新_children值
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L573-L576 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.findObjectById | public findObjectById(id: string | number): any | undefined {
const object = this.contentFrame.findOne(id)
return object
} | /**
* 根据ID查找对象
* @param id 要查找的对象的ID
* @returns 如果找到对象则返回一个FabricObject类型的对象,否则返回undefined
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L596-L599 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.findObjectsByIds | public findObjectsByIds(idsToFind: (string | number)[]): IUI[] {
const objects = this.app.tree.find(function (item) {
return idsToFind.includes(item.innerId) ? 1 : 0
})
return objects
} | /**
* 根据ID数组查找对象
* @param idsToFind 要查找的对象的ID数组
* @returns 返回一个包含Object类型对象的数组,数组中每个元素的值为对应的ID在对象集合中的对象。如果没有找到对象,则相应的数组元素值为undefined。
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L606-L611 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | MLeaferCanvas.bindDragDrop | public bindDragDrop(group: IUI){
const that = this
group.on(DragEvent.ENTER, function () {
DragEvent.setData({ data: 'drop data' })
})
group.on(DropEvent.DROP, function (e: DropEvent) {
e.list.forEach((leaf) => {
if (leaf.innerId !== group.innerId)... | /**
* 绑定组的元素拖动放置事件
* @param group
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/mLeaferCanvas.ts#L617-L634 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | PenDraw.start | public start() {
this.canDrawing = true
this.startDrawing();
this.continueDrawing();
this.stopDrawing();
} | /**
* 开始画
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/penDraw.ts#L37-L42 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | PenDraw.stop | public stop() {
this.canDrawing = false
this.pen = null
} | /**
* 开始画
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/canvas/penDraw.ts#L46-L49 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | Graph.findCycleSlow | findCycleSlow() {
for (const [id, node] of this._nodes) {
const seen = new Set<string>([id])
const res = this._findCycle(node, seen)
if (res) {
return res
}
}
return undefined
} | /**
* This is brute force and slow and **only** be used
* to trouble shoot.
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/instantiation/graph.ts#L83-L92 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.addItem | addItem(item: Item) {
this.items.push(item);
this.items = _.sortBy(this.items, 'zIndex');
} | // 添加项目 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L30-L33 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.updateOrAddItem | updateOrAddItem(item: Item) {
const existingItemIndex = _.findIndex(this.items, { key: item.key });
if (existingItemIndex !== -1) {
this.items[existingItemIndex] = item;
} else {
this.addItem(item);
}
} | // 修改元素或添加新元素 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L36-L43 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.removeItem | removeItem(key: number) {
_.remove(this.items, { key });
} | // 删除项目 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L45-L47 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.getPreviousLevel | getPreviousLevel(keys: number | number[]): Item {
const allKeys = Array.isArray(keys) ? keys : [keys];
const maxZIndexKey = Math.max(...allKeys.map(key => this.getItemByKey(key)?.zIndex || 0));
const index = _.findIndex(this.items, (item) => item.zIndex > maxZIndexKey);
return index !== ... | // 获取指定 key 的上一级 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L50-L55 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.getNextLevel | getNextLevel(keys: number | number[]): Item {
const allKeys = Array.isArray(keys) ? keys : [keys];
const maxZIndexKey = Math.max(...allKeys.map(key => this.getItemByKey(key)?.zIndex || 0));
const index = _.findLastIndex(this.items, (item) => item.zIndex < maxZIndexKey);
return index !== ... | // 获取指定 key 的下一级 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L58-L63 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.getTopLevel | getTopLevel(): Item {
return _.last(this.items) || defaultItem;
} | // 获取顶级 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L66-L68 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.getBottomLevel | getBottomLevel(): Item {
return _.first(this.items) || defaultItem;
} | // 获取最低级 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L71-L73 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | HierarchyService.getItemByKey | private getItemByKey(key: number): Item | undefined {
return _.find(this.items, { key });
} | // 根据 key 获取项目 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/layer/hierarchyService.ts#L76-L78 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | BarCode.calculateBarcodeWidth | public calculateBarcodeWidth(text: string, width: number, format: string) {
// 设置静态参数
var codeLength = text.length;
var quietZone = 10;
// 计算条形码宽度
var barcodeWidth = (width - quietZone * 2);
// 计算每个码的间隔
var barcodeUnitWidth = barcodeWidth / codeLength;
r... | // 定义函数来计算每个码的间隔 | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/core/shapes/BarCode.ts#L163-L174 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | convertCoordsToDeg | const convertCoordsToDeg = ({ x1, y1, x2, y2 }: LinearGradientCoords<number>) =>
(Math.atan2(y2 - y1, x2 - x1) * 180) / Math.PI + 90 | /**
* convertCoordsToDeg
* @param coords
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/hooks/useActiveObjectColor.ts#L35-L36 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | closeColorPicker | const closeColorPicker = () => {
closeFn && closeFn()
} | /** 关闭颜色选择器 */ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/hooks/useActiveObjectColor.ts#L102-L104 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | openColorPicker | const openColorPicker = (index:number) => {
ColorPicker.close()
appInstance.editor.service.invokeFunction((accessor) => {
const canvas = accessor.get(IMLeaferCanvas)
if (!isDefined(canvas.activeObject)) return
closeFn = ColorPicker.open({
object: canvas.activeObject.value,
attr... | /** 打开颜色选择器 */ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/hooks/useActiveObjectColor.ts#L107-L124 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | changeValue | const changeValue = (newValue: T, type: 'swipe' | 'change') => {
if (lockChange || !isDefined(activeObject)) return
setObjectValue(activeObject, newValue)
} | /**
* 更改值
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/hooks/useActiveObjectModel.ts#L73-L76 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | IdleValue.dispose | dispose(): void {
this._handle.dispose()
} | /** 用于释放该对象 */ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/utils/async.ts#L107-L109 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | IdleValue.value | get value(): T {
if (!this._didRun) {
this._handle.dispose()
this._executor()
}
if (this._error) {
throw this._error
}
return this._value!
} | /** 用于获取计算后的值 */ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/utils/async.ts#L112-L121 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | IdleValue.isInitialized | get isInitialized(): boolean {
return this._didRun
} | /** 用于检查该对象的值是否已经初始化过 */ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/utils/async.ts#L124-L126 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | DisposableStore.dispose | public dispose(): void {
if (this._isDisposed) {
return
}
this._isDisposed = true
this.clear()
} | /**
* Dispose of all registered disposables and mark this object as disposed.
*
* Any future disposables added to this object will be disposed of on `add`.
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/utils/lifecycle.ts#L76-L83 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | DisposableStore.isDisposed | public get isDisposed(): boolean {
return this._isDisposed
} | /**
* Returns `true` if this object has been disposed
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/utils/lifecycle.ts#L88-L90 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
gzm-design | github_2023 | LvHuaiSheng | typescript | DisposableStore.clear | public clear(): void {
if (this._toDispose.size === 0) {
return
}
try {
dispose(this._toDispose)
} finally {
this._toDispose.clear()
}
} | /**
* Dispose of all registered disposables but do not mark this object as disposed.
*/ | https://github.com/LvHuaiSheng/gzm-design/blob/6dc166eb6fd4b39cde64544180242ab2dce4ff4c/src/views/Editor/utils/lifecycle.ts#L95-L105 | 6dc166eb6fd4b39cde64544180242ab2dce4ff4c |
rename | github_2023 | JasonGrass | typescript | reload | async function reload() {
for (const file of files.value) {
try {
file.error = ""
await updateFile(file)
} catch (e: any) {
console.log("刷新失败", file.name)
console.error(e)
const message = typeof e === "string" ? e : e instanceof Error ? e.message : `未知错误 ${e}`
... | /**
* 从磁盘读取刷新文件信息
*/ | https://github.com/JasonGrass/rename/blob/385ebf2b78ddd76e27fb4034ed08a895040966d0/src/store/files.ts#L116-L132 | 385ebf2b78ddd76e27fb4034ed08a895040966d0 |
rename | github_2023 | JasonGrass | typescript | refresh | function refresh() {
// 更新引用,触发依赖项的更新,如序号的预览
files.value = [...files.value]
} | /**
* 更新依赖,触发响应式更新
*/ | https://github.com/JasonGrass/rename/blob/385ebf2b78ddd76e27fb4034ed08a895040966d0/src/store/files.ts#L137-L140 | 385ebf2b78ddd76e27fb4034ed08a895040966d0 |
rename | github_2023 | JasonGrass | typescript | clear | function clear() {
files.value = []
} | /**
* 清空文件记录
*/ | https://github.com/JasonGrass/rename/blob/385ebf2b78ddd76e27fb4034ed08a895040966d0/src/store/files.ts#L153-L155 | 385ebf2b78ddd76e27fb4034ed08a895040966d0 |
rename | github_2023 | JasonGrass | typescript | updateIndex | function updateIndex(file: FileItem) {
const files: FileItem[] = filteredFiles.value
const one = files.find((f) => f.hash === file.hash)
if (one) {
one.index = file.index
}
} | /**
* 更新排序索引
*/ | https://github.com/JasonGrass/rename/blob/385ebf2b78ddd76e27fb4034ed08a895040966d0/src/store/files.ts#L160-L166 | 385ebf2b78ddd76e27fb4034ed08a895040966d0 |
pyrodactyl | github_2023 | pyrohost | typescript | PyrodactylProvider | const PyrodactylProvider = ({ children }) => {
return (
<div
data-pyro-pyrodactylprovider=''
data-pyro-pyrodactyl-version={import.meta.env.VITE_PYRODACTYL_VERSION}
data-pyro-pyrodactyl-build={import.meta.env.VITE_PYRODACTYL_BUILD_NUMBER}
data-pyro-commit-hash=... | // Provides necessary information for components to function properly | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/components/PyrodactylProvider.tsx#L3-L17 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | Logo | const Logo = () => {
return (
<svg
xmlns='http://www.w3.org/2000/svg'
className='flex h-full w-full shrink-0'
width='284'
height='61'
fill='none'
viewBox='0 0 284 61'
>
<path
fill='url(#paint0_radial_... | // million-ignore | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/components/elements/PyroLogo.tsx#L2-L44 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | HugeIconsDatabase | const HugeIconsDatabase = (props: HugeIconProps) => {
return (
<svg
className={'h-6 w-6' + (props.className ? ` ${props.className}` : '')}
width='24'
height='24'
viewBox='0 0 24 24'
fill='none'
xmlns='http://www.w3.org/2000/svg'
... | // million-ignore | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/components/elements/hugeicons/Database.tsx#L4-L28 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | asModal | function asModal<P extends {}>(
modalProps?: SettableModalProps | ((props: P) => SettableModalProps),
): (Component: any) => any {
return function (Component) {
return class extends PureComponent<P & AsModalProps, State> {
static displayName = `asModal(${Component.displayName})`;
... | // eslint-disable-next-line @typescript-eslint/ban-types | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/hoc/asModal.tsx#L21-L97 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | mbToBytes | function mbToBytes(megabytes: number): number {
return Math.floor(megabytes * _CONVERSION_UNIT * _CONVERSION_UNIT);
} | /**
* Given a value in megabytes converts it back down into bytes.
*/ | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/lib/formatters.ts#L6-L8 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | bytesToString | function bytesToString(bytes: number, decimals = 2): string {
const k = _CONVERSION_UNIT;
if (bytes < 1) return '0 Bytes';
decimals = Math.floor(Math.max(0, decimals));
const i = Math.floor(Math.log(bytes) / Math.log(k));
const value = Number((bytes / Math.pow(k, i)).toFixed(decimals));
retur... | /**
* Given an amount of bytes, converts them into a human readable string format
* using "1024" as the divisor.
*/ | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/lib/formatters.ts#L14-L24 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | ip | function ip(value: string): string {
// noinspection RegExpSimplifiable
return /([a-f0-9:]+:+)+[a-f0-9]+/.test(value) ? `[${value}]` : value;
} | /**
* Formats an IPv4 or IPv6 address.
*/ | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/lib/formatters.ts#L29-L32 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | hexToRgba | function hexToRgba(hex: string, alpha = 1): string {
// noinspection RegExpSimplifiable
if (!/#?([a-fA-F0-9]{2}){3}/.test(hex)) {
return hex;
}
// noinspection RegExpSimplifiable
const [r, g, b] = hex.match(/[a-fA-F0-9]{2}/g)!.map((v) => parseInt(v, 16));
return `rgba(${r}, ${g}, ${b},... | /**
* Given a valid six character HEX color code, converts it into its associated
* RGBA value with a user controllable alpha channel.
*/ | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/lib/helpers.ts#L5-L15 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | isObject | function isObject(val: unknown): val is Record<string, unknown> {
return typeof val === 'object' && val !== null && !Array.isArray(val);
} | /**
* Determines if the value provided to the function is an object type that
* is not null.
*/ | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/lib/objects.ts#L5-L7 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | isEmptyObject | function isEmptyObject(val: {}): boolean {
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
} | /**
* Determines if an object is truly empty by looking at the keys present
* and the prototype value.
*/ | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/lib/objects.ts#L14-L16 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | getObjectKeys | function getObjectKeys<T extends {}>(o: T): (keyof T)[] {
return Object.keys(o) as (keyof typeof o)[];
} | /**
* A helper function for use in TypeScript that returns all of the keys
* for an object, but in a typed manner to make working with them a little
* easier.
*/ | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/lib/objects.ts#L24-L26 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | Websocket.connect | connect(url: string): this {
this.url = url;
this.socket = new Sockette(`${this.url}`, {
onmessage: (e) => {
try {
const { event, args } = JSON.parse(e.data);
args ? this.emit(event, ...args) : this.emit(event);
} catch... | // Connects to the websocket instance and sets the token for the initial request. | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/plugins/Websocket.ts#L25-L63 | b00ed75584a597596e212456f4501b20186c343e |
pyrodactyl | github_2023 | pyrohost | typescript | Websocket.setToken | setToken(token: string, isUpdate = false): this {
this.token = token;
if (isUpdate) {
this.authenticate();
}
return this;
} | // between the websocket instance. | https://github.com/pyrohost/pyrodactyl/blob/b00ed75584a597596e212456f4501b20186c343e/resources/scripts/plugins/Websocket.ts#L67-L75 | b00ed75584a597596e212456f4501b20186c343e |
AIHub | github_2023 | classfang | typescript | creatTempPath | const creatTempPath = () => {
try {
fs.mkdirSync(appConfig.tempPath)
} catch (e: any) {
if (e.code != 'EEXIST') {
logger.error('create temp path error:' + e)
}
}
} | // 临时缓存目录 | https://github.com/classfang/AIHub/blob/fd695d39d075c4f6ae0d4210b415856ad701983a/src/main/index.ts#L20-L28 | fd695d39d075c4f6ae0d4210b415856ad701983a |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.