@georgedoescode/cx
Advanced tools
Comparing version 1.0.1 to 1.0.2
function createCanvasElement(width, height) { | ||
const canvas = document.createElement('canvas'); | ||
var canvas = document.createElement('canvas'); | ||
canvas.width = width; | ||
@@ -8,5 +8,5 @@ canvas.height = height; | ||
function setCanvasPxDensity(canvas, density = 1) { | ||
const canvasRect = canvas.getBoundingClientRect(); | ||
const ctx = canvas.getContext('2d'); | ||
function setCanvasPxDensity(canvas, density) { | ||
var canvasRect = canvas.getBoundingClientRect(); | ||
var ctx = canvas.getContext('2d'); | ||
canvas.width = canvasRect.width * density; | ||
@@ -24,17 +24,20 @@ canvas.height = canvasRect.height * density; | ||
function createCustomContext(context) { | ||
const customCtx = { | ||
var customCtx = { | ||
base: context | ||
}; | ||
for (const prop in context) { | ||
var _loop = function _loop(prop) { | ||
Object.defineProperty(customCtx, prop, { | ||
get() { | ||
get: function get() { | ||
return typeof customCtx.base[prop] === 'function' ? customCtx.base[prop].bind(context) : customCtx.base[prop]; | ||
}, | ||
set(value) { | ||
set: function set(value) { | ||
console.log('value', value); | ||
customCtx.base[prop] = value; | ||
} | ||
}); | ||
}; | ||
}); | ||
for (var prop in context) { | ||
_loop(prop); | ||
} | ||
@@ -44,3 +47,3 @@ | ||
customCtx[key] = function () { | ||
return value(customCtx.base, ...arguments); | ||
return value.apply(void 0, [customCtx.base].concat(Array.prototype.slice.call(arguments))); | ||
}; | ||
@@ -52,22 +55,21 @@ }; | ||
const DEFAULTS = { | ||
var DEFAULTS = { | ||
width: 640, | ||
height: 480, | ||
mount: document.body | ||
mount: document.body, | ||
dpr: window.devicePixelRatio | ||
}; | ||
function createCanvas(opts) { | ||
const options = Object.assign(DEFAULTS, opts); | ||
const canvasEl = createCanvasElement(options.width, options.height); | ||
const ctx = createCustomContext(canvasEl.getContext('2d')); | ||
var options = Object.assign(DEFAULTS, opts); | ||
var canvasEl = createCanvasElement(options.width, options.height); | ||
var ctx = createCustomContext(canvasEl.getContext('2d')); | ||
mountCanvasToDOM(canvasEl, options.mount); | ||
setCanvasPxDensity(canvasEl, window.devicePixelRatio || 1); | ||
setCanvasPxDensity(canvasEl, options.dpr); | ||
return { | ||
ctx, | ||
ctx: ctx, | ||
element: { | ||
el: canvasEl, | ||
setPXDensity(density) { | ||
setPXDensity: function setPXDensity(density) { | ||
setCanvasPxDensity(canvasEl, density); | ||
} | ||
} | ||
@@ -74,0 +76,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).cx={})}(this,(function(e){"use strict";function t(e,t=1){const n=e.getBoundingClientRect(),i=e.getContext("2d");e.width=n.width*t,e.height=n.height*t,e.style.width=n.width+"px",e.style.height=n.height+"px",i.scale(t,t)}const n={width:640,height:480,mount:document.body};e.createCanvas=function(e){const i=Object.assign(n,e),o=function(e,t){const n=document.createElement("canvas");return n.width=e,n.height=t,n}(i.width,i.height),s=function(e){const t={base:e};for(const n in e)Object.defineProperty(t,n,{get:()=>"function"==typeof t.base[n]?t.base[n].bind(e):t.base[n],set(e){t.base[n]=e}});return t.registerCustomMethod=function(e,n){t[e]=function(){return n(t.base,...arguments)}},t}(o.getContext("2d"));var c;return c=o,i.mount.appendChild(c),t(o,window.devicePixelRatio||1),{ctx:s,element:{el:o,setPXDensity(e){t(o,e)}}}},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).cx={})}(this,(function(e){"use strict";function t(e,t){var n=e.getBoundingClientRect(),i=e.getContext("2d");e.width=n.width*t,e.height=n.height*t,e.style.width=n.width+"px",e.style.height=n.height+"px",i.scale(t,t)}var n={width:640,height:480,mount:document.body,dpr:window.devicePixelRatio};e.createCanvas=function(e){var i,o,c,d=Object.assign(n,e),r=(i=d.width,o=d.height,(c=document.createElement("canvas")).width=i,c.height=o,c),u=function(e){var t={base:e},n=function(n){Object.defineProperty(t,n,{get:function(){return"function"==typeof t.base[n]?t.base[n].bind(e):t.base[n]},set:function(e){console.log("value",e),t.base[n]=e}})};for(var i in e)n(i);return t.registerCustomMethod=function(e,n){t[e]=function(){return n.apply(void 0,[t.base].concat(Array.prototype.slice.call(arguments)))}},t}(r.getContext("2d"));return function(e,t){t.appendChild(e)}(r,d.mount),t(r,d.dpr),{ctx:u,element:{el:r,setPXDensity:function(e){t(r,e)}}}},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@georgedoescode/cx", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "CX 🎨", | ||
@@ -35,2 +35,4 @@ "main": "dist/cx.min.js", | ||
"concurrently": "^5.1.0", | ||
"jest": "^25.2.4", | ||
"jest-canvas-mock": "^2.2.0", | ||
"live-server": "^1.2.1", | ||
@@ -37,0 +39,0 @@ "rollup": "^2.2.0", |
@@ -13,2 +13,3 @@ import { | ||
mount: document.body, | ||
dpr: window.devicePixelRatio, | ||
}; | ||
@@ -23,3 +24,3 @@ | ||
mountCanvasToDOM(canvasEl, options.mount); | ||
setCanvasPxDensity(canvasEl, window.devicePixelRatio || 1); | ||
setCanvasPxDensity(canvasEl, options.dpr); | ||
@@ -26,0 +27,0 @@ return { |
@@ -10,3 +10,3 @@ function createCanvasElement(width, height) { | ||
function setCanvasPxDensity(canvas, density = 1) { | ||
function setCanvasPxDensity(canvas, density) { | ||
const canvasRect = canvas.getBoundingClientRect(); | ||
@@ -13,0 +13,0 @@ const ctx = canvas.getContext('2d'); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
76139
27
779
11
1