diff --git a/.gitignore b/.gitignore index a8f9f08a..d9c1856f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ node_modules yarn.lock package-lock.json dist -cache \ No newline at end of file +cache diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 00000000..7f186f22 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,10 @@ +# Deploy the docs to the `docs` branch. +git branch -D docs-preview +git checkout -b docs-preview +# sed -i '' '/dist/d' .gitignore +sed -i '' '/docs\/.vitepress\/lib/d' .gitignore +# npm run build +git add . +git commit -m "Update docs" +git push origin docs-preview -f +git checkout - diff --git a/docs/.vitepress/lib/charming-cell.umd.min.js b/docs/.vitepress/lib/charming-cell.umd.min.js new file mode 100644 index 00000000..fe1ba5bc --- /dev/null +++ b/docs/.vitepress/lib/charming-cell.umd.min.js @@ -0,0 +1 @@ +!function(A,I){"object"==typeof exports&&"undefined"!=typeof module?I(exports):"function"==typeof define&&define.amd?define(["exports"],I):I((A="undefined"!=typeof globalThis?globalThis:A||self).cm={})}(this,(function(A){"use strict";var I="undefined"!=typeof document?document.currentScript:null;const g="undefined"==typeof navigator?"node":navigator.userAgent,C=g.includes("Firefox"),B=g.includes("Edge"),Q=C||B?"bottom":"ideographic";function E({document:A=window.document,mode:I="single",cols:g=("single"===I?80:40),rows:C=24,fontFamily:B="courier-new, courier, monospace",fontSize:Q=15,fontWeight:E="normal",width:D,height:e}={}){const{width:t,height:a}=i("W",{fontSize:Q,fontFamily:B,fontWeight:E}),s="double"===I?2*t:t,w=a,h=o(D,g,s),c=o(e,C,w),r=h*s,N=c*w,n=function(A,I=640,g=480,C=null){null==C&&(C=devicePixelRatio);const B=A.createElement("canvas");B.width=I*C,B.height=g*C,B.style.width=I+"px",B.style.height=g+"px";const Q=B.getContext("2d");return Q.scale(C,C),Q}(A,r,N),y=Array.from({length:h*c},(()=>null));n.canvas.classList.add("cell-terminal"),Object.defineProperties(this,{_mode:{value:I},_fontSize:{value:Q},_fontFamily:{value:B},_fontWeight:{value:E},_cellWidth:{value:s},_cellHeight:{value:w},_cols:{value:h},_rows:{value:c},_width:{value:r},_height:{value:N},_context:{value:n},_buffer:{value:y}})}function i(A,I){const g=document.createElement("span");g.style.visibility="hidden",g.style.position="absolute",g.style.display="inline-block",g.style.left="-9999em",g.style.top="0",g.style.lineHeight="normal",g.setAttribute("aria-hidden",!0),g.style.fontSize=`${I.fontSize}px`,g.style.fontFamily=I.fontFamily,g.innerHTML=A,document.body.appendChild(g);const C=g.getBoundingClientRect();return{width:C.width,height:Math.ceil(C.height)}}function o(A,I,g){return void 0===A?I:A/g|0}let D;Object.defineProperties(E.prototype,{background:{value:function(A){return this._context.fillStyle=A,this._context.fillRect(0,0,this._width,this._height),this._buffer.fill(null),this},writable:!0,configurable:!0},char:{value:function(A,I,g,C,B,E=!1){const i=this._cellWidth*I,o=this._cellHeight*g,D=3*(this._cols*g+I);B&&(this._context.fillStyle=B,this._context.fillRect(i,o,this._cellWidth,this._cellHeight),this._buffer[D+2]=B);C&&(this._context.fillStyle=C,this._buffer[D+1]=C);if(!A)return;if(this._context.font=`${this._fontWeight} ${this._fontSize}px ${this._fontFamily}`,this._context.textBaseline=Q,this._context.fillText(A,i,o+this._cellHeight),this._buffer[D]=A,"double"!==this._mode||E)return;return this._context.fillText(A,i+this._cellWidth/2,o+this._cellHeight),this._buffer[D]+=A,this},writable:!0,configurable:!0},toString:{value:function(){let A="";for(let I=0;I{throw Error("TextDecoder not available")}};"undefined"!=typeof TextDecoder&&e.decode();let t=null;function a(A,I){return A>>>=0,e.decode((null!==t&&0!==t.byteLength||(t=new Uint8Array(D.memory.buffer)),t).subarray(A,A+I))}class s{static __wrap(A){A>>>=0;const I=Object.create(s.prototype);return I.__wbg_ptr=A,I}__destroy_into_raw(){const A=this.__wbg_ptr;return this.__wbg_ptr=0,A}free(){const A=this.__destroy_into_raw();D.__wbg_renderer_free(A)}stroke(A,I,g,C){D.renderer_stroke(this.__wbg_ptr,A,I,g,C)}fill(A,I,g,C){D.renderer_fill(this.__wbg_ptr,A,I,g,C)}background(A,I,g,C){D.renderer_background(this.__wbg_ptr,A,I,g,C)}noStroke(){D.renderer_noStroke(this.__wbg_ptr)}noFill(){D.renderer_noFill(this.__wbg_ptr)}static new(A,I){const g=D.renderer_new(A,I);return s.__wrap(g)}translate(A,I){D.renderer_translate(this.__wbg_ptr,A,I)}scale(A,I){D.renderer_scale(this.__wbg_ptr,A,I)}rotate(A){D.renderer_rotate(this.__wbg_ptr,A)}pushMatrix(){D.renderer_pushMatrix(this.__wbg_ptr)}popMatrix(){D.renderer_popMatrix(this.__wbg_ptr)}transform(A,I){return D.renderer_transform(this.__wbg_ptr,A,I)}render(){return D.renderer_render(this.__wbg_ptr)}point(A,I){D.renderer_point(this.__wbg_ptr,A,I)}line(A,I,g,C){D.renderer_line(this.__wbg_ptr,A,I,g,C)}rect(A,I,g,C){D.renderer_rect(this.__wbg_ptr,A,I,g,C)}}async function w(A){if(void 0!==D)return D;void 0===A&&(A=new URL("index_bg.wasm","undefined"==typeof document&&"undefined"==typeof location?require("url").pathToFileURL(__filename).href:"undefined"==typeof document?location.href:I&&"SCRIPT"===I.tagName.toUpperCase()&&I.src||new URL("charming-cell.umd.min.js",document.baseURI).href));const g=function(){const A={wbg:{}};return A.wbg.__wbindgen_throw=function(A,I){throw new Error(a(A,I))},A}();("string"==typeof A||"function"==typeof Request&&A instanceof Request||"function"==typeof URL&&A instanceof URL)&&(A=fetch(A));const{instance:C,module:B}=await async function(A,I){if("function"==typeof Response&&A instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(A,I)}catch(I){if("application/wasm"==A.headers.get("Content-Type"))throw I;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",I)}const g=await A.arrayBuffer();return await WebAssembly.instantiate(g,I)}{const g=await WebAssembly.instantiate(A,I);return g instanceof WebAssembly.Instance?{instance:g,module:A}:g}}(await A,g);return function(A,I){return D=A.exports,w.__wbindgen_wasm_module=I,t=null,D}(C,B)}function h(A){return function(A,I,g,C){var B=null;if("undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node)B=Buffer.from(g,"base64");else{var Q=globalThis.atob(g),E=Q.length;B=new Uint8Array(new ArrayBuffer(E));for(var i=0;i>16}, ${(65280&A)>>8}, ${255&A})`}function N(A){if(A===c)return["",0];const I=268435455&A,g=0===A>>31?1:2;return[String.fromCodePoint(I),g]}function n(){const A=this._renderer.render(),I=new Uint32Array(this._memory.buffer,A,this.cols()*this.rows()*4);for(let A=0;A=2,t=B+E;(t||o)&&this._terminal.char(t,g,A,o,D,e)}}function y(A,I,g){A.prototype=I.prototype=g,g.constructor=A}function G(A,I){var g=Object.create(A.prototype);for(var C in I)g[C]=I[C];return g}function R(){}var k=.7,F=1/k,M="\\s*([+-]?\\d+)\\s*",l="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",J="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",S=/^#([0-9a-f]{3,8})$/,Y=new RegExp(`^rgb\\(${M},${M},${M}\\)$`),H=new RegExp(`^rgb\\(${J},${J},${J}\\)$`),U=new RegExp(`^rgba\\(${M},${M},${M},${l}\\)$`),K=new RegExp(`^rgba\\(${J},${J},${J},${l}\\)$`),d=new RegExp(`^hsl\\(${l},${J},${J}\\)$`),q=new RegExp(`^hsla\\(${l},${J},${J},${l}\\)$`),u={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function f(){return this.rgb().formatHex()}function L(){return this.rgb().formatRgb()}function b(A){var I,g;return A=(A+"").trim().toLowerCase(),(I=S.exec(A))?(g=I[1].length,I=parseInt(I[1],16),6===g?m(I):3===g?new x(I>>8&15|I>>4&240,I>>4&15|240&I,(15&I)<<4|15&I,1):8===g?p(I>>24&255,I>>16&255,I>>8&255,(255&I)/255):4===g?p(I>>12&15|I>>8&240,I>>8&15|I>>4&240,I>>4&15|240&I,((15&I)<<4|15&I)/255):null):(I=Y.exec(A))?new x(I[1],I[2],I[3],1):(I=H.exec(A))?new x(255*I[1]/100,255*I[2]/100,255*I[3]/100,1):(I=U.exec(A))?p(I[1],I[2],I[3],I[4]):(I=K.exec(A))?p(255*I[1]/100,255*I[2]/100,255*I[3]/100,I[4]):(I=d.exec(A))?Z(I[1],I[2]/100,I[3]/100,1):(I=q.exec(A))?Z(I[1],I[2]/100,I[3]/100,I[4]):u.hasOwnProperty(A)?m(u[A]):"transparent"===A?new x(NaN,NaN,NaN,0):null}function m(A){return new x(A>>16&255,A>>8&255,255&A,1)}function p(A,I,g,C){return C<=0&&(A=I=g=NaN),new x(A,I,g,C)}function x(A,I,g,C){this.r=+A,this.g=+I,this.b=+g,this.opacity=+C}function T(){return`#${X(this.r)}${X(this.g)}${X(this.b)}`}function V(){const A=j(this.opacity);return`${1===A?"rgb(":"rgba("}${P(this.r)}, ${P(this.g)}, ${P(this.b)}${1===A?")":`, ${A})`}`}function j(A){return isNaN(A)?1:Math.max(0,Math.min(1,A))}function P(A){return Math.max(0,Math.min(255,Math.round(A)||0))}function X(A){return((A=P(A))<16?"0":"")+A.toString(16)}function Z(A,I,g,C){return C<=0?A=I=g=NaN:g<=0||g>=1?A=I=NaN:I<=0&&(A=NaN),new W(A,I,g,C)}function O(A){if(A instanceof W)return new W(A.h,A.s,A.l,A.opacity);if(A instanceof R||(A=b(A)),!A)return new W;if(A instanceof W)return A;var I=(A=A.rgb()).r/255,g=A.g/255,C=A.b/255,B=Math.min(I,g,C),Q=Math.max(I,g,C),E=NaN,i=Q-B,o=(Q+B)/2;return i?(E=I===Q?(g-C)/i+6*(g0&&o<1?0:E,new W(E,i,o,A.opacity)}function W(A,I,g,C){this.h=+A,this.s=+I,this.l=+g,this.opacity=+C}function v(A){return(A=(A||0)%360)<0?A+360:A}function _(A){return Math.max(0,Math.min(1,A||0))}function z(A,I,g){return 255*(A<60?I+(g-I)*A/60:A<180?g:A<240?I+(g-I)*(240-A)/60:I)}function $(A){if(A===c||null===A)return c;const{r:I,g:g,b:C}=b(A);return C+(g<<8)+(I<<16)}function AA(){Object.defineProperties(this,{_memory:{value:null,writable:!0},_terminal:{value:null,writable:!0},_renderer:{value:null,writable:!0},_setup:{value:null,writable:!0}})}y(R,b,{copy(A){return Object.assign(new this.constructor,this,A)},displayable(){return this.rgb().displayable()},hex:f,formatHex:f,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return O(this).formatHsl()},formatRgb:L,toString:L}),y(x,(function(A,I,g,C){return 1===arguments.length?((B=A)instanceof R||(B=b(B)),B?new x((B=B.rgb()).r,B.g,B.b,B.opacity):new x):new x(A,I,g,null==C?1:C);var B}),G(R,{brighter(A){return A=null==A?F:Math.pow(F,A),new x(this.r*A,this.g*A,this.b*A,this.opacity)},darker(A){return A=null==A?k:Math.pow(k,A),new x(this.r*A,this.g*A,this.b*A,this.opacity)},rgb(){return this},clamp(){return new x(P(this.r),P(this.g),P(this.b),j(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:T,formatHex:T,formatHex8:function(){return`#${X(this.r)}${X(this.g)}${X(this.b)}${X(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:V,toString:V})),y(W,(function(A,I,g,C){return 1===arguments.length?O(A):new W(A,I,g,null==C?1:C)}),G(R,{brighter(A){return A=null==A?F:Math.pow(F,A),new W(this.h,this.s,this.l*A,this.opacity)},darker(A){return A=null==A?k:Math.pow(k,A),new W(this.h,this.s,this.l*A,this.opacity)},rgb(){var A=this.h%360+360*(this.h<0),I=isNaN(A)||isNaN(this.s)?0:this.s,g=this.l,C=g+(g<.5?g:1-g)*I,B=2*g-C;return new x(z(A>=240?A-240:A+120,B,C),z(A,B,C),z(A<120?A+240:A-120,B,C),this.opacity)},clamp(){return new W(v(this.h),_(this.s),_(this.l),j(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const A=j(this.opacity);return`${1===A?"hsl(":"hsla("}${v(this.h)}, ${100*_(this.s)}%, ${100*_(this.l)}%${1===A?")":`, ${A})`}`}})),Object.defineProperties(AA.prototype,{setup:{value:function(A){this._setup=A},writable:!0,configurable:!0},init:{value:async function(A={}){const I=await w(await h()),{memory:g}=I,C=new E(A),B=s.new(C._cols,C._rows);this._memory=g,this._terminal=C,this._renderer=B,this._terminal.background("#000")},writable:!0,configurable:!0},run:{value:function(){return this._setup?.(this),n.call(this),this._terminal.node()},writable:!0,configurable:!0},stroke:{value:function(A,I="#ffffff",g=null){const[C,B=c]=function(A){return Array.isArray(A)?A:Array.from(A).slice(0,2).map((A=>A.codePointAt(0)))}(A);return this._renderer.stroke(C,B,$(I),$(g)),this},writable:!0,configurable:!0},point:{value:function(A,I){return this._renderer.point(A,I),this},writable:!0,configurable:!0},rows:{value:function(){return this._terminal._rows},writable:!0,configurable:!0},cols:{value:function(){return this._terminal._cols},writable:!0,configurable:!0},node:{value:function(){return this._terminal.node()},writable:!0,configurable:!0}}),A.cell=async function(A){const I=new AA,{setup:g,...C}=A(I);return await I.init(C),I.setup(g),I.run(),I.node()},A.wide=function(A){return[A.codePointAt(0)+4026531840,c]}})); diff --git a/docs/.vitepress/theme/index.js b/docs/.vitepress/theme/index.js index 9e88d61d..8edc8aa5 100644 --- a/docs/.vitepress/theme/index.js +++ b/docs/.vitepress/theme/index.js @@ -1,6 +1,7 @@ import DefaultTheme from "vitepress/theme"; import Layout from "genji-theme-vitepress"; import { h } from "vue"; +import "../lib/charming-cell.umd.min.js"; // More props: https://genji-md.dev/reference/props const props = { diff --git a/docs/cell/getting-started.md b/docs/cell/getting-started.md index bad55622..8efc13ff 100644 --- a/docs/cell/getting-started.md +++ b/docs/cell/getting-started.md @@ -1 +1,7 @@ # Getting Started + +> WIP + +```bash +npm install @charming-art/cell +``` diff --git a/docs/cell/index.md b/docs/cell/index.md index 3f124ccc..e935d061 100644 --- a/docs/cell/index.md +++ b/docs/cell/index.md @@ -1 +1,15 @@ -# Charming Cell \ No newline at end of file +# Charming Cell + +The P5 like JavaScript API for ASCII art. + +> [!NOTE] +> The current next branch is implementing the new proposal API for production use. Please refer to the [python branch](https://github.com/charming-art/charming-cell/tree/python) for the released Python version. + +## Resources ๐Ÿ“š + +- Documentation - https://charmingjs.org/cell/ +- Examples - https://observablehq.com/d/18b3d6f3affff5bb + +## License ๐Ÿ“„ + +ISC@Bairui SU diff --git a/docs/cell/what-is-cell.md b/docs/cell/what-is-cell.md index 177c0578..14d86f4d 100644 --- a/docs/cell/what-is-cell.md +++ b/docs/cell/what-is-cell.md @@ -1 +1,17 @@ # What is Cell? + +```js eval +cm.cell((ctx) => ({ + mode: "double", + width: 520, + height: 520, + setup() { + for (let t = 0; t <= Math.PI * 2; t += Math.PI / 120) { + const x = ctx.cols() / 2 + 12 * Math.cos(t) * Math.cos(t * 3); + const y = ctx.rows() / 2 + 12 * Math.sin(t) * Math.cos(t * 3); + ctx.stroke(cm.wide("๐ŸŒŸ")); + ctx.point(x, y); + } + }, +})); +``` diff --git a/docs/flow/getting-started.md b/docs/flow/getting-started.md index bad55622..8efc13ff 100644 --- a/docs/flow/getting-started.md +++ b/docs/flow/getting-started.md @@ -1 +1,7 @@ # Getting Started + +> WIP + +```bash +npm install @charming-art/cell +``` diff --git a/docs/flow/index.md b/docs/flow/index.md index da44df44..795f8855 100644 --- a/docs/flow/index.md +++ b/docs/flow/index.md @@ -1 +1,3 @@ # Charming Flow + +The functional JavaScript API for graphics. diff --git a/docs/getting-started.md b/docs/getting-started.md index bad55622..074ffec0 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1 +1,7 @@ # Getting Started + +> WIP + +```bash +npm install @charming-art/charming +``` diff --git a/docs/lodash/index.md b/docs/lodash/index.md index 414937ab..3ff0338b 100644 --- a/docs/lodash/index.md +++ b/docs/lodash/index.md @@ -1 +1,3 @@ # Charming Lodash + +The helpful utils for graphics and geometries. diff --git a/docs/what-is-charming.md b/docs/what-is-charming.md index 1d1faf0f..6e18f5e8 100644 --- a/docs/what-is-charming.md +++ b/docs/what-is-charming.md @@ -1 +1,3 @@ # What is Charming? + +The JavaScript library for tailored creative coding. diff --git a/package.json b/package.json index dec53e72..f35c41eb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test": "echo \"Error: no test specified\" && exit 1", "docs:dev": "vitepress dev docs", "docs:build": "vitepress build docs", - "docs:preview": "vitepress preview docs" + "docs:preview": "vitepress preview docs", + "docs:deploy": "bash ./deploy.sh" }, "keywords": [], "author": "", @@ -16,4 +17,4 @@ "genji-theme-vitepress": "^0.2.6", "vitepress": "^1.3.4" } -} \ No newline at end of file +}