Skip to content

Instantly share code, notes, and snippets.

@lichspace
lichspace / gist:145533df062e4a7574c8f10d15e11124
Created January 3, 2024 06:31
extract pixijs sprite to buffer
import { Application, Assets, loadNodeFont, utils, Text } from '@pixi/node';
import { writeFileSync } from 'fs';
import { Canvas, createImageData, createCanvas } from 'canvas';
const data = this.app.renderer.extract.pixels(this.app.stage);
const { width, height } = this.app.stage;
const canvas = createCanvas(width, height);
const ctx = canvas.getContext('2d');
const imagedata = createImageData(new Uint8ClampedArray(data), width, height);
ctx.putImageData(imagedata, 0, 0);
@lichspace
lichspace / click.scss
Created December 26, 2019 07:24
一种点击其他区域隐藏当前元素的方案
//.context-menu形成透明层,点击。触发。mymenu消失
.context-menu{
.hidden-mask{
position: fixed;
left: 0;
top:0;
width: 100%;
height: 100%;
z-index: 1;
url += (~url.indexOf('?') ? '&' : '?') + param + '=' + enc(id);
url = url.replace('?&', '?');
@lichspace
lichspace / gist:fe6170d892d17ac2ac354c9bb1661b5e
Last active November 29, 2018 08:38
react upload preview
handleChange(e){
console.log('file',e.target.files)
let files = [...e.target.files]
let that = this
let fileList = []
files.map((v,n)=>{
let reader = new FileReader(e);
reader.onload = function () {
let url = event.target.result
fileList.push({
/**
* 去抖函数
* @param func
* @param millisecond
*/
module.exports = (func, millisecond)=>{
//let timeId
let running = false
function debounced() {
if(running) return
@lichspace
lichspace / js
Created August 3, 2018 10:05
JS嵌套匹配
parseHmtlToJson(html,cnt_attr) {
//timeline 处理
let timeLineJson = []
html = html.replace(/<!--TIMELINE-->(.*?)<!--\/TIMELINE-->/,(match)=>{
//console.log(match)
timeLineJson = match.match(/<!--(TIME|EVENT)-->(.*?)<!--\/(TIME|EVENT)-->/g).map(v=>{
let r = v.match(/<!--(TIME|EVENT)-->(?:<P>)*(.*?)(?:<\/P>)*<!--\/(TIME|EVENT)-->/)
return r?{
type:r[1],
value:r[2]