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((el: any) => { if (el!.className === 'waterfall-item') items.push(el) }) } // 获取节点 if (items.length === 0) return false // 遍历节点 for (let i = 0; i < items.length; i++) { const curItem = items[i] as HTMLElement // 最小的y值 const minY = Math.min.apply(null, posY.value) // 最小y的下标 const minYIndex = posY.value.indexOf(minY) // 当前下标对应的x const curX = getX(minYIndex) // 设置x,y,width const style = curItem.style as CssStyleObject // 设置偏移 if (transform) style[transform] = `translate3d(${curX}px,${minY}px, 0)` style.width = `${colWidth.value}px` style.visibility = 'visible' // 更新当前index的y值 const { height } = curItem.getBoundingClientRect() posY.value[minYIndex] += height + props.gutter // 添加入场动画 animation(curItem, () => { // 添加动画时间 const time = props.posDuration / 1000 if (transition) style[transition] = `transform ${time}s` }) } wrapperHeight.value = Math.max.apply(null, posY.value) setTimeout(() => { resolve(true) }, props.posDuration) }) }
// 排版
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 delaySec = `${props.animationDelay / 1000}s` const style = content.style as CssStyleObject addClass(content, props.animationPrefix) addClass(content, props.animationEffect) if (duration) style[duration] = durationSec if (delay) style[delay] = delaySec if (fillMode) style[fillMode] = 'both' if (callback) { setTimeout(() => { callback() }, props.animationDuration + props.animationDelay) } } } }
// 动画
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) { this._setImageSrc(el, src, callback, error) } else { if (!hasIntersectionObserver) { this._setImageSrc(el, src, callback, error) this._log(() => { throw new Error('Not support IntersectionObserver!') }) } this._initIntersectionObserver(el, src, callback, error) } }
// 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 const curHeight = (el.width / width) * height el.height = curHeight const style = el.style as CssStyleObject style.height = `${curHeight}px` callback() }) } }
// 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) => { // 修改容器 const { width, height } = image const ratio = this.options.ratioCalculator?.(width, height) || height / width const lazyBox = el.parentNode!.parentNode as HTMLElement lazyBox.style.paddingBottom = `${ratio * 100}%` // 设置图片 el.setAttribute('lazy', LifecycleEnum.LOADED) el.removeAttribute('src') el.setAttribute('src', src) callback(true) }) .catch(() => { const imgItem = this._realObserver(el) imgItem && imgItem.disconnect() if (error) { el.setAttribute('lazy', LifecycleEnum.ERROR) el.setAttribute('src', error) callback(false) } this._log(() => { throw new Error(`Image failed to load!And failed src was: ${src} `) }) }) }
/** * 设置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, (entry) => { if (entry.isIntersecting) { const imgItem = this._realObserver(el) imgItem && imgItem.unobserve(entry.target) this._setImageSrc(el, src, callback, error) } }) }, observerOptions), ) const imgItem = this._realObserver(el) imgItem && imgItem.observe(el) }
/** * 添加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 ValueFormatterObject).loading || this.options.loading error = (value as ValueFormatterObject).error || this.options.error } return { src, loading, error, } }
// 格式化参数
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 names = getSymbols(arg) for (const key of names) { if (isEnumerable.call(arg, key)) target[key] = arg[key] } } return target }
/** * 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 * * @param {*} target * @param {Array} args * @returns */
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(...localFonts) } if (list.length === 0) { const res = await getFonts({pageNum: 1, pageSize: 1000}) list = res.data.records localStorage.setItem('FONTS', JSON.stringify(list)) localStorage.setItem('FONTS_VERSION', '1') } fontList.value = defaultFonts.concat(list) return list }
/** * 初始化部分字体 */
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) { s = Math.min(l <= 0.5 ? chroma / (2 * l) : chroma / (2 - 2 * l), 1) switch (max) { case r: h = (g - b) / chroma + (g < b ? 6 : 0) break case g: h = (b - r) / chroma + 2 break case b: h = (r - g) / chroma + 4 break } h *= 60 h = Math.round(h) } return new HSLA(h, s, l, a) }
/** * 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) g = HSLA._hue2rgb(p, q, h) b = HSLA._hue2rgb(p, q, h - 1 / 3) } return new RGBA(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a) }
/** * 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 } else if (cmax === r) { m = ((((g - b) / delta) % 6) + 6) % 6 } else if (cmax === g) { m = (b - r) / delta + 2 } else { m = (r - g) / delta + 4 } return new HSVA(Math.round(m * 60), s, cmax, rgba.a) }
// 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 b = x } else if (h < 240) { g = x b = c } else if (h < 300) { r = x b = c } else if (h <= 360) { r = c b = x } r = Math.round((r + m) * 255) g = Math.round((g + m) * 255) b = Math.round((b + m) * 255) return new RGBA(r, g, b, a) }
// 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.Digit4: return 4 case CharCode.Digit5: return 5 case CharCode.Digit6: return 6 case CharCode.Digit7: return 7 case CharCode.Digit8: return 8 case CharCode.Digit9: return 9 case CharCode.a: return 10 case CharCode.A: return 10 case CharCode.b: return 11 case CharCode.B: return 11 case CharCode.c: return 12 case CharCode.C: return 12 case CharCode.d: return 13 case CharCode.D: return 13 case CharCode.e: return 14 case CharCode.E: return 14 case CharCode.f: return 15 case CharCode.F: return 15 } return 0 }
// 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.toRgbString(); }
/** * 对象转颜色字符串 * @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, flags); };
/** * 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 rSideCornerCapture = /to\s+((?:(?:left|right|top|bottom)(?:\s+(?:top|bottom|left|right))?))/; const rComma = /\s*,\s*/; // Allow space around comma. const rColorHex = /#(?:[a-f0-9]{6}|[a-f0-9]{3})/; // 3 or 6 character form const rDigits3 = /\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}\s*\)/; const // "(1, 2, 3)" rDigits4 = /\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}\s*,\s*\d*\.?\d+\)/; const // "(1, 2, 3, 4)" rValue = /(?:[+-]?\d*\.?\d+)(?:%|[a-z]+)?/; const // ".9", "-5px", "100%". rKeyword = /[_a-z-][_a-z0-9-]*/; const // "red", "transparent". rColor = combineRegExp( ['(?:', rColorHex, '|', '(?:rgb|hsl)', rDigits3, '|', '(?:rgba|hsla)', rDigits4, '|', rKeyword, ')'], '', ); const rColorStop = combineRegExp([rColor, '(?:\\s+', rValue, '(?:\\s+', rValue, ')?)?'], ''); const // Single Color Stop, optional %, optional length. rColorStopList = combineRegExp(['(?:', rColorStop, rComma, ')*', rColorStop], ''); const // List of color stops min 1. rLineCapture = combineRegExp(['(?:(', rAngle, ')|', rSideCornerCapture, ')'], ''); const // Angle or SideCorner rGradientSearch = combineRegExp(['(?:(', rLineCapture, ')', rComma, ')?(', rColorStopList, ')'], searchFlags); const // Capture 1:"line", 2:"angle" (optional), 3:"side corner" (optional) and 4:"stop list". rColorStopSearch = combineRegExp( ['\\s*(', rColor, ')', '(?:\\s+', '(', rValue, '))?', '(?:', rComma, '\\s*)?'], searchFlags, ); // Capture 1:"color" and 2:"position" (optional). return { gradientSearch: rGradientSearch, colorStopSearch: rColorStopSearch, }; };
/** * 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 (!isNull(matchGradient)) { result = { original: matchGradient[0], colorStopList: [], }; // Line (Angle or Side-Corner). if (matchGradient[1]) { // eslint-disable-next-line prefer-destructuring result.line = matchGradient[1]; } // Angle or undefined if side-corner. if (matchGradient[2]) { // eslint-disable-next-line prefer-destructuring result.angle = matchGradient[2]; } // Side-corner or undefined if angle. if (matchGradient[3]) { // eslint-disable-next-line prefer-destructuring result.sideCorner = matchGradient[3]; } // reset search position, because we reuse regex. regExpLib.colorStopSearch.lastIndex = 0; // Loop though all the color-stops. matchColorStop = regExpLib.colorStopSearch.exec(matchGradient[4]); while (!isNull(matchColorStop)) { stopResult = { color: matchColorStop[1], }; // Position (optional). if (matchColorStop[2]) { // eslint-disable-next-line prefer-destructuring stopResult.position = matchColorStop[2]; } result.colorStopList.push(stopResult); // Continue searching from previous position. matchColorStop = regExpLib.colorStopSearch.exec(matchGradient[4]); } } // Can be undefined if match not found. return result; };
/** * 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 * @returns {object|undefined} */
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不支持同时存在删除线和下划线,两者都存在则只保留下划线 if (style.strikethrough) { // 删除线 text.textDecoration = 'delete'; } if (style.underline) { // 下划线 text.textDecoration = 'under'; } if (style.leading) { text.lineHeight = { type: 'px', value: style.leading * scale, }; } // TODO 处理水平缩放 props.text.style.horizontalScale };
/** * 设置文本 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'; text.paraIndent = paragraphStyle.firstLineIndent; } };
/** * 设置文本段落 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 type switch (stroke.fillType) { case 'color': type = 'solid' break default: type = 'solid' break } strokeArr.push({ type: type, strokeAlign: stroke.position, opacity: stroke.opacity, color: toRGBColorStr(stroke.color) }) } }) text.stroke = strokeArr } } }
/** * 设置文本 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.activeObject.parent ? this.activeObject.parent.getInnerPoint({ x: x, y: y }) : this.canvas.contentFrame.getInnerPoint({x: x, y: y}) group.x = point.x group.y = point.y } else { // 略微在原基础上偏移粘贴 group.x += 15 group.y += 15 } this.canvas.add(group) // 选中元素 this.canvas.setActiveObjects(group.children) // 解组 MEditorHelper.ungroup([group]) }
// 插入元素到画板内
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)) } finally { // this.canvas.contentLayer.updateLayout() this.enablePropertyChangeWatch() instantiation.resume() } }
// 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() : undefined, }) }) this.eventbus.on('workspaceAddAfter', ({newId}) => { this.undoRedos.set(newId, { instantiation: new UndoRedoBase(), lastState: this.pageId === newId ? this.getJson() : undefined, }) }) this.eventbus.on('workspaceRemoveAfter', (id) => { this.undoRedos.delete(id) }) this.eventbus.on('workspaceChangeAfter', ({newId}) => { this.pageId = newId }) }
// 工作区 | 页面管理
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: [], }) }) this.eventbus.on('workspaceRemoveAfter', (id) => { this.pages.delete(id) }) this.eventbus.on('workspaceChangeBefore', ({oldId}) => { if (!oldId || !this.pages.has(oldId)) return const page = this.pages.get(oldId) if (!page) return // 切换前保存当前工作区 this.setPageJSON(oldId, this.contentFrame.toJSON()) // page.scale = this.contentLayer.scale this.contentFrame.clear() }) this.eventbus.on('workspaceChangeAfter', ({newId}) => { // 切换后恢复当前工作区 if (this.pageId !== newId) { useAppStore().activeTool = 'select' this.discardActiveObject() const page = this.pages.get(newId) this.pageId = newId if (page) { this.importJsonToCurrentPage(page, true) } } }) this.eventbus.on('workspaceChangeRefresh', ({newId}) => { const json = this.pages.get(newId) console.log('json=', json) if (json) { this.contentFrame.set(json) } else { this.setPageJSON(newId, this.contentFrame.toJSON()) } }) }
// 工作区 | 页面管理
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' }] }) this.contentLayer.add(frame) this.contentFrame = frame this.setActiveObjectValue(this.contentFrame) this.app.editor.on(EditorEvent.SELECT, (arg: EditorEvent) => { this.setActiveObjectValue(arg.editor.element) // this.ruler.forceRender() }) // 子元素添加事件 this.contentLayer.on(ChildEvent.ADD, (arg: ChildEvent) => { // this.selectObject(arg.target) this.childrenEffect() }) // 子元素移除事件 this.contentLayer.on(ChildEvent.REMOVE, (arg: ChildEvent) => { this.childrenEffect() }) // 元素属性事件 this.contentLayer.on(PropertyEvent.CHANGE, (e2: PropertyEvent) => { // 监听最底层画布xy变化 触发布局移动事件(用于辅助线跟随画布移动) // @ts-ignore if ((typeUtil.isBottomCanvas(e2.target) || typeUtil.isBottomLeafer(e2.target)) && e2.newValue && ['x', 'y'].includes(e2.attrName)) { this.eventbus.emit('layoutMoveEvent', e2) } }) let initFrameWH = true // resize事件 this.contentLayer.on(ResizeEvent.RESIZE, (e2: ResizeEvent) => { if (initFrameWH) { // 第一次初始化画布时设置画布宽高为可视区域大小 this.contentFrame.width = e2.width this.contentFrame.height = e2.height this.app.tree.zoom('fit') } this.eventbus.emit('layoutResizeEvent', e2) initFrameWH = false }) }
// 页面元素编辑器
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.contentFrame.add(_child, _index) // 选中提添加的元素 this.selectObject(_child) this.childrenEffect() }
/** * 添加元素 * @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 = 'select' this.childrenEffect() } this.zoomToFit() }
/** * 导入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 const { workspaces, pages, }: { workspaces: IWorkspace[] pages: { id: string children: IUI[] }[] } = serialized if (!workspaces || !pages || workspaces.length === 0 || pages.length === 0) { return Promise.reject(new Error('`json` is not valid')) } this.workspacesService.clear() this.pages.clear() for (const { name, id } of workspaces) { this.workspacesService.add(name, id) } for (const page of pages.reverse()) { this.workspacesService.setCurrentId(page.id) await this.reLoadFromJSON(page.children) } }
/** * 导入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) { leaf.dropTo(group) // 放置元素到group中 } }) }) group.on(DragEvent.OUT, function (e: DropEvent) { if (that.objectIsTypes(e.current, 'Group')) { e.target.dropTo(e.current.parent) } }) }
/** * 绑定组的元素拖动放置事件 * @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 !== -1 ? this.items[index] : defaultItem; }
// 获取指定 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 !== -1 ? this.items[index] : defaultItem; }
// 获取指定 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; return barcodeUnitWidth; }
// 定义函数来计算每个码的间隔
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: option.attr, index:index, dialogOption: { onClose() { // 关闭后置空 closeFn = undefined }, }, }) }) }
/** 打开颜色选择器 */
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}` // OPT store 中使用 UI ElMessage.error(`文件 \"${file.name}\" 刷新失败. ${message}`) } } // 更新引用,触发依赖项的更新,如序号的预览 files.value = [...files.value] }
/** * 从磁盘读取刷新文件信息 */
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={import.meta.env.VITE_COMMIT_HASH} style={{ display: 'contents', }} > {children} </div> ); };
// 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_10_136)' fillRule='evenodd' d='M.221 5.894c2.105 4.942 3.762 10.569 3.518 15.349-.124 2.415 2.375 5.89 4.683 6.683 2.568.881 4.998 2.762 6.208 6.329.66 1.942 3.005 3.258 4.995 2.696 4.253-1.203 9.98-1.256 14.475 3.247.529.53.764 1.286.597 2.012a15.343 15.343 0 01-10.022 10.946c-1.798.623-2.37 2.472-.468 2.575 2.41.13 6.157-.897 11.586-4.603.3-.205.71-.175.968.08.228.225.284.57.14.854l-.644 1.276c-.47.93-.358 2.043.287 2.864l.73.93c.431.549.54 1.28.285 1.928l-.192.49c-.14.353-.077.754.162 1.05.485.6 1.434.51 1.793-.172l.329-.623c.187-.355.445-.597.801-.407.717.382 2.333.346 2.279-.458l-.002-.029a.74.74 0 00-.22-.5L40.47 56.33a2.679 2.679 0 01-.396-3.238l.93-1.579a1.478 1.478 0 00-.104-1.656 1.48 1.48 0 01.292-2.097l.93-.69a1.89 1.89 0 012.297.036c.71.562.91 1.548.474 2.339l-.027.05a1.909 1.909 0 00.22 2.162l1.67 1.958c.405.476.502 1.139.25 1.709l-.165.375a.974.974 0 00.155 1.032.997.997 0 001.656-.232l.312-.68c.136-.296.445-.486.761-.398.091.026.186.057.282.095.69.27 2.127.084 2.052-.647a.675.675 0 00-.2-.402l-2.52-2.423a2.68 2.68 0 01-.523-3.172l.414-.796c.417-.802.408-1.762-.115-2.502a19.405 19.405 0 00-.56-.752c-.843-1.077-1.013-2.612-.04-3.576 3.14-3.11 8.802-6.355 15.662-4.248 2.002.614 4.458-.647 5.178-2.596.796-2.157 2.177-4.31 4.396-5.684 2.262-1.4 6.302-6.74 6.465-9.377.228-3.701 1.408-8.64 4.302-14.947 1.104-2.407-1.49-5.198-3.953-4.176C75.77 2.205 69.92 4.458 64.573 6.11c-1.138.352-1.935 1.377-1.96 2.557l-.183 8.996c-.008.393-.095.781-.308 1.112-1.138 1.767-4.333 5.01-10.452 7.749-1.31.586-2.828-.035-3.426-1.33l-.826-1.79c-1.06-2.565.04-5.525 6.322-6.655l.017-.003c.025-.004.04-.007.068-.017l.033-.012c.565-.203 1.4-.503 1.43-1.086.061-1.177-.167-2.505-1.224-2.907a1.529 1.529 0 00-.547-.078h-9.795c-.212 0-.424.02-.626.087-1.419.465-3.466 1.923-5.226 3.175-1.36.967-2.547 1.813-3.14 1.983a.5.5 0 01-.142.017c-.54 0-.847.572-.46.943.823.788 2.085 1.456 3.651 1.142 1.366-.274 2.94-.274 3.674.9 1.309 2.095 2.165 4.855.056 6.647-.361.307-.835.439-1.31.433-4.32-.057-12.867-1.902-18.27-9.031a2.514 2.514 0 01-.496-1.523v-8.77c0-1.227-.833-2.297-2.025-2.636A156.196 156.196 0 014.896 1.071C2.294.032-.869 3.334.221 5.894zM43.993 15.92a.823.823 0 00.827-.82.823.823 0 00-.827-.818.823.823 0 00-.827.819c0 .452.37.819.827.819z' clipRule='evenodd' ></path> <path fill='#F3B4A6' fillOpacity='0.06' fillRule='evenodd' d='M.221 5.894c2.105 4.942 3.762 10.569 3.518 15.349-.124 2.415 2.375 5.89 4.683 6.683 2.568.881 4.998 2.762 6.208 6.329.66 1.942 3.005 3.258 4.995 2.696 4.253-1.203 9.98-1.256 14.475 3.247.529.53.764 1.286.597 2.012a15.343 15.343 0 01-10.022 10.946c-1.798.623-2.37 2.472-.468 2.575 2.41.13 6.157-.897 11.586-4.603.3-.205.71-.175.968.08.228.225.284.57.14.854l-.644 1.276c-.47.93-.358 2.043.287 2.864l.73.93c.431.549.54 1.28.285 1.928l-.192.49c-.14.353-.077.754.162 1.05.485.6 1.434.51 1.793-.172l.329-.623c.187-.355.445-.597.801-.407.717.382 2.333.346 2.279-.458l-.002-.029a.74.74 0 00-.22-.5L40.47 56.33a2.679 2.679 0 01-.396-3.238l.93-1.579a1.478 1.478 0 00-.104-1.656 1.48 1.48 0 01.292-2.097l.93-.69a1.89 1.89 0 012.297.036c.71.562.91 1.548.474 2.339l-.027.05a1.909 1.909 0 00.22 2.162l1.67 1.958c.405.476.502 1.139.25 1.709l-.165.375a.974.974 0 00.155 1.032.997.997 0 001.656-.232l.312-.68c.136-.296.445-.486.761-.398.091.026.186.057.282.095.69.27 2.127.084 2.052-.647a.675.675 0 00-.2-.402l-2.52-2.423a2.68 2.68 0 01-.523-3.172l.414-.796c.417-.802.408-1.762-.115-2.502a19.405 19.405 0 00-.56-.752c-.843-1.077-1.013-2.612-.04-3.576 3.14-3.11 8.802-6.355 15.662-4.248 2.002.614 4.458-.647 5.178-2.596.796-2.157 2.177-4.31 4.396-5.684 2.262-1.4 6.302-6.74 6.465-9.377.228-3.701 1.408-8.64 4.302-14.947 1.104-2.407-1.49-5.198-3.953-4.176C75.77 2.205 69.92 4.458 64.573 6.11c-1.138.352-1.935 1.377-1.96 2.557l-.183 8.996c-.008.393-.095.781-.308 1.112-1.138 1.767-4.333 5.01-10.452 7.749-1.31.586-2.828-.035-3.426-1.33l-.826-1.79c-1.06-2.565.04-5.525 6.322-6.655l.017-.003c.025-.004.04-.007.068-.017l.033-.012c.565-.203 1.4-.503 1.43-1.086.061-1.177-.167-2.505-1.224-2.907a1.529 1.529 0 00-.547-.078h-9.795c-.212 0-.424.02-.626.087-1.419.465-3.466 1.923-5.226 3.175-1.36.967-2.547 1.813-3.14 1.983a.5.5 0 01-.142.017c-.54 0-.847.572-.46.943.823.788 2.085 1.456 3.651 1.142 1.366-.274 2.94-.274 3.674.9 1.309 2.095 2.165 4.855.056 6.647-.361.307-.835.439-1.31.433-4.32-.057-12.867-1.902-18.27-9.031a2.514 2.514 0 01-.496-1.523v-8.77c0-1.227-.833-2.297-2.025-2.636A156.196 156.196 0 014.896 1.071C2.294.032-.869 3.334.221 5.894zM43.993 15.92a.823.823 0 00.827-.82.823.823 0 00-.827-.818.823.823 0 00-.827.819c0 .452.37.819.827.819z' clipRule='evenodd' ></path> <path fill='#fff' d='M102.914 44.556v-25.29h9.699c1.741 0 3.278.305 4.612.916 1.356.611 2.419 1.516 3.188 2.716.768 1.2 1.153 2.682 1.153 4.447 0 1.72-.396 3.18-1.187 4.38-.769 1.199-1.832 2.115-3.188 2.749-1.334.611-2.86.917-4.578.917h-4.443v9.166h-5.256zm5.256-13.748h4.477c.746 0 1.39-.148 1.933-.442.542-.294.96-.701 1.254-1.222.317-.52.475-1.12.475-1.799 0-.702-.158-1.313-.475-1.833a3.112 3.112 0 00-1.254-1.222c-.543-.294-1.187-.442-1.933-.442h-4.477v6.96zM127.446 52.093a9.285 9.285 0 01-1.594-.136 4.546 4.546 0 01-1.322-.441V47.34c.316.09.689.17 1.119.238.43.068.825.102 1.187.102.995 0 1.707-.238 2.136-.713.43-.475.78-1.019 1.052-1.63l1.254-2.885-.067 4.243-8.139-20.674h5.459l5.392 14.7h-2.034l5.392-14.7h5.46l-7.936 20.267c-.497 1.29-1.108 2.365-1.831 3.225-.724.86-1.549 1.505-2.476 1.935-.904.43-1.921.645-3.052.645zM144.964 44.556V26.021h4.748v4.447l-.34-.645c.407-1.561 1.074-2.614 2.001-3.157.95-.566 2.069-.849 3.357-.849h1.086v4.413h-1.594c-1.244 0-2.25.385-3.018 1.155-.769.747-1.153 1.81-1.153 3.19v9.981h-5.087zM167.235 44.964c-1.831 0-3.504-.419-5.019-1.256a9.858 9.858 0 01-3.594-3.429c-.882-1.471-1.323-3.134-1.323-4.99 0-1.879.441-3.542 1.323-4.99a9.858 9.858 0 013.594-3.43c1.515-.837 3.188-1.255 5.019-1.255s3.493.418 4.985 1.256a9.598 9.598 0 013.561 3.428c.904 1.449 1.356 3.112 1.356 4.99 0 1.857-.452 3.52-1.356 4.991a9.598 9.598 0 01-3.561 3.429c-1.492.837-3.154 1.256-4.985 1.256zm0-4.583c.927 0 1.73-.215 2.408-.645a4.333 4.333 0 001.628-1.8c.407-.769.61-1.651.61-2.647 0-.996-.203-1.867-.61-2.614a4.334 4.334 0 00-1.628-1.8c-.678-.452-1.481-.678-2.408-.678-.927 0-1.741.226-2.441.678a4.564 4.564 0 00-1.662 1.8c-.384.747-.577 1.618-.577 2.614 0 .996.193 1.878.577 2.648.407.77.961 1.369 1.662 1.799.7.43 1.514.645 2.441.645zM188.85 44.964c-1.809 0-3.426-.43-4.85-1.29a9.49 9.49 0 01-3.391-3.497c-.814-1.47-1.221-3.1-1.221-4.888 0-1.81.418-3.44 1.255-4.889a9.49 9.49 0 013.391-3.496c1.424-.86 3.018-1.29 4.782-1.29 1.356 0 2.554.26 3.594.78 1.063.498 1.899 1.211 2.51 2.14l-.78 1.018V18.858h5.087v25.698h-4.748v-3.394l.475 1.052c-.633.905-1.492 1.596-2.578 2.07-1.085.454-2.26.68-3.526.68zm.61-4.583c.927 0 1.741-.215 2.442-.645a4.33 4.33 0 001.627-1.8c.407-.769.611-1.651.611-2.647 0-.996-.204-1.879-.611-2.648a4.331 4.331 0 00-1.627-1.8c-.701-.43-1.515-.644-2.442-.644-.927 0-1.763.226-2.51.678a4.488 4.488 0 00-1.695 1.8c-.407.747-.611 1.618-.611 2.614 0 .996.204 1.878.611 2.648.407.77.972 1.369 1.695 1.799.747.43 1.583.645 2.51.645zM208.683 44.964c-1.334 0-2.487-.215-3.459-.645-.972-.43-1.718-1.041-2.238-1.833-.52-.815-.78-1.777-.78-2.886 0-1.04.237-1.958.712-2.75.475-.814 1.198-1.493 2.17-2.037.995-.543 2.227-.927 3.697-1.154l5.663-.916v3.734l-4.748.849c-.723.135-1.277.373-1.661.712-.385.317-.577.781-.577 1.392 0 .566.215 1.008.644 1.324.43.317.961.476 1.594.476.837 0 1.572-.181 2.205-.543a3.767 3.767 0 001.458-1.46 4.113 4.113 0 00.542-2.071v-4.82c0-.702-.282-1.29-.847-1.766-.543-.475-1.289-.713-2.239-.713-.904 0-1.707.25-2.407.747a4.322 4.322 0 00-1.492 1.969l-4.07-1.935a6.616 6.616 0 011.73-2.682c.791-.747 1.74-1.324 2.848-1.731 1.108-.408 2.318-.611 3.629-.611 1.56 0 2.939.282 4.137.848 1.198.566 2.125 1.358 2.781 2.377.678.995 1.017 2.161 1.017 3.496v12.221h-4.748V41.57l1.153-.204c-.542.815-1.141 1.494-1.797 2.037-.655.52-1.39.906-2.204 1.154-.814.272-1.718.408-2.713.408zM231.811 44.964c-1.854 0-3.527-.419-5.019-1.256a9.863 9.863 0 01-3.527-3.497c-.859-1.47-1.288-3.123-1.288-4.956 0-1.833.429-3.474 1.288-4.923a9.26 9.26 0 013.527-3.462c1.492-.838 3.165-1.256 5.019-1.256 1.379 0 2.656.237 3.832.712a8.692 8.692 0 013.018 2.003 7.21 7.21 0 011.798 2.988l-4.409 1.9c-.316-.927-.859-1.662-1.628-2.206-.746-.543-1.616-.814-2.611-.814-.882 0-1.673.215-2.374.645-.678.43-1.221 1.03-1.628 1.799-.384.77-.576 1.652-.576 2.648 0 .996.192 1.878.576 2.648.407.77.95 1.369 1.628 1.799.701.43 1.492.645 2.374.645 1.017 0 1.899-.272 2.645-.815.746-.543 1.278-1.279 1.594-2.206l4.409 1.935c-.34 1.086-.927 2.06-1.764 2.92-.836.86-1.842 1.538-3.018 2.036-1.176.475-2.464.713-3.866.713zM252.373 44.76c-2.238 0-3.979-.6-5.223-1.799-1.22-1.222-1.831-2.92-1.831-5.092v-7.435h-3.12v-4.413h.17c.949 0 1.673-.238 2.17-.713.52-.475.78-1.188.78-2.139v-1.358h5.087v4.21h4.341v4.413h-4.341v7.095c0 .634.113 1.166.339 1.596.226.407.577.713 1.051.916.475.204 1.063.306 1.764.306.158 0 .339-.011.542-.034.204-.023.419-.045.645-.068v4.312c-.34.045-.724.09-1.153.135-.43.046-.837.068-1.221.068zM260.61 52.093a9.277 9.277 0 01-1.594-.136 4.563 4.563 0 01-1.323-.441V47.34c.317.09.69.17 1.12.238.429.068.825.102 1.187.102.994 0 1.706-.238 2.136-.713a6.11 6.11 0 001.051-1.63l1.255-2.885-.068 4.243-8.139-20.674h5.46l5.392 14.7h-2.035l5.392-14.7h5.46l-7.935 20.267c-.498 1.29-1.108 2.365-1.831 3.225-.724.86-1.549 1.505-2.476 1.935-.904.43-1.922.645-3.052.645zM278.128 44.556V18.858h5.086v25.698h-5.086z' ></path> <defs> <radialGradient id='paint0_radial_10_136' cx='0' cy='0' r='1' gradientTransform='matrix(0 62.83 -291.711 0 141.607 -1.83)' gradientUnits='userSpaceOnUse' > <stop stopColor='#FF343C'></stop> <stop offset='1' stopColor='#F06F53'></stop> </radialGradient> </defs> </svg> ); };
// 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' > <path fillRule='evenodd' clipRule='evenodd' d='M3 5C3 4.19711 3.43749 3.55194 3.96527 3.08401C4.49422 2.61504 5.20256 2.2384 5.99202 1.94235C7.57833 1.34749 9.70269 1 12 1C14.2973 1 16.4217 1.34749 18.008 1.94235C18.7974 2.2384 19.5058 2.61504 20.0347 3.08401C20.5625 3.55194 21 4.19711 21 5V9.98763C21 10.9324 20.8466 11.4637 20.0419 11.9907C19.7167 12.2037 19.3522 12.4055 18.9492 12.5952C16.9865 13.5188 14.3887 14 12 14C9.6113 14 7.01354 13.5188 5.0508 12.5952C4.64779 12.4055 4.28325 12.2037 3.95806 11.9907C3.15337 11.4637 3 10.9324 3 9.98763V5ZM6.57313 6.13845C5.97883 5.9045 5.55524 5.65279 5.29209 5.41948C4.9354 5.10324 4.9354 4.89676 5.29209 4.58052C5.57279 4.33166 6.03602 4.06185 6.69427 3.81501C8.0034 3.32409 9.87903 3 12 3C14.121 3 15.9966 3.32409 17.3057 3.81501C17.964 4.06185 18.4272 4.33166 18.7079 4.58052C19.0646 4.89676 19.0646 5.10324 18.7079 5.41948C18.4272 5.66834 17.964 5.93815 17.3057 6.18499C15.9966 6.67591 14.121 7 12 7C11.1029 7 10.2497 6.94202 9.46467 6.83796C8.48782 6.70847 7.52272 6.51225 6.57313 6.13845ZM7.21611 10.1257C6.81943 10.0065 6.40119 10.2314 6.28195 10.628C6.1627 11.0247 6.38761 11.443 6.78428 11.5622C7.42389 11.7545 8.1316 11.9106 8.88764 12.0254C9.29716 12.0875 9.67954 11.8059 9.7417 11.3964C9.80387 10.9869 9.52228 10.6045 9.11276 10.5424C8.41746 10.4368 7.77966 10.2951 7.21611 10.1257Z' fill={props.fill} /> <path fillRule='evenodd' clipRule='evenodd' d='M3.62747 14.1164C3.3392 13.9608 3.19506 13.883 3.09753 13.9412C3 13.9993 3 14.1584 3 14.4765V18.9998C3 19.8027 3.43749 20.4479 3.96527 20.9158C4.49422 21.3848 5.20256 21.7614 5.99202 22.0575C7.57833 22.6523 9.70269 22.9998 12 22.9998C14.2973 22.9998 16.4217 22.6523 18.008 22.0575C18.7974 21.7614 19.5058 21.3848 20.0347 20.9158C20.5625 20.4479 21 19.8027 21 18.9998V14.4765C21 14.1584 21 13.9993 20.9025 13.9412C20.8049 13.883 20.6608 13.9608 20.3725 14.1164C20.1849 14.2177 19.994 14.3137 19.8008 14.4046C17.5135 15.481 14.6113 15.9998 12 15.9998C9.346 15.9998 6.60931 15.5388 4.1992 14.4046C4.00604 14.3137 3.81512 14.2177 3.62747 14.1164ZM7.21611 17.1257C6.81943 17.0065 6.40119 17.2314 6.28195 17.628C6.1627 18.0247 6.38761 18.443 6.78428 18.5622C7.42389 18.7545 8.1316 18.9106 8.88764 19.0254C9.29716 19.0875 9.67954 18.8059 9.7417 18.3964C9.80387 17.9869 9.52228 17.6045 9.11276 17.5424C8.41746 17.4368 7.77966 17.2951 7.21611 17.1257Z' fill={props.fill} /> </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})`; constructor(props: P & AsModalProps) { super(props); this.state = { render: props.visible, visible: props.visible, propOverrides: {}, }; } get computedModalProps(): Readonly<SettableModalProps & { visible: boolean }> { return { ...(typeof modalProps === 'function' ? modalProps(this.props) : modalProps), ...this.state.propOverrides, visible: this.state.visible, }; } /** * @this {React.PureComponent<P & AsModalProps, State>} */ override componentDidUpdate(prevProps: Readonly<P & AsModalProps>, prevState: Readonly<State>) { if (prevProps.visible && !this.props.visible) { this.setState({ visible: false, propOverrides: {} }); } else if (!prevProps.visible && this.props.visible) { this.setState({ render: true, visible: true }); } if (!this.state.render && !isEqual(prevState.propOverrides, this.state.propOverrides)) { this.setState({ propOverrides: {} }); } } dismiss = () => this.setState({ visible: false }); setPropOverrides: ModalContextValues['setPropOverrides'] = (value) => this.setState((state) => ({ propOverrides: !value ? {} : typeof value === 'function' ? value(state.propOverrides) : value, })); /** * @this {React.PureComponent<P & AsModalProps, State>} */ override render() { if (!this.state.render) return null; return ( <PortaledModal onDismissed={() => this.setState({ render: false }, () => { if (typeof this.props.onModalDismissed === 'function') { this.props.onModalDismissed(); } }) } {...this.computedModalProps} > <ModalContext.Provider value={{ dismiss: this.dismiss.bind(this), setPropOverrides: this.setPropOverrides.bind(this), }} > <Component {...this.props} /> </ModalContext.Provider> </PortaledModal> ); } }; }; }
// 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)); return `${value} ${['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'][i]}`; }
/** * 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}, ${alpha})`; }
/** * 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 (ex) { console.warn('Failed to parse incoming websocket message.', ex); } }, onopen: () => { // Clear the timers, we managed to connect just fine. this.timer && clearTimeout(this.timer); this.backoff = 5000; this.emit('SOCKET_OPEN'); this.authenticate(); }, onreconnect: () => { this.emit('SOCKET_RECONNECT'); this.authenticate(); }, onclose: () => this.emit('SOCKET_CLOSE'), onerror: (error) => this.emit('SOCKET_ERROR', error), }); this.timer = setTimeout(() => { this.backoff = this.backoff + 2500 >= 20000 ? 20000 : this.backoff + 2500; this.socket && this.socket.close(); clearTimeout(this.timer); // Re-attempt connecting to the socket. this.connect(url); }, this.backoff); return this; }
// 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